use of com.cloudera.api.swagger.model.ApiCommandList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method doRestartServicesIfNeeded.
private int doRestartServicesIfNeeded(ClustersResourceApi clustersResourceApi, boolean waitForCommandExecutionOnly) throws ApiException, CloudbreakException {
ApiCommandList apiCommandList = clustersResourceApi.listActiveCommands(stack.getName(), SUMMARY);
Optional<ApiCommand> optionalRestartCommand = apiCommandList.getItems().stream().filter(cmd -> "Restart".equals(cmd.getName())).findFirst();
ApiCommand restartCommand = null;
if (optionalRestartCommand.isPresent()) {
restartCommand = optionalRestartCommand.get();
LOGGER.debug("Restart for Cluster services is already running with id: [{}]", restartCommand.getId());
} else if (!waitForCommandExecutionOnly) {
LOGGER.info("Restarting cluster services.");
ApiRestartClusterArgs restartClusterArgs = new ApiRestartClusterArgs();
restartClusterArgs.setRedeployClientConfiguration(true);
restartCommand = clustersResourceApi.restartCommand(stack.getName(), restartClusterArgs);
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), CLUSTER_CM_CLUSTER_SERVICES_RESTARTING);
}
if (restartCommand != null) {
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClient, restartCommand.getId());
handlePollingResult(pollingResult, "Cluster was terminated while restarting services.", "Timeout happened while restarting services.");
}
return getCommandId(restartCommand);
}
use of com.cloudera.api.swagger.model.ApiCommandList in project cloudbreak by hortonworks.
the class SyncApiCommandRetriever method getCommandIdFromActiveCommands.
@VisibleForTesting
BigDecimal getCommandIdFromActiveCommands(String commandName, ApiResponse<ApiCommandList> response, boolean skipActiveRunningCommand) {
LOGGER.debug("Response status code from listActiveCommands: {}", response.getStatusCode());
if (response.getStatusCode() >= ERROR_CODES_FROM) {
return null;
} else {
ApiCommandList commandList = response.getData();
List<CommandResource> commands = commandList.getItems().stream().filter(c -> c.getParent() == null).map(this::convertApiCommandToCommandResource).collect(Collectors.toList());
return getLatestCommandId(commandName, commands, "listActiveCommands", skipActiveRunningCommand);
}
}
use of com.cloudera.api.swagger.model.ApiCommandList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method testUpgradeClusterWhenPatchUpgradeAndNoPostUpgradeCommandIsAvailable.
@Test
void testUpgradeClusterWhenPatchUpgradeAndNoPostUpgradeCommandIsAvailable() throws CloudbreakException, ApiException {
TestUtil.clusterComponents(cluster);
when(clouderaManagerApiFactory.getParcelResourceApi(any())).thenReturn(parcelResourceApi);
when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi);
when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any())).thenReturn(clouderaManagerResourceApi);
when(clouderaManagerApiFactory.getMgmtServiceResourceApi(any())).thenReturn(mgmtServiceResourceApi);
when(clouderaManagerApiFactory.getServicesResourceApi(any())).thenReturn(servicesResourceApi);
BigDecimal apiCommandId = new BigDecimal(200);
// Mgmt Service restart
ApiCommandList apiCommandList = new ApiCommandList();
apiCommandList.setItems(new ArrayList<>());
when(mgmtServiceResourceApi.listActiveCommands("SUMMARY")).thenReturn(apiCommandList);
when(mgmtServiceResourceApi.restartCommand()).thenReturn(new ApiCommand().id(apiCommandId));
when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
// Start services if they are not running
ApiServiceList serviceList = new ApiServiceList();
ApiService service = new ApiService();
service.setServiceState(ApiServiceState.STOPPED);
serviceList.addItemsItem(service);
ApiCommand startCommand = mock(ApiCommand.class);
when(startCommand.getId()).thenReturn(apiCommandId);
when(servicesResourceApi.readServices(any(), any())).thenReturn(serviceList);
when(clustersResourceApi.startCommand(STACK_NAME)).thenReturn(startCommand);
// Post parcel activation
ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_4_3.getVersion());
// Restart services
when(clustersResourceApi.listActiveCommands(stack.getName(), "SUMMARY")).thenReturn(new ApiCommandList().items(List.of()));
when(clustersResourceApi.restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class))).thenReturn(new ApiCommand().id(apiCommandId));
when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
when(clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, apiClientMock)).thenReturn(success);
when(clusterComponentProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_4_3.getVersion());
underTest.upgradeClusterRuntime(cluster.getComponents(), true, Optional.empty());
verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmStartup(stack, apiClientMock);
verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmHostStatus(stack, apiClientMock);
verify(clouderaManagerParcelManagementService, times(1)).checkParcelApiAvailability(stack, apiClientMock);
verify(clouderaManagerParcelManagementService, times(1)).setParcelRepos(any(), eq(clouderaManagerResourceApi));
verify(clouderaManagerParcelManagementService, times(1)).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
verify(mgmtServiceResourceApi, times(1)).listActiveCommands("SUMMARY");
verify(mgmtServiceResourceApi, times(1)).restartCommand();
verify(clouderaManagerPollingServiceProvider, times(2)).startPollingCmServicesRestart(stack, apiClientMock, apiCommandId);
verify(clouderaManagerParcelManagementService, times(1)).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(clouderaManagerParcelManagementService, times(1)).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(clouderaManagerParcelManagementService, times(1)).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(clustersResourceApi, times(1)).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
verifyNoInteractions(clouderaManagerUpgradeService);
InOrder inOrder = Mockito.inOrder(clouderaManagerPollingServiceProvider, clouderaManagerParcelManagementService, clustersResourceApi);
inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmStartup(stack, apiClientMock);
inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmHostStatus(stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).checkParcelApiAvailability(stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).setParcelRepos(any(), eq(clouderaManagerResourceApi));
inOrder.verify(clouderaManagerParcelManagementService).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clouderaManagerParcelManagementService).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clouderaManagerParcelManagementService).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clustersResourceApi).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
}
use of com.cloudera.api.swagger.model.ApiCommandList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method testUpgradeClusterComponentIsNotPresent.
@Test
void testUpgradeClusterComponentIsNotPresent() throws ApiException {
BigDecimal apiCommandId = new BigDecimal(200);
ApiCommandList apiCommandList = new ApiCommandList();
apiCommandList.setItems(new ArrayList<>());
when(clouderaManagerApiFactory.getMgmtServiceResourceApi(any())).thenReturn(mgmtServiceResourceApi);
when(mgmtServiceResourceApi.listActiveCommands("SUMMARY")).thenReturn(apiCommandList);
when(mgmtServiceResourceApi.restartCommand()).thenReturn(new ApiCommand().id(apiCommandId));
when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
when(clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, apiClientMock)).thenReturn(success);
ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
when(clusterComponentProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_5_1.getVersion());
Set<ClusterComponent> clusterComponents = TestUtil.clusterComponentSet(cluster);
Set<ClusterComponent> clusterComponentsNoCDH = clusterComponents.stream().filter(clusterComponent -> !clusterComponent.getName().equals("CDH")).collect(Collectors.toSet());
cluster.setComponents(clusterComponentsNoCDH);
NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.upgradeClusterRuntime(clusterComponentsNoCDH, false, Optional.empty()));
Assertions.assertEquals("Runtime component not found!", exception.getMessage());
}
use of com.cloudera.api.swagger.model.ApiCommandList in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method testDeployConfigAndRefreshCMStaleServicesWhenRefreshFailAndForcedIsFalseFail.
@Test
void testDeployConfigAndRefreshCMStaleServicesWhenRefreshFailAndForcedIsFalseFail() throws ApiException {
ApiService apiService = new ApiService().configStalenessStatus(ApiConfigStalenessStatus.STALE).clientConfigStalenessStatus(ApiConfigStalenessStatus.FRESH);
List<ApiService> apiServices = List.of(apiService);
ApiServiceList apiServiceList = new ApiServiceList();
apiServiceList.setItems(apiServices);
List<ApiCommand> apiCommands = List.of(new ApiCommand().name("DeployClusterClientConfig").id(BigDecimal.ONE), new ApiCommand().name("RefreshCluster").id(BigDecimal.ONE));
ApiCommandList apiCommandList = new ApiCommandList();
apiCommandList.setItems(apiCommands);
when(clouderaManagerApiFactory.getServicesResourceApi(apiClientMock)).thenReturn(servicesResourceApi);
when(clouderaManagerCommonCommandService.getApiCommand(any(), any(), any(), any())).thenThrow(new ClouderaManagerOperationFailedException("RefreshCommand failed"));
when(servicesResourceApi.readServices("stack_name", "SUMMARY")).thenReturn(apiServiceList);
when(clustersResourceApi.listActiveCommands(stack.getName(), "SUMMARY")).thenReturn(apiCommandList);
ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.deployConfigAndRefreshCMStaleServices(clustersResourceApi, false));
assertEquals("RefreshCommand failed", exception.getMessage());
verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmClientConfigDeployment(eq(stack), eq(apiClientMock), any());
}
Aggregations