Ver código fonte

放开组和调度的方法

zhangqiankun 3 anos atrás
pai
commit
aabb54224e

+ 185 - 0
job-admin/src/main/java/com/xxl/job/admin/controller/custom/CustomGroupController.java

@@ -0,0 +1,185 @@
+package com.xxl.job.admin.controller.custom;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.xxl.job.admin.core.model.XxlJobGroup;
+import com.xxl.job.admin.core.model.XxlJobRegistry;
+import com.xxl.job.admin.core.util.I18nUtil;
+import com.xxl.job.admin.dao.XxlJobGroupDao;
+import com.xxl.job.admin.dao.XxlJobInfoDao;
+import com.xxl.job.admin.dao.XxlJobRegistryDao;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.enums.RegistryConfig;
+
+/**
+ * job group controller
+ * @author xuxueli 2016-10-02 20:52:56
+ */
+@Controller
+@RequestMapping("/customGroup")
+public class CustomGroupController {
+
+	@Resource
+	public XxlJobInfoDao xxlJobInfoDao;
+	
+	@Resource
+	public XxlJobGroupDao xxlJobGroupDao;
+	
+	@Resource
+	private XxlJobRegistryDao xxlJobRegistryDao;
+
+	@RequestMapping
+	public String index(Model model) {
+		return "jobgroup/jobgroup.index";
+	}
+
+	@RequestMapping("/query")
+	@ResponseBody
+	public ReturnT<XxlJobGroup> loadById(@RequestBody XxlJobGroup xxlJobGroup){
+		XxlJobGroup jobGroup = xxlJobGroupDao.load(xxlJobGroup.getId());
+		return jobGroup!=null?new ReturnT<XxlJobGroup>(jobGroup):new ReturnT<XxlJobGroup>(ReturnT.FAIL_CODE, null);
+	}
+	
+	@RequestMapping("/save")
+	@ResponseBody
+	public ReturnT<String> save(@RequestBody XxlJobGroup xxlJobGroup){
+
+		// valid
+		if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
+			return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
+		}
+		if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
+			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") );
+		}
+		if (xxlJobGroup.getAppname().contains(">") || xxlJobGroup.getAppname().contains("<")) {
+			return new ReturnT<String>(500, "AppName"+I18nUtil.getString("system_unvalid") );
+		}
+		if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
+			return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
+		}
+		if (xxlJobGroup.getTitle().contains(">") || xxlJobGroup.getTitle().contains("<")) {
+			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_title")+I18nUtil.getString("system_unvalid") );
+		}
+		if (xxlJobGroup.getAddressType()!=0) {
+			if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
+				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
+			}
+			if (xxlJobGroup.getAddressList().contains(">") || xxlJobGroup.getAddressList().contains("<")) {
+				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList")+I18nUtil.getString("system_unvalid") );
+			}
+
+			String[] addresss = xxlJobGroup.getAddressList().split(",");
+			for (String item: addresss) {
+				if (item==null || item.trim().length()==0) {
+					return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
+				}
+			}
+		}
+
+		// process
+		xxlJobGroup.setUpdateTime(new Date());
+
+		int ret = xxlJobGroupDao.save(xxlJobGroup);
+		return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
+	}
+
+	@RequestMapping("/update")
+	@ResponseBody
+	public ReturnT<String> update(@RequestBody XxlJobGroup xxlJobGroup){
+		// valid
+		if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
+			return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
+		}
+		if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
+			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") );
+		}
+		if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
+			return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
+		}
+		if (xxlJobGroup.getAddressType() == 0) {
+			// 0=自动注册
+			List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppname());
+			String addressListStr = null;
+			if (registryList!=null && !registryList.isEmpty()) {
+				Collections.sort(registryList);
+				addressListStr = "";
+				for (String item:registryList) {
+					addressListStr += item + ",";
+				}
+				addressListStr = addressListStr.substring(0, addressListStr.length()-1);
+			}
+			xxlJobGroup.setAddressList(addressListStr);
+		} else {
+			// 1=手动录入
+			if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
+				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
+			}
+			String[] addresss = xxlJobGroup.getAddressList().split(",");
+			for (String item: addresss) {
+				if (item==null || item.trim().length()==0) {
+					return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
+				}
+			}
+		}
+
+		// process
+		xxlJobGroup.setUpdateTime(new Date());
+
+		int ret = xxlJobGroupDao.update(xxlJobGroup);
+		return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
+	}
+
+	private List<String> findRegistryByAppName(String appnameParam){
+		HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
+		List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
+		if (list != null) {
+			for (XxlJobRegistry item: list) {
+				if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
+					String appname = item.getRegistryKey();
+					List<String> registryList = appAddressMap.get(appname);
+					if (registryList == null) {
+						registryList = new ArrayList<String>();
+					}
+
+					if (!registryList.contains(item.getRegistryValue())) {
+						registryList.add(item.getRegistryValue());
+					}
+					appAddressMap.put(appname, registryList);
+				}
+			}
+		}
+		return appAddressMap.get(appnameParam);
+	}
+
+	@RequestMapping("/remove")
+	@ResponseBody
+	public ReturnT<String> remove(@RequestBody XxlJobGroup xxlJobGroup){
+
+		// valid
+		int count = xxlJobInfoDao.pageListCount(0, 10, xxlJobGroup.getId(), -1,  null, null, null);
+		if (count > 0) {
+			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") );
+		}
+
+		List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
+		if (allList.size() == 1) {
+			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") );
+		}
+
+		int ret = xxlJobGroupDao.remove(xxlJobGroup.getId());
+		return (ret > 0)?ReturnT.SUCCESS:ReturnT.FAIL;
+	}
+
+}

