Merge branch 'dev' into dev-FTS
This commit is contained in:
commit
cf9576b74a
|
|
@ -56,7 +56,7 @@ If remote branch has a new branch `DEV-1.0`, you need to synchronize this branch
|
|||
|
||||
```
|
||||
git checkout -b dev-1.0 upstream/dev-1.0
|
||||
git push --set-upstream origin dev1.0
|
||||
git push --set-upstream origin dev-1.0
|
||||
```
|
||||
|
||||
## Create your feature branch
|
||||
|
|
|
|||
|
|
@ -43,3 +43,5 @@ clientPort=2181
|
|||
# Purge task interval in hours
|
||||
# Set to "0" to disable auto purge feature
|
||||
#autopurge.purgeInterval=1
|
||||
#Four Letter Words commands:stat,ruok,conf,isro
|
||||
4lw.commands.whitelist=*
|
||||
|
|
|
|||
|
|
@ -220,11 +220,7 @@ public class ServiceModelToSwagger2MapperImpl extends ServiceModelToSwagger2Mapp
|
|||
if (resourceListing == null) {
|
||||
return null;
|
||||
}
|
||||
ApiInfo info = resourceListing.getInfo();
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
return info;
|
||||
return resourceListing.getInfo();
|
||||
}
|
||||
|
||||
protected List<Tag> tagSetToTagList(Set<springfox.documentation.service.Tag> set) {
|
||||
|
|
|
|||
|
|
@ -57,11 +57,10 @@ public class ResourceFilter implements IFilter {
|
|||
* @return file filtered by suffix
|
||||
*/
|
||||
public Set<Resource> fileFilter(){
|
||||
Set<Resource> resources = resourceList.stream().filter(t -> {
|
||||
return resourceList.stream().filter(t -> {
|
||||
String alias = t.getAlias();
|
||||
return alias.endsWith(suffix);
|
||||
}).collect(Collectors.toSet());
|
||||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -193,10 +193,10 @@ public enum Status {
|
|||
BATCH_COPY_PROCESS_DEFINITION_ERROR(10159, "batch copy process definition error", "复制工作流错误"),
|
||||
BATCH_MOVE_PROCESS_DEFINITION_ERROR(10160, "batch move process definition error", "移动工作流错误"),
|
||||
QUERY_WORKFLOW_LINEAGE_ERROR(10161, "query workflow lineage error", "查询血缘失败"),
|
||||
FORCE_TASK_SUCCESS_ERROR(10162, "force task success error", "强制成功任务实例错误"),
|
||||
TASK_INSTANCE_STATE_OPERATION_ERROR(10163, "the status of task instance {0} is {1},Cannot perform force success operation", "任务实例[{0}]的状态是[{1}],无法执行强制成功操作"),
|
||||
|
||||
|
||||
DELETE_PROCESS_DEFINITION_BY_ID_FAIL(10162,"delete process definition by id fail, for there are {0} process instances in executing using it", "删除工作流定义失败,有[{0}]个运行中的工作流实例正在使用"),
|
||||
FORCE_TASK_SUCCESS_ERROR(10163, "force task success error", "强制成功任务实例错误"),
|
||||
TASK_INSTANCE_STATE_OPERATION_ERROR(10164, "the status of task instance {0} is {1},Cannot perform force success operation", "任务实例[{0}]的状态是[{1}],无法执行强制成功操作"),
|
||||
|
||||
UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"),
|
||||
UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"),
|
||||
|
|
@ -298,4 +298,4 @@ public enum Status {
|
|||
return this.enMsg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -189,10 +189,7 @@ public class DataSourceService extends BaseService {
|
|||
|
||||
private boolean checkName(String name) {
|
||||
List<DataSource> queryDataSource = dataSourceMapper.queryDataSourceByName(name.trim());
|
||||
if (queryDataSource != null && queryDataSource.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return queryDataSource != null && queryDataSource.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import static org.apache.dolphinscheduler.common.Constants.LOCAL_PARAMS;
|
|||
import static org.apache.dolphinscheduler.common.Constants.PROCESS_INSTANCE_STATE;
|
||||
import static org.apache.dolphinscheduler.common.Constants.TASK_LIST;
|
||||
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.gantt.GanttDto;
|
||||
import org.apache.dolphinscheduler.api.dto.gantt.Task;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
|
|
@ -711,4 +710,24 @@ public class ProcessInstanceService extends BaseService {
|
|||
return DagHelper.buildDagGraph(processDag);
|
||||
}
|
||||
|
||||
/**
|
||||
* query process instance by processDefinitionId and stateArray
|
||||
* @param processDefinitionId processDefinitionId
|
||||
* @param states states array
|
||||
* @return process instance list
|
||||
*/
|
||||
public List<ProcessInstance> queryByProcessDefineIdAndStatus(int processDefinitionId, int[] states) {
|
||||
return processInstanceMapper.queryByProcessDefineIdAndStatus(processDefinitionId, states);
|
||||
}
|
||||
|
||||
/**
|
||||
* query process instance by processDefinitionId
|
||||
* @param processDefinitionId processDefinitionId
|
||||
* @param size size
|
||||
* @return process instance list
|
||||
*/
|
||||
public List<ProcessInstance> queryByProcessDefineId(int processDefinitionId,int size) {
|
||||
return processInstanceMapper.queryByProcessDefineId(processDefinitionId, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,10 +272,7 @@ public class ResourcesService extends BaseService {
|
|||
private boolean checkResourceExists(String fullName, int userId, int type ){
|
||||
|
||||
List<Resource> resources = resourcesMapper.queryResourceList(fullName, userId, type);
|
||||
if (resources != null && resources.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return resources != null && resources.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -136,10 +136,7 @@ public class UdfFuncService extends BaseService{
|
|||
*/
|
||||
private boolean checkUdfFuncNameExists(String name){
|
||||
List<UdfFunc> resource = udfFuncMapper.queryUdfByIdStr(null, name);
|
||||
if(resource != null && resource.size() > 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return resource != null && resource.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class AccessTokenServiceImpl extends BaseService implements AccessTokenSe
|
|||
*/
|
||||
public Map<String, Object> generateToken(int userId, String expireTime) {
|
||||
Map<String, Object> result = new HashMap<>(5);
|
||||
String token = EncryptionUtils.getMd5(userId + expireTime + String.valueOf(System.currentTimeMillis()));
|
||||
String token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
|
||||
result.put(Constants.DATA_LIST, token);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|||
import org.apache.dolphinscheduler.api.service.BaseService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessDefinitionVersionService;
|
||||
import org.apache.dolphinscheduler.api.service.ProcessInstanceService;
|
||||
import org.apache.dolphinscheduler.api.service.ProjectService;
|
||||
import org.apache.dolphinscheduler.api.service.SchedulerService;
|
||||
import org.apache.dolphinscheduler.api.utils.CheckUtils;
|
||||
|
|
@ -64,7 +65,6 @@ import org.apache.dolphinscheduler.dao.entity.Schedule;
|
|||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
|
||||
|
|
@ -134,7 +134,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
|
|||
private ProcessDefinitionMapper processDefineMapper;
|
||||
|
||||
@Autowired
|
||||
private ProcessInstanceMapper processInstanceMapper;
|
||||
private ProcessInstanceService processInstanceService;
|
||||
|
||||
@Autowired
|
||||
private TaskInstanceMapper taskInstanceMapper;
|
||||
|
|
@ -488,6 +488,12 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
|
|||
putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE, processDefinitionId);
|
||||
return result;
|
||||
}
|
||||
// check process instances is already running
|
||||
List<ProcessInstance> processInstances = processInstanceService.queryByProcessDefineIdAndStatus(processDefinitionId, Constants.NOT_TERMINATED_STATES);
|
||||
if (CollectionUtils.isNotEmpty(processInstances)) {
|
||||
putMsg(result, Status.DELETE_PROCESS_DEFINITION_BY_ID_FAIL,processInstances.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
// get the timing according to the process definition
|
||||
List<Schedule> schedules = scheduleMapper.queryByProcessDefinitionId(processDefinitionId);
|
||||
|
|
@ -1247,7 +1253,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
|
|||
/**
|
||||
* List of process instances
|
||||
*/
|
||||
List<ProcessInstance> processInstanceList = processInstanceMapper.queryByProcessDefineId(processId, limit);
|
||||
List<ProcessInstance> processInstanceList = processInstanceService.queryByProcessDefineId(processId, limit);
|
||||
|
||||
for (ProcessInstance processInstance : processInstanceList) {
|
||||
processInstance.setDuration(DateUtils.differSec(processInstance.getStartTime(), processInstance.getEndTime()));
|
||||
|
|
@ -1321,14 +1327,11 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
|
|||
if (CollectionUtils.isNotEmpty(postNodeList)) {
|
||||
for (String nextNodeName : postNodeList) {
|
||||
List<TreeViewDto> treeViewDtoList = waitingRunningNodeMap.get(nextNodeName);
|
||||
if (CollectionUtils.isNotEmpty(treeViewDtoList)) {
|
||||
treeViewDtoList.add(treeViewDto);
|
||||
waitingRunningNodeMap.put(nextNodeName, treeViewDtoList);
|
||||
} else {
|
||||
if (CollectionUtils.isEmpty(treeViewDtoList)) {
|
||||
treeViewDtoList = new ArrayList<>();
|
||||
treeViewDtoList.add(treeViewDto);
|
||||
waitingRunningNodeMap.put(nextNodeName, treeViewDtoList);
|
||||
}
|
||||
treeViewDtoList.add(treeViewDto);
|
||||
waitingRunningNodeMap.put(nextNodeName, treeViewDtoList);
|
||||
}
|
||||
}
|
||||
runningNodeMap.remove(nodeName);
|
||||
|
|
@ -1690,16 +1693,16 @@ public class ProcessDefinitionServiceImpl extends BaseService implements
|
|||
if (processDefinition == null) {
|
||||
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId);
|
||||
return result;
|
||||
} else {
|
||||
processDefinition.setProjectId(targetProject.getId());
|
||||
processDefinition.setUpdateTime(new Date());
|
||||
if (processDefineMapper.updateById(processDefinition) > 0) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
processDefinition.setProjectId(targetProject.getId());
|
||||
processDefinition.setUpdateTime(new Date());
|
||||
if (processDefineMapper.updateById(processDefinition) > 0) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dolphinscheduler.api.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.enums.ResourceType;
|
||||
|
|
@ -53,8 +52,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -77,8 +74,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -280,8 +275,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -302,8 +295,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -323,8 +314,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -343,8 +332,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -364,8 +351,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -385,8 +370,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -405,8 +388,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -426,8 +407,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
@ -445,8 +424,6 @@ public class ResourcesControllerTest extends AbstractControllerTest{
|
|||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
result.getCode().equals(Status.SUCCESS.getCode());
|
||||
ObjectNode object = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
|
|
|||
|
|
@ -49,10 +49,9 @@ public class ResourceFilterTest {
|
|||
allList.add(resource6);
|
||||
allList.add(resource7);
|
||||
|
||||
|
||||
ResourceFilter resourceFilter = new ResourceFilter(".jar",allList);
|
||||
List<Resource> resourceList = resourceFilter.filter();
|
||||
Assert.assertNotNull(resourceList);
|
||||
resourceList.stream().forEach(t-> logger.info(t.toString()));
|
||||
resourceList.forEach(t -> logger.info(t.toString()));
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,6 @@ import org.apache.dolphinscheduler.dao.entity.Schedule;
|
|||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
|
||||
|
|
@ -94,7 +93,7 @@ public class ProcessDefinitionServiceTest {
|
|||
private ProcessService processService;
|
||||
|
||||
@Mock
|
||||
private ProcessInstanceMapper processInstanceMapper;
|
||||
private ProcessInstanceService processInstanceService;
|
||||
|
||||
@Mock
|
||||
private TaskInstanceMapper taskInstanceMapper;
|
||||
|
|
@ -734,7 +733,7 @@ public class ProcessDefinitionServiceTest {
|
|||
|
||||
//task instance not exist
|
||||
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition);
|
||||
Mockito.when(processInstanceMapper.queryByProcessDefineId(46, 10)).thenReturn(processInstanceList);
|
||||
Mockito.when(processInstanceService.queryByProcessDefineId(46, 10)).thenReturn(processInstanceList);
|
||||
Mockito.when(taskInstanceMapper.queryByInstanceIdAndName(processInstance.getId(), "shell-1")).thenReturn(null);
|
||||
Map<String, Object> taskNullRes = processDefinitionService.viewTree(46, 10);
|
||||
Assert.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS));
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
|
|
@ -27,7 +28,7 @@ import java.util.regex.Pattern;
|
|||
public final class Constants {
|
||||
|
||||
private Constants() {
|
||||
throw new IllegalStateException("Constants class");
|
||||
throw new UnsupportedOperationException("Construct Constants");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,13 +14,19 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides utility methods and decorators for {@link Collection} instances.
|
||||
|
|
@ -37,8 +43,9 @@ import java.util.*;
|
|||
public class CollectionUtils {
|
||||
|
||||
private CollectionUtils() {
|
||||
throw new IllegalStateException("CollectionUtils class");
|
||||
throw new UnsupportedOperationException("Construct CollectionUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link Collection} containing <i>a</i> minus a subset of
|
||||
* <i>b</i>. Only the elements of <i>b</i> that satisfy the predicate
|
||||
|
|
@ -71,7 +78,7 @@ public class CollectionUtils {
|
|||
/**
|
||||
* String to map
|
||||
*
|
||||
* @param str string
|
||||
* @param str string
|
||||
* @param separator separator
|
||||
* @return string to map
|
||||
*/
|
||||
|
|
@ -82,7 +89,7 @@ public class CollectionUtils {
|
|||
/**
|
||||
* String to map
|
||||
*
|
||||
* @param str string
|
||||
* @param str string
|
||||
* @param separator separator
|
||||
* @param keyPrefix prefix
|
||||
* @return string to map
|
||||
|
|
@ -112,7 +119,6 @@ public class CollectionUtils {
|
|||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper class to easily access cardinality properties of two collections.
|
||||
*
|
||||
|
|
@ -137,8 +143,8 @@ public class CollectionUtils {
|
|||
* @param b the second collection
|
||||
*/
|
||||
public CardinalityHelper(final Iterable<? extends O> a, final Iterable<? extends O> b) {
|
||||
cardinalityA = CollectionUtils.<O>getCardinalityMap(a);
|
||||
cardinalityB = CollectionUtils.<O>getCardinalityMap(b);
|
||||
cardinalityA = CollectionUtils.getCardinalityMap(a);
|
||||
cardinalityB = CollectionUtils.getCardinalityMap(b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -227,7 +233,7 @@ public class CollectionUtils {
|
|||
* Only those elements present in the collection will appear as
|
||||
* keys in the map.
|
||||
*
|
||||
* @param <O> the type of object in the returned {@link Map}. This is a super type of O
|
||||
* @param <O> the type of object in the returned {@link Map}. This is a super type of O
|
||||
* @param coll the collection to get the cardinality map for, must not be null
|
||||
* @return the populated cardinality map
|
||||
*/
|
||||
|
|
@ -239,9 +245,9 @@ public class CollectionUtils {
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes certain attributes of each object in the list
|
||||
*
|
||||
* @param originList origin list
|
||||
* @param exclusionSet exclusion set
|
||||
* @param <T> T
|
||||
|
|
@ -258,8 +264,8 @@ public class CollectionUtils {
|
|||
Map<String, Object> instanceMap;
|
||||
for (T instance : originList) {
|
||||
Map<String, Object> dataMap = new BeanMap(instance);
|
||||
instanceMap = new LinkedHashMap<>(16,0.75f,true);
|
||||
for (Map.Entry<String, Object> entry: dataMap.entrySet()) {
|
||||
instanceMap = new LinkedHashMap<>(16, 0.75f, true);
|
||||
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
||||
if (exclusionSet.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,124 +14,129 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ResUploadType;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* common utils
|
||||
*/
|
||||
public class CommonUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);
|
||||
|
||||
private static final Base64 BASE64 = new Base64();
|
||||
private static final Base64 BASE64 = new Base64();
|
||||
|
||||
private CommonUtils() {
|
||||
throw new IllegalStateException("CommonUtils class");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return get the path of system environment variables
|
||||
*/
|
||||
public static String getSystemEnvPath() {
|
||||
String envPath = PropertyUtils.getString(Constants.DOLPHINSCHEDULER_ENV_PATH);
|
||||
if (StringUtils.isEmpty(envPath)) {
|
||||
URL envDefaultPath = CommonUtils.class.getClassLoader().getResource(Constants.ENV_PATH);
|
||||
|
||||
if (envDefaultPath != null){
|
||||
envPath = envDefaultPath.getPath();
|
||||
logger.debug("env path :{}", envPath);
|
||||
}else{
|
||||
envPath = "/etc/profile";
|
||||
}
|
||||
private CommonUtils() {
|
||||
throw new UnsupportedOperationException("Construct CommonUtils");
|
||||
}
|
||||
|
||||
return envPath;
|
||||
}
|
||||
/**
|
||||
* @return get the path of system environment variables
|
||||
*/
|
||||
public static String getSystemEnvPath() {
|
||||
String envPath = PropertyUtils.getString(Constants.DOLPHINSCHEDULER_ENV_PATH);
|
||||
if (StringUtils.isEmpty(envPath)) {
|
||||
URL envDefaultPath = CommonUtils.class.getClassLoader().getResource(Constants.ENV_PATH);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return is develop mode
|
||||
*/
|
||||
public static boolean isDevelopMode() {
|
||||
return PropertyUtils.getBoolean(Constants.DEVELOPMENT_STATE, true);
|
||||
}
|
||||
if (envDefaultPath != null) {
|
||||
envPath = envDefaultPath.getPath();
|
||||
logger.debug("env path :{}", envPath);
|
||||
} else {
|
||||
envPath = "/etc/profile";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* if upload resource is HDFS and kerberos startup is true , else false
|
||||
* @return true if upload resource is HDFS and kerberos startup
|
||||
*/
|
||||
public static boolean getKerberosStartupState(){
|
||||
String resUploadStartupType = PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE);
|
||||
ResUploadType resUploadType = ResUploadType.valueOf(resUploadStartupType);
|
||||
Boolean kerberosStartupState = PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE,false);
|
||||
return resUploadType == ResUploadType.HDFS && kerberosStartupState;
|
||||
}
|
||||
|
||||
/**
|
||||
* load kerberos configuration
|
||||
* @throws Exception errors
|
||||
*/
|
||||
public static void loadKerberosConf()throws Exception{
|
||||
if (CommonUtils.getKerberosStartupState()) {
|
||||
System.setProperty(Constants.JAVA_SECURITY_KRB5_CONF, PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH));
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.set(Constants.HADOOP_SECURITY_AUTHENTICATION, Constants.KERBEROS);
|
||||
UserGroupInformation.setConfiguration(configuration);
|
||||
UserGroupInformation.loginUserFromKeytab(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME),
|
||||
PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH));
|
||||
return envPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* encode password
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String encodePassword(String password) {
|
||||
if(StringUtils.isEmpty(password)){return StringUtils.EMPTY; }
|
||||
//if encryption is not turned on, return directly
|
||||
boolean encryptionEnable = PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE,false);
|
||||
if ( !encryptionEnable){ return password; }
|
||||
|
||||
// Using Base64 + salt to process password
|
||||
String salt = PropertyUtils.getString(Constants.DATASOURCE_ENCRYPTION_SALT,Constants.DATASOURCE_ENCRYPTION_SALT_DEFAULT);
|
||||
String passwordWithSalt = salt + new String(BASE64.encode(password.getBytes(StandardCharsets.UTF_8))) ;
|
||||
return new String(BASE64.encode(passwordWithSalt.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
/**
|
||||
* decode password
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String decodePassword(String password) {
|
||||
if(StringUtils.isEmpty(password)){return StringUtils.EMPTY ; }
|
||||
|
||||
//if encryption is not turned on, return directly
|
||||
boolean encryptionEnable = PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE,false);
|
||||
if ( !encryptionEnable){ return password; }
|
||||
|
||||
// Using Base64 + salt to process password
|
||||
String salt = PropertyUtils.getString(Constants.DATASOURCE_ENCRYPTION_SALT,Constants.DATASOURCE_ENCRYPTION_SALT_DEFAULT);
|
||||
String passwordWithSalt = new String(BASE64.decode(password), StandardCharsets.UTF_8) ;
|
||||
if(!passwordWithSalt.startsWith(salt)){
|
||||
logger.warn("There is a password and salt mismatch: {} ",password);
|
||||
return password;
|
||||
/**
|
||||
* @return is develop mode
|
||||
*/
|
||||
public static boolean isDevelopMode() {
|
||||
return PropertyUtils.getBoolean(Constants.DEVELOPMENT_STATE, true);
|
||||
}
|
||||
return new String(BASE64.decode(passwordWithSalt.substring(salt.length())), StandardCharsets.UTF_8) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* if upload resource is HDFS and kerberos startup is true , else false
|
||||
*
|
||||
* @return true if upload resource is HDFS and kerberos startup
|
||||
*/
|
||||
public static boolean getKerberosStartupState() {
|
||||
String resUploadStartupType = PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE);
|
||||
ResUploadType resUploadType = ResUploadType.valueOf(resUploadStartupType);
|
||||
Boolean kerberosStartupState = PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false);
|
||||
return resUploadType == ResUploadType.HDFS && kerberosStartupState;
|
||||
}
|
||||
|
||||
/**
|
||||
* load kerberos configuration
|
||||
*
|
||||
* @throws Exception errors
|
||||
*/
|
||||
public static void loadKerberosConf() throws Exception {
|
||||
if (CommonUtils.getKerberosStartupState()) {
|
||||
System.setProperty(Constants.JAVA_SECURITY_KRB5_CONF, PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH));
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.set(Constants.HADOOP_SECURITY_AUTHENTICATION, Constants.KERBEROS);
|
||||
UserGroupInformation.setConfiguration(configuration);
|
||||
UserGroupInformation.loginUserFromKeytab(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME),
|
||||
PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* encode password
|
||||
*/
|
||||
public static String encodePassword(String password) {
|
||||
if (StringUtils.isEmpty(password)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
//if encryption is not turned on, return directly
|
||||
boolean encryptionEnable = PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE, false);
|
||||
if (!encryptionEnable) {
|
||||
return password;
|
||||
}
|
||||
|
||||
// Using Base64 + salt to process password
|
||||
String salt = PropertyUtils.getString(Constants.DATASOURCE_ENCRYPTION_SALT, Constants.DATASOURCE_ENCRYPTION_SALT_DEFAULT);
|
||||
String passwordWithSalt = salt + new String(BASE64.encode(password.getBytes(StandardCharsets.UTF_8)));
|
||||
return new String(BASE64.encode(passwordWithSalt.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
/**
|
||||
* decode password
|
||||
*/
|
||||
public static String decodePassword(String password) {
|
||||
if (StringUtils.isEmpty(password)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
//if encryption is not turned on, return directly
|
||||
boolean encryptionEnable = PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE, false);
|
||||
if (!encryptionEnable) {
|
||||
return password;
|
||||
}
|
||||
|
||||
// Using Base64 + salt to process password
|
||||
String salt = PropertyUtils.getString(Constants.DATASOURCE_ENCRYPTION_SALT, Constants.DATASOURCE_ENCRYPTION_SALT_DEFAULT);
|
||||
String passwordWithSalt = new String(BASE64.decode(password), StandardCharsets.UTF_8);
|
||||
if (!passwordWithSalt.startsWith(salt)) {
|
||||
logger.warn("There is a password and salt mismatch: {} ", password);
|
||||
return password;
|
||||
}
|
||||
return new String(BASE64.decode(passwordWithSalt.substring(salt.length())), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,37 +14,40 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConnectionUtils {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(ConnectionUtils.class);
|
||||
public static final Logger logger = LoggerFactory.getLogger(ConnectionUtils.class);
|
||||
|
||||
private ConnectionUtils() {
|
||||
throw new IllegalStateException("ConnectionUtils class");
|
||||
}
|
||||
|
||||
/**
|
||||
* release resource
|
||||
* @param resources resources
|
||||
*/
|
||||
public static void releaseResource(AutoCloseable... resources) {
|
||||
|
||||
if (resources == null || resources.length == 0) {
|
||||
return;
|
||||
private ConnectionUtils() {
|
||||
throw new UnsupportedOperationException("Construct ConnectionUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* release resource
|
||||
*
|
||||
* @param resources resources
|
||||
*/
|
||||
public static void releaseResource(AutoCloseable... resources) {
|
||||
|
||||
if (resources == null || resources.length == 0) {
|
||||
return;
|
||||
}
|
||||
Arrays.stream(resources).filter(Objects::nonNull)
|
||||
.forEach(resource -> {
|
||||
try {
|
||||
resource.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
Arrays.stream(resources).filter(Objects::nonNull)
|
||||
.forEach(resource -> {
|
||||
try {
|
||||
resource.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ public class DateUtils {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DateUtils.class);
|
||||
|
||||
private DateUtils() {
|
||||
throw new UnsupportedOperationException("Construct DateUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* date to local datetime
|
||||
*
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ import org.apache.dolphinscheduler.common.enums.DependResult;
|
|||
import org.apache.dolphinscheduler.common.enums.DependentRelation;
|
||||
import org.apache.dolphinscheduler.common.model.DateInterval;
|
||||
import org.apache.dolphinscheduler.common.utils.dependent.DependentDateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
|
@ -29,32 +27,35 @@ import java.util.List;
|
|||
|
||||
public class DependentUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DependentUtils.class);
|
||||
private DependentUtils() {
|
||||
throw new UnsupportedOperationException("Construct DependentUtils");
|
||||
}
|
||||
|
||||
public static DependResult getDependResultForRelation(DependentRelation relation,
|
||||
List<DependResult> dependResultList){
|
||||
List<DependResult> dependResultList) {
|
||||
|
||||
DependResult dependResult = DependResult.SUCCESS;
|
||||
|
||||
switch (relation){
|
||||
switch (relation) {
|
||||
case AND:
|
||||
if(dependResultList.contains(DependResult.FAILED)){
|
||||
if (dependResultList.contains(DependResult.FAILED)) {
|
||||
dependResult = DependResult.FAILED;
|
||||
} if(dependResultList.contains(DependResult.WAITING)){
|
||||
}
|
||||
if (dependResultList.contains(DependResult.WAITING)) {
|
||||
dependResult = DependResult.WAITING;
|
||||
}
|
||||
break;
|
||||
case OR:
|
||||
if(dependResultList.contains(DependResult.SUCCESS)){
|
||||
if (dependResultList.contains(DependResult.SUCCESS)) {
|
||||
dependResult = DependResult.SUCCESS;
|
||||
}else if(dependResultList.contains(DependResult.WAITING)){
|
||||
} else if (dependResultList.contains(DependResult.WAITING)) {
|
||||
dependResult = DependResult.WAITING;
|
||||
}else{
|
||||
} else {
|
||||
dependResult = DependResult.FAILED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return dependResult;
|
||||
}
|
||||
|
|
@ -62,36 +63,37 @@ public class DependentUtils {
|
|||
|
||||
/**
|
||||
* get date interval list by business date and date value.
|
||||
*
|
||||
* @param businessDate business date
|
||||
* @param dateValue date value
|
||||
* @return date interval list by business date and date value.
|
||||
*/
|
||||
public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue){
|
||||
public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue) {
|
||||
List<DateInterval> result = new ArrayList<>();
|
||||
switch (dateValue){
|
||||
switch (dateValue) {
|
||||
case "currentHour":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 0);
|
||||
break;
|
||||
case "last1Hour":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 1);
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 1);
|
||||
break;
|
||||
case "last2Hours":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 2);
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 2);
|
||||
break;
|
||||
case "last3Hours":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 3);
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 3);
|
||||
break;
|
||||
case "last24Hours":
|
||||
result = DependentDateUtils.getSpecialLastDayInterval(businessDate);
|
||||
break;
|
||||
case "today":
|
||||
result = DependentDateUtils.getTodayInterval(businessDate);
|
||||
result = DependentDateUtils.getTodayInterval(businessDate);
|
||||
break;
|
||||
case "last1Days":
|
||||
result = DependentDateUtils.getLastDayInterval(businessDate, 1);
|
||||
result = DependentDateUtils.getLastDayInterval(businessDate, 1);
|
||||
break;
|
||||
case "last2Days":
|
||||
result = DependentDateUtils.getLastDayInterval(businessDate, 2);
|
||||
result = DependentDateUtils.getLastDayInterval(businessDate, 2);
|
||||
break;
|
||||
case "last3Days":
|
||||
result = DependentDateUtils.getLastDayInterval(businessDate, 3);
|
||||
|
|
@ -144,5 +146,4 @@ public class DependentUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
|
@ -23,14 +24,16 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|||
*/
|
||||
public class EncryptionUtils {
|
||||
|
||||
private EncryptionUtils() {
|
||||
throw new UnsupportedOperationException("Construct EncryptionUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rawStr raw string
|
||||
* @return md5(rawStr)
|
||||
*/
|
||||
public static String getMd5(String rawStr) {
|
||||
return DigestUtils.md5Hex(null == rawStr ? StringUtils.EMPTY : rawStr);
|
||||
return DigestUtils.md5Hex(null == rawStr ? StringUtils.EMPTY : rawStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
|
||||
|
||||
public class EnumUtils {
|
||||
|
||||
private EnumUtils() {
|
||||
throw new UnsupportedOperationException("Construct EnumUtils");
|
||||
}
|
||||
|
||||
public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final String enumName) {
|
||||
if (enumName == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.DATA_BASEDIR_PATH;
|
||||
|
|
@ -21,6 +22,9 @@ import static org.apache.dolphinscheduler.common.Constants.RESOURCE_VIEW_SUFFIXS
|
|||
import static org.apache.dolphinscheduler.common.Constants.RESOURCE_VIEW_SUFFIXS_DEFAULT_VALUE;
|
||||
import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS;
|
||||
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -36,9 +40,6 @@ import java.nio.charset.Charset;
|
|||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -46,12 +47,17 @@ import org.slf4j.LoggerFactory;
|
|||
* file utils
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
|
||||
|
||||
public static final String DATA_BASEDIR = PropertyUtils.getString(DATA_BASEDIR_PATH,"/tmp/dolphinscheduler");
|
||||
public static final String DATA_BASEDIR = PropertyUtils.getString(DATA_BASEDIR_PATH, "/tmp/dolphinscheduler");
|
||||
|
||||
public static final ThreadLocal<Logger> taskLoggerThreadLocal = new ThreadLocal<>();
|
||||
|
||||
private FileUtils() {
|
||||
throw new UnsupportedOperationException("Construct FileUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* get file suffix
|
||||
*
|
||||
|
|
@ -80,7 +86,7 @@ public class FileUtils {
|
|||
String fileName = String.format("%s/download/%s/%s", DATA_BASEDIR, DateUtils.getCurrentTime(YYYYMMDDHHMMSS), filename);
|
||||
|
||||
File file = new File(fileName);
|
||||
if (!file.getParentFile().exists()){
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +103,7 @@ public class FileUtils {
|
|||
public static String getUploadFilename(String tenantCode, String filename) {
|
||||
String fileName = String.format("%s/%s/resources/%s", DATA_BASEDIR, tenantCode, filename);
|
||||
File file = new File(fileName);
|
||||
if (!file.getParentFile().exists()){
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +112,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* directory of process execution
|
||||
*
|
||||
* @param projectId project id
|
||||
* @param processDefineId process definition id
|
||||
* @param processInstanceId process instance id
|
||||
|
|
@ -114,9 +121,9 @@ public class FileUtils {
|
|||
*/
|
||||
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId, int taskInstanceId) {
|
||||
String fileName = String.format("%s/exec/process/%s/%s/%s/%s", DATA_BASEDIR, Integer.toString(projectId),
|
||||
Integer.toString(processDefineId), Integer.toString(processInstanceId),Integer.toString(taskInstanceId));
|
||||
Integer.toString(processDefineId), Integer.toString(processInstanceId), Integer.toString(taskInstanceId));
|
||||
File file = new File(fileName);
|
||||
if (!file.getParentFile().exists()){
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +132,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* directory of process instances
|
||||
*
|
||||
* @param projectId project id
|
||||
* @param processDefineId process definition id
|
||||
* @param processInstanceId process instance id
|
||||
|
|
@ -150,6 +158,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* create directory and user
|
||||
*
|
||||
* @param execLocalPath execute local path
|
||||
* @param userName user name
|
||||
* @throws IOException errors
|
||||
|
|
@ -190,12 +199,11 @@ public class FileUtils {
|
|||
OSUtils.taskLoggerThreadLocal.remove();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* write content to file ,if parent path not exists, it will do one's utmost to mkdir
|
||||
*
|
||||
* @param content content
|
||||
* @param filePath target file path
|
||||
* @param content content
|
||||
* @param filePath target file path
|
||||
* @return true if write success
|
||||
*/
|
||||
public static boolean writeContent2File(String content, String filePath) {
|
||||
|
|
@ -231,13 +239,13 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Writes a String to a file creating the file if it does not exist.
|
||||
*
|
||||
* <p>
|
||||
* NOTE: As from v1.3, the parent directories of the file will be created
|
||||
* if they do not exist.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @throws IOException in case of an I/O error
|
||||
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
|
||||
* @since 2.4
|
||||
|
|
@ -248,13 +256,13 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Writes a String to a file creating the file if it does not exist.
|
||||
*
|
||||
* <p>
|
||||
* NOTE: As from v1.3, the parent directories of the file will be created
|
||||
* if they do not exist.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @throws IOException in case of an I/O error
|
||||
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
|
||||
*/
|
||||
|
|
@ -265,9 +273,9 @@ public class FileUtils {
|
|||
/**
|
||||
* Writes a String to a file creating the file if it does not exist.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param append if {@code true}, then the String will be added to the
|
||||
* end of the file rather than overwriting
|
||||
* @throws IOException in case of an I/O error
|
||||
|
|
@ -287,15 +295,14 @@ public class FileUtils {
|
|||
/**
|
||||
* Writes a String to a file creating the file if it does not exist.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param encoding the encoding to use, {@code null} means platform default
|
||||
* @param append if {@code true}, then the String will be added to the
|
||||
* end of the file rather than overwriting
|
||||
* @throws IOException in case of an I/O error
|
||||
* @throws UnsupportedCharsetException
|
||||
* thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
|
||||
* supported by the VM
|
||||
* @throws UnsupportedCharsetException thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
|
||||
* supported by the VM
|
||||
* @since 2.1
|
||||
*/
|
||||
public static void writeStringToFile(File file, String data, String encoding, boolean append) throws IOException {
|
||||
|
|
@ -305,8 +312,8 @@ public class FileUtils {
|
|||
/**
|
||||
* Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
public static void writeStringToFile(File file, String data) throws IOException {
|
||||
|
|
@ -316,8 +323,8 @@ public class FileUtils {
|
|||
/**
|
||||
* Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
|
||||
*
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param file the file to write
|
||||
* @param data the content to write to the file
|
||||
* @param append if {@code true}, then the String will be added to the
|
||||
* end of the file rather than overwriting
|
||||
* @throws IOException in case of an I/O error
|
||||
|
|
@ -340,7 +347,7 @@ public class FileUtils {
|
|||
* An exception is thrown if the file exists but cannot be written to.
|
||||
* An exception is thrown if the parent directory cannot be created.
|
||||
*
|
||||
* @param file the file to open for output, must not be {@code null}
|
||||
* @param file the file to open for output, must not be {@code null}
|
||||
* @return a new {@link FileOutputStream} for the specified file
|
||||
* @throws IOException if the file object is a directory
|
||||
* @throws IOException if the file cannot be written to
|
||||
|
|
@ -364,7 +371,7 @@ public class FileUtils {
|
|||
* An exception is thrown if the file exists but cannot be written to.
|
||||
* An exception is thrown if the parent directory cannot be created.
|
||||
*
|
||||
* @param file the file to open for output, must not be {@code null}
|
||||
* @param file the file to open for output, must not be {@code null}
|
||||
* @param append if {@code true}, then bytes will be added to the
|
||||
* end of the file rather than overwriting
|
||||
* @return a new {@link FileOutputStream} for the specified file
|
||||
|
|
@ -384,15 +391,15 @@ public class FileUtils {
|
|||
} else {
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null && !parent.mkdirs() && !parent.isDirectory()) {
|
||||
throw new IOException("Directory '" + parent + "' could not be created");
|
||||
throw new IOException("Directory '" + parent + "' could not be created");
|
||||
}
|
||||
}
|
||||
return new FileOutputStream(file, append);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* deletes a directory recursively
|
||||
*
|
||||
* @param dir directory
|
||||
* @throws IOException in case deletion is unsuccessful
|
||||
*/
|
||||
|
|
@ -420,17 +427,18 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Gets all the parent subdirectories of the parentDir directory
|
||||
*
|
||||
* @param parentDir parent dir
|
||||
* @return all dirs
|
||||
*/
|
||||
public static File[] getAllDir(String parentDir){
|
||||
if(parentDir == null || "".equals(parentDir)) {
|
||||
public static File[] getAllDir(String parentDir) {
|
||||
if (parentDir == null || "".equals(parentDir)) {
|
||||
throw new RuntimeException("parentDir can not be empty");
|
||||
}
|
||||
|
||||
File file = new File(parentDir);
|
||||
if(!file.exists() || !file.isDirectory()) {
|
||||
throw new RuntimeException("parentDir not exist, or is not a directory:"+parentDir);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
throw new RuntimeException("parentDir not exist, or is not a directory:" + parentDir);
|
||||
}
|
||||
|
||||
return file.listFiles(File::isDirectory);
|
||||
|
|
@ -438,6 +446,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Get Content
|
||||
*
|
||||
* @param inputStream input stream
|
||||
* @return string of input stream
|
||||
*/
|
||||
|
|
@ -447,15 +456,14 @@ public class FileUtils {
|
|||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length= inputStream.read(buffer)) != -1) {
|
||||
output.write(buffer,0,length);
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, length);
|
||||
}
|
||||
return output.toString();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public class HadoopUtils implements Closeable {
|
|||
*/
|
||||
String appUrl = "";
|
||||
|
||||
if (StringUtils.isEmpty(rmHaIds)){
|
||||
if (StringUtils.isEmpty(rmHaIds)) {
|
||||
//single resourcemanager enabled
|
||||
appUrl = appAddress;
|
||||
yarnEnabled = true;
|
||||
|
|
@ -206,7 +206,7 @@ public class HadoopUtils implements Closeable {
|
|||
logger.info("application url : {}", appUrl);
|
||||
}
|
||||
|
||||
if(StringUtils.isBlank(appUrl)){
|
||||
if (StringUtils.isBlank(appUrl)) {
|
||||
throw new Exception("application url is blank");
|
||||
}
|
||||
return String.format(appUrl, applicationId);
|
||||
|
|
@ -417,25 +417,33 @@ public class HadoopUtils implements Closeable {
|
|||
String applicationUrl = getApplicationUrl(applicationId);
|
||||
logger.info("applicationUrl={}", applicationUrl);
|
||||
|
||||
String responseContent ;
|
||||
if (PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) {
|
||||
responseContent = KerberosHttpClient.get(applicationUrl);
|
||||
} else {
|
||||
responseContent = HttpUtils.get(applicationUrl);
|
||||
}
|
||||
String responseContent;
|
||||
if (PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) {
|
||||
responseContent = KerberosHttpClient.get(applicationUrl);
|
||||
} else {
|
||||
responseContent = HttpUtils.get(applicationUrl);
|
||||
}
|
||||
if (responseContent != null) {
|
||||
ObjectNode jsonObject = JSONUtils.parseObject(responseContent);
|
||||
if (!jsonObject.has("app")) {
|
||||
return ExecutionStatus.FAILURE;
|
||||
}
|
||||
result = jsonObject.path("app").path("finalStatus").asText();
|
||||
|
||||
} else {
|
||||
//may be in job history
|
||||
String jobHistoryUrl = getJobHistoryUrl(applicationId);
|
||||
logger.info("jobHistoryUrl={}", jobHistoryUrl);
|
||||
responseContent = HttpUtils.get(jobHistoryUrl);
|
||||
ObjectNode jsonObject = JSONUtils.parseObject(responseContent);
|
||||
if (!jsonObject.has("job")){
|
||||
if (null != responseContent) {
|
||||
ObjectNode jsonObject = JSONUtils.parseObject(responseContent);
|
||||
if (!jsonObject.has("job")) {
|
||||
return ExecutionStatus.FAILURE;
|
||||
}
|
||||
result = jsonObject.path("job").path("state").asText();
|
||||
} else {
|
||||
return ExecutionStatus.FAILURE;
|
||||
}
|
||||
result = jsonObject.path("job").path("state").asText();
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
|
|
@ -474,7 +482,7 @@ public class HadoopUtils implements Closeable {
|
|||
/**
|
||||
* hdfs resource dir
|
||||
*
|
||||
* @param tenantCode tenant code
|
||||
* @param tenantCode tenant code
|
||||
* @param resourceType resource type
|
||||
* @return hdfs resource dir
|
||||
*/
|
||||
|
|
@ -679,7 +687,7 @@ public class HadoopUtils implements Closeable {
|
|||
ObjectNode jsonObject = JSONUtils.parseObject(retStr);
|
||||
|
||||
//get ResourceManager state
|
||||
if (!jsonObject.has("clusterInfo")){
|
||||
if (!jsonObject.has("clusterInfo")) {
|
||||
return null;
|
||||
}
|
||||
return jsonObject.get("clusterInfo").path("haState").asText();
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
|
|
@ -30,148 +32,148 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
|||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* http utils
|
||||
*/
|
||||
public class HttpUtils {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
|
||||
private HttpUtils() {
|
||||
throw new UnsupportedOperationException("Construct HttpUtils");
|
||||
}
|
||||
|
||||
private HttpUtils() {
|
||||
public static CloseableHttpClient getInstance() {
|
||||
return HttpClientInstance.httpClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static CloseableHttpClient getInstance(){
|
||||
return HttpClientInstance.httpClient;
|
||||
}
|
||||
|
||||
private static class HttpClientInstance{
|
||||
private static final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
|
||||
}
|
||||
private static class HttpClientInstance {
|
||||
private static final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
|
||||
}
|
||||
|
||||
|
||||
private static PoolingHttpClientConnectionManager cm;
|
||||
private static PoolingHttpClientConnectionManager cm;
|
||||
|
||||
private static SSLContext ctx = null;
|
||||
private static SSLContext ctx = null;
|
||||
|
||||
private static SSLConnectionSocketFactory socketFactory;
|
||||
private static SSLConnectionSocketFactory socketFactory;
|
||||
|
||||
private static RequestConfig requestConfig;
|
||||
private static RequestConfig requestConfig;
|
||||
|
||||
private static Registry<ConnectionSocketFactory> socketFactoryRegistry;
|
||||
private static Registry<ConnectionSocketFactory> socketFactoryRegistry;
|
||||
|
||||
private static X509TrustManager xtm = new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||
}
|
||||
private static X509TrustManager xtm = new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||
}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
try {
|
||||
ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
|
||||
ctx.init(null, new TrustManager[] { xtm }, null);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
logger.error("SSLContext init with NoSuchAlgorithmException", e);
|
||||
} catch (KeyManagementException e) {
|
||||
logger.error("SSLContext init with KeyManagementException", e);
|
||||
}
|
||||
socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
|
||||
/** set timeout、request time、socket timeout */
|
||||
requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
|
||||
.setExpectContinueEnabled(Boolean.TRUE)
|
||||
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
|
||||
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
|
||||
.setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT).setSocketTimeout(Constants.SOCKET_TIMEOUT)
|
||||
.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT).setRedirectsEnabled(true)
|
||||
.build();
|
||||
socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", PlainConnectionSocketFactory.INSTANCE).register("https", socketFactory).build();
|
||||
cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
||||
cm.setDefaultMaxPerRoute(60);
|
||||
cm.setMaxTotal(100);
|
||||
static {
|
||||
try {
|
||||
ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
|
||||
ctx.init(null, new TrustManager[]{xtm}, null);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
logger.error("SSLContext init with NoSuchAlgorithmException", e);
|
||||
} catch (KeyManagementException e) {
|
||||
logger.error("SSLContext init with KeyManagementException", e);
|
||||
}
|
||||
socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
|
||||
/** set timeout、request time、socket timeout */
|
||||
requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
|
||||
.setExpectContinueEnabled(Boolean.TRUE)
|
||||
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
|
||||
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
|
||||
.setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT).setSocketTimeout(Constants.SOCKET_TIMEOUT)
|
||||
.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT).setRedirectsEnabled(true)
|
||||
.build();
|
||||
socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", PlainConnectionSocketFactory.INSTANCE).register("https", socketFactory).build();
|
||||
cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
||||
cm.setDefaultMaxPerRoute(60);
|
||||
cm.setMaxTotal(100);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get http request content
|
||||
*
|
||||
* @param url url
|
||||
* @return http get request response content
|
||||
*/
|
||||
public static String get(String url) {
|
||||
CloseableHttpClient httpclient = HttpUtils.getInstance();
|
||||
|
||||
|
||||
/**
|
||||
* get http request content
|
||||
* @param url url
|
||||
* @return http get request response content
|
||||
*/
|
||||
public static String get(String url){
|
||||
CloseableHttpClient httpclient = HttpUtils.getInstance();
|
||||
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
return getResponseContentString(httpget,httpclient);
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
return getResponseContentString(httpget, httpclient);
|
||||
}
|
||||
|
||||
/**
|
||||
* get http response content
|
||||
*
|
||||
* @param httpget httpget
|
||||
* @param httpget httpget
|
||||
* @param httpClient httpClient
|
||||
* @return http get request response content
|
||||
*/
|
||||
public static String getResponseContentString(HttpGet httpget, CloseableHttpClient httpClient) {
|
||||
String responseContent = null;
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
response = httpClient.execute(httpget);
|
||||
// check response status is 200
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
responseContent = EntityUtils.toString(entity, Constants.UTF_8);
|
||||
} else {
|
||||
logger.warn("http entity is null");
|
||||
}
|
||||
} else {
|
||||
logger.error("http get:{} response status code is not 200!", response.getStatusLine().getStatusCode());
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
} finally {
|
||||
try {
|
||||
if (response != null) {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
if (!httpget.isAborted()) {
|
||||
httpget.releaseConnection();
|
||||
httpget.abort();
|
||||
}
|
||||
String responseContent = null;
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
response = httpClient.execute(httpget);
|
||||
// check response status is 200
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
responseContent = EntityUtils.toString(entity, Constants.UTF_8);
|
||||
} else {
|
||||
logger.warn("http entity is null");
|
||||
}
|
||||
} else {
|
||||
logger.error("http get:{} response status code is not 200!", response.getStatusLine().getStatusCode());
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
} finally {
|
||||
try {
|
||||
if (response != null) {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
if (!httpget.isAborted()) {
|
||||
httpget.releaseConnection();
|
||||
httpget.abort();
|
||||
}
|
||||
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -18,14 +17,17 @@
|
|||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
public class IOUtils {
|
||||
|
||||
public static void closeQuietly(Closeable closeable){
|
||||
if(closeable != null){
|
||||
private IOUtils() {
|
||||
throw new UnsupportedOperationException("Construct IOUtils");
|
||||
}
|
||||
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException ignore) {
|
||||
|
|
|
|||
|
|
@ -14,46 +14,50 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
/**
|
||||
* http utils
|
||||
*/
|
||||
public class IpUtils {
|
||||
|
||||
public static final String DOT = ".";
|
||||
private IpUtils() {
|
||||
throw new UnsupportedOperationException("Construct IpUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* ip str to long <p>
|
||||
*
|
||||
* @param ipStr ip string
|
||||
* @return ip to long
|
||||
*/
|
||||
public static Long ipToLong(String ipStr) {
|
||||
String[] ipSet = ipStr.split("\\" + DOT);
|
||||
public static final String DOT = ".";
|
||||
|
||||
return Long.parseLong(ipSet[0]) << 24 | Long.parseLong(ipSet[1]) << 16 | Long.parseLong(ipSet[2]) << 8 | Long.parseLong(ipSet[3]);
|
||||
}
|
||||
/**
|
||||
* ip str to long <p>
|
||||
*
|
||||
* @param ipStr ip string
|
||||
* @return ip to long
|
||||
*/
|
||||
public static Long ipToLong(String ipStr) {
|
||||
String[] ipSet = ipStr.split("\\" + DOT);
|
||||
|
||||
/**
|
||||
* long to ip
|
||||
* @param ipLong the long number converted from IP
|
||||
* @return String
|
||||
*/
|
||||
public static String longToIp(long ipLong) {
|
||||
long[] ipNumbers = new long[4];
|
||||
long tmp = 0xFF;
|
||||
ipNumbers[0] = ipLong >> 24 & tmp;
|
||||
ipNumbers[1] = ipLong >> 16 & tmp;
|
||||
ipNumbers[2] = ipLong >> 8 & tmp;
|
||||
ipNumbers[3] = ipLong & tmp;
|
||||
return Long.parseLong(ipSet[0]) << 24 | Long.parseLong(ipSet[1]) << 16 | Long.parseLong(ipSet[2]) << 8 | Long.parseLong(ipSet[3]);
|
||||
}
|
||||
|
||||
String sb = ipNumbers[0] + DOT +
|
||||
ipNumbers[1] + DOT +
|
||||
ipNumbers[2] + DOT +
|
||||
ipNumbers[3];
|
||||
return sb;
|
||||
}
|
||||
/**
|
||||
* long to ip
|
||||
*
|
||||
* @param ipLong the long number converted from IP
|
||||
* @return String
|
||||
*/
|
||||
public static String longToIp(long ipLong) {
|
||||
long[] ipNumbers = new long[4];
|
||||
long tmp = 0xFF;
|
||||
ipNumbers[0] = ipLong >> 24 & tmp;
|
||||
ipNumbers[1] = ipLong >> 16 & tmp;
|
||||
ipNumbers[2] = ipLong >> 8 & tmp;
|
||||
ipNumbers[3] = ipLong & tmp;
|
||||
|
||||
return ipNumbers[0] + DOT
|
||||
+ ipNumbers[1] + DOT
|
||||
+ ipNumbers[2] + DOT
|
||||
+ ipNumbers[3];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,25 +14,39 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
|
||||
import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.*;
|
||||
import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
|
||||
|
||||
/**
|
||||
* json utils
|
||||
|
|
@ -49,13 +63,12 @@ public class JSONUtils {
|
|||
.configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
|
||||
.configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
|
||||
.configure(REQUIRE_SETTERS_FOR_GETTERS, true)
|
||||
.setTimeZone(TimeZone.getDefault())
|
||||
;
|
||||
.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
private JSONUtils() {
|
||||
throw new UnsupportedOperationException("Construct JSONUtils");
|
||||
}
|
||||
|
||||
|
||||
public static ArrayNode createArrayNode() {
|
||||
return objectMapper.createArrayNode();
|
||||
}
|
||||
|
|
@ -94,9 +107,9 @@ public class JSONUtils {
|
|||
* the fields of the specified object are generics, just the object itself should not be a
|
||||
* generic type.
|
||||
*
|
||||
* @param json the string from which the object is to be deserialized
|
||||
* @param json the string from which the object is to be deserialized
|
||||
* @param clazz the class of T
|
||||
* @param <T> T
|
||||
* @param <T> T
|
||||
* @return an object of type T from the string
|
||||
* classOfT
|
||||
*/
|
||||
|
|
@ -116,9 +129,9 @@ public class JSONUtils {
|
|||
/**
|
||||
* json to list
|
||||
*
|
||||
* @param json json string
|
||||
* @param json json string
|
||||
* @param clazz class
|
||||
* @param <T> T
|
||||
* @param <T> T
|
||||
* @return list
|
||||
*/
|
||||
public static <T> List<T> toList(String json, Class<T> clazz) {
|
||||
|
|
@ -137,7 +150,6 @@ public class JSONUtils {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check json object valid
|
||||
*
|
||||
|
|
@ -160,13 +172,12 @@ public class JSONUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method for finding a JSON Object field with specified name in this
|
||||
* node or its child nodes, and returning value it has.
|
||||
* If no matching field is found in this node or its descendants, returns null.
|
||||
*
|
||||
* @param jsonNode json node
|
||||
* @param jsonNode json node
|
||||
* @param fieldName Name of field to look for
|
||||
* @return Value of first matching node found, if any; null if none
|
||||
*/
|
||||
|
|
@ -180,7 +191,6 @@ public class JSONUtils {
|
|||
return node.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* json to map
|
||||
* <p>
|
||||
|
|
@ -195,7 +205,8 @@ public class JSONUtils {
|
|||
}
|
||||
|
||||
try {
|
||||
return objectMapper.readValue(json, new TypeReference<Map<String, String>>() {});
|
||||
return objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("json to map exception!", e);
|
||||
}
|
||||
|
|
@ -206,11 +217,11 @@ public class JSONUtils {
|
|||
/**
|
||||
* json to map
|
||||
*
|
||||
* @param json json
|
||||
* @param json json
|
||||
* @param classK classK
|
||||
* @param classV classV
|
||||
* @param <K> K
|
||||
* @param <V> V
|
||||
* @param <K> K
|
||||
* @param <V> V
|
||||
* @return to map
|
||||
*/
|
||||
public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {
|
||||
|
|
@ -258,7 +269,6 @@ public class JSONUtils {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* json serializer
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,22 +14,28 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* logger utils
|
||||
* logger utils
|
||||
*/
|
||||
public class LoggerUtils {
|
||||
|
||||
private LoggerUtils() {
|
||||
throw new UnsupportedOperationException("Construct LoggerUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* rules for extracting application ID
|
||||
*/
|
||||
|
|
@ -53,29 +59,29 @@ public class LoggerUtils {
|
|||
/**
|
||||
* build job id
|
||||
*
|
||||
* @param affix Task Logger's prefix
|
||||
* @param processDefId process define id
|
||||
* @param affix Task Logger's prefix
|
||||
* @param processDefId process define id
|
||||
* @param processInstId process instance id
|
||||
* @param taskId task id
|
||||
* @param taskId task id
|
||||
* @return task id format
|
||||
*/
|
||||
public static String buildTaskId(String affix,
|
||||
int processDefId,
|
||||
int processInstId,
|
||||
int taskId){
|
||||
int processDefId,
|
||||
int processInstId,
|
||||
int taskId) {
|
||||
// - [taskAppId=TASK_79_4084_15210]
|
||||
return String.format(" - %s%s-%s-%s-%s]",TASK_APPID_LOG_FORMAT,affix,
|
||||
return String.format(" - %s%s-%s-%s-%s]", TASK_APPID_LOG_FORMAT, affix,
|
||||
processDefId,
|
||||
processInstId,
|
||||
taskId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* processing log
|
||||
* get yarn application id list
|
||||
* @param log log content
|
||||
* @param logger logger
|
||||
*
|
||||
* @param log log content
|
||||
* @param logger logger
|
||||
* @return app id list
|
||||
*/
|
||||
public static List<String> getAppIds(String log, Logger logger) {
|
||||
|
|
@ -87,7 +93,7 @@ public class LoggerUtils {
|
|||
// analyse logs to get all submit yarn application id
|
||||
while (matcher.find()) {
|
||||
String appId = matcher.group();
|
||||
if(!appIds.contains(appId)){
|
||||
if (!appIds.contains(appId)) {
|
||||
logger.info("find app id: {}", appId);
|
||||
appIds.add(appId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,27 +14,36 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.apache.dolphinscheduler.common.Constants.DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE;
|
||||
|
||||
/**
|
||||
* NetUtils
|
||||
*/
|
||||
public class NetUtils {
|
||||
|
||||
|
||||
private NetUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
throw new UnsupportedOperationException("Construct NetUtils");
|
||||
}
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(NetUtils.class);
|
||||
|
|
|
|||
|
|
@ -14,8 +14,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.shell.ShellExecutor;
|
||||
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -32,9 +38,6 @@ import java.util.Optional;
|
|||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.shell.ShellExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -45,431 +48,444 @@ import oshi.hardware.HardwareAbstractionLayer;
|
|||
|
||||
/**
|
||||
* os utils
|
||||
*
|
||||
*/
|
||||
public class OSUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OSUtils.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(OSUtils.class);
|
||||
|
||||
public static final ThreadLocal<Logger> taskLoggerThreadLocal = new ThreadLocal<>();
|
||||
public static final ThreadLocal<Logger> taskLoggerThreadLocal = new ThreadLocal<>();
|
||||
|
||||
private static final SystemInfo SI = new SystemInfo();
|
||||
public static final String TWO_DECIMAL = "0.00";
|
||||
private static final SystemInfo SI = new SystemInfo();
|
||||
public static final String TWO_DECIMAL = "0.00";
|
||||
|
||||
/**
|
||||
* return -1 when the function can not get hardware env info
|
||||
* e.g {@link OSUtils#loadAverage()} {@link OSUtils#cpuUsage()}
|
||||
*/
|
||||
public static final double NEGATIVE_ONE = -1;
|
||||
/**
|
||||
* return -1 when the function can not get hardware env info
|
||||
* e.g {@link OSUtils#loadAverage()} {@link OSUtils#cpuUsage()}
|
||||
*/
|
||||
public static final double NEGATIVE_ONE = -1;
|
||||
|
||||
private static HardwareAbstractionLayer hal = SI.getHardware();
|
||||
private static HardwareAbstractionLayer hal = SI.getHardware();
|
||||
|
||||
private OSUtils() {}
|
||||
|
||||
/**
|
||||
* Initialization regularization, solve the problem of pre-compilation performance,
|
||||
* avoid the thread safety problem of multi-thread operation
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile("\\s+");
|
||||
|
||||
|
||||
/**
|
||||
* get memory usage
|
||||
* Keep 2 decimal
|
||||
* @return percent %
|
||||
*/
|
||||
public static double memoryUsage() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double memoryUsage = (memory.getTotal() - memory.getAvailable() - memory.getSwapUsed()) * 0.1 / memory.getTotal() * 10;
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(memoryUsage));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get available physical memory size
|
||||
*
|
||||
* Keep 2 decimal
|
||||
* @return available Physical Memory Size, unit: G
|
||||
*/
|
||||
public static double availablePhysicalMemorySize() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double availablePhysicalMemorySize = (memory.getAvailable() + memory.getSwapUsed()) /1024.0/1024/1024;
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(availablePhysicalMemorySize));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get total physical memory size
|
||||
*
|
||||
* Keep 2 decimal
|
||||
* @return available Physical Memory Size, unit: G
|
||||
*/
|
||||
public static double totalMemorySize() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double availablePhysicalMemorySize = memory.getTotal() /1024.0/1024/1024;
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(availablePhysicalMemorySize));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* load average
|
||||
*
|
||||
* @return load average
|
||||
*/
|
||||
public static double loadAverage() {
|
||||
double loadAverage = hal.getProcessor().getSystemLoadAverage();
|
||||
if (Double.isNaN(loadAverage)) {
|
||||
return NEGATIVE_ONE;
|
||||
private OSUtils() {
|
||||
throw new UnsupportedOperationException("Construct OSUtils");
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(loadAverage));
|
||||
}
|
||||
/**
|
||||
* Initialization regularization, solve the problem of pre-compilation performance,
|
||||
* avoid the thread safety problem of multi-thread operation
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile("\\s+");
|
||||
|
||||
/**
|
||||
* get cpu usage
|
||||
*
|
||||
* @return cpu usage
|
||||
*/
|
||||
public static double cpuUsage() {
|
||||
CentralProcessor processor = hal.getProcessor();
|
||||
double cpuUsage = processor.getSystemCpuLoad();
|
||||
if (Double.isNaN(cpuUsage)) {
|
||||
return NEGATIVE_ONE;
|
||||
/**
|
||||
* get memory usage
|
||||
* Keep 2 decimal
|
||||
*
|
||||
* @return percent %
|
||||
*/
|
||||
public static double memoryUsage() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double memoryUsage = (memory.getTotal() - memory.getAvailable() - memory.getSwapUsed()) * 0.1 / memory.getTotal() * 10;
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(memoryUsage));
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(cpuUsage));
|
||||
}
|
||||
/**
|
||||
* get available physical memory size
|
||||
* <p>
|
||||
* Keep 2 decimal
|
||||
*
|
||||
* @return available Physical Memory Size, unit: G
|
||||
*/
|
||||
public static double availablePhysicalMemorySize() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double availablePhysicalMemorySize = (memory.getAvailable() + memory.getSwapUsed()) / 1024.0 / 1024 / 1024;
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(availablePhysicalMemorySize));
|
||||
|
||||
public static List<String> getUserList() {
|
||||
try {
|
||||
if (isMacOS()) {
|
||||
return getUserListFromMac();
|
||||
} else if (isWindows()) {
|
||||
return getUserListFromWindows();
|
||||
} else {
|
||||
return getUserListFromLinux();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
/**
|
||||
* get total physical memory size
|
||||
* <p>
|
||||
* Keep 2 decimal
|
||||
*
|
||||
* @return available Physical Memory Size, unit: G
|
||||
*/
|
||||
public static double totalMemorySize() {
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
double availablePhysicalMemorySize = memory.getTotal() / 1024.0 / 1024 / 1024;
|
||||
|
||||
/**
|
||||
* get user list from linux
|
||||
*
|
||||
* @return user list
|
||||
*/
|
||||
private static List<String> getUserListFromLinux() throws IOException {
|
||||
List<String> userList = new ArrayList<>();
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(availablePhysicalMemorySize));
|
||||
}
|
||||
|
||||
try (BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream("/etc/passwd")))) {
|
||||
String line;
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.contains(":")) {
|
||||
String[] userInfo = line.split(":");
|
||||
userList.add(userInfo[0]);
|
||||
/**
|
||||
* load average
|
||||
*
|
||||
* @return load average
|
||||
*/
|
||||
public static double loadAverage() {
|
||||
double loadAverage = hal.getProcessor().getSystemLoadAverage();
|
||||
if (Double.isNaN(loadAverage)) {
|
||||
return NEGATIVE_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(loadAverage));
|
||||
}
|
||||
|
||||
return userList;
|
||||
}
|
||||
|
||||
/**
|
||||
* get user list from mac
|
||||
* @return user list
|
||||
*/
|
||||
private static List<String> getUserListFromMac() throws IOException {
|
||||
String result = exeCmd("dscl . list /users");
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
return Arrays.asList(result.split( "\n"));
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* get user list from windows
|
||||
* @return user list
|
||||
* @throws IOException
|
||||
*/
|
||||
private static List<String> getUserListFromWindows() throws IOException {
|
||||
String result = exeCmd("net user");
|
||||
String[] lines = result.split("\n");
|
||||
|
||||
int startPos = 0;
|
||||
int endPos = lines.length - 2;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (lines[i].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
if (lines[i].charAt(0) == '-') {
|
||||
for (int j = 0; j < lines[i].length(); j++) {
|
||||
if (lines[i].charAt(i) == '-') {
|
||||
count++;
|
||||
}
|
||||
/**
|
||||
* get cpu usage
|
||||
*
|
||||
* @return cpu usage
|
||||
*/
|
||||
public static double cpuUsage() {
|
||||
CentralProcessor processor = hal.getProcessor();
|
||||
double cpuUsage = processor.getSystemCpuLoad();
|
||||
if (Double.isNaN(cpuUsage)) {
|
||||
return NEGATIVE_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == lines[i].length()) {
|
||||
startPos = i + 1;
|
||||
break;
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
|
||||
df.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return Double.parseDouble(df.format(cpuUsage));
|
||||
}
|
||||
|
||||
List<String> users = new ArrayList<>();
|
||||
while (startPos <= endPos) {
|
||||
users.addAll(Arrays.asList(PATTERN.split(lines[startPos])));
|
||||
startPos++;
|
||||
public static List<String> getUserList() {
|
||||
try {
|
||||
if (isMacOS()) {
|
||||
return getUserListFromMac();
|
||||
} else if (isWindows()) {
|
||||
return getUserListFromWindows();
|
||||
} else {
|
||||
return getUserListFromLinux();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
/**
|
||||
* get user list from linux
|
||||
*
|
||||
* @return user list
|
||||
*/
|
||||
private static List<String> getUserListFromLinux() throws IOException {
|
||||
List<String> userList = new ArrayList<>();
|
||||
|
||||
try (BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream("/etc/passwd")))) {
|
||||
String line;
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.contains(":")) {
|
||||
String[] userInfo = line.split(":");
|
||||
userList.add(userInfo[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return userList;
|
||||
}
|
||||
|
||||
/**
|
||||
* get user list from mac
|
||||
*
|
||||
* @return user list
|
||||
*/
|
||||
private static List<String> getUserListFromMac() throws IOException {
|
||||
String result = exeCmd("dscl . list /users");
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
return Arrays.asList(result.split("\n"));
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* get user list from windows
|
||||
*
|
||||
* @return user list
|
||||
*/
|
||||
private static List<String> getUserListFromWindows() throws IOException {
|
||||
String result = exeCmd("net user");
|
||||
String[] lines = result.split("\n");
|
||||
|
||||
int startPos = 0;
|
||||
int endPos = lines.length - 2;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (lines[i].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
if (lines[i].charAt(0) == '-') {
|
||||
for (int j = 0; j < lines[i].length(); j++) {
|
||||
if (lines[i].charAt(i) == '-') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == lines[i].length()) {
|
||||
startPos = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<String> users = new ArrayList<>();
|
||||
while (startPos <= endPos) {
|
||||
users.addAll(Arrays.asList(PATTERN.split(lines[startPos])));
|
||||
startPos++;
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* create user
|
||||
*
|
||||
* @param userName user name
|
||||
* @return true if creation was successful, otherwise false
|
||||
*/
|
||||
public static boolean createUser(String userName) {
|
||||
try {
|
||||
String userGroup = OSUtils.getGroup();
|
||||
if (StringUtils.isEmpty(userGroup)) {
|
||||
String errorLog = String.format("%s group does not exist for this operating system.", userGroup);
|
||||
LoggerUtils.logError(Optional.ofNullable(logger), errorLog);
|
||||
LoggerUtils.logError(Optional.ofNullable(taskLoggerThreadLocal.get()), errorLog);
|
||||
return false;
|
||||
}
|
||||
if (isMacOS()) {
|
||||
createMacUser(userName, userGroup);
|
||||
} else if (isWindows()) {
|
||||
createWindowsUser(userName, userGroup);
|
||||
} else {
|
||||
createLinuxUser(userName, userGroup);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LoggerUtils.logError(Optional.ofNullable(logger), e);
|
||||
LoggerUtils.logError(Optional.ofNullable(taskLoggerThreadLocal.get()), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* create user
|
||||
* @param userName user name
|
||||
* @return true if creation was successful, otherwise false
|
||||
*/
|
||||
public static boolean createUser(String userName) {
|
||||
try {
|
||||
String userGroup = OSUtils.getGroup();
|
||||
if (StringUtils.isEmpty(userGroup)) {
|
||||
String errorLog = String.format("%s group does not exist for this operating system.", userGroup);
|
||||
LoggerUtils.logError(Optional.ofNullable(logger), errorLog);
|
||||
LoggerUtils.logError(Optional.ofNullable(taskLoggerThreadLocal.get()), errorLog);
|
||||
return false;
|
||||
}
|
||||
if (isMacOS()) {
|
||||
createMacUser(userName, userGroup);
|
||||
} else if (isWindows()) {
|
||||
createWindowsUser(userName, userGroup);
|
||||
} else {
|
||||
createLinuxUser(userName, userGroup);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LoggerUtils.logError(Optional.ofNullable(logger), e);
|
||||
LoggerUtils.logError(Optional.ofNullable(taskLoggerThreadLocal.get()), e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* create linux user
|
||||
*
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createLinuxUser(String userName, String userGroup) throws IOException {
|
||||
String infoLog1 = String.format("create linux os user : %s", userName);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog1);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog1);
|
||||
|
||||
/**
|
||||
* create linux user
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createLinuxUser(String userName, String userGroup) throws IOException {
|
||||
String infoLog1 = String.format("create linux os user : %s", userName);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog1);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog1);
|
||||
|
||||
String cmd = String.format("sudo useradd -g %s %s", userGroup, userName);
|
||||
String infoLog2 = String.format("execute cmd : %s", cmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog2);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog2);
|
||||
OSUtils.exeCmd(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* create mac user (Supports Mac OSX 10.10+)
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createMacUser(String userName, String userGroup) throws IOException {
|
||||
|
||||
Optional<Logger> optionalLogger = Optional.ofNullable(logger);
|
||||
Optional<Logger> optionalTaskLogger = Optional.ofNullable(taskLoggerThreadLocal.get());
|
||||
|
||||
String infoLog1 = String.format("create mac os user : %s", userName);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog1);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog1);
|
||||
|
||||
String createUserCmd = String.format("sudo sysadminctl -addUser %s -password %s", userName, userName);
|
||||
String infoLog2 = String.format("create user command : %s", createUserCmd);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog2);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog2);
|
||||
OSUtils.exeCmd(createUserCmd);
|
||||
|
||||
String appendGroupCmd = String.format("sudo dseditgroup -o edit -a %s -t user %s", userName, userGroup);
|
||||
String infoLog3 = String.format("append user to group : %s", appendGroupCmd);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog3);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog3);
|
||||
OSUtils.exeCmd(appendGroupCmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* create windows user
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createWindowsUser(String userName, String userGroup) throws IOException {
|
||||
String infoLog1 = String.format("create windows os user : %s", userName);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog1);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog1);
|
||||
|
||||
String userCreateCmd = String.format("net user \"%s\" /add", userName);
|
||||
String infoLog2 = String.format("execute create user command : %s", userCreateCmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog2);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog2);
|
||||
OSUtils.exeCmd(userCreateCmd);
|
||||
|
||||
String appendGroupCmd = String.format("net localgroup \"%s\" \"%s\" /add", userGroup, userName);
|
||||
String infoLog3 = String.format("execute append user to group : %s", appendGroupCmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog3);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog3);
|
||||
OSUtils.exeCmd(appendGroupCmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* get system group information
|
||||
* @return system group info
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String getGroup() throws IOException {
|
||||
if (isWindows()) {
|
||||
String currentProcUserName = System.getProperty("user.name");
|
||||
String result = exeCmd(String.format("net user \"%s\"", currentProcUserName));
|
||||
String line = result.split("\n")[22];
|
||||
String group = PATTERN.split(line)[1];
|
||||
if (group.charAt(0) == '*') {
|
||||
return group.substring(1);
|
||||
} else {
|
||||
return group;
|
||||
}
|
||||
} else {
|
||||
String result = exeCmd("groups");
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
String[] groupInfo = result.split(" ");
|
||||
return groupInfo[0];
|
||||
}
|
||||
String cmd = String.format("sudo useradd -g %s %s", userGroup, userName);
|
||||
String infoLog2 = String.format("execute cmd : %s", cmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog2);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog2);
|
||||
OSUtils.exeCmd(cmd);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* create mac user (Supports Mac OSX 10.10+)
|
||||
*
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createMacUser(String userName, String userGroup) throws IOException {
|
||||
|
||||
/**
|
||||
* Execute the corresponding command of Linux or Windows
|
||||
*
|
||||
* @param command command
|
||||
* @return result of execute command
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String exeCmd(String command) throws IOException {
|
||||
StringTokenizer st = new StringTokenizer(command);
|
||||
String[] cmdArray = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
cmdArray[i] = st.nextToken();
|
||||
Optional<Logger> optionalLogger = Optional.ofNullable(logger);
|
||||
Optional<Logger> optionalTaskLogger = Optional.ofNullable(taskLoggerThreadLocal.get());
|
||||
|
||||
String infoLog1 = String.format("create mac os user : %s", userName);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog1);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog1);
|
||||
|
||||
String createUserCmd = String.format("sudo sysadminctl -addUser %s -password %s", userName, userName);
|
||||
String infoLog2 = String.format("create user command : %s", createUserCmd);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog2);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog2);
|
||||
OSUtils.exeCmd(createUserCmd);
|
||||
|
||||
String appendGroupCmd = String.format("sudo dseditgroup -o edit -a %s -t user %s", userName, userGroup);
|
||||
String infoLog3 = String.format("append user to group : %s", appendGroupCmd);
|
||||
LoggerUtils.logInfo(optionalLogger, infoLog3);
|
||||
LoggerUtils.logInfo(optionalTaskLogger, infoLog3);
|
||||
OSUtils.exeCmd(appendGroupCmd);
|
||||
}
|
||||
return exeShell(cmdArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the shell
|
||||
* @param command command
|
||||
* @return result of execute the shell
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String exeShell(String[] command) throws IOException {
|
||||
return ShellExecutor.execCommand(command);
|
||||
}
|
||||
/**
|
||||
* create windows user
|
||||
*
|
||||
* @param userName user name
|
||||
* @param userGroup user group
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
private static void createWindowsUser(String userName, String userGroup) throws IOException {
|
||||
String infoLog1 = String.format("create windows os user : %s", userName);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog1);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog1);
|
||||
|
||||
/**
|
||||
* get process id
|
||||
* @return process id
|
||||
*/
|
||||
public static int getProcessID() {
|
||||
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
|
||||
return Integer.parseInt(runtimeMXBean.getName().split("@")[0]);
|
||||
}
|
||||
String userCreateCmd = String.format("net user \"%s\" /add", userName);
|
||||
String infoLog2 = String.format("execute create user command : %s", userCreateCmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog2);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog2);
|
||||
OSUtils.exeCmd(userCreateCmd);
|
||||
|
||||
/**
|
||||
* whether is macOS
|
||||
* @return true if mac
|
||||
*/
|
||||
public static boolean isMacOS() {
|
||||
return getOSName().startsWith("Mac");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* whether is windows
|
||||
* @return true if windows
|
||||
*/
|
||||
public static boolean isWindows() {
|
||||
return getOSName().startsWith("Windows");
|
||||
}
|
||||
|
||||
/**
|
||||
* get current OS name
|
||||
* @return current OS name
|
||||
*/
|
||||
public static String getOSName() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
|
||||
/**
|
||||
* check memory and cpu usage
|
||||
* @param systemCpuLoad systemCpuLoad
|
||||
* @param systemReservedMemory systemReservedMemory
|
||||
* @return check memory and cpu usage
|
||||
*/
|
||||
public static Boolean checkResource(double systemCpuLoad, double systemReservedMemory){
|
||||
// system load average
|
||||
double loadAverage = OSUtils.loadAverage();
|
||||
// system available physical memory
|
||||
double availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize();
|
||||
|
||||
if(loadAverage > systemCpuLoad || availablePhysicalMemorySize < systemReservedMemory){
|
||||
logger.warn("load is too high or availablePhysicalMemorySize(G) is too low, it's availablePhysicalMemorySize(G):{},loadAvg:{}", availablePhysicalMemorySize , loadAverage);
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
String appendGroupCmd = String.format("net localgroup \"%s\" \"%s\" /add", userGroup, userName);
|
||||
String infoLog3 = String.format("execute append user to group : %s", appendGroupCmd);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(logger), infoLog3);
|
||||
LoggerUtils.logInfo(Optional.ofNullable(taskLoggerThreadLocal.get()), infoLog3);
|
||||
OSUtils.exeCmd(appendGroupCmd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check memory and cpu usage
|
||||
* @param conf conf
|
||||
* @param isMaster is master
|
||||
* @return check memory and cpu usage
|
||||
*/
|
||||
public static Boolean checkResource(Configuration conf, Boolean isMaster){
|
||||
double systemCpuLoad;
|
||||
double systemReservedMemory;
|
||||
/**
|
||||
* get system group information
|
||||
*
|
||||
* @return system group info
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String getGroup() throws IOException {
|
||||
if (isWindows()) {
|
||||
String currentProcUserName = System.getProperty("user.name");
|
||||
String result = exeCmd(String.format("net user \"%s\"", currentProcUserName));
|
||||
String line = result.split("\n")[22];
|
||||
String group = PATTERN.split(line)[1];
|
||||
if (group.charAt(0) == '*') {
|
||||
return group.substring(1);
|
||||
} else {
|
||||
return group;
|
||||
}
|
||||
} else {
|
||||
String result = exeCmd("groups");
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
String[] groupInfo = result.split(" ");
|
||||
return groupInfo[0];
|
||||
}
|
||||
}
|
||||
|
||||
if(Boolean.TRUE.equals(isMaster)){
|
||||
systemCpuLoad = conf.getDouble(Constants.MASTER_MAX_CPULOAD_AVG, Constants.DEFAULT_MASTER_CPU_LOAD);
|
||||
systemReservedMemory = conf.getDouble(Constants.MASTER_RESERVED_MEMORY, Constants.DEFAULT_MASTER_RESERVED_MEMORY);
|
||||
}else{
|
||||
systemCpuLoad = conf.getDouble(Constants.WORKER_MAX_CPULOAD_AVG, Constants.DEFAULT_WORKER_CPU_LOAD);
|
||||
systemReservedMemory = conf.getDouble(Constants.WORKER_RESERVED_MEMORY, Constants.DEFAULT_WORKER_RESERVED_MEMORY);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the corresponding command of Linux or Windows
|
||||
*
|
||||
* @param command command
|
||||
* @return result of execute command
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String exeCmd(String command) throws IOException {
|
||||
StringTokenizer st = new StringTokenizer(command);
|
||||
String[] cmdArray = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
cmdArray[i] = st.nextToken();
|
||||
}
|
||||
return exeShell(cmdArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the shell
|
||||
*
|
||||
* @param command command
|
||||
* @return result of execute the shell
|
||||
* @throws IOException errors
|
||||
*/
|
||||
public static String exeShell(String[] command) throws IOException {
|
||||
return ShellExecutor.execCommand(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* get process id
|
||||
*
|
||||
* @return process id
|
||||
*/
|
||||
public static int getProcessID() {
|
||||
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
|
||||
return Integer.parseInt(runtimeMXBean.getName().split("@")[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* whether is macOS
|
||||
*
|
||||
* @return true if mac
|
||||
*/
|
||||
public static boolean isMacOS() {
|
||||
return getOSName().startsWith("Mac");
|
||||
}
|
||||
|
||||
/**
|
||||
* whether is windows
|
||||
*
|
||||
* @return true if windows
|
||||
*/
|
||||
public static boolean isWindows() {
|
||||
return getOSName().startsWith("Windows");
|
||||
}
|
||||
|
||||
/**
|
||||
* get current OS name
|
||||
*
|
||||
* @return current OS name
|
||||
*/
|
||||
public static String getOSName() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
|
||||
/**
|
||||
* check memory and cpu usage
|
||||
*
|
||||
* @param systemCpuLoad systemCpuLoad
|
||||
* @param systemReservedMemory systemReservedMemory
|
||||
* @return check memory and cpu usage
|
||||
*/
|
||||
public static Boolean checkResource(double systemCpuLoad, double systemReservedMemory) {
|
||||
// system load average
|
||||
double loadAverage = OSUtils.loadAverage();
|
||||
// system available physical memory
|
||||
double availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize();
|
||||
|
||||
if (loadAverage > systemCpuLoad || availablePhysicalMemorySize < systemReservedMemory) {
|
||||
logger.warn("load is too high or availablePhysicalMemorySize(G) is too low, it's availablePhysicalMemorySize(G):{},loadAvg:{}", availablePhysicalMemorySize, loadAverage);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check memory and cpu usage
|
||||
*
|
||||
* @param conf conf
|
||||
* @param isMaster is master
|
||||
* @return check memory and cpu usage
|
||||
*/
|
||||
public static Boolean checkResource(Configuration conf, Boolean isMaster) {
|
||||
double systemCpuLoad;
|
||||
double systemReservedMemory;
|
||||
|
||||
if (Boolean.TRUE.equals(isMaster)) {
|
||||
systemCpuLoad = conf.getDouble(Constants.MASTER_MAX_CPULOAD_AVG, Constants.DEFAULT_MASTER_CPU_LOAD);
|
||||
systemReservedMemory = conf.getDouble(Constants.MASTER_RESERVED_MEMORY, Constants.DEFAULT_MASTER_RESERVED_MEMORY);
|
||||
} else {
|
||||
systemCpuLoad = conf.getDouble(Constants.WORKER_MAX_CPULOAD_AVG, Constants.DEFAULT_WORKER_CPU_LOAD);
|
||||
systemReservedMemory = conf.getDouble(Constants.WORKER_RESERVED_MEMORY, Constants.DEFAULT_WORKER_RESERVED_MEMORY);
|
||||
}
|
||||
return checkResource(systemCpuLoad, systemReservedMemory);
|
||||
}
|
||||
return checkResource(systemCpuLoad,systemReservedMemory);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.CommandType;
|
||||
import org.apache.dolphinscheduler.common.enums.DataType;
|
||||
|
|
@ -25,231 +24,228 @@ import org.apache.dolphinscheduler.common.process.Property;
|
|||
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.placeholder.PlaceholderUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.placeholder.TimePlaceholderUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* parameter parse utils
|
||||
*/
|
||||
public class ParameterUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ParameterUtils.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ParameterUtils.class);
|
||||
|
||||
/**
|
||||
* convert parameters place holders
|
||||
*
|
||||
* @param parameterString parameter
|
||||
* @param parameterMap parameter map
|
||||
* @return convert parameters place holders
|
||||
*/
|
||||
public static String convertParameterPlaceholders(String parameterString, Map<String, String> parameterMap) {
|
||||
if (StringUtils.isEmpty(parameterString) || parameterMap == null) {
|
||||
return parameterString;
|
||||
private ParameterUtils() {
|
||||
throw new UnsupportedOperationException("Construct ParameterUtils");
|
||||
}
|
||||
|
||||
//Get current time, schedule execute time
|
||||
String cronTimeStr = parameterMap.get(Constants.PARAMETER_DATETIME);
|
||||
/**
|
||||
* convert parameters place holders
|
||||
*
|
||||
* @param parameterString parameter
|
||||
* @param parameterMap parameter map
|
||||
* @return convert parameters place holders
|
||||
*/
|
||||
public static String convertParameterPlaceholders(String parameterString, Map<String, String> parameterMap) {
|
||||
if (StringUtils.isEmpty(parameterString) || parameterMap == null) {
|
||||
return parameterString;
|
||||
}
|
||||
|
||||
Date cronTime = null;
|
||||
//Get current time, schedule execute time
|
||||
String cronTimeStr = parameterMap.get(Constants.PARAMETER_DATETIME);
|
||||
|
||||
if (StringUtils.isNotEmpty(cronTimeStr)) {
|
||||
try {
|
||||
cronTime = DateUtils.parseDate(cronTimeStr, new String[]{Constants.PARAMETER_FORMAT_TIME});
|
||||
} catch (ParseException e) {
|
||||
logger.error("parse {} exception", cronTimeStr, e);
|
||||
}
|
||||
} else {
|
||||
cronTime = new Date();
|
||||
Date cronTime = null;
|
||||
|
||||
if (StringUtils.isNotEmpty(cronTimeStr)) {
|
||||
cronTime = DateUtils.parse(cronTimeStr, Constants.PARAMETER_FORMAT_TIME);
|
||||
} else {
|
||||
cronTime = new Date();
|
||||
}
|
||||
|
||||
// replace variable ${} form,refers to the replacement of system variables and custom variables
|
||||
parameterString = PlaceholderUtils.replacePlaceholders(parameterString, parameterMap, true);
|
||||
|
||||
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||
if (cronTime != null) {
|
||||
parameterString = TimePlaceholderUtils.replacePlaceholders(parameterString, cronTime, true);
|
||||
}
|
||||
|
||||
return parameterString;
|
||||
}
|
||||
|
||||
// replace variable ${} form,refers to the replacement of system variables and custom variables
|
||||
parameterString = PlaceholderUtils.replacePlaceholders(parameterString, parameterMap, true);
|
||||
/**
|
||||
* new
|
||||
* convert parameters place holders
|
||||
*
|
||||
* @param parameterString parameter
|
||||
* @param parameterMap parameter map
|
||||
* @return convert parameters place holders
|
||||
*/
|
||||
public static String convertParameterPlaceholders2(String parameterString, Map<String, String> parameterMap) {
|
||||
if (StringUtils.isEmpty(parameterString)) {
|
||||
return parameterString;
|
||||
}
|
||||
//Get current time, schedule execute time
|
||||
String cronTimeStr = parameterMap.get(Constants.PARAMETER_SHECDULE_TIME);
|
||||
Date cronTime = null;
|
||||
|
||||
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||
if (cronTime != null) {
|
||||
parameterString = TimePlaceholderUtils.replacePlaceholders(parameterString, cronTime, true);
|
||||
if (StringUtils.isNotEmpty(cronTimeStr)) {
|
||||
cronTime = DateUtils.parse(cronTimeStr, Constants.PARAMETER_FORMAT_TIME);
|
||||
|
||||
} else {
|
||||
cronTime = new Date();
|
||||
}
|
||||
|
||||
// replace variable ${} form,refers to the replacement of system variables and custom variables
|
||||
parameterString = PlaceholderUtils.replacePlaceholders(parameterString, parameterMap, true);
|
||||
|
||||
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||
if (cronTime != null) {
|
||||
parameterString = TimePlaceholderUtils.replacePlaceholders(parameterString, cronTime, true);
|
||||
|
||||
}
|
||||
return parameterString;
|
||||
}
|
||||
|
||||
return parameterString;
|
||||
}
|
||||
|
||||
/**
|
||||
* new
|
||||
* convert parameters place holders
|
||||
*
|
||||
* @param parameterString parameter
|
||||
* @param parameterMap parameter map
|
||||
* @return convert parameters place holders
|
||||
*/
|
||||
public static String convertParameterPlaceholders2(String parameterString, Map<String, String> parameterMap) {
|
||||
if (StringUtils.isEmpty(parameterString)) {
|
||||
return parameterString;
|
||||
}
|
||||
//Get current time, schedule execute time
|
||||
String cronTimeStr = parameterMap.get(Constants.PARAMETER_SHECDULE_TIME);
|
||||
Date cronTime = null;
|
||||
|
||||
if (StringUtils.isNotEmpty(cronTimeStr)) {
|
||||
try {
|
||||
cronTime = DateUtils.parseDate(cronTimeStr, new String[]{Constants.PARAMETER_FORMAT_TIME});
|
||||
|
||||
} catch (ParseException e) {
|
||||
logger.error(String.format("parse %s exception", cronTimeStr), e);
|
||||
}
|
||||
} else {
|
||||
cronTime = new Date();
|
||||
/**
|
||||
* set in parameter
|
||||
*
|
||||
* @param index index
|
||||
* @param stmt preparedstatement
|
||||
* @param dataType data type
|
||||
* @param value value
|
||||
* @throws Exception errors
|
||||
*/
|
||||
public static void setInParameter(int index, PreparedStatement stmt, DataType dataType, String value) throws Exception {
|
||||
if (dataType.equals(DataType.VARCHAR)) {
|
||||
stmt.setString(index, value);
|
||||
} else if (dataType.equals(DataType.INTEGER)) {
|
||||
stmt.setInt(index, Integer.parseInt(value));
|
||||
} else if (dataType.equals(DataType.LONG)) {
|
||||
stmt.setLong(index, Long.parseLong(value));
|
||||
} else if (dataType.equals(DataType.FLOAT)) {
|
||||
stmt.setFloat(index, Float.parseFloat(value));
|
||||
} else if (dataType.equals(DataType.DOUBLE)) {
|
||||
stmt.setDouble(index, Double.parseDouble(value));
|
||||
} else if (dataType.equals(DataType.DATE)) {
|
||||
stmt.setDate(index, java.sql.Date.valueOf(value));
|
||||
} else if (dataType.equals(DataType.TIME)) {
|
||||
stmt.setString(index, value);
|
||||
} else if (dataType.equals(DataType.TIMESTAMP)) {
|
||||
stmt.setTimestamp(index, java.sql.Timestamp.valueOf(value));
|
||||
} else if (dataType.equals(DataType.BOOLEAN)) {
|
||||
stmt.setBoolean(index, Boolean.parseBoolean(value));
|
||||
}
|
||||
}
|
||||
|
||||
// replace variable ${} form,refers to the replacement of system variables and custom variables
|
||||
parameterString = PlaceholderUtils.replacePlaceholders(parameterString, parameterMap, true);
|
||||
/**
|
||||
* curing user define parameters
|
||||
*
|
||||
* @param globalParamMap global param map
|
||||
* @param globalParamList global param list
|
||||
* @param commandType command type
|
||||
* @param scheduleTime schedule time
|
||||
* @return curing user define parameters
|
||||
*/
|
||||
public static String curingGlobalParams(Map<String, String> globalParamMap, List<Property> globalParamList,
|
||||
CommandType commandType, Date scheduleTime) {
|
||||
|
||||
// replace time $[...] form, eg. $[yyyyMMdd]
|
||||
if (cronTime != null) {
|
||||
parameterString = TimePlaceholderUtils.replacePlaceholders(parameterString, cronTime, true);
|
||||
if (globalParamList == null || globalParamList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
return parameterString;
|
||||
}
|
||||
Map<String, String> globalMap = new HashMap<>();
|
||||
if (globalParamMap != null) {
|
||||
globalMap.putAll(globalParamMap);
|
||||
}
|
||||
Map<String, String> allParamMap = new HashMap<>();
|
||||
//If it is a complement, a complement time needs to be passed in, according to the task type
|
||||
Map<String, String> timeParams = BusinessTimeUtils
|
||||
.getBusinessTime(commandType, scheduleTime);
|
||||
|
||||
if (timeParams != null) {
|
||||
allParamMap.putAll(timeParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* set in parameter
|
||||
* @param index index
|
||||
* @param stmt preparedstatement
|
||||
* @param dataType data type
|
||||
* @param value value
|
||||
* @throws Exception errors
|
||||
*/
|
||||
public static void setInParameter(int index, PreparedStatement stmt, DataType dataType, String value)throws Exception{
|
||||
if (dataType.equals(DataType.VARCHAR)){
|
||||
stmt.setString(index,value);
|
||||
}else if (dataType.equals(DataType.INTEGER)){
|
||||
stmt.setInt(index, Integer.parseInt(value));
|
||||
}else if (dataType.equals(DataType.LONG)){
|
||||
stmt.setLong(index, Long.parseLong(value));
|
||||
}else if (dataType.equals(DataType.FLOAT)){
|
||||
stmt.setFloat(index, Float.parseFloat(value));
|
||||
}else if (dataType.equals(DataType.DOUBLE)){
|
||||
stmt.setDouble(index, Double.parseDouble(value));
|
||||
}else if (dataType.equals(DataType.DATE)){
|
||||
stmt.setDate(index, java.sql.Date.valueOf(value));
|
||||
}else if (dataType.equals(DataType.TIME)){
|
||||
stmt.setString(index, value);
|
||||
}else if (dataType.equals(DataType.TIMESTAMP)){
|
||||
stmt.setTimestamp(index, java.sql.Timestamp.valueOf(value));
|
||||
}else if (dataType.equals(DataType.BOOLEAN)){
|
||||
stmt.setBoolean(index,Boolean.parseBoolean(value));
|
||||
}
|
||||
}
|
||||
allParamMap.putAll(globalMap);
|
||||
|
||||
/**
|
||||
* curing user define parameters
|
||||
*
|
||||
* @param globalParamMap global param map
|
||||
* @param globalParamList global param list
|
||||
* @param commandType command type
|
||||
* @param scheduleTime schedule time
|
||||
* @return curing user define parameters
|
||||
*/
|
||||
public static String curingGlobalParams(Map<String,String> globalParamMap, List<Property> globalParamList,
|
||||
CommandType commandType, Date scheduleTime){
|
||||
Set<Map.Entry<String, String>> entries = allParamMap.entrySet();
|
||||
|
||||
if (globalParamList == null || globalParamList.isEmpty()) {
|
||||
return null;
|
||||
Map<String, String> resolveMap = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : entries) {
|
||||
String val = entry.getValue();
|
||||
if (val.startsWith("$")) {
|
||||
String str = ParameterUtils.convertParameterPlaceholders(val, allParamMap);
|
||||
resolveMap.put(entry.getKey(), str);
|
||||
}
|
||||
}
|
||||
globalMap.putAll(resolveMap);
|
||||
|
||||
for (Property property : globalParamList) {
|
||||
String val = globalMap.get(property.getProp());
|
||||
if (val != null) {
|
||||
property.setValue(val);
|
||||
}
|
||||
}
|
||||
return JSONUtils.toJsonString(globalParamList);
|
||||
}
|
||||
|
||||
Map<String, String> globalMap = new HashMap<>();
|
||||
if (globalParamMap!= null){
|
||||
globalMap.putAll(globalParamMap);
|
||||
}
|
||||
Map<String,String> allParamMap = new HashMap<>();
|
||||
//If it is a complement, a complement time needs to be passed in, according to the task type
|
||||
Map<String,String> timeParams = BusinessTimeUtils
|
||||
.getBusinessTime(commandType, scheduleTime);
|
||||
/**
|
||||
* handle escapes
|
||||
*
|
||||
* @param inputString input string
|
||||
* @return string filter escapes
|
||||
*/
|
||||
public static String handleEscapes(String inputString) {
|
||||
|
||||
if (timeParams != null) {
|
||||
allParamMap.putAll(timeParams);
|
||||
if (StringUtils.isNotEmpty(inputString)) {
|
||||
return inputString.replace("%", "////%").replaceAll("[\n|\r\t]", "_");
|
||||
}
|
||||
return inputString;
|
||||
}
|
||||
|
||||
allParamMap.putAll(globalMap);
|
||||
/**
|
||||
* $[yyyyMMdd] replace schedule time
|
||||
*/
|
||||
public static String replaceScheduleTime(String text, Date scheduleTime) {
|
||||
Map<String, Property> paramsMap = new HashMap<>();
|
||||
//if getScheduleTime null ,is current date
|
||||
if (null == scheduleTime) {
|
||||
scheduleTime = new Date();
|
||||
}
|
||||
|
||||
Set<Map.Entry<String, String>> entries = allParamMap.entrySet();
|
||||
String dateTime = org.apache.dolphinscheduler.common.utils.DateUtils.format(scheduleTime, Constants.PARAMETER_FORMAT_TIME);
|
||||
Property p = new Property();
|
||||
p.setValue(dateTime);
|
||||
p.setProp(Constants.PARAMETER_SHECDULE_TIME);
|
||||
paramsMap.put(Constants.PARAMETER_SHECDULE_TIME, p);
|
||||
text = ParameterUtils.convertParameterPlaceholders2(text, convert(paramsMap));
|
||||
|
||||
Map<String,String> resolveMap = new HashMap<>();
|
||||
for (Map.Entry<String,String> entry : entries){
|
||||
String val = entry.getValue();
|
||||
if (val.startsWith("$")){
|
||||
String str = ParameterUtils.convertParameterPlaceholders(val, allParamMap);
|
||||
resolveMap.put(entry.getKey(),str);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
globalMap.putAll(resolveMap);
|
||||
|
||||
for (Property property : globalParamList){
|
||||
String val = globalMap.get(property.getProp());
|
||||
if (val != null){
|
||||
property.setValue(val);
|
||||
}
|
||||
/**
|
||||
* format convert
|
||||
*
|
||||
* @param paramsMap params map
|
||||
* @return Map of converted
|
||||
* see org.apache.dolphinscheduler.server.utils.ParamUtils.convert
|
||||
*/
|
||||
public static Map<String, String> convert(Map<String, Property> paramsMap) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Iterator<Map.Entry<String, Property>> iter = paramsMap.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, Property> en = iter.next();
|
||||
map.put(en.getKey(), en.getValue().getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return JSONUtils.toJsonString(globalParamList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle escapes
|
||||
* @param inputString input string
|
||||
* @return string filter escapes
|
||||
*/
|
||||
public static String handleEscapes(String inputString){
|
||||
|
||||
if(StringUtils.isNotEmpty(inputString)){
|
||||
return inputString.replace("%", "////%").replaceAll("[\n|\r\t]", "_");
|
||||
}
|
||||
return inputString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* $[yyyyMMdd] replace schedule time
|
||||
* @param text
|
||||
* @param scheduleTime
|
||||
* @return
|
||||
*/
|
||||
public static String replaceScheduleTime(String text, Date scheduleTime) {
|
||||
Map<String, Property> paramsMap = new HashMap<>();
|
||||
//if getScheduleTime null ,is current date
|
||||
if (null == scheduleTime) {
|
||||
scheduleTime = new Date();
|
||||
}
|
||||
|
||||
String dateTime = org.apache.dolphinscheduler.common.utils.DateUtils.format(scheduleTime, Constants.PARAMETER_FORMAT_TIME);
|
||||
Property p = new Property();
|
||||
p.setValue(dateTime);
|
||||
p.setProp(Constants.PARAMETER_SHECDULE_TIME);
|
||||
paramsMap.put(Constants.PARAMETER_SHECDULE_TIME, p);
|
||||
text = ParameterUtils.convertParameterPlaceholders2(text, convert(paramsMap));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* format convert
|
||||
* @param paramsMap params map
|
||||
* @return Map of converted
|
||||
* see org.apache.dolphinscheduler.server.utils.ParamUtils.convert
|
||||
*/
|
||||
public static Map<String,String> convert(Map<String,Property> paramsMap){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
Iterator<Map.Entry<String, Property>> iter = paramsMap.entrySet().iterator();
|
||||
while (iter.hasNext()){
|
||||
Map.Entry<String, Property> en = iter.next();
|
||||
map.put(en.getKey(),en.getValue().getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,16 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
|
||||
/**
|
||||
* utility methods for validating input
|
||||
*
|
||||
* utility methods for validating input
|
||||
*/
|
||||
public final class Preconditions {
|
||||
|
||||
private Preconditions() {}
|
||||
private Preconditions() {
|
||||
throw new UnsupportedOperationException("Construct Preconditions");
|
||||
}
|
||||
|
||||
/**
|
||||
* if obj is null will throw NPE
|
||||
|
|
@ -41,32 +42,30 @@ public final class Preconditions {
|
|||
|
||||
/**
|
||||
* if obj is null will throw NullPointerException with error message
|
||||
*
|
||||
* @param obj obj
|
||||
* @param errorMsg error message
|
||||
* @param <T> T
|
||||
* @return T
|
||||
*/
|
||||
public static <T> T checkNotNull(T obj, String errorMsg) {
|
||||
public static <T> T checkNotNull(T obj, String errorMsg) {
|
||||
if (obj == null) {
|
||||
throw new NullPointerException(errorMsg);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* if condition is false will throw an IllegalArgumentException with the given message
|
||||
*
|
||||
* @param condition condition
|
||||
* @param errorMsg error message
|
||||
*
|
||||
* @param errorMsg error message
|
||||
* @throws IllegalArgumentException Thrown, if the condition is violated.
|
||||
*/
|
||||
public static void checkArgument(boolean condition, Object errorMsg) {
|
||||
public static void checkArgument(boolean condition, Object errorMsg) {
|
||||
if (!condition) {
|
||||
throw new IllegalArgumentException(String.valueOf(errorMsg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.COMMON_PROPERTIES_PATH;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ResUploadType;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -28,7 +30,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.COMMON_PROPERTIES_PATH;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* property utils
|
||||
|
|
@ -44,7 +47,7 @@ public class PropertyUtils {
|
|||
private static final Properties properties = new Properties();
|
||||
|
||||
private PropertyUtils() {
|
||||
throw new IllegalStateException("PropertyUtils class");
|
||||
throw new UnsupportedOperationException("Construct PropertyUtils");
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
@ -68,10 +71,9 @@ public class PropertyUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return judge whether resource upload startup
|
||||
* @return judge whether resource upload startup
|
||||
*/
|
||||
public static Boolean getResUploadStartupState(){
|
||||
public static Boolean getResUploadStartupState() {
|
||||
String resUploadStartupType = PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE);
|
||||
ResUploadType resUploadType = ResUploadType.valueOf(resUploadStartupType);
|
||||
return resUploadType == ResUploadType.HDFS || resUploadType == ResUploadType.S3;
|
||||
|
|
@ -113,14 +115,13 @@ public class PropertyUtils {
|
|||
* get property value
|
||||
*
|
||||
* @param key property name
|
||||
* @return get property int value , if key == null, then return -1
|
||||
* @return get property int value , if key == null, then return -1
|
||||
*/
|
||||
public static int getInt(String key) {
|
||||
return getInt(key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @return property value
|
||||
|
|
@ -134,7 +135,7 @@ public class PropertyUtils {
|
|||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.info(e.getMessage(),e);
|
||||
logger.info(e.getMessage(), e);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
|
@ -147,7 +148,7 @@ public class PropertyUtils {
|
|||
*/
|
||||
public static boolean getBoolean(String key) {
|
||||
String value = properties.getProperty(key.trim());
|
||||
if(null != value){
|
||||
if (null != value) {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +164,7 @@ public class PropertyUtils {
|
|||
*/
|
||||
public static Boolean getBoolean(String key, boolean defaultValue) {
|
||||
String value = properties.getProperty(key.trim());
|
||||
if(null != value){
|
||||
if (null != value) {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +173,7 @@ public class PropertyUtils {
|
|||
|
||||
/**
|
||||
* get property long value
|
||||
*
|
||||
* @param key key
|
||||
* @param defaultVal default value
|
||||
* @return property value
|
||||
|
|
@ -182,16 +184,14 @@ public class PropertyUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key key
|
||||
* @return property value
|
||||
*/
|
||||
public static long getLong(String key) {
|
||||
return getLong(key,-1);
|
||||
return getLong(key, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key key
|
||||
* @param defaultVal default value
|
||||
* @return property value
|
||||
|
|
@ -201,11 +201,11 @@ public class PropertyUtils {
|
|||
return val == null ? defaultVal : Double.parseDouble(val);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get array
|
||||
* @param key property name
|
||||
* @param splitStr separator
|
||||
* get array
|
||||
*
|
||||
* @param key property name
|
||||
* @param splitStr separator
|
||||
* @return property value through array
|
||||
*/
|
||||
public static String[] getArray(String key, String splitStr) {
|
||||
|
|
@ -217,18 +217,17 @@ public class PropertyUtils {
|
|||
String[] propertyArray = value.split(splitStr);
|
||||
return propertyArray;
|
||||
} catch (NumberFormatException e) {
|
||||
logger.info(e.getMessage(),e);
|
||||
logger.info(e.getMessage(), e);
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key key
|
||||
* @param type type
|
||||
* @param defaultValue default value
|
||||
* @param <T> T
|
||||
* @return get enum value
|
||||
* @return get enum value
|
||||
*/
|
||||
public <T extends Enum<T>> T getEnum(String key, Class<T> type,
|
||||
T defaultValue) {
|
||||
|
|
@ -238,6 +237,7 @@ public class PropertyUtils {
|
|||
|
||||
/**
|
||||
* get all properties with specified prefix, like: fs.
|
||||
*
|
||||
* @param prefix prefix to search
|
||||
* @return all properties with specified prefix
|
||||
*/
|
||||
|
|
@ -253,11 +253,9 @@ public class PropertyUtils {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void setValue(String key, String value) {
|
||||
properties.setProperty(key,value);
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,21 @@
|
|||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import com.github.rholder.retry.*;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.github.rholder.retry.RetryException;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.RetryerBuilder;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
import com.github.rholder.retry.WaitStrategies;
|
||||
|
||||
/**
|
||||
* The Retryer util.
|
||||
*/
|
||||
|
|
@ -35,7 +41,7 @@ public class RetryerUtils {
|
|||
private static Retryer<Boolean> defaultRetryerResultNoCheck;
|
||||
|
||||
private RetryerUtils() {
|
||||
|
||||
throw new UnsupportedOperationException("Construct RetryerUtils");
|
||||
}
|
||||
|
||||
private static Retryer<Boolean> getDefaultRetryerResultNoCheck() {
|
||||
|
|
|
|||
|
|
@ -14,10 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -29,113 +27,123 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Metadata related common classes
|
||||
*
|
||||
*/
|
||||
public class SchemaUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchemaUtils.class);
|
||||
private static Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchemaUtils.class);
|
||||
private static Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
||||
|
||||
/**
|
||||
* Gets upgradable schemas for all upgrade directories
|
||||
* @return all schema list
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<String> getAllSchemaList() {
|
||||
List<String> schemaDirList = new ArrayList<>();
|
||||
File[] schemaDirArr = FileUtils.getAllDir("sql/upgrade");
|
||||
if(schemaDirArr == null || schemaDirArr.length == 0) {
|
||||
return null;
|
||||
}
|
||||
private SchemaUtils() {
|
||||
throw new UnsupportedOperationException("Construct SchemaUtils");
|
||||
}
|
||||
|
||||
for(File file : schemaDirArr) {
|
||||
schemaDirList.add(file.getName());
|
||||
}
|
||||
/**
|
||||
* Gets upgradable schemas for all upgrade directories
|
||||
*
|
||||
* @return all schema list
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<String> getAllSchemaList() {
|
||||
List<String> schemaDirList = new ArrayList<>();
|
||||
File[] schemaDirArr = FileUtils.getAllDir("sql/upgrade");
|
||||
if (schemaDirArr == null || schemaDirArr.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.sort(schemaDirList , new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1 , Object o2){
|
||||
try {
|
||||
String dir1 = String.valueOf(o1);
|
||||
String dir2 = String.valueOf(o2);
|
||||
String version1 = dir1.split("_")[0];
|
||||
String version2 = dir2.split("_")[0];
|
||||
if(version1.equals(version2)) {
|
||||
return 0;
|
||||
}
|
||||
for (File file : schemaDirArr) {
|
||||
schemaDirList.add(file.getName());
|
||||
}
|
||||
|
||||
if(SchemaUtils.isAGreatVersion(version1, version2)) {
|
||||
return 1;
|
||||
}
|
||||
Collections.sort(schemaDirList, new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
try {
|
||||
String dir1 = String.valueOf(o1);
|
||||
String dir2 = String.valueOf(o2);
|
||||
String version1 = dir1.split("_")[0];
|
||||
String version2 = dir2.split("_")[0];
|
||||
if (version1.equals(version2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
if (SchemaUtils.isAGreatVersion(version1, version2)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return -1;
|
||||
|
||||
return schemaDirList;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Determine whether schemaVersion is higher than version
|
||||
* @param schemaVersion schema version
|
||||
* @param version version
|
||||
* @return Determine whether schemaVersion is higher than version
|
||||
*/
|
||||
public static boolean isAGreatVersion(String schemaVersion, String version) {
|
||||
if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) {
|
||||
throw new RuntimeException("schemaVersion or version is empty");
|
||||
}
|
||||
return schemaDirList;
|
||||
}
|
||||
|
||||
String[] schemaVersionArr = schemaVersion.split("\\.");
|
||||
String[] versionArr = version.split("\\.");
|
||||
int arrLength = Math.min(schemaVersionArr.length, versionArr.length);
|
||||
for(int i = 0 ; i < arrLength ; i++) {
|
||||
if(Integer.parseInt(schemaVersionArr[i]) > Integer.parseInt(versionArr[i])) {
|
||||
return true;
|
||||
}else if(Integer.parseInt(schemaVersionArr[i]) < Integer.parseInt(versionArr[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determine whether schemaVersion is higher than version
|
||||
*
|
||||
* @param schemaVersion schema version
|
||||
* @param version version
|
||||
* @return Determine whether schemaVersion is higher than version
|
||||
*/
|
||||
public static boolean isAGreatVersion(String schemaVersion, String version) {
|
||||
if (StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) {
|
||||
throw new RuntimeException("schemaVersion or version is empty");
|
||||
}
|
||||
|
||||
// If the version and schema version is the same from 0 up to the arrlength-1 element,whoever has a larger arrLength has a larger version number
|
||||
return schemaVersionArr.length > versionArr.length;
|
||||
}
|
||||
String[] schemaVersionArr = schemaVersion.split("\\.");
|
||||
String[] versionArr = version.split("\\.");
|
||||
int arrLength = Math.min(schemaVersionArr.length, versionArr.length);
|
||||
for (int i = 0; i < arrLength; i++) {
|
||||
if (Integer.parseInt(schemaVersionArr[i]) > Integer.parseInt(versionArr[i])) {
|
||||
return true;
|
||||
} else if (Integer.parseInt(schemaVersionArr[i]) < Integer.parseInt(versionArr[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current software version number of the system
|
||||
* @return current software version
|
||||
*/
|
||||
public static String getSoftVersion() {
|
||||
String soft_version;
|
||||
try {
|
||||
soft_version = FileUtils.readFile2Str(new FileInputStream(new File("sql/soft_version")));
|
||||
soft_version = replaceBlank(soft_version);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
throw new RuntimeException("Failed to get the product version description file. The file could not be found", e);
|
||||
}
|
||||
return soft_version;
|
||||
}
|
||||
// If the version and schema version is the same from 0 up to the arrlength-1 element,whoever has a larger arrLength has a larger version number
|
||||
return schemaVersionArr.length > versionArr.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the string of space carriage returns and tabs
|
||||
* @param str string
|
||||
* @return string removed blank
|
||||
*/
|
||||
public static String replaceBlank(String str) {
|
||||
String dest = "";
|
||||
if (str!=null) {
|
||||
/**
|
||||
* Gets the current software version number of the system
|
||||
*
|
||||
* @return current software version
|
||||
*/
|
||||
public static String getSoftVersion() {
|
||||
String softVersion;
|
||||
try {
|
||||
softVersion = FileUtils.readFile2Str(new FileInputStream(new File("sql/soft_version")));
|
||||
softVersion = replaceBlank(softVersion);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
throw new RuntimeException("Failed to get the product version description file. The file could not be found", e);
|
||||
}
|
||||
return softVersion;
|
||||
}
|
||||
|
||||
Matcher m = p.matcher(str);
|
||||
dest = m.replaceAll("");
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
/**
|
||||
* Strips the string of space carriage returns and tabs
|
||||
*
|
||||
* @param str string
|
||||
* @return string removed blank
|
||||
*/
|
||||
public static String replaceBlank(String str) {
|
||||
String dest = "";
|
||||
if (str != null) {
|
||||
|
||||
Matcher m = p.matcher(str);
|
||||
dest = m.replaceAll("");
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,21 +14,25 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
|
||||
/**
|
||||
* sensitive log Util
|
||||
* sensitive log Util
|
||||
*/
|
||||
public class SensitiveLogUtils {
|
||||
|
||||
private SensitiveLogUtils() {
|
||||
throw new UnsupportedOperationException("Construct SensitiveLogUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataSourcePwd data source password
|
||||
* @return String
|
||||
*/
|
||||
public static String maskDataSourcePwd(String dataSourcePwd){
|
||||
public static String maskDataSourcePwd(String dataSourcePwd) {
|
||||
|
||||
if (StringUtils.isNotEmpty(dataSourcePwd)) {
|
||||
dataSourcePwd = Constants.PASSWORD_DEFAULT;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
|
@ -22,7 +23,9 @@ import java.util.stream.StreamSupport;
|
|||
|
||||
public class StreamUtils {
|
||||
|
||||
private StreamUtils() { }
|
||||
private StreamUtils() {
|
||||
throw new UnsupportedOperationException("Construct StreamUtils");
|
||||
}
|
||||
|
||||
public static <T> Stream<T> asStream(Iterator<T> sourceIterator) {
|
||||
return asStream(sourceIterator, false);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public static final String EMPTY = "";
|
||||
|
||||
private StringUtils() {
|
||||
throw new UnsupportedOperationException("Construct StringUtils");
|
||||
}
|
||||
|
||||
public static boolean isEmpty(final CharSequence cs) {
|
||||
return cs == null || cs.length() == 0;
|
||||
}
|
||||
|
|
@ -27,18 +33,18 @@ public class StringUtils {
|
|||
return !isEmpty(cs);
|
||||
}
|
||||
|
||||
public static boolean isBlank(String s){
|
||||
public static boolean isBlank(String s) {
|
||||
if (isEmpty(s)) {
|
||||
return true;
|
||||
}
|
||||
return s.trim().length() == 0;
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(String s){
|
||||
public static boolean isNotBlank(String s) {
|
||||
return !isBlank(s);
|
||||
}
|
||||
|
||||
public static String replaceNRTtoUnderline(String src){
|
||||
public static String replaceNRTtoUnderline(String src) {
|
||||
return src.replaceAll("[\n|\r|\t]", "_");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.TaskType;
|
||||
import org.apache.dolphinscheduler.common.task.AbstractParameters;
|
||||
import org.apache.dolphinscheduler.common.task.conditions.ConditionsParameters;
|
||||
import org.apache.dolphinscheduler.common.task.dependent.DependentParameters;
|
||||
import org.apache.dolphinscheduler.common.task.datax.DataxParameters;
|
||||
import org.apache.dolphinscheduler.common.task.dependent.DependentParameters;
|
||||
import org.apache.dolphinscheduler.common.task.flink.FlinkParameters;
|
||||
import org.apache.dolphinscheduler.common.task.http.HttpParameters;
|
||||
import org.apache.dolphinscheduler.common.task.mr.MapreduceParameters;
|
||||
|
|
@ -31,60 +32,65 @@ import org.apache.dolphinscheduler.common.task.spark.SparkParameters;
|
|||
import org.apache.dolphinscheduler.common.task.sql.SqlParameters;
|
||||
import org.apache.dolphinscheduler.common.task.sqoop.SqoopParameters;
|
||||
import org.apache.dolphinscheduler.common.task.subprocess.SubProcessParameters;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* task parameters utils
|
||||
*/
|
||||
public class TaskParametersUtils {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TaskParametersUtils.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(TaskParametersUtils.class);
|
||||
|
||||
/**
|
||||
* get task parameters
|
||||
* @param taskType task type
|
||||
* @param parameter parameter
|
||||
* @return task parameters
|
||||
*/
|
||||
public static AbstractParameters getParameters(String taskType, String parameter) {
|
||||
try {
|
||||
switch (EnumUtils.getEnum(TaskType.class,taskType)) {
|
||||
case SUB_PROCESS:
|
||||
return JSONUtils.parseObject(parameter, SubProcessParameters.class);
|
||||
case WATERDROP:
|
||||
return JSONUtils.parseObject(parameter, ShellParameters.class);
|
||||
case SHELL:
|
||||
return JSONUtils.parseObject(parameter, ShellParameters.class);
|
||||
case PROCEDURE:
|
||||
return JSONUtils.parseObject(parameter, ProcedureParameters.class);
|
||||
case SQL:
|
||||
return JSONUtils.parseObject(parameter, SqlParameters.class);
|
||||
case MR:
|
||||
return JSONUtils.parseObject(parameter, MapreduceParameters.class);
|
||||
case SPARK:
|
||||
return JSONUtils.parseObject(parameter, SparkParameters.class);
|
||||
case PYTHON:
|
||||
return JSONUtils.parseObject(parameter, PythonParameters.class);
|
||||
case DEPENDENT:
|
||||
return JSONUtils.parseObject(parameter, DependentParameters.class);
|
||||
case FLINK:
|
||||
return JSONUtils.parseObject(parameter, FlinkParameters.class);
|
||||
case HTTP:
|
||||
return JSONUtils.parseObject(parameter, HttpParameters.class);
|
||||
case DATAX:
|
||||
return JSONUtils.parseObject(parameter, DataxParameters.class);
|
||||
case CONDITIONS:
|
||||
return JSONUtils.parseObject(parameter, ConditionsParameters.class);
|
||||
case SQOOP:
|
||||
return JSONUtils.parseObject(parameter, SqoopParameters.class);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
private TaskParametersUtils() {
|
||||
throw new UnsupportedOperationException("Construct TaskParametersUtils");
|
||||
}
|
||||
|
||||
/**
|
||||
* get task parameters
|
||||
*
|
||||
* @param taskType task type
|
||||
* @param parameter parameter
|
||||
* @return task parameters
|
||||
*/
|
||||
public static AbstractParameters getParameters(String taskType, String parameter) {
|
||||
try {
|
||||
switch (EnumUtils.getEnum(TaskType.class, taskType)) {
|
||||
case SUB_PROCESS:
|
||||
return JSONUtils.parseObject(parameter, SubProcessParameters.class);
|
||||
case WATERDROP:
|
||||
return JSONUtils.parseObject(parameter, ShellParameters.class);
|
||||
case SHELL:
|
||||
return JSONUtils.parseObject(parameter, ShellParameters.class);
|
||||
case PROCEDURE:
|
||||
return JSONUtils.parseObject(parameter, ProcedureParameters.class);
|
||||
case SQL:
|
||||
return JSONUtils.parseObject(parameter, SqlParameters.class);
|
||||
case MR:
|
||||
return JSONUtils.parseObject(parameter, MapreduceParameters.class);
|
||||
case SPARK:
|
||||
return JSONUtils.parseObject(parameter, SparkParameters.class);
|
||||
case PYTHON:
|
||||
return JSONUtils.parseObject(parameter, PythonParameters.class);
|
||||
case DEPENDENT:
|
||||
return JSONUtils.parseObject(parameter, DependentParameters.class);
|
||||
case FLINK:
|
||||
return JSONUtils.parseObject(parameter, FlinkParameters.class);
|
||||
case HTTP:
|
||||
return JSONUtils.parseObject(parameter, HttpParameters.class);
|
||||
case DATAX:
|
||||
return JSONUtils.parseObject(parameter, DataxParameters.class);
|
||||
case CONDITIONS:
|
||||
return JSONUtils.parseObject(parameter, ConditionsParameters.class);
|
||||
case SQOOP:
|
||||
return JSONUtils.parseObject(parameter, SqoopParameters.class);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,19 +14,22 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.dao.mapper;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
/**
|
||||
* process instance mapper interface
|
||||
*/
|
||||
|
|
@ -201,9 +204,20 @@ public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {
|
|||
* @param endTime
|
||||
* @return ProcessInstance list
|
||||
*/
|
||||
|
||||
List<ProcessInstance> queryTopNProcessInstance(@Param("size") int size,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime,
|
||||
@Param("status")ExecutionStatus status);
|
||||
/**
|
||||
* query process instance by processDefinitionId and stateArray
|
||||
* @param processDefinitionId processDefinitionId
|
||||
* @param states states array
|
||||
* @return process instance list
|
||||
*/
|
||||
|
||||
List<ProcessInstance> queryByProcessDefineIdAndStatus(
|
||||
@Param("processDefinitionId") int processDefinitionId,
|
||||
@Param("states") int[] states);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,6 +191,16 @@
|
|||
</if>
|
||||
order by end_time desc limit 1
|
||||
</select>
|
||||
|
||||
<select id="queryByProcessDefineIdAndStatus"
|
||||
resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
|
||||
select *
|
||||
from t_ds_process_instance
|
||||
where process_definition_id=#{processDefinitionId}
|
||||
and state in
|
||||
<foreach collection="states" item="i" open="(" close=")" separator=",">
|
||||
#{i}
|
||||
</foreach>
|
||||
order by id asc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -27,7 +27,6 @@ import io.netty.channel.EventLoopGroup;
|
|||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
import org.apache.dolphinscheduler.remote.codec.NettyDecoder;
|
||||
import org.apache.dolphinscheduler.remote.codec.NettyEncoder;
|
||||
|
|
@ -155,11 +154,12 @@ public class NettyRemotingClient {
|
|||
|
||||
this.bootstrap
|
||||
.group(this.workerGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.channel(NettyUtils.getSocketChannelClass())
|
||||
.option(ChannelOption.SO_KEEPALIVE, clientConfig.isSoKeepalive())
|
||||
.option(ChannelOption.TCP_NODELAY, clientConfig.isTcpNoDelay())
|
||||
.option(ChannelOption.SO_SNDBUF, clientConfig.getSendBufferSize())
|
||||
.option(ChannelOption.SO_RCVBUF, clientConfig.getReceiveBufferSize())
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, clientConfig.getConnectTimeoutMillis())
|
||||
.handler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
|
|
|
|||
|
|
@ -17,17 +17,6 @@
|
|||
|
||||
package org.apache.dolphinscheduler.remote;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
import org.apache.dolphinscheduler.remote.codec.NettyDecoder;
|
||||
import org.apache.dolphinscheduler.remote.codec.NettyEncoder;
|
||||
import org.apache.dolphinscheduler.remote.command.CommandType;
|
||||
|
|
@ -37,15 +26,25 @@ import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor;
|
|||
import org.apache.dolphinscheduler.remote.utils.Constants;
|
||||
import org.apache.dolphinscheduler.remote.utils.NettyUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
|
||||
/**
|
||||
* remoting netty server
|
||||
*/
|
||||
|
|
@ -146,17 +145,17 @@ public class NettyRemotingServer {
|
|||
if (isStarted.compareAndSet(false, true)) {
|
||||
this.serverBootstrap
|
||||
.group(this.bossGroup, this.workGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.channel(NettyUtils.getServerSocketChannelClass())
|
||||
.option(ChannelOption.SO_REUSEADDR, true)
|
||||
.option(ChannelOption.SO_BACKLOG, serverConfig.getSoBacklog())
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, serverConfig.isSoKeepalive())
|
||||
.childOption(ChannelOption.TCP_NODELAY, serverConfig.isTcpNoDelay())
|
||||
.childOption(ChannelOption.SO_SNDBUF, serverConfig.getSendBufferSize())
|
||||
.childOption(ChannelOption.SO_RCVBUF, serverConfig.getReceiveBufferSize())
|
||||
.childHandler(new ChannelInitializer<NioSocketChannel>() {
|
||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
protected void initChannel(NioSocketChannel ch) throws Exception {
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
initNettyChannel(ch);
|
||||
}
|
||||
});
|
||||
|
|
@ -182,9 +181,8 @@ public class NettyRemotingServer {
|
|||
* init netty channel
|
||||
*
|
||||
* @param ch socket channel
|
||||
* @throws Exception
|
||||
*/
|
||||
private void initNettyChannel(NioSocketChannel ch) throws Exception {
|
||||
private void initNettyChannel(SocketChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast("encoder", encoder);
|
||||
pipeline.addLast("decoder", new NettyDecoder());
|
||||
|
|
|
|||
|
|
@ -14,22 +14,23 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.remote.config;
|
||||
|
||||
import org.apache.dolphinscheduler.remote.utils.Constants;
|
||||
|
||||
/**
|
||||
* netty client config
|
||||
* netty client config
|
||||
*/
|
||||
public class NettyClientConfig {
|
||||
|
||||
/**
|
||||
* worker threads,default get machine cpus
|
||||
* worker threads,default get machine cpus
|
||||
*/
|
||||
private int workerThreads = Constants.CPUS;
|
||||
|
||||
/**
|
||||
* whether tpc delay
|
||||
* whether tpc delay
|
||||
*/
|
||||
private boolean tcpNoDelay = true;
|
||||
|
||||
|
|
@ -39,15 +40,20 @@ public class NettyClientConfig {
|
|||
private boolean soKeepalive = true;
|
||||
|
||||
/**
|
||||
* send buffer size
|
||||
* send buffer size
|
||||
*/
|
||||
private int sendBufferSize = 65535;
|
||||
|
||||
/**
|
||||
* receive buffer size
|
||||
* receive buffer size
|
||||
*/
|
||||
private int receiveBufferSize = 65535;
|
||||
|
||||
/**
|
||||
* connect timeout millis
|
||||
*/
|
||||
private int connectTimeoutMillis = 3000;
|
||||
|
||||
public int getWorkerThreads() {
|
||||
return workerThreads;
|
||||
}
|
||||
|
|
@ -88,4 +94,11 @@ public class NettyClientConfig {
|
|||
this.receiveBufferSize = receiveBufferSize;
|
||||
}
|
||||
|
||||
public int getConnectTimeoutMillis() {
|
||||
return connectTimeoutMillis;
|
||||
}
|
||||
|
||||
public void setConnectTimeoutMillis(int connectTimeoutMillis) {
|
||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.remote.utils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
|
@ -21,7 +22,7 @@ import java.nio.charset.StandardCharsets;
|
|||
|
||||
|
||||
/**
|
||||
* constant
|
||||
* constant
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
|
|
@ -30,12 +31,12 @@ public class Constants {
|
|||
public static final String SLASH = "/";
|
||||
|
||||
/**
|
||||
* charset
|
||||
* charset
|
||||
*/
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* cpus
|
||||
* cpus
|
||||
*/
|
||||
public static final int CPUS = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ public class Constants {
|
|||
/**
|
||||
* netty epoll enable switch
|
||||
*/
|
||||
public static final String NETTY_EPOLL_ENABLE = System.getProperty("netty.epoll.enable");
|
||||
public static final String NETTY_EPOLL_ENABLE = System.getProperty("netty.epoll.enable", "true");
|
||||
|
||||
/**
|
||||
* OS Name
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@
|
|||
package org.apache.dolphinscheduler.remote.utils;
|
||||
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.epoll.EpollSocketChannel;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
||||
/**
|
||||
* NettyUtils
|
||||
|
|
@ -39,4 +45,18 @@ public class NettyUtils {
|
|||
return Boolean.parseBoolean(enableNettyEpoll);
|
||||
}
|
||||
|
||||
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass() {
|
||||
if (useEpoll()) {
|
||||
return EpollServerSocketChannel.class;
|
||||
}
|
||||
return NioServerSocketChannel.class;
|
||||
}
|
||||
|
||||
public static Class<? extends SocketChannel> getSocketChannelClass() {
|
||||
if (useEpoll()) {
|
||||
return EpollSocketChannel.class;
|
||||
}
|
||||
return NioSocketChannel.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,20 +17,28 @@
|
|||
|
||||
package org.apache.dolphinscheduler.remote;
|
||||
|
||||
import static org.apache.dolphinscheduler.remote.utils.Constants.OS_NAME;
|
||||
|
||||
import org.apache.dolphinscheduler.remote.utils.NettyUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
|
||||
/**
|
||||
* NettyUtilTest
|
||||
*/
|
||||
public class NettyUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testUserEpoll() {
|
||||
System.setProperty("netty.epoll.enable", "false");
|
||||
Assert.assertFalse(NettyUtils.useEpoll());
|
||||
if (OS_NAME.toLowerCase().contains("linux") && Epoll.isAvailable()) {
|
||||
Assert.assertTrue(NettyUtils.useEpoll());
|
||||
} else {
|
||||
Assert.assertFalse(NettyUtils.useEpoll());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* task fulture
|
||||
* task future
|
||||
*/
|
||||
public class TaskFuture {
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import org.apache.dolphinscheduler.common.utils.*;
|
|||
import org.apache.dolphinscheduler.common.utils.LoggerUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.NetUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.utils.LogUtils;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -123,7 +125,7 @@ public class ConditionsTaskExecThread extends MasterBaseTaskExecThread {
|
|||
}
|
||||
|
||||
private void initTaskParameters() {
|
||||
this.taskInstance.setLogPath(getTaskLogPath(taskInstance));
|
||||
this.taskInstance.setLogPath(LogUtils.getTaskLogPath(taskInstance));
|
||||
this.taskInstance.setHost(NetUtils.getHost() + Constants.COLON + masterConfig.getListenPort());
|
||||
taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
|
||||
taskInstance.setStartTime(new Date());
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.server.master.runner;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import static org.apache.dolphinscheduler.common.Constants.DEPENDENT_SPLIT;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.DependResult;
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
|
|
@ -24,16 +26,22 @@ import org.apache.dolphinscheduler.common.model.DependentTaskModel;
|
|||
import org.apache.dolphinscheduler.common.task.dependent.DependentParameters;
|
||||
import org.apache.dolphinscheduler.common.thread.Stopper;
|
||||
import org.apache.dolphinscheduler.common.utils.DependentUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.*;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.LoggerUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.NetUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.utils.LogUtils;
|
||||
import org.apache.dolphinscheduler.server.utils.DependentExecute;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.DEPENDENT_SPLIT;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
||||
|
||||
|
|
@ -172,7 +180,7 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|||
}
|
||||
|
||||
private void initTaskParameters() {
|
||||
taskInstance.setLogPath(getTaskLogPath(taskInstance));
|
||||
taskInstance.setLogPath(LogUtils.getTaskLogPath(taskInstance));
|
||||
taskInstance.setHost(NetUtils.getHost() + Constants.COLON + masterConfig.getListenPort());
|
||||
taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
|
||||
taskInstance.setStartTime(new Date());
|
||||
|
|
|
|||
|
|
@ -14,17 +14,16 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.server.master.runner;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.UNDERLINE;
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.AlertDao;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator;
|
||||
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
|
||||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
||||
import org.apache.dolphinscheduler.service.process.ProcessService;
|
||||
|
|
@ -36,10 +35,6 @@ import java.util.concurrent.Callable;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.sift.SiftingAppender;
|
||||
|
||||
|
||||
/**
|
||||
* master task exec base class
|
||||
*/
|
||||
|
|
@ -85,11 +80,13 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
* taskUpdateQueue
|
||||
*/
|
||||
private TaskPriorityQueue taskUpdateQueue;
|
||||
|
||||
/**
|
||||
* constructor of MasterBaseTaskExecThread
|
||||
* @param taskInstance task instance
|
||||
*
|
||||
* @param taskInstance task instance
|
||||
*/
|
||||
public MasterBaseTaskExecThread(TaskInstance taskInstance){
|
||||
public MasterBaseTaskExecThread(TaskInstance taskInstance) {
|
||||
this.processService = SpringApplicationContext.getBean(ProcessService.class);
|
||||
this.alertDao = SpringApplicationContext.getBean(AlertDao.class);
|
||||
this.cancel = false;
|
||||
|
|
@ -100,24 +97,26 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
|
||||
/**
|
||||
* get task instance
|
||||
*
|
||||
* @return TaskInstance
|
||||
*/
|
||||
public TaskInstance getTaskInstance(){
|
||||
public TaskInstance getTaskInstance() {
|
||||
return this.taskInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* kill master base task exec thread
|
||||
*/
|
||||
public void kill(){
|
||||
public void kill() {
|
||||
this.cancel = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* submit master base task exec thread
|
||||
*
|
||||
* @return TaskInstance
|
||||
*/
|
||||
protected TaskInstance submit(){
|
||||
protected TaskInstance submit() {
|
||||
Integer commitRetryTimes = masterConfig.getMasterTaskCommitRetryTimes();
|
||||
Integer commitRetryInterval = masterConfig.getMasterTaskCommitInterval();
|
||||
|
||||
|
|
@ -156,14 +155,13 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dispatcht task
|
||||
*
|
||||
* @param taskInstance taskInstance
|
||||
* @return whether submit task success
|
||||
*/
|
||||
public Boolean dispatchTask(TaskInstance taskInstance) {
|
||||
|
||||
try{
|
||||
if(taskInstance.isConditionsTask()
|
||||
|| taskInstance.isDependTask()
|
||||
|
|
@ -202,7 +200,7 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
|
||||
|
||||
/**
|
||||
* buildTaskPriorityInfo
|
||||
* buildTaskPriorityInfo
|
||||
*
|
||||
* @param processInstancePriority processInstancePriority
|
||||
* @param processInstanceId processInstanceId
|
||||
|
|
@ -215,7 +213,7 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
int processInstanceId,
|
||||
int taskInstancePriority,
|
||||
int taskInstanceId,
|
||||
String workerGroup){
|
||||
String workerGroup) {
|
||||
return processInstancePriority +
|
||||
UNDERLINE +
|
||||
processInstanceId +
|
||||
|
|
@ -229,14 +227,16 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
|
||||
/**
|
||||
* submit wait complete
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
protected Boolean submitWaitComplete(){
|
||||
protected Boolean submitWaitComplete() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* call
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Exception exception
|
||||
*/
|
||||
|
|
@ -246,34 +246,4 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
|
|||
return submitWaitComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* get task log path
|
||||
* @return log path
|
||||
*/
|
||||
public String getTaskLogPath(TaskInstance task) {
|
||||
String logPath;
|
||||
try{
|
||||
String baseLog = ((TaskLogDiscriminator) ((SiftingAppender) ((LoggerContext) LoggerFactory.getILoggerFactory())
|
||||
.getLogger("ROOT")
|
||||
.getAppender("TASKLOGFILE"))
|
||||
.getDiscriminator()).getLogBase();
|
||||
if (baseLog.startsWith(Constants.SINGLE_SLASH)){
|
||||
logPath = baseLog + Constants.SINGLE_SLASH +
|
||||
task.getProcessDefinitionId() + Constants.SINGLE_SLASH +
|
||||
task.getProcessInstanceId() + Constants.SINGLE_SLASH +
|
||||
task.getId() + ".log";
|
||||
}else{
|
||||
logPath = System.getProperty("user.dir") + Constants.SINGLE_SLASH +
|
||||
baseLog + Constants.SINGLE_SLASH +
|
||||
task.getProcessDefinitionId() + Constants.SINGLE_SLASH +
|
||||
task.getProcessInstanceId() + Constants.SINGLE_SLASH +
|
||||
task.getId() + ".log";
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error("logger", e);
|
||||
logPath = "";
|
||||
}
|
||||
return logPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.server.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext;
|
||||
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.transaction.NotSupportedException;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.sift.SiftingAppender;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.spi.AppenderAttachable;
|
||||
|
||||
public class LogUtils {
|
||||
|
||||
private LogUtils() throws NotSupportedException {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* get task log path
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String getTaskLogPath(int processDefinitionId, int processInstanceId, int taskInstanceId) {
|
||||
// Optional.map will be skipped if null
|
||||
return Optional.of(LoggerFactory.getILoggerFactory())
|
||||
.map(e -> (AppenderAttachable<ILoggingEvent>) (e.getLogger("ROOT")))
|
||||
.map(e -> (SiftingAppender) (e.getAppender("TASKLOGFILE")))
|
||||
.map(e -> ((TaskLogDiscriminator) (e.getDiscriminator())))
|
||||
.map(TaskLogDiscriminator::getLogBase)
|
||||
.map(e -> Paths.get(e)
|
||||
.toAbsolutePath()
|
||||
.resolve(String.valueOf(processDefinitionId))
|
||||
.resolve(String.valueOf(processInstanceId))
|
||||
.resolve(taskInstanceId + ".log"))
|
||||
.map(Path::toString)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
/**
|
||||
* get task log path by TaskInstance
|
||||
*/
|
||||
public static String getTaskLogPath(TaskInstance taskInstance) {
|
||||
return getTaskLogPath(taskInstance.getProcessDefinitionId(), taskInstance.getProcessInstanceId(), taskInstance.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* get task log path by TaskExecutionContext
|
||||
*/
|
||||
public static String getTaskLogPath(TaskExecutionContext taskExecutionContext) {
|
||||
return getTaskLogPath(taskExecutionContext.getProcessId(), taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getTaskInstanceId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.dolphinscheduler.server.worker.processor;
|
||||
|
||||
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
import org.apache.dolphinscheduler.common.enums.TaskType;
|
||||
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
|
||||
|
|
@ -36,7 +34,7 @@ import org.apache.dolphinscheduler.remote.command.TaskExecuteRequestCommand;
|
|||
import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor;
|
||||
import org.apache.dolphinscheduler.remote.utils.JsonSerializer;
|
||||
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext;
|
||||
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator;
|
||||
import org.apache.dolphinscheduler.server.utils.LogUtils;
|
||||
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig;
|
||||
import org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread;
|
||||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
||||
|
|
@ -51,8 +49,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.github.rholder.retry.RetryException;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.sift.SiftingAppender;
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
/**
|
||||
|
|
@ -154,28 +150,6 @@ public class TaskExecuteProcessor implements NettyRequestProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get task log path
|
||||
* @return log path
|
||||
*/
|
||||
private String getTaskLogPath(TaskExecutionContext taskExecutionContext) {
|
||||
String baseLog = ((TaskLogDiscriminator) ((SiftingAppender) ((LoggerContext) LoggerFactory.getILoggerFactory())
|
||||
.getLogger("ROOT")
|
||||
.getAppender("TASKLOGFILE"))
|
||||
.getDiscriminator()).getLogBase();
|
||||
if (baseLog.startsWith(Constants.SINGLE_SLASH)){
|
||||
return baseLog + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getProcessDefineId() + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getProcessInstanceId() + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getTaskInstanceId() + ".log";
|
||||
}
|
||||
return System.getProperty("user.dir") + Constants.SINGLE_SLASH +
|
||||
baseLog + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getProcessDefineId() + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getProcessInstanceId() + Constants.SINGLE_SLASH +
|
||||
taskExecutionContext.getTaskInstanceId() + ".log";
|
||||
}
|
||||
|
||||
/**
|
||||
* build ack command
|
||||
* @param taskExecutionContext taskExecutionContext
|
||||
|
|
@ -185,7 +159,7 @@ public class TaskExecuteProcessor implements NettyRequestProcessor {
|
|||
TaskExecuteAckCommand ackCommand = new TaskExecuteAckCommand();
|
||||
ackCommand.setTaskInstanceId(taskExecutionContext.getTaskInstanceId());
|
||||
ackCommand.setStatus(taskExecutionContext.getCurrentExecutionStatus().getCode());
|
||||
ackCommand.setLogPath(getTaskLogPath(taskExecutionContext));
|
||||
ackCommand.setLogPath(LogUtils.getTaskLogPath(taskExecutionContext));
|
||||
ackCommand.setHost(taskExecutionContext.getHost());
|
||||
ackCommand.setStartTime(taskExecutionContext.getStartTime());
|
||||
if(taskExecutionContext.getTaskType().equals(TaskType.SQL.name()) || taskExecutionContext.getTaskType().equals(TaskType.PROCEDURE.name())){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* 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.server.master;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
import org.apache.dolphinscheduler.common.enums.TaskType;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNode;
|
||||
import org.apache.dolphinscheduler.common.thread.Stopper;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
|
||||
import org.apache.dolphinscheduler.server.master.runner.SubProcessTaskExecThread;
|
||||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
||||
import org.apache.dolphinscheduler.service.process.ProcessService;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({
|
||||
Stopper.class,
|
||||
})
|
||||
public class SubProcessTaskTest {
|
||||
|
||||
/**
|
||||
* TaskNode.runFlag : task can be run normally
|
||||
*/
|
||||
public static final String FLOWNODE_RUN_FLAG_NORMAL = "NORMAL";
|
||||
|
||||
private ProcessService processService;
|
||||
|
||||
private ProcessInstance processInstance;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
|
||||
SpringApplicationContext springApplicationContext = new SpringApplicationContext();
|
||||
springApplicationContext.setApplicationContext(applicationContext);
|
||||
|
||||
MasterConfig config = new MasterConfig();
|
||||
Mockito.when(applicationContext.getBean(MasterConfig.class)).thenReturn(config);
|
||||
config.setMasterTaskCommitRetryTimes(3);
|
||||
config.setMasterTaskCommitInterval(1000);
|
||||
|
||||
PowerMockito.mockStatic(Stopper.class);
|
||||
PowerMockito.when(Stopper.isRunning()).thenReturn(true);
|
||||
|
||||
processService = Mockito.mock(ProcessService.class);
|
||||
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService);
|
||||
|
||||
processInstance = getProcessInstance();
|
||||
Mockito.when(processService
|
||||
.findProcessInstanceById(processInstance.getId()))
|
||||
.thenReturn(processInstance);
|
||||
|
||||
// for SubProcessTaskExecThread.setTaskInstanceState
|
||||
Mockito.when(processService
|
||||
.updateTaskInstance(Mockito.any()))
|
||||
.thenReturn(true);
|
||||
|
||||
// for MasterBaseTaskExecThread.submit
|
||||
Mockito.when(processService
|
||||
.submitTask(Mockito.any()))
|
||||
.thenAnswer(t -> t.getArgument(0));
|
||||
}
|
||||
|
||||
private TaskInstance testBasicInit(ExecutionStatus expectResult) {
|
||||
TaskInstance taskInstance = getTaskInstance(getTaskNode(), processInstance);
|
||||
|
||||
ProcessInstance subProcessInstance = getSubProcessInstance(expectResult);
|
||||
// for SubProcessTaskExecThread.waitTaskQuit
|
||||
Mockito.when(processService
|
||||
.findProcessInstanceById(subProcessInstance.getId()))
|
||||
.thenReturn(subProcessInstance);
|
||||
Mockito.when(processService
|
||||
.findSubProcessInstance(processInstance.getId(), taskInstance.getId()))
|
||||
.thenReturn(subProcessInstance);
|
||||
|
||||
return taskInstance;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicSuccess() throws Exception {
|
||||
TaskInstance taskInstance = testBasicInit(ExecutionStatus.SUCCESS);
|
||||
SubProcessTaskExecThread taskExecThread = new SubProcessTaskExecThread(taskInstance);
|
||||
taskExecThread.call();
|
||||
Assert.assertEquals(ExecutionStatus.SUCCESS, taskExecThread.getTaskInstance().getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicFailure() throws Exception {
|
||||
TaskInstance taskInstance = testBasicInit(ExecutionStatus.FAILURE);
|
||||
SubProcessTaskExecThread taskExecThread = new SubProcessTaskExecThread(taskInstance);
|
||||
taskExecThread.call();
|
||||
Assert.assertEquals(ExecutionStatus.FAILURE, taskExecThread.getTaskInstance().getState());
|
||||
}
|
||||
|
||||
private TaskNode getTaskNode() {
|
||||
TaskNode taskNode = new TaskNode();
|
||||
taskNode.setId("tasks-10");
|
||||
taskNode.setName("S");
|
||||
taskNode.setType(TaskType.SUB_PROCESS.toString());
|
||||
taskNode.setRunFlag(FLOWNODE_RUN_FLAG_NORMAL);
|
||||
return taskNode;
|
||||
}
|
||||
|
||||
private ProcessInstance getProcessInstance() {
|
||||
ProcessInstance processInstance = new ProcessInstance();
|
||||
processInstance.setId(100);
|
||||
processInstance.setProcessDefinitionId(1);
|
||||
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
|
||||
|
||||
return processInstance;
|
||||
}
|
||||
|
||||
private ProcessInstance getSubProcessInstance(ExecutionStatus executionStatus) {
|
||||
ProcessInstance processInstance = new ProcessInstance();
|
||||
processInstance.setId(102);
|
||||
processInstance.setProcessDefinitionId(2);
|
||||
processInstance.setState(executionStatus);
|
||||
|
||||
return processInstance;
|
||||
}
|
||||
|
||||
private TaskInstance getTaskInstance(TaskNode taskNode, ProcessInstance processInstance) {
|
||||
TaskInstance taskInstance = new TaskInstance();
|
||||
taskInstance.setId(1000);
|
||||
taskInstance.setTaskJson(JSONUtils.toJsonString(taskNode));
|
||||
taskInstance.setName(taskNode.getName());
|
||||
taskInstance.setTaskType(taskNode.getType());
|
||||
taskInstance.setProcessInstanceId(processInstance.getId());
|
||||
taskInstance.setProcessDefinitionId(processInstance.getProcessDefinitionId());
|
||||
taskInstance.setState(ExecutionStatus.SUBMITTED_SUCCESS);
|
||||
return taskInstance;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,67 +14,53 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.server.master.dispatch.host;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.NetUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.StringUtils;
|
||||
import org.apache.dolphinscheduler.remote.utils.Host;
|
||||
import org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext;
|
||||
import org.apache.dolphinscheduler.server.registry.DependencyConfig;
|
||||
import org.apache.dolphinscheduler.server.registry.ZookeeperNodeManager;
|
||||
import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter;
|
||||
import org.apache.dolphinscheduler.server.utils.ExecutionContextTestUtils;
|
||||
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig;
|
||||
import org.apache.dolphinscheduler.server.worker.registry.WorkerRegistry;
|
||||
import org.apache.dolphinscheduler.server.zk.SpringZKServer;
|
||||
import org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient;
|
||||
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator;
|
||||
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
|
||||
/**
|
||||
* round robin host manager test
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes={DependencyConfig.class, SpringZKServer.class, WorkerRegistry.class, ZookeeperRegistryCenter.class, WorkerConfig.class,
|
||||
ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, CuratorZookeeperClient.class})
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RoundRobinHostManagerTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
@Mock
|
||||
private ZookeeperNodeManager zookeeperNodeManager;
|
||||
|
||||
@Autowired
|
||||
private WorkerRegistry workerRegistry;
|
||||
|
||||
@Autowired
|
||||
private WorkerConfig workerConfig;
|
||||
@InjectMocks
|
||||
RoundRobinHostManager roundRobinHostManager;
|
||||
|
||||
@Test
|
||||
public void testSelectWithEmptyResult(){
|
||||
RoundRobinHostManager roundRobinHostManager = new RoundRobinHostManager();
|
||||
roundRobinHostManager.setZookeeperNodeManager(zookeeperNodeManager);
|
||||
public void testSelectWithEmptyResult() {
|
||||
Mockito.when(zookeeperNodeManager.getWorkerGroupNodes("default")).thenReturn(null);
|
||||
ExecutionContext context = ExecutionContextTestUtils.getExecutionContext(10000);
|
||||
Host emptyHost = roundRobinHostManager.select(context);
|
||||
Assert.assertTrue(StringUtils.isEmpty(emptyHost.getAddress()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectWithResult(){
|
||||
workerRegistry.registry();
|
||||
RoundRobinHostManager roundRobinHostManager = new RoundRobinHostManager();
|
||||
roundRobinHostManager.setZookeeperNodeManager(zookeeperNodeManager);
|
||||
public void testSelectWithResult() {
|
||||
Mockito.when(zookeeperNodeManager.getWorkerGroupNodes("default")).thenReturn(Sets.newHashSet("192.168.1.1:22:100"));
|
||||
ExecutionContext context = ExecutionContextTestUtils.getExecutionContext(10000);
|
||||
Host host = roundRobinHostManager.select(context);
|
||||
Assert.assertTrue(StringUtils.isNotEmpty(host.getAddress()));
|
||||
Assert.assertTrue(host.getAddress().equalsIgnoreCase(NetUtils.getHost() + ":" + workerConfig.getListenPort()));
|
||||
workerRegistry.unRegistry();
|
||||
Assert.assertTrue(host.getAddress().equalsIgnoreCase("192.168.1.1:22"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,15 @@
|
|||
|
||||
package org.apache.dolphinscheduler.server.master.runner;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter;
|
||||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
||||
import org.apache.dolphinscheduler.service.process.ProcessService;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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.server.utils;
|
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.server.log.TaskLogDiscriminator;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.sift.SiftingAppender;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LogUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetTaskLogPath() {
|
||||
TaskInstance taskInstance = new TaskInstance();
|
||||
taskInstance.setProcessDefinitionId(1);
|
||||
taskInstance.setProcessInstanceId(100);
|
||||
taskInstance.setId(1000);
|
||||
|
||||
Logger rootLogger = (Logger) LoggerFactory.getILoggerFactory().getLogger("ROOT");
|
||||
Assert.assertNotNull(rootLogger);
|
||||
|
||||
SiftingAppender appender = Mockito.mock(SiftingAppender.class);
|
||||
// it's a trick to mock logger.getAppend("TASKLOGFILE")
|
||||
Mockito.when(appender.getName()).thenReturn("TASKLOGFILE");
|
||||
rootLogger.addAppender(appender);
|
||||
|
||||
Path logBase = Paths.get("path").resolve("to").resolve("test");
|
||||
|
||||
TaskLogDiscriminator taskLogDiscriminator = Mockito.mock(TaskLogDiscriminator.class);
|
||||
Mockito.when(taskLogDiscriminator.getLogBase()).thenReturn(logBase.toString());
|
||||
Mockito.when(appender.getDiscriminator()).thenReturn(taskLogDiscriminator);
|
||||
|
||||
Path logPath = Paths.get(".").toAbsolutePath().getParent()
|
||||
.resolve(logBase)
|
||||
.resolve("1").resolve("100").resolve("1000.log");
|
||||
Assert.assertEquals(logPath.toString(), LogUtils.getTaskLogPath(taskInstance));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -790,7 +790,8 @@
|
|||
props: {
|
||||
processDefinition: {
|
||||
id: self.urlParam.id,
|
||||
version: self.$store.state.dag.version
|
||||
version: self.$store.state.dag.version,
|
||||
state: self.releaseState
|
||||
},
|
||||
processDefinitionVersions: processDefinitionVersions,
|
||||
total: total,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<x-button type="text" @click="close()"> {{$t('Cancel')}} </x-button>
|
||||
<x-button type="primary" shape="circle" @click="ok()">{{$t('Add')}}</x-button>
|
||||
<x-button type="primary" shape="circle" :disabled="isDetails" @click="ok()">{{$t('Add')}}</x-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@
|
|||
</x-poptip>
|
||||
<template v-if="strSelectIds !== ''">
|
||||
<x-button size="xsmall" style="position: absolute; bottom: -48px; left: 80px;" @click="_batchExport(item)" >{{$t('Export')}}</x-button>
|
||||
<x-button size="xsmall" style="position: absolute; bottom: -48px; left: 140px;" @click="_batchCopy(item)" >{{$t('Batch copy')}}</x-button>
|
||||
<x-button size="xsmall" style="position: absolute; bottom: -48px; left: 225px;" @click="_batchMove(item)" >{{$t('Batch move')}}</x-button>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
|
|
@ -147,6 +149,7 @@
|
|||
import _ from 'lodash'
|
||||
import mStart from './start'
|
||||
import mTiming from './timing'
|
||||
import mRelatedItems from './relatedItems'
|
||||
import { mapActions } from 'vuex'
|
||||
import { publishStatus } from '@/conf/home/pages/dag/_source/config'
|
||||
import mVersions from './versions'
|
||||
|
|
@ -166,7 +169,7 @@
|
|||
pageSize: Number
|
||||
},
|
||||
methods: {
|
||||
...mapActions('dag', ['editProcessState', 'getStartCheck', 'getReceiver', 'deleteDefinition', 'batchDeleteDefinition', 'exportDefinition', 'getProcessDefinitionVersionsPage', 'copyProcess', 'switchProcessDefinitionVersion', 'deleteProcessDefinitionVersion']),
|
||||
...mapActions('dag', ['editProcessState', 'getStartCheck', 'getReceiver', 'deleteDefinition', 'batchDeleteDefinition', 'exportDefinition', 'getProcessDefinitionVersionsPage', 'copyProcess', 'switchProcessDefinitionVersion', 'deleteProcessDefinitionVersion', 'moveProcess']),
|
||||
...mapActions('security', ['getWorkerGroupsAll']),
|
||||
_rtPublishStatus (code) {
|
||||
return _.filter(publishStatus, v => v.code === code)[0].desc
|
||||
|
|
@ -317,8 +320,27 @@
|
|||
*/
|
||||
_copyProcess (item) {
|
||||
this.copyProcess({
|
||||
processId: item.id
|
||||
processDefinitionIds: item.id,
|
||||
targetProjectId: item.projectId
|
||||
}).then(res => {
|
||||
this.strSelectIds = ''
|
||||
this.$message.success(res.msg)
|
||||
$('body').find('.tooltip.fade.top.in').remove()
|
||||
this._onUpdate()
|
||||
}).catch(e => {
|
||||
this.$message.error(e.msg || '')
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* move
|
||||
*/
|
||||
_moveProcess (item) {
|
||||
this.moveProcess({
|
||||
processDefinitionIds: item.id,
|
||||
targetProjectId: item.projectId
|
||||
}).then(res => {
|
||||
this.strSelectIds = ''
|
||||
this.$message.success(res.msg)
|
||||
$('body').find('.tooltip.fade.top.in').remove()
|
||||
this._onUpdate()
|
||||
|
|
@ -469,7 +491,64 @@
|
|||
this.$message.error(e.msg)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Batch Copy
|
||||
*/
|
||||
_batchCopy () {
|
||||
let self = this
|
||||
let modal = this.$modal.dialog({
|
||||
closable: false,
|
||||
showMask: true,
|
||||
escClose: true,
|
||||
className: 'v-modal-custom',
|
||||
transitionName: 'opacityp',
|
||||
render (h) {
|
||||
return h(mRelatedItems, {
|
||||
on: {
|
||||
onBatchCopy (item) {
|
||||
self._copyProcess({id: self.strSelectIds,projectId: item})
|
||||
modal.remove()
|
||||
},
|
||||
close () {
|
||||
modal.remove()
|
||||
}
|
||||
},
|
||||
props: {
|
||||
tmp: false
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* _batchMove
|
||||
*/
|
||||
_batchMove() {
|
||||
let self = this
|
||||
let modal = this.$modal.dialog({
|
||||
closable: false,
|
||||
showMask: true,
|
||||
escClose: true,
|
||||
className: 'v-modal-custom',
|
||||
transitionName: 'opacityp',
|
||||
render (h) {
|
||||
return h(mRelatedItems, {
|
||||
on: {
|
||||
onBatchMove (item) {
|
||||
self._moveProcess({id: self.strSelectIds,projectId: item})
|
||||
modal.remove()
|
||||
},
|
||||
close () {
|
||||
modal.remove()
|
||||
}
|
||||
},
|
||||
props: {
|
||||
tmp: true
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* Edit state
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
<template>
|
||||
<m-popup
|
||||
ref="popup"
|
||||
:ok-text="$t('Confirm')"
|
||||
:nameText="$t('Related items')"
|
||||
@ok="_ok">
|
||||
<template slot="content">
|
||||
<div class="create-tenement-model">
|
||||
<m-list-box-f>
|
||||
<template slot="name"><strong>*</strong>{{$t('Project Name')}}</template>
|
||||
<template slot="content">
|
||||
<x-select v-model="itemId">
|
||||
<x-option
|
||||
v-for="item in itemList"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="item.name">
|
||||
</x-option>
|
||||
</x-select>
|
||||
</template>
|
||||
</m-list-box-f>
|
||||
</div>
|
||||
</template>
|
||||
</m-popup>
|
||||
</template>
|
||||
<script>
|
||||
import _ from 'lodash'
|
||||
import i18n from '@/module/i18n'
|
||||
import store from '@/conf/home/store'
|
||||
import mPopup from '@/module/components/popup/popup'
|
||||
import mListBoxF from '@/module/components/listBoxF/listBoxF'
|
||||
|
||||
export default {
|
||||
name: 'create-tenement',
|
||||
data () {
|
||||
return {
|
||||
store,
|
||||
itemList: [],
|
||||
itemId: ''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
tmp: Boolean
|
||||
},
|
||||
methods: {
|
||||
_ok () {
|
||||
if(this._verification()) {
|
||||
if(this.tmp) {
|
||||
this.$emit('onBatchMove',this.itemId)
|
||||
} else {
|
||||
this.$emit('onBatchCopy',this.itemId)
|
||||
}
|
||||
}
|
||||
},
|
||||
_verification() {
|
||||
if(!this.itemId) {
|
||||
this.$message.warning(`${i18n.$t('Project name is required')}`)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
},
|
||||
watch: {
|
||||
},
|
||||
created () {
|
||||
this.store.dispatch('dag/getAllItems', {}).then(res => {
|
||||
if(res.data.length> 0) {
|
||||
this.itemList = res.data
|
||||
}
|
||||
})
|
||||
},
|
||||
mounted () {
|
||||
|
||||
},
|
||||
components: { mPopup, mListBoxF }
|
||||
}
|
||||
</script>
|
||||
|
|
@ -25,13 +25,10 @@
|
|||
<table class="fixed">
|
||||
<caption><!-- placeHolder --></caption>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<span>#</span>
|
||||
<th scope="col" style="min-width: 40px;text-align: left">
|
||||
<span>{{$t('Version')}}</span>
|
||||
</th>
|
||||
<th scope="col" style="min-width: 40px">
|
||||
<span>Version</span>
|
||||
</th>
|
||||
<th scope="col" style="min-width: 200px;max-width: 300px;">
|
||||
<th scope="col" style="min-width: 30px">
|
||||
<span>{{$t('Description')}}</span>
|
||||
</th>
|
||||
<th scope="col" style="min-width: 50px">
|
||||
|
|
@ -42,9 +39,6 @@
|
|||
</th>
|
||||
</tr>
|
||||
<tr v-for="(item, $index) in processDefinitionVersions" :key="item.id">
|
||||
<td>
|
||||
<span>-</span>
|
||||
</td>
|
||||
<td>
|
||||
<span v-if="item.version">
|
||||
<span v-if="item.version === processDefinition.version" style="color: green"><strong>{{item.version}} {{$t('Current Version')}}</strong></span>
|
||||
|
|
@ -52,7 +46,7 @@
|
|||
</span>
|
||||
<span v-else>-</span>
|
||||
</td>
|
||||
<td>
|
||||
<td style="word-break:break-all;">
|
||||
<span v-if="item.description">{{item.description}}</span>
|
||||
<span v-else>-</span>
|
||||
</td>
|
||||
|
|
@ -64,11 +58,15 @@
|
|||
<x-poptip
|
||||
:ref="'poptip-switch-version-' + $index"
|
||||
placement="top-end"
|
||||
width="90">
|
||||
width="260">
|
||||
<p>{{$t('Confirm Switch To This Version?')}}</p>
|
||||
<div style="text-align: right; margin: 0;padding-top: 4px;">
|
||||
<x-button type="text" size="xsmall" shape="circle" @click="_closeSwitchVersion($index)">{{$t('Cancel')}}</x-button>
|
||||
<x-button type="primary" size="xsmall" shape="circle" @click="_mVersionSwitchProcessDefinitionVersion(item)">{{$t('Confirm')}}</x-button>
|
||||
<x-button type="text" size="xsmall" shape="circle" @click="_closeSwitchVersion($index)">
|
||||
{{$t('Cancel')}}
|
||||
</x-button>
|
||||
<x-button type="primary" size="xsmall" shape="circle"
|
||||
@click="_mVersionSwitchProcessDefinitionVersion(item)">{{$t('Confirm')}}
|
||||
</x-button>
|
||||
</div>
|
||||
<template slot="reference">
|
||||
<x-button
|
||||
|
|
@ -76,7 +74,7 @@
|
|||
type="primary"
|
||||
shape="circle"
|
||||
size="xsmall"
|
||||
:disabled="item.version === processDefinition.version"
|
||||
:disabled="item.version === processDefinition.version || 'ONLINE' === processDefinition.state"
|
||||
data-toggle="tooltip"
|
||||
:title="$t('Switch To This Version')">
|
||||
</x-button>
|
||||
|
|
@ -88,8 +86,11 @@
|
|||
width="90">
|
||||
<p>{{$t('Delete?')}}</p>
|
||||
<div style="text-align: right; margin: 0;padding-top: 4px;">
|
||||
<x-button type="text" size="xsmall" shape="circle" @click="_closeDelete($index)">{{$t('Cancel')}}</x-button>
|
||||
<x-button type="primary" size="xsmall" shape="circle" @click="_mVersionDeleteProcessDefinitionVersion(item,$index)">{{$t('Confirm')}}</x-button>
|
||||
<x-button type="text" size="xsmall" shape="circle" @click="_closeDelete($index)">{{$t('Cancel')}}
|
||||
</x-button>
|
||||
<x-button type="primary" size="xsmall" shape="circle"
|
||||
@click="_mVersionDeleteProcessDefinitionVersion(item,$index)">{{$t('Confirm')}}
|
||||
</x-button>
|
||||
</div>
|
||||
<template slot="reference">
|
||||
<x-button
|
||||
|
|
@ -97,7 +98,7 @@
|
|||
type="error"
|
||||
shape="circle"
|
||||
size="xsmall"
|
||||
:disabled="item.version === processDefinition.version"
|
||||
:disabled="item.version === processDefinition.version || 'ONLINE' === processDefinition.state"
|
||||
data-toggle="tooltip"
|
||||
:title="$t('delete')">
|
||||
</x-button>
|
||||
|
|
@ -114,8 +115,9 @@
|
|||
|
||||
<div v-if="processDefinitionVersions.length > 0">
|
||||
<div class="bottom-box">
|
||||
<x-button type="text" @click="_close()"> {{$t('Cancel')}} </x-button>
|
||||
<x-page :current="pageNo" :total="total" @on-change="_mVersionGetProcessDefinitionVersionsPage" small><!----></x-page>
|
||||
<x-button type="text" @click="_close()"> {{$t('Cancel')}}</x-button>
|
||||
<x-page :current="pageNo" :total="total" @on-change="_mVersionGetProcessDefinitionVersionsPage" small>
|
||||
<!----></x-page>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -187,18 +189,14 @@
|
|||
* Close the switch version layer
|
||||
*/
|
||||
_closeSwitchVersion (i) {
|
||||
if (i > 0) {
|
||||
this.$refs[`poptip-switch-version-${i}`][0].doClose()
|
||||
}
|
||||
this.$refs[`poptip-switch-version-${i}`][0].doClose()
|
||||
},
|
||||
|
||||
/**
|
||||
* Close the delete layer
|
||||
*/
|
||||
_closeDelete (i) {
|
||||
if (i > 0) {
|
||||
this.$refs[`poptip-delete-${i}`][0].doClose()
|
||||
}
|
||||
this.$refs[`poptip-delete-${i}`][0].doClose()
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -211,8 +209,10 @@
|
|||
})
|
||||
}
|
||||
},
|
||||
created () {},
|
||||
mounted () {},
|
||||
created () {
|
||||
},
|
||||
mounted () {
|
||||
},
|
||||
components: { mNoData }
|
||||
}
|
||||
</script>
|
||||
|
|
@ -221,10 +221,12 @@
|
|||
.container {
|
||||
width: 500px;
|
||||
position: relative;
|
||||
|
||||
.title-box {
|
||||
height: 61px;
|
||||
border-bottom: 1px solid #DCDEDC;
|
||||
position: relative;
|
||||
|
||||
.name {
|
||||
position: absolute;
|
||||
left: 24px;
|
||||
|
|
@ -232,6 +234,7 @@
|
|||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-box {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
|
|
@ -242,10 +245,12 @@
|
|||
line-height: 60px;
|
||||
border-top: 1px solid #DCDEDC;
|
||||
background: #fff;
|
||||
|
||||
.ans-page {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
.table-box {
|
||||
overflow-y: scroll;
|
||||
height: calc(100vh - 61px);
|
||||
|
|
|
|||
|
|
@ -196,7 +196,8 @@ export default {
|
|||
copyProcess ({ state }, payload) {
|
||||
return new Promise((resolve, reject) => {
|
||||
io.post(`projects/${state.projectName}/process/copy`, {
|
||||
processId: payload.processId
|
||||
processDefinitionIds: payload.processDefinitionIds,
|
||||
targetProjectId: payload.targetProjectId
|
||||
}, res => {
|
||||
resolve(res)
|
||||
}).catch(e => {
|
||||
|
|
@ -205,6 +206,35 @@ export default {
|
|||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Get process definition DAG diagram details
|
||||
*/
|
||||
moveProcess ({ state }, payload) {
|
||||
return new Promise((resolve, reject) => {
|
||||
io.post(`projects/${state.projectName}/process/move`, {
|
||||
processDefinitionIds: payload.processDefinitionIds,
|
||||
targetProjectId: payload.targetProjectId
|
||||
}, res => {
|
||||
resolve(res)
|
||||
}).catch(e => {
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all the items created by the logged in user
|
||||
*/
|
||||
getAllItems ({ state }, payload) {
|
||||
return new Promise((resolve, reject) => {
|
||||
io.get(`projects/login-user-created-project`, {}, res => {
|
||||
resolve(res)
|
||||
}).catch(e => {
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the process instance DAG diagram details
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -638,5 +638,9 @@ export default {
|
|||
'Connection name': 'Connection name',
|
||||
'Current connection settings': 'Current connection settings',
|
||||
'Please save the DAG before formatting': 'Please save the DAG before formatting',
|
||||
'Batch copy': 'Batch copy'
|
||||
'Batch copy': 'Batch copy',
|
||||
'Related items': 'Related items',
|
||||
'Project name is required': 'Project name is required',
|
||||
'Batch move': 'Batch move',
|
||||
Version: 'Version'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -638,5 +638,9 @@ export default {
|
|||
'Connection name': '连线名',
|
||||
'Current connection settings': '当前连线设置',
|
||||
'Please save the DAG before formatting': '格式化前请先保存DAG',
|
||||
'Batch copy': '批量复制'
|
||||
'Batch copy': '批量复制',
|
||||
'Related items': '关联项目',
|
||||
'Project name is required': '项目名称必填',
|
||||
'Batch move': '批量移动',
|
||||
Version: '版本'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,3 @@ sh ${workDir}/script/remove-zk-node.sh $zkRoot
|
|||
# 6.startup
|
||||
echo "6.startup"
|
||||
sh ${workDir}/script/start-all.sh
|
||||
|
||||
# 7.query status
|
||||
echo "7.query status"
|
||||
sh ${workDir}/script/status-all.sh
|
||||
|
|
|
|||
3
pom.xml
3
pom.xml
|
|
@ -821,16 +821,19 @@
|
|||
<include>**/server/master/dispatch/host/assign/RandomSelectorTest.java</include>
|
||||
<include>**/server/master/dispatch/host/assign/RoundRobinSelectorTest.java</include>
|
||||
<include>**/server/master/register/MasterRegistryTest.java</include>
|
||||
<include>**/server/master/dispatch/host/assign/RoundRobinHostManagerTest.java</include>
|
||||
<include>**/server/master/AlertManagerTest.java</include>
|
||||
<include>**/server/master/MasterCommandTest.java</include>
|
||||
<include>**/server/master/DependentTaskTest.java</include>
|
||||
<include>**/server/master/ConditionsTaskTest.java</include>
|
||||
<include>**/server/master/MasterExecThreadTest.java</include>
|
||||
<include>**/server/master/ParamsTest.java</include>
|
||||
<include>**/server/master/SubProcessTaskTest.java</include>
|
||||
<include>**/server/register/ZookeeperNodeManagerTest.java</include>
|
||||
<include>**/server/utils/DataxUtilsTest.java</include>
|
||||
<include>**/server/utils/ExecutionContextTestUtils.java</include>
|
||||
<!--<include>**/server/utils/FlinkArgsUtilsTest.java</include>-->
|
||||
<include>**/server/utils/LogUtilsTest.java</include>
|
||||
<include>**/server/utils/ParamUtilsTest.java</include>
|
||||
<include>**/server/utils/ProcessUtilsTest.java</include>
|
||||
<include>**/server/utils/SparkArgsUtilsTest.java</include>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
usage="Usage: dolphinscheduler-daemon.sh (start|stop) <command> "
|
||||
usage="Usage: dolphinscheduler-daemon.sh (start|stop|status) <command> "
|
||||
|
||||
# if no args specified, show usage
|
||||
if [ $# -le 1 ]; then
|
||||
|
|
@ -29,7 +29,6 @@ shift
|
|||
command=$1
|
||||
shift
|
||||
|
||||
echo "Begin $startStop $command......"
|
||||
|
||||
BIN_DIR=`dirname $0`
|
||||
BIN_DIR=`cd "$BIN_DIR"; pwd`
|
||||
|
|
@ -122,11 +121,23 @@ case $startStop in
|
|||
fi
|
||||
;;
|
||||
|
||||
(status)
|
||||
# more details about the status can be added later
|
||||
serverCount=`ps -ef |grep "$CLASS" |grep -v "grep" |wc -l`
|
||||
state="STOP"
|
||||
# font color - red
|
||||
state="[ \033[1;31m $state \033[0m ]"
|
||||
if [[ $serverCount -gt 0 ]];then
|
||||
state="RUNNING"
|
||||
# font color - green
|
||||
state="[ \033[1;32m $state \033[0m ]"
|
||||
fi
|
||||
echo -e "$command $state"
|
||||
;;
|
||||
|
||||
(*)
|
||||
echo $usage
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
echo "End $startStop $command."
|
||||
|
|
|
|||
|
|
@ -54,4 +54,8 @@ for apiServer in ${apiServersHost[@]}
|
|||
do
|
||||
echo "$apiServer worker server is starting"
|
||||
ssh -p $sshPort $apiServer "cd $installPath/; sh bin/dolphinscheduler-daemon.sh start api-server;"
|
||||
done
|
||||
done
|
||||
|
||||
# query server status
|
||||
echo "query server status"
|
||||
cd $installPath/; sh bin/status-all.sh
|
||||
|
|
|
|||
|
|
@ -20,22 +20,59 @@ workDir=`dirname $0`
|
|||
workDir=`cd ${workDir};pwd`
|
||||
source $workDir/../conf/config/install_config.conf
|
||||
|
||||
# install_config.conf info
|
||||
echo -e '\n'
|
||||
echo "====================== dolphinscheduler install config============================="
|
||||
echo -e "1.dolphinscheduler server node install hosts:[ \033[1;32m ${ips} \033[0m ]"
|
||||
echo -e "2.master server node install hosts:[ \033[1;32m ${masters} \033[0m ]"
|
||||
echo -e "3.worker server node install hosts:[ \033[1;32m ${workers} \033[0m ]"
|
||||
echo -e "4.alert server node install hosts:[ \033[1;32m ${alertServer} \033[0m ]"
|
||||
echo -e "5.api server node install hosts:[ \033[1;32m ${apiServers} \033[0m ]"
|
||||
echo "====================== dolphinscheduler server config ============================="
|
||||
echo -e "1.dolphinscheduler server node config hosts:[ \033[1;32m ${ips} \033[0m ]"
|
||||
echo -e "2.master server node config hosts:[ \033[1;32m ${masters} \033[0m ]"
|
||||
echo -e "3.worker server node config hosts:[ \033[1;32m ${workers} \033[0m ]"
|
||||
echo -e "4.alert server node config hosts:[ \033[1;32m ${alertServer} \033[0m ]"
|
||||
echo -e "5.api server node config hosts:[ \033[1;32m ${apiServers} \033[0m ]"
|
||||
|
||||
# all server check state
|
||||
echo -e '\n'
|
||||
echo "====================== dolphinscheduler server status ============================="
|
||||
firstColumn="node server state"
|
||||
echo $firstColumn
|
||||
echo -e '\n'
|
||||
|
||||
declare -A workersGroupMap=()
|
||||
|
||||
ipsHost=(${ips//,/ })
|
||||
for ip in ${ipsHost[@]}
|
||||
workersGroup=(${workers//,/ })
|
||||
for workerGroup in ${workersGroup[@]}
|
||||
do
|
||||
echo -e "====================== [ \033[1;32m ${ip} \033[0m ] node all servers =========================="
|
||||
ssh -p $sshPort $ip "jps"
|
||||
echo -e '\n'
|
||||
worker=`echo $workerGroup|awk -F':' '{print $1}'`
|
||||
groupName=`echo $workerGroup|awk -F':' '{print $2}'`
|
||||
workersGroupMap+=([$worker]=$groupName)
|
||||
done
|
||||
|
||||
StateRunning="Running"
|
||||
# 1.master server check state
|
||||
mastersHost=(${masters//,/ })
|
||||
for master in ${mastersHost[@]}
|
||||
do
|
||||
masterState=`ssh -p $sshPort $master "cd $installPath/; sh bin/dolphinscheduler-daemon.sh status master-server;"`
|
||||
echo "$master $masterState"
|
||||
done
|
||||
|
||||
# 2.worker server and logger-server check state
|
||||
for worker in ${!workersGroupMap[*]}
|
||||
do
|
||||
workerState=`ssh -p $sshPort $worker "cd $installPath/; sh bin/dolphinscheduler-daemon.sh status worker-server;"`
|
||||
echo "$worker $workerState"
|
||||
|
||||
masterState=`ssh -p $sshPort $worker "cd $installPath/; sh bin/dolphinscheduler-daemon.sh status logger-server;"`
|
||||
echo "$worker $masterState"
|
||||
done
|
||||
|
||||
# 3.alter server check state
|
||||
alertState=`ssh -p $sshPort $alertServer "cd $installPath/; sh bin/dolphinscheduler-daemon.sh status alert-server;"`
|
||||
echo "$alertServer $alertState"
|
||||
|
||||
# 4.api server check state
|
||||
apiServersHost=(${apiServers//,/ })
|
||||
for apiServer in ${apiServersHost[@]}
|
||||
do
|
||||
apiState=`ssh -p $sshPort $apiServer "cd $installPath/; sh bin/dolphinscheduler-daemon.sh status api-server;"`
|
||||
echo "$apiServer $apiState"
|
||||
done
|
||||
|
|
|
|||
|
|
@ -54,4 +54,8 @@ for apiServer in ${apiServersHost[@]}
|
|||
do
|
||||
echo "$apiServer worker server is stopping"
|
||||
ssh -p $sshPort $apiServer "cd $installPath/; sh bin/dolphinscheduler-daemon.sh stop api-server;"
|
||||
done
|
||||
done
|
||||
|
||||
# query server status
|
||||
echo "query server status"
|
||||
cd $installPath/; sh bin/status-all.sh
|
||||
|
|
|
|||
Loading…
Reference in New Issue