Search in sources :

Example 1 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorFlowManager method triggerClusterUpscale.

public FlowIdentifier triggerClusterUpscale(Long stackId, HostGroupAdjustmentV4Request hostGroupAdjustment) {
    String selector = CLUSTER_UPSCALE_TRIGGER_EVENT.event();
    Acceptable event = new ClusterScaleTriggerEvent(selector, stackId, Collections.singletonMap(hostGroupAdjustment.getHostGroup(), hostGroupAdjustment.getScalingAdjustment()), null, null);
    return reactorNotifier.notify(stackId, selector, event);
}
Also used : ClusterScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterScaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable)

Example 2 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorFlowManager method triggerClusterDownscale.

public FlowIdentifier triggerClusterDownscale(Long stackId, HostGroupAdjustmentV4Request hostGroupAdjustment) {
    String selector = FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT;
    ScalingType scalingType = hostGroupAdjustment.getWithStackUpdate() ? ScalingType.DOWNSCALE_TOGETHER : ScalingType.DOWNSCALE_ONLY_CLUSTER;
    Acceptable event = new ClusterAndStackDownscaleTriggerEvent(selector, stackId, Collections.singletonMap(hostGroupAdjustment.getHostGroup(), hostGroupAdjustment.getScalingAdjustment()), scalingType);
    return reactorNotifier.notify(stackId, selector, event);
}
Also used : ScalingType(com.sequenceiq.cloudbreak.common.type.ScalingType) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) MultiHostgroupClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.MultiHostgroupClusterAndStackDownscaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable)

Example 3 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class ReactorNotifier method notify.

public FlowIdentifier notify(Long stackId, String selector, Acceptable acceptable, Function<Long, Stack> getStackFn) {
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(eventParameterFactory.createEventParameters(stackId), acceptable);
    Stack stack = getStackFn.apply(event.getData().getResourceId());
    Optional.ofNullable(stack).map(Stack::getStatus).ifPresent(isTriggerAllowedInMaintenance(selector));
    reactorReporter.logInfoReport();
    reactor.notify(selector, event);
    return checkFlowStatus(event, stack.getName());
}
Also used : Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 4 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class Flow2Handler method doAccept.

private void doAccept(Event<? extends Payload> event, String key, Payload payload, String flowChainId, String flowChainType, FlowParameters flowParameters) {
    try {
        if (FLOW_CANCEL.equals(key)) {
            cancelRunningFlows(payload.getResourceId());
        } else if (FLOW_FINAL.equals(key)) {
            finalizeFlow(flowParameters, flowChainId, payload.getResourceId(), getContextParams(event));
        } else if (flowParameters.getFlowId() == null) {
            AcceptResult result = handleNewFlowRequest(key, payload, flowParameters, flowChainId, flowChainType, getContextParams(event));
            LOGGER.info("Create new flow result {}", result);
            if (isAcceptablePayload(payload)) {
                ((Acceptable) payload).accepted().accept(result);
            }
        } else {
            handleFlowControlEvent(key, payload, flowParameters, flowChainId);
        }
    } catch (FlowNotTriggerableException e) {
        LOGGER.error("Failed to handle flow event.", e);
        if (isAcceptablePayload(payload)) {
            ((Acceptable) payload).accepted().onError(e);
        } else {
            throw e;
        }
    } catch (CloudbreakServiceException e) {
        LOGGER.error("Failed to handle flow event.", e);
        throw e;
    } catch (Exception e) {
        LOGGER.error("Failed to handle flow event.", e);
        throw new CloudbreakServiceException(e);
    }
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) FlowNotFoundException(com.sequenceiq.flow.core.exception.FlowNotFoundException) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 5 with Acceptable

use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.

the class FlowPayloadConstructorTest method constructorAccessible.

@Test
void constructorAccessible() {
    Reflections reflections = new Reflections("com.sequenceiq", new SubTypesScanner(true));
    Set<Class<? extends Acceptable>> eventClasses = reflections.getSubTypesOf(Acceptable.class);
    eventClasses.stream().filter(c -> !c.isInterface() && !isAbstract(c) && !c.isAnonymousClass() && !c.isLocalClass() && !c.isMemberClass()).filter(c -> !c.getName().endsWith("Test")).forEach(this::checkForConstructor);
}
Also used : Test(org.junit.jupiter.api.Test) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Modifier(java.lang.reflect.Modifier) Set(java.util.Set) ReflectionUtils(org.reflections.ReflectionUtils) Reflections(org.reflections.Reflections) Constructor(java.lang.reflect.Constructor) SubTypesScanner(org.reflections.scanners.SubTypesScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Reflections(org.reflections.Reflections) Test(org.junit.jupiter.api.Test)

Aggregations

Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)27 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)5 Constructor (java.lang.reflect.Constructor)5 Modifier (java.lang.reflect.Modifier)5 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)4 StackAndClusterUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 BaseFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseFlowEvent)4 Operation (com.sequenceiq.freeipa.entity.Operation)4 ReflectionUtils (org.reflections.ReflectionUtils)4 Reflections (org.reflections.Reflections)4 SubTypesScanner (org.reflections.scanners.SubTypesScanner)4 Event (reactor.bus.Event)4 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3