use of com.sequenceiq.cloudbreak.cloud.gcp.view.GcpDatabaseNetworkView in project cloudbreak by hortonworks.
the class GcpDatabaseServerLaunchService method getDatabaseInstance.
private DatabaseInstance getDatabaseInstance(DatabaseStack stack, String deploymentName, Compute compute, String projectId) throws java.io.IOException {
DatabaseServer databaseServer = stack.getDatabaseServer();
GcpDatabaseServerView databaseServerView = new GcpDatabaseServerView(databaseServer);
GcpDatabaseNetworkView databaseNetworkView = new GcpDatabaseNetworkView(stack.getNetwork());
Subnetwork subnetworkForRedbeams;
if (Strings.isNullOrEmpty(databaseNetworkView.getSharedProjectId())) {
subnetworkForRedbeams = compute.subnetworks().get(projectId, databaseServerView.getLocation(), databaseNetworkView.getSubnetId()).execute();
} else {
subnetworkForRedbeams = compute.subnetworks().get(databaseNetworkView.getSharedProjectId(), databaseServerView.getLocation(), databaseNetworkView.getSubnetId()).execute();
}
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setCurrentDiskSize(databaseServerView.getAllocatedStorageInMb());
databaseInstance.setName(deploymentName);
databaseInstance.setInstanceType("CLOUD_SQL_INSTANCE");
databaseInstance.setBackendType("SECOND_GEN");
databaseInstance.setRegion(databaseServerView.getLocation());
databaseInstance.setRootPassword(databaseServerView.getAdminPassword());
databaseInstance.setConnectionName(databaseServerView.getAdminLoginName());
databaseInstance.setGceZone(databaseNetworkView.getAvailabilityZone());
databaseInstance.setDatabaseVersion(databaseServerView.getDatabaseVersion());
databaseInstance.setSettings(getSettings(stack, databaseServerView, subnetworkForRedbeams));
String keyName = databaseServer.getStringParameter(VOLUME_ENCRYPTION_KEY_ID);
if (keyName != null && !keyName.isEmpty()) {
DiskEncryptionConfiguration diskEncryptionConfiguration = new DiskEncryptionConfiguration();
diskEncryptionConfiguration.setKmsKeyName(keyName);
databaseInstance.setDiskEncryptionConfiguration(diskEncryptionConfiguration);
}
return databaseInstance;
}
Aggregations