Search in sources :

Example 1 with InstanceViewStatus

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;
    });
}
Also used : InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)

Example 2 with InstanceViewStatus

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();
    }
}
Also used : InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState)

Example 3 with InstanceViewStatus

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;
}
Also used : VirtualMachineExtensionInstanceView(com.microsoft.azure.management.compute.VirtualMachineExtensionInstanceView) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

InstanceViewStatus (com.microsoft.azure.management.compute.InstanceViewStatus)3 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VirtualMachineExtensionInstanceView (com.microsoft.azure.management.compute.VirtualMachineExtensionInstanceView)1 Default (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)1 PowerState (com.vmware.photon.controller.model.resources.ComputeService.PowerState)1 IOException (java.io.IOException)1