Search in sources :

Example 1 with ApiCommandList

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);
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Locale(java.util.Locale) Map(java.util.Map) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CLOUDERAMANAGER_VERSION_7_6_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_6_0) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) PollingResultErrorHandler(com.sequenceiq.cloudbreak.cm.polling.PollingResultErrorHandler) Set(java.util.Set) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) List(java.util.List) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ClusterModificationService(com.sequenceiq.cloudbreak.cluster.api.ClusterModificationService) ApiCallback(com.cloudera.api.swagger.client.ApiCallback) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiConfigStalenessStatus(com.cloudera.api.swagger.model.ApiConfigStalenessStatus) CLUSTER_CM_CLUSTER_SERVICES_STARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTING) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Inject(javax.inject.Inject) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) Service(org.springframework.stereotype.Service) ApiHost(com.cloudera.api.swagger.model.ApiHost) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) CLUSTER_CM_CLUSTER_SERVICES_RESTARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_RESTARTING) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) CLOUDERAMANAGER_VERSION_7_5_1(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_5_1) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT) Logger(org.slf4j.Logger) CLOUDERAMANAGER_VERSION_7_1_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_1_0) CLUSTER_CM_CLUSTER_SERVICES_STARTED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTED) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) URLUtils(com.sequenceiq.cloudbreak.util.URLUtils) ApplicationContext(org.springframework.context.ApplicationContext) Consumer(java.util.function.Consumer) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs)

Example 2 with ApiCommandList

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);
    }
}
Also used : ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) CommandResource(com.sequenceiq.cloudbreak.cm.model.CommandResource) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ApiCommandList

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));
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) InOrder(org.mockito.InOrder) ApiService(com.cloudera.api.swagger.model.ApiService) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) BigDecimal(java.math.BigDecimal) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with ApiCommandList

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());
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BeforeEach(org.junit.jupiter.api.BeforeEach) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ApiService(com.cloudera.api.swagger.model.ApiService) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) Mockito.doThrow(org.mockito.Mockito.doThrow) BigDecimal(java.math.BigDecimal) MockitoAnnotations(org.mockito.MockitoAnnotations) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) CLOUDERAMANAGER_VERSION_7_6_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_6_0) PollingResultErrorHandler(com.sequenceiq.cloudbreak.cm.polling.PollingResultErrorHandler) Set(java.util.Set) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) Mock(org.mockito.Mock) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Supplier(java.util.function.Supplier) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) CLOUDERAMANAGER_VERSION_7_5_1(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_5_1) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) InjectMocks(org.mockito.InjectMocks) CLOUDERAMANAGER_VERSION_7_1_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_1_0) Mockito.times(org.mockito.Mockito.times) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Mockito.never(org.mockito.Mockito.never) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) TestUtil(com.sequenceiq.cloudbreak.cm.util.TestUtil) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Spy(org.mockito.Spy) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CLOUDERAMANAGER_VERSION_7_4_3(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_4_3) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) MethodSource(org.junit.jupiter.params.provider.MethodSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ApiBatchResponseElement(com.cloudera.api.swagger.model.ApiBatchResponseElement) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiConfigStalenessStatus(com.cloudera.api.swagger.model.ApiConfigStalenessStatus) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) InOrder(org.mockito.InOrder) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Assertions(org.junit.jupiter.api.Assertions) Call(com.squareup.okhttp.Call) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) Collections(java.util.Collections) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BigDecimal(java.math.BigDecimal) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with ApiCommandList

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());
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ApiService(com.cloudera.api.swagger.model.ApiService) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ApiCommandList (com.cloudera.api.swagger.model.ApiCommandList)20 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)15 BigDecimal (java.math.BigDecimal)11 ApiService (com.cloudera.api.swagger.model.ApiService)10 Test (org.junit.jupiter.api.Test)9 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)7 ApiRestartClusterArgs (com.cloudera.api.swagger.model.ApiRestartClusterArgs)6 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)5 ApiHost (com.cloudera.api.swagger.model.ApiHost)4 ApiHostRefList (com.cloudera.api.swagger.model.ApiHostRefList)4 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)3 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)3 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)3 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)3 MgmtServiceResourceApi (com.cloudera.api.swagger.MgmtServiceResourceApi)3 ParcelResourceApi (com.cloudera.api.swagger.ParcelResourceApi)3 ParcelsResourceApi (com.cloudera.api.swagger.ParcelsResourceApi)3 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)3