Search in sources :

Example 71 with Stack

use of com.sequenceiq.cloudbreak.domain.Stack 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 72 with Stack

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

the class AmbariClusterUpscaleService method executePostRecipesOnNewHosts.

public void executePostRecipesOnNewHosts(Long stackId, String hostGroupName) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    LOGGER.info("Start executing post recipes");
    recipeEngine.executePostInstall(stack);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 73 with Stack

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

the class AmbariClusterUpscaleService method uploadRecipesOnNewHosts.

public void uploadRecipesOnNewHosts(Long stackId, String hostGroupName) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    LOGGER.info("Start executing pre recipes");
    HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName);
    Set<HostGroup> hostGroups = hostGroupService.getByCluster(stack.getCluster().getId());
    Set<HostMetadata> hostMetadata = hostGroupService.findEmptyHostMetadataInHostGroup(hostGroup.getId());
    recipeEngine.uploadUpscaleRecipes(stack, hostGroup, hostMetadata, hostGroups);
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 74 with Stack

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

the class UnhealthyInstancesDetectionHandlerTest method shouldCreateResponseWithExactInstances.

@Test
public void shouldCreateResponseWithExactInstances() throws CloudbreakSecuritySetupException {
    long stackId = 1L;
    UnhealthyInstancesDetectionRequest unhealthyInstancesDetectionRequest = new UnhealthyInstancesDetectionRequest(stackId);
    Event event = mock(Event.class);
    when(event.getData()).thenReturn(unhealthyInstancesDetectionRequest);
    Stack stack = mock(Stack.class);
    when(stackService.getById(stackId)).thenReturn(stack);
    Set<InstanceMetaData> unhealthyInstances = new HashSet<>();
    InstanceMetaData imd1 = mock(InstanceMetaData.class);
    InstanceMetaData imd2 = mock(InstanceMetaData.class);
    InstanceMetaData imd3 = mock(InstanceMetaData.class);
    unhealthyInstances.add(imd1);
    unhealthyInstances.add(imd2);
    unhealthyInstances.add(imd3);
    when(candidateUnhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId())).thenReturn(unhealthyInstances);
    Set<String> unhealthyInstanceIds = new HashSet<>();
    unhealthyInstanceIds.add("i-0f1e0605506aaaaaa");
    unhealthyInstanceIds.add("i-0f1e0605506cccccc");
    when(unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, unhealthyInstances)).thenReturn(unhealthyInstanceIds);
    unhealthyInstancesDetectionHandler.accept(event);
    verify(eventBus).notify(eq(EventSelectorUtil.selector(UnhealthyInstancesDetectionResult.class)), argThat(new UnhealthyInstancesResultMatcher(unhealthyInstanceIds)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Event(reactor.bus.Event) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with Stack

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

the class StackUpdaterTest method updateStackStatusWithoutStatusReasonThenNoNotificationSentOnWebsocket.

@Test
public void updateStackStatusWithoutStatusReasonThenNoNotificationSentOnWebsocket() {
    Stack stack = TestUtil.stack();
    DetailedStackStatus newStatus = DetailedStackStatus.DELETE_COMPLETED;
    StackStatus testStackStatus = new StackStatus(stack, newStatus.getStatus(), "", newStatus);
    when(stackStatusRepository.save(any(StackStatus.class))).thenReturn(testStackStatus);
    when(stackRepository.findOne(anyLong())).thenReturn(stack);
    when(stackRepository.save(any(Stack.class))).thenReturn(stack);
    doNothing().when(cloudbreakEventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
    when(statusToPollGroupConverter.convert(newStatus.getStatus())).thenReturn(PollGroup.POLLABLE);
    Stack newStack = underTest.updateStackStatus(1L, DetailedStackStatus.DELETE_COMPLETED);
    assertEquals(newStatus.getStatus(), newStack.getStatus());
    assertEquals("", newStack.getStatusReason());
    verify(cloudbreakEventService, times(0)).fireCloudbreakEvent(anyLong(), anyString(), anyString());
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Stack(com.sequenceiq.cloudbreak.domain.Stack) Test(org.junit.Test)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.Stack)207 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)74 Test (org.junit.Test)70 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)32 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)30 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)26 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)18 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)18 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)18 HashMap (java.util.HashMap)18 HashSet (java.util.HashSet)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Map (java.util.Map)17 Matchers.anyString (org.mockito.Matchers.anyString)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)15 Set (java.util.Set)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14