Search in sources :

Example 46 with CloudInstance

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

the class UnhealthyInstancesFinalizerTest method shouldFinalizeInstancesMarkedAsTerminated.

@Test
public void shouldFinalizeInstancesMarkedAsTerminated() {
    Stack stack = TestUtil.stack(Status.AVAILABLE, TestUtil.awsCredential());
    CloudCredential cloudCredential = mock(CloudCredential.class);
    when(credentialConverter.convert(stack.getCredential())).thenReturn(cloudCredential);
    String instanceId1 = "i-0f1e0605506aaaaaa";
    String instanceId2 = "i-0f1e0605506bbbbbb";
    Set<InstanceMetaData> candidateUnhealthyInstances = new HashSet<>();
    setupInstanceMetaData(instanceId1, candidateUnhealthyInstances);
    setupInstanceMetaData(instanceId2, candidateUnhealthyInstances);
    List<CloudInstance> cloudInstances = new ArrayList<>();
    CloudInstance cloudInstance1 = setupCloudInstance(instanceId1, cloudInstances);
    CloudInstance cloudInstance2 = setupCloudInstance(instanceId2, cloudInstances);
    when(cloudInstanceConverter.convert(candidateUnhealthyInstances)).thenReturn(cloudInstances);
    List<CloudVmInstanceStatus> cloudVmInstanceStatusList = new ArrayList<>();
    setupCloudVmInstanceStatus(cloudInstance1, InstanceStatus.STOPPED, cloudVmInstanceStatusList);
    setupCloudVmInstanceStatus(cloudInstance2, InstanceStatus.TERMINATED, cloudVmInstanceStatusList);
    when(instanceStateQuery.getCloudVmInstanceStatuses(eq(cloudCredential), any(CloudContext.class), eq(cloudInstances))).thenReturn(cloudVmInstanceStatusList);
    Set<String> unhealthyInstances = underTest.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances);
    assertEquals(1, unhealthyInstances.size());
    assertTrue(unhealthyInstances.contains(instanceId2));
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with CloudInstance

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

the class GcpResourceConnector method collectProviderSpecificResources.

@Override
protected List<CloudResource> collectProviderSpecificResources(List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudResource> result = new ArrayList<>();
    for (CloudInstance instance : vms) {
        String instanceId = instance.getInstanceId();
        String baseName = instanceId.substring(0, instanceId.lastIndexOf(CloudbreakResourceNameService.DELIMITER));
        for (CloudResource resource : resources) {
            if (resource.getType() == ResourceType.GCP_RESERVED_IP && resource.getName().startsWith(baseName)) {
                result.add(resource);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 48 with CloudInstance

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

the class GcpAttachedDiskResourceBuilder method create.

@Override
public List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image) {
    List<CloudResource> cloudResources = new ArrayList<>();
    CloudInstance instance = group.getReferenceInstanceConfiguration();
    InstanceTemplate template = instance.getTemplate();
    GcpResourceNameService resourceNameService = getResourceNameService();
    String groupName = group.getName();
    CloudContext cloudContext = auth.getCloudContext();
    String stackName = cloudContext.getName();
    for (int i = 0; i < template.getVolumes().size(); i++) {
        String resourceName = resourceNameService.resourceName(resourceType(), stackName, groupName, privateId, i);
        cloudResources.add(createNamedResource(resourceType(), resourceName));
    }
    return cloudResources;
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) GcpResourceNameService(com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 49 with CloudInstance

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

the class GcpInstanceResourceBuilder method checkInstances.

@Override
public List<CloudVmInstanceStatus> checkInstances(GcpContext context, AuthenticatedContext auth, List<CloudInstance> instances) {
    CloudInstance cloudInstance = instances.get(0);
    try {
        LOGGER.info("Checking instance: {}", cloudInstance);
        Operation operation = check(context, cloudInstance);
        boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
        InstanceStatus status = finished ? context.isBuild() ? InstanceStatus.STARTED : InstanceStatus.STOPPED : InstanceStatus.IN_PROGRESS;
        LOGGER.info("Instance: {} status: {}", instances, status);
        return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, status));
    } catch (Exception ignored) {
        LOGGER.info("Failed to check instance state of {}", cloudInstance);
        return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
    }
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Operation(com.google.api.services.compute.model.Operation) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)

Example 50 with CloudInstance

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

the class GcpInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    CloudCredential credential = ac.getCloudCredential();
    CloudContext cloudContext = ac.getCloudContext();
    Compute compute = GcpStackUtil.buildCompute(credential);
    for (CloudInstance instance : vms) {
        InstanceStatus status = InstanceStatus.UNKNOWN;
        try {
            Instance executeInstance = getInstance(cloudContext, credential, compute, instance.getInstanceId());
            if ("RUNNING".equals(executeInstance.getStatus())) {
                status = InstanceStatus.STARTED;
            } else if ("TERMINATED".equals(executeInstance.getStatus())) {
                status = InstanceStatus.STOPPED;
            }
        } catch (GoogleJsonResponseException e) {
            if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                status = InstanceStatus.TERMINATED;
            } else {
                LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
            }
        } catch (IOException e) {
            LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
        }
        statuses.add(new CloudVmInstanceStatus(instance, status));
    }
    return statuses;
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Instance(com.google.api.services.compute.model.Instance) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Compute(com.google.api.services.compute.Compute) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) IOException(java.io.IOException)

Aggregations

CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)75 ArrayList (java.util.ArrayList)41 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)32 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)25 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)17 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)16 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)10 Group (com.sequenceiq.cloudbreak.cloud.model.Group)10 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)10 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)7 Instance (com.amazonaws.services.ec2.model.Instance)7