Search in sources :

Example 31 with PluginDefineException

use of com.dtstack.taier.pluginapi.exception.PluginDefineException in project Taier by DTStack.

the class AcceptedApplicationMonitor method run.

@Override
public void run() {
    try (YarnClient yarnClient = KerberosUtils.login(config, () -> {
        YarnClient client = YarnClient.createYarnClient();
        client.init(yarnConf);
        client.start();
        return client;
    }, yarnConf)) {
        EnumSet<YarnApplicationState> enumSet = EnumSet.noneOf(YarnApplicationState.class);
        enumSet.add(YarnApplicationState.ACCEPTED);
        if (yarnClient == null) {
            throw new PluginDefineException("AcceptedApplicationMonitor init yarnClient fail");
        }
        List<ApplicationReport> acceptedApps = yarnClient.getApplications(enumSet).stream().filter(report -> report.getQueue().endsWith(queueName)).collect(Collectors.toList());
        for (ApplicationReport report : acceptedApps) {
            long startTime = report.getStartTime();
            long currentTime = System.currentTimeMillis();
            if (currentTime - startTime > THRESHOLD) {
                ApplicationId appId = report.getApplicationId();
                yarnClient.killApplication(appId);
            }
        }
    } catch (Exception e) {
        logger.error("Monitor Accepted Application Exception: " + e.getMessage());
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) Logger(org.slf4j.Logger) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) LoggerFactory(org.slf4j.LoggerFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collectors(java.util.stream.Collectors) KerberosUtils(com.dtstack.taier.base.util.KerberosUtils) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) BaseConfig(com.dtstack.taier.base.BaseConfig) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) EnumSet(java.util.EnumSet) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 32 with PluginDefineException

use of com.dtstack.taier.pluginapi.exception.PluginDefineException in project Taier by DTStack.

the class SftpFileManage method downloadDir.

/**
 * download 后自动释放连接
 *
 * @param remoteDir
 * @param localDir
 * @return
 */
public boolean downloadDir(String remoteDir, String localDir) {
    ChannelSftp channelSftp = null;
    try {
        // 检查并创建本地文件目录
        File localDirPath = new File(localDir);
        if (!localDirPath.exists()) {
            boolean mkdirs = localDirPath.mkdirs();
            LOGGER.info("local file localDir {}  mkdir {} :", localDir, mkdirs);
        }
        channelSftp = getChannelSftp();
        Vector files = channelSftp.ls(remoteDir);
        if (files == null) {
            return false;
        }
        // 递归下载文件
        for (Iterator<ChannelSftp.LsEntry> iterator = files.iterator(); iterator.hasNext(); ) {
            ChannelSftp.LsEntry str = iterator.next();
            String filename = str.getFilename();
            if (".".equals(filename) || "..".equals(filename)) {
                continue;
            }
            SftpATTRS attrs = str.getAttrs();
            boolean isdir = attrs.isDir();
            String localFilePath = localDir + "/" + filename;
            String ftpFilePath;
            if (channelSftp.stat(remoteDir).isDir()) {
                ftpFilePath = remoteDir + "/" + filename;
            } else {
                ftpFilePath = remoteDir;
            }
            if (isdir) {
                File dir2 = new File(localFilePath);
                if (!dir2.exists()) {
                    LOGGER.info("local file path mkdir :", localFilePath);
                    dir2.mkdir();
                }
                downloadDir(ftpFilePath, localFilePath);
            } else {
                downloadFile(ftpFilePath, localFilePath, channelSftp);
            }
        }
        return true;
    } catch (Exception e) {
        LOGGER.error("sftp downloadDir error {}", e);
        throw new PluginDefineException(e);
    } finally {
        close(channelSftp);
    }
}
Also used : PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) File(java.io.File) Vector(java.util.Vector) IOException(java.io.IOException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 33 with PluginDefineException

use of com.dtstack.taier.pluginapi.exception.PluginDefineException in project Taier by DTStack.

the class SftpFileManage method listFile.

public Vector listFile(String remotePath) {
    ChannelSftp channelSftp = null;
    try {
        channelSftp = getChannelSftp();
        Vector vector = channelSftp.ls(remotePath);
        return vector;
    } catch (SftpException e) {
        LOGGER.error("listFile  error", e);
        throw new PluginDefineException(e);
    } finally {
        close(channelSftp);
    }
}
Also used : PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) Vector(java.util.Vector)

Example 34 with PluginDefineException

use of com.dtstack.taier.pluginapi.exception.PluginDefineException in project Taier by DTStack.

the class UrlUtil method getHttpRootUrl.

/**
 * 返回URL请求的 ${域名:port}部分
 * @return
 */
public static String getHttpRootUrl(String url) {
    Matcher matcher = URLPattern.matcher(url);
    if (!matcher.find()) {
        throw new PluginDefineException(String.format("url:%s is not regular HTTP_URL", url));
    }
    String protocol = matcher.group(1) == null ? "http" : matcher.group(1);
    String hostName = matcher.group(2);
    String port = matcher.group(3);
    if (port == null) {
        return protocol + "://" + hostName;
    } else {
        return protocol + "://" + hostName + ":" + port;
    }
}
Also used : Matcher(java.util.regex.Matcher) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 35 with PluginDefineException

use of com.dtstack.taier.pluginapi.exception.PluginDefineException in project Taier by DTStack.

the class HadoopClient method downloadHdfsFile.

private void downloadHdfsFile(String from, String to) throws IOException {
    try {
        KerberosUtils.login(config, () -> {
            try {
                File toFile = new File(to);
                if (!toFile.getParentFile().exists()) {
                    Files.createParentDirs(toFile);
                }
                Path hdfsFilePath = new Path(from);
                // 读取文件
                InputStream is = FileSystem.get(conf).open(hdfsFilePath);
                // 保存到本地
                IOUtils.copyBytes(is, new FileOutputStream(toFile), 2048, true);
            } catch (Exception e) {
                throw new PluginDefineException(e);
            }
            return null;
        }, conf);
    } catch (Exception e) {
        LOG.error("", e);
        throw new PluginDefineException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Aggregations

PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)58 IOException (java.io.IOException)30 File (java.io.File)13 MalformedURLException (java.net.MalformedURLException)13 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)11 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)10 JarFileInfo (com.dtstack.taier.pluginapi.JarFileInfo)8 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)8 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)7 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)7 ClusterClient (org.apache.flink.client.program.ClusterClient)6 JSONObject (com.alibaba.fastjson.JSONObject)5 Configuration (org.apache.flink.configuration.Configuration)5 Path (org.apache.hadoop.fs.Path)5 KerberosUtils (com.dtstack.taier.base.util.KerberosUtils)4 FlinkConfig (com.dtstack.taier.flink.FlinkConfig)4 ConfigConstant (com.dtstack.taier.pluginapi.constrant.ConfigConstant)4 URL (java.net.URL)4 Matcher (java.util.regex.Matcher)4