Search in sources :

Example 6 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testRotateHostCertificates.

@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteSucceededDataProvider")
public void testRotateHostCertificates(String testCaseName, String subAltName) throws Exception {
    // GIVEN
    initTestInput("user");
    when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
    when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
    ApiHostList hostList = createApiHostList();
    when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
    ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(createApiBatchResponse(hostList, true));
    when(clouderaManagerPollingServiceProvider.startPollingCommandList(eq(stack), eq(apiClient), any(List.class), eq("Rotate host certificates"))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build());
    // WHEN
    underTest.rotateHostCertificates(null, null, subAltName);
    // THEN no exception
    verifyBatchRequest(batchRequestArgumentCaptor.getValue(), subAltName, "/api/v31/hosts/host-1/commands/generateHostCerts", "/api/v31/hosts/host%40company.com%202/commands/generateHostCerts");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenPollingCancelled.

@Test
public void testRotateHostCertificatesWhenPollingCancelled() throws Exception {
    // GIVEN
    initTestInput("user");
    when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
    when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
    ApiHostList hostList = createApiHostList();
    when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
    ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(createApiBatchResponse(hostList, true));
    when(clouderaManagerPollingServiceProvider.startPollingCommandList(eq(stack), eq(apiClient), any(List.class), eq("Rotate host certificates"))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().exit().build());
    // WHEN
    CancellationException exception = assertThrows(CancellationException.class, () -> underTest.rotateHostCertificates(null, null, null));
    // THEN exception
    assertThat(exception).hasMessage("Cluster was terminated during rotation of host certificates");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenBatchExecuteFailed.

@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteFailedDataProvider")
public void testRotateHostCertificatesWhenBatchExecuteFailed(String testCaseName, Function<ApiHostList, ApiBatchResponse> batchResponseFactory) throws Exception {
    // GIVEN
    initTestInput("user");
    when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
    when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
    ApiHostList hostList = createApiHostList();
    when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
    ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(batchResponseFactory.apply(hostList));
    // WHEN
    ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.rotateHostCertificates(null, null, null));
    // THEN exception
    assertThat(exception).hasMessageStartingWith("Host certificates rotation batch operation failed: ");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost.

@Test
void upscaleClusterTestWhenRackIdUpdatedForOutdatedClusterHostAndUpscaledHost() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpDeployClientConfigPolling(success);
    setUpBatchSuccess();
    BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
    when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
    when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(HOST_GROUP_NAME);
    InstanceMetaData instanceMetaDataOriginal = new InstanceMetaData();
    instanceMetaDataOriginal.setDiscoveryFQDN("original");
    instanceMetaDataOriginal.setRackId("/originalRack");
    instanceMetaDataOriginal.setInstanceGroup(instanceGroup);
    InstanceMetaData instanceMetaDataUpscaled = new InstanceMetaData();
    instanceMetaDataUpscaled.setDiscoveryFQDN("upscaled");
    instanceMetaDataUpscaled.setRackId("/upscaledRack");
    instanceMetaDataUpscaled.setInstanceGroup(instanceGroup);
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaDataOriginal, instanceMetaDataUpscaled);
    List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    assertThat(result).containsOnly("original", "upscaled");
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
    assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi, times(2)).execute(batchRequestCaptor.capture());
    List<ApiBatchRequest> batchRequests = batchRequestCaptor.getAllValues();
    assertThat(batchRequests).hasSize(2);
    verifyRackIdBatch(batchRequests.get(0), "originalId", "/originalRack");
    verifyRackIdBatch(batchRequests.get(1), "upscaledId", "/upscaledRack");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 10 with ApiBatchRequest

use of com.cloudera.api.swagger.model.ApiBatchRequest in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdNotUpdatedForClusterHostButSetForUpscaledHost.

@Test
void upscaleClusterTestWhenRackIdNotUpdatedForClusterHostButSetForUpscaledHost() throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true, "/originalRack");
    setUpDeployClientConfigPolling(success);
    setUpBatchSuccess();
    BigDecimal applyHostTemplateCommandId = new BigDecimal(200);
    when(hostTemplatesResourceApi.applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), any(ApiHostRefList.class))).thenReturn(new ApiCommand().id(applyHostTemplateCommandId));
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(eq(apiClientMock))).thenReturn(hostTemplatesResourceApi);
    when(clouderaManagerPollingServiceProvider.startPollingCmApplyHostTemplate(eq(stack), eq(apiClientMock), eq(applyHostTemplateCommandId))).thenReturn(success);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(HOST_GROUP_NAME);
    InstanceMetaData instanceMetaDataOriginal = new InstanceMetaData();
    instanceMetaDataOriginal.setDiscoveryFQDN("original");
    instanceMetaDataOriginal.setRackId("/originalRack");
    instanceMetaDataOriginal.setInstanceGroup(instanceGroup);
    InstanceMetaData instanceMetaDataUpscaled = new InstanceMetaData();
    instanceMetaDataUpscaled.setDiscoveryFQDN("upscaled");
    instanceMetaDataUpscaled.setRackId("/upscaledRack");
    instanceMetaDataUpscaled.setInstanceGroup(instanceGroup);
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaDataOriginal, instanceMetaDataUpscaled);
    List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    assertThat(result).containsOnly("upscaled", "original");
    ArgumentCaptor<ApiHostRefList> bodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(clustersResourceApi, times(1)).addHosts(eq(STACK_NAME), bodyCatcher.capture());
    verify(clouderaManagerRoleRefreshService).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    assertEquals(1, bodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", bodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiHostRefList> applyTemplateBodyCatcher = ArgumentCaptor.forClass(ApiHostRefList.class);
    verify(hostTemplatesResourceApi, times(1)).applyHostTemplate(eq(STACK_NAME), eq(HOST_GROUP_NAME), eq(Boolean.TRUE), applyTemplateBodyCatcher.capture());
    assertEquals(1, applyTemplateBodyCatcher.getValue().getItems().size());
    assertEquals("upscaled", applyTemplateBodyCatcher.getValue().getItems().get(0).getHostname());
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi).execute(batchRequestCaptor.capture());
    verifyRackIdBatch(batchRequestCaptor.getValue(), "upscaledId", "/upscaledRack");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(com.cloudera.api.swagger.client.ApiClient) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ApiBatchRequest (com.cloudera.api.swagger.model.ApiBatchRequest)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 BatchResourceApi (com.cloudera.api.swagger.BatchResourceApi)7 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)6 ApiClient (com.cloudera.api.swagger.client.ApiClient)6 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)6 Test (org.junit.jupiter.api.Test)6 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)5 ApiHostRefList (com.cloudera.api.swagger.model.ApiHostRefList)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)5 ApiBatchResponse (com.cloudera.api.swagger.model.ApiBatchResponse)4 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)4 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)4 BigDecimal (java.math.BigDecimal)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3