+ 41 - 2
job-admin/src/main/java/com/xxl/job/admin/controller/custom/CustomInfoController.java

@@ -3,19 +3,28 @@ package com.xxl.job.admin.controller.custom;
 import javax.annotation.Resource;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.persagy.common.constant.CommonConstant;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.persagy.common.utils.StringUtil;
+import com.xxl.job.admin.core.model.DictQuery;
 import com.xxl.job.admin.core.model.XxlJobInfo;
+import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
+import com.xxl.job.admin.core.scheduler.MisfireStrategyEnum;
+import com.xxl.job.admin.core.scheduler.ScheduleTypeEnum;
 import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
 import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
 import com.xxl.job.admin.service.XxlJobService;
 import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.constant.CommonConstant;
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
 
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.parameters.RequestBody;
 
 /**
@@ -81,11 +90,41 @@ public class CustomInfoController {
 	public ReturnT<String> triggerJob(@RequestBody XxlJobInfo jobInfo) {
 		String executorParam = jobInfo.getExecutorParam();
 		if (StringUtil.isBlank(executorParam)) {
-			executorParam = CommonConstant.EMPTY;
+			executorParam = StringUtil.EMPTY;
 		}
 
 		JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.MANUAL, -1, null, executorParam, jobInfo.getAddressList());
 		return ReturnT.SUCCESS;
 	}
 	
+	
+	/************************************************ 字典值查询  *********************************************/
+	
+	@RequestMapping("/dictQuery")
+	@ApiOperation(value = "字典值查询")
+	public String remove(@RequestBody @Validated DictQuery query) {
+		JSONObject content = new JSONObject();
+		if (CommonConstant.EXECUTOR_ROUTE_STRATEGY.equals(query.getQueryType())) {
+			for (ExecutorRouteStrategyEnum item : ExecutorRouteStrategyEnum.values()) {
+				content.put(item.name(), item.getTitle());
+	        }
+		} else if (CommonConstant.EXECUTOR_BLOCK_STRATEGY.equals(query.getQueryType())) {
+			for (ExecutorBlockStrategyEnum item : ExecutorBlockStrategyEnum.values()) {
+				content.put(item.name(), item.getTitle());
+            }
+		} else if (CommonConstant.MISFIRE_STRATEGY.equals(query.getQueryType())) {
+			for (MisfireStrategyEnum item : MisfireStrategyEnum.values()) {
+				content.put(item.name(), item.getTitle());
+            }
+		} else if (CommonConstant.SCHEDULE_TYPE.equals(query.getQueryType())) {
+			for (ScheduleTypeEnum item : ScheduleTypeEnum.values()) {
+				content.put(item.name(), item.getTitle());
+            }
+		} else {
+			content = null;
+		}
+		ReturnT<JSONObject> returnT = new ReturnT<JSONObject>(content);
+		return JSON.toJSONString(returnT);
+	}
+	
 }

+ 2 - 0
job-admin/src/main/java/com/xxl/job/admin/controller/custom/CustomInfoHandler.java

@@ -53,6 +53,8 @@ public class CustomInfoHandler {
 			ReturnT<String> returnT = xxlJobService.add(this.transferDataInfo(oldXxlJobInfo));
 			if (ReturnT.SUCCESS_CODE == returnT.getCode()) {
 				xxlJobService.start(Integer.valueOf(returnT.getContent()));
+			} else {
+				return ReturnT.FAIL;
 			}
 		}
 		

+ 1 - 0
job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/WebMvcConfig.java

@@ -28,6 +28,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
     
     static {
     	excludePaths.add("/customInfo/**");
+    	excludePaths.add("/customGroup/**");
     	excludePaths.add("/v2/api-docs");
     	excludePaths.add("/swagger/**");
     	excludePaths.add("/swagger-resources/**");

+ 28 - 0
job-admin/src/main/java/com/xxl/job/admin/core/model/DictQuery.java

@@ -0,0 +1,28 @@
+package com.xxl.job.admin.core.model;
+
+import javax.validation.constraints.NotBlank;
+
+import groovy.transform.ToString;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @version 
+ * @description 
+ * @company persagy
+ * @author zhangqiankun
+ * @since 2020年12月3日:	下午6:50:46
+ */
+@Getter
+@Setter
+@ToString
+@ApiModel(description = "字典查询请求类")
+public class DictQuery {
+	
+	@NotBlank(message = "查询类型不可为空")
+	@ApiModelProperty(value = "查询类型", example = "", required = true)
+	private String queryType;
+	
+}

+ 4 - 0
job-core/src/main/java/com/xxl/job/core/constant/CommonConstant.java

@@ -21,4 +21,8 @@ public interface CommonConstant {
 	
 	String EXECUTOR_BLOCK_STRATEGY = "executorBlockStrategy";
 	
+	String MISFIRE_STRATEGY = "misfireStrategy";
+	
+	String SCHEDULE_TYPE = "scheduleType";
+	
 }