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/04/19 06:42:57 UTC
[incubator-datalab] 01/02: [DATALAB-2314] - change path
This is an automated email from the ASF dual-hosted git repository.
ykinash pushed a commit to branch DATALAB-2314
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
commit 5a44f677ebb2f48459c112e20a8e346cd7eee23e
Author: KinashYurii <ur...@gmail.com>
AuthorDate: Mon Apr 12 14:28:29 2021 +0300
[DATALAB-2314] - change path
---
.../datalab/properties/ChangePropertiesConst.java | 2 +-
.../properties/ExternalChangeProperties.java | 51 ++++++++++++++--------
.../resources/ChangePropertiesResource.java | 20 +++++++++
.../resources/ChangePropertiesResource.java | 27 +++++++-----
4 files changed, 71 insertions(+), 29 deletions(-)
diff --git a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
index 42c96ea..b246276 100644
--- a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
@@ -20,7 +20,7 @@ public interface ChangePropertiesConst {
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 EXTERNAL_OVERWRITE_URL = "/api/config/";
String SELF_SERVICE_SUPERVISORCTL_RUN_NAME = " ui ";
String PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME = " provserv ";
diff --git a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ExternalChangeProperties.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ExternalChangeProperties.java
index 8e7fcf3..b8bb42d 100644
--- a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ExternalChangeProperties.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ExternalChangeProperties.java
@@ -3,23 +3,26 @@ package com.epam.datalab.properties;
import com.epam.datalab.auth.UserInfo;
import com.epam.datalab.constants.ServiceConsts;
import com.epam.datalab.rest.client.RESTService;
-import com.google.inject.name.Named;
import lombok.extern.slf4j.Slf4j;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import javax.inject.Inject;
+import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class ExternalChangeProperties implements ChangePropertiesConst {
- private final RESTService externalSelfService;
+ private final RESTService externalService;
+ private final RESTService provService;
private final ChangePropertiesService changePropertiesService;
@Inject
- public ExternalChangeProperties(@Named(ServiceConsts.PROVISIONING_SERVICE_NAME)
- RESTService externalSelfService, ChangePropertiesService changePropertiesService) {
- this.externalSelfService = externalSelfService;
+ public ExternalChangeProperties(RESTService externalService,
+ @Named(ServiceConsts.PROVISIONING_SERVICE_NAME) RESTService provService,
+ ChangePropertiesService changePropertiesService) {
+ this.externalService = externalService;
+ this.provService = provService;
this.changePropertiesService = changePropertiesService;
}
@@ -33,23 +36,32 @@ public class ExternalChangeProperties implements ChangePropertiesConst {
public Map<String, String> getPropertiesWithExternal(String endpoint, UserInfo userInfo, String url) {
Map<String, String> properties = new HashMap<>();
- 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));
+ log.info("TEST LOG!!!: endpoint: {}, local const: {}",
+ endpoint, LOCAL_ENDPOINT_NAME);
+ if (endpoint.equals(LOCAL_ENDPOINT_NAME)) {
+ log.info("TEST LOG!!!: 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));
+
} else {
+ log.info("TEST LOG!!!: EXTERNAL");
log.info("Trying to read properties, for external endpoint : {} , for user: {}",
endpoint, userInfo.getSimpleName());
- properties.put(ChangePropertiesConst.PROVISIONING_SERVICE,
- externalSelfService.get(url + "/provisioning-service", userInfo.getAccessToken(), String.class));
- properties.put(ChangePropertiesConst.BILLING_SERVICE,
- externalSelfService.get(url + "/billing", userInfo.getAccessToken(), String.class));
+ String provPath = url + "/provisioning-service";
+ log.info("TEST LOG!!!: provPath: {}", provPath);
+ properties.put(PROVISIONING_SERVICE,
+ externalService.get(provPath, userInfo.getAccessToken(), String.class));
+ String billPath = url + "/billing";
+ log.info("TEST LOG!!!: provPath: {}", provPath);
+ properties.put(BILLING_SERVICE,
+ externalService.get(billPath, userInfo.getAccessToken(), String.class));
}
return properties;
}
- public void overwritePropertiesWithExternal(String path, String name, YmlDTO ymlDTO, UserInfo userInfo,
- String url) {
+ 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());
if (ymlDTO.getEndpointName().equals(ChangePropertiesConst.LOCAL_ENDPOINT_NAME)
@@ -57,18 +69,23 @@ public class ExternalChangeProperties implements ChangePropertiesConst {
|| name.equals(GKE_SELF_SERVICE)) {
changePropertiesService.writeFileFromString(ymlDTO.getYmlString(), name, path);
} else {
+
url += findMethodName(name);
- externalSelfService.post(url, ymlDTO.getYmlString(), userInfo.getAccessToken(), String.class);
+ log.info("TEST LOG: on external call method , url for the next step: {}", url);
+ externalService.post(url, ymlDTO.getYmlString(), userInfo.getAccessToken(), String.class);
}
}
public void restartForExternal(RestartForm restartForm, UserInfo userInfo, String url) {
if (restartForm.getEndpoint().equals(LOCAL_ENDPOINT_NAME)) {
+ provService.post(url, userInfo.getAccessToken(), restartForm, Void.class);
+ restartForm.setProvserv(false);
+ restartForm.setBilling(false);
changePropertiesService.restart(restartForm);
} else {
log.info("External request for endpoint {}, for user {}", restartForm.getEndpoint(), userInfo.getSimpleName());
- externalSelfService.post(url, userInfo.getAccessToken(), restartForm, Void.class);
+ externalService.post(url, userInfo.getAccessToken(), restartForm, Void.class);
}
}
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
index 2b8306d..e5a0180 100644
--- 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
@@ -80,6 +80,21 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
private void checkResponseFiles(RestartForm restartForm) {
List<WatchItem> watchItems = new ArrayList<>();
//or check getFileHandlerCallback().getId()/uuid
+
+ FolderListener.getListeners().get(0).getItemList().get(0).getFileHandlerCallback().getUUID();
+ FolderListener.getListeners().stream()
+ .map(FolderListener::getItemList)
+ .forEach(
+ x -> {
+ for (int i = 0; i < x.size(); i++) {
+ log.info("TEST LOG!!!" +
+ "watchItem:{}, fileHandlerCallBack: {}, uuid: {}",
+ x.get(i), x.get(i).getFileHandlerCallback(),
+ x.get(i).getFileHandlerCallback().getId());
+ }
+ }
+ );
+
boolean isNoneFinishedRequests = FolderListener.getListeners().stream()
.filter(FolderListener::isAlive)
.filter(FolderListener::isListen)
@@ -90,13 +105,18 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
" Provisioning restart is denied", watchItems);
restartForm.setProvserv(false);
}
+
}
private Predicate<WatchItemList> findAnyInStatus(List<WatchItem> watchItems,
List<WatchItem.ItemStatus> statuses) {
+ log.info("TEST LOG!!!" +
+ "watchItems:{}, statuses to find: {}", watchItems, statuses);
return watchItemList -> {
for (int i = 0; i < watchItemList.size(); i++) {
if (statuses.contains(watchItemList.get(i).getStatus())) {
+ log.info("TEST LOG!!!" +
+ "watchItem:{}, status: {}", watchItemList.get(i), watchItemList.get(i).getStatus());
watchItems.add(watchItemList.get(i));
}
}
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
index bc03f15..86942b0 100644
--- 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
@@ -1,16 +1,16 @@
package com.epam.datalab.backendapi.resources;
-import com.epam.datalab.properties.ChangePropertiesConst;
-import com.epam.datalab.properties.ExternalChangeProperties;
-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 com.epam.datalab.properties.ChangePropertiesConst;
+import com.epam.datalab.properties.ExternalChangeProperties;
+import com.epam.datalab.properties.RestartForm;
+import com.epam.datalab.properties.YmlDTO;
import io.dropwizard.auth.Auth;
+import lombok.extern.slf4j.Slf4j;
import javax.inject.Inject;
import javax.ws.rs.*;
@@ -20,6 +20,7 @@ import javax.ws.rs.core.Response;
@Path("/config")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
+@Slf4j
public class ChangePropertiesResource implements ChangePropertiesConst {
private final EndpointDAO endpointDAO;
@@ -38,7 +39,8 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
@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;
+ String url = findEndpointDTOUrl(endpoint) + ChangePropertiesConst.BASE_CONFIG_URL;
+ log.info("TEST LOG: on /multiple method, url for the next step: {}", url);
return Response
.ok(externalChangeProperties.getPropertiesWithExternal(endpoint, userInfo, url))
.build();
@@ -72,7 +74,8 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
@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;
+ String url = findEndpointDTOUrl(ymlDTO.getEndpointName()) + EXTERNAL_OVERWRITE_URL;
+ log.info("TEST LOG: on /multiple method, url for the next step: {}", url);
externalChangeProperties.overwritePropertiesWithExternal(PROVISIONING_SERVICE_PROP_PATH, PROVISIONING_SERVICE,
ymlDTO, userInfo, url);
return Response.status(Response.Status.OK).build();
@@ -87,7 +90,8 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
@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;
+ String url = findEndpointDTOUrl(ymlDTO.getEndpointName()) + EXTERNAL_OVERWRITE_URL;
+ log.info("TEST LOG: on /multiple method, url for the next step: {}", url);
externalChangeProperties.overwritePropertiesWithExternal(BILLING_SERVICE_PROP_PATH, BILLING_SERVICE,
ymlDTO, userInfo, url);
return Response.status(Response.Status.OK).build();
@@ -106,7 +110,8 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
if (deployedOn.equals("GKE")) {
externalChangeProperties.restartForExternalForGKE(userInfo, restartForm);
} else {
- String url = findEndpointDTO(restartForm.getEndpoint()).getUrl() + ChangePropertiesConst.RESTART_URL;
+ String url = findEndpointDTOUrl(restartForm.getEndpoint())
+ + ChangePropertiesConst.RESTART_URL;
externalChangeProperties.restartForExternal(restartForm, userInfo, url);
}
return Response.ok().build();
@@ -117,9 +122,9 @@ public class ChangePropertiesResource implements ChangePropertiesConst {
}
}
- private EndpointDTO findEndpointDTO(String endpointName) {
+ private String findEndpointDTOUrl(String endpointName) {
return endpointDAO.get(endpointName)
.orElseThrow(() -> new ResourceNotFoundException("Endpoint with name " + endpointName
- + " not found"));
+ + " not found")).getUrl();
}
}
\ 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