use of com.microsoft.azure.management.compute.InstanceViewStatus in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method patchVMInstanceDetails.
private DeferredResult<ComputeState> patchVMInstanceDetails(EnumerationContext ctx, VirtualMachinesInner vmOps, ComputeState computeState) {
String resourceGroupName = getResourceGroupName(computeState.id);
String vmName = computeState.name;
AzureDeferredResultServiceCallback<VirtualMachineInner> handler = new Default<>(this, "Load virtual machine instance view:" + vmName);
PhotonModelUtils.runInExecutor(this.executorService, () -> {
vmOps.getByResourceGroupAsync(resourceGroupName, vmName, InstanceViewTypes.INSTANCE_VIEW, handler);
}, handler::failure);
return handler.toDeferredResult().thenApply(vm -> {
for (InstanceViewStatus status : vm.instanceView().statuses()) {
if (computeState.creationTimeMicros == null && status.time() != null) {
computeState.creationTimeMicros = TimeUnit.MILLISECONDS.toMicros(status.time().getMillis());
}
if (status.code().equals(AzureConstants.AZURE_VM_POWER_STATE_RUNNING)) {
computeState.powerState = PowerState.ON;
} else if (status.code().equals(AzureConstants.AZURE_VM_POWER_STATE_STOPPED)) {
computeState.powerState = PowerState.OFF;
} else if (status.code().equals(AzureConstants.AZURE_VM_POWER_STATE_DEALLOCATED)) {
computeState.powerState = PowerState.SUSPEND;
}
}
if (computeState.customProperties == null) {
computeState.customProperties = new HashMap<>();
}
computeState.customProperties.put(RESOURCE_GROUP_NAME, resourceGroupName);
computeState.endpointLinks.add(ctx.request.endpointLink);
computeState.type = ComputeType.VM_GUEST;
computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
return computeState;
});
}
use of com.microsoft.azure.management.compute.InstanceViewStatus in project photon-model by vmware.
the class AzurePowerServiceTest method assertVmCurrentPowerState.
private void assertVmCurrentPowerState(PowerState powerState) {
if (this.isMock) {
// return. Nothing provisioned on Azure so nothing to check
return;
}
try {
PowerState vmPowerState = PowerState.UNKNOWN;
VirtualMachineInner vm = AzureTestUtil.getAzureVirtualMachineWithExtension(this.computeManagementClient, azureVMName, azureVMName, EXPAND_INSTANCE_VIEW_PARAM);
for (InstanceViewStatus status : vm.instanceView().statuses()) {
if (status.code().equals(AzureConstants.AZURE_VM_POWER_STATE_RUNNING)) {
vmPowerState = PowerState.ON;
} else if (status.code().equals(AzureConstants.AZURE_VM_POWER_STATE_STOPPED)) {
vmPowerState = PowerState.OFF;
}
}
assertEquals("VM current power state does not match expected value.", powerState, vmPowerState);
} catch (Exception e) {
fail("Unable to verify current Machine Power state on Azure");
e.printStackTrace();
}
}
use of com.microsoft.azure.management.compute.InstanceViewStatus in project azure-sdk-for-java by Azure.
the class LinuxDiskVolumeEncryptionMonitorImpl method instanceViewFirstSubStatus.
/**
* @return the first sub-status from instance view sub-status collection associated with the
* encryption extension
*/
private JsonNode instanceViewFirstSubStatus() {
if (!hasEncryptionExtension()) {
return null;
}
VirtualMachineExtensionInstanceView instanceView = this.encryptionExtension.instanceView();
if (instanceView == null || instanceView.substatuses() == null) {
return null;
}
List<InstanceViewStatus> instanceViewSubStatuses = instanceView.substatuses();
if (instanceViewSubStatuses.size() == 0) {
return null;
}
ObjectMapper mapper = new ObjectMapper();
final JsonNode rootNode;
try {
rootNode = mapper.readTree(instanceViewSubStatuses.get(0).message());
} catch (IOException exception) {
return null;
}
return rootNode;
}
Aggregations