Search in sources :

Example 81 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class StackCommonServiceTest method testChangeImageInWorkspace.

@Test
public void testChangeImageInWorkspace() {
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    when(stackService.getIdByNameOrCrnInWorkspace(STACK_NAME, WORKSPACE_ID)).thenReturn(STACK_ID);
    when(stackOperationService.updateImage(any(ImageChangeDto.class))).thenReturn(new FlowIdentifier(FlowType.FLOW, "id"));
    FlowIdentifier result = underTest.changeImageInWorkspace(STACK_NAME, WORKSPACE_ID, stackImageChangeRequest);
    assertEquals(FlowType.FLOW, result.getType());
    assertEquals("id", result.getPollableId());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 82 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class ClusterCommonServiceTest method testRotateAutoTls.

@Test
public void testRotateAutoTls() {
    NameOrCrn cluster = NameOrCrn.ofName("cluster");
    Stack stack = new Stack();
    stack.setName("cluster");
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
    when(clusterOperationService.rotateAutoTlsCertificates(stack, certificatesRotationV4Request)).thenReturn(new FlowIdentifier(FlowType.FLOW, "1"));
    when(stackService.getByNameOrCrnInWorkspace(cluster, 1L)).thenReturn(stack);
    underTest.rotateAutoTlsCertificates(cluster, 1L, certificatesRotationV4Request);
    verify(clusterOperationService, times(1)).rotateAutoTlsCertificates(stack, certificatesRotationV4Request);
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 83 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxController method create.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_DATALAKE)
public SdxClusterResponse create(String name, @Valid SdxCustomClusterRequest createSdxClusterRequest) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    Pair<SdxCluster, FlowIdentifier> result = sdxService.createSdx(userCrn, name, createSdxClusterRequest);
    SdxCluster sdxCluster = result.getLeft();
    metricService.incrementMetricCounter(MetricType.CUSTOM_SDX_REQUESTED, sdxCluster);
    SdxClusterResponse sdxClusterResponse = sdxClusterConverter.sdxClusterToResponse(sdxCluster);
    sdxClusterResponse.setName(sdxCluster.getClusterName());
    sdxClusterResponse.setFlowIdentifier(result.getRight());
    return sdxClusterResponse;
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 84 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxReactorFlowManager method notify.

private FlowIdentifier notify(String selector, SdxEvent acceptable, String identifier) {
    Map<String, Object> flowTriggerUserCrnHeader = Map.of(FlowConstants.FLOW_TRIGGER_USERCRN, acceptable.getUserId());
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(flowTriggerUserCrnHeader, acceptable);
    reactor.notify(selector, event);
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for sdx cluster %s.", event.getData().getResourceId()));
        } else {
            switch(accepted.getResultType()) {
                case ALREADY_EXISTING_FLOW:
                    throw new FlowsAlreadyRunningException(String.format("Request not allowed, datalake cluster '%s' already has a running operation. " + "Running operation(s): [%s]", identifier, flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
                case RUNNING_IN_FLOW:
                    return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
                case RUNNING_IN_FLOW_CHAIN:
                    return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
                default:
                    throw new IllegalStateException("Unsupported accept result type: " + accepted.getClass());
            }
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 85 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxRecoveryServiceTest method triggerCloudbreakRecovery.

@Test
public void triggerCloudbreakRecovery() {
    Long clusterId = cluster.getId();
    doNothing().when(cloudbreakFlowService).saveLastCloudbreakFlowChainId(any(), any());
    FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "FLOW_ID_1");
    RecoveryV4Response recoveryV4Response = new RecoveryV4Response(flowId);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(clusterId)).thenReturn(cluster);
    when(ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> stackV4Endpoint.recoverClusterByNameInternal(0L, cluster.getClusterName(), ThreadBasedUserCrnProvider.getUserCrn()))).thenReturn(recoveryV4Response);
    ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> underTest.recoverCluster(clusterId));
    verify(stackV4Endpoint).recoverClusterByNameInternal(eq(0L), eq(CLUSTER_NAME), nullable(String.class));
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.RECOVERY_IN_PROGRESS, DATALAKE_RECOVERY_REQUESTED, "Recovering datalake stack", cluster);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) RecoveryV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response) Test(org.junit.jupiter.api.Test)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)150 Test (org.junit.jupiter.api.Test)55 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)15 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)14 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)10 Supplier (java.util.function.Supplier)10 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)7 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)7