use of com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext in project cloudbreak by hortonworks.
the class AbstractRedbeamsStartAction method createFlowContext.
@Override
protected RedbeamsStartContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStartState, RedbeamsStartEvent> stateContext, P payload) {
DBStack dbStack = dbStackService.getById(payload.getResourceId());
MDCBuilder.buildMdcContext(dbStack);
Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
String userName = dbStack.getOwnerCrn().getUserId();
String accountId = dbStack.getOwnerCrn().getAccountId();
CloudContext cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withLocation(location).withUserName(userName).withAccountId(accountId).build();
Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
CloudCredential cloudCredential = credentialConverter.convert(credential);
DatabaseStack databaseStack = databaseStackConverter.convert(dbStack);
return new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, databaseStack);
}
use of com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext in project cloudbreak by hortonworks.
the class StartDatabaseServerActionTest method createRequestShouldReturnStartDatabaseServerRequest.
@Test
public void createRequestShouldReturnStartDatabaseServerRequest() {
RedbeamsStartContext context = new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, dbStack);
StartDatabaseServerRequest startDatabaseServerRequest = (StartDatabaseServerRequest) victim.createRequest(context);
assertEquals(cloudContext, startDatabaseServerRequest.getCloudContext());
assertEquals(cloudCredential, startDatabaseServerRequest.getCloudCredential());
assertEquals(dbStack, startDatabaseServerRequest.getDbStack());
}
use of com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext in project cloudbreak by hortonworks.
the class StartDatabaseServerFailedActionTest method shouldCreateFlowContext.
@Test
public void shouldCreateFlowContext() {
when(flowParameters.getFlowId()).thenReturn(FLOW_ID);
when(runningFlows.get(FLOW_ID)).thenReturn(flow);
when(payload.getException()).thenReturn(exception);
when(payload.getResourceId()).thenReturn(RESOURCE_ID);
when(dbStackService.getById(RESOURCE_ID)).thenReturn(dbStack);
when(dbStack.getOwnerCrn()).thenReturn(ownerCrn);
when(dbStack.getId()).thenReturn(DB_STACK_ID);
when(dbStack.getName()).thenReturn(DB_STACK_NAME);
when(dbStack.getCloudPlatform()).thenReturn(DB_STACK_CLOUD_PLATFORM);
when(dbStack.getPlatformVariant()).thenReturn(DB_STACK_PLATFORM_VARIANT);
when(dbStack.getRegion()).thenReturn(DB_STACK_REGION);
when(dbStack.getAvailabilityZone()).thenReturn(DB_STACK_AZ);
when(dbStack.getEnvironmentId()).thenReturn(DB_STACK_ENV_ID);
when(dbStack.getResourceCrn()).thenReturn(CrnTestUtil.getDatabaseServerCrnBuilder().setAccountId("acc").setResource("resource").build().toString());
when(ownerCrn.getUserId()).thenReturn(USER_NAME);
when(ownerCrn.getAccountId()).thenReturn(ACCOUNT_ID);
when(credentialService.getCredentialByEnvCrn(DB_STACK_ENV_ID)).thenReturn(credential);
when(credentialConverter.convert(credential)).thenReturn(cloudCredential);
when(databaseStackConverter.convert(dbStack)).thenReturn(databaseStack);
RedbeamsStartContext redbeamsStartContext = victim.createFlowContext(flowParameters, stateContext, payload);
verify(flow).setFlowFailed(exception);
assertEquals(flowParameters, redbeamsStartContext.getFlowParameters());
assertEquals(DB_STACK_ID, redbeamsStartContext.getCloudContext().getId());
assertEquals(DB_STACK_NAME, redbeamsStartContext.getCloudContext().getName());
assertEquals(DB_STACK_CLOUD_PLATFORM, redbeamsStartContext.getCloudContext().getPlatform().value());
assertEquals(DB_STACK_PLATFORM_VARIANT, redbeamsStartContext.getCloudContext().getVariant().value());
assertEquals(DB_STACK_REGION, redbeamsStartContext.getCloudContext().getLocation().getRegion().value());
assertEquals(DB_STACK_AZ, redbeamsStartContext.getCloudContext().getLocation().getAvailabilityZone().value());
assertEquals(ACCOUNT_ID, redbeamsStartContext.getCloudContext().getAccountId());
assertEquals(flowParameters, redbeamsStartContext.getFlowParameters());
assertEquals(cloudCredential, redbeamsStartContext.getCloudCredential());
assertEquals(databaseStack, redbeamsStartContext.getDatabaseStack());
}
use of com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext in project cloudbreak by hortonworks.
the class StartDatabaseServerFinishedActionTest method shouldIncrementMetricOnCreateRequest.
@Test
public void shouldIncrementMetricOnCreateRequest() {
RedbeamsStartContext context = new RedbeamsStartContext(flowParameters, cloudContext, cloudCredential, databaseStack);
RedbeamsEvent redbeamsEvent = (RedbeamsEvent) victim.createRequest(context);
assertEquals(RedbeamsStartEvent.REDBEAMS_START_FINISHED_EVENT.name(), redbeamsEvent.selector());
}
Aggregations