use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class CandidateUnhealthyInstancesSelectorTest method shouldSelectInstancesWithUnknownStatus.
@Test
public void shouldSelectInstancesWithUnknownStatus() throws CloudbreakSecuritySetupException {
Map<String, String> hostStatuses = new HashMap<>();
hostStatuses.put("ip-10-0-0-1.ec2.internal", "HEALTHY");
hostStatuses.put("ip-10-0-0-2.ec2.internal", "UNKNOWN");
hostStatuses.put("ip-10-0-0-3.ec2.internal", "HEALTHY");
hostStatuses.put("ip-10-0-0-4.ec2.internal", "UNKNOWN");
when(clusterService.getHostStatuses(stack.getId())).thenReturn(hostStatuses);
InstanceGroup slaveGroup = setupInstanceGroup(InstanceGroupType.CORE);
InstanceMetaData imd1 = setupInstanceMetaData(stack.getId(), "ip-10-0-0-2.ec2.internal", slaveGroup);
InstanceMetaData imd2 = setupInstanceMetaData(stack.getId(), "ip-10-0-0-4.ec2.internal", slaveGroup);
Set<InstanceMetaData> candidateUnhealthyInstances = undertest.selectCandidateUnhealthyInstances(stack.getId());
assertEquals(2, candidateUnhealthyInstances.size());
assertTrue(candidateUnhealthyInstances.contains(imd1));
assertTrue(candidateUnhealthyInstances.contains(imd2));
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class CandidateUnhealthyInstancesSelectorTest method shouldRemoveNonCoreGroupNodes.
@Test
public void shouldRemoveNonCoreGroupNodes() throws CloudbreakSecuritySetupException {
Map<String, String> hostStatuses = new HashMap<>();
hostStatuses.put("ip-10-0-0-1.ec2.internal", "HEALTHY");
hostStatuses.put("ip-10-0-0-2.ec2.internal", "UNKNOWN");
hostStatuses.put("ip-10-0-0-3.ec2.internal", "UNKNOWN");
hostStatuses.put("ip-10-0-0-4.ec2.internal", "UNKNOWN");
when(clusterService.getHostStatuses(stack.getId())).thenReturn(hostStatuses);
InstanceGroup slaveGroup = setupInstanceGroup(InstanceGroupType.CORE);
InstanceGroup gatewayGroup = setupInstanceGroup(InstanceGroupType.GATEWAY);
InstanceMetaData imd1 = setupInstanceMetaData(stack.getId(), "ip-10-0-0-2.ec2.internal", slaveGroup);
InstanceMetaData imd2 = setupInstanceMetaData(stack.getId(), "ip-10-0-0-4.ec2.internal", slaveGroup);
setupInstanceMetaData(stack.getId(), "ip-10-0-0-3.ec2.internal", gatewayGroup);
Set<InstanceMetaData> candidateUnhealthyInstances = undertest.selectCandidateUnhealthyInstances(stack.getId());
assertEquals(2, candidateUnhealthyInstances.size());
assertTrue(candidateUnhealthyInstances.contains(imd1));
assertTrue(candidateUnhealthyInstances.contains(imd2));
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandlerTest method clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed.
@Test
public void clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed() throws CloudbreakOrchestratorFailedException {
Stack stack = TestUtil.stack();
doNothing().when(eventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
when(orchestrator.getAvailableNodes(any(GatewayConfig.class), anySet())).thenReturn(new ArrayList<>());
when(instanceGroupRepository.save(any(InstanceGroup.class))).then(returnsFirstArg());
when(instanceMetaDataRepository.save(any(InstanceMetaData.class))).then(returnsFirstArg());
doNothing().when(resourceRepository).delete(anyLong());
when(resourceRepository.findByStackIdAndNameAndType(anyLong(), anyString(), any(ResourceType.class))).thenReturn(new Resource());
when(connector.removeInstances(any(Stack.class), anySet(), anyString())).thenReturn(new HashSet<>());
when(instanceMetaDataRepository.findNotTerminatedByPrivateAddress(anyLong(), anyString())).thenAnswer(new Answer<InstanceMetaData>() {
@Override
public InstanceMetaData answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String ip = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
if (instanceMetaData.getPrivateIp().equals(ip)) {
return instanceMetaData;
}
}
return null;
}
});
when(instanceGroupRepository.findOneByGroupNameInStack(anyLong(), anyString())).thenAnswer(new Answer<InstanceGroup>() {
@Override
public InstanceGroup answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String name = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
if (instanceMetaData.getInstanceGroup().getGroupName().equals(name)) {
InstanceGroup instanceGroup = instanceMetaData.getInstanceGroup();
instanceGroup.setNodeCount(2);
return instanceGroup;
}
}
return null;
}
});
underTest.terminateFailedNodes(null, orchestrator, TestUtil.stack(), new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false), prepareNodes(stack));
verify(eventService, times(4)).fireCloudbreakEvent(anyLong(), anyString(), anyString());
verify(instanceGroupRepository, times(3)).save(any(InstanceGroup.class));
verify(instanceMetaDataRepository, times(3)).save(any(InstanceMetaData.class));
verify(connector, times(3)).removeInstances(any(Stack.class), anySet(), anyString());
verify(resourceRepository, times(3)).findByStackIdAndNameAndType(anyLong(), anyString(), any(ResourceType.class));
verify(resourceRepository, times(3)).delete(anyLong());
verify(instanceGroupRepository, times(3)).findOneByGroupNameInStack(anyLong(), anyString());
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackToStackV2RequestConverter method convert.
@Override
public StackV2Request convert(Stack source) {
StackV2Request stackV2Request = new StackV2Request();
stackV2Request.setGeneral(getGeneralSettings("", source.getCredential().getName()));
stackV2Request.setPlacement(getPlacementSettings(source.getRegion(), source.getAvailabilityZone()));
stackV2Request.setCustomDomain(getCustomDomainSettings(source.getCustomDomain(), source.getCustomHostname(), source.isHostgroupNameAsHostname(), source.isClusterNameAsSubdomain()));
stackV2Request.setFlexId(source.getFlexSubscription() == null ? null : source.getFlexSubscription().getId());
stackV2Request.setParameters(source.getParameters());
stackV2Request.setInstanceGroups(new ArrayList<>());
stackV2Request.setStackAuthentication(getConversionService().convert(source.getStackAuthentication(), StackAuthenticationRequest.class));
stackV2Request.setNetwork(getConversionService().convert(source.getNetwork(), NetworkV2Request.class));
stackV2Request.setCluster(getConversionService().convert(source.getCluster(), ClusterV2Request.class));
for (InstanceGroup instanceGroup : source.getInstanceGroups()) {
InstanceGroupV2Request instanceGroupV2Request = getConversionService().convert(instanceGroup, InstanceGroupV2Request.class);
instanceGroupV2Request = collectInformationsFromActualHostgroup(source, instanceGroup, instanceGroupV2Request);
stackV2Request.getInstanceGroups().add(instanceGroupV2Request);
}
prepareImage(source, stackV2Request);
prepareTags(source, stackV2Request);
return stackV2Request;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
@Override
public CloudInstance convert(InstanceMetaData metaDataEnity) {
InstanceGroup group = metaDataEnity.getInstanceGroup();
Template template = metaDataEnity.getInstanceGroup().getTemplate();
StackAuthentication stackAuthentication = group.getStack().getStackAuthentication();
InstanceStatus status = getInstanceStatus(metaDataEnity);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEnity.getPrivateId(), status);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.getPublicKey(), stackAuthentication.getPublicKeyId(), stackAuthentication.getLoginUserName());
Map<String, Object> params = new HashMap<>();
params.put(CloudInstance.SUBNET_ID, metaDataEnity.getSubnetId());
return new CloudInstance(metaDataEnity.getInstanceId(), instanceTemplate, instanceAuthentication, params);
}
Aggregations