Search in sources :

Example 1 with ApiBatchRequest

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

the class ClouderaManagerModificationService method updateHostsWithRackIdUsingBatchCall.

private void updateHostsWithRackIdUsingBatchCall(List<ApiBatchRequestElement> batchRequestElements) throws ApiException {
    BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(apiClient);
    ApiBatchRequest batchRequest = new ApiBatchRequest().items(batchRequestElements);
    ApiBatchResponse batchResponse = batchResourceApi.execute(batchRequest);
    validateBatchResponse(batchResponse);
}
Also used : BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest)

Example 2 with ApiBatchRequest

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

the class ClouderaManagerModificationServiceTest method upscaleCluster.

@Test
void upscaleCluster() 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 instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("upscaled");
    instanceMetaData.setRackId("/upscaledRack");
    instanceMetaData.setInstanceGroup(instanceGroup);
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    List<String> result = underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    assertThat(result).isEqualTo(List.of("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).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)

Example 3 with ApiBatchRequest

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

the class ClouderaManagerModificationServiceTest method setUpBatchSuccess.

private void setUpBatchSuccess() throws ApiException {
    setUpBatchWithResponseAnswer(invocation -> {
        ApiBatchRequest batchRequest = invocation.getArgument(0, ApiBatchRequest.class);
        int responseItemCount = batchRequest.getItems().size();
        ApiBatchResponse batchResponse = new ApiBatchResponse().success(true).items(new ArrayList<>());
        for (int i = 0; i < responseItemCount; i++) {
            batchResponse.addItemsItem(new ApiBatchResponseElement());
        }
        return batchResponse;
    });
}
Also used : ApiBatchResponseElement(com.cloudera.api.swagger.model.ApiBatchResponseElement) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest)

Example 4 with ApiBatchRequest

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

the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenRackIdBatchExecutionFailure.

@ParameterizedTest(name = "{0}")
@MethodSource("upscaleClusterTestWhenRackIdBatchExecutionFailureDataProvider")
void upscaleClusterTestWhenRackIdBatchExecutionFailure(String testCaseName, Supplier<ApiBatchResponse> batchResponseFactory) throws Exception {
    setUpListClusterHosts();
    setUpReadHosts(true);
    setUpBatchWithResponseAnswer(invocation -> batchResponseFactory.get());
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("upscaled");
    instanceMetaData.setRackId("/upscaledRack");
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList))));
    assertThat(exception).hasMessageStartingWith("Setting rack ID for hosts batch operation failed. Response: ");
    verify(clustersResourceApi, never()).addHosts(anyString(), any(ApiHostRefList.class));
    verify(clouderaManagerRoleRefreshService, never()).refreshClusterRoles(any(ApiClient.class), any(Stack.class));
    verify(hostTemplatesResourceApi, never()).applyHostTemplate(anyString(), anyString(), anyBoolean(), any(ApiHostRefList.class));
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi).execute(batchRequestCaptor.capture());
    verifyRackIdBatch(batchRequestCaptor.getValue(), "upscaledId", "/upscaledRack");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ApiClient(com.cloudera.api.swagger.client.ApiClient) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with ApiBatchRequest

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

the class ClouderaManagerModificationServiceTest method upscaleClusterTestWhenNoHostToUpscaleButRackIdUpdatedForOutdatedClusterHost.

@Test
void upscaleClusterTestWhenNoHostToUpscaleButRackIdUpdatedForOutdatedClusterHost() throws Exception {
    setUpDeployClientConfigPolling(success);
    when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any())).thenReturn(clouderaManagerResourceApi);
    when(clouderaManagerResourceApi.refreshParcelRepos()).thenReturn(new ApiCommand().id(REFRESH_PARCEL_REPOS_ID));
    when(clouderaManagerPollingServiceProvider.startPollingCmParcelRepositoryRefresh(stack, apiClientMock, REFRESH_PARCEL_REPOS_ID)).thenReturn(success);
    setUpListClusterHosts();
    setUpReadHosts(false);
    setUpBatchSuccess();
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("original");
    instanceMetaData.setRackId("/originalRack");
    List<InstanceMetaData> instanceMetaDataList = List.of(instanceMetaData);
    underTest.upscaleCluster(Map.of(hostGroup, new LinkedHashSet<>(instanceMetaDataList)));
    verify(clustersResourceApi, never()).addHosts(anyString(), any(ApiHostRefList.class));
    verify(clouderaManagerRoleRefreshService).refreshClusterRoles(apiClientMock, stack);
    ArgumentCaptor<ApiBatchRequest> batchRequestCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
    verify(batchResourceApi).execute(batchRequestCaptor.capture());
    verifyRackIdBatch(batchRequestCaptor.getValue(), "originalId", "/originalRack");
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) LinkedHashSet(java.util.LinkedHashSet) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) 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