use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView in project cloudbreak by hortonworks.
the class AzureDatabaseTemplateBuilder method build.
public String build(CloudContext cloudContext, DatabaseStack databaseStack) {
try {
String location = cloudContext.getLocation().getRegion().getRegionName();
AzureNetworkView azureNetworkView = new AzureNetworkView(databaseStack.getNetwork());
AzureDatabaseServerView azureDatabaseServerView = new AzureDatabaseServerView(databaseStack.getDatabaseServer());
Map<String, Object> model = new HashMap<>();
model.put("usePrivateEndpoints", USE_PRIVATE_ENDPOINT.equals(azureNetworkView.getEndpointType()));
model.put("subnetIdForPrivateEndpoint", azureNetworkView.getSubnetIdForPrivateEndpoint());
model.put("existingDatabasePrivateDnsZoneId", azureNetworkView.getExistingDatabasePrivateDnsZoneId());
model.put("adminLoginName", azureDatabaseServerView.getAdminLoginName());
model.put("adminPassword", azureDatabaseServerView.getAdminPassword());
model.put("backupRetentionDays", azureDatabaseServerView.getBackupRetentionDays());
model.put("dbServerName", azureDatabaseServerView.getDbServerName());
model.put("dbVersion", azureDatabaseServerView.getDbVersion());
model.put("geoRedundantBackup", azureDatabaseServerView.getGeoRedundantBackup());
model.put("location", location);
if (azureDatabaseServerView.getPort() != null) {
LOGGER.warn("Found port {} in database stack, but Azure ignores it", azureDatabaseServerView.getPort());
}
model.put("dataEncryption", false);
String keyVaultUrl = azureDatabaseServerView.getKeyVaultUrl();
if (keyVaultUrl != null) {
String keyVaultName;
String keyName;
String keyVersion;
Matcher matcher = ENCRYPTION_KEY_URL_VAULT_NAME.matcher(keyVaultUrl);
if (matcher.matches()) {
keyVaultName = matcher.group(1);
} else {
throw new IllegalArgumentException(String.format("keyVaultName cannot be fetched from encryptionKeyUrl %s.", keyVaultUrl));
}
matcher = ENCRYPTION_KEY_NAME.matcher(keyVaultUrl);
if (matcher.matches()) {
keyName = matcher.group(1);
} else {
throw new IllegalArgumentException(String.format("keyName cannot be fetched from encryptionKeyUrl %s.", keyVaultUrl));
}
matcher = ENCRYPTION_KEY_VERSION.matcher(keyVaultUrl);
if (matcher.matches()) {
keyVersion = matcher.group(1);
} else {
throw new IllegalArgumentException(String.format("keyVersion cannot be fetched from encryptionKeyUrl %s.", keyVaultUrl));
}
model.put("dataEncryption", true);
model.put("keyVaultName", keyVaultName);
model.put("keyVaultResourceGroupName", azureDatabaseServerView.getKeyVaultResourceGroupName());
model.put("keyName", keyName);
model.put("keyVersion", keyVersion);
}
model.put("serverTags", databaseStack.getTags());
model.put("skuCapacity", azureDatabaseServerView.getSkuCapacity());
model.put("skuFamily", azureDatabaseServerView.getSkuFamily());
model.put("skuName", azureDatabaseServerView.getSkuName());
model.put("skuSizeMB", azureDatabaseServerView.getAllocatedStorageInMb());
model.put("skuTier", getSkuTier(azureDatabaseServerView));
model.put("useSslEnforcement", azureDatabaseServerView.isUseSslEnforcement());
model.put("storageAutoGrow", azureDatabaseServerView.getStorageAutoGrow());
model.put("subnets", azureNetworkView.getSubnets());
String[] subnets = azureNetworkView.getSubnets().split(",");
model.put("subnetIdList", subnets);
// if subnet number is 1 then Azure does not create the endpoints if the batchsize is 5
model.put("batchSize", azureNetworkView.getSubnets().split(",").length >= defaultBatchSize ? defaultBatchSize : 1);
model.put("location", azureDatabaseServerView.getLocation());
model.put("privateEndpointName", String.format("pe-%s-to-%s", azureUtils.encodeString(getSubnetName(azureNetworkView.getSubnetList().get(0))), azureDatabaseServerView.getDbServerName()));
String generatedTemplate = freeMarkerTemplateUtils.processTemplateIntoString(azureDatabaseTemplateProvider.getTemplate(databaseStack), model);
LOGGER.debug("Generated ARM database template: {}", AnonymizerUtil.anonymize(generatedTemplate));
return generatedTemplate;
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process the ARM TemplateBuilder", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView in project cloudbreak by hortonworks.
the class AzureNetworkLinkServiceTest method getNetworkView.
private AzureNetworkView getNetworkView() {
AzureNetworkView networkView = new AzureNetworkView();
networkView.setExistingNetwork(false);
networkView.setNetworkId(NETWORK_ID);
networkView.setResourceGroupName(NETWORK_RG);
return networkView;
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method getNetworkView.
private AzureNetworkView getNetworkView() {
AzureNetworkView networkView = new AzureNetworkView();
networkView.setExistingNetwork(false);
networkView.setNetworkId(NETWORK_ID);
networkView.setResourceGroupName(NETWORK_RG);
return networkView;
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView in project cloudbreak by hortonworks.
the class AzureDnsZoneServiceTest method getNetworkView.
private AzureNetworkView getNetworkView() {
AzureNetworkView networkView = new AzureNetworkView();
networkView.setExistingNetwork(false);
networkView.setNetworkId(NETWORK_ID);
networkView.setResourceGroupName(NETWORK_RG);
return networkView;
}
use of com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView in project cloudbreak by hortonworks.
the class AzureNetworkConnector method createProviderSpecificNetworkResources.
@Override
public void createProviderSpecificNetworkResources(NetworkResourcesCreationRequest request) {
if (request.isPrivateEndpointsEnabled()) {
LOGGER.debug("Private endpoints are enabled, and DNS zone is managed by CDP. Checking the presence of DNS Zones and Network links..");
AzureClient azureClient = azureClientService.getClient(request.getCloudCredential());
String resourceGroup = request.getResourceGroup();
AuthenticatedContext authenticatedContext = new AuthenticatedContext(request.getCloudContext(), request.getCloudCredential());
Map<String, String> tags = request.getTags();
AzureNetworkView networkView = new AzureNetworkView();
networkView.setExistingNetwork(request.isExistingNetwork());
networkView.setNetworkId(request.getNetworkId());
networkView.setResourceGroupName(request.getNetworkResourceGroup());
Set<AzurePrivateDnsZoneServiceEnum> servicesWithExistingDnsZone = getServicesWithExistingDnsZone(request);
azureDnsZoneService.checkOrCreateDnsZones(authenticatedContext, azureClient, networkView, resourceGroup, tags, servicesWithExistingDnsZone);
azureNetworkLinkService.checkOrCreateNetworkLinks(authenticatedContext, azureClient, networkView, resourceGroup, tags, servicesWithExistingDnsZone);
} else {
LOGGER.debug("Private endpoints are disabled, nothing to do.");
}
}
Aggregations