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));
}
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;
}
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;
}
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);
}
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;
}
Aggregations