You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by yk...@apache.org on 2021/02/24 13:51:46 UTC

[incubator-datalab] branch DATALAB-2228-fix created (now 77138cb)

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

ykinash pushed a change to branch DATALAB-2228-fix
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git.


      at 77138cb  [DATALAB-2228-fix] - fixed bugs, refactoring

This branch includes the following new commits:

     new 77138cb  [DATALAB-2228-fix] - fixed bugs, refactoring

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org


[incubator-datalab] 01/01: [DATALAB-2228-fix] - fixed bugs, refactoring

Posted by yk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ykinash pushed a commit to branch DATALAB-2228-fix
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git

commit 77138cb2ec7f183ec0a41c433d0d3b8aa4d4cdd1
Author: KinashYurii <ur...@gmail.com>
AuthorDate: Wed Feb 24 15:51:12 2021 +0200

    [DATALAB-2228-fix] - fixed bugs, refactoring
---
 services/datalab-webapp-common/pom.xml             |   5 +
 .../datalab/properties}/ChangePropertiesConst.java |  19 +-
 .../properties}/DynamicChangeProperties.java       | 102 +++++------
 .../com/epam/datalab/properties}/RestartForm.java  |   2 +-
 .../java/com/epam/datalab/properties}/YmlDTO.java  |   2 +-
 ...rovisioningServiceApplicationConfiguration.java |   1 +
 .../resources/ChangePropertiesResource.java        |  67 +++++++
 .../datalab/backendapi/SelfServiceApplication.java |   2 +-
 .../resources/ChangePropertiesResource.java        | 125 +++++++++++++
 .../resources/admin/ChangePropertiesResource.java  | 199 ---------------------
 10 files changed, 260 insertions(+), 264 deletions(-)

diff --git a/services/datalab-webapp-common/pom.xml b/services/datalab-webapp-common/pom.xml
index a89c115..b42da46 100644
--- a/services/datalab-webapp-common/pom.xml
+++ b/services/datalab-webapp-common/pom.xml
@@ -65,5 +65,10 @@
             <groupId>com.epam.datalab</groupId>
             <artifactId>common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.4</version>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
