Search in sources :

Example 1 with INSTANCE_NAME

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance.INSTANCE_NAME in project cloudbreak by hortonworks.

the class AzureVirtualMachineService method fillVmStatuses.

private void fillVmStatuses(List<CloudInstance> cloudInstances, AzureVirtualMachinesWithStatuses virtualMachineListResult) {
    Map<String, VirtualMachine> virtualMachines = virtualMachineListResult.getVirtualMachines();
    List<CloudVmInstanceStatus> statuses = virtualMachineListResult.getStatuses();
    LOGGER.info("Fill vm statuses from returned virtualmachines from azure: {}", virtualMachines.keySet());
    for (CloudInstance cloudInstance : cloudInstances) {
        virtualMachines.values().stream().filter(virtualMachine -> virtualMachine.name().equals(cloudInstance.getInstanceId())).findFirst().ifPresentOrElse(virtualMachine -> {
            PowerState virtualMachinePowerState = virtualMachine.powerState();
            String computerName = virtualMachine.computerName();
            cloudInstance.putParameter(INSTANCE_NAME, computerName);
            statuses.add(new CloudVmInstanceStatus(cloudInstance, AzureInstanceStatus.get(virtualMachinePowerState)));
        }, () -> statuses.stream().filter(cvis -> cvis.getCloudInstance().getInstanceId() != null && cvis.getCloudInstance().getInstanceId().equals(cloudInstance.getInstanceId())).findAny().ifPresentOrElse(cloudInstanceWithStatus -> logTheStatusOfTheCloudInstance(cloudInstanceWithStatus), () -> statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.TERMINATED))));
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Completable(rx.Completable) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AzureInstanceStatus(com.sequenceiq.cloudbreak.cloud.azure.status.AzureInstanceStatus) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) PagedList(com.microsoft.azure.PagedList) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) Retryable(org.springframework.retry.annotation.Retryable) INSTANCE_NAME(com.sequenceiq.cloudbreak.cloud.model.CloudInstance.INSTANCE_NAME) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) Component(org.springframework.stereotype.Component) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) HasName(com.microsoft.azure.management.resources.fluentcore.arm.models.HasName) CloudException(com.microsoft.azure.CloudException) PowerState(com.microsoft.azure.management.compute.PowerState) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) PowerState(com.microsoft.azure.management.compute.PowerState) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimaps (com.google.common.collect.Multimaps)1 CloudException (com.microsoft.azure.CloudException)1 PagedList (com.microsoft.azure.PagedList)1 PowerState (com.microsoft.azure.management.compute.PowerState)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 HasName (com.microsoft.azure.management.resources.fluentcore.arm.models.HasName)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureInstanceStatus (com.sequenceiq.cloudbreak.cloud.azure.status.AzureInstanceStatus)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 INSTANCE_NAME (com.sequenceiq.cloudbreak.cloud.model.CloudInstance.INSTANCE_NAME)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1