Преглед изворни кода

milestone - dmaster 和 dagent 测试环境版本

reghao пре 4 година
родитељ
комит
f32da85618

+ 0 - 0
dagent/bin/mqtt1.json → dagent/bin/mqtt-dev.json


+ 0 - 0
dagent/bin/mqtt.json → dagent/bin/mqtt-prod.json


+ 0 - 5
dagent/bin/shutdown.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-app_name='autodop-dagent.jar'
-pid=`jps | grep ${app_name} | awk '{print $1}'`
-kill -15 ${pid}

+ 0 - 5
dagent/bin/start.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-app_dir=`pwd`
-app_name='autodop-dagent.jar'
-nohup java -jar ${app_dir}"/"${app_name} ${app_dir}/mqtt.json > console.log 2>&1 &

+ 2 - 2
dagent/pom.xml

@@ -24,7 +24,7 @@
     </dependencies>
 
     <build>
-        <finalName>${project.parent.artifactId}-${project.artifactId}</finalName>
+        <finalName>autodop-dagent</finalName>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -41,7 +41,7 @@
                     </descriptorRefs>
                     <!-- 不设置此属性则生成的 jar 包名字会带有 jar-with-dependencies -->
                     <appendAssemblyId>false</appendAssemblyId>
-                    <outputDirectory>${project.build.outputDir}</outputDirectory>
+                    <!--<outputDirectory>${project.build.outputDir}</outputDirectory>-->
                 </configuration>
                 <executions>
                     <execution>

+ 7 - 29
dagent/src/main/java/cn/reghao/autodop/dagent/DagentApp.java

@@ -19,6 +19,7 @@ import cn.reghao.autodop.dagent.mqttsub.impl.AppRpcClazzImpl;
 import cn.reghao.jutil.jdk.http.WebClient;
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.jutil.jdk.text.TextFile;
+import cn.reghao.jutil.jdk.util.SingleInstance;
 import lombok.extern.slf4j.Slf4j;
 import oshi.SystemInfo;
 
