This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch DLAB-terraform
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/DLAB-terraform by this push:
     new 180f8c5  DLAB-000 unified cloud properties from different cloud 
providers
180f8c5 is described below

commit 180f8c548dc449851471a5ca26efc706ad4a2633
Author: bhliva <[email protected]>
AuthorDate: Thu Sep 5 14:36:42 2019 +0300

    DLAB-000 unified cloud properties from different cloud providers
---
 .../dlab/backendapi/conf/CloudConfiguration.java   |   6 +
 .../com/epam/dlab/backendapi/dao/MongoSetting.java | 124 ++++++++++++---------
 .../com/epam/dlab/backendapi/dao/SettingsDAO.java  |  65 ++++++++++-
 .../dropwizard/listeners/MongoStartupListener.java |  14 +++
 4 files changed, 155 insertions(+), 54 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/conf/CloudConfiguration.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/conf/CloudConfiguration.java
index 1bd641a..2db4734 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/conf/CloudConfiguration.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/conf/CloudConfiguration.java
@@ -21,6 +21,12 @@ public class CloudConfiguration {
        private final String notebookSubnetId;
        private final String confKeyDir;
        private final String vpcId;
+       private final String azureResourceGroupName;
+       private final String ssnStorageAccountTagName;
+       private final String sharedStorageAccountTagName;
+       private final String datalakeTagName;
+       private final String azureClientId;
+       private final String peeringId;
        @JsonProperty("ldap")
        private final LdapConfig ldapConfig;
 
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/MongoSetting.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/MongoSetting.java
index dabb214..4656b6b 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/MongoSetting.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/MongoSetting.java
@@ -19,67 +19,89 @@
 
 package com.epam.dlab.backendapi.dao;
 
-/** Name of fields in the Mongo collection {@link MongoCollections#SETTINGS}. 
*/
+/**
+ * Name of fields in the Mongo collection {@link MongoCollections#SETTINGS}.
+ */
 public enum MongoSetting {
 
-    // General properties
-       /** Base name of service. */
-    SERIVICE_BASE_NAME("conf_service_base_name"),
-    /** Name of directory for user key. */
-    CONF_KEY_DIRECTORY("conf_key_dir"),
-    /** Name of resource id. */
-    CONF_TAG_RESOURCE_ID("conf_tag_resource_id"),
-    /** Name of OS family. */
-    CONF_OS_FAMILY("conf_os_family"),
+       // General properties
+       /**
+        * Base name of service.
+        */
+       SERIVICE_BASE_NAME("conf_service_base_name"),
+       /**
+        * Name of directory for user key.
+        */
+       CONF_KEY_DIRECTORY("conf_key_dir"),
+       /**
+        * Name of resource id.
+        */
+       CONF_TAG_RESOURCE_ID("conf_tag_resource_id"),
+       /**
+        * Name of OS family.
+        */
+       CONF_OS_FAMILY("conf_os_family"),
+
+       CONF_MAX_BUDGET("conf_max_budget"),
+       SSN_STORAGE_ACCOUNT_TAG_NAME("ssn_storage_account_tag_name"),
+       SHARED_STORAGE_ACCOUNT_TAG_NAME("shared_storage_account_tag_name"),
 
-    CONF_MAX_BUDGET("conf_max_budget"),
+       LDAP_HOSTNAME("ldap_hostname"),
+       LDAP_DN("ldap_dn"),
+       LDAP_OU("ldap_ou"),
+       LDAP_USER("ldap_service_username"),
+       LDAP_PASSWORD("ldap_service_password"),
 
-    LDAP_HOSTNAME("ldap_hostname"),
-    LDAP_DN("ldap_dn"),
-    LDAP_OU("ldap_ou"),
-    LDAP_USER("ldap_service_username"),
-    LDAP_PASSWORD("ldap_service_password"),
+       PEERING_ID("peering_id"),
 
 
-    // AWS Related properties
-    /** Name of AWS region. */
-    AWS_REGION("aws_region"),
-       /** Id of security group. */
-    AWS_SECURITY_GROUPS("aws_security_groups_ids"),
-       /** Id of virtual private cloud for AWS account. */
-    AWS_VPC_ID("aws_vpc_id"),
-       /** Id of virtual private cloud subnet for AWS account. */
-    AWS_SUBNET_ID("aws_subnet_id"),
-    AWS_NOTEBOOK_VPC_ID("aws_notebook_vpc_id"),
-    AWS_NOTEBOOK_SUBNET_ID("aws_notebook_subnet_id"),
-    AWS_ZONE("aws_zone"),
+       // AWS Related properties
+       /**
+        * Name of AWS region.
+        */
+       AWS_REGION("aws_region"),
+       /**
+        * Id of security group.
+        */
+       AWS_SECURITY_GROUPS("aws_security_groups_ids"),
+       /**
+        * Id of virtual private cloud for AWS account.
+        */
+       AWS_VPC_ID("aws_vpc_id"),
+       /**
+        * Id of virtual private cloud subnet for AWS account.
+        */
+       AWS_SUBNET_ID("aws_subnet_id"),
+       AWS_NOTEBOOK_VPC_ID("aws_notebook_vpc_id"),
+       AWS_NOTEBOOK_SUBNET_ID("aws_notebook_subnet_id"),
+       AWS_ZONE("aws_zone"),
 
 
-    // Azure related properties
-    AZURE_REGION("azure_region"),
-    AZURE_RESOURCE_GROUP_NAME("azure_resource_group_name"),
-    AZURE_SUBNET_NAME("azure_subnet_name"),
-    AZURE_VPC_NAME("azure_vpc_name"),
-    AZURE_SECURITY_GROUP_NAME("azure_security_group_name"),
-    AZURE_EDGE_INSTANCE_SIZE("edge_instance_size"),
-    AZURE_SSN_INSTANCE_SIZE("ssn_instance_size"),
-    AZURE_DATA_LAKE_NAME_TAG("datalake_tag_name"),
-    AZURE_DATA_LAKE_CLIENT_ID("azure_client_id"),
+       // Azure related properties
+       AZURE_REGION("azure_region"),
+       AZURE_RESOURCE_GROUP_NAME("azure_resource_group_name"),
+       AZURE_SUBNET_NAME("azure_subnet_name"),
+       AZURE_VPC_NAME("azure_vpc_name"),
+       AZURE_SECURITY_GROUP_NAME("azure_security_group_name"),
+       AZURE_EDGE_INSTANCE_SIZE("edge_instance_size"),
+       AZURE_SSN_INSTANCE_SIZE("ssn_instance_size"),
+       AZURE_DATA_LAKE_NAME_TAG("datalake_tag_name"),
+       AZURE_DATA_LAKE_CLIENT_ID("azure_client_id"),
 
-    // GCP related properties
-    GCP_REGION("gcp_region"),
-    GCP_ZONE("gcp_zone"),
-    GCP_SUBNET_NAME("gcp_subnet_name"),
-    GCP_PROJECT_ID("gcp_project_id"),
-    GCP_VPC_NAME("gcp_vpc_name");
+       // GCP related properties
+       GCP_REGION("gcp_region"),
+       GCP_ZONE("gcp_zone"),
+       GCP_SUBNET_NAME("gcp_subnet_name"),
+       GCP_PROJECT_ID("gcp_project_id"),
+       GCP_VPC_NAME("gcp_vpc_name");
 
-    private String id;
+       private String id;
 
-    MongoSetting(String id) {
-        this.id = id;
-    }
+       MongoSetting(String id) {
+               this.id = id;
+       }
 
-    public String getId() {
-        return id;
-    }
+       public String getId() {
+               return id;
+       }
 }
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SettingsDAO.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SettingsDAO.java
index 3326e3c..3c35109 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SettingsDAO.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/SettingsDAO.java
@@ -21,6 +21,7 @@ package com.epam.dlab.backendapi.dao;
 
 import com.epam.dlab.exceptions.DlabException;
 import com.mongodb.client.model.UpdateOptions;
+import org.apache.commons.lang3.StringUtils;
 import org.bson.Document;
 
 import java.util.Map;
@@ -184,6 +185,26 @@ public class SettingsDAO extends BaseDAO {
                return getSetting(AWS_NOTEBOOK_VPC_ID);
        }
 
+       public void setSsnStorageAccountTagName(String 
ssnStorageAccountTagName) {
+               setSetting(SSN_STORAGE_ACCOUNT_TAG_NAME, 
ssnStorageAccountTagName);
+       }
+
+       public String getSsnStorageAccountTagName() {
+               return getSetting(SSN_STORAGE_ACCOUNT_TAG_NAME);
+       }
+
+       public void setSharedStorageAccountTagName(String 
sharedStorageAccountTagName) {
+               setSetting(SHARED_STORAGE_ACCOUNT_TAG_NAME, 
sharedStorageAccountTagName);
+       }
+
+       public String getSharedStorageAccountTagName() {
+               return getSetting(SHARED_STORAGE_ACCOUNT_TAG_NAME);
+       }
+
+       public void setPeeringId(String peeringId) {
+               setSetting(PEERING_ID, peeringId);
+       }
+
        public void setAwsNotebookVpcId(String awsNotebookVpcId) {
                setSetting(AWS_NOTEBOOK_VPC_ID, awsNotebookVpcId);
        }
@@ -237,6 +258,42 @@ public class SettingsDAO extends BaseDAO {
                return getSetting(AZURE_DATA_LAKE_CLIENT_ID);
        }
 
+       public void setAzureRegion(String region) {
+               setSetting(AZURE_REGION, region);
+       }
+
+       public void setAzureResourceGroupName(String resourceGroupName) {
+               setSetting(AZURE_RESOURCE_GROUP_NAME, resourceGroupName);
+       }
+
+       public void setAzureSubnetName(String subnetName) {
+               setSetting(AZURE_SUBNET_NAME, subnetName);
+       }
+
+       public void setAzureVpcName(String vpcName) {
+               setSetting(AZURE_VPC_NAME, vpcName);
+       }
+
+       public void setAzureSecurityGroupName(String securityGroupName) {
+               setSetting(AZURE_SECURITY_GROUP_NAME, securityGroupName);
+       }
+
+       public void setAzureEdgeInstanceSize(String azureEdgeInstanceSize) {
+               setSetting(AZURE_EDGE_INSTANCE_SIZE, azureEdgeInstanceSize);
+       }
+
+       public void setAzureSsnInstanceSize(String ssnInstanceSize) {
+               setSetting(AZURE_SSN_INSTANCE_SIZE, ssnInstanceSize);
+       }
+
+       public void setAzureDataLakeNameTag(String dataLakeNameTag) {
+               setSetting(AZURE_DATA_LAKE_NAME_TAG, dataLakeNameTag);
+       }
+
+       public void setAzureDataLakeClientId(String dataLakeClientId) {
+               setSetting(AZURE_DATA_LAKE_CLIENT_ID, dataLakeClientId);
+       }
+
        public String getGcpRegion() {
                return getSetting(GCP_REGION);
        }
@@ -296,9 +353,11 @@ public class SettingsDAO extends BaseDAO {
        }
 
        private void setSetting(MongoSetting mongoSetting, String value) {
-               mongoService.getCollection(SETTINGS)
-                               .updateOne(eq(ID, mongoSetting.getId()), new 
Document("$set", new Document(VALUE, value)),
-                                               new 
UpdateOptions().upsert(true));
+               if (StringUtils.isNotEmpty(value)) {
+                       mongoService.getCollection(SETTINGS)
+                                       .updateOne(eq(ID, 
mongoSetting.getId()), new Document("$set", new Document(VALUE, value)),
+                                                       new 
UpdateOptions().upsert(true));
+               }
        }
 
 
diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dropwizard/listeners/MongoStartupListener.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dropwizard/listeners/MongoStartupListener.java
index f94028a..1651c80 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dropwizard/listeners/MongoStartupListener.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dropwizard/listeners/MongoStartupListener.java
@@ -56,6 +56,8 @@ public class MongoStartupListener implements 
ServerLifecycleListener {
                settingsDAO.setLdapOu(ldapConfig.getOu());
                settingsDAO.setLdapUser(ldapConfig.getUser());
                settingsDAO.setLdapPassword(ldapConfig.getPassword());
+               
settingsDAO.setSsnStorageAccountTagName(cloudConfiguration.getSsnStorageAccountTagName());
+               settingsDAO.setPeeringId(cloudConfiguration.getPeeringId());
 
                if (configuration.getCloudProvider() == CloudProvider.AWS) {
                        settingsDAO.setAwsZone(cloudConfiguration.getZone());
@@ -66,6 +68,18 @@ public class MongoStartupListener implements 
ServerLifecycleListener {
                        
settingsDAO.setAwsNotebookSubnetId(cloudConfiguration.getNotebookSubnetId());
                        
settingsDAO.setAwsSecurityGroups(cloudConfiguration.getSecurityGroupIds());
                }
+
+               if (configuration.getCloudProvider() == CloudProvider.AZURE) {
+                       
settingsDAO.setAzureRegion(cloudConfiguration.getRegion());
+                       
settingsDAO.setAzureVpcName(cloudConfiguration.getVpcId());
+                       
settingsDAO.setAzureDataLakeClientId(cloudConfiguration.getAzureClientId());
+                       
settingsDAO.setAzureResourceGroupName(cloudConfiguration.getAzureResourceGroupName());
+                       
settingsDAO.setAzureSecurityGroupName(cloudConfiguration.getSecurityGroupIds());
+                       
settingsDAO.setAzureDataLakeNameTag(cloudConfiguration.getDatalakeTagName());
+                       
settingsDAO.setSsnStorageAccountTagName(cloudConfiguration.getSsnStorageAccountTagName());
+                       
settingsDAO.setSharedStorageAccountTagName(cloudConfiguration.getSharedStorageAccountTagName());
+
+               }
        }
 
        private void insertRoles() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to