Search in sources :

Example 16 with PluginDefineException

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

the class HiveConnFactory method getConnByTaskParams.

@Override
public Connection getConnByTaskParams(String taskParams, String jobName) throws ClassNotFoundException, SQLException, IOException {
    Properties properties = new Properties();
    Connection conn;
    properties.setProperty(HIVE_JOBNAME_PROPERTY, jobName);
    if (StringUtils.isNotEmpty(taskParams)) {
        for (String line : taskParams.split("\n")) {
            line = StringUtils.trim(line);
            if (StringUtils.isEmpty(line) || line.startsWith("#")) {
                continue;
            }
            String[] keyAndVal = line.split("=");
            if (keyAndVal.length > 1) {
                String newKey = keyAndVal[0].startsWith(HIVE_CONF_PREFIX) ? keyAndVal[0] : HIVE_CONF_PREFIX + keyAndVal[0];
                String newValue = keyAndVal[1];
                properties.setProperty(newKey, newValue);
            }
        }
    }
    try {
        conn = KerberosUtils.login(baseConfig, () -> {
            Connection connection;
            try {
                if (getUsername() != null) {
                    properties.setProperty(HIVE_USER, getUsername());
                    properties.setProperty(HIVE_PASSWORD, getPassword());
                }
                connection = DriverManager.getConnection(jdbcUrl, properties);
            } catch (Exception e) {
                throw new PluginDefineException(e);
            }
            return connection;
        }, yarnConf);
    } catch (Exception e) {
        throw new PluginDefineException("get connection by taskParams error", e);
    }
    return conn;
}
Also used : PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) Connection(java.sql.Connection) Properties(java.util.Properties) IOException(java.io.IOException) SQLException(java.sql.SQLException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 17 with PluginDefineException

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

the class DtYarnClient method testYarnConnect.

private ComponentTestResult testYarnConnect(ComponentTestResult testResult, Config allConfig) {
    try {
        HadoopConf hadoopConf = new HadoopConf();
        hadoopConf.initYarnConf(allConfig.getYarnConf());
        YarnClient testYarnClient = YarnClient.createYarnClient();
        testYarnClient.init(hadoopConf.getYarnConfiguration());
        testYarnClient.start();
        List<NodeReport> nodes = testYarnClient.getNodeReports(NodeState.RUNNING);
        int totalMemory = 0;
        int totalCores = 0;
        for (NodeReport rep : nodes) {
            totalMemory += rep.getCapability().getMemory();
            totalCores += rep.getCapability().getVirtualCores();
        }
        boolean isFullPath = hadoopConf.getYarnConfiguration().getBoolean(ConfigConstrant.IS_FULL_PATH_KEY, false);
        String rootQueueName = isFullPath ? getRootQueueName(testYarnClient) : "";
        List<ComponentTestResult.QueueDescription> descriptions = getQueueDescription(rootQueueName, testYarnClient.getRootQueueInfos(), isFullPath);
        testResult.setClusterResourceDescription(new ComponentTestResult.ClusterResourceDescription(nodes.size(), totalMemory, totalCores, descriptions));
    } catch (Exception e) {
        LOG.error("test yarn connect error", e);
        throw new PluginDefineException(e);
    }
    testResult.setResult(true);
    return testResult;
}
Also used : YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) IOException(java.io.IOException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) HadoopConf(com.dtstack.taier.yarn.util.HadoopConf) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport)

Example 18 with PluginDefineException

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

the class AbstractConnFactory method testConn.

public void testConn() {
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = getConn();
        stmt = conn.createStatement();
        stmt.execute(testSql);
    } catch (Exception e) {
        throw new PluginDefineException("get conn exception:" + e.toString());
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            LOG.error("", e);
        }
    }
}
Also used : Statement(java.sql.Statement) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) Connection(java.sql.Connection) SQLException(java.sql.SQLException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 19 with PluginDefineException

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

the class AddJarOperator method parseSql.

public static JarFileInfo parseSql(String sql) {
    Matcher matcher = pattern.matcher(sql);
    if (!matcher.find()) {
        throw new PluginDefineException("not a addJar operator:" + sql);
    }
    JarFileInfo jarFileInfo = new JarFileInfo();
    jarFileInfo.setJarPath(matcher.group(1));
    if (matcher.groupCount() == 3) {
        jarFileInfo.setMainClass(matcher.group(3));
    }
    return jarFileInfo;
}
Also used : JarFileInfo(com.dtstack.taier.pluginapi.JarFileInfo) Matcher(java.util.regex.Matcher) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Example 20 with PluginDefineException

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

the class PackagedProgram method getEntryPointClassNameFromJar.

private static String getEntryPointClassNameFromJar(URL jarFile) throws PluginDefineException {
    JarFile jar;
    Manifest manifest;
    String className;
    // Open jar file
    try {
        jar = new JarFile(new File(jarFile.toURI()));
    } catch (URISyntaxException use) {
        throw new PluginDefineException("Invalid file path '" + jarFile.getPath() + "'", use);
    } catch (IOException ioex) {
        throw new PluginDefineException("Error while opening jar file '" + jarFile.getPath() + "'. " + ioex.getMessage(), ioex);
    }
    // jar file must be closed at the end
    try {
        // Read from jar manifest
        try {
            manifest = jar.getManifest();
        } catch (IOException ioex) {
            throw new PluginDefineException("The Manifest in the jar file could not be accessed '" + jarFile.getPath() + "'. " + ioex.getMessage(), ioex);
        }
        if (manifest == null) {
            throw new PluginDefineException("No manifest found in jar file '" + jarFile.getPath() + "'. The manifest is need to point to the program's main class.");
        }
        Attributes attributes = manifest.getMainAttributes();
        // check for a "program-class" entry first
        className = attributes.getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
        if (className != null) {
            return className;
        }
        // check for a main class
        className = attributes.getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
        if (className != null) {
            return className;
        } else {
            throw new PluginDefineException("Neither a '" + MANIFEST_ATTRIBUTE_MAIN_CLASS + "', nor a '" + MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS + "' entry was found in the jar file.");
        }
    } finally {
        try {
            if (jar != null) {
                jar.close();
            }
        } catch (Exception e) {
        }
    }
}
Also used : PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) Attributes(java.util.jar.Attributes) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) File(java.io.File) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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