Search in sources :

Example 1 with DATALAKE

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.DATALAKE in project cloudbreak by hortonworks.

the class DatalakeService method addSharedServiceResponse.

public void addSharedServiceResponse(Stack stack, StackV4Response stackResponse) {
    SharedServiceV4Response sharedServiceResponse = new SharedServiceV4Response();
    if (!Strings.isNullOrEmpty(stack.getDatalakeCrn())) {
        LOGGER.debug("Checking datalake through the datalakeCrn.");
        Optional<ResourceBasicView> resourceBasicView = stackService.getResourceBasicViewByResourceCrn(stack.getDatalakeCrn());
        if (resourceBasicView.isPresent()) {
            ResourceBasicView s = resourceBasicView.get();
            sharedServiceResponse.setSharedClusterId(s.getId());
            sharedServiceResponse.setSharedClusterName(s.getName());
        } else {
            LOGGER.debug("Unable to find datalake with CRN {}", stack.getDatalakeCrn());
        }
    }
    stackResponse.setSharedService(sharedServiceResponse);
}
Also used : ResourceBasicView(com.sequenceiq.cloudbreak.common.dal.ResourceBasicView) SharedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.sharedservice.SharedServiceV4Response)

Example 2 with DATALAKE

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.DATALAKE in project cloudbreak by hortonworks.

the class ImageCatalogChangeTest method testFreeipaImageCatalogChange.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "a running Freeipa/Datalake/Datahub", when = "calling change image catalog", then = "it should have new image catalog")
public void testFreeipaImageCatalogChange(MockedTestContext testContext) {
    // Freeipa
    final String newImageCatalog = testContext.given(FreeIpaTestDto.class).getResponse().getImage().getCatalog() + "&changed=true";
    testContext.given(FreeipaChangeImageCatalogTestDto.class).withImageCatalog(newImageCatalog).when(freeIpaTestClient.changeImageCatalog()).given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getImage().getCatalog();
        if (!newImageCatalog.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Freeipa was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    });
    // Datalake
    testContext.given(SdxInternalTestDto.class).when(sdxTestClient.createInternal()).await(SdxClusterStatusResponse.RUNNING);
    final StackImageV4Response sdxImage = testContext.given(SdxInternalTestDto.class).getResponse().getStackV4Response().getImage();
    final String sdxNewImageCatalogName = createNewImageCatalog(testContext, sdxImage);
    testContext.given(SdxChangeImageCatalogTestDto.class).withImageCatalog(sdxNewImageCatalogName).when(sdxTestClient.changeImageCatalog()).given(SdxInternalTestDto.class).when(sdxTestClient.describeInternal()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getStackV4Response().getImage().getCatalogName();
        if (!sdxNewImageCatalogName.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Datalake was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    });
    // Datahub
    testContext.given(DistroXTestDto.class).when(distroXClient.create()).await(STACK_AVAILABLE);
    final StackImageV4Response distroXImage = testContext.given(DistroXTestDto.class).getResponse().getImage();
    final String distroXNewImageCatalogName = createNewImageCatalog(testContext, distroXImage);
    testContext.given(DistroXChangeImageCatalogTestDto.class).withImageCatalog(distroXNewImageCatalogName).when(distroXClient.changeImageCatalog()).given(DistroXTestDto.class).when(distroXClient.get()).then((testContext1, testDto, client) -> {
        final String actualCatalog = testDto.getResponse().getImage().getCatalogName();
        if (!distroXNewImageCatalogName.equals(actualCatalog)) {
            throw new TestFailException(String.format("Image catalog of Datahub was not changed. Catalog : %s", actualCatalog));
        }
        return testDto;
    }).validate();
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) Test(org.testng.annotations.Test) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) DistroXChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXChangeImageCatalogTestDto) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) NotNull(org.jetbrains.annotations.NotNull) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) FreeipaChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeipaChangeImageCatalogTestDto) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StackImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.StackImageV4Response) SdxChangeImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxChangeImageCatalogTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 3 with DATALAKE

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.DATALAKE 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 DATALAKE

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.DATALAKE in project cloudbreak by hortonworks.

the class SdxServiceTest method testCcmV2JumpgateVersionChecker.

@ParameterizedTest(name = "Runtime {0} is compatible with CCMv2JumpGate = {1}")
@MethodSource("ccmV2JumpgateScenarios")
void testCcmV2JumpgateVersionChecker(String runtime, boolean compatible) throws IOException {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, LIGHT_DUTY);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.10/aws/light_duty.json");
    lenient().when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.MOCK, Tunnel.CCMV2_JUMPGATE);
    if (!compatible) {
        assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null))).isInstanceOf(BadRequestException.class).hasMessage(String.format("Runtime version %s does not support Cluster Connectivity Manager. " + "Please try creating a datalake with runtime version at least %s.", runtime, CCMV2_JUMPGATE_REQUIRED_VERSION));
    } else {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    }
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with DATALAKE

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.DATALAKE in project cloudbreak by hortonworks.

the class SdxServiceTest method testDeleteSdxWhenSdxHasStoppedDataHubsShouldSucceedWhenForced.

@Test
void testDeleteSdxWhenSdxHasStoppedDataHubsShouldSucceedWhenForced() {
    SdxCluster sdxCluster = getSdxCluster();
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    when(sdxReactorFlowManager.triggerSdxDeletion(any(SdxCluster.class), anyBoolean())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    StackViewV4Response stackViewV4Response = new StackViewV4Response();
    stackViewV4Response.setName("existingDistroXCluster");
    stackViewV4Response.setStatus(Status.STOPPED);
    mockCBCallForDistroXClusters(Sets.newHashSet(stackViewV4Response));
    underTest.deleteSdx(USER_CRN, "sdx-cluster-name", true);
    verify(sdxReactorFlowManager, times(1)).triggerSdxDeletion(sdxCluster, true);
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_REQUESTED, "Datalake deletion requested", sdxCluster);
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)11 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)10 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)6 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)3 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)2 RangerRazEnabledV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response)2 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)2 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)2 UpgradeOptionV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2