use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class FileUploadAspect method before.
/**
* 文件上传前处理,生产临时文件
* @param joinPoint
* @throws Throwable
*/
@Before("fileUploadPointCut()")
public void before(JoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
if (args.length < 2) {
throw new RdosDefineException("upload method args less than 2.");
}
if (!MultipartFile.class.isAssignableFrom(args[1].getClass())) {
throw new RdosDefineException("upload method args[1] not AssignableFrom MultipartFile.");
}
MultipartFile file = (MultipartFile) args[1];
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
if (file != null) {
String originalFilename = file.getOriginalFilename();
String fileName = UUID.randomUUID() + "_" + originalFilename;
String tmpPath = System.getProperty("user.dir") + File.separator + "upload" + File.separator + fileName;
File tmpFile = new File(tmpPath);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
file.transferTo(tmpFile);
Class clazz = args[0].getClass();
Method tmpPathMethod = clazz.getDeclaredMethod("setTmpPath", String.class);
Method originalFilenameMethod = clazz.getDeclaredMethod("setOriginalFilename", String.class);
tmpPathMethod.invoke(args[0], tmpPath);
originalFilenameMethod.invoke(args[0], originalFilename);
JSONObject bodyJson = (JSONObject) request.getAttribute(DtRequestWrapperFilter.DT_REQUEST_BODY);
Object cjObj = JSON.toJavaObject(bodyJson, clazz);
PublicUtil.copyPropertiesIgnoreNull(args[0], cjObj);
PublicUtil.copyPropertiesIgnoreNull(cjObj, args[0]);
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class ClientCache method getClient.
/**
* @param pluginInfo 集群配置信息
* @return
*/
public IClient getClient(String pluginInfo) throws ClientAccessException {
String typeName = "";
try {
if (StringUtils.isBlank(pluginInfo)) {
throw new RdosDefineException("plugin info is empty");
}
Properties properties = PublicUtil.jsonStrToObjectWithOutNull(pluginInfo, Properties.class);
typeName = properties.getProperty(ConfigConstant.TYPE_NAME_KEY);
if (StringUtils.isBlank(typeName)) {
throw new RdosDefineException("typeName is empty");
}
String md5plugin = MD5Util.getMd5String(pluginInfo);
String md5sum = null;
if (!properties.containsKey(MD5_SUM_KEY) || (md5sum = MathUtil.getString(properties.get(MD5_SUM_KEY))) == null) {
String md5zip = MathUtil.getString(properties.get(MD5_ZIP_KEY));
if (md5zip == null) {
md5zip = "";
}
md5sum = md5zip + md5plugin;
properties.setProperty(MD5_SUM_KEY, md5sum);
}
Map<String, IClient> clientMap = cache.computeIfAbsent(typeName, k -> Maps.newConcurrentMap());
IClient client = clientMap.get(md5sum);
if (client == null) {
synchronized (clientMap) {
client = clientMap.get(md5sum);
if (client == null) {
client = ClientFactory.buildPluginClient(pluginInfo, pluginPath);
client.init(properties);
clientMap.putIfAbsent(md5sum, client);
}
}
}
return client;
} catch (Throwable e) {
LOGGER.error("------- typeName {} plugin info {} get client error ", typeName, pluginInfo, e);
throw new ClientAccessException(e);
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class ClientOperator method getJobStatus.
public TaskStatus getJobStatus(String pluginInfo, JobIdentifier jobIdentifier) {
checkoutOperator(pluginInfo, jobIdentifier);
String jobId = jobIdentifier.getEngineJobId();
if (Strings.isNullOrEmpty(jobId) && Strings.isNullOrEmpty(jobIdentifier.getApplicationId())) {
throw new RdosDefineException("can't get job of jobId is empty or null!");
}
try {
IClient client = clientCache.getClient(pluginInfo);
Object result = client.getJobStatus(jobIdentifier);
if (result == null) {
return null;
}
return (TaskStatus) result;
} catch (Exception e) {
LOGGER.error("getStatus happens error:{}", jobId, e);
return TaskStatus.NOTFOUND;
}
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class ScheduleFactory method parseFromJson.
public static ScheduleCron parseFromJson(String jsonStr) throws IOException, ParseException {
Map<String, Object> jsonMap = objMapper.readValue(jsonStr, Map.class);
Preconditions.checkState(jsonMap.containsKey(PERIOD_TYPE_KEY), "schedule param must contain " + PERIOD_TYPE_KEY);
Preconditions.checkNotNull(jsonMap.containsKey(BEGIN_DATE_KEY), "schedule param must contain " + BEGIN_DATE_KEY);
Preconditions.checkNotNull(jsonMap.containsKey(END_DATE_KEY), "schedule param must contain " + END_DATE_KEY);
int periodType = MathUtil.getIntegerVal(jsonMap.get(PERIOD_TYPE_KEY));
ScheduleCron scheduleCron = null;
if (periodType == ESchedulePeriodType.MONTH.getVal()) {
scheduleCron = new ScheduleCronMonthParser();
} else if (periodType == ESchedulePeriodType.WEEK.getVal()) {
scheduleCron = new ScheduleCronWeekParser();
} else if (periodType == ESchedulePeriodType.DAY.getVal()) {
scheduleCron = new ScheduleCronDayParser();
} else if (periodType == ESchedulePeriodType.HOUR.getVal()) {
scheduleCron = new ScheduleCronHourParser();
} else if (periodType == ESchedulePeriodType.MIN.getVal()) {
scheduleCron = new ScheduleCronMinParser();
} else if (periodType == ESchedulePeriodType.CRON.getVal()) {
scheduleCron = new ScheduleCronParser();
} else {
throw new RdosDefineException("not support period type!");
}
String beginDateStr = (String) jsonMap.get(BEGIN_DATE_KEY);
String endDateStr = (String) jsonMap.get(END_DATE_KEY);
if (jsonMap.containsKey(SELFRELIANCE_KEY)) {
String obj = MapUtils.getString(jsonMap, SELFRELIANCE_KEY);
Integer type = MathUtil.getIntegerVal(obj);
scheduleCron.setSelfReliance(type);
}
DateTime beginDateTime = timeFormatter.parseDateTime(beginDateStr + " 00:00:00");
DateTime endDateTime = timeFormatter.parseDateTime(endDateStr + " 23:59:59");
scheduleCron.setBeginDate(beginDateTime.toDate());
scheduleCron.setEndDate(endDateTime.toDate());
scheduleCron.setPeriodType(periodType);
scheduleCron.parse(jsonMap);
return scheduleCron;
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class ConsoleComponentService method testConnects.
/**
* 测试所有组件连通性
*
* @param clusterName
* @return
*/
public List<ComponentMultiTestResult> testConnects(String clusterName) {
Cluster cluster = clusterMapper.getByClusterName(clusterName);
List<Component> components = getComponents(cluster);
if (CollectionUtils.isEmpty(components)) {
return new ArrayList<>();
}
Map sftpMap = componentService.getComponentByClusterId(cluster.getId(), EComponentType.SFTP.getTypeCode(), false, Map.class, null);
Map<Component, CompletableFuture<ComponentTestResult>> completableFutureMap = components.stream().collect(Collectors.toMap(component -> component, c -> CompletableFuture.supplyAsync(() -> testComponentWithResult(clusterName, cluster, sftpMap, c), connectPool)));
CompletableFuture<List<ComponentTestResult>> completableFuture = CompletableFuture.allOf(completableFutureMap.values().toArray(new CompletableFuture[0])).thenApply((f) -> completableFutureMap.keySet().stream().map(component -> {
try {
return completableFutureMap.get(component).get(env.getTestConnectTimeout(), TimeUnit.SECONDS);
} catch (Exception e) {
ComponentTestResult testResult = new ComponentTestResult();
testResult.setResult(false);
testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
testResult.setComponentVersion(component.getVersionValue());
testResult.setComponentTypeCode(component.getComponentTypeCode());
return testResult;
}
}).collect(Collectors.toList()));
try {
List<ComponentTestResult> componentTestResults = completableFuture.get();
Map<Integer, List<ComponentTestResult>> componentCodeResultMap = componentTestResults.stream().collect(Collectors.groupingBy(ComponentTestResult::getComponentTypeCode, Collectors.collectingAndThen(Collectors.toList(), c -> c)));
return componentCodeResultMap.keySet().stream().map(componentCode -> {
ComponentMultiTestResult multiTestResult = new ComponentMultiTestResult(componentCode);
multiTestResult.setMultiVersion(componentCodeResultMap.get(componentCode));
List<ComponentTestResult> testResults = componentCodeResultMap.get(componentCode);
multiTestResult.setResult(testResults.stream().allMatch(ComponentTestResult::getResult));
testResults.stream().filter(componentTestResult -> StringUtils.isNotBlank(componentTestResult.getErrorMsg())).findFirst().ifPresent(errorResult -> multiTestResult.setErrorMsg(errorResult.getErrorMsg()));
return multiTestResult;
}).collect(Collectors.toList());
} catch (Exception e) {
throw new RdosDefineException(e);
}
}
Aggregations