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/19 08:30:18 UTC
[incubator-datalab] branch DATALAB-2228 updated: [DATALAB-2228] -
refactoring
This is an automated email from the ASF dual-hosted git repository.
ykinash pushed a commit to branch DATALAB-2228
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
The following commit(s) were added to refs/heads/DATALAB-2228 by this push:
new d5088ad [DATALAB-2228] - refactoring
d5088ad is described below
commit d5088adc8626f40c14b450d3fa30ab0ae486bad9
Author: KinashYurii <ur...@gmail.com>
AuthorDate: Fri Feb 19 10:23:17 2021 +0200
[DATALAB-2228] - refactoring
---
.../backendapi/modules/ChangePropertiesConst.java | 3 +-
.../resources/admin/ChangePropertiesResource.java | 46 +++++++++++++++++++++-
.../datalab/backendapi/resources/dto/YmlDTO.java | 2 +
.../service/impl/DynamicChangeProperties.java | 27 ++++++-------
4 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java
index cfcd923..8c88337 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/modules/ChangePropertiesConst.java
@@ -1,7 +1,8 @@
package com.epam.datalab.backendapi.modules;
public interface ChangePropertiesConst {
-
+ // /root/self-service.yaml
+ // /root/billing.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";
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
index ff367d4..ac82c1b 100644
--- 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
@@ -124,7 +124,7 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
@GET
@Path("/multiple")
- public Response getAllSelfServiceProperties(@Auth UserInfo userInfo, @QueryParam("endpoint") String endpoint) {
+ public Response getAllPropertiesForEndpoint(@Auth UserInfo userInfo, @QueryParam("endpoint") String endpoint) {
if (UserRoles.isAdmin(userInfo)) {
return Response
.ok(dynamicChangeProperties.getPropertiesWithExternal(endpoint, userInfo))
@@ -135,4 +135,46 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
.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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java
index 7d137eb..0287882 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/resources/dto/YmlDTO.java
@@ -1,10 +1,12 @@
package com.epam.datalab.backendapi.resources.dto;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
@Data
public class YmlDTO {
+ @JsonIgnoreProperties
private String endpointName;
private String ymlString;
}
\ No newline at end of file
diff --git a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java
index 888f717..f317689 100644
--- a/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java
+++ b/services/self-service/src/main/java/com/epam/datalab/backendapi/service/impl/DynamicChangeProperties.java
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
@Slf4j
public class DynamicChangeProperties implements ChangePropertiesConst {
@@ -66,21 +65,17 @@ public class DynamicChangeProperties implements ChangePropertiesConst {
return properties;
}
- public void overwritePropertiesWithExternal(String path, String name, Map<String, YmlDTO> ymlDTOS,
- UserInfo userInfo) {
- List<EndpointDTO> allEndpoints = endpointDAO.getEndpointsWithStatus("ACTIVE");
- Map<EndpointDTO, String> endpointsToChange = allEndpoints.stream()
- .filter(e -> ymlDTOS.containsKey(e.getName()))
- .filter(e -> !e.getName().equals("local"))
- .collect(Collectors.toMap(e -> e, e -> ymlDTOS.get(e.getName()).getYmlString()));
- endpointsToChange.forEach((endpoint, ymlString) -> {
- log.info("Trying to write {}, for external endpoint : {} , for user: {}",
- name, endpoint.getName(), userInfo.getSimpleName());
- String url = endpoint.getUrl() + "/api/admin/" + findMethodName(name);
- externalSelfService.post(url, ymlString, userInfo.getAccessToken(), String.class);
- });
- if (ymlDTOS.containsKey("local")) {
- overwriteProperties(path, name, ymlDTOS.get("local").getYmlString());
+ public void overwritePropertiesWithExternal(String path, String name, YmlDTO ymlDTO, UserInfo userInfo) {
+ log.info("Trying to write {}, for external endpoint : {} , for user: {}",
+ name, ymlDTO.getEndpointName(), userInfo.getSimpleName());
+ EndpointDTO endpoint = endpointDAO.get(ymlDTO.getEndpointName())
+ .orElseThrow(() -> new ResourceNotFoundException("Endpoint with name " + ymlDTO.getEndpointName()
+ + " not found"));
+ if (ymlDTO.getEndpointName().equals("local")) {
+ writeFileFromString(ymlDTO.getYmlString(), name, path);
+ } else {
+ String url = endpoint.getUrl() + "/api/config/" + findMethodName(name);
+ externalSelfService.post(url, ymlDTO.getYmlString(), userInfo.getAccessToken(), String.class);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org