Search in sources :

Example 56 with InstanceGroup

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));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HashMap(java.util.HashMap) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 57 with InstanceGroup

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));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HashMap(java.util.HashMap) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 58 with InstanceGroup

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());
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) ResourceType(com.sequenceiq.cloudbreak.common.type.ResourceType) Matchers.anyString(org.mockito.Matchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.Test)

Example 59 with InstanceGroup

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;
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) ClusterV2Request(com.sequenceiq.cloudbreak.api.model.v2.ClusterV2Request) NetworkV2Request(com.sequenceiq.cloudbreak.api.model.v2.NetworkV2Request) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 60 with InstanceGroup

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);
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)89 Test (org.junit.Test)32 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)27 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)27 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)24 HashSet (java.util.HashSet)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)8 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)6 Template (com.sequenceiq.cloudbreak.domain.Template)6 ArrayList (java.util.ArrayList)6 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)5 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5