use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class AzureDatabaseResourceService method buildDatabaseResourcesForLaunch.
public List<CloudResourceStatus> buildDatabaseResourcesForLaunch(AuthenticatedContext ac, DatabaseStack stack, PersistenceNotifier persistenceNotifier) {
CloudContext cloudContext = ac.getCloudContext();
AzureClient client = ac.getParameter(AzureClient.class);
String stackName = azureUtils.getStackName(cloudContext);
String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack);
ResourceGroupUsage resourceGroupUsage = azureResourceGroupMetadataProvider.getResourceGroupUsage(stack);
String template = azureDatabaseTemplateBuilder.build(cloudContext, stack);
if (!client.resourceGroupExists(resourceGroupName)) {
if (resourceGroupUsage != ResourceGroupUsage.MULTIPLE) {
LOGGER.warn("Resource group with name {} does not exist", resourceGroupName);
throw new CloudConnectorException(String.format("Resource group with name %s does not exist!", resourceGroupName));
} else {
LOGGER.debug("Resource group with name {} does not exist, creating it now..", resourceGroupName);
String region = ac.getCloudContext().getLocation().getRegion().value();
client.createResourceGroup(resourceGroupName, region, stack.getTags());
}
}
createResourceGroupResource(persistenceNotifier, cloudContext, resourceGroupName);
createTemplateResource(persistenceNotifier, cloudContext, stackName);
Deployment deployment;
try {
String parametersMapAsString = new Json(Map.of()).getValue();
client.createTemplateDeployment(resourceGroupName, stackName, template, parametersMapAsString);
} catch (CloudException e) {
throw azureUtils.convertToCloudConnectorException(e, "Database stack provisioning");
} catch (Exception e) {
throw new CloudConnectorException(String.format("Error in provisioning database stack %s: %s", stackName, e.getMessage()), e);
} finally {
deployment = client.getTemplateDeployment(resourceGroupName, stackName);
if (deployment != null) {
List<CloudResource> cloudResources = azureCloudResourceService.getDeploymentCloudResources(deployment);
cloudResources.forEach(cloudResource -> persistenceNotifier.notifyAllocation(cloudResource, cloudContext));
}
}
String fqdn = (String) ((Map) ((Map) deployment.outputs()).get(DATABASE_SERVER_FQDN)).get("value");
List<CloudResource> databaseResources = createCloudResources(fqdn);
databaseResources.forEach(dbr -> persistenceNotifier.notifyAllocation(dbr, cloudContext));
return databaseResources.stream().map(resource -> new CloudResourceStatus(resource, ResourceStatus.CREATED)).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class DatabaseServerSslCertificatePrescriptionServiceTest method setUp.
@BeforeEach
void setUp() {
dbStack = new DBStack();
databaseServer = DatabaseServer.builder().build();
databaseStack = new DatabaseStack(null, databaseServer, Map.of(), "");
region = Region.region("myregion");
location = Location.location(region);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class AllocateDatabaseServerHandlerTest method setUp.
@BeforeEach
void setUp() {
dbStack = new DBStack();
dbStack.setCloudPlatform(CloudPlatform.AWS.name());
lenient().when(dbStackService.getById(anyLong())).thenReturn(dbStack);
databaseStack = new DatabaseStack(null, null, Map.of(), "");
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionAzureWithMultipleResourceGroups.
@Test
public void testConversionAzureWithMultipleResourceGroups() {
Network network = new Network();
network.setAttributes(new Json(NETWORK_ATTRIBUTES));
dbStack.setNetwork(network);
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setParameters(new HashMap<>());
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
dbStack.setDatabaseServer(server);
dbStack.setTags(new Json(STACK_TAGS));
dbStack.setTemplate("template");
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
environmentResponse.setCloudPlatform(CLOUD_PLATFORM);
environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.MULTIPLE).build()).build());
when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
DatabaseStack convertedStack = underTest.convert(dbStack);
Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
assertThat(parameters.containsKey(RESOURCE_GROUP_NAME_PARAMETER)).isFalse();
assertThat(parameters.containsKey(RESOURCE_GROUP_USAGE_PARAMETER)).isFalse();
assertThat(parameters.size()).isEqualTo(2);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionAzureWithAzureEncryptionResourcesPresentAndSingleResourceGroup.
@Test
public void testConversionAzureWithAzureEncryptionResourcesPresentAndSingleResourceGroup() {
Network network = new Network();
network.setAttributes(new Json(NETWORK_ATTRIBUTES));
dbStack.setNetwork(network);
dbStack.setCloudPlatform(CLOUD_PLATFORM);
dbStack.setParameters(new HashMap<>());
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
server.setAttributes(new Json(DATABASE_SERVER_ATTRIBUTES));
dbStack.setDatabaseServer(server);
dbStack.setTags(new Json(STACK_TAGS));
dbStack.setTemplate("template");
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
environmentResponse.setCloudPlatform(CLOUD_PLATFORM);
environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName(RESOURCE_GROUP).build()).withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(RESOURCE_GROUP).build()).build());
when(environmentService.getByCrn(anyString())).thenReturn(environmentResponse);
DatabaseStack convertedStack = underTest.convert(dbStack);
Map<String, Object> parameters = convertedStack.getDatabaseServer().getParameters();
assertThat(parameters.get(RESOURCE_GROUP_NAME_PARAMETER).toString()).isEqualTo(RESOURCE_GROUP);
assertThat(parameters.get(RESOURCE_GROUP_USAGE_PARAMETER).toString()).isEqualTo(ResourceGroupUsage.SINGLE.name());
assertThat(parameters.get(ENCRYPTION_KEY_URL).toString()).isEqualTo(KEY_URL);
assertThat(parameters.get(ENCRYPTION_KEY_RESOURCE_GROUP_NAME).toString()).isEqualTo(RESOURCE_GROUP);
assertThat(parameters.size()).isEqualTo(6);
}
Aggregations