diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index cc15a9a35..c1d4605a3 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -56,6 +56,7 @@ jobs: - { name: 'spring-kafka-2.2.x-scenario', title: 'Spring-Kafka 2.2.x (7)' } - { name: 'spring-kafka-2.3.x-scenario', title: 'Spring-Kafka 2.3.x (7)' } - { name: 'spring-scheduled-scenario', title: 'Spring Scheduled 3.1.x-5.2.x (9)' } + - { name: 'elasticjob-2.x-scenario', title: 'elasticjob-2.x-scenario (2)' } steps: - uses: actions/checkout@v2 with: diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java index ab3cc9f39..3a87b3777 100644 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java @@ -18,11 +18,11 @@ package org.apache.skywalking.apm.plugin.esjob; -import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.event.type.JobExecutionEvent; import com.dangdang.ddframe.job.executor.ShardingContexts; -import com.google.common.base.Strings; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; @@ -31,23 +31,31 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** - * {@link JobExecutorInterceptor} enhances {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor#process(ShardingContext)} + * {@link JobExecutorInterceptor} enhances {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor#process(ShardingContexts, int, JobExecutionEvent)} * ,creating a local span that records job execution. */ public class JobExecutorInterceptor implements InstanceMethodsAroundInterceptor { + + private static final AbstractTag TAG_ITEM = Tags.ofKey("item"); + private static final AbstractTag TAG_TASK_ID = Tags.ofKey("taskId"); + private static final AbstractTag TAG_SHARDING_TOTAL_COUNT = Tags.ofKey("shardingTotalCount"); + private static final AbstractTag TAG_SHARDING_ITEM_PARAMETERS = Tags.ofKey("shardingItemParameters"); + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { ShardingContexts shardingContexts = (ShardingContexts) allArguments[0]; Integer item = (Integer) allArguments[1]; - ShardingContext shardingContext = new ShardingContext(shardingContexts, item); - String operateName = shardingContext.getJobName(); - if (!Strings.isNullOrEmpty(shardingContext.getShardingParameter())) { - operateName += "-" + shardingContext.getShardingParameter(); - } + String operateName = ComponentsDefine.ELASTIC_JOB.getName() + "/" + shardingContexts.getJobName(); + AbstractSpan span = ContextManager.createLocalSpan(operateName); span.setComponent(ComponentsDefine.ELASTIC_JOB); - span.tag(Tags.ofKey("sharding_context"), shardingContext.toString()); + Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT); + + span.tag(TAG_ITEM, item == null ? "" : String.valueOf(item)); + span.tag(TAG_TASK_ID, shardingContexts.getTaskId()); + span.tag(TAG_SHARDING_TOTAL_COUNT, Integer.toString(shardingContexts.getShardingTotalCount())); + span.tag(TAG_SHARDING_ITEM_PARAMETERS, shardingContexts.getShardingItemParameters() == null ? "" : shardingContexts.getShardingItemParameters().toString()); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java index a565ceb0c..3304f6e03 100644 --- a/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java @@ -29,6 +29,7 @@ import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.network.language.agent.v3.SpanObject; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -69,13 +70,21 @@ public class JobExecutorInterceptorTest { List spans = SegmentHelper.getSpans(segment); assertNotNull(spans); assertThat(spans.size(), is(1)); - assertThat(spans.get(0).transform().getOperationName(), is("fooJob-test")); - assertThat(spans.get(0).transform().getComponentId(), is(24)); - assertThat(spans.get(0).transform().getTags(0).getKey(), is("sharding_context")); - assertThat(spans.get(0) - .transform() - .getTags(0) - .getValue(), is("ShardingContext(jobName=fooJob, taskId=fooJob1, shardingTotalCount=2, jobParameter=, shardingItem=1, shardingParameter=test)")); + + SpanObject.Builder builder = spans.get(0).transform(); + + assertThat(builder.getOperationName(), is("ElasticJob/fooJob")); + assertThat(builder.getComponentId(), is(24)); + assertThat(builder.getTags(0).getKey(), is("x-le")); + assertThat(builder.getTags(0).getValue(), is("{\"logic-span\":true}")); + assertThat(builder.getTags(1).getKey(), is("item")); + assertThat(builder.getTags(1).getValue(), is("1")); + assertThat(builder.getTags(2).getKey(), is("taskId")); + assertThat(builder.getTags(2).getValue(), is("fooJob1")); + assertThat(builder.getTags(3).getKey(), is("shardingTotalCount")); + assertThat(builder.getTags(3).getValue(), is("2")); + assertThat(builder.getTags(4).getKey(), is("shardingItemParameters")); + assertThat(builder.getTags(4).getValue(), is("{1=test}")); } @Test @@ -89,11 +98,21 @@ public class JobExecutorInterceptorTest { List spans = SegmentHelper.getSpans(segment); assertNotNull(spans); assertThat(spans.size(), is(1)); - assertThat(spans.get(0).transform().getOperationName(), is("fooJob")); - assertThat(spans.get(0) - .transform() - .getTags(0) - .getValue(), is("ShardingContext(jobName=fooJob, taskId=fooJob0, shardingTotalCount=1, jobParameter=, shardingItem=0, shardingParameter=null)")); + + SpanObject.Builder builder = spans.get(0).transform(); + + assertThat(builder.getOperationName(), is("ElasticJob/fooJob")); + assertThat(builder.getComponentId(), is(24)); + assertThat(builder.getTags(0).getKey(), is("x-le")); + assertThat(builder.getTags(0).getValue(), is("{\"logic-span\":true}")); + assertThat(builder.getTags(1).getKey(), is("item")); + assertThat(builder.getTags(1).getValue(), is("0")); + assertThat(builder.getTags(2).getKey(), is("taskId")); + assertThat(builder.getTags(2).getValue(), is("fooJob0")); + assertThat(builder.getTags(3).getKey(), is("shardingTotalCount")); + assertThat(builder.getTags(3).getValue(), is("1")); + assertThat(builder.getTags(4).getKey(), is("shardingItemParameters")); + assertThat(builder.getTags(4).getValue(), is("{}")); } @Test diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/bin/startup.sh b/test/plugin/scenarios/elasticjob-2.x-scenario/bin/startup.sh new file mode 100644 index 000000000..41d2c7d49 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +home="$(cd "$(dirname $0)"; pwd)" + +java -Dzookeeper.host=${ZK_ADDRESS} -jar ${agent_opts} -Dco.paralleluniverse.fibers.detectRunawayFibers=false ${home}/../libs/elasticjob-2.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/elasticjob-2.x-scenario/config/expectedData.yaml new file mode 100644 index 000000000..9890f364d --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/config/expectedData.yaml @@ -0,0 +1,73 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +segmentItems: +- serviceName: elasticjob-2.x-scenario + segmentSize: ge 2 + segments: + - segmentId: not null + spans: + - operationName: /elasticjob-2.x-scenario/case/call + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + skipAnalysis: false + tags: + - {key: url, value: 'http://localhost:8080/elasticjob-2.x-scenario/case/call'} + - {key: http.method, value: GET} + refs: + - {parentEndpoint: ElasticJob/org.apache.skywalking.apm.testcase.elasticjob.job.DemoSimpleJob, networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: not null, traceId: not null} + - segmentId: not null + spans: + - operationName: /elasticjob-2.x-scenario/case/call + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: not null + endTime: not null + componentId: 12 + isError: false + spanType: Exit + peer: localhost:8080 + skipAnalysis: false + tags: + - {key: http.method, value: GET} + - {key: url, value: 'http://localhost:8080/elasticjob-2.x-scenario/case/call'} + - operationName: ElasticJob/org.apache.skywalking.apm.testcase.elasticjob.job.DemoSimpleJob + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: not null + endTime: not null + componentId: 24 + isError: false + spanType: Local + peer: '' + skipAnalysis: false + tags: + - {key: x-le, value: '{"logic-span":true}'} + - {key: item, value: '0'} + - {key: taskId, value: not null} + - {key: shardingTotalCount, value: '1'} + - {key: shardingItemParameters, value: '{0=test}'} \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/configuration.yml b/test/plugin/scenarios/elasticjob-2.x-scenario/configuration.yml new file mode 100644 index 000000000..5ae9d7838 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/configuration.yml @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +type: jvm +entryService: http://localhost:8080/elasticjob-2.x-scenario/case/healthCheck +healthCheck: http://localhost:8080/elasticjob-2.x-scenario/case/healthCheck +startScript: ./bin/startup.sh +environment: + - ZK_ADDRESS=zk-server:2181 +depends_on: + - zk-server +dependencies: + zk-server: + image: zookeeper:3.6.0 + hostname: zk-server \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/pom.xml b/test/plugin/scenarios/elasticjob-2.x-scenario/pom.xml new file mode 100644 index 000000000..f6dd1e277 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/pom.xml @@ -0,0 +1,132 @@ + + + + + org.apache.skywalking.apm.testcase + elasticjob-2.x-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + + 2.0.3 + 2.1.6.RELEASE + 1.18.10 + 3.0.0 + + + skywalking-elasticjob-2.x-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + com.dangdang + elastic-job-lite-spring + ${test.framework.version} + + + + com.squareup.okhttp3 + okhttp + ${okhttp-version} + + + + + elasticjob-2.x-scenario + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 000000000..cc07e4043 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/elasticjob-2.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/Application.java b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/Application.java new file mode 100644 index 000000000..f75df64fe --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/Application.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.elasticjob; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/controller/CaseController.java b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/controller/CaseController.java new file mode 100644 index 000000000..c63f9e626 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/controller/CaseController.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.elasticjob.controller; + +import lombok.extern.log4j.Log4j2; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/case") +@Log4j2 +public class CaseController { + + private static final String SUCCESS = "Success"; + + @RequestMapping("/call") + @ResponseBody + public String call() { + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + return SUCCESS; + } + +} diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/DemoSimpleJob.java b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/DemoSimpleJob.java new file mode 100644 index 000000000..fc753851e --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/DemoSimpleJob.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.elasticjob.job; + +import com.dangdang.ddframe.job.api.ShardingContext; +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +import java.io.IOException; + +@Slf4j +public class DemoSimpleJob implements SimpleJob { + + private static final OkHttpClient client = new OkHttpClient.Builder().build(); + + @Override + public void execute(ShardingContext shardingContext) { + log.info("Elastic job execute: {}", shardingContext.getJobName()); + + Request request = new Request.Builder().url("http://localhost:8080/elasticjob-2.x-scenario/case/call").build(); + Response response = null; + try { + response = client.newCall(request).execute(); + } catch (IOException e) { + throw new RuntimeException(e); + } + response.body().close(); + } +} diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/JobConfig.java b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/JobConfig.java new file mode 100644 index 000000000..aba1bdd9d --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticjob/job/JobConfig.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.testcase.elasticjob.job; + +import com.dangdang.ddframe.job.api.simple.SimpleJob; +import com.dangdang.ddframe.job.config.JobCoreConfiguration; +import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration; +import com.dangdang.ddframe.job.lite.api.JobScheduler; +import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration; +import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler; +import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter; +import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration; +import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class JobConfig { + + private final String cron = "0/5 * * * * ?"; + private final int shardingTotalCount = 1; + private final String shardingItemParameters = "0=test"; + private final String jobParameters = "parameter"; + + @Bean + public SimpleJob simpleJob() { + return new DemoSimpleJob(); + } + + @Bean(initMethod = "init") + public ZookeeperRegistryCenter regCenter(@Value("${elasticjob.regCenter.serverList}") final String serverList, + @Value("${elasticjob.regCenter.namespace}") final String namespace) { + return new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, namespace)); + } + + @Bean(initMethod = "init") + public JobScheduler simpleJobScheduler(final SimpleJob simpleJob, final CoordinatorRegistryCenter regCenter) { + return new SpringJobScheduler(simpleJob, regCenter, + getLiteJobConfiguration(simpleJob.getClass(), + cron, shardingTotalCount, shardingItemParameters, jobParameters)); + } + + private LiteJobConfiguration getLiteJobConfiguration(final Class jobClass, + final String cron, + final int shardingTotalCount, + final String shardingItemParameters, + final String jobParameters) { + JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration + .newBuilder(jobClass.getName(), cron, shardingTotalCount) + .shardingItemParameters(shardingItemParameters) + .jobParameter(jobParameters) + .build(); + + SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, jobClass.getCanonicalName()); + + LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration + .newBuilder(simpleJobConfig) + .overwrite(true).build(); + return simpleJobRootConfig; + } +} \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/application.yaml new file mode 100644 index 000000000..d523e22a6 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/application.yaml @@ -0,0 +1,28 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +server: + port: 8080 + servlet: + context-path: /elasticjob-2.x-scenario +logging: + config: classpath:log4j2.xml + +elasticjob: + regCenter: + serverList: ${zookeeper.host} + namespace: elasticjob-lite-springboot \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 000000000..b16354bfa --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/elasticjob-2.x-scenario/support-version.list b/test/plugin/scenarios/elasticjob-2.x-scenario/support-version.list new file mode 100644 index 000000000..57f7652d2 --- /dev/null +++ b/test/plugin/scenarios/elasticjob-2.x-scenario/support-version.list @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# lists your version here +2.0.3 +2.1.5 \ No newline at end of file