Search in sources :

Example 6 with UpgradeOptionV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.

the class SdxUpgradeService method changeImage.

public void changeImage(Long id, UpgradeOptionV4Response upgradeOption) {
    SdxCluster cluster = sdxService.getById(id);
    String targetImageId = upgradeOption.getUpgrade().getImageId();
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageId(targetImageId);
    stackImageChangeRequest.setImageCatalogName(upgradeOption.getUpgrade().getImageCatalogName());
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CHANGE_IMAGE_IN_PROGRESS, "Changing image", cluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageInternal(0L, cluster.getClusterName(), stackImageChangeRequest, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack change image failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 7 with UpgradeOptionV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.

the class UpgradeService method getUpgradeOption.

private UpgradeOptionV4Response getUpgradeOption(Stack stack, Long workspaceId, User user) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Image image = componentConfigProviderService.getImage(stack.getId());
    UpgradeOptionV4Response upgradeResponse;
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairResult = clusterRepairService.repairWithDryRun(stack.getId());
    if (repairResult.isSuccess()) {
        StatedImage latestImage = getLatestImage(workspaceId, stack, image, user);
        if (!isLatestImage(stack, image, latestImage)) {
            upgradeResponse = currentImageNotLatest(stack, image, latestImage);
        } else {
            upgradeResponse = notUpgradable(image, String.format("According to the image catalog, the current image %s is already the latest version.", image.getImageId()));
        }
    } else {
        upgradeResponse = notUpgradableWithValidationResult(image, repairResult.getError());
    }
    return upgradeResponse;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) HashMap(java.util.HashMap) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 8 with UpgradeOptionV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.

the class UpgradeService method notUpgradable.

private UpgradeOptionV4Response notUpgradable(Image image, String reason) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    UpgradeOptionV4Response response = createUpgradeBaseWithCurrent(image);
    response.setReason(reason);
    LOGGER.error("Datalake upgrade option evaluation finished with error, reason: {}", response.getReason());
    return response;
}
Also used : UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)

Example 9 with UpgradeOptionV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.

the class UpgradeService method upgradeableAfterAction.

private UpgradeOptionV4Response upgradeableAfterAction(Image image, StatedImage latestImage, Stack stack, String reason) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    UpgradeOptionV4Response response = notUpgradable(image, reason);
    ImageInfoV4Response upgradeImageInfo = new ImageInfoV4Response(getImageNameForStack(stack, latestImage), latestImage.getImage().getUuid(), latestImage.getImageCatalogName(), latestImage.getImage().getCreated(), latestImage.getImage().getDate(), getComponentVersions(latestImage.getImage()));
    response.setUpgrade(upgradeImageInfo);
    return response;
}
Also used : UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)

Example 10 with UpgradeOptionV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response in project cloudbreak by hortonworks.

the class UpgradeServiceTest method shouldReturnNewImageName.

@Test
public void shouldReturnNewImageName() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    setUpMocks(stack, image, true, "id-1", "id-2");
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.success(new HashMap<>());
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    ClouderaManagerRepo clouderaManagerRepo = new ClouderaManagerRepo();
    clouderaManagerRepo.setBaseUrl("cm-base-url");
    when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(1L)).thenReturn(clouderaManagerRepo);
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verify(distroXV1Endpoint).list(eq(null), eq("env-crn"));
    verify(componentConfigProviderService).getImage(1L);
    verify(imageService).determineImageFromCatalog(eq(WORKSPACE_ID), captor.capture(), eq("aws"), eq("AWS"), eq(stack.getCluster().getBlueprint()), eq(false), eq(false), eq(user), any());
    assertThat(result.getUpgrade().getImageName()).isEqualTo("id-2");
    assertThat(result.getReason()).isEqualTo(null);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UpgradeOptionV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)12 Map (java.util.Map)8 Image (com.sequenceiq.cloudbreak.cloud.model.Image)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)7 RepairValidation (com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation)7 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)7 HashMap (java.util.HashMap)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 Test (org.junit.jupiter.api.Test)6 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)4 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)3 ClusterViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response)2 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)1 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)1 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 DatalakeChangeImageWaitRequest (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest)1 DatalakeImageChangeEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeImageChangeEvent)1