Search in sources :

Example 36 with CloudVmInstanceStatus

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

the class MockServer method addInstance.

public void addInstance(int numberOfAddedInstances) {
    ServerAddressGenerator serverAddressGenerator = new ServerAddressGenerator(numberOfAddedInstances);
    serverAddressGenerator.setFrom(instanceMap.size());
    serverAddressGenerator.iterateOver((address, number) -> {
        String instanceId = "instance-" + address;
        InstanceTemplate instanceTemplate = new InstanceTemplate("medium", "group", Integer.toUnsignedLong(number), new ArrayList<>(), InstanceStatus.CREATED, null, 0L);
        InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
        CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, instanceTemplate, instanceAuthentication);
        CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
        CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, mockServerAddress, sshPort, "MOCK");
        CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
        instanceMap.put(instanceId, cloudVmMetaDataStatus);
    });
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ServerAddressGenerator(com.sequenceiq.it.util.ServerAddressGenerator) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 37 with CloudVmInstanceStatus

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

the class AzureInstanceConnector method start.

@Override
public List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    for (CloudInstance vm : vms) {
        try {
            AzureClient azureClient = ac.getParameter(AzureClient.class);
            azureClient.startVirtualMachine(stackName, vm.getInstanceId());
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
        } catch (RuntimeException e) {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.FAILED, e.getMessage()));
        }
    }
    return statuses;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 38 with CloudVmInstanceStatus

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

the class AzureInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
    for (CloudInstance vm : vms) {
        try {
            AzureClient azureClient = ac.getParameter(AzureClient.class);
            boolean virtualMachineExists = azureClient.isVirtualMachineExists(stackName, vm.getInstanceId());
            if (virtualMachineExists) {
                PowerState virtualMachinePowerState = azureClient.getVirtualMachinePowerState(stackName, vm.getInstanceId());
                statuses.add(new CloudVmInstanceStatus(vm, AzureInstanceStatus.get(virtualMachinePowerState)));
            } else {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
            }
        } catch (CloudException e) {
            if (e.body() != null && "ResourceNotFound".equals(e.body().code())) {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
            } else {
                statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
            }
        } catch (RuntimeException ignored) {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
        }
    }
    return statuses;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudException(com.microsoft.azure.CloudException) PowerState(com.microsoft.azure.management.compute.PowerState)

Example 39 with CloudVmInstanceStatus

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

the class CloudMetaDataStatuses method createCloudVmMetaDataStatuses.

private List<CloudVmMetaDataStatus> createCloudVmMetaDataStatuses(Collection<CloudInstance> cloudInstances) {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
        CloudVmMetaDataStatus oldCloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
        InstanceTemplate oldTemplate = oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getTemplate();
        Optional<CloudInstance> cloudInstance = cloudInstances.stream().filter(instance -> Objects.equals(instance.getTemplate().getPrivateId(), oldTemplate.getPrivateId())).findFirst();
        if (cloudInstance.isPresent()) {
            CloudInstance newCloudInstance = new CloudInstance(stringCloudVmMetaDataStatusEntry.getKey(), cloudInstance.get().getTemplate(), cloudInstance.get().getAuthentication(), cloudInstance.get().getParameters());
            CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(newCloudInstance, oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus());
            CloudVmMetaDataStatus newCloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, oldCloudVmMetaDataStatus.getMetaData());
            cloudVmMetaDataStatuses.add(newCloudVmMetaDataStatus);
        }
    }
    return cloudVmMetaDataStatuses;
}
Also used : Collection(java.util.Collection) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Gson(com.google.gson.Gson) Map(java.util.Map) Entry(java.util.Map.Entry) ITResponse(com.sequenceiq.it.spark.ITResponse) Optional(java.util.Optional) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)39 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)32 ArrayList (java.util.ArrayList)21 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)12 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)8 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 Server (org.openstack4j.model.compute.Server)5 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)4 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)4 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)4 List (java.util.List)4 Map (java.util.Map)4 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2