Browse Source
* refactor process export * comment & null check for export process * add License * add javadoc * add DataSourceParamTest and DependentParamTest * refactor process export & add exportProcessMetaDataStr UTpull/2/head
Yelli
5 years ago
committed by
qiaozhanwei
11 changed files with 709 additions and 99 deletions
@ -0,0 +1,247 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.dto; |
||||||
|
|
||||||
|
/** |
||||||
|
* ProcessMeta |
||||||
|
*/ |
||||||
|
public class ProcessMeta { |
||||||
|
|
||||||
|
/** |
||||||
|
* project name |
||||||
|
*/ |
||||||
|
private String projectName; |
||||||
|
|
||||||
|
/** |
||||||
|
* process definition name |
||||||
|
*/ |
||||||
|
private String processDefinitionName; |
||||||
|
|
||||||
|
/** |
||||||
|
* processs definition json |
||||||
|
*/ |
||||||
|
private String processDefinitionJson; |
||||||
|
|
||||||
|
/** |
||||||
|
* process definition desc |
||||||
|
*/ |
||||||
|
private String processDefinitionDescription; |
||||||
|
|
||||||
|
/** |
||||||
|
* process definition locations |
||||||
|
*/ |
||||||
|
private String processDefinitionLocations; |
||||||
|
|
||||||
|
/** |
||||||
|
* process definition connects |
||||||
|
*/ |
||||||
|
private String processDefinitionConnects; |
||||||
|
|
||||||
|
/** |
||||||
|
* warning type |
||||||
|
*/ |
||||||
|
private String scheduleWarningType; |
||||||
|
|
||||||
|
/** |
||||||
|
* warning group id |
||||||
|
*/ |
||||||
|
private int scheduleWarningGroupId; |
||||||
|
|
||||||
|
/** |
||||||
|
* warning group name |
||||||
|
*/ |
||||||
|
private String scheduleWarningGroupName; |
||||||
|
|
||||||
|
/** |
||||||
|
* start time |
||||||
|
*/ |
||||||
|
private String scheduleStartTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* end time |
||||||
|
*/ |
||||||
|
private String scheduleEndTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* crontab |
||||||
|
*/ |
||||||
|
private String scheduleCrontab; |
||||||
|
|
||||||
|
/** |
||||||
|
* failure strategy |
||||||
|
*/ |
||||||
|
private String scheduleFailureStrategy; |
||||||
|
|
||||||
|
/** |
||||||
|
* release state |
||||||
|
*/ |
||||||
|
private String scheduleReleaseState; |
||||||
|
|
||||||
|
/** |
||||||
|
* process instance priority |
||||||
|
*/ |
||||||
|
private String scheduleProcessInstancePriority; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group id |
||||||
|
*/ |
||||||
|
private int scheduleWorkerGroupId; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group name |
||||||
|
*/ |
||||||
|
private String scheduleWorkerGroupName; |
||||||
|
|
||||||
|
public ProcessMeta() { |
||||||
|
} |
||||||
|
|
||||||
|
public String getProjectName() { |
||||||
|
return projectName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProjectName(String projectName) { |
||||||
|
this.projectName = projectName; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProcessDefinitionName() { |
||||||
|
return processDefinitionName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionName(String processDefinitionName) { |
||||||
|
this.processDefinitionName = processDefinitionName; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProcessDefinitionJson() { |
||||||
|
return processDefinitionJson; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionJson(String processDefinitionJson) { |
||||||
|
this.processDefinitionJson = processDefinitionJson; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProcessDefinitionDescription() { |
||||||
|
return processDefinitionDescription; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionDescription(String processDefinitionDescription) { |
||||||
|
this.processDefinitionDescription = processDefinitionDescription; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProcessDefinitionLocations() { |
||||||
|
return processDefinitionLocations; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionLocations(String processDefinitionLocations) { |
||||||
|
this.processDefinitionLocations = processDefinitionLocations; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProcessDefinitionConnects() { |
||||||
|
return processDefinitionConnects; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionConnects(String processDefinitionConnects) { |
||||||
|
this.processDefinitionConnects = processDefinitionConnects; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleWarningType() { |
||||||
|
return scheduleWarningType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleWarningType(String scheduleWarningType) { |
||||||
|
this.scheduleWarningType = scheduleWarningType; |
||||||
|
} |
||||||
|
|
||||||
|
public int getScheduleWarningGroupId() { |
||||||
|
return scheduleWarningGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleWarningGroupId(int scheduleWarningGroupId) { |
||||||
|
this.scheduleWarningGroupId = scheduleWarningGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleWarningGroupName() { |
||||||
|
return scheduleWarningGroupName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleWarningGroupName(String scheduleWarningGroupName) { |
||||||
|
this.scheduleWarningGroupName = scheduleWarningGroupName; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleStartTime() { |
||||||
|
return scheduleStartTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleStartTime(String scheduleStartTime) { |
||||||
|
this.scheduleStartTime = scheduleStartTime; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleEndTime() { |
||||||
|
return scheduleEndTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleEndTime(String scheduleEndTime) { |
||||||
|
this.scheduleEndTime = scheduleEndTime; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleCrontab() { |
||||||
|
return scheduleCrontab; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleCrontab(String scheduleCrontab) { |
||||||
|
this.scheduleCrontab = scheduleCrontab; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleFailureStrategy() { |
||||||
|
return scheduleFailureStrategy; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleFailureStrategy(String scheduleFailureStrategy) { |
||||||
|
this.scheduleFailureStrategy = scheduleFailureStrategy; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleReleaseState() { |
||||||
|
return scheduleReleaseState; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleReleaseState(String scheduleReleaseState) { |
||||||
|
this.scheduleReleaseState = scheduleReleaseState; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleProcessInstancePriority() { |
||||||
|
return scheduleProcessInstancePriority; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleProcessInstancePriority(String scheduleProcessInstancePriority) { |
||||||
|
this.scheduleProcessInstancePriority = scheduleProcessInstancePriority; |
||||||
|
} |
||||||
|
|
||||||
|
public int getScheduleWorkerGroupId() { |
||||||
|
return scheduleWorkerGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleWorkerGroupId(int scheduleWorkerGroupId) { |
||||||
|
this.scheduleWorkerGroupId = scheduleWorkerGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public String getScheduleWorkerGroupName() { |
||||||
|
return scheduleWorkerGroupName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleWorkerGroupName(String scheduleWorkerGroupName) { |
||||||
|
this.scheduleWorkerGroupName = scheduleWorkerGroupName; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.DataSource; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; |
||||||
|
import org.springframework.beans.factory.InitializingBean; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* task node add datasource param strategy |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class DataSourceParam implements exportProcessAddTaskParam, InitializingBean { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private DataSourceMapper dataSourceMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* add datasource params |
||||||
|
* @param taskNode task node json object |
||||||
|
* @return task node json object |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public JSONObject addSpecialParam(JSONObject taskNode) { |
||||||
|
// add sqlParameters
|
||||||
|
JSONObject sqlParameters = JSONUtils.parseObject(taskNode.getString("params")); |
||||||
|
DataSource dataSource = dataSourceMapper.selectById((Integer) sqlParameters.get("datasource")); |
||||||
|
if (null != dataSource) { |
||||||
|
sqlParameters.put("datasourceName", dataSource.getName()); |
||||||
|
} |
||||||
|
taskNode.put("params", sqlParameters); |
||||||
|
|
||||||
|
return taskNode; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* put datasource strategy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void afterPropertiesSet() { |
||||||
|
TaskNodeParamFactory.register(TaskType.SQL.name(), this); |
||||||
|
TaskNodeParamFactory.register(TaskType.PROCEDURE.name(), this); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
||||||
|
import org.springframework.beans.factory.InitializingBean; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* task node add dependent param strategy |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class DependentParam implements exportProcessAddTaskParam, InitializingBean { |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
ProcessDefinitionMapper processDefineMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* add dependent param |
||||||
|
* @param taskNode task node json object |
||||||
|
* @return task node json object |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public JSONObject addSpecialParam(JSONObject taskNode) { |
||||||
|
// add dependent param
|
||||||
|
JSONObject dependentParameters = JSONUtils.parseObject(taskNode.getString("dependence")); |
||||||
|
|
||||||
|
if (null != dependentParameters) { |
||||||
|
JSONArray dependTaskList = (JSONArray) dependentParameters.get("dependTaskList"); |
||||||
|
for (int j = 0; j < dependTaskList.size(); j++) { |
||||||
|
JSONObject dependentTaskModel = dependTaskList.getJSONObject(j); |
||||||
|
JSONArray dependItemList = (JSONArray) dependentTaskModel.get("dependItemList"); |
||||||
|
for (int k = 0; k < dependItemList.size(); k++) { |
||||||
|
JSONObject dependentItem = dependItemList.getJSONObject(k); |
||||||
|
int definitionId = dependentItem.getInteger("definitionId"); |
||||||
|
ProcessDefinition definition = processDefineMapper.queryByDefineId(definitionId); |
||||||
|
if (null != definition) { |
||||||
|
dependentItem.put("projectName", definition.getProjectName()); |
||||||
|
dependentItem.put("definitionName", definition.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
taskNode.put("dependence", dependentParameters); |
||||||
|
} |
||||||
|
|
||||||
|
return taskNode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* put dependent strategy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void afterPropertiesSet() { |
||||||
|
TaskNodeParamFactory.register(TaskType.DEPENDENT.name(), this); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* task node param factory |
||||||
|
*/ |
||||||
|
public class TaskNodeParamFactory { |
||||||
|
|
||||||
|
private static Map<String, exportProcessAddTaskParam> taskServices = new ConcurrentHashMap<>(); |
||||||
|
|
||||||
|
public static exportProcessAddTaskParam getByTaskType(String taskType){ |
||||||
|
return taskServices.get(taskType); |
||||||
|
} |
||||||
|
|
||||||
|
static void register(String taskType, exportProcessAddTaskParam addSpecialTaskParam){ |
||||||
|
if (null != taskType) { |
||||||
|
taskServices.put(taskType, addSpecialTaskParam); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
|
||||||
|
/** |
||||||
|
* exportProcessAddTaskParam |
||||||
|
*/ |
||||||
|
public interface exportProcessAddTaskParam { |
||||||
|
|
||||||
|
/** |
||||||
|
* add task special param: sql task dependent task |
||||||
|
* @param taskNode task node json object |
||||||
|
* @return task node json object |
||||||
|
*/ |
||||||
|
JSONObject addSpecialParam(JSONObject taskNode); |
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.dolphinscheduler.api.ApiApplicationServer; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
||||||
|
import org.json.JSONException; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.skyscreamer.jsonassert.JSONAssert; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
|
||||||
|
/** |
||||||
|
* DataSourceParamTest |
||||||
|
*/ |
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@SpringBootTest(classes = ApiApplicationServer.class) |
||||||
|
public class DataSourceParamTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testAddDependentSpecialParam() throws JSONException { |
||||||
|
|
||||||
|
String dependentJson = "{\"type\":\"DEPENDENT\",\"id\":\"tasks-33787\"," + |
||||||
|
"\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\"," + |
||||||
|
"\"dependence\":{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\"," + |
||||||
|
"\"dependItemList\":[{\"projectId\":2,\"definitionId\":46,\"depTasks\":\"ALL\"," + |
||||||
|
"\"cycle\":\"day\",\"dateValue\":\"today\"}]}]}}"; |
||||||
|
|
||||||
|
|
||||||
|
JSONObject taskNode = JSONUtils.parseObject(dependentJson); |
||||||
|
if (StringUtils.isNotEmpty(taskNode.getString("type"))) { |
||||||
|
String taskType = taskNode.getString("type"); |
||||||
|
|
||||||
|
exportProcessAddTaskParam addTaskParam = TaskNodeParamFactory.getByTaskType(taskType); |
||||||
|
|
||||||
|
JSONObject dependent = addTaskParam.addSpecialParam(taskNode); |
||||||
|
|
||||||
|
JSONAssert.assertEquals(taskNode.toString(),dependent.toString(),false); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,63 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.api.utils.exportprocess; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.dolphinscheduler.api.ApiApplicationServer; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
||||||
|
import org.json.JSONException; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.skyscreamer.jsonassert.JSONAssert; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
|
||||||
|
/** |
||||||
|
* DependentParamTest |
||||||
|
*/ |
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@SpringBootTest(classes = ApiApplicationServer.class) |
||||||
|
public class DependentParamTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testAddDependentSpecialParam() throws JSONException { |
||||||
|
|
||||||
|
String sqlJson = "{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," + |
||||||
|
"\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\"," + |
||||||
|
"\"udfs\":\"\",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":\"TABLE\"" + |
||||||
|
",\"localParams\":[],\"connParams\":\"\"," + |
||||||
|
"\"preStatements\":[],\"postStatements\":[]}," + |
||||||
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + |
||||||
|
"\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\"," + |
||||||
|
"\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + |
||||||
|
"\"preTasks\":[\"dependent\"]}"; |
||||||
|
|
||||||
|
|
||||||
|
JSONObject taskNode = JSONUtils.parseObject(sqlJson); |
||||||
|
if (StringUtils.isNotEmpty(taskNode.getString("type"))) { |
||||||
|
String taskType = taskNode.getString("type"); |
||||||
|
|
||||||
|
exportProcessAddTaskParam addTaskParam = TaskNodeParamFactory.getByTaskType(taskType); |
||||||
|
|
||||||
|
JSONObject sql = addTaskParam.addSpecialParam(taskNode); |
||||||
|
|
||||||
|
JSONAssert.assertEquals(taskNode.toString(),sql.toString(),false); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue