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());
}
}
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);
}
}
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);
}
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());
}
}
Aggregations