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

menghaoran 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 fd8698b  add create_time and stop_time for scaling job. (#9541)
fd8698b is described below

commit fd8698bfb1854647122582374db2cb1a4a37b41b
Author: 邱鹿 Lucas <[email protected]>
AuthorDate: Mon Mar 1 16:54:19 2021 +0800

    add create_time and stop_time for scaling job. (#9541)
    
    Co-authored-by: qiulu3 <Lucas209910>
---
 .../distsql/ral/impl/ShowScalingJobListBackendHandler.java  |  4 ++++
 .../org/apache/shardingsphere/scaling/core/api/JobInfo.java |  4 ++++
 .../scaling/core/api/impl/ScalingAPIImpl.java               | 13 +++++++++++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/impl/ShowScalingJobListBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/impl/ShowScalingJobListBackendHandler.java
index 5c48b65..eac9e3b 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/impl/ShowScalingJobListBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/impl/ShowScalingJobListBackendHandler.java
@@ -54,6 +54,8 @@ public final class ShowScalingJobListBackendHandler 
implements TextProtocolBacke
         result.add(new QueryHeader("", "", "tables", "", Types.CHAR, "CHAR", 
1024, 0, false, false, false, false));
         result.add(new QueryHeader("", "", "sharding_total_count", "", 
Types.SMALLINT, "SMALLINT", 255, 0, false, false, false, false));
         result.add(new QueryHeader("", "", "active", "", Types.TINYINT, 
"TINYINT", 255, 0, false, false, false, false));
+        result.add(new QueryHeader("", "", "create_time", "", Types.CHAR, 
"CHAR", 255, 0, false, false, false, false));
+        result.add(new QueryHeader("", "", "stop_time", "", Types.CHAR, 
"CHAR", 255, 0, false, false, false, false));
         return result;
     }
     
@@ -71,6 +73,8 @@ public final class ShowScalingJobListBackendHandler 
implements TextProtocolBacke
                     map.put("tables", each.getTables());
                     map.put("sharding_total_count", 
each.getShardingTotalCount());
                     map.put("active", each.isActive() ? 1 : 0);
+                    map.put("create_time", each.getCreateTime());
+                    map.put("stop_time", each.getStopTime());
                     return map;
                 })
                 .collect(Collectors.toList())
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/JobInfo.java
 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/JobInfo.java
index 00cba9b..d455951 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/JobInfo.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/JobInfo.java
@@ -36,4 +36,8 @@ public final class JobInfo {
     private String tables;
     
     private int shardingTotalCount;
+    
+    private String createTime;
+    
+    private String stopTime;
 }
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
index e387d4d..ca68fb8 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImpl.java
@@ -36,6 +36,8 @@ import 
org.apache.shardingsphere.scaling.core.job.progress.JobProgress;
 import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
 
 import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +48,8 @@ import java.util.stream.IntStream;
 @Slf4j
 public final class ScalingAPIImpl implements ScalingAPI {
     
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = 
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+    
     @Override
     public List<JobInfo> list() {
         return 
ScalingAPIFactory.getJobStatisticsAPI().getAllJobsBriefInfo().stream()
@@ -61,6 +65,8 @@ public final class ScalingAPIImpl implements ScalingAPI {
         result.setActive(!jobConfigPOJO.isDisabled());
         
result.setShardingTotalCount(jobConfig.getHandleConfig().getShardingTotalCount());
         result.setTables(jobConfig.getHandleConfig().getLogicTables());
+        
result.setCreateTime(jobConfigPOJO.getProps().getProperty("create_time"));
+        result.setStopTime(jobConfigPOJO.getProps().getProperty("stop_time"));
         return result;
     }
     
@@ -69,6 +75,7 @@ public final class ScalingAPIImpl implements ScalingAPI {
         log.info("Start scaling job {}", jobId);
         JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
         jobConfigPOJO.setDisabled(false);
+        jobConfigPOJO.getProps().remove("stop_time");
         
ScalingAPIFactory.getJobConfigurationAPI().updateJobConfiguration(jobConfigPOJO);
     }
     
@@ -81,15 +88,16 @@ public final class ScalingAPIImpl implements ScalingAPI {
         }
         log.info("Start scaling job by {}", YamlEngine.marshal(jobConfig));
         
ScalingAPIFactory.getRegistryRepositoryAPI().persist(String.format("%s/%d", 
ScalingConstant.SCALING_ROOT, jobConfig.getHandleConfig().getJobId()), 
ScalingJob.class.getCanonicalName());
-        
ScalingAPIFactory.getRegistryRepositoryAPI().persist(String.format("%s/%d/config",
 ScalingConstant.SCALING_ROOT, jobConfig.getHandleConfig().getJobId()), 
createElasticJobConfig(jobConfig));
+        
ScalingAPIFactory.getRegistryRepositoryAPI().persist(String.format("%s/%d/config",
 ScalingConstant.SCALING_ROOT, jobConfig.getHandleConfig().getJobId()), 
createJobConfig(jobConfig));
         return Optional.of(jobConfig.getHandleConfig().getJobId());
     }
     
-    private String createElasticJobConfig(final JobConfiguration jobConfig) {
+    private String createJobConfig(final JobConfiguration jobConfig) {
         JobConfigurationPOJO jobConfigPOJO = new JobConfigurationPOJO();
         
jobConfigPOJO.setJobName(String.valueOf(jobConfig.getHandleConfig().getJobId()));
         
jobConfigPOJO.setShardingTotalCount(jobConfig.getHandleConfig().getShardingTotalCount());
         jobConfigPOJO.setJobParameter(YamlEngine.marshal(jobConfig));
+        jobConfigPOJO.getProps().setProperty("create_time", 
LocalDateTime.now().format(DATE_TIME_FORMATTER));
         return YamlEngine.marshal(jobConfigPOJO);
     }
     
@@ -98,6 +106,7 @@ public final class ScalingAPIImpl implements ScalingAPI {
         log.info("Stop scaling job {}", jobId);
         JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
         jobConfigPOJO.setDisabled(true);
+        jobConfigPOJO.getProps().setProperty("stop_time", 
LocalDateTime.now().format(DATE_TIME_FORMATTER));
         
ScalingAPIFactory.getJobConfigurationAPI().updateJobConfiguration(jobConfigPOJO);
     }
     

Reply via email to