Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.alibaba.dts.sdk.DtsCommonSDKManager Maven / Gradle / Ivy
package com.alibaba.dts.sdk;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.dts.common.constants.Constants;
import com.alibaba.dts.common.domain.ProgressDetail;
import com.alibaba.dts.common.domain.result.Result;
import com.alibaba.dts.common.domain.result.ResultCode;
import com.alibaba.dts.common.domain.store.Cluster;
import com.alibaba.dts.common.domain.store.Job;
import com.alibaba.dts.common.domain.store.WarningSetup;
import com.alibaba.dts.common.domain.store.assemble.AssembledMonitor;
import com.alibaba.dts.common.domain.store.assemble.AssembledUserGroup;
import com.alibaba.dts.common.domain.store.assemble.JobExecuteHistory;
import com.alibaba.dts.common.domain.store.assemble.JobInstanceDetailStatus;
import com.alibaba.dts.common.domain.store.assemble.JobStatus;
import com.alibaba.dts.common.domain.store.assemble.WarningNotifier;
import com.alibaba.dts.common.logger.SchedulerXLoggerFactory;
import com.alibaba.dts.common.logger.innerlog.Logger;
import com.alibaba.dts.common.remoting.protocol.RemotingSerializable;
import com.alibaba.dts.common.service.HttpService;
import com.alibaba.dts.common.util.CheckUtil;
import com.alibaba.dts.common.util.DiamondHelper;
import com.alibaba.dts.common.util.GroupIdUtil;
import com.alibaba.dts.common.util.StringUtil;
import com.alibaba.dts.sdk.client.DtsHttpClient;
import com.alibaba.dts.sdk.context.SDKContext;
import com.alibaba.dts.sdk.util.exception.SDKModeUnsupportException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* Created by luliang on 14/12/24.
*/
public class DtsCommonSDKManager implements DtsSDKManager {
private static final Logger logger = SchedulerXLoggerFactory.getLogger(DtsCommonSDKManager.class);
private SDKMode mode = SDKMode.ALIYUN_MODE;
public long clusterId;
private DtsHttpClient client = new DtsHttpClient();
public DtsCommonSDKManager(SDKMode mode) {
this.mode = mode;
if (mode == SDKMode.DAILY_MODE) {
client.setDomainUrl(SDKContext.DTS_DOMAIN_DAILY_URL);
// client.setDomainUrl("http://localhost/dts-console");
} else if (mode == SDKMode.ONLINE_MODE) {
client.setDomainUrl(SDKContext.DTS_DOMAIN_ONLINE_URL);
} else if (mode == SDKMode.ALIYUN_MODE) {
client.setDomainUrl(SDKContext.DTS_DOMAIN_ALIYUN_URL);
} else if (mode == SDKMode.USA_MODE) {
client.setDomainUrl(SDKContext.DTS_DOMAIN_USA_URL);
} else {
throw new SDKModeUnsupportException("sdk mode not support!");
}
}
public DtsCommonSDKManager(String url) {
if (StringUtil.isBlank(url)) {
throw new RuntimeException("url不能为空!");
}
client.setDomainUrl(url);
}
public DtsCommonSDKManager() {
String domainName = null;
try {
domainName = DiamondHelper.getData(HttpService.DOMAIN_NAME_DATA_ID, 10 * 1000L);
client.setDomainUrl("http://" + domainName + "/dts-console");
DiamondHelper.addListener(HttpService.DOMAIN_NAME_DATA_ID, new DiamondHelper.DataListener() {
@Override
public void receiveConfigInfo(String dataId, String configInfo) {
client.setDomainUrl("http://" + configInfo + "/dts-console");
}
});
} catch (Throwable e) {
throw new RuntimeException("[DtsCommonSDKManager]: get domainName from diamond error", e);
}
if (StringUtil.isBlank(domainName)) {
throw new RuntimeException("[DtsCommonSDKManager]: domainName is blank error");
}
}
@Override
public Result> getDtsClustersInfo() {
Result> result = new Result>();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_clusters");
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getDtsClustersInfo json isBlank, postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
List dtsClusters = null;
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
JSONArray clusterArray = jsonResult.getJSONArray("clusters");
dtsClusters = new ArrayList(clusterArray.size());
for (int i = 0; i < clusterArray.size(); i++) {
JSONObject json = (JSONObject) clusterArray.get(i);
Cluster cluster = RemotingSerializable.fromJson(json.toJSONString(), Cluster.class);
dtsClusters.add(cluster);
}
result.setResultCode(ResultCode.SUCCESS);
result.setData(dtsClusters);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getDtsClustersInfo error, postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result createGroup(long clusterId, String groupDescription) {
Result result = new Result();
if (StringUtil.isBlank(groupDescription)) {
result.setResultCode(ResultCode.USER_PARAMETER_ERROR);
result.setData("组描述不能为空!");
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_create_group");
client.addParameter("clusterId", String.valueOf(clusterId))
.addParameter("groupDesc", groupDescription);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: createGroup json isBlank"
+ ", clusterId:" + clusterId
+ ", groupDescription:" + groupDescription
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData((String) jsonResult.get("userGroupId"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: createGroup error"
+ ", clusterId:" + clusterId
+ ", groupDescription:" + groupDescription
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result deleteGroup(String userGroupId) {
Result result = new Result();
if (StringUtil.isBlank(userGroupId) || !GroupIdUtil.checkClientGroupId(userGroupId)) {
result.setResultCode(ResultCode.USER_PARAMETER_ERROR);
result.setData(false);
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_delete_group");
client.addParameter("userGroupId", userGroupId);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: deleteGroup json isBlank"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: deleteGroup error"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result> getUserGroups(long clusterId) {
Result> result = new Result>();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_user_groups");
client.addParameter("clusterId", String.valueOf(clusterId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getUserGroups json isBlank"
+ ", clusterId:" + clusterId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JSONArray jsonArray = jsonResult.getJSONArray("groups");
List userGroups = new ArrayList(jsonArray.size());
for (int i = 0; i < jsonArray.size(); i++) {
AssembledUserGroup userGroup =RemotingSerializable.fromJson(jsonArray.get(i).toString(), AssembledUserGroup.class);
userGroups.add(userGroup);
}
result.setData(userGroups);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getUserGroups error"
+ ", clusterId:" + clusterId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result createJob(String userGroupId, Job job) {
Result result = new Result();
// 检查userGroupId
if (StringUtil.isBlank(userGroupId) || !GroupIdUtil.checkClientGroupId(userGroupId)) {
result.setResultCode(ResultCode.USER_PARAMETER_ERROR);
result.getResultCode().setInformation("组名不正确!");
return result;
}
Result checkResult = CheckUtil.checkUserConfigJob(job);
if (!checkResult.getData()) {
result.setResultCode(checkResult.getResultCode());
result.getResultCode().setInformation(checkResult.getResultCode().getInformation());
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_create_job");
client.addParameter("userGroupId", userGroupId);
try {
client.addParameter("jobProcessor", job.getJobProcessor())
.addParameter("jobType", String.valueOf(job.getType()))
.addParameter("cronExpression", StringUtil.isEmpty(job.getCronExpression()) ? StringUtil.EMPTY_STRING : job.getCronExpression())
.addParameter("jobDesc", StringUtil.isEmpty(job.getDescription()) ? StringUtil.EMPTY_STRING : URLEncoder.encode(job.getDescription(),"UTF-8"))
.addParameter("firePolicy", String.valueOf(job.getMaxInstanceAmount()))
.addParameter("jobArguments", StringUtil.isEmpty(job.getJobArguments()) ? StringUtil.EMPTY_STRING : URLEncoder.encode(job.getJobArguments(),"UTF-8"))
.addParameter("extAttribute", StringUtil.isEmpty(job.getExtAttribute()) ? StringUtil.EMPTY_STRING : job.getExtAttribute())
.addParameter("jobStatus", String.valueOf(job.getStatus()));
} catch (UnsupportedEncodingException e) {
result.setResultCode(ResultCode.ENCODE_ERROR);
return result;
}
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: createJob json isBlank"
+ ", userGroupId:" + userGroupId
+ ", job:" + job
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(jsonResult.getLong("jobId"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: createJob"
+ ", userGroupId:" + userGroupId
+ ", job:" + job
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result deleteJob(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_delete_job");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: deleteJob json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(jsonResult.getInteger("deleteCount"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: deleteJob error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result updateJob(String groupId, Job job) {
Result result = new Result();
Result checkResult = CheckUtil.checkUserConfigJob(job);
if (!checkResult.getData()) {
result.setResultCode(checkResult.getResultCode());
result.getResultCode().setInformation(checkResult.getResultCode().getInformation());
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_update_job");
try {
client.addParameter("jobId", String.valueOf(job.getId()))
.addParameter("jobProcessor", job.getJobProcessor())
.addParameter("jobType", String.valueOf(job.getType()))
.addParameter("cronExpression", StringUtil.isEmpty(job.getCronExpression()) ? StringUtil.EMPTY_STRING : job.getCronExpression())
.addParameter("jobDesc", StringUtil.isEmpty(job.getDescription()) ? StringUtil.EMPTY_STRING : URLEncoder.encode(job.getDescription(),"UTF-8"))
.addParameter("firePolicy", String.valueOf(job.getMaxInstanceAmount()))
.addParameter("jobArguments", StringUtil.isEmpty(job.getJobArguments()) ? StringUtil.EMPTY_STRING : URLEncoder.encode(job.getJobArguments(),"UTF-8"))
.addParameter("extAttribute", StringUtil.isEmpty(job.getExtAttribute()) ? StringUtil.EMPTY_STRING : job.getExtAttribute())
.addParameter("groupId", groupId);
} catch (Exception e) {
result.setResultCode(ResultCode.ENCODE_ERROR);
return result;
}
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: updateJob json isBlank"
+ ", groupId:" + groupId
+ ", job:" + job
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(jsonResult.getInteger("updateCount"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: updateJob error"
+ ", groupId:" + groupId
+ ", job:" + job
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result updateJobWithArguments(String groupId, Job job) {
Result result = new Result();
Result checkResult = CheckUtil.checkUserConfigJob(job);
if (!checkResult.getData()) {
result.setResultCode(checkResult.getResultCode());
result.getResultCode().setInformation(checkResult.getResultCode().getInformation());
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_update_job");
client.addParameter("jobId", String.valueOf(job.getId()))
.addParameter("jobProcessor", job.getJobProcessor())
.addParameter("jobType", String.valueOf(job.getType()))
.addParameter("cronExpression", job.getCronExpression())
.addParameter("jobDesc", job.getDescription())
.addParameter("firePolicy", String.valueOf(job.getMaxInstanceAmount()))
.addParameter("jobArguments", job.getJobArguments())
.addParameter("groupId", groupId);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: updateJobWithArguments json isBlank"
+ ", groupId:" + groupId
+ ", job:" + job
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(jsonResult.getInteger("updateCount"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: updateJobWithArguments error"
+ ", groupId:" + groupId
+ ", job:" + job
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result updateJobArguments(long jobId, String jobArguments) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_update_job_arguments");
try {
client.addParameter("jobId", String.valueOf(jobId))
.addParameter("jobArguments", URLEncoder.encode(jobArguments,"UTF-8"));
} catch (UnsupportedEncodingException e) {
result.setResultCode(ResultCode.ENCODE_ERROR);
return result;
}
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: updateJobArguments json isBlank"
+ ", jobId:" + jobId
+ ", jobArguments:" + jobArguments
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(jsonResult.getInteger("updateCount"));
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: updateJobArguments error"
+ ", jobId:" + jobId
+ ", jobArguments:" + jobArguments
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result> getJobsForGroup(String userGroupId) {
Result> result = new Result>();
// 检查userGroupId
if (StringUtil.isBlank(userGroupId) || !GroupIdUtil.checkClientGroupId(userGroupId)) {
result.setResultCode(ResultCode.USER_PARAMETER_ERROR);
result.getResultCode().setInformation("组名不正确!");
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_group_jobs");
client.addParameter("groupId", userGroupId);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobsForGroup json isBlank"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JSONArray jsonArray = jsonResult.getJSONArray("jobs");
List groupJobs = new ArrayList(jsonArray.size());
for (int i = 0; i < jsonArray.size(); i++) {
Job job = RemotingSerializable.fromJson(jsonArray.get(i).toString(), Job.class);
groupJobs.add(job);
}
result.setData(groupJobs);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobsForGroup error"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result> getJobsForGroupByPage(String userGroupId, int pageSize, int pageNumber) {
Result> result = new Result>();
// 检查userGroupId
if (StringUtil.isBlank(userGroupId) || !GroupIdUtil.checkClientGroupId(userGroupId)) {
result.setResultCode(ResultCode.USER_PARAMETER_ERROR);
result.getResultCode().setInformation("组名不正确!");
return result;
}
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_group_jobs_by_page");
client.addParameter("groupId", userGroupId);
client.addParameter("pageSize", String.valueOf(pageSize));
client.addParameter("pageNumber", String.valueOf(pageNumber));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobsForGroupByPage json isBlank"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson
+ ", pageSize:" + pageSize
+ ", pageNumber:" + pageNumber);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JSONArray jsonArray = jsonResult.getJSONArray("jobs");
List groupJobs = new ArrayList(jsonArray.size());
for (int i = 0; i < jsonArray.size(); i++) {
Job job = RemotingSerializable.fromJson(jsonArray.get(i).toString(), Job.class);
groupJobs.add(job);
}
result.setData(groupJobs);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobsForGroupByPage error"
+ ", userGroupId:" + userGroupId
+ ", postJson:" + postJson
+ ", pageSize:" + pageSize
+ ", pageNumber:" + pageNumber, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result enableJob(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_enable_job");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: enableJob json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: enableJob error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result disableJob(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_disable_job");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: disableJob json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: disableJob error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result instanceRunJob(String userGroupId, long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_instance_start_job");
client.addParameter("jobId", String.valueOf(jobId)).addParameter("groupId", userGroupId);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: instanceRunJob json isBlank"
+ ", userGroupId:" + userGroupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation(postJson);
} else {
result.setResultCode(ResultCode.SUCCESS);
result.getResultCode().setInformation(postJson);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: instanceRunJob error"
+ ", userGroupId:" + userGroupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result instanceRunJob(String userGroupId, long jobId, String instanceGlobal) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_instance_start_job");
client.addParameter("jobId", String.valueOf(jobId)).addParameter("groupId", userGroupId);
client.addParameter("instanceGlobal", instanceGlobal);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: instanceRunJob json isBlank"
+ ", userGroupId:" + userGroupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation(postJson);
} else {
result.setResultCode(ResultCode.SUCCESS);
result.getResultCode().setInformation(postJson);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: instanceRunJob error"
+ ", userGroupId:" + userGroupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result instanceStopJob(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_instance_stop_job");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: instanceStopJob json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: instanceStopJob error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public String parseWarningSetup(AssembledMonitor assembledMonitor) {
JSONObject jsonObject = new JSONObject();
if(assembledMonitor.getTimeoutLimit() != 0) {
jsonObject.put(assembledMonitor.TIMEOUT_LIMIT, assembledMonitor.getTimeoutLimit());
}
if(assembledMonitor.getErrorRate() != 0.0) {
jsonObject.put(assembledMonitor.ERROR_RATE, assembledMonitor.getErrorRate());
}
if (assembledMonitor.getNotFireTimes() > 0) {
// 界面上默认不能超过10
if (assembledMonitor.getNotFireTimes() > 10) {
jsonObject.put(assembledMonitor.NOT_FIRE_TIME, 10);
} else {
jsonObject.put(assembledMonitor.NOT_FIRE_TIME, assembledMonitor.getNotFireTimes());
}
} else {
jsonObject.put(assembledMonitor.NOT_FIRE_TIME, assembledMonitor.NOT_FIRE_TIMES_LIMIT);
}
jsonObject.put(WarningSetup.FORCED_TERMINATION, assembledMonitor.isForcedTermination());
// 设置报警方式
jsonObject.put(assembledMonitor.SMS_WARING,assembledMonitor.isSmsWaring());
jsonObject.put(assembledMonitor.DING_WARING,assembledMonitor.isDingWaring());
jsonObject.put(assembledMonitor.EMAIL_WARING,assembledMonitor.isEmailWaring());
jsonObject.put(assembledMonitor.WW_WARING,assembledMonitor.isWwWaring());
jsonObject.put(assembledMonitor.PHONE_WARNING,assembledMonitor.isPhoneWarning());
// 没有设置报警方式默认钉钉
if (!(assembledMonitor.isDingWaring() || assembledMonitor.isSmsWaring() || assembledMonitor.isEmailWaring() ||
assembledMonitor.isWwWaring() || assembledMonitor.isPhoneWarning())) {
jsonObject.put(assembledMonitor.DING_WARING,true);
}
// 设置报警开关
jsonObject.put(assembledMonitor.DISABLE_WARING,assembledMonitor.isDisableWaring());
return jsonObject.toJSONString();
}
public String parseContact(AssembledMonitor assembledMonitor) {
JSONArray jsonArray = new JSONArray();
if (assembledMonitor.getNotifiers() == null || assembledMonitor.getNotifiers().isEmpty()) {
throw new RuntimeException("没有配置报警通知人员");
}
for(WarningNotifier warningNotifier:assembledMonitor.getNotifiers()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(assembledMonitor.MOBILEID, warningNotifier.getMobileId());
jsonObject.put(assembledMonitor.WWID, warningNotifier.getWwId());
jsonArray.add(jsonObject);
}
return jsonArray.toJSONString();
}
@Override
public Result setJobMonitorConfig(AssembledMonitor monitorSeting) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_set_monitor");
client.addParameter("jobId", String.valueOf(monitorSeting.getJobId()))
.addParameter("warningSetup", parseWarningSetup(monitorSeting))
.addParameter("contact", parseContact(monitorSeting));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: setJobMonitorConfig json isBlank"
+ ", monitorSeting:" + monitorSeting
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: setJobMonitorConfig error"
+ ", monitorSeting:" + monitorSeting
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result updateJobMonitor(AssembledMonitor monitorSeting) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_set_monitor");
client.addParameter("jobId", String.valueOf(monitorSeting.getJobId()))
.addParameter("warningSetup", parseWarningSetup(monitorSeting))
.addParameter("contact", parseContact(monitorSeting));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: updateJobMonitor json isBlank"
+ ", monitorSeting:" + monitorSeting
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: updateJobMonitor error"
+ ", monitorSeting:" + monitorSeting
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getMonitorSetings(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_monitor");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getMonitorSetings json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
AssembledMonitor monitorSetings
= RemotingSerializable.fromJson((String) jsonResult.get("monitor"), AssembledMonitor.class);
result.setData(monitorSetings);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getMonitorSetings error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getJobRunningStatus(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_status");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobRunningStatus json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JobStatus jobStatus = RemotingSerializable.fromJson(jsonResult.get("status").toString(), JobStatus.class);
result.setData(jobStatus);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobRunningStatus error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getJobRunningInformations(long jobInstanceId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_running_information");
client.addParameter("jobInstanceId", String.valueOf(jobInstanceId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobRunningInformations json isBlank"
+ ", jobInstanceId:" + jobInstanceId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
String runInformation = jsonResult.get("information").toString();
result.setData(runInformation);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobRunningInformations error"
+ ", jobInstanceId:" + jobInstanceId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getJobLastInstanceId(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_last_instance_id");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobLastInstanceId json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
long lastInstanceId = Long.valueOf(jsonResult.get("lastInstanceId").toString());
result.setData(lastInstanceId);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobLastInstanceId error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getJobDetailRunningStatus(long jobId, long instanceId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_detail_statistics");
client.addParameter("jobId", String.valueOf(jobId))
.addParameter("instanceId", String.valueOf(instanceId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobDetailRunningStatus json isBlank"
+ ", jobId:" + jobId
+ ", instanceId:" + instanceId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JobInstanceDetailStatus jobStatus = RemotingSerializable.fromJson(jsonResult.get("statistics").toString(), JobInstanceDetailStatus.class);
result.setData(jobStatus);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobDetailRunningStatus error"
+ ", jobId:" + jobId
+ ", instanceId:" + instanceId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result getJobRunningHistoryStatusById(long jobId, long instanceId) {
Result result = new Result();
JobInstanceDetailStatus jobStatus = new JobInstanceDetailStatus();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_history_by_instanceid");
client.addParameter("jobId", String.valueOf(jobId))
.addParameter("instanceId", String.valueOf(instanceId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobDetailRunningStatus json isBlank"
+ ", jobId:" + jobId
+ ", instanceId:" + instanceId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
jobStatus.setJobId(jobId);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
ProgressDetail progressDetail = RemotingSerializable.fromJson(jsonResult.get("statistics").toString(), ProgressDetail.class);
jobStatus.setProgressDetail(progressDetail);
result.setData(jobStatus);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobDetailRunningStatus error"
+ ", jobId:" + jobId
+ ", instanceId:" + instanceId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result grantGroupAuth(String userGroupId, String ownerUserId, String grantUserId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_grant_auth");
client.addParameter("userGroupId", userGroupId)
.addParameter("ownerUserId", ownerUserId)
.addParameter("grantUserId", grantUserId);
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: grantGroupAuth json isBlank"
+ ", userGroupId:" + userGroupId
+ ", ownerUserId:" + ownerUserId
+ ", grantUserId:" + grantUserId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: grantGroupAuth error"
+ ", userGroupId:" + userGroupId
+ ", ownerUserId:" + ownerUserId
+ ", grantUserId:" + grantUserId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@Override
public Result getJobRunningHistoryStatus(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_history");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobRunningHistoryStatus json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
JobExecuteHistory jobExecuteHistory
= RemotingSerializable.fromJson(jsonResult.get("history").toString(), JobExecuteHistory.class);
result.setData(jobExecuteHistory);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobRunningHistoryStatus error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result resetJobRelation(List startJobIdList) {
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_reset_job_relation");
String jobIds = "";
for (Long jobId : startJobIdList) {
jobIds += jobId.longValue() + Constants.COLON;
}
jobIds = jobIds.substring(0, jobIds.length() - 1);
client.addParameter("jobIds", jobIds);
Result result = new Result();
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: resetJobRelation json isBlank"
+ ", startJobIdList:" + startJobIdList
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: resetJobRelation error"
+ ", startJobIdList:" + startJobIdList
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result createRelation(long afterJobId, long beforeJobId) {
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_create_relation");
client.addParameter("afterJobId", String.valueOf(afterJobId));
client.addParameter("beforeJobId", String.valueOf(beforeJobId));
Result result = new Result();
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: createRelation json isBlank"
+ ", afterJobId:" + afterJobId
+ ", beforeJobId:" + beforeJobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: createRelation error"
+ ", afterJobId:" + afterJobId
+ ", beforeJobId:" + beforeJobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public Result deleteRelation(long afterJobId, long beforeJobId) {
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_delete_relation");
client.addParameter("afterJobId", String.valueOf(afterJobId));
client.addParameter("beforeJobId", String.valueOf(beforeJobId));
Result result = new Result();
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: deleteRelation json isBlank"
+ ", afterJobId:" + afterJobId
+ ", beforeJobId:" + beforeJobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
result.setData(true);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: deleteRelation error"
+ ", afterJobId:" + afterJobId
+ ", beforeJobId:" + beforeJobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
@SuppressWarnings("unchecked")
public List queryClientGroupIpList(String groupId, long jobId) {
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_query_client_group_ip_list");
client.addParameter("clientGroup", groupId);
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: queryClientGroupIpList json isBlank"
+ ", groupId:" + groupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
return new ArrayList();
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
String json = jsonResult.getString("ipList");
if (success.booleanValue()) {
return (List) RemotingSerializable.fromJson(json, List.class);
} else {
return new ArrayList();
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: queryClientGroupIpList json isBlank"
+ ", groupId:" + groupId
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
return new ArrayList();
}
}
@Override
public Result getJobConfig(long jobId) {
Result result = new Result();
client.setTarget("sdkManager.do").setSubmitAction("event_submit_do_get_job_config");
client.addParameter("jobId", String.valueOf(jobId));
String postJson = client.doPost();
if (StringUtil.isBlank(postJson)) {
logger.error("[DtsCommonSDKManager]: getJobConfig json isBlank"
+ ", jobId:" + jobId
+ ", postJson:" + postJson);
result.setResultCode(ResultCode.FAILURE);
return result;
}
try {
JSONObject jsonResult = JSON.parseObject(postJson);
Boolean success = (Boolean) jsonResult.get(Constants.SUCCESS);
if (success == false) {
result.setResultCode(ResultCode.FAILURE);
result.getResultCode().setInformation((String) jsonResult.get(Constants.ERROR_MSG));
} else {
result.setResultCode(ResultCode.SUCCESS);
Job job = RemotingSerializable.fromJson(jsonResult.get("jobConfig").toString(), Job.class);
result.setData(job);
}
} catch (Throwable e) {
logger.error("[DtsCommonSDKManager]: getJobConfig error"
+ ", jobId:" + jobId
+ ", postJson:" + postJson, e);
result.setResultCode(ResultCode.SDK_IO_ERROR);
}
return result;
}
public long getClusterId() {
return clusterId;
}
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public SDKMode getMode() {
return mode;
}
public void setMode(SDKMode mode) {
this.mode = mode;
}
}