Search in sources :

Example 6 with ImageChangeDto

use of com.sequenceiq.cloudbreak.service.image.ImageChangeDto in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method testTriggerStackImageUpdate.

@Test
public void testTriggerStackImageUpdate() {
    long stackId = 1L;
    String imageID = "imageID";
    String imageCatalogName = "imageCatalogName";
    String imageCatalogUrl = "imageCatalogUrl";
    underTest.triggerStackImageUpdate(new ImageChangeDto(stackId, imageID, imageCatalogName, imageCatalogUrl));
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(reactorNotifier).notify(eq(stackId), eq(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT), captor.capture());
    StackImageUpdateTriggerEvent event = (StackImageUpdateTriggerEvent) captor.getValue();
    assertEquals(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT, event.selector());
    assertEquals(stack.getId(), event.getResourceId());
    assertEquals(imageCatalogName, event.getImageCatalogName());
    assertEquals(imageID, event.getNewImageId());
    assertEquals(imageCatalogUrl, event.getImageCatalogUrl());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Test(org.junit.Test)

Example 7 with ImageChangeDto

use of com.sequenceiq.cloudbreak.service.image.ImageChangeDto in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.

@Test
public void shouldReturnTheNextFailureTransition() {
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setScalingAdjustment(5);
    instanceGroupAdjustment.setInstanceGroup("hostgroup");
    HostGroupAdjustmentV4Request hostGroupAdjustment = new HostGroupAdjustmentV4Request();
    hostGroupAdjustment.setHostGroup("hostgroup");
    hostGroupAdjustment.setScalingAdjustment(5);
    Map<String, Set<Long>> instanceIdsByHostgroup = new HashMap<>();
    instanceIdsByHostgroup.put("hostgroup", Collections.singleton(1L));
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, "imageid");
    when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
    when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
    underTest.triggerProvisioning(STACK_ID);
    underTest.triggerClusterInstall(STACK_ID);
    underTest.triggerClusterReInstall(STACK_ID);
    underTest.triggerStackStop(STACK_ID);
    underTest.triggerStackStart(STACK_ID);
    underTest.triggerClusterStop(STACK_ID);
    underTest.triggerClusterStart(STACK_ID);
    underTest.triggerTermination(STACK_ID);
    underTest.triggerStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStackDownscale(STACK_ID, instanceGroupAdjustment);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L, false);
    underTest.triggerStackRemoveInstances(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterUpscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterDownscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterSync(STACK_ID);
    underTest.triggerClusterSyncWithoutCheck(STACK_ID);
    underTest.triggerStackSync(STACK_ID);
    underTest.triggerFullSync(STACK_ID);
    underTest.triggerFullSyncWithoutCheck(STACK_ID);
    underTest.triggerClusterCredentialReplace(STACK_ID, "admin", "admin1");
    underTest.triggerClusterCredentialUpdate(STACK_ID, "admin1");
    underTest.triggerClusterTermination(stack, false, USER_CRN);
    underTest.triggerClusterTermination(stack, true, USER_CRN);
    underTest.triggerManualRepairFlow(STACK_ID);
    underTest.triggerStackRepairFlow(STACK_ID, new UnhealthyInstances());
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), false);
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), true, false);
    underTest.triggerStackImageUpdate(new ImageChangeDto(STACK_ID, "asdf"));
    underTest.triggerMaintenanceModeValidationFlow(STACK_ID);
    underTest.triggerClusterCertificationRenewal(STACK_ID);
    underTest.triggerDatalakeClusterUpgrade(STACK_ID, "asdf");
    underTest.triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, false, "variant");
    underTest.triggerSaltUpdate(STACK_ID);
    underTest.triggerPillarConfigurationUpdate(STACK_ID);
    underTest.triggerDatalakeDatabaseBackup(STACK_ID, null, null, true);
    underTest.triggerDatalakeDatabaseRestore(STACK_ID, null, null);
    underTest.triggerAutoTlsCertificatesRotation(STACK_ID, new CertificatesRotationV4Request());
    underTest.triggerStackLoadBalancerUpdate(STACK_ID);
    underTest.triggerSyncComponentVersionsFromCm(STACK_ID, Set.of());
    underTest.triggerDatalakeClusterRecovery(STACK_ID);
    underTest.triggerStopStartStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStopStartStackDownscale(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterServicesRestart(STACK_ID);
    underTest.triggerClusterProxyConfigReRegistration(STACK_ID);
    int count = 0;
    for (Method method : underTest.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("trigger")) {
            count++;
        }
    }
    // -3: 2 notifyWithoutCheck, 1 terminationTriggerService, 1 triggerStackRemoveInstance internal
    verify(reactorNotifier, times(count - 3)).notify(anyLong(), anyString(), any(Acceptable.class));
    verify(reactorNotifier, times(2)).notifyWithoutCheck(anyLong(), anyString(), any(Acceptable.class));
    verify(terminationTriggerService, times(1)).triggerTermination(stack, true);
    verify(terminationTriggerService, times(1)).triggerTermination(stack, false);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Method(java.lang.reflect.Method) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 8 with ImageChangeDto