similarity index 78%
rename from services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java
rename to services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
index a5b59f7..ded9565 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
@@ -1,23 +1,26 @@
-package com.epam.datalab.backendapi.modules;
+package com.epam.datalab.properties;
 
 public interface ChangePropertiesConst {
     String GKE_SELF_SERVICE_PATH = "/root/self-service.yaml";
     String GKE_SELF_SERVICE = "self-service.yaml";
     String SELF_SERVICE = "self-service.yml";
-    //    String SELF_SERVICE_PROP_PATH = "services/self-service/self-service.yml";
-    String SELF_SERVICE_PROP_PATH = "/opt/datalab/conf/self-service.yml";
+    String SELF_SERVICE_PROP_PATH = "services/self-service/self-service.yml";
+    //    String SELF_SERVICE_PROP_PATH = "/opt/datalab/conf/self-service.yml";
     String PROVISIONING_SERVICE = "provisioning.yml";
-    //    String PROVISIONING_SERVICE_PROP_PATH = "services/provisioning-service/provisioning.yml";
-    String PROVISIONING_SERVICE_PROP_PATH = "/opt/datalab/conf/provisioning.yml";
+    String PROVISIONING_SERVICE_PROP_PATH = "services/provisioning-service/provisioning.yml";
+//    String PROVISIONING_SERVICE_PROP_PATH = "/opt/datalab/conf/provisioning.yml";
 
     String BILLING_SERVICE = "billing.yml";
     //  String BILLING_SERVICE_PROP_PATH = "services/billing-gcp/billing.yml";
 //      String BILLING_SERVICE_PROP_PATH = "services/billing-azure/billing.yml";
-//    String BILLING_SERVICE_PROP_PATH = "services/billing-aws/billing.yml";
-    String BILLING_SERVICE_PROP_PATH = "/opt/datalab/conf/billing.yml";
+    String BILLING_SERVICE_PROP_PATH = "services/billing-aws/billing.yml";
+    //    String BILLING_SERVICE_PROP_PATH = "/opt/datalab/conf/billing.yml";
     String GKE_BILLING_PATH = "/root/billing.yaml";
     String GKE_BILLING_SERVICE = "billing.yml";
-
+    String RESTART_URL = "api/config/restart";
+    String LOCAL_ENDPOINT_NAME = "local";
+    String BASE_CONFIG_URL = "api/config";
+    String BASE_MULTIPLE_CONFIG_URL = "api/config/multiple/";
 
     String SELF_SERVICE_SUPERVISORCTL_RUN_NAME = " ui ";
     String PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME = " provserv ";
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/DynamicChangeProperties.java
similarity index 63%
rename from services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java
rename to services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/DynamicChangeProperties.java
index 6ed7d15..5ae76bd 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/DynamicChangeProperties.java
@@ -1,16 +1,13 @@
-package com.epam.datalab.backendapi.service.impl;
+package com.epam.datalab.properties;
 
 import com.epam.datalab.auth.UserInfo;
-import com.epam.datalab.backendapi.dao.EndpointDAO;
-import com.epam.datalab.backendapi.domain.EndpointDTO;
-import com.epam.datalab.backendapi.modules.ChangePropertiesConst;
-import com.epam.datalab.backendapi.modules.RestartForm;
-import com.epam.datalab.backendapi.resources.dto.YmlDTO;
+import com.epam.datalab.constants.ServiceConsts;
 import com.epam.datalab.exceptions.DynamicChangePropertiesException;
-import com.epam.datalab.exceptions.ResourceNotFoundException;
 import com.epam.datalab.rest.client.RESTService;
+import com.google.inject.name.Named;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
 import javax.inject.Inject;
 import java.io.BufferedWriter;
@@ -28,12 +25,10 @@ import java.util.regex.Pattern;
 @Slf4j
 public class DynamicChangeProperties implements ChangePropertiesConst {
     private final RESTService externalSelfService;
-    private final EndpointDAO endpointDAO;
 
     @Inject
-    public DynamicChangeProperties(RESTService externalSelfService, EndpointDAO endpointDAO) {
+    public DynamicChangeProperties(@Named(ServiceConsts.PROVISIONING_SERVICE_NAME) RESTService externalSelfService) {
         this.externalSelfService = externalSelfService;
-        this.endpointDAO = endpointDAO;
     }
 
     public String getProperties(String path, String name) {
@@ -44,45 +39,38 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
         writeFileFromString(ymlString, name, path);
     }
 
-    public Map<String, String> getPropertiesWithExternal(String endpoint, UserInfo userInfo) {
-        EndpointDTO endpointDTO = findEndpointDTO(endpoint);
+    public Map<String, String> getPropertiesWithExternal(String endpoint, UserInfo userInfo, String url) {
         Map<String, String> properties = new HashMap<>();
-        if (endpoint.equals("local")) {
-            properties.put(SELF_SERVICE, getProperties(SELF_SERVICE_PROP_PATH, SELF_SERVICE));
-            properties.put(PROVISIONING_SERVICE, getProperties(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE));
-            properties.put(BILLING_SERVICE, getProperties(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE));
+        if (endpoint.equals(ChangePropertiesConst.LOCAL_ENDPOINT_NAME)) {
+            properties.put(ChangePropertiesConst.SELF_SERVICE, getProperties(ChangePropertiesConst.SELF_SERVICE_PROP_PATH, ChangePropertiesConst.SELF_SERVICE));
+            properties.put(ChangePropertiesConst.PROVISIONING_SERVICE, getProperties(ChangePropertiesConst.PROVISIONING_SERVICE_PROP_PATH, ChangePropertiesConst.PROVISIONING_SERVICE));
+            properties.put(ChangePropertiesConst.BILLING_SERVICE, getProperties(ChangePropertiesConst.BILLING_SERVICE_PROP_PATH, ChangePropertiesConst.BILLING_SERVICE));
         } else {
             log.info("Trying to read properties, for external endpoint : {} , for user: {}",
                     endpoint, userInfo.getSimpleName());
-            String url = endpointDTO.getUrl() + "/api/config";
-            properties.put(SELF_SERVICE,
-                    externalSelfService.get(url + "/self-service", userInfo.getAccessToken(), String.class));
-            properties.put(PROVISIONING_SERVICE,
+            properties.put(ChangePropertiesConst.SELF_SERVICE, getProperties(ChangePropertiesConst.SELF_SERVICE_PROP_PATH, ChangePropertiesConst.SELF_SERVICE));
+            properties.put(ChangePropertiesConst.PROVISIONING_SERVICE,
                     externalSelfService.get(url + "/provisioning-service", userInfo.getAccessToken(), String.class));
-            properties.put(BILLING_SERVICE,
+            properties.put(ChangePropertiesConst.BILLING_SERVICE,
                     externalSelfService.get(url + "/billing", userInfo.getAccessToken(), String.class));
         }
         return properties;
     }
 
-    public void overwritePropertiesWithExternal(String path, String name, YmlDTO ymlDTO, UserInfo userInfo) {
+    public void overwritePropertiesWithExternal(String path, String name, YmlDTO ymlDTO, UserInfo userInfo,
+                                                String url) {
         log.info("Trying to write {}, for external endpoint : {} , for user: {}",
                 name, ymlDTO.getEndpointName(), userInfo.getSimpleName());
-        EndpointDTO endpoint = findEndpointDTO(ymlDTO.getEndpointName());
-        if (ymlDTO.getEndpointName().equals("local")) {
+        if (ymlDTO.getEndpointName().equals(ChangePropertiesConst.LOCAL_ENDPOINT_NAME)
+                || name.equals(SELF_SERVICE)
+                || name.equals(GKE_SELF_SERVICE)) {
             writeFileFromString(ymlDTO.getYmlString(), name, path);
         } else {
-            String url = endpoint.getUrl() + "/api/config/multiple/" + findMethodName(name);
+            url += findMethodName(name);
             externalSelfService.post(url, ymlDTO.getYmlString(), userInfo.getAccessToken(), String.class);
         }
     }
 
-    private EndpointDTO findEndpointDTO(String endpointName) {
-        return endpointDAO.get(endpointName)
-                .orElseThrow(() -> new ResourceNotFoundException("Endpoint with name " + endpointName
-                        + " not found"));
-    }
-
     public void restart(RestartForm restartForm) {
         try {
             boolean billing = restartForm.isBilling();
@@ -97,12 +85,14 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
         }
     }
 
+    public void restartForExternal(RestartForm restartForm, UserInfo userInfo, String url) {
+        if (restartForm.getEndpoint().equals(LOCAL_ENDPOINT_NAME)) {
+            restart(restartForm);
+        } else {
+            log.info("External request for endpoint {}, for user {}", restartForm.getEndpoint(), userInfo.getSimpleName());
 
-    public void restartForExternal(RestartForm restartForm, UserInfo userInfo) {
-        EndpointDTO endpointDTO = findEndpointDTO(restartForm.getEndpoint());
-        String url = endpointDTO.getUrl() + "/api/config/multiple/restart";
-        log.info("External request for endpoint {}, for user {}", restartForm.getEndpoint(), userInfo.getSimpleName());
-        externalSelfService.post(url, userInfo.getAccessToken(), restartForm, Void.class);
+            externalSelfService.post(url, userInfo.getAccessToken(), restartForm, Void.class);
+        }
     }
 
     private String findMethodName(String name) {
@@ -123,10 +113,10 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
 
 
     private String buildSHRestartCommand(boolean billing, boolean provserv, boolean ui) {
-        StringBuilder stringBuilder = new StringBuilder(SUPERVISORCTL_RESTART_SH_COMMAND);
-        if (billing) stringBuilder.append(BILLING_SERVICE_SUPERVISORCTL_RUN_NAME);
-        if (provserv) stringBuilder.append(PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME);
-        if (ui) stringBuilder.append(SELF_SERVICE_SUPERVISORCTL_RUN_NAME);
+        StringBuilder stringBuilder = new StringBuilder(ChangePropertiesConst.SUPERVISORCTL_RESTART_SH_COMMAND);
+        if (billing) stringBuilder.append(ChangePropertiesConst.BILLING_SERVICE_SUPERVISORCTL_RUN_NAME);
+        if (provserv) stringBuilder.append(ChangePropertiesConst.PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME);
+        if (ui) stringBuilder.append(ChangePropertiesConst.SELF_SERVICE_SUPERVISORCTL_RUN_NAME);
         return stringBuilder.toString();
     }
 
@@ -142,35 +132,35 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
     }
 
     private String hideSecretsAndRemoveLicence(String currentConf) {
-        Matcher m = Pattern.compile(SECRET_REGEX).matcher(currentConf);
+        Matcher m = Pattern.compile(ChangePropertiesConst.SECRET_REGEX).matcher(currentConf);
         List<String> secrets = new ArrayList<>();
         String confWithReplacedSecretConf = removeLicence(currentConf);
         while (m.find()) {
-            String secret = m.group().split(":")[DEFAULT_VALUE_PLACE];
+            String secret = m.group().split(":")[ChangePropertiesConst.DEFAULT_VALUE_PLACE];
             if (!(secret.isEmpty() || secret.trim().isEmpty()))
                 secrets.add(secret);
         }
         for (String secret : secrets) {
-            confWithReplacedSecretConf = confWithReplacedSecretConf.replace(secret, SECRET_REPLACEMENT_FORMAT);
+            confWithReplacedSecretConf = confWithReplacedSecretConf.replace(secret, ChangePropertiesConst.SECRET_REPLACEMENT_FORMAT);
         }
         return confWithReplacedSecretConf;
     }
 
     private String removeLicence(String conf) {
-        return conf.split(LICENCE_REGEX)[conf.split(LICENCE_REGEX).length - 1];
+        return conf.split(ChangePropertiesConst.LICENCE_REGEX)[conf.split(ChangePropertiesConst.LICENCE_REGEX).length - 1];
     }
 
     private void writeFileFromString(String newPropFile, String serviceName, String servicePath) {
         try {
             String oldFile = FileUtils.readFileToString(new File(servicePath), Charset.defaultCharset());
-            changeCHMODE(serviceName, servicePath, DEFAULT_CHMOD, WRITE_CHMOD);
+            changeCHMODE(serviceName, servicePath, ChangePropertiesConst.DEFAULT_CHMOD, ChangePropertiesConst.WRITE_CHMOD);
             BufferedWriter writer = new BufferedWriter(new FileWriter(servicePath));
             log.info("Trying to overwrite {}, file for path {} :", serviceName, servicePath);
             writer.write(addLicence());
             writer.write(checkAndReplaceSecretIfEmpty(newPropFile, oldFile));
             log.info("{} overwritten successfully", serviceName);
             writer.close();
-            changeCHMODE(serviceName, servicePath, WRITE_CHMOD, DEFAULT_CHMOD);
+            changeCHMODE(serviceName, servicePath, ChangePropertiesConst.WRITE_CHMOD, ChangePropertiesConst.DEFAULT_CHMOD);
         } catch (IOException e) {
             log.error("Failed during overwriting {}", serviceName);
             throw new DynamicChangePropertiesException(String.format("Failed during overwriting %s", serviceName));
@@ -179,7 +169,7 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
 
     private void changeCHMODE(String serviceName, String path, String fromMode, String toMode) throws IOException {
         try {
-            String command = String.format(CHANGE_CHMOD_SH_COMMAND_FORMAT, toMode, path);
+            String command = String.format(ChangePropertiesConst.CHANGE_CHMOD_SH_COMMAND_FORMAT, toMode, path);
             log.info("Trying to change chmod for file {} {}->{}", serviceName, fromMode, toMode);
             log.info("Execute command: {}", command);
             Runtime.getRuntime().exec(command).waitFor();
@@ -189,7 +179,7 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
     }
 
     private String addLicence() {
-        return LICENCE;
+        return ChangePropertiesConst.LICENCE;
     }
 
     private String checkAndReplaceSecretIfEmpty(String newPropFile, String oldProf) {
@@ -199,25 +189,29 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
 
     private String replaceEmptySecret(String newPropFile, String oldProf, Map<String, String> emptySecrets) {
         String fileWithReplacedEmptySecrets = newPropFile;
-        Matcher oldProfMatcher = Pattern.compile(SECRET_REGEX).matcher(oldProf);
+        Matcher oldProfMatcher = Pattern.compile(ChangePropertiesConst.SECRET_REGEX).matcher(oldProf);
         while (oldProfMatcher.find()) {
             String[] s = oldProfMatcher.group().split(":");
-            if (emptySecrets.containsKey(s[DEFAULT_NAME_PLACE])) {
-                fileWithReplacedEmptySecrets = fileWithReplacedEmptySecrets.replace(emptySecrets.get(s[DEFAULT_NAME_PLACE]), oldProfMatcher.group());
+            if (emptySecrets.containsKey(s[ChangePropertiesConst.DEFAULT_NAME_PLACE])) {
+                fileWithReplacedEmptySecrets = fileWithReplacedEmptySecrets.replace(emptySecrets.get(s[ChangePropertiesConst.DEFAULT_NAME_PLACE]), oldProfMatcher.group());
             }
         }
         return fileWithReplacedEmptySecrets;
     }
 
     private Map<String, String> findEmptySecret(String newPropFile) {
-        Matcher newPropFileMatcher = Pattern.compile(SECRET_REGEX).matcher(newPropFile);
+        Matcher newPropFileMatcher = Pattern.compile(ChangePropertiesConst.SECRET_REGEX).matcher(newPropFile);
         Map<String, String> emptySecrets = new HashMap<>();
         while (newPropFileMatcher.find()) {
             String[] s = newPropFileMatcher.group().split(":");
-            if (s[DEFAULT_VALUE_PLACE].equals(SECRET_REPLACEMENT_FORMAT)) {
-                emptySecrets.put(s[DEFAULT_NAME_PLACE], newPropFileMatcher.group());
+            if (s[ChangePropertiesConst.DEFAULT_VALUE_PLACE].equals(ChangePropertiesConst.SECRET_REPLACEMENT_FORMAT)) {
+                emptySecrets.put(s[ChangePropertiesConst.DEFAULT_NAME_PLACE], newPropFileMatcher.group());
             }
         }
         return emptySecrets;
     }
+
+    public void restartForExternalForGKE(UserInfo userInfo, RestartForm restartForm) {
+        throw new NotImplementedException();
+    }
 }
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/RestartForm.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/RestartForm.java
similarity index 79%
rename from services/self-service/src/main/java/com/epam/datalab/backendapi/modules/RestartForm.java
rename to services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/RestartForm.java
index 045260d..c399fb5 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/RestartForm.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/RestartForm.java
@@ -1,4 +1,4 @@
-package com.epam.datalab.backendapi.modules;
+package com.epam.datalab.properties;
 
 import lombok.Data;
 
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/YmlDTO.java
similarity index 79%
rename from services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java
rename to services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/YmlDTO.java
index 0287882..5fdd64e 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/YmlDTO.java
@@ -1,4 +1,4 @@
-package com.epam.datalab.backendapi.resources.dto;
+package com.epam.datalab.properties;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import lombok.Data;
diff --git a/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/ProvisioningServiceApplicationConfiguration.java b/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/ProvisioningServiceApplicationConfiguration.java
index 25bdfcc..84ff288 100644
--- a/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/ProvisioningServiceApplicationConfiguration.java
+++ b/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/ProvisioningServiceApplicationConfiguration.java
@@ -194,4 +194,5 @@ public class ProvisioningServiceApplicationConfiguration extends ServiceConfigur
     public CloudConfiguration getCloudConfiguration() {
         return cloudConfiguration;
     }
+
 }
diff --git a/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java b/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java
new file mode 100644
index 0000000..7bc319a
--- /dev/null
+++ b/services/provisioning-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java
@@ -0,0 +1,67 @@
+package com.epam.datalab.backendapi.resources;
+
+import com.epam.datalab.auth.UserInfo;
+import com.epam.datalab.backendapi.ProvisioningServiceApplicationConfiguration;
+import com.epam.datalab.properties.ChangePropertiesConst;
+import com.epam.datalab.properties.DynamicChangeProperties;
+import com.epam.datalab.properties.RestartForm;
+import com.epam.datalab.properties.YmlDTO;
+import io.dropwizard.auth.Auth;
+
+import javax.inject.Inject;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("config")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class ChangePropertiesResource implements ChangePropertiesConst {
+
+    private final DynamicChangeProperties dynamicChangeProperties;
+
+    @Inject
+    public ChangePropertiesResource(DynamicChangeProperties dynamicChangeProperties,
+                                    ProvisioningServiceApplicationConfiguration conf) {
+        this.dynamicChangeProperties = dynamicChangeProperties;
+    }
+
+    @GET
+    @Path("/provisioning-service")
+    public Response getProvisioningServiceProperties(@Auth UserInfo userInfo) {
+        return Response
+                .ok(dynamicChangeProperties.getProperties(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE))
+                .build();
+    }
+
+    @GET
+    @Path("/billing")
+    public Response getBillingServiceProperties(@Auth UserInfo userInfo) {
+        return Response
+                .ok(dynamicChangeProperties.getProperties(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE))
+                .build();
+    }
+
+    @POST
+    @Path("/provisioning-service")
+    public Response overwriteProvisioningServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
+        dynamicChangeProperties.overwriteProperties(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE,
+                ymlDTO.getYmlString());
+        return Response.ok().build();
+    }
+
+    @POST
+    @Path("/billing")
+    public Response overwriteBillingServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
+        dynamicChangeProperties.overwriteProperties(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE, ymlDTO.getYmlString());
+        return Response.ok().build();
+
+    }
+
+    @POST
+    @Path("/restart")
+    public Response restart(@Auth UserInfo userInfo, RestartForm restartForm) {
+        dynamicChangeProperties.restart(restartForm);
+        return Response.ok().build();
+    }
+}
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/SelfServiceApplication.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/SelfServiceApplication.java
index 9c5f166..08ebf1a 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/SelfServiceApplication.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/SelfServiceApplication.java
@@ -46,7 +46,7 @@ import com.epam.datalab.backendapi.resources.SystemInfoResource;
 import com.epam.datalab.backendapi.resources.UserGroupResource;
 import com.epam.datalab.backendapi.resources.UserRoleResource;
 import com.epam.datalab.backendapi.resources.UserSettingsResource;
-import com.epam.datalab.backendapi.resources.admin.ChangePropertiesResource;
+import com.epam.datalab.backendapi.resources.ChangePropertiesResource;
 import com.epam.datalab.backendapi.resources.callback.BackupCallback;
 import com.epam.datalab.backendapi.resources.callback.CheckInactivityCallback;
 import com.epam.datalab.backendapi.resources.callback.ComputationalCallback;
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java
new file mode 100644
index 0000000..e38a2b5
--- /dev/null
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/ChangePropertiesResource.java
@@ -0,0 +1,125 @@
+package com.epam.datalab.backendapi.resources;
+
+import com.epam.datalab.properties.ChangePropertiesConst;
+import com.epam.datalab.properties.DynamicChangeProperties;
+import com.epam.datalab.properties.RestartForm;
+import com.epam.datalab.properties.YmlDTO;
+import com.epam.datalab.auth.UserInfo;
+import com.epam.datalab.backendapi.conf.SelfServiceApplicationConfiguration;
+import com.epam.datalab.backendapi.dao.EndpointDAO;
+import com.epam.datalab.backendapi.domain.EndpointDTO;
+import com.epam.datalab.backendapi.roles.UserRoles;
+import com.epam.datalab.exceptions.ResourceNotFoundException;
+import io.dropwizard.auth.Auth;
+
+import javax.inject.Inject;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("config")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class ChangePropertiesResource implements ChangePropertiesConst {
+
+    private final EndpointDAO endpointDAO;
+    private final DynamicChangeProperties dynamicChangeProperties;
+    private final String deployedOn;
+
+    @Inject
+    public ChangePropertiesResource(EndpointDAO endpointDAO, DynamicChangeProperties dynamicChangeProperties,
+                                    SelfServiceApplicationConfiguration selfServiceApplicationConfiguration) {
+        this.endpointDAO = endpointDAO;
+        this.dynamicChangeProperties = dynamicChangeProperties;
+        deployedOn = selfServiceApplicationConfiguration.getDeployed();
+    }
+
+    @GET
+    @Path("/multiple")
+    public Response getAllPropertiesForEndpoint(@Auth UserInfo userInfo, @QueryParam("endpoint") String endpoint) {
+        if (UserRoles.isAdmin(userInfo)) {
+            String url = findEndpointDTO(endpoint).getUrl() + ChangePropertiesConst.BASE_CONFIG_URL;
+            return Response
+                    .ok(dynamicChangeProperties.getPropertiesWithExternal(endpoint, userInfo, url))
+                    .build();
+        } else {
+            return Response
+                    .status(Response.Status.FORBIDDEN)
+                    .build();
+        }
+    }
+
+    @POST
+    @Path("/multiple/self-service")
+    public Response overwriteExternalSelfServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
+        if (UserRoles.isAdmin(userInfo)) {
+            if (deployedOn.equals("GKE")) {
+                dynamicChangeProperties.overwritePropertiesWithExternal(GKE_SELF_SERVICE_PATH, GKE_SELF_SERVICE,
+                        ymlDTO, userInfo, null);
+            } else {
+                dynamicChangeProperties.overwritePropertiesWithExternal(SELF_SERVICE_PROP_PATH, SELF_SERVICE,
+                        ymlDTO, userInfo, null);
+            }
+            return Response.status(Response.Status.OK).build();
+        } else {
+            return Response
+                    .status(Response.Status.FORBIDDEN)
+                    .build();
+        }
+    }
+
+    @POST
+    @Path("/multiple/provisioning-service")
+    public Response overwriteExternalProvisioningServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
+        if (UserRoles.isAdmin(userInfo)) {
+            String url = findEndpointDTO(ymlDTO.getEndpointName()).getUrl() + ChangePropertiesConst.BASE_MULTIPLE_CONFIG_URL;
+            dynamicChangeProperties.overwritePropertiesWithExternal(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE,
+                    ymlDTO, userInfo, url);
+            return Response.status(Response.Status.OK).build();
+        } else {
+            return Response
+                    .status(Response.Status.FORBIDDEN)
+                    .build();
+        }
+    }
+
+    @POST
+    @Path("/multiple/billing")
+    public Response overwriteExternalBillingProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
+        if (UserRoles.isAdmin(userInfo)) {
+            String url = findEndpointDTO(ymlDTO.getEndpointName()).getUrl() + ChangePropertiesConst.BASE_MULTIPLE_CONFIG_URL;
+            dynamicChangeProperties.overwritePropertiesWithExternal(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE,
+                    ymlDTO, userInfo, url);
+            return Response.status(Response.Status.OK).build();
+        } else {
+            return Response
+                    .status(Response.Status.FORBIDDEN)
+                    .build();
+        }
+    }
+
+
+    @POST
+    @Path("/multiple/restart")
+    public Response restartWithExternal(@Auth UserInfo userInfo, RestartForm restartForm) {
+        if (UserRoles.isAdmin(userInfo)) {
+            if (deployedOn.equals("GKE")) {
+                dynamicChangeProperties.restartForExternalForGKE(userInfo, restartForm);
+            } else {
+                String url = findEndpointDTO(restartForm.getEndpoint()).getUrl() + ChangePropertiesConst.RESTART_URL;
+                dynamicChangeProperties.restartForExternal(restartForm, userInfo, url);
+            }
+            return Response.ok().build();
+        } else {
+            return Response
+                    .status(Response.Status.FORBIDDEN)
+                    .build();
+        }
+    }
+
+    private EndpointDTO findEndpointDTO(String endpointName) {
+        return endpointDAO.get(endpointName)
+                .orElseThrow(() -> new ResourceNotFoundException("Endpoint with name " + endpointName
+                        + " not found"));
+    }
+}
\ No newline at end of file
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/admin/ChangePropertiesResource.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/admin/ChangePropertiesResource.java
deleted file mode 100644
index 133b17e..0000000
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/admin/ChangePropertiesResource.java
+++ /dev/null
@@ -1,199 +0,0 @@
-package com.epam.datalab.backendapi.resources.admin;
-
-import com.epam.datalab.auth.UserInfo;
-import com.epam.datalab.backendapi.conf.SelfServiceApplicationConfiguration;
-import com.epam.datalab.backendapi.modules.ChangePropertiesConst;
-import com.epam.datalab.backendapi.modules.RestartForm;
-import com.epam.datalab.backendapi.resources.dto.YmlDTO;
-import com.epam.datalab.backendapi.roles.UserRoles;
-import com.epam.datalab.backendapi.service.impl.DynamicChangeProperties;
-import io.dropwizard.auth.Auth;
-
-import javax.inject.Inject;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("config")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class ChangePropertiesResource implements ChangePropertiesConst {
-
-    private final DynamicChangeProperties dynamicChangeProperties;
-    private final String deployedOn;
-
-    @Inject
-    public ChangePropertiesResource(DynamicChangeProperties dynamicChangeProperties, SelfServiceApplicationConfiguration selfServiceApplicationConfiguration) {
-        this.dynamicChangeProperties = dynamicChangeProperties;
-        deployedOn = selfServiceApplicationConfiguration.getDeployed();
-    }
-
-    @GET
-    @Path("/self-service")
-    public Response getSelfServiceProperties(@Auth UserInfo userInfo) {
-        if (UserRoles.isAdmin(userInfo)) {
-            return Response
-                    .ok(deployedOn.equals("onPremise") ?
-                            dynamicChangeProperties.getProperties(SELF_SERVICE_PROP_PATH, SELF_SERVICE) :
-                            dynamicChangeProperties.getProperties(GKE_SELF_SERVICE_PATH, GKE_SELF_SERVICE))
-                    .build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @GET
-    @Path("/provisioning-service")
-    public Response getProvisioningServiceProperties(@Auth UserInfo userInfo) {
-        if (UserRoles.isAdmin(userInfo)) {
-            return Response
-                    .ok(dynamicChangeProperties.getProperties(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE))
-                    .build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @GET
-    @Path("/billing")
-    public Response getBillingServiceProperties(@Auth UserInfo userInfo) {
-        if (UserRoles.isAdmin(userInfo)) {
-            return Response
-                    .ok(deployedOn.equals("onPremise") ?
-                            dynamicChangeProperties.getProperties(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE) :
-                            dynamicChangeProperties.getProperties(GKE_BILLING_PATH, GKE_BILLING_SERVICE))
-                    .build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/self-service")
-    public Response overwriteSelfServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwriteProperties(SELF_SERVICE_PROP_PATH, SELF_SERVICE, ymlDTO.getYmlString());
-            return Response.ok().build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/provisioning-service")
-    public Response overwriteProvisioningServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwriteProperties(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE,
-                    ymlDTO.getYmlString());
-            return Response.ok().build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/billing")
-    public Response overwriteBillingServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwriteProperties(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE, ymlDTO.getYmlString());
-            return Response.ok().build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("restart")
-    public Response restart(@Auth UserInfo userInfo, RestartForm restartForm) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.restart(restartForm);
-            return Response.ok().build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @GET
-    @Path("/multiple")
-    public Response getAllPropertiesForEndpoint(@Auth UserInfo userInfo, @QueryParam("endpoint") String endpoint) {
-        if (UserRoles.isAdmin(userInfo)) {
-            return Response
-                    .ok(dynamicChangeProperties.getPropertiesWithExternal(endpoint, userInfo))
-                    .build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/multiple/self-service")
-    public Response overwriteExternalSelfServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwritePropertiesWithExternal(SELF_SERVICE_PROP_PATH, SELF_SERVICE,
-                    ymlDTO, userInfo);
-            return Response.status(Response.Status.OK).build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/multiple/provisioning-service")
-    public Response overwriteExternalProvisioningServiceProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwritePropertiesWithExternal(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE,
-                    ymlDTO, userInfo);
-            return Response.status(Response.Status.OK).build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-    @POST
-    @Path("/multiple/billing")
-    public Response overwriteExternalBillingProperties(@Auth UserInfo userInfo, YmlDTO ymlDTO) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.overwritePropertiesWithExternal(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE,
-                    ymlDTO, userInfo);
-            return Response.status(Response.Status.OK).build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-
-
-    @POST
-    @Path("/multiple/restart")
-    public Response restartWithExternal(@Auth UserInfo userInfo, RestartForm restartForm) {
-        if (UserRoles.isAdmin(userInfo)) {
-            dynamicChangeProperties.restartForExternal(restartForm, userInfo);
-            return Response.ok().build();
-        } else {
-            return Response
-                    .status(Response.Status.FORBIDDEN)
-                    .build();
-        }
-    }
-}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org