Search in sources :

Example 1 with Orchestrator

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

the class AmbariClusterUpscaleService method upscaleAmbari.

public void upscaleAmbari(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    LOGGER.info("Start adding cluster containers");
    Orchestrator orchestrator = stack.getOrchestrator();
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
    if (orchestratorType.containerOrchestrator()) {
        Map<String, List<Container>> containers = containerRunner.addClusterContainers(stackId, hostGroupName, scalingAdjustment);
        for (Entry<String, List<Container>> containersEntry : containers.entrySet()) {
            List<String> hostNames = containersEntry.getValue().stream().map(Container::getHost).collect(Collectors.toList());
            hostsPerHostGroup.put(containersEntry.getKey(), hostNames);
        }
        clusterService.updateHostMetadata(stack.getCluster().getId(), hostsPerHostGroup, HostMetadataState.CONTAINER_RUNNING);
    } else if (orchestratorType.hostOrchestrator()) {
        Map<String, String> hosts = hostRunner.addAmbariServices(stackId, hostGroupName, scalingAdjustment);
        for (String hostName : hosts.keySet()) {
            if (!hostsPerHostGroup.keySet().contains(hostGroupName)) {
                hostsPerHostGroup.put(hostGroupName, new ArrayList<>());
            }
            hostsPerHostGroup.get(hostGroupName).add(hostName);
        }
        clusterService.updateHostMetadata(stack.getCluster().getId(), hostsPerHostGroup, HostMetadataState.SERVICES_RUNNING);
    } else {
        LOGGER.info(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
        throw new CloudbreakException(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
    }
    Set<String> allHosts = new HashSet<>();
    for (Entry<String, List<String>> hostsPerHostGroupEntry : hostsPerHostGroup.entrySet()) {
        allHosts.addAll(hostsPerHostGroupEntry.getValue());
    }
    clusterService.updateHostCountWithAdjustment(stack.getCluster().getId(), hostGroupName, allHosts.size());
    instanceMetadataService.updateInstanceStatus(stack.getInstanceGroups(), InstanceStatus.UNREGISTERED, allHosts);
    ambariClusterConnector.waitForHosts(stackService.getByIdWithLists(stackId));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with Orchestrator

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

the class AmbariClusterServiceTest method setup.

@Before
public void setup() throws CloudbreakException {
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setBlueprint(new Blueprint());
    cluster.getBlueprint().setId(1L);
    Stack stack = new Stack();
    stack.setOrchestrator(new Orchestrator());
    stack.setCluster(cluster);
    when(clusterRepository.findById(any(Long.class))).thenReturn(cluster);
    when(stackService.getByIdWithLists(any(Long.class))).thenReturn(stack);
    when(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).thenReturn(OrchestratorType.HOST);
    when(orchestratorTypeResolver.resolveType(anyString())).thenReturn(OrchestratorType.HOST);
    when(clusterComponentConfigProvider.getHDPRepo(any(Long.class))).thenReturn(new StackRepoDetails());
    when(clusterComponentConfigProvider.store(any(ClusterComponent.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, ClusterComponent.class));
    when(clusterComponentConfigProvider.getComponent(any(Long.class), any(ComponentType.class))).thenReturn(new ClusterComponent());
    when(blueprintService.get(any(Long.class))).thenReturn(cluster.getBlueprint());
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) Before(org.junit.Before)

Example 3 with Orchestrator

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

the class StackRequestToStackConverterTest method testConvertWithLoginUserName.

@Test
public void testConvertWithLoginUserName() throws CloudbreakException {
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.GATEWAY);
    // GIVEN
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
    given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
    given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
    given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
    given(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).willReturn(OrchestratorType.HOST);
    given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
    given(defaultCostTaggingService.prepareDefaultTags(any(String.class), any(String.class), anyMap(), anyString())).willReturn(new HashMap<>());
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("You can not modify the default user!");
    // WHEN
    Stack stack = underTest.convert(getRequest("stack/stack-with-loginusername.json"));
    // THEN
    assertAllFieldsNotNull(stack, Arrays.asList("description", "statusReason", "cluster", "credential", "gatewayPort", "template", "network", "securityConfig", "securityGroup", "version", "created", "platformVariant", "cloudPlatform", "saltPassword", "stackTemplate", "flexSubscription", "datalakeId", "customHostname", "customDomain", "clusterNameAsSubdomain", "hostgroupNameAsHostname", "loginUserName"));
    Assert.assertEquals("eu-west-1", stack.getRegion());
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) Matchers.anyString(org.mockito.Matchers.anyString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Test(org.junit.Test)

Example 4 with Orchestrator

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

the class StackRequestToStackConverterTest method testConvert.

@Test
public void testConvert() throws CloudbreakException {
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.GATEWAY);
    // GIVEN
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
    given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
    given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
    given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
    given(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).willReturn(OrchestratorType.HOST);
    given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
    given(defaultCostTaggingService.prepareDefaultTags(any(String.class), any(String.class), anyMap(), anyString())).willReturn(new HashMap<>());
    // WHEN
    Stack stack = underTest.convert(getRequest("stack/stack.json"));
    // THEN
    assertAllFieldsNotNull(stack, Arrays.asList("description", "statusReason", "cluster", "credential", "gatewayPort", "template", "network", "securityConfig", "securityGroup", "version", "created", "platformVariant", "cloudPlatform", "saltPassword", "stackTemplate", "flexSubscription", "datalakeId", "customHostname", "customDomain", "clusterNameAsSubdomain", "hostgroupNameAsHostname", "loginUserName", "parameters"));
    Assert.assertEquals("YARN", stack.getRegion());
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) Matchers.anyString(org.mockito.Matchers.anyString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Test(org.junit.Test)

Example 5 with Orchestrator

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

the class StackToStackResponseConverterTest method createSource.

@Override
public Stack createSource() {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster(TestUtil.blueprint(), stack, 1L);
    stack.setCluster(cluster);
    stack.setAvailabilityZone("avZone");
    Network network = new Network();
    network.setId(1L);
    stack.setNetwork(network);
    stack.setFailurePolicy(new FailurePolicy());
    Orchestrator orchestrator = new Orchestrator();
    orchestrator.setId(1L);
    orchestrator.setApiEndpoint("endpoint");
    orchestrator.setType("type");
    stack.setOrchestrator(orchestrator);
    stack.setParameters(new HashMap<>());
    stack.setCloudPlatform("OPENSTACK");
    stack.setGatewayPort(9443);
    stack.setCustomDomain("custom.domain");
    stack.setCustomHostname("hostname");
    stack.setStackAuthentication(new StackAuthentication());
    stack.getStackAuthentication().setPublicKey("rsakey");
    stack.getStackAuthentication().setLoginUserName("cloudbreak");
    stack.setHostgroupNameAsHostname(false);
    stack.setClusterNameAsSubdomain(false);
    Resource s3ArnResource = new Resource(ResourceType.S3_ACCESS_ROLE_ARN, "s3Arn", stack);
    stack.setResources(Collections.singleton(s3ArnResource));
    return stack;
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) Network(com.sequenceiq.cloudbreak.domain.Network) Resource(com.sequenceiq.cloudbreak.domain.Resource) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)20 Stack (com.sequenceiq.cloudbreak.domain.Stack)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 List (java.util.List)7 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)6 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)6 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)5 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)5 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 FailurePolicyRequest (com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest)4 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)4 OrchestratorRequest (com.sequenceiq.cloudbreak.api.model.OrchestratorRequest)4 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)4 Container (com.sequenceiq.cloudbreak.domain.Container)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)4