Search in sources :

Example 6 with ExecutorException

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);
}
Also used : CommandHandlerException(org.apache.samza.sql.client.exceptions.CommandHandlerException) ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) CliException(org.apache.samza.sql.client.exceptions.CliException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ExecutorException

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);
    }
}
Also used : ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with ExecutorException

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());
}
Also used : CommandHandlerException(org.apache.samza.sql.client.exceptions.CommandHandlerException) ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 9 with ExecutorException

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);
}
Also used : ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) SamzaSqlApplicationRunner(org.apache.samza.sql.runner.SamzaSqlApplicationRunner) SqlSchema(org.apache.samza.sql.schema.SqlSchema) SamzaException(org.apache.samza.SamzaException)

Aggregations

ExecutorException (org.apache.samza.sql.client.exceptions.ExecutorException)9 SamzaException (org.apache.samza.SamzaException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CommandHandlerException (org.apache.samza.sql.client.exceptions.CommandHandlerException)2 ExecutionStatus (org.apache.samza.sql.client.interfaces.ExecutionStatus)2 SamzaSqlApplicationRunner (org.apache.samza.sql.runner.SamzaSqlApplicationRunner)2 SqlSchema (org.apache.samza.sql.schema.SqlSchema)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CliException (org.apache.samza.sql.client.exceptions.CliException)1 RelSchemaProvider (org.apache.samza.sql.interfaces.RelSchemaProvider)1 SqlIOConfig (org.apache.samza.sql.interfaces.SqlIOConfig)1 SqlIOResolver (org.apache.samza.sql.interfaces.SqlIOResolver)1 SamzaSqlApplicationConfig (org.apache.samza.sql.runner.SamzaSqlApplicationConfig)1 AttributedStringBuilder (org.jline.utils.AttributedStringBuilder)1 AttributedStyle (org.jline.utils.AttributedStyle)1