use of com.cloudera.api.swagger.model.ApiParcelList in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method testUndistributeUnusedComponentsAndUndistributionFails.
@Test
public void testUndistributeUnusedComponentsAndUndistributionFails() throws Exception {
// GIVEN
Set<String> productsFromImage = Set.of("product1", "product2", "product3");
Set<String> usedComponents = Set.of("product1", "product2");
Map<String, String> distributedParcels = Map.of("product1", "version1", "product3", "version3", "customParcel", "customParcelVersion");
ApiParcelList parcelList = createApiParcelList(distributedParcels, ParcelStatus.DISTRIBUTED);
when(parcelsResourceApi.readParcels(STACK_NAME, "summary")).thenReturn(parcelList);
when(parcelResourceApi.startRemovalOfDistributionCommand(STACK_NAME, "product3", "version3")).thenThrow(new ApiException());
Stack stack = mock(Stack.class);
when(stack.getName()).thenReturn(STACK_NAME);
when(clouderaManagerPollingServiceProvider.startPollingCmParcelStatus(eq(stack), eq(apiClient), any(), any())).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build());
// WHEN
ParcelOperationStatus operationStatus = underTest.undistributeUnusedParcels(apiClient, parcelsResourceApi, parcelResourceApi, stack, usedComponents, productsFromImage);
// THEN
verify(parcelResourceApi, times(1)).startRemovalOfDistributionCommand(STACK_NAME, "product3", "version3");
verify(parcelResourceApi, times(0)).startRemovalOfDistributionCommand(STACK_NAME, "product1", "version1");
verify(parcelResourceApi, times(0)).startRemovalOfDistributionCommand(STACK_NAME, "product2", "version2");
verifyNoMoreInteractions(parcelResourceApi);
assertEquals(0, operationStatus.getSuccessful().size());
assertEquals(1, operationStatus.getFailed().size());
assertTrue(operationStatus.getFailed().containsEntry("product3", "version3"));
}
use of com.cloudera.api.swagger.model.ApiParcelList in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method createApiParcelList.
private ApiParcelList createApiParcelList(Map<String, String> products, ParcelStatus parcelStatus) {
ApiParcelList parcelList = new ApiParcelList();
List<ApiParcel> apiParcels = products.entrySet().stream().map(entry -> createApiParcel(entry.getKey(), entry.getValue(), parcelStatus)).collect(Collectors.toList());
parcelList.setItems(apiParcels);
return parcelList;
}
use of com.cloudera.api.swagger.model.ApiParcelList in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method testDeactivateUnusedComponentsWhenDeactivationFailsOnParcel.
@Test
public void testDeactivateUnusedComponentsWhenDeactivationFailsOnParcel() throws Exception {
// GIVEN
Set<String> productsFromImage = Set.of("product1", "product2", "product3");
Set<String> usedComponents = Set.of("product1", "product2");
Map<String, String> activatedParcels = Map.of("product1", "version1", "product3", "version3", "customParcel", "customParcelVersion");
ApiParcelList parcelList = createApiParcelList(activatedParcels, ParcelStatus.ACTIVATED);
when(parcelsResourceApi.readParcels(STACK_NAME, "summary")).thenReturn(parcelList);
when(parcelResourceApi.deactivateCommand(STACK_NAME, "product3", "version3")).thenThrow(new ApiException());
// WHEN and THEN
ParcelOperationStatus operationStatus = underTest.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, STACK_NAME, usedComponents, productsFromImage);
verify(parcelResourceApi, times(1)).deactivateCommand(STACK_NAME, "product3", "version3");
verifyNoMoreInteractions(parcelResourceApi);
assertEquals(0, operationStatus.getSuccessful().size());
assertEquals(1, operationStatus.getFailed().size());
assertTrue(operationStatus.getFailed().containsEntry("product3", "version3"));
}
use of com.cloudera.api.swagger.model.ApiParcelList in project cloudbreak by hortonworks.
the class ClouderaManagerParcelActivationListenerTaskTest method checkStatusActivated.
@Test
void checkStatusActivated() throws ApiException {
when(clouderaManagerApiPojoFactory.getParcelsResourceApi(eq(apiClientMock))).thenReturn(parcelsResourcesApi);
ClouderaManagerCommandPollerObject clouderaManagerCommandPollerObject = new ClouderaManagerCommandPollerObject(stack, apiClientMock, COMMAND_ID);
ApiParcel apiParcel1 = TestUtil.apiParcel(CDH, ACTIVATED);
ApiParcel apiParcel2 = TestUtil.apiParcel(CDSW, ACTIVATED);
ApiParcelList apiParcelList = new ApiParcelList().items(List.of(apiParcel1, apiParcel2));
when(parcelsResourcesApi.readParcels(eq(STACK_NAME), eq(SUMMARY))).thenReturn(apiParcelList);
assertTrue(underTest.checkStatus(clouderaManagerCommandPollerObject));
}
use of com.cloudera.api.swagger.model.ApiParcelList in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method testRemoveUnusedComponentsWhenRemovalFails.
@Test
public void testRemoveUnusedComponentsWhenRemovalFails() throws Exception {
// GIVEN
Set<String> productsFromImage = Set.of("product1", "product2", "product3");
Set<String> usedComponents = Set.of("product1", "product2");
Map<String, String> distributedParcels = Map.of("product1", "version1", "product3", "version3", "customParcel", "customParcelVersion");
ApiParcelList parcelList = createApiParcelList(distributedParcels, ParcelStatus.DOWNLOADED);
when(parcelsResourceApi.readParcels(STACK_NAME, "summary")).thenReturn(parcelList);
Stack stack = mock(Stack.class);
when(stack.getName()).thenReturn(STACK_NAME);
when(parcelResourceApi.removeDownloadCommand(STACK_NAME, "product3", "version3")).thenThrow(new ApiException());
when(clouderaManagerPollingServiceProvider.startPollingCmParcelDelete(eq(stack), eq(apiClient), any())).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build());
// WHEN
ParcelOperationStatus operationStatus = underTest.removeUnusedParcels(apiClient, parcelsResourceApi, parcelResourceApi, stack, usedComponents, productsFromImage);
// THEN
verify(parcelResourceApi, times(1)).removeDownloadCommand(STACK_NAME, "product3", "version3");
verify(parcelResourceApi, times(0)).removeDownloadCommand(STACK_NAME, "product1", "version1");
verify(parcelResourceApi, times(0)).removeDownloadCommand(STACK_NAME, "product2", "version2");
verifyNoMoreInteractions(parcelResourceApi);
assertEquals(1, operationStatus.getFailed().size());
assertEquals(0, operationStatus.getSuccessful().size());
assertTrue(operationStatus.getFailed().containsEntry("product3", "version3"));
}
Aggregations