Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uber-jar the frameless sample and set mainClass #3341

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ private Object process(HttpMethod httpMethod, String uri, String requestData, St
if (uri == null || uri.trim().length() == 0) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping empty.");
}
if (accessToken != null
&& accessToken.trim().length() > 0
if (accessToken == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "The access token is null.");
}
if (accessToken.trim().length() > 0
&& !accessToken.equals(accessTokenReq)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "The access token is wrong.");
}
Expand Down
41 changes: 39 additions & 2 deletions xxl-job-executor-samples/xxl-job-executor-sample-frameless/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xuxueli</groupId>
Expand All @@ -15,6 +15,43 @@
<description>Example executor project for spring boot.</description>
<url>https://www.xuxueli.com/</url>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>
com.xxl.job.executor.sample.frameless.FramelessApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.xxl.job.executor.sample.frameless.FramelessApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,71 @@
public class FrameLessXxlJobConfig {
private static Logger logger = LoggerFactory.getLogger(FrameLessXxlJobConfig.class);


private static FrameLessXxlJobConfig instance = new FrameLessXxlJobConfig();

public static FrameLessXxlJobConfig getInstance() {
return instance;
}


private XxlJobSimpleExecutor xxlJobExecutor = null;

/**
* init
*/
public void initXxlJobExecutor() {

// load executor prop
Properties xxlJobProp = loadProperties("xxl-job-executor.properties");

// init executor
xxlJobExecutor = new XxlJobSimpleExecutor();
xxlJobExecutor.setAdminAddresses(xxlJobProp.getProperty("xxl.job.admin.addresses"));
xxlJobExecutor.setAccessToken(xxlJobProp.getProperty("xxl.job.accessToken"));
xxlJobExecutor.setAppname(xxlJobProp.getProperty("xxl.job.executor.appname"));
xxlJobExecutor.setAddress(xxlJobProp.getProperty("xxl.job.executor.address"));
xxlJobExecutor.setIp(xxlJobProp.getProperty("xxl.job.executor.ip"));
xxlJobExecutor.setPort(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.port")));
xxlJobExecutor.setLogPath(xxlJobProp.getProperty("xxl.job.executor.logpath"));
xxlJobExecutor.setLogRetentionDays(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.logretentiondays")));

String envAppname = System.getenv("XXL_JOB_EXECUTOR_APPNAME");
if (envAppname == null) {
envAppname = xxlJobProp.getProperty("xxl.job.executor.appname");
}
xxlJobExecutor.setAppname(envAppname);

String envPort = System.getenv("XXL_JOB_EXECUTOR_PORT");
if (envPort == null) {
envPort = xxlJobProp.getProperty("xxl.job.executor.port");
}
xxlJobExecutor.setPort(Integer.valueOf(envPort));

String envAdminAddresses = System.getenv("XXL_JOB_ADMIN_ADDRESSES");
if (envAdminAddresses == null) {
envAdminAddresses = xxlJobProp.getProperty("xxl.job.admin.addresses");
}
xxlJobExecutor.setAdminAddresses(envAdminAddresses);

String accessToken = System.getenv("XXL_JOB_ACCESS_TOKEN");
if (accessToken == null) {
accessToken = xxlJobProp.getProperty("xxl.job.accessToken");
}
xxlJobExecutor.setAccessToken(accessToken);

String envAddress = System.getenv("XXL_JOB_EXECUTOR_ADDRESS");
if (envAddress == null) {
envAddress = xxlJobProp.getProperty("xxl.job.executor.address");
}
xxlJobExecutor.setAddress(envAddress);

String envIp = System.getenv("XXL_JOB_EXECUTOR_IP");
if (envIp == null) {
envIp = xxlJobProp.getProperty("xxl.job.executor.ip");
}
xxlJobExecutor.setIp(envIp);

String envLogPath = System.getenv("XXL_JOB_EXECUTOR_LOGPATH");
if (envLogPath == null) {
envLogPath = xxlJobProp.getProperty("xxl.job.executor.logpath");
}
xxlJobExecutor.setLogPath(envLogPath);

String envLogRetentionDays = System.getenv("XXL_JOB_EXECUTOR_LOGRETENTIONDAYS");
if (envLogRetentionDays == null) {
envLogRetentionDays = xxlJobProp.getProperty("xxl.job.executor.logretentiondays");
}
xxlJobExecutor.setLogRetentionDays(Integer.valueOf(envLogRetentionDays));

// registry job bean
xxlJobExecutor.setXxlJobBeanList(Arrays.asList(new SampleXxlJob()));
Expand All @@ -64,13 +102,12 @@ public void destroyXxlJobExecutor() {
}
}


public static Properties loadProperties(String propertyFileName) {
InputStreamReader in = null;
try {
ClassLoader loder = Thread.currentThread().getContextClassLoader();

in = new InputStreamReader(loder.getResourceAsStream(propertyFileName), "UTF-8");;
in = new InputStreamReader(loder.getResourceAsStream(propertyFileName), "UTF-8");
if (in != null) {
Properties prop = new Properties();
prop.load(in);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
1. /etc/default/xxl-job-executor-mgmt-9999

XXL_JOB_EXECUTOR_APPNAME=mgmt
XXL_JOB_EXECUTOR_PORT=9999

2. /etc/systemd/system/xxl-job-executor@.service

[Unit]
Description=xxl-job-executor service

[Service]
ExecStart=/usr/bin/java -jar /opt/xxl-job-executor-2.4.1.jar
Restart=always
User=root
EnvironmentFile=/etc/default/xxl-job-executor-%i
Environment=XXL_JOB_ACCESS_TOKEN=default_token
Environment=XXL_JOB_ADMIN_ADDRESSES=http://127.0.0.1:8080/xxl-job-admin
Environment=JAVA_OPTS="-Xmx512m"

[Install]
WantedBy=default.target

3. systemctl enable xxl-job-executor@mgmt-9999.service

4. systemctl start xxl-job-executor@mgmt-9999.service