Search in sources :

Example 1 with RedbeamsStartContext

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);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) RedbeamsStartContext(com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 2 with RedbeamsStartContext

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());
}
Also used : StartDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest) RedbeamsStartContext(com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext) Test(org.junit.jupiter.api.Test)

Example 3 with RedbeamsStartContext

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());
}
Also used : RedbeamsStartContext(com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext) Test(org.junit.jupiter.api.Test)

Example 4 with RedbeamsStartContext

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());
}
Also used : RedbeamsStartContext(com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent) Test(org.junit.jupiter.api.Test)

Aggregations

RedbeamsStartContext (com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext)4 Test (org.junit.jupiter.api.Test)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 Credential (com.sequenceiq.redbeams.dto.Credential)1 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)1 StartDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest)1