Search in sources :

Example 1 with RdosDefineException

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]);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartFile(org.springframework.web.multipart.MultipartFile) JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) JSONObject(com.alibaba.fastjson.JSONObject) Method(java.lang.reflect.Method) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Before(org.aspectj.lang.annotation.Before)

Example 2 with RdosDefineException

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);
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IClient(com.dtstack.taier.pluginapi.client.IClient) Properties(java.util.Properties) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException)

Example 3 with RdosDefineException

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;
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IClient(com.dtstack.taier.pluginapi.client.IClient) JSONObject(com.alibaba.fastjson.JSONObject) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 4 with RdosDefineException

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;
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) DateTime(org.joda.time.DateTime)

Example 5 with RdosDefineException

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);
    }
}
Also used : IComponentVO(com.dtstack.taier.scheduler.vo.IComponentVO) ClusterTenantMapper(com.dtstack.taier.dao.mapper.ClusterTenantMapper) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) MathUtil(com.dtstack.taier.common.util.MathUtil) ComponentService(com.dtstack.taier.scheduler.service.ComponentService) Keytab(org.apache.kerby.kerberos.kerb.keytab.Keytab) MD5Util(com.dtstack.taier.pluginapi.util.MD5Util) QueueService(com.dtstack.taier.scheduler.service.QueueService) DictType(com.dtstack.taier.common.enums.DictType) Xml2JsonUtil(com.dtstack.taier.common.util.Xml2JsonUtil) ComponentVersionUtil(com.dtstack.taier.common.util.ComponentVersionUtil) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) PublicUtil(com.dtstack.taier.pluginapi.util.PublicUtil) ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) DownloadType(com.dtstack.taier.common.enums.DownloadType) WorkerOperator(com.dtstack.taier.scheduler.WorkerOperator) Krb5FileUtil(com.dtstack.taier.scheduler.utils.Krb5FileUtil) Resource(com.dtstack.taier.dao.dto.Resource) ConfigConstant(com.dtstack.taier.pluginapi.constrant.ConfigConstant) JSONObject(com.alibaba.fastjson.JSONObject) PartCluster(com.dtstack.taier.develop.model.PartCluster) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) BeanUtils(org.springframework.beans.BeanUtils) java.util(java.util) ZipUtil(com.dtstack.taier.common.util.ZipUtil) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Part(com.dtstack.taier.develop.model.Part) SftpFileManage(com.dtstack.taier.pluginapi.sftp.SftpFileManage) ClusterFactory(com.dtstack.taier.develop.model.ClusterFactory) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterMapper(com.dtstack.taier.dao.mapper.ClusterMapper) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) JSONArray(com.alibaba.fastjson.JSONArray) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) ComponentConfigUtils(com.dtstack.taier.scheduler.utils.ComponentConfigUtils) ConsoleKerberosMapper(com.dtstack.taier.dao.mapper.ConsoleKerberosMapper) com.dtstack.taier.dao.domain(com.dtstack.taier.dao.domain) Logger(org.slf4j.Logger) MapUtils(org.apache.commons.collections.MapUtils) ExceptionUtil(com.dtstack.taier.pluginapi.exception.ExceptionUtil) XmlFileUtil(com.dtstack.taier.scheduler.utils.XmlFileUtil) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) ScheduleDictService(com.dtstack.taier.scheduler.service.ScheduleDictService) File(java.io.File) ComponentMapper(com.dtstack.taier.dao.mapper.ComponentMapper) SftpConfig(com.dtstack.taier.pluginapi.sftp.SftpConfig) EComponentType(com.dtstack.taier.common.enums.EComponentType) TimeUnit(java.util.concurrent.TimeUnit) ZIP_SUFFIX(com.dtstack.taier.common.constant.CommonConstant.ZIP_SUFFIX) ComponentConfigService(com.dtstack.taier.scheduler.service.ComponentConfigService) PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) Transactional(org.springframework.transaction.annotation.Transactional) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) PartCluster(com.dtstack.taier.develop.model.PartCluster) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)176 JSONObject (com.alibaba.fastjson.JSONObject)80 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)20 EComponentType (com.dtstack.taier.common.enums.EComponentType)18 List (java.util.List)18 JSONArray (com.alibaba.fastjson.JSONArray)17 File (java.io.File)16 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)15 Transactional (org.springframework.transaction.annotation.Transactional)15 BatchTask (com.dtstack.taier.dao.domain.BatchTask)14 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)13 Map (java.util.Map)13 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)10 Component (com.dtstack.taier.dao.domain.Component)10 Resource (com.dtstack.taier.dao.dto.Resource)10 HashMap (java.util.HashMap)10 CollectionUtils (org.apache.commons.collections.CollectionUtils)10 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)9 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)9