com.azure.resourcemanager.compute.implementation.VirtualMachineScaleSetVMsImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-resourcemanager-compute Show documentation
Show all versions of azure-resourcemanager-compute Show documentation
This package contains Microsoft Azure Compute Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.resourcemanager.compute.implementation;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.resourcemanager.compute.ComputeManager;
import com.azure.resourcemanager.compute.fluent.VirtualMachineScaleSetVMsClient;
import com.azure.resourcemanager.compute.fluent.VirtualMachineScaleSetsClient;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetVMInner;
import com.azure.resourcemanager.compute.models.InstanceViewTypes;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVM;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMExpandType;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMInstanceIDs;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMInstanceRequiredIDs;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMs;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/** Implementation for {@link VirtualMachineScaleSetVMs}. */
class VirtualMachineScaleSetVMsImpl
extends ReadableWrappersImpl
implements VirtualMachineScaleSetVMs {
private final VirtualMachineScaleSetImpl scaleSet;
private final VirtualMachineScaleSetVMsClient client;
private final ComputeManager computeManager;
VirtualMachineScaleSetVMsImpl(
VirtualMachineScaleSetImpl scaleSet, VirtualMachineScaleSetVMsClient client, ComputeManager computeManager) {
this.scaleSet = scaleSet;
this.client = client;
this.computeManager = computeManager;
}
@Override
protected VirtualMachineScaleSetVMImpl wrapModel(VirtualMachineScaleSetVMInner inner) {
if (inner == null) {
return null;
}
return new VirtualMachineScaleSetVMImpl(inner, this.scaleSet, this.client, this.computeManager);
}
@Override
public PagedIterable list() {
return new PagedIterable<>(this.listAsync());
}
public VirtualMachineScaleSetVMsClient inner() {
return this.client;
}
@Override
public PagedFlux listAsync() {
return super.wrapPageAsync(this.client.listAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name()));
}
@Override
public Mono deleteInstancesAsync(Collection instanceIds) {
return this.scaleSet.manager().virtualMachineScaleSets()
.deleteInstancesAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name(), instanceIds, false);
}
@Override
public Mono deleteInstancesAsync(String... instanceIds) {
return this.deleteInstancesAsync(new ArrayList<>(Arrays.asList(instanceIds)));
}
@Override
public void deleteInstances(String... instanceIds) {
this.deleteInstancesAsync(instanceIds).block();
}
@Override
public Mono deleteInstancesAsync(Collection instanceIds, boolean forceDeletion) {
return this.scaleSet.manager().virtualMachineScaleSets().deleteInstancesAsync(this.scaleSet.resourceGroupName(),
this.scaleSet.name(), instanceIds, forceDeletion);
}
@Override
public void deleteInstances(Collection instanceIds, boolean forceDeletion) {
this.deleteInstancesAsync(instanceIds, forceDeletion).block();
}
@Override
public void deallocateInstances(Collection instanceIds) {
this.deallocateInstancesAsync(instanceIds).block();
}
@Override
public Mono deallocateInstancesAsync(Collection instanceIds) {
return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().deallocateAsync(
this.scaleSet.resourceGroupName(), this.scaleSet.name(), null,
new VirtualMachineScaleSetVMInstanceIDs().withInstanceIds(new ArrayList<>(instanceIds)));
}
@Override
public void powerOffInstances(Collection instanceIds, boolean skipShutdown) {
this.powerOffInstancesAsync(instanceIds, skipShutdown).block();
}
@Override
public Mono powerOffInstancesAsync(Collection instanceIds, boolean skipShutdown) {
return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().powerOffAsync(
this.scaleSet.resourceGroupName(), this.scaleSet.name(), skipShutdown,
new VirtualMachineScaleSetVMInstanceIDs().withInstanceIds(new ArrayList<>(instanceIds)));
}
@Override
public void startInstances(Collection instanceIds) {
this.startInstancesAsync(instanceIds).block();
}
@Override
public Mono startInstancesAsync(Collection instanceIds) {
return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().startAsync(
this.scaleSet.resourceGroupName(), this.scaleSet.name(),
new VirtualMachineScaleSetVMInstanceIDs().withInstanceIds(new ArrayList<>(instanceIds)));
}
@Override
public void restartInstances(Collection instanceIds) {
this.restartInstancesAsync(instanceIds).block();
}
@Override
public Mono restartInstancesAsync(Collection instanceIds) {
return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().restartAsync(
this.scaleSet.resourceGroupName(), this.scaleSet.name(),
new VirtualMachineScaleSetVMInstanceIDs().withInstanceIds(new ArrayList<>(instanceIds)));
}
@Override
public void redeployInstances(Collection instanceIds) {
this.redeployInstancesAsync(instanceIds).block();
}
@Override
public Mono redeployInstancesAsync(Collection instanceIds) {
return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().redeployAsync(
this.scaleSet.resourceGroupName(), this.scaleSet.name(),
new VirtualMachineScaleSetVMInstanceIDs().withInstanceIds(new ArrayList<>(instanceIds)));
}
// @Override
// public void reimageInstances(Collection instanceIds) {
// this.reimageInstancesAsync(instanceIds).block();
// }
//
// @Override
// public Mono reimageInstancesAsync(Collection instanceIds) {
// return this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets().reimageAsync(
// this.scaleSet.resourceGroupName(), this.scaleSet.name(),
// new VirtualMachineScaleSetReimageParameters().withInstanceIds(new ArrayList<>(instanceIds)));
// }
@Override
public VirtualMachineScaleSetVM getInstance(String instanceId) {
return this.getInstanceAsync(instanceId).block();
}
@Override
public Mono getInstanceAsync(String instanceId) {
return this
.client
.getWithResponseAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name(), instanceId,
InstanceViewTypes.INSTANCE_VIEW)
.map(Response::getValue)
.map(this::wrapModel);
}
@Override
public Mono updateInstancesAsync(Collection instanceIds) {
if (instanceIds == null || instanceIds.size() == 0) {
return Mono.empty();
}
List instanceIdList = new ArrayList<>();
for (String instanceId : instanceIds) {
instanceIdList.add(instanceId);
}
VirtualMachineScaleSetsClient scaleSetInnerManager =
this.scaleSet.manager().serviceClient().getVirtualMachineScaleSets();
return scaleSetInnerManager
.updateInstancesAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name(),
new VirtualMachineScaleSetVMInstanceRequiredIDs().withInstanceIds(instanceIdList));
}
@Override
public Mono updateInstancesAsync(String... instanceIds) {
return this.updateInstancesAsync(new ArrayList<>(Arrays.asList(instanceIds)));
}
@Override
public void updateInstances(String... instanceIds) {
this.updateInstancesAsync(instanceIds).block();
}
@Override
public Mono simulateEvictionAsync(String instanceId) {
return this.client.simulateEvictionAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name(), instanceId);
}
@Override
public void simulateEviction(String instanceId) {
this.simulateEvictionAsync(instanceId).block();
}
@Override
public PagedIterable list(String filter, VirtualMachineScaleSetVMExpandType expand) {
return new PagedIterable<>(this.listAsync(filter, expand));
}
@Override
public PagedFlux listAsync(String filter, VirtualMachineScaleSetVMExpandType expand) {
return super.wrapPageAsync(this.client.listAsync(this.scaleSet.resourceGroupName(), this.scaleSet.name(),
filter, null, expand.toString()));
}
}