Search in sources :

Example 1 with FlowsAlreadyRunningException

use of com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException in project cloudbreak by hortonworks.

the class FreeIpaFlowManager method checkFlowOperationForResource.

private FlowIdentifier checkFlowOperationForResource(Event<? extends Acceptable> event) {
    try {
        Promise<AcceptResult> acceptPromise = event.getData().accepted();
        FlowAcceptResult accepted = (FlowAcceptResult) Benchmark.checkedMeasure(() -> acceptPromise.await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS), LOGGER, "Accepting flow event took {}ms");
        if (accepted == null) {
            reactorReporter.logErrorReport();
            throw new RuntimeException("FlowAcceptResult was null. Maybe flow is under operation, request not allowed.");
        }
        switch(accepted.getResultType()) {
            case RUNNING_IN_FLOW:
                return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
            case RUNNING_IN_FLOW_CHAIN:
                return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
            case ALREADY_EXISTING_FLOW:
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, freeipa cluster already has a running operation. " + "Running operation(s): [%s]", flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
            default:
                throw new IllegalStateException("Illegal resultType: " + accepted.getResultType());
        }
    } catch (InterruptedException e) {
        reactorReporter.logErrorReport();
        throw new RuntimeException(e.getMessage());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult)

Example 2 with FlowsAlreadyRunningException

use of com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException in project cloudbreak by hortonworks.

the class ReactorNotifier method checkFlowStatus.

private FlowIdentifier checkFlowStatus(Event<? extends Acceptable> event, String identifier) {
    try {
        FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        if (accepted == null) {
            LOGGER.error("Event not accepted: {}", event);
            reactorReporter.logErrorReport();
            throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", identifier));
        }
        switch(accepted.getResultType()) {
            case ALREADY_EXISTING_FLOW:
                reactorReporter.logErrorReport();
                throw new FlowsAlreadyRunningException(String.format("Request not allowed, 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(), e);
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 3 with FlowsAlreadyRunningException

use of com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException in project cloudbreak by hortonworks.

the class ClusterOperationServiceTest method shouldNotUpdateHostMetaDataWhenRecoveryTriggerFails.

@Test
public void shouldNotUpdateHostMetaDataWhenRecoveryTriggerFails() {
    Blueprint blueprint = new Blueprint();
    blueprint.setBlueprintText("{ \"Blueprints\": { \"blueprint_name\": \"MyBlueprint\" } }");
    cluster.setBlueprint(blueprint);
    when(stackService.findByCrn(STACK_CRN)).thenReturn(stack);
    InstanceMetaData host1 = getHost("host1", "master", InstanceStatus.SERVICES_HEALTHY, InstanceGroupType.GATEWAY);
    when(instanceMetaDataService.getAllInstanceMetadataByStackId(eq(stack.getId()))).thenReturn(Set.of(host1));
    when(hostGroupService.findHostGroupsInCluster(stack.getCluster().getId())).thenReturn(Set.of(getHostGroup(host1, RecoveryMode.AUTO)));
    doThrow(new FlowsAlreadyRunningException("Flow in action")).when(flowManager).triggerClusterRepairFlow(anyLong(), anyMap(), anyBoolean());
    assertThrows(FlowsAlreadyRunningException.class, () -> {
        underTest.reportHealthChange(STACK_CRN, Map.of("host1", Optional.empty()), Set.of());
    });
    verifyNoMoreInteractions(cloudbreakMessagesService);
    verifyNoMoreInteractions(cloudbreakEventService);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Test(org.junit.jupiter.api.Test)

Example 4 with FlowsAlreadyRunningException

use of com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException 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)

Aggregations

FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)3 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)2 FlowNotAcceptedException (com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)2 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)1 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 Test (org.junit.jupiter.api.Test)1