提交 b75a6a7b 编写于 作者: NoSubject's avatar NoSubject

Merge remote-tracking branch 'origin/develop' into develop

......@@ -475,6 +475,10 @@ public class Query extends ConfigObject {
}
}
public String getHdfsDirectoryPath() {
return this.adjustHdfsDirectoryPath();
}
private String adjustHdfsDirectoryPath() {
return StringUtils.startsWith(this.hdfsDirectoryPath, "/") ? this.hdfsDirectoryPath
: "/" + hdfsDirectoryPath;
......
......@@ -25,6 +25,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
......@@ -182,7 +183,7 @@ public class BaseTools {
boolean Syncflag = false;
Nodes nodes = Config.nodes();
// 同步config文件
if (Config.general().getConfigApiEnable()) {
if (BooleanUtils.isTrue(Config.general().getConfigApiEnable())) {
for (String node : nodes.keySet()) {
if (nodes.get(node).getApplication().getEnable() || nodes.get(node).getCenter().getEnable()) {
Syncflag = executeSyncFile(syncFilePath, node, nodes.get(node).nodeAgentPort());
......@@ -226,7 +227,7 @@ public class BaseTools {
dos.write(bytes, 0, length);
dos.flush();
}
logger.info("同步文件:" + syncFilePath + "end.");
logger.info("同步文件:" + syncFilePath + " end.");
} finally {
dos.close();
......
......@@ -32,7 +32,6 @@ import java.util.regex.Matcher;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Scheduler;
import com.x.base.core.project.config.ApplicationServer;
import com.x.base.core.project.config.CenterServer;
......@@ -44,7 +43,6 @@ import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.Crypto;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.StringTools;
import com.x.server.console.action.ActionConfig;
import com.x.server.console.action.ActionControl;
import com.x.server.console.action.ActionSetPassword;
import com.x.server.console.action.ActionVersion;
......@@ -123,7 +121,7 @@ public class Main {
public static void main(String[] args) throws Exception {
init();
if (null == Config.currentNode()) {
throw new Exception("无法找到当前节点,请检查config/node_{name}.json与local/node.cfg文件内容中的名称是否一致.");
throw new IllegalStateException("无法找到当前节点,请检查config/node_{name}.json与local/node.cfg文件内容中的名称是否一致.");
}
swapCommandThread.start();
consoleCommandThread.start();
......@@ -134,8 +132,8 @@ public class Main {
nodeAgent.start();
}
SchedulerBuilder schedulerBuilder = new SchedulerBuilder();
Scheduler scheduler = schedulerBuilder.start();
// SchedulerBuilder schedulerBuilder = new SchedulerBuilder();
// Scheduler scheduler = schedulerBuilder.start();
if (BooleanUtils.isTrue(Config.currentNode().autoStart())) {
startAll();
......@@ -217,12 +215,8 @@ public class Main {
matcher = CommandFactory.setPassword_pattern.matcher(cmd);
if (matcher.find()) {
setPassword(matcher.group(1), matcher.group(2));
if (config()) {
break;
} else {
continue;
}
}
matcher = CommandFactory.control_pattern.matcher(cmd);
if (matcher.find()) {
......@@ -242,9 +236,6 @@ public class Main {
}
System.out.println("unknown command:" + cmd);
}
// 关闭定时器
scheduler.shutdown();
// SystemOutErrorSideCopyBuilder.stop();
}
private static void version() {
......@@ -255,15 +246,6 @@ public class Main {
}
}
private static boolean config() {
try {
return new ActionConfig().execute();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void startDataServer() {
try {
if (BooleanUtils.isTrue(Servers.dataServerIsRunning())) {
......
package com.x.server.console.action;
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.tools.JarTools;
public class ActionConfig extends ActionBase {
public boolean execute() throws Exception {
if (StringUtils.equalsIgnoreCase(Config.node(), Config.resource_node_centersPirmaryNode())) {
byte[] bytes = this.getZip();
this.unzip(bytes);
System.out.println("synchronize config success, should to restart server.");
return true;
} else {
System.out.println("config command only synchronize config from primary center.");
return false;
}
}
@SuppressWarnings("deprecation")
private byte[] getZip() throws Exception {
String address = Config.url_x_program_center_jaxrs("config");
URL url = new URL(address);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", HttpMediaType.APPLICATION_JSON_UTF_8);
EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher(),
Config.person().getEncryptType());
connection.setRequestProperty(Config.person().getTokenName(), effectivePerson.getToken());
connection.setRequestMethod("GET");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
String json = null;
try (InputStream input = connection.getInputStream()) {
json = IOUtils.toString(input);
}
JsonElement jsonElement = XGsonBuilder.instance().fromJson(json, JsonElement.class);
if (jsonElement.isJsonObject()) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject.has("type")) {
if (StringUtils.equals("success", jsonObject.get("type").getAsString())) {
String value = jsonObject.get("data").getAsString();
byte[] bytes = Base64.decodeBase64(value);
return bytes;
} else {
throw new Exception("return type not success.");
}
} else {
throw new Exception("can not read return type.");
}
} else {
throw new Exception("return object is not jsonObject.");
}
}
private void unzip(byte[] bytes) throws Exception {
File dir = new File(Config.base(), "config");
FileUtils.forceMkdir(dir);
JarTools.unjar(bytes, "", dir, true);
}
}
\ No newline at end of file
......@@ -14,10 +14,11 @@ import com.x.base.core.project.config.DataServer;
import com.x.base.core.project.config.Token;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.server.console.server.Servers;
public class ActionSetPassword extends ActionBase {
private static Logger logger = LoggerFactory.getLogger(ActionSetPassword.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ActionSetPassword.class);
public boolean execute(String oldPassword, String newPassword) throws Exception {
/** 如果初始密码没有修改就设置为初始密码 */
......@@ -25,13 +26,13 @@ public class ActionSetPassword extends ActionBase {
oldPassword = Token.initPassword;
}
if (!StringUtils.equals(Config.token().getPassword(), oldPassword)) {
logger.print("old password not match.");
LOGGER.print("old password not match.");
return false;
}
this.changeInternalDataServerPassword(oldPassword, newPassword);
Config.token().setPassword(newPassword);
Config.token().save();
logger.print("The initial manager password has been modified.");
LOGGER.print("The initial manager password has been modified.");
return true;
}
......@@ -39,7 +40,7 @@ public class ActionSetPassword extends ActionBase {
org.h2.Driver.load();
for (Entry<String, DataServer> en : Config.nodes().dataServers().entrySet()) {
DataServer o = en.getValue();
if (BooleanUtils.isTrue(o.getEnable())) {
if (BooleanUtils.isTrue(o.getEnable()) && (!Config.externalDataSources().enable())) {
try (Connection conn = DriverManager.getConnection(
"jdbc:h2:tcp://" + en.getKey() + ":" + o.getTcpPort() + "/X", "sa", oldPassword)) {
RunScript.execute(conn, new StringReader("ALTER USER SA SET PASSWORD '" + newPassword + "'"));
......
......@@ -107,7 +107,7 @@ class ActionChangePassword extends BaseAction {
org.h2.Driver.load();
for (Entry<String, DataServer> en : Config.nodes().dataServers().entrySet()) {
DataServer o = en.getValue();
if (BooleanUtils.isTrue(o.getEnable())) {
if (BooleanUtils.isTrue(o.getEnable()) && (!Config.externalDataSources().enable())) {
try (Connection conn = DriverManager.getConnection(
"jdbc:h2:tcp://" + en.getKey() + ":" + o.getTcpPort() + "/X", "sa", oldPassword)) {
RunScript.execute(conn, new StringReader("ALTER USER SA SET PASSWORD '" + newPassword + "'"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册