use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method callPostClouderaRuntimeUpgradeCommandIfCMIsNewerThan751.
private void callPostClouderaRuntimeUpgradeCommandIfCMIsNewerThan751(ClustersResourceApi clustersResourceApi) throws ApiException, CloudbreakException {
ClouderaManagerRepo clouderaManagerRepo = clusterComponentConfigProvider.getClouderaManagerRepoDetails(stack.getCluster().getId());
String currentCMVersion = clouderaManagerRepo.getVersion();
Versioned baseCMVersion = CLOUDERAMANAGER_VERSION_7_5_1;
if (isVersionNewerOrEqualThanLimited(currentCMVersion, baseCMVersion)) {
LOGGER.debug("Cloudera Manager version {} is newer than {} hence calling post runtime upgrade command using /v45 API", currentCMVersion, baseCMVersion.getVersion());
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_UPGRADE_START_POST_UPGRADE);
waitForRestartCommandIfThereIsAny(clustersResourceApi);
Cluster cluster = stack.getCluster();
String user = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
try {
ApiClient v45Client = clouderaManagerApiClientProvider.getV45Client(stack.getGatewayPort(), user, password, clientConfig);
ClustersResourceApi clustersResourceV45Api = clouderaManagerApiFactory.getClustersResourceApi(v45Client);
clouderaManagerUpgradeService.callPostRuntimeUpgradeCommand(clustersResourceV45Api, stack, v45Client);
} catch (ClouderaManagerClientInitException e) {
LOGGER.info("Couldn't build CM v45 client", e);
throw new CloudbreakException(e);
}
} else {
LOGGER.debug("Cloudera Manager version {} is older than {} hence NOT calling post runtime upgrade command", currentCMVersion, baseCMVersion.getVersion());
}
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method deleteHostFromClouderaManager.
private void deleteHostFromClouderaManager(Stack stack, InstanceMetaData data, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
Optional<ApiHost> hostRefOptional = hostRefList.getItems().stream().filter(host -> data.getDiscoveryFQDN() != null && data.getDiscoveryFQDN().equals(host.getHostname())).findFirst();
if (hostRefOptional.isPresent()) {
ApiHost hostRef = hostRefOptional.get();
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
clustersResourceApi.removeHost(stack.getName(), hostRef.getHostId());
hostsResourceApi.deleteHost(hostRef.getHostId());
LOGGER.debug("Host remove request sent. Host id: [{}]", hostRef.getHostId());
} else {
LOGGER.debug("Host already deleted.");
}
} catch (ApiException e) {
LOGGER.error("Failed to delete host: {}", data.getDiscoveryFQDN(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerKerberosService method configureKerberosViaApi.
public void configureKerberosViaApi(ApiClient client, HttpClientConfig clientConfig, Stack stack, KerberosConfig kerberosConfig) throws ApiException, CloudbreakException {
Cluster cluster = stack.getCluster();
if (kerberosDetailService.isAdJoinable(kerberosConfig) || kerberosDetailService.isIpaJoinable(kerberosConfig)) {
ClouderaManagerModificationService modificationService = applicationContext.getBean(ClouderaManagerModificationService.class, stack, clientConfig);
ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
modificationService.stopCluster(false);
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
ApiCommand configureForKerberos = clustersResourceApi.configureForKerberos(cluster.getName(), new ApiConfigureForKerberosArguments());
clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, configureForKerberos.getId());
ApiCommand generateCredentials = clouderaManagerResourceApi.generateCredentialsCommand();
clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, generateCredentials.getId());
List<ApiCommand> commands = clustersResourceApi.listActiveCommands(stack.getName(), SUMMARY).getItems();
BigDecimal deployClusterConfigId = clouderaManagerCommonCommandService.getDeployClientConfigCommandId(stack, clustersResourceApi, commands);
clouderaManagerPollingServiceProvider.startPollingCmKerberosJob(stack, client, deployClusterConfigId);
modificationService.startCluster();
}
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClusterStatusService method findCommand.
@Override
public Optional<ClusterManagerCommand> findCommand(Stack stack, ClusterCommandType command) {
try {
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(client);
ClouderaManagerCommand clouderaManagerCommand = ClouderaManagerCommand.ofType(command);
if (clouderaManagerCommand == null) {
return Optional.empty();
}
Optional<BigDecimal> commandId = syncApiCommandRetriever.getCommandId(clouderaManagerCommand.getName(), clustersResourceApi, stack);
if (commandId.isPresent()) {
return Optional.ofNullable(convertApiCommand(clouderaManagerCommandsService.getApiCommand(client, commandId.get())));
} else {
LOGGER.info("Command {} could not been found in CM for stack {}", command, stack.getName());
return Optional.empty();
}
} catch (CloudbreakException | ApiException e) {
LOGGER.warn("Unexpected error during CM command table fetching, assuming no such command exists", e);
return Optional.empty();
}
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSetupServiceTest method testInstallClusterWhenApiExceptionOccursShouldReturnClouderaManagerOperationFailedException.
@Test
public void testInstallClusterWhenApiExceptionOccursShouldReturnClouderaManagerOperationFailedException() throws ApiException {
ClustersResourceApi clustersResourceApi = mock(ClustersResourceApi.class);
ApiException error = mock(ApiException.class);
when(error.getResponseBody()).thenReturn(null);
when(error.getMessage()).thenReturn("error");
when(clouderaManagerApiFactory.getClustersResourceApi(any(ApiClient.class))).thenReturn(clustersResourceApi);
doThrow(error).when(clustersResourceApi).readCluster(anyString());
ClouderaManagerOperationFailedException actual = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.installCluster(""));
assertEquals(ClouderaManagerOperationFailedException.class, actual.getClass());
}
Aggregations