2016-05-03 15:17:38 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2015 LinkedIn Corp. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
package actors;
|
|
|
|
|
2016-05-30 08:59:05 +02:00
|
|
|
import metadata.etl.Launcher;
|
|
|
|
import metadata.etl.models.EtlJobName;
|
|
|
|
import wherehows.common.Constant;
|
|
|
|
|
2016-05-03 15:17:38 -07:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility class for generate cmd, write and delete config files.
|
|
|
|
*/
|
2016-05-30 08:59:05 +02:00
|
|
|
class ConfigUtil {
|
2016-05-03 15:17:38 -07:00
|
|
|
|
2016-05-30 08:59:05 +02:00
|
|
|
private static final String javaCmd = "java";
|
|
|
|
private static final String WH_APPLICATION_DEFAULT_DIRECTORY = "/var/tmp/wherehows";
|
2016-05-03 15:17:38 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the config file in the 'wherehows.app_folder' folder
|
|
|
|
* The file name is {whEtlExecId}.config
|
2016-05-30 08:59:05 +02:00
|
|
|
*
|
2016-05-03 15:17:38 -07:00
|
|
|
* @param etlJobName
|
|
|
|
* @param refId
|
|
|
|
* @param whEtlExecId
|
|
|
|
* @param props
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-30 08:59:05 +02:00
|
|
|
static void generateProperties(EtlJobName etlJobName, int refId, long whEtlExecId, Properties props)
|
|
|
|
throws IOException {
|
2016-05-03 15:17:38 -07:00
|
|
|
|
|
|
|
props.setProperty(Launcher.JOB_NAME_KEY, etlJobName.name());
|
|
|
|
props.setProperty(Launcher.REF_ID_KEY, String.valueOf(refId));
|
|
|
|
props.setProperty(Launcher.WH_ETL_EXEC_ID_KEY, String.valueOf(whEtlExecId));
|
|
|
|
|
2016-05-30 08:59:05 +02:00
|
|
|
String dirName = props.getProperty(Constant.WH_APP_FOLDER_KEY, WH_APPLICATION_DEFAULT_DIRECTORY) + "/exec";
|
2016-05-03 15:17:38 -07:00
|
|
|
File dir = new File(dirName);
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdir();
|
|
|
|
}
|
|
|
|
File configFile = new File(dirName, whEtlExecId + ".properties");
|
|
|
|
FileWriter writer = new FileWriter(configFile);
|
|
|
|
props.store(writer, "exec id : " + whEtlExecId + " job configurations");
|
|
|
|
writer.close();
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:59:05 +02:00
|
|
|
static void deletePropertiesFile(Properties props, long whEtlExecId) {
|
|
|
|
String dirName = props.getProperty(Constant.WH_APP_FOLDER_KEY, WH_APPLICATION_DEFAULT_DIRECTORY) + "/exec";
|
2016-05-03 15:17:38 -07:00
|
|
|
File configFile = new File(dirName, whEtlExecId + ".properties");
|
|
|
|
if (configFile.exists()) {
|
|
|
|
configFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-23 16:54:52 -07:00
|
|
|
static String generateCommand(EtlJobName etlJobName, long whEtlExecId, String cmdParam, Properties etlJobProperties) {
|
2016-05-03 15:17:38 -07:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(javaCmd);
|
|
|
|
sb.append(cmdParam).append(" ");
|
2016-05-30 08:59:05 +02:00
|
|
|
|
2016-05-03 15:17:38 -07:00
|
|
|
String classPath = System.getProperty("java.class.path");
|
2017-03-24 22:57:24 -07:00
|
|
|
sb.append("-cp ").append(classPath);
|
2016-05-30 08:59:05 +02:00
|
|
|
|
|
|
|
String directoryPath = etlJobProperties.getProperty(Constant.WH_APP_FOLDER_KEY, WH_APPLICATION_DEFAULT_DIRECTORY);
|
2017-03-24 22:57:24 -07:00
|
|
|
String configFile = directoryPath + "/exec/" + whEtlExecId + ".properties";
|
|
|
|
sb.append(" -Dconfig=").append(configFile);
|
|
|
|
sb.append(" -DCONTEXT=").append(etlJobName.name());
|
2016-05-30 08:59:05 +02:00
|
|
|
|
2017-03-24 22:57:24 -07:00
|
|
|
sb.append(" metadata.etl.Launcher");
|
2016-05-03 15:17:38 -07:00
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
}
|