Skip to content

Commit a7bc483

Browse files
committed
Optimize account opening script
1 parent 59d06db commit a7bc483

File tree

11 files changed

+128
-104
lines changed

11 files changed

+128
-104
lines changed

dss-server/src/main/resources/linkis.properties

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
wds.linkis.test.mode=true
1919

20-
wds.linkis.server.mybatis.datasource.url=jdbc:mysql://0.0.0.0:3306/dss
20+
wds.linkis.server.mybatis.datasource.url=jdbc:mysql://0.0.0.1:3306/linkis?characterEncoding=UTF-8
2121

2222
wds.linkis.server.mybatis.datasource.username=
2323

@@ -38,28 +38,34 @@ wds.linkis.server.mybatis.typeAliasesPackage=com.webank.wedatasphere.dss.server.
3838
wds.linkis.server.mybatis.BasePackage=com.webank.wedatasphere.dss.server.dao,com.webank.wedatasphere.dss.application.dao
3939

4040
##azkaban
41-
wds.dss.appjoint.scheduler.azkaban.address=http://127.0.0.1:8091
41+
wds.dss.appjoint.scheduler.azkaban.address=http://0.0.0.0:8081
4242

4343
wds.linkis.gateway.ip=127.0.0.1
4444
wds.linkis.gateway.port=9001
4545

4646
wds.dss.appjoint.scheduler.project.store.dir=file:///appcom/tmp/wds/scheduler
47-
wds.linkis.super.user.name=
48-
wds.linkis.workspace.user.root.path=
49-
wds.linkis.hdfs.user.root.path=
50-
wds.linkis.result.set.root.path=
51-
wds.linkis.scheduler.path=
47+
wds.linkis.super.user.name=root
48+
wds.linkis.workspace.user.root.path=file:///tmp/linkis/
49+
wds.linkis.hdfs.user.root.path=hdfs:///tmp/linkis
50+
wds.linkis.result.set.root.path=hdfs:///tmp/linkis
51+
wds.linkis.scheduler.path=file:///appcom/tmp/wds/scheduler
5252
wds.linkis.user.path=hdfs:///user
53-
wds.linkis.ldap.script.server=
54-
wds.linkis.ldap.script.login.user=
55-
wds.linkis.ldap.script.login.password=
56-
wds.linkis.ldap.script.python.path=/software/tools/bin/ldap_user.py
57-
wds.linkis.ldap.script.source.path=/software/tools/venv/bin/activate
58-
wds.linkis.ldap.script.server.ssh.port=22
5953
wds.linkis.dss.install.dir=/usr/local/dss_linkis/dss/dss-server
60-
wds.linkis.azkaban.install.dir=/usr/local/dss_linkis/azkban
54+
wds.linkis.azkaban.install.dir=/usr/local/dss_linkis/azkaban
55+
56+
wds.linkis.metastore.hive.hdfs.base.path=/user/hive/warehouse
57+
wds.linkis.metastore.script.path=default/Metastore.sh
58+
wds.linkis.metastore.db.tail=_default
59+
60+
wds.linkis.kerberos.realm=
61+
wds.linkis.kerberos.admin=
62+
wds.linkis.kerberos.enable.switch=0
63+
wds.linkis.kerberos.script.path=default/Kerberos.sh
64+
wds.linkis.kerberos.keytab.path=/etc/security/keytabs
65+
wds.linkis.kerberos.kdc.node=
66+
wds.linkis.kerberos.kdc.user.name=
67+
wds.linkis.kerberos.kdc.user.password=
68+
wds.linkis.kerberos.ssh.port=22
69+
wds.dss.deploy.path=/usr/local/dss_linkis
70+
wds.dss.user.account.command.class=com.webank.wedatasphpere.dss.user.service.impl.LinuxUserCommand,com.webank.wedatasphpere.dss.user.service.impl.LdapCommand,com.webank.wedatasphpere.dss.user.service.impl.WorkspaceCommand,com.webank.wedatasphpere.dss.user.service.impl.KerberosCommand,com.webank.wedatasphpere.dss.user.service.impl.MetastoreCommand,com.webank.wedatasphpere.dss.user.service.impl.AzkabanCommand
6171

62-
63-
wds.dss.user.account.command.class=com.webank.wedatasphpere.dss.user.service.impl.LdapCommand
64-
65-
#,com.webank.wedatasphpere.dss.user.service.impl.WorkspaceCommand,com.webank.wedatasphpere.dss.user.service.impl.KerberosCommand,com.webank.wedatasphpere.dss.user.service.impl.MetastoreCommand,com.webank.wedatasphpere.dss.user.service.impl.com.webank.wedatasphpere.dss.user.service.impl.AzkabanCommand

