Search in sources :

Example 36 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class NetworkUtils method getPorts.

public static List<Port> getPorts(Optional<Stack> stack) {
    List<Port> result = new ArrayList<>();
    if (stack.isPresent()) {
        Stack stackInstance = stack.get();
        List<EndpointRule> aclRules = createACLRules(stackInstance);
        for (InstanceGroup instanceGroup : stackInstance.getInstanceGroups()) {
            for (SecurityRule rule : instanceGroup.getSecurityGroup().getSecurityRules()) {
                for (String portNumber : rule.getPorts()) {
                    Port port = getPortByPortNumberAndProtocol(portNumber, rule.getProtocol());
                    if (port != null) {
                        result.add(new Port(port.getExposedService(), portNumber, portNumber, rule.getProtocol(), aclRules));
                    }
                }
            }
        }
    } else {
        result.addAll(PORTS);
    }
    return result;
}
Also used : Port(com.sequenceiq.cloudbreak.api.model.Port) EndpointRule(com.sequenceiq.cloudbreak.api.model.EndpointRule) ArrayList(java.util.ArrayList) SecurityRule(com.sequenceiq.cloudbreak.domain.SecurityRule) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 37 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class ClusterRepairFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public Queue<Selectable> createFlowTriggerEventQueue(ClusterRepairTriggerEvent event) {
    StackView stackView = stackService.getByIdView(event.getStackId());
    Queue<Selectable> flowChainTriggers = new ConcurrentLinkedDeque<>();
    Map<String, List<String>> failedNodesMap = event.getFailedNodesMap();
    for (Entry<String, List<String>> failedNodes : failedNodesMap.entrySet()) {
        String hostGroupName = failedNodes.getKey();
        List<String> hostNames = failedNodes.getValue();
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stackView.getClusterView().getId(), hostGroupName);
        InstanceGroup instanceGroup = hostGroup.getConstraint().getInstanceGroup();
        if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
            List<InstanceMetaData> primary = instanceMetadataRepository.findAllByInstanceGroup(instanceGroup).stream().filter(imd -> hostNames.contains(imd.getDiscoveryFQDN()) && imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).collect(Collectors.toList());
            if (!primary.isEmpty()) {
                flowChainTriggers.add(new ChangePrimaryGatewayTriggerEvent(ChangePrimaryGatewayEvent.CHANGE_PRIMARY_GATEWAY_TRIGGER_EVENT.event(), event.getStackId(), event.accepted()));
            }
        }
        flowChainTriggers.add(new ClusterAndStackDownscaleTriggerEvent(FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, new HashSet<>(hostNames), ScalingType.DOWNSCALE_TOGETHER, event.accepted()));
        if (!event.isRemoveOnly()) {
            flowChainTriggers.add(new StackAndClusterUpscaleTriggerEvent(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, hostNames.size(), ScalingType.UPSCALE_TOGETHER, Sets.newHashSet(hostNames)));
            // we need to update all ephemeral clusters that are connected to a datalake
            if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()) && !stackService.findClustersConnectedToDatalake(event.getStackId()).isEmpty()) {
                flowChainTriggers.add(new EphemeralClustersUpgradeTriggerEvent(FlowChainTriggers.EPHEMERAL_CLUSTERS_UPDATE_TRIGGER_EVENT, event.getStackId(), event.accepted()));
            }
        }
    }
    return flowChainTriggers;
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) LoggerFactory(org.slf4j.LoggerFactory) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterRepairTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterRepairTriggerEvent) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) ChangePrimaryGatewayTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ChangePrimaryGatewayTriggerEvent) ChangePrimaryGatewayEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.repair.ChangePrimaryGatewayEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) Collectors(java.util.stream.Collectors) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Sets(com.google.common.collect.Sets) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) List(java.util.List) Component(org.springframework.stereotype.Component) ScalingType(com.sequenceiq.cloudbreak.common.type.ScalingType) Entry(java.util.Map.Entry) EphemeralClustersUpgradeTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.EphemeralClustersUpgradeTriggerEvent) Queue(java.util.Queue) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) EphemeralClustersUpgradeTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.EphemeralClustersUpgradeTriggerEvent) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ChangePrimaryGatewayTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ChangePrimaryGatewayTriggerEvent) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) List(java.util.List) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) HashSet(java.util.HashSet)

Example 38 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class ServiceTestUtils method createStack.

public static Stack createStack(String owner, String account, Template template, Credential credential, Cluster cluster, Set<Resource> resources) {
    Template template1 = createTemplate(AWS);
    Template template2 = createTemplate(AWS);
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    InstanceGroup instanceGroup1 = new InstanceGroup();
    instanceGroup1.setNodeCount(2);
    instanceGroup1.setGroupName("master");
    instanceGroup1.setTemplate(template1);
    instanceGroups.add(instanceGroup1);
    InstanceGroup instanceGroup2 = new InstanceGroup();
    instanceGroup2.setNodeCount(2);
    instanceGroup2.setGroupName("slave_1");
    instanceGroup2.setTemplate(template2);
    instanceGroups.add(instanceGroup2);
    Stack stack = new Stack();
    stack.setCredential(credential);
    stack.setRegion("EU_WEST_1");
    stack.setOwner(owner);
    stack.setAccount(account);
    stack.setStackStatus(new StackStatus(stack, Status.REQUESTED, "", DetailedStackStatus.PROVISION_REQUESTED));
    stack.setInstanceGroups(instanceGroups);
    stack.setCluster(cluster);
    stack.setPublicInAccount(true);
    stack.setResources(resources);
    return stack;
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 39 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class AccountPreferencesValidatorTest method testValidateShouldThrowExceptionWhenTheStackContainsNotAllowedInstanceTypes.

@Test
public void testValidateShouldThrowExceptionWhenTheStackContainsNotAllowedInstanceTypes() throws AccountPreferencesValidationException {
    String n1St4Type = "n1-standard-4";
    List<String> allowedInstanceTypes = Arrays.asList(n1St4Type, "n1-standard-8", "n1-standard-16");
    when(preferences.getAllowedInstanceTypes()).thenReturn(allowedInstanceTypes);
    InstanceGroup cbgateway = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    InstanceGroup master = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    InstanceGroup slave = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
    when(cbgateway.getTemplate().getInstanceType()).thenReturn(n1St4Type);
    when(master.getTemplate().getInstanceType()).thenReturn(n1St4Type);
    when(slave.getTemplate().getInstanceType()).thenReturn("n1-standard-32");
    when(stack.getInstanceGroups()).thenReturn(Sets.newHashSet(cbgateway, master, slave));
    thrown.expect(AccountPreferencesValidationException.class);
    thrown.expectMessage("The 'n1-standard-32' instance type isn't allowed within the account!");
    underTest.validate(stack, EMPTY_STRING, EMPTY_STRING);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 40 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.

the class InstanceGroupMetadataCollectorTest method testCollectFqdnsWhenMetadataAvailable.

@Test
public void testCollectFqdnsWhenMetadataAvailable() {
    Stack stack = TestUtil.stack();
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        when(instanceMetadataRepository.findAliveInstancesInInstanceGroup(instanceGroup.getId())).thenReturn(Lists.newArrayList(instanceGroup.getInstanceMetaData().iterator()));
    }
    Map<String, List<InstanceMetaData>> stringListMap = underTest.collectMetadata(stack);
    Assert.assertEquals(3, stringListMap.size());
    Assert.assertTrue(stringListMap.keySet().containsAll(Sets.newHashSet("is1", "is2", "is3")));
    verify(instanceMetadataRepository, times(3)).findAliveInstancesInInstanceGroup(anyLong());
}
Also used : List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

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