-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PipelineJobConfigurationManager (#29198)
* Add PipelineJobConfigurationLoader * Refactor PipelineJobConfigurationLoader * Add PipelineJobConfigurationLoader * Add PipelineJobConfigurationManager
- Loading branch information
Showing
16 changed files
with
131 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...apache/shardingsphere/data/pipeline/core/job/service/PipelineJobConfigurationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.shardingsphere.data.pipeline.common.config.job.PipelineJobConfiguration; | ||
import org.apache.shardingsphere.data.pipeline.common.listener.PipelineElasticJobListener; | ||
import org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtils; | ||
import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO; | ||
import org.apache.shardingsphere.infra.util.yaml.YamlEngine; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Pipeline job configuration manager. | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class PipelineJobConfigurationManager { | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
private final PipelineJobAPI jobAPI; | ||
|
||
/** | ||
* Get job configuration. | ||
* | ||
* @param jobId job ID | ||
* @param <T> type of pipeline job configuration | ||
* @return pipeline job configuration | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <T extends PipelineJobConfiguration> T getJobConfiguration(final String jobId) { | ||
return (T) jobAPI.getYamlJobConfigurationSwapper().swapToObject(PipelineJobIdUtils.getElasticJobConfigurationPOJO(jobId).getJobParameter()); | ||
} | ||
|
||
/** | ||
* Convert to job configuration POJO. | ||
* | ||
* @param jobConfig pipeline job configuration | ||
* @return converted job configuration POJO | ||
*/ | ||
public JobConfigurationPOJO convertToJobConfigurationPOJO(final PipelineJobConfiguration jobConfig) { | ||
JobConfigurationPOJO result = new JobConfigurationPOJO(); | ||
result.setJobName(jobConfig.getJobId()); | ||
int shardingTotalCount = jobAPI.isForceNoShardingWhenConvertToJobConfigurationPOJO() ? 1 : jobConfig.getJobShardingCount(); | ||
result.setShardingTotalCount(shardingTotalCount); | ||
result.setJobParameter(YamlEngine.marshal(jobAPI.getYamlJobConfigurationSwapper().swapToYamlConfiguration(jobConfig))); | ||
String createTimeFormat = LocalDateTime.now().format(DATE_TIME_FORMATTER); | ||
result.getProps().setProperty("create_time", createTimeFormat); | ||
result.getProps().setProperty("start_time_millis", String.valueOf(System.currentTimeMillis())); | ||
result.getProps().setProperty("run_count", "1"); | ||
result.setJobListenerTypes(Collections.singletonList(PipelineElasticJobListener.class.getName())); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.