use of com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext in project cloudbreak by hortonworks.
the class AbstractRedbeamsStopAction method createFlowContext.
@Override
protected RedbeamsStopContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsStopState, RedbeamsStopEvent> 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 RedbeamsStopContext(flowParameters, cloudContext, cloudCredential, databaseStack);
}
use of com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext in project cloudbreak by hortonworks.
the class StopDatabaseServerActionTest method createRequestShouldReturnStopDatabaseServerRequest.
@Test
public void createRequestShouldReturnStopDatabaseServerRequest() {
RedbeamsStopContext context = new RedbeamsStopContext(flowParameters, cloudContext, cloudCredential, databaseStack);
StopDatabaseServerRequest stopDatabaseServerRequest = (StopDatabaseServerRequest) victim.createRequest(context);
assertEquals(cloudContext, stopDatabaseServerRequest.getCloudContext());
assertEquals(cloudCredential, stopDatabaseServerRequest.getCloudCredential());
}
use of com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext in project cloudbreak by hortonworks.
the class StopDatabaseServerFailedActionTest 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);
RedbeamsStopContext redbeamsStopContext = victim.createFlowContext(flowParameters, stateContext, payload);
verify(flow).setFlowFailed(exception);
assertEquals(flowParameters, redbeamsStopContext.getFlowParameters());
assertEquals(DB_STACK_ID, redbeamsStopContext.getCloudContext().getId());
assertEquals(DB_STACK_NAME, redbeamsStopContext.getCloudContext().getName());
assertEquals(DB_STACK_CLOUD_PLATFORM, redbeamsStopContext.getCloudContext().getPlatform().value());
assertEquals(DB_STACK_PLATFORM_VARIANT, redbeamsStopContext.getCloudContext().getVariant().value());
assertEquals(DB_STACK_REGION, redbeamsStopContext.getCloudContext().getLocation().getRegion().value());
assertEquals(DB_STACK_AZ, redbeamsStopContext.getCloudContext().getLocation().getAvailabilityZone().value());
assertEquals(ACCOUNT_ID, redbeamsStopContext.getCloudContext().getAccountId());
assertEquals(flowParameters, redbeamsStopContext.getFlowParameters());
assertEquals(cloudCredential, redbeamsStopContext.getCloudCredential());
assertEquals(databaseStack, redbeamsStopContext.getDatabaseStack());
}
use of com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext in project cloudbreak by hortonworks.
the class StopDatabaseServerFinishedActionTest method shouldIncrementMetricOnCreateRequest.
@Test
public void shouldIncrementMetricOnCreateRequest() {
RedbeamsStopContext context = new RedbeamsStopContext(flowParameters, cloudContext, cloudCredential, databaseStack);
RedbeamsEvent redbeamsEvent = (RedbeamsEvent) victim.createRequest(context);
assertEquals(RedbeamsStopEvent.REDBEAMS_STOP_FINISHED_EVENT.name(), redbeamsEvent.selector());
}
Aggregations