Search in sources :

Example 1 with ImageChangeDto

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

the class DistroXUpgradeService method initUpgrade.

private UpgradeV4Response initUpgrade(UpgradeV4Request request, UpgradeV4Response upgradeV4Response, NameOrCrn cluster, Long workspaceId, String userCrn) {
    ImageInfoV4Response image = imageSelector.determineImageId(request, upgradeV4Response.getUpgradeCandidates());
    ImageChangeDto imageChangeDto = createImageChangeDto(cluster, workspaceId, image);
    Stack stack = stackService.getByNameOrCrnInWorkspace(cluster, workspaceId);
    boolean lockComponents = request.getLockComponents() != null ? request.getLockComponents() : isComponentsLocked(stack, image);
    validateOsUpgradeEntitled(lockComponents, request);
    boolean replaceVms = determineReplaceVmsParam(upgradeV4Response, lockComponents, stack);
    String upgradeVariant = calculateUpgradeVariant(stack, userCrn);
    FlowIdentifier flowIdentifier = reactorFlowManager.triggerDistroXUpgrade(stack.getId(), imageChangeDto, replaceVms, lockComponents, upgradeVariant);
    UpgradeV4Response response = new UpgradeV4Response("Upgrade started with Image: " + image.getImageId(), flowIdentifier);
    response.setReplaceVms(replaceVms);
    return response;
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ImageChangeDto

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

the class StackCommonServiceTest method testCreateImageChangeDtoWithoutCatalog.

@Test
public void testCreateImageChangeDtoWithoutCatalog() {
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageId("imageId");
    when(stackService.getIdByNameOrCrnInWorkspace(STACK_NAME, WORKSPACE_ID)).thenReturn(STACK_ID);
    ImageChangeDto result = underTest.createImageChangeDto(STACK_NAME, WORKSPACE_ID, stackImageChangeRequest);
    assertEquals(STACK_ID, result.getStackId());
    assertEquals(stackImageChangeRequest.getImageId(), result.getImageId());
    assertNull(result.getImageCatalogName());
    assertNull(result.getImageCatalogUrl());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) Test(org.junit.jupiter.api.Test)

Example 3 with ImageChangeDto

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

the class StackCommonServiceTest method testCreateImageChangeDtoWithCatalog.

@Test
public void testCreateImageChangeDtoWithCatalog() {
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageCatalogName("catalog");
    stackImageChangeRequest.setImageId("imageId");
    ImageCatalog catalog = new ImageCatalog();
    catalog.setName(stackImageChangeRequest.getImageCatalogName());
    catalog.setImageCatalogUrl("catalogUrl");
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, stackImageChangeRequest.getImageCatalogName())).thenReturn(catalog);
    when(stackService.getIdByNameOrCrnInWorkspace(STACK_NAME, WORKSPACE_ID)).thenReturn(STACK_ID);
    ImageChangeDto result = underTest.createImageChangeDto(STACK_NAME, WORKSPACE_ID, stackImageChangeRequest);
    assertEquals(STACK_ID, result.getStackId());
    assertEquals(stackImageChangeRequest.getImageId(), result.getImageId());
    assertEquals(catalog.getName(), result.getImageCatalogName());
    assertEquals(catalog.getImageCatalogUrl(), result.getImageCatalogUrl());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 4 with ImageChangeDto

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

the class DistroXUpgradeServiceTest method testTriggerFlowWithPaywallCheck.

@Test
public void testTriggerFlowWithPaywallCheck() {
    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.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(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);
    verify(paywallAccessChecker).checkPaywallAccess(any(), any());
    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) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 5 with ImageChangeDto

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

the class DistroXUpgradeServiceTest method testTriggerFlowWhenReplaceVmsParamIsFalse.

@Test
public void testTriggerFlowWhenReplaceVmsParamIsFalse() {
    // GIVEN
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(false);
    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(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);
    // WHEN
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    // THEN
    verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, LOCK_COMPONENTS, "variant");
    assertFalse(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)

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