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/01/04 12:10:46 UTC
[incubator-datalab] 02/02: [DATALAB-2203] - added change chmode.
This is an automated email from the ASF dual-hosted git repository.
ykinash pushed a commit to branch DATALAB-2178
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
commit d61356980ee660b32f4ade7de6cf3f26f51d921c
Author: KinashYurii <ur...@gmail.com>
AuthorDate: Mon Jan 4 14:09:45 2021 +0200
[DATALAB-2203] - added change chmode.
---
.../service/impl/DynamicChangeProperties.java | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
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 76c428c..2e1950a 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
@@ -35,6 +35,8 @@ public class DynamicChangeProperties {
private static final String SECRET_REGEX = "((.*)[sS]ecret(.*)|password): (.*)";
private static final String SECRET_REPLACEMENT_FORMAT = " ***********";
private static final String SH_COMMAND = "sudo supervisorctl restart";
+ private static final String DEFAULT_CHMODE = "644";
+ private static final String WRITE_CHMODE = "777";
private static final String LICENCE =
"# *****************************************************************************\n" +
@@ -93,7 +95,7 @@ public class DynamicChangeProperties {
public static void restart(boolean billing, boolean provserv, boolean ui) {
try {
- String shCommand = buildSHCommand(billing, provserv, ui);
+ String shCommand = buildSHREstartCommand(billing, provserv, ui);
log.info("Tying to restart ui: {}, provserv: {}, billing: {}, with command: {}", ui,
provserv, billing, shCommand);
Runtime.getRuntime().exec(shCommand).waitFor();
@@ -104,7 +106,7 @@ public class DynamicChangeProperties {
}
}
- private static String buildSHCommand(boolean billing, boolean provserv, boolean ui) {
+ private static String buildSHREstartCommand(boolean billing, boolean provserv, boolean ui) {
StringBuilder stringBuilder = new StringBuilder(SH_COMMAND);
if (billing) stringBuilder.append(BILLING_SERVICE_SUPERVISORCTL_RUN_NAME);
if (provserv) stringBuilder.append(PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME);
@@ -114,7 +116,7 @@ public class DynamicChangeProperties {
private static String readFileAsString(String selfServicePropPath, String serviceName) {
try {
- log.trace("Trying to read self-service.yml, file from path {} :", selfServicePropPath);
+ log.info("Trying to read self-service.yml, file from path {} :", selfServicePropPath);
String currentConf = FileUtils.readFileToString(new File(selfServicePropPath), Charset.defaultCharset());
return hideSecretsAndRemoveLicence(currentConf);
} catch (IOException e) {
@@ -143,16 +145,28 @@ public class DynamicChangeProperties {
private static void writeFileFromString(String newPropFile, String serviceName, String servicePath) {
try {
String oldFile = FileUtils.readFileToString(new File(servicePath), Charset.defaultCharset());
+ changeCHMODE(serviceName, DEFAULT_CHMODE, WRITE_CHMODE);
BufferedWriter writer = new BufferedWriter(new FileWriter(servicePath));
- log.trace("Trying to overwrite {}, file for path {} :", serviceName, 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, WRITE_CHMODE, DEFAULT_CHMODE);
} catch (IOException e) {
log.error("Failed during overwriting {}", serviceName);
throw new DynamicChangePropertiesException(String.format("Failed during overwriting %s", serviceName));
}
+
+ }
+
+ private static void changeCHMODE(String serviceName, String writeChmode, String defaultChmode) throws IOException {
+ try {
+ log.info("Trying to change chmode for file {} {}->{}", serviceName, writeChmode, defaultChmode);
+ Runtime.getRuntime().exec("sudo chmode " + defaultChmode).waitFor();
+ } catch (InterruptedException e) {
+ log.error("Failed change chmode for file {} {}->{}", serviceName, writeChmode, defaultChmode);
+ }
}
private static String addLicence() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org