use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AbstractRedbeamsTerminationAction method createFlowContext.
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsTerminationState, RedbeamsTerminationEvent> stateContext, P payload) {
Optional<DBStack> optionalDBStack = dbStackService.findById(payload.getResourceId());
CloudContext cloudContext = null;
CloudCredential cloudCredential = null;
DatabaseStack databaseStack = null;
DBStack dbStack = null;
if (optionalDBStack.isPresent()) {
dbStack = optionalDBStack.get();
MDCBuilder.buildMdcContext(dbStack);
Location location = location(region(dbStack.getRegion()), availabilityZone(dbStack.getAvailabilityZone()));
String userName = dbStack.getOwnerCrn().getUserId();
String accountId = dbStack.getOwnerCrn().getAccountId();
cloudContext = CloudContext.Builder.builder().withId(dbStack.getId()).withName(dbStack.getName()).withCrn(dbStack.getResourceCrn()).withPlatform(dbStack.getCloudPlatform()).withVariant(dbStack.getPlatformVariant()).withUserName(userName).withLocation(location).withAccountId(accountId).build();
try {
Credential credential = credentialService.getCredentialByEnvCrn(dbStack.getEnvironmentId());
cloudCredential = credentialConverter.convert(credential);
} catch (Exception ex) {
LOGGER.warn("Could not detect credential for environment: {}", dbStack.getEnvironmentId());
}
databaseStack = databaseStackConverter.convert(dbStack);
} else {
LOGGER.warn("DBStack for {} id is not found in the database, it seems to be only possible if the redbeams process was killed during the execution" + " of the termination finished action", payload.getResourceId());
}
return new RedbeamsContext(flowParameters, cloudContext, cloudCredential, databaseStack, dbStack);
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverter method convert.
public DatabaseServerV4Response convert(DatabaseServerConfig source) {
DatabaseServerV4Response response = new DatabaseServerV4Response();
response.setId(source.getId());
response.setCrn(source.getResourceCrn().toString());
response.setName(source.getName());
response.setDescription(source.getDescription());
response.setHost(source.getHost());
response.setPort(source.getPort());
response.setDatabaseVendor(source.getDatabaseVendor().databaseType());
response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName());
response.setConnectionDriver(source.getConnectionDriver());
response.setConnectionUserName(stringToSecretResponseConverter.convert(source.getConnectionUserNameSecret()));
response.setConnectionPassword(stringToSecretResponseConverter.convert(source.getConnectionPasswordSecret()));
response.setCreationDate(source.getCreationDate());
response.setEnvironmentCrn(source.getEnvironmentId());
response.setClusterCrn(source.getClusterCrn());
response.setResourceStatus(source.getResourceStatus());
if (source.getDbStack().isPresent()) {
DBStack dbStack = source.getDbStack().get();
response.setStatus(dbStack.getStatus());
response.setStatusReason(dbStack.getStatusReason());
if (dbStack.getSslConfig() != null) {
SslConfig sslConfig = dbStack.getSslConfig();
SslConfigV4Response sslConfigV4Response = new SslConfigV4Response();
sslConfigV4Response.setSslCertificates(sslConfig.getSslCertificates());
sslConfigV4Response.setSslCertificateType(sslConfig.getSslCertificateType());
sslConfigV4Response.setSslMode(NONE.equals(sslConfig.getSslCertificateType()) ? DISABLED : ENABLED);
String cloudPlatform = dbStack.getCloudPlatform();
String region = dbStack.getRegion();
// TODO Add SslConfig.sslCertificateMaxVersion that is kept up-to-date (mostly for GCP), use getMaxVersionByPlatform() as fallback
sslConfigV4Response.setSslCertificateHighestAvailableVersion(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(cloudPlatform, region));
sslConfigV4Response.setSslCertificateActiveVersion(Optional.ofNullable(sslConfig.getSslCertificateActiveVersion()).orElse(databaseServerSslCertificateConfig.getLegacyMaxVersionByCloudPlatformAndRegion(cloudPlatform, region)));
sslConfigV4Response.setSslCertificateActiveCloudProviderIdentifier(Optional.ofNullable(sslConfig.getSslCertificateActiveCloudProviderIdentifier()).orElse(databaseServerSslCertificateConfig.getLegacyCloudProviderIdentifierByCloudPlatformAndRegion(cloudPlatform, region)));
response.setSslConfig(sslConfigV4Response);
}
} else if (source.getHost() != null && source.getPort() != null) {
response.setStatus(Status.AVAILABLE);
} else {
response.setStatus(Status.UNKNOWN);
}
if (response.getSslConfig() == null) {
response.setSslConfig(new SslConfigV4Response());
}
return response;
}
use of com.sequenceiq.redbeams.domain.stack.DBStack 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.domain.stack.DBStack in project cloudbreak by hortonworks.
the class RedbeamsProvisionActions method provisionFailed.
@Bean(name = "REDBEAMS_PROVISION_FAILED_STATE")
public Action<?, ?> provisionFailed() {
return new AbstractRedbeamsProvisionAction<>(RedbeamsFailureEvent.class) {
// A lot here - some of this could go into some sort of failure handler class
// compare to core StackCreationService::handleStackCreationFailure
@Override
protected void prepareExecution(RedbeamsFailureEvent payload, Map<Object, Object> variables) {
Exception failureException = payload.getException();
LOGGER.info("Error during database stack creation flow:", failureException);
if (failureException instanceof CancellationException || ExceptionUtils.getRootCause(failureException) instanceof CancellationException) {
LOGGER.debug("The flow has been cancelled");
} else {
// StackCreationActions / StackCreationService only update status if stack isn't mid-deletion
String errorReason = failureException == null ? "Unknown error" : failureException.getMessage();
Optional<DBStack> dbStack = dbStackStatusUpdater.updateStatus(payload.getResourceId(), DetailedDBStackStatus.PROVISION_FAILED, errorReason);
metricService.incrementMetricCounter(MetricType.DB_PROVISION_FAILED, dbStack);
}
}
@Override
protected RedbeamsContext createFlowContext(FlowParameters flowParameters, StateContext<RedbeamsProvisionState, RedbeamsProvisionEvent> stateContext, RedbeamsFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected Selectable createRequest(RedbeamsContext context) {
return new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_FAILURE_HANDLED_EVENT.event(), 0L);
}
};
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverterTest method conversionTestWhenOptionalElementsGenerated.
@Test
void conversionTestWhenOptionalElementsGenerated() throws IOException {
setupAllocateRequest(false);
when(databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(AWS_CLOUD_PLATFORM.name(), REGION)).thenReturn(SINGLE_CERT);
when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndVersion(AWS_CLOUD_PLATFORM.name(), REGION, VERSION_3)).thenReturn(sslCertificateEntryV3);
List<CloudSubnet> cloudSubnets = List.of(new CloudSubnet("subnet-1", "", "az-a", ""), new CloudSubnet("subnet-2", "", "az-b", ""));
DetailedEnvironmentResponse environment = DetailedEnvironmentResponse.builder().withCloudPlatform(AWS_CLOUD_PLATFORM.name()).withName(ENVIRONMENT_NAME).withCrn(ENVIRONMENT_CRN).withTag(new TagResponse()).withLocation(LocationResponse.LocationResponseBuilder.aLocationResponse().withName(REGION).build()).withSecurityAccess(SecurityAccessResponse.builder().withDefaultSecurityGroupId(DEFAULT_SECURITY_GROUP_ID).build()).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("subnet-1", cloudSubnets.get(0), "subnet-2", cloudSubnets.get(1))).build()).build();
when(environmentService.getByCrn(ENVIRONMENT_CRN)).thenReturn(environment);
when(subnetListerService.listSubnets(any(), any())).thenReturn(cloudSubnets);
when(subnetChooserService.chooseSubnets(any(), any(), any())).thenReturn(cloudSubnets);
when(networkParameterAdder.addSubnetIds(any(), any(), any(), any())).thenReturn(SUBNET_ID_REQUEST_PARAMETERS);
when(userGeneratorService.generateUserName()).thenReturn(USERNAME);
when(passwordGeneratorService.generatePassword(any())).thenReturn(PASSWORD);
DBStack dbStack = underTest.convert(allocateRequest, OWNER_CRN);
assertEquals(ENVIRONMENT_NAME + "-dbstck-parts", dbStack.getName());
assertEquals(PASSWORD, dbStack.getDatabaseServer().getRootPassword());
assertEquals(USERNAME, dbStack.getDatabaseServer().getRootUserName());
assertEquals("n-uuid", dbStack.getNetwork().getName());
assertEquals(1, dbStack.getNetwork().getAttributes().getMap().size());
assertEquals("netvalue", dbStack.getNetwork().getAttributes().getMap().get("netkey"));
assertThat(dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds()).hasSize(1);
assertEquals(dbStack.getDatabaseServer().getSecurityGroup().getSecurityGroupIds().iterator().next(), DEFAULT_SECURITY_GROUP_ID);
assertEquals(dbStack.getTags().get(StackTags.class).getUserDefinedTags().get("DistroXKey1"), "DistroXValue1");
verifySsl(dbStack, Set.of(CERT_PEM_V3), CLOUD_PROVIDER_IDENTIFIER_V3);
verify(databaseServerSslCertificateConfig, never()).getCertsByCloudPlatformAndRegionAndVersions(anyString(), anyString(), any());
verify(providerParameterCalculator).get(allocateRequest);
verify(providerParameterCalculator, never()).get(networkRequest);
verify(subnetListerService).listSubnets(any(), any());
verify(subnetChooserService).chooseSubnets(anyList(), any(), any());
verify(networkParameterAdder).addSubnetIds(any(), any(), any(), any());
verify(userGeneratorService).generateUserName();
verify(passwordGeneratorService).generatePassword(any());
}
Aggregations