use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus 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.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus 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.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method removeUnusedParcels.
@Test
void removeUnusedParcels() {
// GIVEN
Set<String> parcelNamesFromImage = new HashSet<>();
ClouderaManagerProduct cmProduct1 = createClouderaManagerProduct("product1", "version1");
ClouderaManagerProduct cmProduct2 = createClouderaManagerProduct("product2", "version2");
Set<ClusterComponent> usedComponents = Set.of(createClusterComponent(cmProduct1), createClusterComponent(cmProduct2));
Set<String> usedParcelComponentNames = Set.of(cmProduct1.getName(), cmProduct2.getName());
when(clouderaManagerApiFactory.getParcelsResourceApi(apiClientMock)).thenReturn(parcelsResourceApi);
when(clouderaManagerApiFactory.getParcelResourceApi(apiClientMock)).thenReturn(parcelResourceApi);
when(clouderaManagerParcelDecommissionService.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, STACK_NAME, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("product3", "version3"), Map.of()));
when(clouderaManagerParcelDecommissionService.undistributeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("product3", "version3"), Map.of()));
when(clouderaManagerParcelDecommissionService.removeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("product3", "version3"), Map.of()));
// WHEN
ParcelOperationStatus operationStatus = underTest.removeUnusedParcels(usedComponents, parcelNamesFromImage);
// THEN
verify(clouderaManagerParcelDecommissionService).deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, stack.getName(), usedParcelComponentNames, parcelNamesFromImage);
verify(clouderaManagerParcelDecommissionService).undistributeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage);
verify(clouderaManagerParcelDecommissionService).removeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage);
assertEquals(1, operationStatus.getSuccessful().size());
assertEquals(0, operationStatus.getFailed().size());
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method removeUnusedParcelsWhenSomeParcelOperationsFail.
@Test
void removeUnusedParcelsWhenSomeParcelOperationsFail() {
// GIVEN
Set<String> parcelNamesFromImage = new HashSet<>();
ClouderaManagerProduct cmProduct1 = createClouderaManagerProduct("product1", "version1");
ClouderaManagerProduct cmProduct2 = createClouderaManagerProduct("product2", "version2");
Set<ClusterComponent> usedComponents = Set.of(createClusterComponent(cmProduct1), createClusterComponent(cmProduct2));
Set<String> usedParcelComponentNames = Set.of(cmProduct1.getName(), cmProduct2.getName());
when(clouderaManagerApiFactory.getParcelsResourceApi(apiClientMock)).thenReturn(parcelsResourceApi);
when(clouderaManagerApiFactory.getParcelResourceApi(apiClientMock)).thenReturn(parcelResourceApi);
when(clouderaManagerParcelDecommissionService.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, STACK_NAME, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("spark3", "version3", "product5", "version5"), Map.of("product4", "version4")));
when(clouderaManagerParcelDecommissionService.undistributeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("product5", "version5"), Map.of("spark3", "version3")));
when(clouderaManagerParcelDecommissionService.removeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage)).thenReturn(new ParcelOperationStatus(Map.of("product5", "version5"), Map.of()));
// WHEN
ParcelOperationStatus operationStatus = underTest.removeUnusedParcels(usedComponents, parcelNamesFromImage);
// THEN
verify(clouderaManagerParcelDecommissionService, times(1)).deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, stack.getName(), usedParcelComponentNames, parcelNamesFromImage);
verify(clouderaManagerParcelDecommissionService, times(1)).undistributeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage);
verify(clouderaManagerParcelDecommissionService, times(1)).removeUnusedParcels(apiClientMock, parcelsResourceApi, parcelResourceApi, stack, usedParcelComponentNames, parcelNamesFromImage);
assertEquals(1, operationStatus.getSuccessful().size());
assertTrue(operationStatus.getSuccessful().containsEntry("product5", "version5"));
assertEquals(2, operationStatus.getFailed().size());
assertTrue(operationStatus.getFailed().containsEntry("spark3", "version3"));
assertTrue(operationStatus.getFailed().containsEntry("product4", "version4"));
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus 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