use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClusterDecommissionServiceTest method testRestartStaleServices.
@Test
public void testRestartStaleServices() throws CloudbreakException, ApiException {
ClouderaManagerModificationService modificationService = Mockito.mock(ClouderaManagerModificationService.class);
ClustersResourceApi clustersResourceApi = Mockito.mock(ClustersResourceApi.class);
when(applicationContext.getBean(ClouderaManagerModificationService.class, stack, clientConfig)).thenReturn(modificationService);
when(clouderaManagerApiFactory.getClustersResourceApi(v31Client)).thenReturn(clustersResourceApi);
underTest.restartStaleServices(false);
verify(applicationContext).getBean(ClouderaManagerModificationService.class, stack, clientConfig);
verify(clouderaManagerApiFactory).getClustersResourceApi(v31Client);
verify(modificationService).restartStaleServices(clustersResourceApi, false);
}
use of com.cloudera.api.swagger.ClustersResourceApi 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));
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSyncApiCommandIdCheckerTask method checkStatus.
@Override
public boolean checkStatus(ClouderaManagerCommandPollerObject pollerObject) {
ApiClient apiClient = pollerObject.getApiClient();
ClustersResourceApi api = clouderaManagerApiPojoFactory.getClustersResourceApi(apiClient);
boolean result = false;
ClouderaManagerSyncCommandPollerObject castedObj = cast(pollerObject);
try {
Optional<BigDecimal> commandId = syncApiCommandRetriever.getCommandId(castedObj.getCommandName(), api, castedObj.getStack());
if (commandId.isPresent() && !commandId.get().equals(pollerObject.getId())) {
LOGGER.debug("Found a new latest command ID for {} command: {}", castedObj.getCommandName(), commandId);
result = true;
} else if (castedObj.getId() != null && castedObj.getId().equals(commandId.orElse(null))) {
LOGGER.debug("There is a valid command ID found: {}, but that is not the " + "newest command id of {}", castedObj.getId(), castedObj.getCommandName());
} else {
LOGGER.debug("Not found any new commandId yet - [recent_id: {}]", castedObj.getId());
}
} catch (ApiException | CloudbreakException e) {
LOGGER.debug(String.format("Exception during polling the newest %s command.", castedObj.getCommandName()), e);
result = false;
}
return result;
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerRangerUtil method getClusterName.
private String getClusterName(ApiClient client) throws ApiException {
ClustersResourceApi clustersResource = clouderaManagerApiFactory.getClustersResourceApi(client);
ApiClusterList clusterList = clustersResource.readClusters(null, null);
return Iterables.getOnlyElement(clusterList.getItems()).getName();
}
use of com.cloudera.api.swagger.ClustersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method upscaleCluster.
@Override
public List<String> upscaleCluster(Map<HostGroup, Set<InstanceMetaData>> instanceMetaDatasByHostGroup) throws CloudbreakException {
ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient);
Set<InstanceMetaData> instanceMetaDatas = instanceMetaDatasByHostGroup.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
try {
LOGGER.debug("Starting cluster upscale with hosts: {}.", instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.joining(", ")));
String clusterName = stack.getName();
Set<String> clusterHostnames = getClusterHostnamesFromCM(clustersResourceApi, clusterName);
List<ApiHost> hosts = getHostsFromCM();
LOGGER.debug("Processing outdated cluster hosts. Cluster hostnames from CM: {}", clusterHostnames);
setHostRackIdForOutdatedClusterHosts(instanceMetaDatas, clusterHostnames, hosts);
LOGGER.debug("Processing upscaled cluster hosts.");
Map<String, InstanceMetaData> upscaleInstancesMap = getInstancesMap(clusterHostnames, instanceMetaDatas, true);
if (!upscaleInstancesMap.isEmpty()) {
Map<String, ApiHost> upscaleHostsMap = getHostsMap(upscaleInstancesMap, hosts);
setHostRackIdBatch(upscaleInstancesMap, upscaleHostsMap);
ApiHostRefList bodyForAddHosts = createUpscaledHostRefList(upscaleInstancesMap, upscaleHostsMap);
clustersResourceApi.addHosts(clusterName, bodyForAddHosts);
activateParcels(clustersResourceApi);
for (HostGroup hostGroup : instanceMetaDatasByHostGroup.keySet()) {
ApiHostRefList bodyForApplyHostGroupRoles = getBodyForApplyHostGroupRoles(upscaleInstancesMap, upscaleHostsMap, hostGroup);
applyHostGroupRolesOnUpscaledHosts(bodyForApplyHostGroupRoles, hostGroup.getName());
}
} else {
redistributeParcelsForRecovery();
activateParcels(clustersResourceApi);
}
deployClientConfig(clustersResourceApi, stack);
clouderaManagerRoleRefreshService.refreshClusterRoles(apiClient, stack);
LOGGER.debug("Cluster upscale completed.");
return instanceMetaDatas.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).collect(Collectors.toList());
} catch (ApiException e) {
LOGGER.error(String.format("Failed to upscale. Response: %s", e.getResponseBody()), e);
throw new CloudbreakException("Failed to upscale", e);
}
}
Aggregations