use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method testDeactivateUnusedComponents.
@Test
void testDeactivateUnusedComponents() 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
ParcelOperationStatus actual = underTest.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, STACK_NAME, usedComponents, productsFromImage);
// THEN
verify(parcelResourceApi, times(1)).deactivateCommand(STACK_NAME, "product3", "version3");
verify(parcelResourceApi, times(0)).deactivateCommand(STACK_NAME, "product1", "version1");
verify(parcelResourceApi, times(0)).deactivateCommand(STACK_NAME, "product2", "version2");
verifyNoMoreInteractions(parcelResourceApi);
assertEquals(1, actual.getSuccessful().size());
assertEquals(0, actual.getFailed().size());
assertTrue(actual.getSuccessful().containsEntry("product3", "version3"));
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClouderaManagerParcelDecommissionServiceTest method testRemoveUnusedComponents.
@Test
public void testRemoveUnusedComponents() 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(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(0, operationStatus.getFailed().size());
assertEquals(1, operationStatus.getSuccessful().size());
assertTrue(operationStatus.getSuccessful().containsEntry("product3", "version3"));
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClusterUpscaleServiceTest method testInstallServicesWithRepairAndServiceRestartWhenOneHostIsDecommissioned.
@Test
public void testInstallServicesWithRepairAndServiceRestartWhenOneHostIsDecommissioned() throws CloudbreakException {
HostGroup hostGroup = newHostGroup("master", newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY));
when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
when(hostGroupService.getByCluster(any())).thenReturn(Set.of(hostGroup));
when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Map.of(), Map.of()));
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
when(clusterApi.clusterCommissionService()).thenReturn(clusterCommissionService);
when(clusterStatusService.getDecommissionedHostsFromCM()).thenReturn(List.of("master-2"));
underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true, Map.of("master", Set.of("master-1", "master-2", "master-3")));
inOrder.verify(parcelService).removeUnusedParcelComponents(stack);
inOrder.verify(recipeEngine, times(1)).executePostAmbariStartRecipes(stack, Set.of(hostGroup));
inOrder.verify(clusterApi, times(1)).upscaleCluster(any());
inOrder.verify(clusterStatusService, times(1)).getDecommissionedHostsFromCM();
inOrder.verify(clusterCommissionService, times(1)).recommissionHosts(List.of("master-2"));
inOrder.verify(clusterApi, times(1)).restartAll(false);
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClusterUpscaleServiceTest method testInstallServicesShouldThrowExceptionWhenFailedToRemoveUnusedParcels.
@Test
public void testInstallServicesShouldThrowExceptionWhenFailedToRemoveUnusedParcels() throws CloudbreakException {
when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Map.of(), Map.of("parcel", "parcel")));
CloudbreakException exception = assertThrows(CloudbreakException.class, () -> underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true, new HashMap<>()));
assertEquals("Failed to remove the following parcels: {parcel=[parcel]}", exception.getMessage());
verify(parcelService).removeUnusedParcelComponents(stack);
}
use of com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus in project cloudbreak by hortonworks.
the class ClusterUpscaleServiceTest method testInstallServicesWithRepairAndServiceRestart.
@Test
public void testInstallServicesWithRepairAndServiceRestart() throws CloudbreakException {
HostGroup hostGroup = newHostGroup("master", newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY), newInstance(InstanceStatus.SERVICES_HEALTHY));
when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
when(hostGroupService.getByCluster(any())).thenReturn(Set.of(hostGroup));
when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Map.of(), Map.of()));
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
when(clusterStatusService.getDecommissionedHostsFromCM()).thenReturn(List.of());
underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true, Map.of("master", Set.of("master-1", "master-2", "master-3")));
inOrder.verify(parcelService).removeUnusedParcelComponents(stack);
inOrder.verify(recipeEngine, times(1)).executePostAmbariStartRecipes(stack, Set.of(hostGroup));
inOrder.verify(clusterApi, times(1)).upscaleCluster(any());
inOrder.verify(clusterStatusService, times(1)).getDecommissionedHostsFromCM();
inOrder.verify(clusterCommissionService, times(0)).recommissionHosts(any());
inOrder.verify(clusterApi, times(1)).restartAll(false);
}
Aggregations