use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SdxCreateActions method storageValidation.
@Bean(name = "SDX_CREATION_STORAGE_VALIDATION_STATE")
public Action<?, ?> storageValidation() {
return new AbstractSdxAction<>(SdxEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
// When SDX is created as part of re-size flow chain, SDX in payload will not have the correct ID.
setCorrectSdxIdIfNecessary(context, payload);
StorageValidationRequest req = new StorageValidationRequest(context);
sendEvent(context, req.selector(), req);
}
@Override
protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return SdxCreateFailedEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class CertRotationActions method certRotationFinishedAction.
@Bean(name = "CERT_ROTATION_FINISHED_STATE")
public Action<?, ?> certRotationFinishedAction() {
return new AbstractSdxAction<>(SdxEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
LOGGER.info("Cert rotation is finished");
certRotationService.finalizeCertRotation(payload.getResourceId());
SdxEvent event = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_FINALIZED_EVENT.event(), context);
sendEvent(context, event);
}
@Override
protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return new SdxCertRotationFailedEvent(payload, ex);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class CertRotationActions method starCertRotationAction.
@Bean(name = "START_CERT_ROTATION_STATE")
public Action<?, ?> starCertRotationAction() {
return new AbstractSdxAction<>(SdxStartCertRotationEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxStartCertRotationEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxStartCertRotationEvent payload, Map<Object, Object> variables) {
LOGGER.info("Start cert rotation with request: {}", payload.getRequest());
certRotationService.startCertRotation(context.getSdxId(), payload.getRequest());
SdxEvent sdxEvent = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_STARTED_EVENT.event(), payload.getResourceId(), payload.getUserId());
sendEvent(context, sdxEvent);
}
@Override
protected Object getFailurePayload(SdxStartCertRotationEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return new SdxCertRotationFailedEvent(payload, ex);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class AbstractStackTerminationAction method createFlowContext.
@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
TerminationType terminationType = (TerminationType) variables.getOrDefault(TERMINATION_TYPE, TerminationType.REGULAR);
Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
stack.setResources(new HashSet<>(resourceService.getAllByStackId(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()).withOriginalName(stack.getOriginalName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
CloudStack cloudStack = cloudStackConverter.convert(stack);
List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
return createStackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources, terminationType);
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method setup.
@Before
public void setup() throws CloudbreakImageNotFoundException {
MockitoAnnotations.initMocks(this);
when(stateContext.getMessageHeader(HEADERS.FLOW_PARAMETERS.name())).thenReturn(new FlowParameters("flowId", "usercrn", null));
when(stateContext.getExtendedState()).thenReturn(extendedState);
when(stateContext.getStateMachine()).thenReturn(stateMachine);
when(stateMachine.getState()).thenReturn(state);
when(extendedState.getVariables()).thenReturn(variables);
when(runningFlows.getFlowChainId(anyString())).thenReturn("flowchainid");
when(reactorEventFactory.createEvent(any(Map.class), any(Object.class))).thenReturn(new Event("dummy"));
when(imageService.getImage(anyLong())).thenReturn(image);
when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
when(spanBuilder.start()).thenReturn(span);
when(tracer.activateSpan(span)).thenReturn(scope);
when(span.context()).thenReturn(spanContext);
User user = new User();
user.setUserId("horton@hortonworks.com");
user.setUserCrn("testCrn");
user.setUserName("Alma ur");
Tenant tenant = new Tenant();
tenant.setName("hortonworks");
tenant.setId(1L);
Workspace workspace = new Workspace();
workspace.setId(1L);
workspace.setTenant(tenant);
Stack stack = new Stack();
stack.setCreator(user);
stack.setWorkspace(workspace);
stack.setId(1L);
stack.setRegion("region");
stack.setAvailabilityZone("az");
stack.setResourceCrn("crn:cdp:datalake:us-west-1:tenant:cluster:1234");
when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
when(stackService.getById(anyLong())).thenReturn(stack);
when(stackUtil.getCloudCredential(stack)).thenReturn(cloudCredential);
variables.clear();
}
Aggregations