You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/20 10:26:19 UTC

[shardingsphere-elasticjob] branch master updated: Move ShardingItemParameters (#1195)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new c42d345  Move ShardingItemParameters (#1195)
c42d345 is described below

commit c42d3455320e4cc66293f87b1ddb775d34400f84
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Jul 20 18:26:09 2020 +0800

    Move ShardingItemParameters (#1195)
---
 .../cloud/util/config/ShardingItemParameters.java  | 80 ----------------------
 .../cloud/executor/local/LocalTaskExecutor.java    |  2 +-
 .../mesos/TaskLaunchScheduledService.java          |  2 +-
 .../infra/context}/ShardingItemParameters.java     |  2 +-
 .../infra/context}/ShardingItemParametersTest.java |  4 +-
 .../internal/sharding/ExecutionContextService.java |  1 +
 .../sharding/ShardingItemParametersTest.java       | 55 ---------------
 7 files changed, 6 insertions(+), 140 deletions(-)

diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParameters.java b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParameters.java
deleted file mode 100755
index c4fff6f..0000000
--- a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParameters.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.cloud.util.config;
-
-import com.google.common.base.Strings;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Sharding item parameters.
- */
-@Getter
-public final class ShardingItemParameters {
-    
-    private static final String PARAMETER_DELIMITER = ",";
-    
-    private static final String KEY_VALUE_DELIMITER = "=";
-    
-    private final Map<Integer, String> map;
-    
-    public ShardingItemParameters(final String shardingItemParameters) {
-        map = toMap(shardingItemParameters);
-    }
-    
-    private Map<Integer, String> toMap(final String originalShardingItemParameters) {
-        if (Strings.isNullOrEmpty(originalShardingItemParameters)) {
-            return Collections.emptyMap();
-        }
-        String[] shardingItemParameters = originalShardingItemParameters.split(PARAMETER_DELIMITER);
-        Map<Integer, String> result = new HashMap<>(shardingItemParameters.length);
-        for (String each : shardingItemParameters) {
-            ShardingItem shardingItem = parse(each, originalShardingItemParameters);
-            result.put(shardingItem.item, shardingItem.parameter);
-        }
-        return result;
-    }
-    
-    private ShardingItem parse(final String shardingItemParameter, final String originalShardingItemParameters) {
-        String[] pair = shardingItemParameter.trim().split(KEY_VALUE_DELIMITER);
-        if (2 != pair.length) {
-            throw new JobConfigurationException("Sharding item parameters '%s' format error, should be int=xx,int=xx", originalShardingItemParameters);
-        }
-        try {
-            return new ShardingItem(Integer.parseInt(pair[0].trim()), pair[1].trim());
-        } catch (final NumberFormatException ex) {
-            throw new JobConfigurationException("Sharding item parameters key '%s' is not an integer.", pair[0]);
-        }
-    }
-
-    /**
-     * Sharding item.
-     */
-    @AllArgsConstructor
-    private static final class ShardingItem {
-        
-        private final int item;
-        
-        private final String parameter;
-    }
-}
diff --git a/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/LocalTaskExecutor.java b/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/LocalTaskExecutor.java
index d12f52b..5d43276 100755
--- a/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/LocalTaskExecutor.java
+++ b/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/LocalTaskExecutor.java
@@ -24,9 +24,9 @@ import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.api.listener.ShardingContexts;
 import org.apache.shardingsphere.elasticjob.cloud.executor.CloudJobFacade;
 import org.apache.shardingsphere.elasticjob.cloud.executor.JobTypeConfigurationUtil;
-import org.apache.shardingsphere.elasticjob.cloud.util.config.ShardingItemParameters;
 import org.apache.shardingsphere.elasticjob.executor.ElasticJobExecutor;
 import org.apache.shardingsphere.elasticjob.executor.JobFacade;
+import org.apache.shardingsphere.elasticjob.infra.context.ShardingItemParameters;
 import org.apache.shardingsphere.elasticjob.tracing.JobEventBus;
 
 import java.util.HashMap;
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
index e6c301a..13578ab 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
@@ -38,8 +38,8 @@ import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
 import org.apache.shardingsphere.elasticjob.cloud.config.pojo.CloudJobConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.pojo.CloudAppConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
-import org.apache.shardingsphere.elasticjob.cloud.util.config.ShardingItemParameters;
 import org.apache.shardingsphere.elasticjob.infra.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.infra.context.ShardingItemParameters;
 import org.apache.shardingsphere.elasticjob.infra.context.TaskContext;
 import org.apache.shardingsphere.elasticjob.infra.context.TaskContext.MetaInfo;
 import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParameters.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParameters.java
similarity index 97%
rename from elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParameters.java
rename to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParameters.java
index 4801b6f..da58282 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParameters.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParameters.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.elasticjob.lite.internal.sharding;
+package org.apache.shardingsphere.elasticjob.infra.context;
 
 import com.google.common.base.Strings;
 import lombok.AllArgsConstructor;
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParametersTest.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParametersTest.java
similarity index 96%
rename from elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParametersTest.java
rename to elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParametersTest.java
index 405fdd7..8d0bb22 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/util/config/ShardingItemParametersTest.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/context/ShardingItemParametersTest.java
@@ -7,7 +7,7 @@
  * 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.
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.elasticjob.cloud.util.config;
+package org.apache.shardingsphere.elasticjob.infra.context;
 
 import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
 import org.junit.Test;
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
index be1464a..dc4b6df 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.elasticjob.lite.internal.sharding;
 
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.api.listener.ShardingContexts;
+import org.apache.shardingsphere.elasticjob.infra.context.ShardingItemParameters;
 import org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobInstance;
 import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParametersTest.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParametersTest.java
deleted file mode 100644
index 874332a..0000000
--- a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingItemParametersTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.internal.sharding;
-
-import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class ShardingItemParametersTest {
-    
-    @Test(expected = JobConfigurationException.class)
-    public void assertNewWhenPairFormatInvalid() {
-        new ShardingItemParameters("xxx-xxx");
-    }
-    
-    @Test(expected = JobConfigurationException.class)
-    public void assertNewWhenItemIsNotNumber() {
-        new ShardingItemParameters("xxx=xxx");
-    }
-    
-    @Test
-    public void assertGetMapWhenIsEmpty() {
-        assertThat(new ShardingItemParameters("").getMap(), is(Collections.EMPTY_MAP));
-    }
-    
-    @Test
-    public void assertGetMap() {
-        Map<Integer, String> expected = new HashMap<>(3);
-        expected.put(0, "A");
-        expected.put(1, "B");
-        expected.put(2, "C");
-        assertThat(new ShardingItemParameters("0=A,1=B,2=C").getMap(), is(expected));
-    }
-}