diff --git a/udf-api/pom.xml b/udf-api/pom.xml index a18b54b..c8e7823 100644 --- a/udf-api/pom.xml +++ b/udf-api/pom.xml @@ -24,21 +24,8 @@ - - - - - - - - - - - - - - - + udf-api-server + udf-api-common @@ -51,84 +38,12 @@ pom import - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.itkk.udf + udf-api-common + ${udf-api.version} + org.itkk.udf diff --git a/udf-api/udf-api-common/pom.xml b/udf-api/udf-api-common/pom.xml new file mode 100644 index 0000000..bfcb043 --- /dev/null +++ b/udf-api/udf-api-common/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + udf-api-common + udf-api-common + jar + https://www.itkk.org/ + + + org.itkk.udf + udf-api + 1.0 + + + + + + org.itkk.udf + udf-starter-core + + + + mysql + mysql-connector-java + + + + org.itkk.udf + udf-starter-datasource-dynamic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${project.basedir}/src/main/resources/ + true + + **/*.jar + + + + + diff --git a/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConfiguration.java b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConfiguration.java new file mode 100644 index 0000000..9108b7a --- /dev/null +++ b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConfiguration.java @@ -0,0 +1,12 @@ +package org.itkk.udf.api.common; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 配置类 + */ +@Configuration +public class CommonConfiguration implements WebMvcConfigurer { + +} diff --git a/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConstant.java b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConstant.java new file mode 100644 index 0000000..8b23afc --- /dev/null +++ b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonConstant.java @@ -0,0 +1,13 @@ +package org.itkk.udf.api.common; + +/** + * 常量类 + */ +public class CommonConstant { + /** + * 私有化构造函数 + */ + private CommonConstant() { + + } +} diff --git a/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonProperties.java b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonProperties.java new file mode 100644 index 0000000..8317752 --- /dev/null +++ b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonProperties.java @@ -0,0 +1,20 @@ +package org.itkk.udf.api.common; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +/** + * 属性类 + */ +@Component +@ConfigurationProperties(prefix = CommonProperties.UDF_API_PROPERTIES) +@Validated +@Data +public class CommonProperties { + /** + * 配置文件前缀 + */ + protected static final String UDF_API_PROPERTIES = "org.itkk.udf.api.common.properties"; +} diff --git a/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonUtil.java b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonUtil.java new file mode 100644 index 0000000..d45466b --- /dev/null +++ b/udf-api/udf-api-common/src/main/java/org/itkk/udf/api/common/CommonUtil.java @@ -0,0 +1,16 @@ +package org.itkk.udf.api.common; + +import lombok.extern.slf4j.Slf4j; + +/** + * 工具类 + */ +@Slf4j +public class CommonUtil { + /** + * 私有化构造函数 + */ + private CommonUtil() { + + } +} diff --git a/udf-api/udf-api-common/src/main/resources/README.md b/udf-api/udf-api-common/src/main/resources/README.md new file mode 100644 index 0000000..e69de29 diff --git a/udf-api/udf-api-server/pom.xml b/udf-api/udf-api-server/pom.xml new file mode 100644 index 0000000..52722fe --- /dev/null +++ b/udf-api/udf-api-server/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + udf-api-server + udf-api-server + jar + https://www.itkk.org/ + + + org.itkk.udf + udf-api + 1.0 + + + + 9000 + 8000 + + + + + + org.itkk.udf + udf-api-common + + + + + + + ${project.basedir}/src/main/resources/ + true + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${springboot.version} + + true + + + + + repackage + + + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + UTF-8 + + xlsx + xls + + + + + + diff --git a/udf-api/udf-api-server/src/main/java/org/itkk/udf/api/server/UdfApiServerApplication.java b/udf-api/udf-api-server/src/main/java/org/itkk/udf/api/server/UdfApiServerApplication.java new file mode 100644 index 0000000..b91720a --- /dev/null +++ b/udf-api/udf-api-server/src/main/java/org/itkk/udf/api/server/UdfApiServerApplication.java @@ -0,0 +1,20 @@ +package org.itkk.udf.api.server; + +import org.apache.ibatis.annotations.Mapper; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@ServletComponentScan(basePackages = {"org.itkk"}) +@ComponentScan(basePackages = {"org.itkk"}) +@MapperScan(basePackages = {"org.itkk"}, annotationClass = Mapper.class) +@EnableAsync +public class UdfApiServerApplication { + public static void main(String[] args) { + SpringApplication.run(UdfApiServerApplication.class, args); + } +} diff --git a/udf-api/udf-api-server/src/main/resources/application-dev.properties b/udf-api/udf-api-server/src/main/resources/application-dev.properties new file mode 100644 index 0000000..cae5ca7 --- /dev/null +++ b/udf-api/udf-api-server/src/main/resources/application-dev.properties @@ -0,0 +1,32 @@ +# CORS +org.itkk.udf.starter.core.properties.corsAllowedOrigins=http://localhost:8080 +# GUAVA CACHE +org.itkk.udf.starter.core.properties.guavaCacheProperties.concurrencyLevel=10 +org.itkk.udf.starter.core.properties.guavaCacheProperties.initialCapacity=10 +org.itkk.udf.starter.core.properties.guavaCacheProperties.maximumSize=100 +org.itkk.udf.starter.core.properties.guavaCacheProperties.expireAfterWrite=10 +# LOGGING +logging.file.name=d:/${spring.application.name}/app/application-log/${spring.application.name}_${server.port}_${spring.profiles.active}/base.log +logging.file.max-size=100MB +logging.file.max-history=31 +# EXCEPTION +org.itkk.udf.starter.core.properties.outputExceptionStackTrace=true +# DataSource Dynamic +org.itkk.udf.starter.datasource.dynamic.properties.defaultCode=udf +# DataSource Dynamic -- udf +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.code=udf +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.enable=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.url=jdbc:mysql://itkk.org:3306/dev_udf?useUnicode=true&useSSL=false&autoReconnect=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.username=dev_udf +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.password=123456 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.jdbc.Driver +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.initialSize=1 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minIdle=1 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxActive=2 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxWait=5000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.timeBetweenEvictionRunsMillis=60000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minEvictableIdleTimeMillis=30000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.validationQuery=select 1 from dual +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testWhileIdle=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testOnBorrow=false +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testOnReturn=false \ No newline at end of file diff --git a/udf-api/udf-api-server/src/main/resources/application-prod.properties b/udf-api/udf-api-server/src/main/resources/application-prod.properties new file mode 100644 index 0000000..6d6c9a0 --- /dev/null +++ b/udf-api/udf-api-server/src/main/resources/application-prod.properties @@ -0,0 +1,32 @@ +# CORS +org.itkk.udf.starter.core.properties.corsAllowedOrigins=https://itkk.org,https://www.itkk.org,http://itkk.org:81,http://www.itkk.org:81,http://192.168.1.100 +# GUAVA CACHE +org.itkk.udf.starter.core.properties.guavaCacheProperties.concurrencyLevel=10 +org.itkk.udf.starter.core.properties.guavaCacheProperties.initialCapacity=10 +org.itkk.udf.starter.core.properties.guavaCacheProperties.maximumSize=200 +org.itkk.udf.starter.core.properties.guavaCacheProperties.expireAfterWrite=10 +# LOGGING +logging.file.name=/usr/local/share/${spring.application.name}/app/application-log/${spring.application.name}_${server.port}_${spring.profiles.active}/base.log +logging.file.max-size=100MB +logging.file.max-history=31 +# EXCEPTION +org.itkk.udf.starter.core.properties.outputExceptionStackTrace=false +# DataSource Dynamic +org.itkk.udf.starter.datasource.dynamic.properties.defaultCode=udf +# DataSource Dynamic -- udf +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.code=udf +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.enable=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.url=jdbc:mysql://itkk.org:3306/dev_prod?useUnicode=true&useSSL=false&autoReconnect=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.username=dev_prod +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.password=5ds2c6de54t1fd36e5f +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.driverClassName=com.mysql.jdbc.Driver +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.initialSize=1 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minIdle=1 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxActive=2 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.maxWait=5000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.timeBetweenEvictionRunsMillis=60000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.minEvictableIdleTimeMillis=30000 +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.validationQuery=select 1 from dual +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testWhileIdle=true +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testOnBorrow=false +org.itkk.udf.starter.datasource.dynamic.properties.map.udf.testOnReturn=false \ No newline at end of file diff --git a/udf-api/udf-api-server/src/main/resources/application.properties b/udf-api/udf-api-server/src/main/resources/application.properties new file mode 100644 index 0000000..1632938 --- /dev/null +++ b/udf-api/udf-api-server/src/main/resources/application.properties @@ -0,0 +1,49 @@ +# HTTP +spring.http.encoding.force=true +# file encoding +spring.mandatory-file-encoding=UTF-8 +# INFO +info.build.group=${project.groupId} +info.build.artifact=${project.artifactId} +info.build.version=${project.version} +info.build.name=${spring.application.name} +info.build.env=${spring.profiles.active} +info.build.time=${project.build.date} +info.build.encoding=${project.build.sourceEncoding} +info.build.java.source=${java.version} +info.build.java.target=${java.version} +# SPRING +spring.application.name=${project.name} +# HTTP SERVER +server.port=${server.port} +# compression +server.compression.enabled=true +server.compression.min-response-size=1KB +# MANAGEMENT HTTP SERVER (ManagementServerProperties) +#management.server.address=127.0.0.1 +management.server.port=${management.port} +# ENDPOINTS WEB CONFIGURATION (WebEndpointProperties) +management.endpoints.web.exposure.include=* +# ENDPOINT +management.endpoint.health.showDetails=always +management.endpoint.shutdown.enabled=true +management.endpoint.restart.enabled=true +management.endpoint.pause.enabled=true +management.endpoint.resume.enabled=true +# JACKSON +spring.jackson.timeZone=Asia/Shanghai +spring.jackson.serialization.INDENT_OUTPUT=false +spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false +spring.jackson.deserialization.FAIL_ON_UNKNOWN_PROPERTIES=false +spring.jackson.parser.ALLOW_SINGLE_QUOTES=true +spring.jackson.parser.ALLOW_UNQUOTED_CONTROL_CHARS=true +# HTTP FILE UPLOAD +spring.servlet.multipart.max-file-size=1MB +spring.servlet.multipart.max-request-size=1MB +spring.servlet.multipart.resolve-lazily=false +# TASK SCHEDULING +spring.task.scheduling.pool.size=10 +# mybatisPlus +mybatisPlus.mapperLocations=classpath*:mapper/*.xml +mybatisPlus.configuration.logImpl=org.itkk.udf.starter.core.trace.TraceMybatisLogImpl +mybatisPlus.configuration.callSettersOnNulls=true \ No newline at end of file diff --git a/udf-api/udf-api-server/src/main/resources/build_prod.sh b/udf-api/udf-api-server/src/main/resources/build_prod.sh new file mode 100644 index 0000000..6af2bbd --- /dev/null +++ b/udf-api/udf-api-server/src/main/resources/build_prod.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +echo 'shutdown application begin' + returnCode=`curl -I -s -X POST "http://127.0.0.1:${management.port}/actuator/shutdown"|head -1|cut -d" " -f2` +echo "shutdown status code : $returnCode" + sleep 5 +echo 'shutdown application end' + +echo 'stop application begin' + PID=$(ps -ef | grep ${project.name}-${project.version}.jar | grep -v grep | awk '{ print $2 }') + if [[ -z "$PID" ]] + then + echo 'application is already stopped' + else + echo 'kill process' + kill -9 $PID + fi +echo 'stop application end' + +echo 'bak and copy application begin' + datestr=$(date +%Y_%m_%d_%H_%M_%S) + mv /usr/local/share/${spring.application.name}/app/${project.name}/${project.name}-${project.version}.jar /usr/local/share/${spring.application.name}/app/${project.name}/${project.name}-${project.version}.jar.${datestr} + cp ${project.name}-${project.version}.jar /usr/local/share/${spring.application.name}/app/${project.name}/${project.name}-${project.version}.jar +echo 'bak and copy application end' + +echo 'start application begin' + rm -rf nohup.out + nohup java -server -Xms1024m -Xmx1024m -XX:+UseG1GC -jar /usr/local/share/${spring.application.name}/app/${project.name}/${project.name}-${project.version}.jar --spring.profiles.active=prod & +echo 'start application end' + +echo 'check service begin' + echo 'sleep 10s begin' + sleep 10 + echo 'sleep 10s end' + startedStatus="0"; + maxCount=40; + for (( i = 0; i < $maxCount; i++ ));do + returnCode=`curl -I -s "http://127.0.0.1:${management.port}/actuator/info"|head -1|cut -d" " -f2` + if [[ "$returnCode" == "200" ]] + then + startedStatus="1"; + break; + else + echo "sleep 2s,count:$i"; + sleep 2 + fi + done + if [[ "$startedStatus" == "1" ]] + then + echo "service has started"; + else + echo "service start fail"; + exit 1; + fi +echo 'check service end' \ No newline at end of file diff --git a/udf-api/udf-api-server/src/main/resources/logback.xml b/udf-api/udf-api-server/src/main/resources/logback.xml new file mode 100644 index 0000000..049dc97 --- /dev/null +++ b/udf-api/udf-api-server/src/main/resources/logback.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file