Search in sources :

Example 1 with UpgradeOptionV4Response

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

the class UpgradeServiceTest method upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted.

@Test
public void upgradeAllowedWhenConnectedDataHubStackAndClusterStoppedOrDeleted() 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);
    StackViewV4Response datahubStack1 = new StackViewV4Response();
    datahubStack1.setStatus(Status.STOPPED);
    ClusterViewV4Response datahubCluster1 = new ClusterViewV4Response();
    datahubCluster1.setStatus(Status.STOPPED);
    datahubStack1.setCluster(datahubCluster1);
    StackViewV4Response datahubStack2 = new StackViewV4Response();
    datahubStack2.setStatus(Status.DELETE_COMPLETED);
    ClusterViewV4Response datahubCluster2 = new ClusterViewV4Response();
    datahubCluster2.setStatus(Status.DELETE_COMPLETED);
    datahubStack2.setCluster(datahubCluster2);
    StackViewV4Response datahubStack3 = new StackViewV4Response();
    datahubStack3.setStatus(Status.STOPPED);
    when(distroXV1Endpoint.list(any(), anyString())).thenReturn(new StackViewV4Responses(Set.of(datahubStack1, datahubStack2, datahubStack3)));
    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) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) ClusterViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.views.ClusterViewV4Response) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Map(java.util.Map) HashMap(java.util.HashMap) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with UpgradeOptionV4Response

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

the class UpgradeServiceTest method shouldNotAllowUpgradeIfDryRunFails.

@Test
public void shouldNotAllowUpgradeIfDryRunFails() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = getStack();
    Image image = getImage("id-1");
    when(stackService.getByNameOrCrnInWorkspace(eq(ofName), eq(WORKSPACE_ID))).thenReturn(stack);
    when(componentConfigProviderService.getImage(anyLong())).thenReturn(image);
    StatedImage currentImageFromCatalog = imageFromCatalog(true, image.getImageId());
    when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(currentImageFromCatalog);
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> repairStartResult = Result.error(RepairValidation.of(List.of("Repair cannot be performed because there is an active flow running.", "No external Database")));
    when(clusterRepairService.repairWithDryRun(1L)).thenReturn(repairStartResult);
    UpgradeOptionV4Response result = underTest.getOsUpgradeOptionByStackNameOrCrn(WORKSPACE_ID, ofName, user);
    verify(clusterRepairService).repairWithDryRun(eq(stack.getId()));
    verifyNoMoreInteractions(distroXV1Endpoint);
    verifyNoMoreInteractions(componentConfigProviderService);
    verifyNoMoreInteractions(imageService);
    assertThat(result.getUpgrade()).isEqualTo(null);
    assertThat(result.getReason()).isEqualTo("Repair cannot be performed because there is an active flow running.; No external Database");
}
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) 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)

Example 3 with UpgradeOptionV4Response

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

the class DatalakeUpgradeActions method imageChange.

@Bean(name = "DATALAKE_IMAGE_CHANGE_STATE")
public Action<?, ?> imageChange() {
    return new AbstractSdxAction<>(DatalakeImageChangeEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeImageChangeEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeImageChangeEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Start Datalake upgrade image change for {} ", payload.getResourceId());
            sdxUpgradeService.updateRuntimeVersionFromCloudbreak(payload.getResourceId());
            String catalogName = sdxUpgradeService.getCurrentImageCatalogName(payload.getResourceId());
            UpgradeOptionV4Response upgrade = new UpgradeOptionV4Response().upgrade(new ImageInfoV4Response().imageId(payload.getImageId()).imageCatalogName(catalogName));
            sdxUpgradeService.changeImage(payload.getResourceId(), upgrade);
            sendEvent(context, new DatalakeChangeImageWaitRequest(DATALAKE_IMAGE_CHANGE_IN_PROGRESS_EVENT.event(), context.getSdxId(), context.getUserId(), upgrade));
        }

        @Override
        protected Object getFailurePayload(DatalakeImageChangeEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeUpgradeFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) DatalakeImageChangeEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeImageChangeEvent) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) DatalakeChangeImageWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 4 with UpgradeOptionV4Response

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

the class UpgradeService method createUpgradeBaseWithCurrent.

private UpgradeOptionV4Response createUpgradeBaseWithCurrent(Image image) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image currentImage = imageCatalogService.getImage(image.getImageCatalogUrl(), image.getImageCatalogName(), image.getImageId()).getImage();
    ImageInfoV4Response currentImageInfo = new ImageInfoV4Response(image.getImageName(), image.getImageId(), image.getImageCatalogName(), currentImage.getCreated(), currentImage.getDate(), getComponentVersions(currentImage));
    UpgradeOptionV4Response response = new UpgradeOptionV4Response();
    response.setCurrent(currentImageInfo);
    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 5 with UpgradeOptionV4Response

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

the class UpgradeService method upgradeable.

private UpgradeOptionV4Response upgradeable(Image image, StatedImage latestImage, Stack stack) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    UpgradeOptionV4Response response = createUpgradeBaseWithCurrent(image);
    ImageInfoV4Response upgradeImageInfo = new ImageInfoV4Response(getImageNameForStack(stack, latestImage), latestImage.getImage().getUuid(), latestImage.getImageCatalogName(), latestImage.getImage().getCreated(), latestImage.getImage().getDate(), getComponentVersions(latestImage.getImage()));
    response.setUpgrade(upgradeImageInfo);
    LOGGER.info("Datalake upgrade option evaulation finished, image found with image id {}", response.getUpgrade().getImageId());
    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)

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