Search in sources :

Example 1 with ApiHostRefList

use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.

the class ClouderaManagerModificationService method createUpscaledHostRefList.

private ApiHostRefList createUpscaledHostRefList(Map<String, InstanceMetaData> upscaleInstancesMap, Map<String, ApiHost> upscaleHostsMap) {
    LOGGER.debug("Creating ApiHostRefList from upscaled hosts.");
    ApiHostRefList body = new ApiHostRefList();
    upscaleHostsMap.forEach((hostname, host) -> Optional.ofNullable(upscaleInstancesMap.get(hostname)).ifPresent(instance -> {
        ApiHostRef apiHostRef = new ApiHostRef().hostname(instance.getDiscoveryFQDN()).hostId(host.getHostId());
        body.addItemsItem(apiHostRef);
    }));
    if (body.getItems() != null) {
        LOGGER.debug("Created ApiHostRefList from upscaled hosts. Host count: [{}]", body.getItems().size());
    } else {
        LOGGER.debug("Created ApiHostRefList is empty.");
    }
    return body;
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Locale(java.util.Locale) Map(java.util.Map) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CLOUDERAMANAGER_VERSION_7_6_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_6_0) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) PollingResultErrorHandler(com.sequenceiq.cloudbreak.cm.polling.PollingResultErrorHandler) Set(java.util.Set) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) List(java.util.List) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ClusterModificationService(com.sequenceiq.cloudbreak.cluster.api.ClusterModificationService) ApiCallback(com.cloudera.api.swagger.client.ApiCallback) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiConfigStalenessStatus(com.cloudera.api.swagger.model.ApiConfigStalenessStatus) CLUSTER_CM_CLUSTER_SERVICES_STARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTING) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Inject(javax.inject.Inject) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) Service(org.springframework.stereotype.Service) ApiHost(com.cloudera.api.swagger.model.ApiHost) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) CLUSTER_CM_CLUSTER_SERVICES_RESTARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_RESTARTING) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) CLOUDERAMANAGER_VERSION_7_5_1(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_5_1) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT) Logger(org.slf4j.Logger) CLOUDERAMANAGER_VERSION_7_1_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_1_0) CLUSTER_CM_CLUSTER_SERVICES_STARTED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTED) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) URLUtils(com.sequenceiq.cloudbreak.util.URLUtils) ApplicationContext(org.springframework.context.ApplicationContext) Consumer(java.util.function.Consumer) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef)

Example 2 with ApiHostRefList

use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleCluster.

@Test
void upscaleCluster() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpDeployClientConfigPolling(success);
    setUpBatchSuccess();
    BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
    when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
    when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(HOST_GROUP_NAME);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("upscaled");
    instanceMetaData.setRackId("/upscaledRack");
    instanceMetaData.setInstanceGroup(instanceGroup);
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    assertThat(result).isEqualTo(List.of("upscaled"));
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
    assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi).execute(batchRequestCaptor.capture());
    verifyRackIdBatch(batchRequestCaptor.getValue(), "upscaledId", "/upscaledRack");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with ApiHostRefList

use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleClusterTerminationOnDeployConfig.

@Test
void upscaleClusterTerminationOnDeployConfig() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpDeployClientConfigPolling(exit);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("upscaled");
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    String exceptionMessage = "Cluster was terminated while waiting for config deploy";
    doThrow(new CancellationException(exceptionMessage)).when(pollingResultErrorHandler).handlePollingResult(eq(exit), any(), any());
    CancellationException exception = assertThrows(CancellationException.class, () -> underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList))));
    assertEquals(exceptionMessage, exception.getMessage());
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    verify(clouderaManagerRoleRefreshService, never()).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    verify(clouderaManagerApiFactory, never()).getBatchResourceApi(any(ApiClient.class));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with ApiHostRefList

use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleClusterTimeoutOnDeployConfig.

@Test
void upscaleClusterTimeoutOnDeployConfig() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpDeployClientConfigPolling(timeout);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("upscaled");
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    String exceptionMessage = "Timeout while Cloudera Manager was config deploying services.";
    doThrow(new CloudbreakException(exceptionMessage)).when(pollingResultErrorHandler).handlePollingResult(eq(timeout), any(), any());
    CloudbreakException exception = assertThrows(CloudbreakException.class, () -> underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList))));
    assertEquals(exceptionMessage, exception.getMessage());
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    verify(clouderaManagerRoleRefreshService, never()).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    verify(clouderaManagerApiFactory, never()).getBatchResourceApi(any(ApiClient.class));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with ApiHostRefList

use of com.cloudera.api.swagger.model.ApiHostRefList in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost.

@Test
void upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpDeployClientConfigPolling(success);
    setUpBatchSuccess();
    BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
    when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
    when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(HOST_GROUP_NAME);
    InstanceMetaData instanceMetaDataOriginal = new InstanceMetaData();
    instanceMetaDataOriginal.setDiscoveryFQDN("original");
    instanceMetaDataOriginal.setRackId("/originalRack");
    instanceMetaDataOriginal.setInstanceGroup(instanceGroup);
    InstanceMetaData instanceMetaDataUpscaled = new InstanceMetaData();
    instanceMetaDataUpscaled.setDiscoveryFQDN("upscaled");
    instanceMetaDataUpscaled.setRackId("/upscaledRack");
    instanceMetaDataUpscaled.setInstanceGroup(instanceGroup);
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaDataOriginal, instanceMetaDataUpscaled);
    List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    assertThat(result).containsOnly("original", "upscaled");
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
    assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi, times(2)).execute(batchRequestCaptor.capture());
    List<ApiBatchRequest> batchRequests = batchRequestCaptor.getAllValues();
    assertThat(batchRequests).hasSize(2);
    verifyRackIdBatch(batchRequests.get(0), "originalId", "/originalRack");
    verifyRackIdBatch(batchRequests.get(1), "upscaledId", "/upscaledRack");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ApiHostRefList (com.cloudera.api.swagger.model.ApiHostRefList)8 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)8 ApiClient (com.cloudera.api.swagger.client.ApiClient)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)5 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)5 BigDecimal (java.math.BigDecimal)5 ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)4 LinkedHashSet (java.util.LinkedHashSet)3 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)2 ApiException (com.cloudera.api.swagger.client.ApiException)2 ApiHost (com.cloudera.api.swagger.model.ApiHost)2 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)2 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)1 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)1 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)1