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));
}
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);
}
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);
}
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)));
}
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());
}
Aggregations