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.git
The following commit(s) were added to refs/heads/master by this push:
new 7b032212691 Use PipelineJobType.getTypeAliases() to instead of
JobCodeRegistry (#37118)
7b032212691 is described below
commit 7b03221269149bea9f9f660638962972c8c81560
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 15 22:36:01 2025 +0800
Use PipelineJobType.getTypeAliases() to instead of JobCodeRegistry (#37118)
* Use PipelineJobType.getTypeAliases() to instead of JobCodeRegistry
* Use PipelineJobType.getTypeAliases() to instead of JobCodeRegistry
---
.../pipeline/core/job/id/PipelineJobIdUtils.java | 5 +-
.../pipeline/core/job/type/JobCodeRegistry.java | 54 ----------------------
.../pipeline/core/job/type/PipelineJobType.java | 8 ++++
.../core/job/type/JobCodeRegistryTest.java | 46 ------------------
4 files changed, 11 insertions(+), 102 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
index 46baa0beffa..4073f908004 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
@@ -27,11 +27,11 @@ import org.apache.commons.codec.binary.Hex;
import org.apache.shardingsphere.data.pipeline.core.context.PipelineContextKey;
import
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobNotFoundException;
import org.apache.shardingsphere.data.pipeline.core.job.api.PipelineAPIFactory;
-import org.apache.shardingsphere.data.pipeline.core.job.type.JobCodeRegistry;
import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.nio.charset.StandardCharsets;
@@ -39,6 +39,7 @@ import java.nio.charset.StandardCharsets;
* Pipeline job id utility class.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@SuppressWarnings("rawtypes")
public final class PipelineJobIdUtils {
/**
@@ -67,7 +68,7 @@ public final class PipelineJobIdUtils {
*/
public static PipelineJobType parseJobType(final String jobId) {
verifyJobId(jobId);
- return JobCodeRegistry.getJobType(jobId.substring(1, 3));
+ return TypedSPILoader.getService(PipelineJobType.class,
jobId.substring(1, 3));
}
/**
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
deleted file mode 100644
index d856e3d46f0..00000000000
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
+++ /dev/null
@@ -1,54 +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.data.pipeline.core.job.type;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Job code registry.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@SuppressWarnings("rawtypes")
-public final class JobCodeRegistry {
-
- private static final Map<String, PipelineJobType> JOB_CODE_AND_TYPE_MAP =
new HashMap<>();
-
- static {
- for (PipelineJobType each :
ShardingSphereServiceLoader.getServiceInstances(PipelineJobType.class)) {
- Preconditions.checkArgument(2 ==
each.getOption().getCode().length(), "Job type code length is not 2.");
- JOB_CODE_AND_TYPE_MAP.put(each.getOption().getCode(), each);
- }
- }
-
- /**
- * Get job type.
- *
- * @param jobTypeCode job type code
- * @return job type
- */
- public static PipelineJobType getJobType(final String jobTypeCode) {
-
Preconditions.checkArgument(JOB_CODE_AND_TYPE_MAP.containsKey(jobTypeCode),
"Can not get job type by `%s`.", jobTypeCode);
- return JOB_CODE_AND_TYPE_MAP.get(jobTypeCode);
- }
-}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/PipelineJobType.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/PipelineJobType.java
index fc115063047..e57c0ddff66 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/PipelineJobType.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/PipelineJobType.java
@@ -26,6 +26,9 @@ import
org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobObjective;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
+import java.util.Collection;
+import java.util.Collections;
+
/**
* Pipeline job type.
*
@@ -66,4 +69,9 @@ public interface PipelineJobType<T extends
PipelineJobConfiguration> extends Typ
@Override
String getType();
+
+ @Override
+ default Collection<Object> getTypeAliases() {
+ return Collections.singleton(getOption().getCode());
+ }
}
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
deleted file mode 100644
index 740f46b46b3..00000000000
---
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
+++ /dev/null
@@ -1,46 +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.data.pipeline.core.job.type;
-
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
-import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings(ShardingSphereServiceLoader.class)
-class JobCodeRegistryTest {
-
- @Test
- void assertGetJobType() {
- PipelineJobType<?> pipelineJobType = mock(PipelineJobType.class,
RETURNS_DEEP_STUBS);
- when(pipelineJobType.getOption().getCode()).thenReturn("-1");
- when(pipelineJobType.getType()).thenReturn("FIXTURE");
-
when(ShardingSphereServiceLoader.getServiceInstances(PipelineJobType.class)).thenReturn(Collections.singleton(pipelineJobType));
- assertThat(JobCodeRegistry.getJobType("-1").getType(), is("FIXTURE"));
- }
-}