use of com.sequenceiq.cloudbreak.service.image.ImageChangeDto in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWithoutTurnOffReplaceVmsParam.

@Test
public void testTriggerFlowWithoutTurnOffReplaceVmsParam() {
    // GIVEN
    UpgradeV4Request request = createRequest(true);
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(true);
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
    when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.FALSE);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
    ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
    imageInfoV4Response.setImageId("imgId");
    imageInfoV4Response.setImageCatalogName("catalogName");
    when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
    ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
    when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
    when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(true);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
    when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), anyBoolean(), anyString())).thenReturn(flowIdentifier);
    // WHEN
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    // THEN
    verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, true, true, "variant");
    assertTrue(result.isReplaceVms());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 9 with ImageChangeDto

use of com.sequenceiq.cloudbreak.service.image.ImageChangeDto in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerDistroXUpgradeShouldThrowBadRequestExceptionWhenTheOsUpgradeIsDisabledByEntitlement.

@Test
public void testTriggerDistroXUpgradeShouldThrowBadRequestExceptionWhenTheOsUpgradeIsDisabledByEntitlement() {
    UpgradeV4Request request = createRequest(false);
    request.setLockComponents(true);
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(true);
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
    when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
    ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
    imageInfoV4Response.setImageId("imgId");
    imageInfoV4Response.setImageCatalogName("catalogName");
    when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
    ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
    when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
    Assertions.assertThrows(BadRequestException.class, () -> underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test)

Example 10 with ImageChangeDto

use of com.sequenceiq.cloudbreak.service.image.ImageChangeDto in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWithoutPaywallCheck.

@Test
public void testTriggerFlowWithoutPaywallCheck() {
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
    when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
    imageInfoV4Response.setImageId("imgId");
    imageInfoV4Response.setImageCatalogName("catalogName");
    when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
    ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
    when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
    when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(LOCK_COMPONENTS);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
    when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), eq(LOCK_COMPONENTS), anyString())).thenReturn(flowIdentifier);
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    verifyNoInteractions(paywallAccessChecker);
    assertEquals(flowIdentifier, result.getFlowIdentifier());
    assertTrue(result.getReason().contains(imageInfoV4Response.getImageId()));
    StackImageChangeV4Request imageChangeV4Request = imageChangeRequestArgumentCaptor.getValue();
    assertEquals(imageInfoV4Response.getImageId(), imageChangeV4Request.getImageId());
    assertEquals(imageInfoV4Response.getImageCatalogName(), imageChangeV4Request.getImageCatalogName());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)11 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)8 Test (org.junit.jupiter.api.Test)8 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)6 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)6 JsonCMLicense (com.sequenceiq.cloudbreak.auth.JsonCMLicense)4 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)1 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)1 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)1 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 UnhealthyInstances (com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1