Search in sources :

Example 11 with ParcelOperationStatus

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

Example 12 with ParcelOperationStatus

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

Example 13 with ParcelOperationStatus

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());
}
Also used : ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 14 with ParcelOperationStatus

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"));
}
Also used : ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 15 with ParcelOperationStatus

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"));
}
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) ApiException(com.cloudera.api.swagger.client.ApiException) 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