Search in sources :

Example 31 with Payload

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

the class Flow2HandlerTest method testNewFlowButNotHandled.

@Test
public void testNewFlowButNotHandled() {
    Event<Payload> event = new Event<>(payload);
    event.setKey("KEY");
    CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.accept(event));
    assertEquals("Couldn't start process.", exception.getMessage());
    verify(flowConfigurationMap, times(1)).get(anyString());
    verify(runningFlows, never()).put(any(Flow.class), isNull(String.class));
    verify(flowLogService, never()).save(any(FlowParameters.class), anyString(), anyString(), any(Payload.class), anyMap(), any(), any(FlowState.class));
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 32 with Payload

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

the class Flow2HandlerTest method testRestartFlowNoRestartActionNoFlowChainId.

@Test
public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException {
    FlowLog flowLog = createFlowLog(null);
    Payload payload = new TestPayload(STACK_ID);
    flowLog.setPayloadType(ClassValue.of(TestPayload.class));
    flowLog.setPayload(JsonWriter.objectToJson(payload));
    when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
    HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
    setUpFlowConfigCreateFlow(helloWorldFlowConfig);
    List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
    ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
    underTest.restartFlow(FLOW_ID);
    verify(flowChainHandler, never()).restoreFlowChain(FLOW_CHAIN_ID);
    verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
    verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
Also used : FlowConfiguration(com.sequenceiq.flow.core.config.FlowConfiguration) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) HelloWorldFlowConfig(com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig) Test(org.junit.jupiter.api.Test)

Example 33 with Payload

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

the class FlowChains method getRootTriggerEvent.

public Optional<Pair<String, Payload>> getRootTriggerEvent(String flowChainId) {
    String rootFlowChainId = getRootFlowChainId(flowChainId);
    FlowTriggerEventQueue flowTriggerEventQueue = flowChainMap.get(rootFlowChainId);
    if (flowTriggerEventQueue != null) {
        return Optional.of(Pair.of(rootFlowChainId, flowTriggerEventQueue.getTriggerEvent()));
    }
    Optional<FlowChainLog> initFlowChainLog = flowChainLogService.findRootInitFlowChainLog(flowChainId);
    if (initFlowChainLog.isEmpty()) {
        return Optional.empty();
    }
    LOGGER.info("Found root init flow chain log {} for flow chain {}", initFlowChainLog.get(), flowChainId);
    Payload triggerEvent = FlowLogUtil.tryDeserializeTriggerEvent(initFlowChainLog.get());
    if (triggerEvent == null) {
        return Optional.empty();
    } else {
        return Optional.of(Pair.of(initFlowChainLog.get().getFlowChainId(), triggerEvent));
    }
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Payload(com.sequenceiq.cloudbreak.common.event.Payload) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 34 with Payload

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

the class FillInMemoryStateStoreRestartAction method restart.

@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
    Payload redbeamsPayload = (Payload) payload;
    DBStack dbStack = dbStackService.getById(redbeamsPayload.getResourceId());
    if (dbStack != null) {
        redbeamsInMemoryStateStoreUpdaterService.update(dbStack.getId(), dbStack.getStatus());
        MDCBuilder.buildMdcContext(dbStack);
        MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
        MDCBuilder.addAccountId(getAccountId(dbStack));
    }
    super.restart(flowParameters, flowChainId, event, payload);
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) Payload(com.sequenceiq.cloudbreak.common.event.Payload)

Example 35 with Payload

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

the class AbstractStackTerminationAction method createFlowContext.

@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    List<Resource> resourceList = resourceService.findAllByStackId(stack.getId());
    List<CloudResource> resources = resourceList.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
    return new StackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources);
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) Inject(javax.inject.Inject) StackTerminationEvent(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationEvent) StateContext(org.springframework.statemachine.StateContext) Credential(com.sequenceiq.freeipa.dto.Credential) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Resource(com.sequenceiq.freeipa.entity.Resource) Location(com.sequenceiq.cloudbreak.cloud.model.Location) StackService(com.sequenceiq.freeipa.service.stack.StackService) AbstractStackAction(com.sequenceiq.freeipa.flow.stack.AbstractStackAction) Stack(com.sequenceiq.freeipa.entity.Stack) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackTerminationState(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationState) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CredentialToCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) StackTerminationContext(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) Optional(java.util.Optional) CredentialService(com.sequenceiq.freeipa.service.CredentialService) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) StackTerminationContext(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationContext) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Payload (com.sequenceiq.cloudbreak.common.event.Payload)36 Test (org.junit.jupiter.api.Test)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Event (reactor.bus.Event)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)8 List (java.util.List)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Location (com.sequenceiq.cloudbreak.cloud.model.Location)7 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)7 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)7 FlowParameters (com.sequenceiq.flow.core.FlowParameters)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 StateContext (org.springframework.statemachine.StateContext)7 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)6