dss-user-manager/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
<artifactId>dss-user-manager</artifactId>
1313
<packaging>jar</packaging>
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
1417

1518
<dependencies>
1619
<dependency>

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/conf/DSSUserManagerConfig.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@
1313

1414

1515
public class DSSUserManagerConfig {
16-
// private final static ResourceBundle resource = ResourceBundle.getBundle("linkis");
17-
public static final String LOCAL_USER_ROOT_PATH = CommonVars.apply("wds.dss.user.root.dir","").getValue();
18-
public static final String BDP_SERVER_LDAP_SCRIPT_SERVER = CommonVars.apply("wds.linkis.ldap.script.server", "").getValue();
19-
public static final String BDP_SERVER_LDAP_SCRIPT_LOGIN_USER = CommonVars.apply("wds.linkis.ldap.script.login.user", "").getValue();
20-
public static final String BDP_SERVER_LDAP_SCRIPT_LOGIN_PASSWORD = CommonVars.apply("wds.linkis.ldap.script.login.password", "").getValue();
21-
public static final String BDP_SERVER_LDAP_SCRIPT_PYTHON_PATH = CommonVars.apply("wds.linkis.ldap.script.python.path", "").getValue();
22-
public static final String BDP_SERVER_LDAP_SCRIPT_SOURCE_PATH = CommonVars.apply("wds.linkis.ldap.script.source.path", "").getValue();
23-
public static final String BDP_SERVER_LDAP_SCRIPT_SERVER_SSH_PORT = CommonVars.apply("wds.linkis.ldap.script.server.ssh.port", "22").getValue();
24-
25-
public static final String BDP_SERVER_MYBATIS_DATASOURCE_URL = CommonVars.apply("wds.linkis.server.mybatis.datasource.url", "").getValue();
26-
public static final String BDP_SERVER_MYBATIS_DATASOURCE_USERNAME = CommonVars.apply("wds.linkis.server.mybatis.datasource.username", "").getValue();
27-
public static final String BDP_SERVER_MYBATIS_DATASOURCE_PASSWORD = CommonVars.apply("wds.linkis.server.mybatis.datasource.password", "").getValue();
28-
public static final String SCHEDULER_ADDRESS = CommonVars.apply("wds.dss.appjoint.scheduler.azkaban.address", "").getValue();
29-
public static final String USER_ACCOUNT_COMMANDS = CommonVars.apply("wds.dss.user.account.command.class", "").getValue();
16+
// private final static ResourceBundle resource = ResourceBundle.getBundle("linkis");
17+
public static final String LOCAL_USER_ROOT_PATH = CommonVars.apply("wds.dss.user.root.dir","").getValue().trim();
18+
public static final String BDP_SERVER_MYBATIS_DATASOURCE_URL = CommonVars.apply("wds.linkis.server.mybatis.datasource.url", "").getValue().trim();
19+
public static final String BDP_SERVER_MYBATIS_DATASOURCE_USERNAME = CommonVars.apply("wds.linkis.server.mybatis.datasource.username", "").getValue().trim();
20+
public static final String BDP_SERVER_MYBATIS_DATASOURCE_PASSWORD = CommonVars.apply("wds.linkis.server.mybatis.datasource.password", "").getValue().trim();
21+
public static final String SCHEDULER_ADDRESS = CommonVars.apply("wds.dss.appjoint.scheduler.azkaban.address", "").getValue().trim();
22+
public static final String USER_ACCOUNT_COMMANDS = CommonVars.apply("wds.dss.user.account.command.class", "").getValue().trim();
23+
24+
public static final String METASTORE_HDFS_PATH = CommonVars.apply("wds.linkis.metastore.hive.hdfs.base.path", "").getValue().trim();
25+
public static final String METASTORE_SCRIPT_PAHT = CommonVars.apply("wds.linkis.metastore.script.path", "").getValue().trim();
26+
public static final String METASTORE_DB_TAIL = CommonVars.apply("wds.linkis.metastore.db.tail", "_default").getValue().trim();
27+
28+
public static final String KERBEROS_REALM = CommonVars.apply("wds.linkis.kerberos.realm", "").getValue().trim();
29+
public static final String KERBEROS_ADMIN = CommonVars.apply("wds.linkis.kerberos.admin", "").getValue().trim();
30+
public static final String KERBEROS_SCRIPT_PATH = CommonVars.apply("wds.linkis.kerberos.script.path", "").getValue().trim();
31+
public static final String KERBEROS_KEYTAB_PATH = CommonVars.apply("wds.linkis.kerberos.keytab.path", "").getValue().trim();
32+
public static final String KERBEROS_SSH_PORT = CommonVars.apply("wds.linkis.kerberos.ssh.port", "22").getValue().trim();
33+
public static final String KERBEROS_KDC_NODE = CommonVars.apply("wds.linkis.kerberos.kdc.node", "").getValue().trim();
34+
public static final String KERBEROS_KDC_USER_NAME = CommonVars.apply("wds.linkis.kerberos.kdc.user.name", "").getValue().trim();
35+
public static final String KERBEROS_KDC_USER_PASSWORD = CommonVars.apply("wds.linkis.kerberos.kdc.user.password", "").getValue().trim();
36+
public static final String KEBBEROS_ENABLE_SWITCH = CommonVars.apply("wds.linkis.kerberos.enable.switch", "").getValue().trim();
37+
public static final String DSS_DEPLOY_PATH = CommonVars.apply("wds.dss.deploy.path", "").getValue().trim();
3038

3139
}

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/service/AbsCommand.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.webank.wedatasphpere.dss.user.service;
22

