Search in sources :

Example 26 with ClusterApi

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);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoggerFactory(org.slf4j.LoggerFactory) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) Function(java.util.function.Function) KerberosConfigService(com.sequenceiq.cloudbreak.kerberos.KerberosConfigService) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) RecipeEngine(com.sequenceiq.cloudbreak.service.cluster.flow.recipe.RecipeEngine) Logger(org.slf4j.Logger) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) ParcelService(com.sequenceiq.cloudbreak.service.parcel.ParcelService) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Set(java.util.Set) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 27 with ClusterApi

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);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)27 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Set (java.util.Set)7 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)6 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)5 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)5 ClusterStatusService (com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)4 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)4 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Test (org.junit.jupiter.api.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Service (org.springframework.stereotype.Service)4 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)3