use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.
the class ClusterUpscaleService method installServicesOnNewHosts.
public void installServicesOnNewHosts(Long stackId, Set<String> hostGroupNames, Boolean repair, Boolean restartServices) throws CloudbreakException {
Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
LOGGER.debug("Start installing CM services");
removeUnusedParcelComponents(stack);
Set<HostGroup> hostGroupSetWithRecipes = hostGroupService.getByClusterWithRecipes(stack.getCluster().getId());
Set<HostGroup> hostGroupSetWithInstanceMetadas = hostGroupService.getByCluster(stack.getCluster().getId());
Map<HostGroup, Set<InstanceMetaData>> instanceMetaDatasByHostGroup = hostGroupSetWithInstanceMetadas.stream().filter(hostGroup -> hostGroupNames.contains(hostGroup.getName())).collect(Collectors.toMap(Function.identity(), hostGroup -> hostGroup.getInstanceGroup().getRunningInstanceMetaDataSet()));
recipeEngine.executePostAmbariStartRecipes(stack, hostGroupSetWithRecipes);
Set<InstanceMetaData> runningInstanceMetaDataSet = hostGroupSetWithInstanceMetadas.stream().flatMap(hostGroup -> hostGroup.getInstanceGroup().getRunningInstanceMetaDataSet().stream()).collect(Collectors.toSet());
ClusterApi connector = getClusterConnector(stack);
List<String> upscaledHosts = connector.upscaleCluster(instanceMetaDatasByHostGroup);
restartServicesIfNecessary(repair, restartServices, stack, connector);
setInstanceStatus(runningInstanceMetaDataSet, upscaledHosts);
}
use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.
the class ClusterUpscaleServiceTest method testInstallServicesOnNewHostWithRestart.
@Test
public void testInstallServicesOnNewHostWithRestart() throws CloudbreakException {
Stack stack = new Stack();
stack.setId(1L);
Cluster cluster = new Cluster();
cluster.setId(2L);
stack.setCluster(cluster);
when(stackService.getByIdWithClusterInTransaction(eq(1L))).thenReturn(stack);
ClusterApi clusterApi = mock(ClusterApi.class);
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
HostGroup hostGroup = new HostGroup();
InstanceGroup instanceGroup = new InstanceGroup();
InstanceMetaData im1 = new InstanceMetaData();
im1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
InstanceMetaData im2 = new InstanceMetaData();
im2.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
InstanceMetaData im3 = new InstanceMetaData();
im3.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
instanceGroup.setInstanceMetaData(Set.of(im1, im2, im3));
hostGroup.setInstanceGroup(instanceGroup);
when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Collections.emptyMap(), Collections.emptyMap()));
underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true);
verify(clusterApi, times(1)).upscaleCluster(any());
verify(clusterApi, times(1)).restartAll(false);
verify(parcelService).removeUnusedParcelComponents(stack);
}
Aggregations