Search in sources :

Example 1 with RedbeamsStopContext

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);
}
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) RedbeamsStopContext(com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 2 with RedbeamsStopContext

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

Example 3 with RedbeamsStopContext

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

Example 4 with RedbeamsStopContext

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

Aggregations

RedbeamsStopContext (com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext)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 StopDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerRequest)1