Search in sources :

Example 31 with CloudInstance

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

the class UnhealthyInstancesFinalizerTest method shouldFinalizeInstancesThatAreNotFound.

@Test
public void shouldFinalizeInstancesThatAreNotFound() {
    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);
    when(cloudInstanceConverter.convert(candidateUnhealthyInstances)).thenReturn(cloudInstances);
    List<CloudVmInstanceStatus> cloudVmInstanceStatusList = new ArrayList<>();
    setupCloudVmInstanceStatus(cloudInstance1, InstanceStatus.TERMINATED, cloudVmInstanceStatusList);
    when(instanceStateQuery.getCloudVmInstanceStatuses(eq(cloudCredential), any(CloudContext.class), eq(cloudInstances))).thenReturn(cloudVmInstanceStatusList);
    Set<String> unhealthyInstances = underTest.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances);
    assertEquals(2, unhealthyInstances.size());
    assertTrue(unhealthyInstances.contains(instanceId1));
    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 32 with CloudInstance

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

the class UnhealthyInstancesFinalizerTest method setupCloudInstance.

private CloudInstance setupCloudInstance(String instanceId, List<CloudInstance> cloudInstances) {
    CloudInstance cloudInstance = mock(CloudInstance.class);
    when(cloudInstance.getInstanceId()).thenReturn(instanceId);
    cloudInstances.add(cloudInstance);
    return cloudInstance;
}
Also used : CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 33 with CloudInstance

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

the class StackToCloudStackConverter method buildInstanceGroups.

public List<Group> buildInstanceGroups(List<InstanceGroup> instanceGroups, StackAuthentication stackAuthentication, Collection<String> deleteRequests) {
    // sort by name to avoid shuffling the different instance groups
    Collections.sort(instanceGroups);
    List<Group> groups = new ArrayList<>();
    long privateId = getFirstValidPrivateId(instanceGroups);
    for (InstanceGroup instanceGroup : instanceGroups) {
        if (instanceGroup.getTemplate() != null) {
            CloudInstance skeleton = null;
            List<CloudInstance> instances = new ArrayList<>();
            Template template = instanceGroup.getTemplate();
            int desiredNodeCount = instanceGroup.getNodeCount();
            // existing instances
            for (InstanceMetaData metaData : instanceGroup.getInstanceMetaData()) {
                InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
                instances.add(buildInstance(metaData, template, stackAuthentication, instanceGroup.getGroupName(), metaData.getPrivateId(), status));
            }
            // new instances
            int existingNodesSize = instances.size();
            if (existingNodesSize < desiredNodeCount) {
                for (long i = 0; i < desiredNodeCount - existingNodesSize; i++) {
                    instances.add(buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), privateId++, InstanceStatus.CREATE_REQUESTED));
                }
            }
            if (existingNodesSize == desiredNodeCount && desiredNodeCount == 0) {
                skeleton = buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), 0L, InstanceStatus.CREATE_REQUESTED);
            }
            Json attributes = instanceGroup.getAttributes();
            InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
            Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
            groups.add(new Group(instanceGroup.getGroupName(), instanceGroup.getInstanceGroupType(), instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
        }
    }
    return groups;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.domain.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)

Example 34 with CloudInstance

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

the class StackToCloudStackConverter method buildInstance.

public CloudInstance buildInstance(InstanceMetaData instanceMetaData, Template template, StackAuthentication stackAuthentication, String name, Long privateId, InstanceStatus status) {
    String id = instanceMetaData == null ? null : instanceMetaData.getInstanceId();
    String hostName = instanceMetaData == null ? null : instanceMetaData.getShortHostname();
    String subnetId = instanceMetaData == null ? null : instanceMetaData.getSubnetId();
    InstanceTemplate instanceTemplate = buildInstanceTemplate(template, name, privateId, status);
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
    Map<String, Object> params = new HashMap<>();
    if (hostName != null) {
        params.put(CloudInstance.DISCOVERY_NAME, hostName);
    }
    if (subnetId != null) {
        params.put(CloudInstance.SUBNET_ID, subnetId);
    }
    return new CloudInstance(id, instanceTemplate, instanceAuthentication, params);
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 35 with CloudInstance

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

the class StackToCloudStackConverter method buildInstances.

public List<CloudInstance> buildInstances(Stack stack) {
    List<Group> groups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), Collections.emptySet());
    List<CloudInstance> cloudInstances = new ArrayList<>();
    for (Group group : groups) {
        cloudInstances.addAll(group.getInstances());
    }
    return cloudInstances;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

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