Skip to content

Commit

Permalink
Fixed #327.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed May 24, 2017
1 parent 6ea4f7f commit 509bdf4
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 42 deletions.
4 changes: 3 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

### 功能提升

1. [ISSUE #327](https://github.com/dangdangdotcom/elastic-job/issues/327) spring命名空间支持使用xml方式配置bean
1. [ISSUE #332](https://github.com/dangdangdotcom/elastic-job/issues/332) elastic-job-cloud增加Docker镜像dangdangdotcom/elastic-job-cloud

### 缺陷修正

1. [ISSUE #321](https://github.com/dangdangdotcom/elastic-job/issues/321)新版2.1.2的console版本在添加注册中心时命名空间不支持/
1. [ISSUE #321](https://github.com/dangdangdotcom/elastic-job/issues/321) elastic-job-lite界面在添加注册中心时命名空间不支持/
1. [ISSUE #333](https://github.com/dangdangdotcom/elastic-job/issues/333) elastic-job-lite界面中注册中心配置中登录凭证隐式显示

## 2.1.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ Root对应JobRootConfiguration,有2个子类分别对应Lite和Cloud部署类
<!-- 配置简单作业-->
<job:simple id="simpleElasticJob" class="xxx.MySimpleElasticJob" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" />

<bean id="yourRefJobBeanId" class="xxx.MySimpleRefElasticJob">
<property name="fooService" ref="xxx.FooService"/>
</bean>

<!-- 配置关联Bean作业-->
<job:simple id="simpleRefElasticJob" job-ref="yourRefJobBeanId" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" />

<!-- 配置数据流作业-->
<job:dataflow id="throughputDataflow" class="xxx.MyThroughputDataflowElasticJob" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" />

Expand All @@ -182,7 +189,7 @@ Root对应JobRootConfiguration,有2个子类分别对应Lite和Cloud部署类
</job:simple>

<!-- 配置带作业数据库事件追踪的简单作业-->
<job:simple id="listenerElasticJob" class="xxx.MySimpleListenerElasticJob" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" event-trace-rdb-data-source="yourDataSource">
<job:simple id="eventTraceElasticJob" class="xxx.MySimpleListenerElasticJob" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" event-trace-rdb-data-source="yourDataSource">
</job:simple>
</beans>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Spring命名空间与Java Code方式配置类似,大部分属性只是将命
| ------------------------------------|:--------|:--------|:----------------|:---------------------------------------------------------------------------|
| id | String || | 作业名称 |
| class | String || | 作业实现类,需实现ElasticJob接口 |
| job-ref | String || | 作业关联的beanId,该配置优先级大于class属性配置 |
| registry-center-ref | String || | 注册中心Bean的引用,需引用reg:zookeeper的声明 |
| cron | String || | cron表达式,用于控制作业触发时间 |
| sharding-total-count | int || | 作业分片总数 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,7 @@
import java.util.EnumMap;
import java.util.List;

import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CRON_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.DESCRIPTION_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.DISABLED_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.DISTRIBUTED_LISTENER_COMPLETED_TIMEOUT_MILLISECONDS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.DISTRIBUTED_LISTENER_STARTED_TIMEOUT_MILLISECONDS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.DISTRIBUTED_LISTENER_TAG;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.EVENT_TRACE_RDB_DATA_SOURCE_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.EXECUTOR_SERVICE_HANDLER_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.FAILOVER_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.JOB_EXCEPTION_HANDLER_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.JOB_PARAMETER_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.JOB_SHARDING_STRATEGY_CLASS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.LISTENER_TAG;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.MAX_TIME_DIFF_SECONDS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.MISFIRE_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.MONITOR_EXECUTION_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.MONITOR_PORT_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.OVERWRITE_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.RECONCILE_INTERVAL_MINUTES;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.REGISTRY_CENTER_REF_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.SHARDING_ITEM_PARAMETERS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.SHARDING_TOTAL_COUNT_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.*;

/**
* 基本作业的命名空间解析器.
Expand All @@ -72,13 +50,18 @@ public abstract class AbstractJobBeanDefinitionParser extends AbstractBeanDefini
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
factory.setInitMethodName("init");
if ("".equals(element.getAttribute(CLASS_ATTRIBUTE))) {
factory.addConstructorArgValue(null);
//TODO 抽象子类
if ("".equals(element.getAttribute(JOB_REF_ATTRIBUTE))) {
if ("".equals(element.getAttribute(CLASS_ATTRIBUTE))) {
factory.addConstructorArgValue(null);
} else {
factory.addConstructorArgValue(BeanDefinitionBuilder.rootBeanDefinition(element.getAttribute(CLASS_ATTRIBUTE)).getBeanDefinition());
}
} else {
factory.addConstructorArgValue(BeanDefinitionBuilder.rootBeanDefinition(element.getAttribute(CLASS_ATTRIBUTE)).getBeanDefinition());
factory.addConstructorArgReference(element.getAttribute(JOB_REF_ATTRIBUTE));
}
factory.addConstructorArgReference(element.getAttribute(REGISTRY_CENTER_REF_ATTRIBUTE));
factory.addConstructorArgValue(createLiteJobConfiguration(element));
factory.addConstructorArgValue(createLiteJobConfiguration(parserContext, element));
BeanDefinition jobEventConfig = createJobEventConfig(element);
if (null != jobEventConfig) {
factory.addConstructorArgValue(jobEventConfig);
Expand All @@ -87,15 +70,15 @@ protected AbstractBeanDefinition parseInternal(final Element element, final Pars
return factory.getBeanDefinition();
}

protected abstract BeanDefinition getJobTypeConfigurationBeanDefinition(final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element);
protected abstract BeanDefinition getJobTypeConfigurationBeanDefinition(ParserContext parserContext, BeanDefinition jobCoreConfigurationBeanDefinition, Element element);

private BeanDefinition createLiteJobConfiguration(final Element element) {
return createLiteJobConfigurationBeanDefinition(element, createJobCoreBeanDefinition(element));
private BeanDefinition createLiteJobConfiguration(final ParserContext parserContext, final Element element) {
return createLiteJobConfigurationBeanDefinition(parserContext, element, createJobCoreBeanDefinition(element));
}

private BeanDefinition createLiteJobConfigurationBeanDefinition(final Element element, final BeanDefinition jobCoreBeanDefinition) {
private BeanDefinition createLiteJobConfigurationBeanDefinition(final ParserContext parserContext, final Element element, final BeanDefinition jobCoreBeanDefinition) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(LiteJobConfiguration.class);
result.addConstructorArgValue(getJobTypeConfigurationBeanDefinition(jobCoreBeanDefinition, element));
result.addConstructorArgValue(getJobTypeConfigurationBeanDefinition(parserContext, jobCoreBeanDefinition, element));
result.addConstructorArgValue(element.getAttribute(MONITOR_EXECUTION_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(MAX_TIME_DIFF_SECONDS_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(MONITOR_PORT_ATTRIBUTE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class BaseJobBeanDefinitionParserTag {

public static final String REGISTRY_CENTER_REF_ATTRIBUTE = "registry-center-ref";

public static final String CLASS_ATTRIBUTE = "class";

public static final String JOB_REF_ATTRIBUTE = "job-ref";

public static final String REGISTRY_CENTER_REF_ATTRIBUTE = "registry-center-ref";

public static final String CRON_ATTRIBUTE = "cron";

public static final String SHARDING_TOTAL_COUNT_ATTRIBUTE = "sharding-total-count";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@

import com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration;
import com.dangdang.ddframe.job.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
import com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag;
import com.google.common.base.Strings;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE;

/**
* 数据流作业的命名空间解析器.
*
Expand All @@ -32,10 +36,14 @@
public final class DataflowJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {

@Override
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(DataflowJobConfiguration.class);
result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE));
if (Strings.isNullOrEmpty(element.getAttribute(CLASS_ATTRIBUTE))) {
result.addConstructorArgValue(parserContext.getRegistry().getBeanDefinition(element.getAttribute(JOB_REF_ATTRIBUTE)).getBeanClassName());
} else {
result.addConstructorArgValue(element.getAttribute(CLASS_ATTRIBUTE));
}
result.addConstructorArgValue(element.getAttribute(DataflowJobBeanDefinitionParserTag.STREAMING_PROCESS_ATTRIBUTE));
return result.getBeanDefinition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.dangdang.ddframe.job.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
Expand All @@ -31,7 +32,7 @@
public final class ScriptJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {

@Override
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ScriptJobConfiguration.class);
result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
result.addConstructorArgValue(element.getAttribute(ScriptJobBeanDefinitionParserTag.SCRIPT_COMMAND_LINE_ATTRIBUTE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
import com.google.common.base.Strings;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE;

/**
* 简单作业的命名空间解析器.
Expand All @@ -33,10 +36,14 @@
public final class SimpleJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {

@Override
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(SimpleJobConfiguration.class);
result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
result.addConstructorArgValue(element.getAttribute(CLASS_ATTRIBUTE));
if (Strings.isNullOrEmpty(element.getAttribute(CLASS_ATTRIBUTE))) {
result.addConstructorArgValue(parserContext.getRegistry().getBeanDefinition(element.getAttribute(JOB_REF_ATTRIBUTE)).getBeanClassName());
} else {
result.addConstructorArgValue(element.getAttribute(CLASS_ATTRIBUTE));
}
return result.getBeanDefinition();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<xsd:element ref="distributed-listener" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="class" type="xsd:string" />
<xsd:attribute name="job-ref" type="xsd:string" />
<xsd:attribute name="registry-center-ref" type="xsd:string" use="required" />
<xsd:attribute name="cron" type="xsd:string" use="required" />
<xsd:attribute name="sharding-total-count" type="xsd:string" use="required" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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.
* </p>
*/

package com.dangdang.ddframe.job.lite.spring.fixture.job.ref;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.dangdang.ddframe.job.lite.spring.fixture.service.FooService;
import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

public class RefFooDataflowElasticJob implements DataflowJob<String> {

@Getter
private static volatile boolean completed;

@Getter
@Setter
private FooService fooService;

@Override
public List<String> fetchData(final ShardingContext shardingContext) {
if (completed) {
return Collections.emptyList();
}
fooService.foo();
return Collections.singletonList("data");
}

@Override
public void processData(final ShardingContext shardingContext, final List<String> data) {
completed = true;
}

public static void reset() {
completed = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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.
* </p>
*/

package com.dangdang.ddframe.job.lite.spring.fixture.job.ref;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.ddframe.job.lite.spring.fixture.service.FooService;
import lombok.Getter;
import lombok.Setter;

public class RefFooSimpleElasticJob implements SimpleJob {

@Getter
private static volatile boolean completed;

@Getter
@Setter
private FooService fooService;

@Override
public void execute(final ShardingContext shardingContext) {
fooService.foo();
completed = true;
}

public static void reset() {
completed = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@SuiteClasses({
JobSpringNamespaceWithoutListenerTest.class,
JobSpringNamespaceWithJobPropertiesTest.class,
JobSpringNamespaceWithRefTest.class,
JobSpringNamespaceWithListenerTest.class,
JobSpringNamespaceWithListenerAndJdkDynamicProxyTest.class,
JobSpringNamespaceWithListenerAndCglibTest.class,
Expand Down
Loading

0 comments on commit 509bdf4

Please sign in to comment.