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