@@ -29,7 +30,6 @@ import java.util.List;
 
 @Slf4j
 public class DagentApp {
-	static ServerSocket serverSocket;
 	static AsyncMqttClient mqttClient;
 	static DagentTopicListener dagentTopicListener;
 	static NodeEventClazzPubImpl nodeEventClazzPub;
@@ -52,43 +52,18 @@ public class DagentApp {
 	}
 
 	static void stop() {
-		try {
-			serverSocket.close();
-		} catch (IOException e) {
-			String errmsg = ExceptionUtil.errorMsg(e);
-			log.error("关闭 54321 端口出错 {}", errmsg);
-		}
-
 		pubDagentShutdown();
 		log.info("资源清理完成,结束 autodop-dagent...");
 	}
 
-	/**
-	 * 通过监听一个端口来保证一台机器上只运行一个 autodop-dagent 实例
-	 *
-	 * @param
-	 * @return
-	 * @date 2021-11-02 下午3:01
-	 */
-	static void singleInstance() throws Exception {
-		try {
-			serverSocket = new ServerSocket();
-			serverSocket.bind(new InetSocketAddress("127.0.0.1", 54321));
-		} catch (IOException e) {
-			throw new Exception("已有一个 autodop-dagent 实例在运行, 一台机器上只能运行一个 autodop-dagent 实例.");
-		}
-	}
-
 	public static void main(String[] args) throws Exception {
-		singleInstance();
-		Appender<ILoggingEvent> appender = Appenders.fileAppender();
-		LoggerConfig.initLogger(List.of(appender));
-
-
 		if (args.length != 1) {
 			log.error("必须指定配置文件...");
 			return;
 		}
+
+		//Thread t = new Thread(new SingleInstance(65432));
+
 		String configFilePath = ConfigFile.configFilePath(args[0], DagentApp.class);
 		String json = new TextFile().readFile(configFilePath);
 		MqttProperties mqttProperties = JsonConverter.jsonToObject(json, MqttProperties.class);
@@ -106,5 +81,8 @@ public class DagentApp {
 
 		mqttClient.connect(connActionListener);
 		shutdownGracefully();
+
+		Appender<ILoggingEvent> appender = Appenders.fileAppender();
+		LoggerConfig.initLogger(List.of(appender));
 	}
 }

+ 0 - 34
dagent/src/main/java/cn/reghao/autodop/dagent/JdkAppContext.java

@@ -1,34 +0,0 @@
-package cn.reghao.autodop.dagent;
-
-import com.sun.net.httpserver.HttpServer;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.Random;
-
-/**
- * @author reghao
- * @date 2021-10-31 13:38:08
- */
-public class JdkAppContext {
-    public void start(Runnable hook) {
-        shutdownGracefully(hook);
-        singleInstance();
-    }
-
-    void shutdownGracefully(Runnable hook) {
-        Runtime.getRuntime().addShutdownHook(new Thread(hook, "main-shutdown-hook"));
-    }
-
-    void singleInstance() {
-        int min = 30000;
-        int max = 50000;
-        int range = max-min+1;
-        int port = new Random().nextInt(range) + min;
-        try {
-            HttpServer.create(new InetSocketAddress("127.0.0.1", port), 0).start();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-}

+ 7 - 0
dmaster/Dockerfile

@@ -0,0 +1,7 @@
+FROM alpine/openjdk:11
+
+WORKDIR /app
+#RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
+COPY target/autodop-dmaster.jar /app/app.jar
+
+ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]

+ 0 - 5
dmaster/bin/shutdown.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-app_name='autodop-dmaster.jar'
-pid=`jps | grep ${app_name} | awk '{print $1}'`
-kill -15 ${pid}

+ 0 - 5
dmaster/bin/start.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-app_dir=`pwd`
-app_name='autodop-dmaster.jar'
-nohup java -jar ${app_dir}"/"${app_name} > console.log 2>&1 &

+ 3 - 2
dmaster/pom.xml

@@ -275,9 +275,10 @@
                         </goals>
                     </execution>
                 </executions>
-                <configuration>
+                <!--<configuration>
+                    &lt;!&ndash; 生成的 jar 包输出到指定目录 &ndash;&gt;
                     <outputDirectory>${project.build.outputDir}</outputDirectory>
-                </configuration>
+                </configuration>-->
             </plugin>
         </plugins>
     </build>

+ 2 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuilder.java

@@ -77,8 +77,7 @@ public class AppBuilder {
 
     private void initLocalDir() {
         appLocalRepo = LocalBuildDir.localRepo + File.separator + app.getAppId();
-        //appCompileDir = LocalBuildDir.compileDir + File.separator + app.getAppId();
-        appCompileDir = LocalBuildDir.localRepo + File.separator + app.getAppId();
+        appCompileDir = LocalBuildDir.compileDir + File.separator + app.getAppId();
         appPackDir = LocalBuildDir.packDir + File.separator + app.getAppId();
     }
 
@@ -153,7 +152,7 @@ public class AppBuilder {
         if (updateStatus.isUpdated) {
             latestCommitInfo = updateStatus.getLatestCommitInfo();
             // 将代码由本地仓库复制到编译目录
-            //BuilderUtil.copyToCompileDir(local, app);
+            BuilderUtil.copyToCompileDir(local, app);
         }
 
         return latestCommitInfo;

+ 2 - 1
dmaster/src/main/resources/application-prod.yml

@@ -5,7 +5,8 @@ spring:
     password: Test@123456
   data:
     mongodb:
-      uri: mongodb://192.168.0.211/log
+      host: 192.168.0.220
+      database: iquizoo_devops_tdb
 mosquitto:
   broker: tcp://192.168.0.211:1883
   username: test

+ 2 - 1
dmaster/src/main/resources/application-test.yml

@@ -5,7 +5,8 @@ spring:
     password: Azy@123456
   data:
     mongodb:
-      uri: mongodb://mongodb.alpha.iquizoo.com/iquizoo_devops_tdb
+      host: 192.168.0.220
+      database: iquizoo_devops_tdb
 mosquitto:
   broker: tcp://s75.iquizoo.com:1883
   username: test

+ 10 - 0
scripts/docker.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -e
+
+cd /home/reghao/code/aha/autodop/
+mvn clean package -am -Dmaven.test.skip=true -pl dmaster -Pdev
+
+cd /home/reghao/code/aha/autodop/dmaster/
+docker build -t docker.reghao.icu/devops/dmaster .
+docker push docker.reghao.icu/devops/dmaster