Search in sources :

Example 1 with ClusterCommand

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand in project cloudbreak by hortonworks.

the class ClouderaManagerSetupService method installCluster.

@Override
public void installCluster(String template) {
    Cluster cluster = stack.getCluster();
    try {
        Optional<ApiCluster> cmCluster = getCmClusterByName(cluster.getName());
        boolean prewarmed = isPrewarmed(cluster.getId());
        Optional<ClusterCommand> importCommand = clusterCommandRepository.findTopByClusterIdAndClusterCommandType(cluster.getId(), ClusterCommandType.IMPORT_CLUSTER);
        if (cmCluster.isEmpty() || importCommand.isEmpty()) {
            ApiClusterTemplate apiClusterTemplate = JsonUtil.readValue(template, ApiClusterTemplate.class);
            cluster.setExtendedBlueprintText(getExtendedBlueprintText(apiClusterTemplate));
            ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(apiClient);
            LOGGER.info("Generated Cloudera cluster template: {}", AnonymizerUtil.anonymize(template));
            // addRepositories - if true the parcels repositories in the cluster template
            // will be added.
            ApiCommand apiCommand = clouderaManagerResourceApi.importClusterTemplate(calculateAddRepositories(apiClusterTemplate, prewarmed), apiClusterTemplate);
            ClusterCommand clusterCommand = new ClusterCommand();
            clusterCommand.setClusterId(cluster.getId());
            clusterCommand.setCommandId(apiCommand.getId());
            clusterCommand.setClusterCommandType(ClusterCommandType.IMPORT_CLUSTER);
            importCommand = Optional.of(clusterCommandRepository.save(clusterCommand));
            LOGGER.debug("Cloudera cluster template has been submitted, cluster install is in progress");
        }
        importCommand.ifPresent(cmd -> clouderaManagerPollingServiceProvider.startPollingCmTemplateInstallation(stack, apiClient, cmd.getCommandId()));
    } catch (ApiException e) {
        String msg = "Installation of CDP with Cloudera Manager has failed: " + extractMessage(e);
        throw new ClouderaManagerOperationFailedException(msg, e);
    } catch (CloudStorageConfigurationFailedException e) {
        LOGGER.info("Error while configuring cloud storage. Message: {}", e.getMessage(), e);
        throw new ClouderaManagerOperationFailedException(mapStorageError(e, stack.getResourceCrn(), stack.cloudPlatform(), cluster), e);
    } catch (Exception e) {
        throw mapException(e);
    }
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ApiException(com.cloudera.api.swagger.client.ApiException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) CloudStorageConfigurationFailedException(com.sequenceiq.cloudbreak.cm.exception.CloudStorageConfigurationFailedException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) ClusterCommand(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand) CloudStorageConfigurationFailedException(com.sequenceiq.cloudbreak.cm.exception.CloudStorageConfigurationFailedException) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ClusterCommand

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testInstallClusterWhenEverythingWorksFineShouldPollTheInsallProgress.

@Test
public void testInstallClusterWhenEverythingWorksFineShouldPollTheInsallProgress() throws ApiException {
    ClustersResourceApi clustersResourceApi = mock(ClustersResourceApi.class);
    ApiCommand apiCommand = mock(ApiCommand.class);
    ApiCluster apiCluster = mock(ApiCluster.class);
    ClusterCommand clusterCommand = mock(ClusterCommand.class);
    ClouderaManagerRepo clouderaManagerRepo = new ClouderaManagerRepo();
    clouderaManagerRepo.setVersion("6.2.0");
    ClouderaManagerResourceApi clouderaManagerResourceApi = mock(ClouderaManagerResourceApi.class);
    when(clusterComponentProvider.getClouderaManagerRepoDetails(anyLong())).thenReturn(clouderaManagerRepo);
    when(clouderaManagerApiFactory.getClustersResourceApi(any(ApiClient.class))).thenReturn(clustersResourceApi);
    when(clustersResourceApi.readCluster(anyString())).thenReturn(apiCluster);
    when(clusterCommandRepository.findTopByClusterIdAndClusterCommandType(anyLong(), any(ClusterCommandType.class))).thenReturn(Optional.empty());
    when(apiCommand.getId()).thenReturn(BigDecimal.ONE);
    when(clusterCommand.getCommandId()).thenReturn(BigDecimal.ONE);
    when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any(ApiClient.class))).thenReturn(clouderaManagerResourceApi);
    when(clouderaManagerResourceApi.importClusterTemplate(anyBoolean(), any(ApiClusterTemplate.class))).thenReturn(apiCommand);
    when(clusterCommandRepository.save(any(ClusterCommand.class))).thenReturn(clusterCommand);
    when(clouderaManagerPollingServiceProvider.startPollingCmTemplateInstallation(any(Stack.class), any(ApiClient.class), any(BigDecimal.class))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().exit().build());
    underTest.installCluster("{}");
    verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmTemplateInstallation(any(Stack.class), any(ApiClient.class), any(BigDecimal.class));
    verify(clusterCommandRepository, times(1)).save(any(ClusterCommand.class));
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) ClusterCommand(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand) ClusterCommandType(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommandType) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)2 ApiCluster (com.cloudera.api.swagger.model.ApiCluster)2 ApiClusterTemplate (com.cloudera.api.swagger.model.ApiClusterTemplate)2 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)2 ClusterCommand (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommand)2 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 ClusterClientInitException (com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException)1 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)1 CloudStorageConfigurationFailedException (com.sequenceiq.cloudbreak.cm.exception.CloudStorageConfigurationFailedException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 ClusterCommandType (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommandType)1 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1