use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class CliEnvironment method finishInitialization.
/**
* Gives CliEnvironment a chance to apply settings, especially during initialization, things like
* making default values take effect
*/
public void finishInitialization() throws CliException {
if (executor == null) {
try {
createShellExecutor(CliConstants.DEFAULT_EXECUTOR_CLASS);
activeExecutorClassName = CliConstants.DEFAULT_EXECUTOR_CLASS;
executorEnvHandler = executor.getEnvironmentVariableHandler();
if (delayedExecutorVars != null) {
for (Map.Entry<String, String> entry : delayedExecutorVars.entrySet()) {
setEnvironmentVariable(entry.getKey(), entry.getValue());
}
delayedExecutorVars = null;
}
} catch (ExecutorException | CommandHandlerException e) {
// we have failed to create even the default executor thus not recoverable
throw new CliException(e);
}
}
finishInitialization(shellEnvHandler);
finishInitialization(executorEnvHandler);
}
use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class CliEnvironment method createInstance.
private Object createInstance(String className) throws Exception {
try {
Class<?> clazz = Class.forName(className);
Constructor<?> ctor = clazz.getConstructor();
return ctor.newInstance();
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new ExecutorException(e);
}
}
use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class Main method main.
public static void main(String[] args) {
// Get configuration file path
String configFilePath = null;
for (int i = 0; i < args.length; ++i) {
switch(args[i]) {
case "-conf":
if (i + 1 < args.length) {
configFilePath = args[i + 1];
i++;
}
break;
default:
LOG.warn("Unknown parameter {}", args[i]);
break;
}
}
CliEnvironment environment = new CliEnvironment();
StringBuilder messageBuilder = new StringBuilder();
if (!CliUtil.isNullOrEmpty(configFilePath)) {
LOG.info("Configuration file path is: {}", configFilePath);
try {
FileReader fileReader = new FileReader(configFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.startsWith("#") || line.startsWith("[")) {
continue;
}
String[] strs = line.split("=");
if (strs.length != 2) {
continue;
}
String key = strs[0].trim().toLowerCase();
String value = strs[1].trim();
try {
LOG.info("Configuration: setting {} = {}", key, value);
int result = environment.setEnvironmentVariable(key, value);
if (result == -1) {
// CliEnvironment doesn't recognize the key.
LOG.warn("Unknowing shell environment variable: {}", key);
} else if (result == -2) {
// Invalid value
LOG.warn("Unknowing shell environment value: {}", value);
}
} catch (ExecutorException e) {
messageBuilder.append("Warning: Failed to create executor: ").append(value).append('\n');
messageBuilder.append("Warning: Using default executor " + CliConstants.DEFAULT_EXECUTOR_CLASS);
LOG.error("Failed to create user specified executor {}", value, e);
} catch (CommandHandlerException e) {
messageBuilder.append("Warning: Failed to create CommandHandler: ").append(value).append('\n');
LOG.error("Failed to create user specified CommandHandler {}", value, e);
}
}
} catch (IOException e) {
LOG.error("Error in opening and reading the configuration file {}", e.toString());
}
}
environment.finishInitialization();
CliShell shell;
try {
shell = new CliShell(environment);
} catch (ExecutorException e) {
System.out.println("Unable to initialize executor. Shell must exit. ");
LOG.error("Unable to initialize executor.", e);
return;
}
shell.open(messageBuilder.toString());
}
use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class SamzaExecutor method executeQuery.
@Override
public QueryResult executeQuery(ExecutionContext context, String statement) throws ExecutorException {
outputData.clear();
int execId = execIdSeq.incrementAndGet();
Map<String, String> staticConfigs = fetchSamzaSqlConfig(execId);
List<String> sqlStmts = formatSqlStmts(Collections.singletonList(statement));
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
SamzaSqlApplicationRunner runner;
try {
runner = new SamzaSqlApplicationRunner(true, new MapConfig(staticConfigs));
runner.run(null);
} catch (SamzaException ex) {
throw new ExecutorException(ex);
}
executions.put(execId, runner);
LOG.debug("Executing sql. Id ", execId);
SqlSchema resultSchema = null;
// resultSchema = generateResultSchema(new MapConfig(staticConfigs));
return new QueryResult(execId, resultSchema);
}
Aggregations