Search in sources :

Example 16 with ParcelOperationStatus

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"));
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList) Test(org.junit.jupiter.api.Test)

Example 17 with ParcelOperationStatus

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"));
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 18 with ParcelOperationStatus

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);
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 19 with ParcelOperationStatus

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);
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HashMap(java.util.HashMap) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Test(org.junit.jupiter.api.Test)

Example 20 with ParcelOperationStatus

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);
}
Also used : ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)25 Test (org.junit.jupiter.api.Test)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)15 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)8 ApiException (com.cloudera.api.swagger.client.ApiException)7 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)7 ApiParcelList (com.cloudera.api.swagger.model.ApiParcelList)6 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)5 ParcelResourceApi (com.cloudera.api.swagger.ParcelResourceApi)3 ParcelsResourceApi (com.cloudera.api.swagger.ParcelsResourceApi)3 ApiClient (com.cloudera.api.swagger.client.ApiClient)3 ApiParcel (com.cloudera.api.swagger.model.ApiParcel)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)3 Test (org.junit.Test)3 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2