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;
}
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;
}
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);
}
}
}
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;
}
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) {
}
}
}
Aggregations