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);
}
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");
}
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;
});
}
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");
}
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");
}
Aggregations