| @@ -25,11 +25,11 @@ | |||
| <artifactId>runtime-modular-booter</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <!--<dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>ump-booter</artifactId> | |||
| <artifactId>manager-booter</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency>--> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>storage-composite</artifactId> | |||
| @@ -39,6 +39,18 @@ | |||
| <include>com.jd.blockchain:deployment-peer</include> | |||
| </includes> | |||
| </dependencySet> | |||
| <dependencySet> | |||
| <unpack>false</unpack> | |||
| <useProjectArtifact>true</useProjectArtifact> | |||
| <outputDirectory>manager</outputDirectory> | |||
| <includes> | |||
| <include>com.jd.blockchain:manager-booter</include> | |||
| <include>com.jd.blockchain:manager-model</include> | |||
| <include>com.jd.blockchain:manager-service</include> | |||
| <include>com.jd.blockchain:manager-web</include> | |||
| <include>com.jd.blockchain:ump-explorer</include> | |||
| </includes> | |||
| </dependencySet> | |||
| <dependencySet> | |||
| <unpack>false</unpack> | |||
| <useProjectArtifact>true</useProjectArtifact> | |||
| @@ -53,11 +65,11 @@ | |||
| <exclude>com.jd.blockchain:runtime-modular-booter</exclude> | |||
| <exclude>com.jd.blockchain:peer</exclude> | |||
| <exclude>com.jd.blockchain:deployment-peer</exclude> | |||
| <exclude>com.jd.blockchain:ump-booter</exclude> | |||
| <exclude>com.jd.blockchain:manager-booter</exclude> | |||
| <exclude>com.jd.blockchain:manager-model</exclude> | |||
| <exclude>com.jd.blockchain:manager-service</exclude> | |||
| <exclude>com.jd.blockchain:manager-web</exclude> | |||
| <exclude>com.jd.blockchain:ump-explorer</exclude> | |||
| <exclude>com.jd.blockchain:ump-model</exclude> | |||
| <exclude>com.jd.blockchain:ump-service</exclude> | |||
| <exclude>com.jd.blockchain:ump-web</exclude> | |||
| </excludes> | |||
| </dependencySet> | |||
| @@ -4,13 +4,13 @@ | |||
| BOOT_HOME=$(cd `dirname $0`;cd ../; pwd) | |||
| #获取进程PID | |||
| PID=`ps -ef | grep $BOOT_HOME/ext/ump-booter | grep -v grep | awk '{print $2}'` | |||
| PID=`ps -ef | grep $BOOT_HOME/manager/manager-booter | grep -v grep | awk '{print $2}'` | |||
| #通过Kill命令将进程杀死 | |||
| if [ -z "$PID" ]; then | |||
| echo "Unable to find UMP PID. stop aborted." | |||
| echo "Unable to find JDChain Manager PID. stop aborted." | |||
| else | |||
| echo "Start to kill PID = $PID ..." | |||
| kill -9 $PID | |||
| echo "Unified Management Platform has been stopped ..." | |||
| echo "JDChain Manager has been stopped ..." | |||
| fi | |||
| @@ -1,9 +0,0 @@ | |||
| #!/bin/bash | |||
| HOME=$(cd `dirname $0`;cd ../; pwd) | |||
| UMP=$(ls $HOME/ext | grep ump-booter-) | |||
| if [ ! -n "UMP" ]; then | |||
| echo "Unified Management Platform Is Null !!!" | |||
| else | |||
| nohup java -jar -server -Djump.log=$HOME $HOME/ext/$UMP -p 8000 $* >$HOME/bin/jump.out 2>&1 & | |||
| fi | |||
| @@ -0,0 +1,9 @@ | |||
| #!/bin/bash | |||
| HOME=$(cd `dirname $0`;cd ../; pwd) | |||
| UMP=$(ls $HOME/manager | grep manager-booter-) | |||
| if [ ! -n "UMP" ]; then | |||
| echo "JDChain Manager Is Null !!!" | |||
| else | |||
| nohup java -jar -server -Djump.log=$HOME $HOME/manager/$UMP -home $HOME -p 8000 $* >$HOME/bin/jump.out 2>&1 & | |||
| fi | |||
| @@ -82,6 +82,34 @@ | |||
| </dependencies> | |||
| <build> | |||
| <plugins> | |||
| <plugin> | |||
| <groupId>org.apache.maven.plugins</groupId> | |||
| <artifactId>maven-jar-plugin</artifactId> | |||
| <configuration> | |||
| <archive> | |||
| <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> | |||
| <manifest> | |||
| <mainClass>com.jd.blockchain.ump.UmpBooter</mainClass> | |||
| <addClasspath>false</addClasspath> | |||
| <useUniqueVersions>false</useUniqueVersions> | |||
| </manifest> | |||
| </archive> | |||
| </configuration> | |||
| </plugin> | |||
| <plugin> | |||
| <groupId>org.apache.maven.plugins</groupId> | |||
| <artifactId>maven-deploy-plugin</artifactId> | |||
| <version>2.8.2</version> | |||
| <configuration> | |||
| <skip>true</skip> | |||
| </configuration> | |||
| </plugin> | |||
| </plugins> | |||
| </build> | |||
| <!--<build> | |||
| <plugins> | |||
| <plugin> | |||
| <groupId>org.springframework.boot</groupId> | |||
| @@ -128,5 +156,5 @@ | |||
| </resource> | |||
| </resources> | |||
| </build> | |||
| </build>--> | |||
| </project> | |||
| @@ -1,11 +1,15 @@ | |||
| package com.jd.blockchain.ump; | |||
| import com.jd.blockchain.ump.web.RetrievalConfigListener; | |||
| import com.jd.blockchain.ump.web.UmpConfiguration; | |||
| import org.springframework.boot.SpringApplication; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.net.MalformedURLException; | |||
| import java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Properties; | |||
| @@ -13,11 +17,13 @@ import java.util.Properties; | |||
| public class UmpBooter { | |||
| private static final String ARG_HOME = "-home"; | |||
| private static final String ARG_PORT = "-p"; | |||
| private static final String ARG_HOST = "-h"; | |||
| private static final String CONFIG = "BOOT-INF" + File.separator + "classes" + File.separator + "config.properties"; | |||
| private static final String CONFIG = "/config.properties"; | |||
| private static final String CONFIG_APPLICATION = "BOOT-INF" + File.separator + "classes" + File.separator + "application.properties"; | |||
| @@ -33,9 +39,20 @@ public class UmpBooter { | |||
| private static final String CONFIG_PROP_DB_URL_DEFAULT = "rocksdb://#project#/jumpdb"; | |||
| private static String HOME_DIR = null; | |||
| public static void main(String[] args) { | |||
| startServer(server(args)); | |||
| System.out.println("Unified Management Platform Server Start SUCCESS !!!"); | |||
| try { | |||
| // 设置相关参数 | |||
| Server server = server(args); | |||
| // 加载libs/manager下的jar包 | |||
| loadJars(); | |||
| // 启动Server | |||
| startServer(server); | |||
| System.out.println("Unified Management Platform Server Start SUCCESS !!!"); | |||
| } catch (Exception e) { | |||
| System.err.println(e); | |||
| } | |||
| } | |||
| private static void startServer(Server server) { | |||
| @@ -66,9 +83,12 @@ public class UmpBooter { | |||
| springApplication.run(args); | |||
| } | |||
| private static Server server(String[] args) { | |||
| private static Server server(String[] args) throws Exception { | |||
| Server defaultServer = serverFromConfig(); | |||
| if (args == null || args.length == 0) { | |||
| // 获取当前Class所在路径 | |||
| HOME_DIR = UmpBooter.class.getResource("").toURI().getPath(); | |||
| return defaultServer; | |||
| } | |||
| String host = null; | |||
| @@ -82,6 +102,8 @@ public class UmpBooter { | |||
| host = args[i + 1]; | |||
| } else if (arg.equals(ARG_PORT)) { | |||
| port = Integer.parseInt(args[i + 1]); | |||
| } else if (arg.equals(ARG_HOME)) { | |||
| HOME_DIR = args[i + 1]; | |||
| } | |||
| } | |||
| @@ -98,7 +120,7 @@ public class UmpBooter { | |||
| private static Server serverFromConfig() { | |||
| try { | |||
| InputStream inputStream = UmpBooter.class.getResourceAsStream(File.separator + CONFIG); | |||
| InputStream inputStream = UmpBooter.class.getResourceAsStream(CONFIG); | |||
| if (inputStream == null) { | |||
| System.err.println("InputStream is NULL !!!"); | |||
| } | |||
| @@ -114,6 +136,55 @@ public class UmpBooter { | |||
| } | |||
| } | |||
| private static void loadJars() { | |||
| // 获取两个路径下所有的正确的Jar包 | |||
| URL[] libsJars = totalURLs(); | |||
| URLClassLoader libClassLoader = new URLClassLoader(libsJars, UmpBooter.class.getClassLoader()); | |||
| Thread.currentThread().setContextClassLoader(libClassLoader); | |||
| } | |||
| public static URL[] totalURLs() { | |||
| List<URL> totalURLs = new ArrayList<>(); | |||
| totalURLs.addAll(libsPathURLs()); | |||
| totalURLs.addAll(managerPathURLs()); | |||
| URL[] totalURLArray = new URL[totalURLs.size()]; | |||
| return totalURLs.toArray(totalURLArray); | |||
| } | |||
| public static List<URL> libsPathURLs() { | |||
| try { | |||
| File libsDir = new File(HOME_DIR + File.separator + "libs"); | |||
| File[] jars = libsDir.listFiles(f -> f.getName().endsWith(".jar") && f.isFile() && !f.getName().contains("-booter-")); | |||
| List<URL> libsPathURLs = new ArrayList<>(); | |||
| if (jars != null && jars.length > 0) { | |||
| for (int i = 0; i < jars.length; i++) { | |||
| libsPathURLs.add(jars[i].toURI().toURL()); | |||
| } | |||
| } | |||
| return libsPathURLs; | |||
| } catch (MalformedURLException e) { | |||
| throw new IllegalStateException(e.getMessage(), e); | |||
| } | |||
| } | |||
| public static List<URL> managerPathURLs() { | |||
| try { | |||
| File managerDir = new File(HOME_DIR + File.separator + "manager"); | |||
| File[] jars = managerDir.listFiles(f -> f.getName().endsWith(".jar") && f.isFile()); | |||
| List<URL> managerPathURLs = new ArrayList<>(); | |||
| if (jars != null && jars.length > 0) { | |||
| for (int i = 0; i < jars.length; i++) { | |||
| managerPathURLs.add(jars[i].toURI().toURL()); | |||
| } | |||
| } | |||
| return managerPathURLs; | |||
| } catch (MalformedURLException e) { | |||
| throw new IllegalStateException(e.getMessage(), e); | |||
| } | |||
| } | |||
| private static class Server { | |||
| private String host; | |||
| @@ -143,5 +214,13 @@ public class UmpBooter { | |||
| public void setPort(int port) { | |||
| this.port = port; | |||
| } | |||
| public String getDbUrl() { | |||
| return dbUrl; | |||
| } | |||
| public void setDbUrl(String dbUrl) { | |||
| this.dbUrl = dbUrl; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| Manifest-Version: 1.0 | |||
| Created-By: 1.8.0 | |||
| Built-By: shaozhuguang@jd.com | |||
| Extension-Name: JDChain | |||
| Specification-Title: JDChain | |||
| Specification-Vendor: JD Software Foundation | |||
| Implementation-Vendor: JD Software Foundation | |||
| Implementation-URL: http://ledger.jd.com | |||
| Build-Jdk: 1.8.0 | |||
| @@ -1,9 +0,0 @@ | |||
| #!/bin/bash | |||
| HOME=$(cd `dirname $0`;cd ../; pwd) | |||
| UMP=$(ls $HOME/ext | grep ump-booter-) | |||
| if [ ! -n "UMP" ]; then | |||
| echo "Unified Management Platform Is Null !!!" | |||
| else | |||
| nohup java -jar -server -Djump.log=$HOME $HOME/ext/$UMP $* >$HOME/bin/jump.out 2>&1 & | |||
| fi | |||
| @@ -1,16 +0,0 @@ | |||
| #!/bin/bash | |||
| #启动Home路径 | |||
| BOOT_HOME=$(cd `dirname $0`;cd ../; pwd) | |||
| #获取进程PID | |||
| PID=`ps -ef | grep $BOOT_HOME/ext/ump-booter | grep -v grep | awk '{print $2}'` | |||
| #通过Kill命令将进程杀死 | |||
| if [ -z "$PID" ]; then | |||
| echo "Unable to find UMP PID. stop aborted." | |||
| else | |||
| echo "Start to kill PID = $PID ..." | |||
| kill -9 $PID | |||
| echo "Unified Management Platform has been stopped ..." | |||
| fi | |||
| @@ -25,7 +25,9 @@ public class PartiNode { | |||
| configCharList.add(formatConfig(UmpConstant.PARTINODE_PUBKEY_FORMAT, pubKey)); | |||
| configCharList.addAll(partiRoleConfigs); | |||
| if (partiRoleConfigs != null && !partiRoleConfigs.isEmpty()) { | |||
| configCharList.addAll(partiRoleConfigs); | |||
| } | |||
| configCharList.add(formatConfig(UmpConstant.PARTINODE_INIT_HOST_FORMAT, initHost)); | |||
| @@ -61,7 +61,9 @@ public class LedgerInitConfig { | |||
| configChars.add(toConfigChars(UmpConstant.PARTINODE_COUNT, partiNodes.size())); | |||
| configChars.addAll(securityConfigs); | |||
| if (securityConfigs != null && !securityConfigs.isEmpty()) { | |||
| configChars.addAll(securityConfigs); | |||
| } | |||
| for (PartiNode partiNode : partiNodes) { | |||
| configChars.addAll(partiNode.toConfigChars(this.partiRolesConfigs)); | |||
| @@ -1,6 +1,8 @@ | |||
| package com.jd.blockchain.ump.service; | |||
| import com.jd.blockchain.ump.model.UmpConstant; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.stereotype.Service; | |||
| import java.io.File; | |||
| @@ -12,6 +14,8 @@ import java.util.Properties; | |||
| @Service | |||
| public class SecurityServiceHandler implements SecurityService { | |||
| private static final Logger LOGGER = LoggerFactory.getLogger(SecurityServiceHandler.class); | |||
| static final String SECURITY_FILE = "security.config"; | |||
| private List<String> securityConfigs = new ArrayList<>(); | |||
| @@ -34,6 +38,7 @@ public class SecurityServiceHandler implements SecurityService { | |||
| @Override | |||
| public void init() { | |||
| try { | |||
| // 读取配置文件中的内容 | |||
| InputStream currentFileInputStream = SecurityServiceHandler.class.getResourceAsStream( | |||
| @@ -78,7 +83,8 @@ public class SecurityServiceHandler implements SecurityService { | |||
| participantRoleConfigs.add(propBuild(UmpConstant.SECURITY_PARTI_ROLES_POLICY, partiRolesPolicyValue)); | |||
| } else { | |||
| throw new IllegalStateException("Can not find Properties from security.config"); | |||
| // 打印日志即可 | |||
| LOGGER.error("Can not find Properties from {}", SECURITY_FILE); | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| security.roles=DEFAULT, ADMIN, MANAGER, GUEST | |||
| #security.roles=DEFAULT, ADMIN, MANAGER, GUEST | |||
| security.role.DEFAULT.ledger-privileges=REGISTER_USER, REGISTER_DATA_ACCOUNT | |||
| @@ -1,4 +1,4 @@ | |||
| package com.jd.blockchain.ump; | |||
| package com.jd.blockchain.ump.web; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||