33

4+
import com.webank.wedatasphere.linkis.server.Message;
45
import com.webank.wedatasphpere.dss.user.dto.request.AuthorizationBody;
56
import org.dom4j.DocumentException;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
89

10+
import javax.ws.rs.core.Response;
911
import java.io.BufferedReader;
1012
import java.io.IOException;
1113
import java.io.InputStreamReader;
@@ -31,12 +33,14 @@ public String renew(AuthorizationBody body) {
3133
public String undoAuthorization(AuthorizationBody body) { return Command.SUCCESS; }
3234

3335
@Override
34-
public String authorization(AuthorizationBody body) throws IOException,DocumentException, Exception { return Command.SUCCESS; }
36+
// public String authorization(AuthorizationBody body) throws DocumentException { return Command.SUCCESS; }
37+
public String authorization(AuthorizationBody body) throws IOException, Exception { return Command.SUCCESS; }
38+
3539
public String toMessage(String msg) {
3640
return this.getClass().getSimpleName() + "模块开始执行:"+ msg;
3741
}
3842

39-
protected String runShell(String scriptPath, String[] args) throws Exception {
43+
protected String runShell(String scriptPath, String[] args){
4044
String bashCommand;
4145
try {
4246
bashCommand = "sh " + scriptPath + " " + String.join(" ", args);
@@ -51,14 +55,14 @@ protected String runShell(String scriptPath, String[] args) throws Exception {
5155
}
5256
}
5357

54-
protected String getString(Process process) throws Exception {
58+
protected String getString(Process process) throws IOException, InterruptedException {
5559
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
5660

5761
String inline;
5862
while ((inline = br.readLine()) != null) {
5963
if (!inline.equals("")) {
6064
inline = inline.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
61-
logger.info("shell info:"+inline);
65+
logger.info(inline);
6266
} else {
6367
logger.info("\n");
6468
}
@@ -67,10 +71,9 @@ protected String getString(Process process) throws Exception {
6771
br = new BufferedReader(new InputStreamReader(process.getErrorStream())); //错误信息
6872
while ((inline = br.readLine()) != null) {
6973
if (!inline.equals(""))
70-
logger.error("shell error:"+inline);
74+
logger.warn(inline);
7175
else
72-
logger.error("\n");
73-
// throw new Exception(inline);
76+
logger.warn("\n");
7477
}
7578

7679
int status = process.waitFor();

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/service/Command.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,31 @@
99
public interface Command {
1010

1111
final public static String SUCCESS = "success";
12-
final public static String ERROR = "create account failed";
13-
1412
/**
1513
* 授权开通服务
1614
* @param body
1715
* @return 成功 success 其他失败
1816
*/
19-
public String authorization(AuthorizationBody body) throws Exception;
17+
public String authorization(AuthorizationBody body) throws DocumentException, IOException, Exception;
2018

2119
/**
2220
* 关闭授权
2321
* @param body
2422
* @return 成功 success 其他失败
2523
*/
26-
public String undoAuthorization(AuthorizationBody body) throws Exception;
24+
public String undoAuthorization(AuthorizationBody body);
2725

2826
/**
2927
* 扩容
3028
* @param body
3129
* @return 成功 success 其他失败
3230
*/
33-
public String capacity(AuthorizationBody body) throws Exception;
31+
public String capacity(AuthorizationBody body);
3432

3533
/**
3634
* 续费
3735
* @param body
3836
* @return 成功 success 其他失败
3937
*/
40-
public String renew(AuthorizationBody body) throws Exception;
38+
public String renew(AuthorizationBody body);
4139
}

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/service/impl/KerberosCommand.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigFactory;
5+
import com.webank.wedatasphere.linkis.common.conf.CommonVars;
6+
import com.webank.wedatasphpere.dss.user.conf.DSSUserManagerConfig;
57
import com.webank.wedatasphpere.dss.user.dto.request.AuthorizationBody;
68
import com.webank.wedatasphpere.dss.user.service.AbsCommand;
79
import com.webank.wedatasphpere.dss.user.service.Command;
@@ -17,33 +19,31 @@ public class KerberosCommand extends AbsCommand {
1719

1820
@Override
1921
public String authorization(AuthorizationBody body) throws Exception {
20-
Config parms = ConfigFactory.load("config/properties.conf");
21-
String rst = createKt(body, parms);
22+
String rst = createKt(body);
2223
return rst != Command.SUCCESS ? rst : Command.SUCCESS;
2324
}
2425

25-
private String createKt(AuthorizationBody body, Config parms) throws Exception {
26-
26+
private String createKt(AuthorizationBody body) throws Exception {
2727
String userName = body.getUsername();
2828
String hostName = InetAddress.getLocalHost().getHostName();
2929
String res = null;
3030
if(userName != null){
31-
res = callShell(parms.getString("shellFile"), userName,hostName,
32-
parms.getString("keytabPath"),parms.getString("sshPort"),
33-
parms.getString("kdcNode"),parms.getString("kdcUser"),parms.getString("password"),parms.getString("realm"));
31+
res = callShell(DSSUserManagerConfig.KERBEROS_SCRIPT_PATH, userName,hostName,
32+
DSSUserManagerConfig.KERBEROS_KEYTAB_PATH,DSSUserManagerConfig.KERBEROS_SSH_PORT,
33+
DSSUserManagerConfig.KERBEROS_KDC_NODE,DSSUserManagerConfig.KERBEROS_KDC_USER_NAME,DSSUserManagerConfig.KERBEROS_KDC_USER_PASSWORD,DSSUserManagerConfig.KERBEROS_REALM,DSSUserManagerConfig.KEBBEROS_ENABLE_SWITCH);
3434
}
3535
return res;
3636
}
3737

3838
private String callShell(String shellFile, String username, String hostName, String keytabPath,
39-
String sshPort, String kdcNode, String kdcUser,String password, String realm) throws Exception {
39+
String sshPort, String kdcNode, String kdcUser,String password, String realm,String enableSwich) throws Exception {
4040

4141
String bashCommand = getResource(shellFile);
4242
String scriptCmd ;
4343
if(null != hostName){
44-
scriptCmd = String.format("%s %s %s %s %s %s %s %s", username,hostName,keytabPath,sshPort,kdcNode,kdcUser,password,realm);
44+
scriptCmd = String.format("%s %s %s %s %s %s %s %s %s", username,hostName,keytabPath,sshPort,kdcNode,kdcUser,password,realm,enableSwich);
4545
}else {
46-
scriptCmd = String.format("%s %s %s %s %s %s %s", username,keytabPath,sshPort,kdcNode,kdcUser,password,realm);
46+
scriptCmd = String.format("%s %s %s %s %s %s %s %s", username,keytabPath,sshPort,kdcNode,kdcUser,password,realm,enableSwich);
4747
}
4848
String[] args = scriptCmd.split(" ");
4949
return this.runShell(bashCommand, args);

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/service/impl/LdapCommand.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,15 @@ public class LdapCommand extends AbsCommand {
2323
@Override
2424
public String authorization(AuthorizationBody body) throws Exception {
2525

26-
27-
String ldapScriptServer = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_SERVER;
28-
String ldapLoginUser = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_LOGIN_USER;
29-
String ldapLoginPassword = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_LOGIN_PASSWORD;
30-
String ldapPythonPath = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_PYTHON_PATH;
31-
String ldapSourcePath = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_SOURCE_PATH;
32-
String ldapSshPort = DSSUserManagerConfig.BDP_SERVER_LDAP_SCRIPT_SERVER_SSH_PORT;
3326
String userName = body.getUsername();
3427
String UserPassword = body.getPassword();
28+
String dssDeployPath = DSSUserManagerConfig.DSS_DEPLOY_PATH;
3529

3630
String bashCommand = this.getClass().getClassLoader().getResource("default/CreateLdapAccount.sh").getPath();
3731
String[] args = {
38-
ldapScriptServer,
39-
ldapLoginUser,
40-
ldapLoginPassword,
41-
ldapPythonPath,
42-
ldapSourcePath,
4332
userName,
4433
UserPassword,
45-
ldapSshPort,
34+
dssDeployPath
4635
};
4736

4837
return this.runShell(bashCommand, args);

dss-user-manager/src/main/java/com/webank/wedatasphpere/dss/user/service/impl/MetastoreCommand.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@
22

33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigFactory;
5+
import com.webank.wedatasphere.linkis.common.conf.CommonVars;
6+
import com.webank.wedatasphpere.dss.user.conf.DSSUserManagerConfig;
57
import com.webank.wedatasphpere.dss.user.dto.request.AuthorizationBody;
68
import com.webank.wedatasphpere.dss.user.service.AbsCommand;
79
import com.webank.wedatasphpere.dss.user.service.Command;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
812

913
/**
1014
* @author anlexander
1115
* @date 2021/1/5
1216
*/
1317
public class MetastoreCommand extends AbsCommand {
18+
private static final Logger logger = LoggerFactory.getLogger(MetastoreCommand.class);
1419

1520
@Override
1621
public String authorization(AuthorizationBody body) throws Exception {
17-
Config parms = ConfigFactory.load("config/properties.conf");
18-
String rst = createDb(body,parms);
22+
String rst = createDb(body);
1923
return rst != Command.SUCCESS ? rst : Command.SUCCESS;
2024
}
2125

22-
private String createDb(AuthorizationBody body, Config parms) throws Exception {
23-
26+
private String createDb(AuthorizationBody body) throws Exception {
2427
String bashCommand = null;
25-
String scriptCmd = null;
28+
String[] args = null;
2629
String userName = body.getUsername();
2730
if (userName != null) {
28-
String dbName = userName + parms.getString("db_tail");
29-
String path = parms.getString("base_path") + dbName + ".db";
30-
bashCommand = getResource(parms.getString("metastore_sh"));
31-
scriptCmd = String.format("%s %s %s %s %s %s", userName,dbName,path,
32-
parms.getString("realm"),parms.getString("admin"),parms.getString("keytabPath"));
31+
String dbName = userName + DSSUserManagerConfig.METASTORE_DB_TAIL;
32+
String path = DSSUserManagerConfig.METASTORE_HDFS_PATH + "/"+dbName+".db";
33+
bashCommand = getResource(DSSUserManagerConfig.METASTORE_SCRIPT_PAHT);
34+
args = new String[]{ userName,dbName,path,
35+
DSSUserManagerConfig.KERBEROS_REALM,DSSUserManagerConfig.KERBEROS_ADMIN,DSSUserManagerConfig.KERBEROS_KEYTAB_PATH,DSSUserManagerConfig.KEBBEROS_ENABLE_SWITCH};
3336
}
34-
return this.runShell(bashCommand, scriptCmd.split(" "));
37+
return this.runShell(bashCommand, args);
3538
}
3639
}
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
#!/bin/bash
22
source /etc/profile
3-
server_host=$1
4-
server_login_user=$2
5-
server_login_password=$3
6-
server_python_path=$4
7-
server_ldap_source_path=$5
8-
ldap_user=$6
9-
ldap_password=$7
10-
echo "$server_login_password ssh $server_login_user@$server_host sudo python $server_python_path add_with_pw $ldap_user -p $ldap_password"
11-
sshpass -p $server_login_password ssh $server_login_user@$server_host "sudo python $server_python_path add_with_pw $ldap_user -p $ldap_password"
12-
#sshpass -p $server_login_password ssh $server_login_user@$server_host "sudo su - root -c 'source /etc/profile && source $server_ldap_source_path && sudo python $server_python_path add_with_pw $ldap_user -p $ldap_password && deactivate'"
13-
3+
ldap_user=$1
4+
ldap_password=$2
5+
ldap_script_path=$3
6+
source $ldap_script_path/tools/venv/bin/activate && sudo $ldap_script_path/tools/venv/bin/python $ldap_script_path/tools/bin/ldap_user.py add_with_pw $ldap_user -p $ldap_password
147
echo "******************LDAP USER CREATED***********************"
15-
16-
17-
18-

0 commit comments

Comments
 (0)