Search in sources :

Example 1 with ApplicationConfig

use of org.apache.samza.config.ApplicationConfig in project samza by apache.

the class JobGraphJsonGenerator method toJson.

/**
   * Returns the JSON representation of a {@link JobGraph}
   * @param jobGraph {@link JobGraph}
   * @return JSON of the graph
   * @throws Exception exception during creating JSON
   */
/* package private */
String toJson(JobGraph jobGraph) throws Exception {
    JobGraphJson jobGraphJson = new JobGraphJson();
    // build StreamEdge JSON
    ApplicationConfig appConfig = jobGraph.getApplicationConfig();
    jobGraphJson.applicationName = appConfig.getAppName();
    jobGraphJson.applicationId = appConfig.getAppId();
    jobGraphJson.sourceStreams = new HashMap<>();
    jobGraphJson.sinkStreams = new HashMap<>();
    jobGraphJson.intermediateStreams = new HashMap<>();
    jobGraph.getSources().forEach(e -> buildStreamEdgeJson(e, jobGraphJson.sourceStreams));
    jobGraph.getSinks().forEach(e -> buildStreamEdgeJson(e, jobGraphJson.sinkStreams));
    jobGraph.getIntermediateStreamEdges().forEach(e -> buildStreamEdgeJson(e, jobGraphJson.intermediateStreams));
    jobGraphJson.jobs = jobGraph.getJobNodes().stream().map(jobNode -> buildJobNodeJson(jobNode)).collect(Collectors.toList());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(out, jobGraphJson);
    return new String(out.toByteArray());
}
Also used : ApplicationConfig(org.apache.samza.config.ApplicationConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with ApplicationConfig

use of org.apache.samza.config.ApplicationConfig in project samza by apache.

the class TaskFactoryUtil method createStreamApplication.

/**
   * Returns {@link StreamApplication} if it's configured, otherwise null.
   * @param config Config
   * throws {@link ConfigException} if there is misconfiguration of StreamApp.
   * @return {@link StreamApplication} instance
   */
public static StreamApplication createStreamApplication(Config config) {
    ApplicationConfig appConfig = new ApplicationConfig(config);
    if (appConfig.getAppClass() != null && !appConfig.getAppClass().isEmpty()) {
        TaskConfig taskConfig = new TaskConfig(config);
        if (taskConfig.getTaskClass() != null && !taskConfig.getTaskClass().isEmpty()) {
            throw new ConfigException("High level StreamApplication API cannot be used together with low-level API using task.class.");
        }
        String appClassName = appConfig.getAppClass();
        try {
            Class<?> builderClass = Class.forName(appClassName);
            return (StreamApplication) builderClass.newInstance();
        } catch (Throwable t) {
            String errorMsg = String.format("Failed to create StreamApplication class from the config. %s = %s", ApplicationConfig.APP_CLASS, appConfig.getAppClass());
            log.error(errorMsg, t);
            throw new ConfigException(errorMsg, t);
        }
    } else {
        return null;
    }
}
Also used : ApplicationConfig(org.apache.samza.config.ApplicationConfig) StreamApplication(org.apache.samza.application.StreamApplication) TaskConfig(org.apache.samza.config.TaskConfig) ConfigException(org.apache.samza.config.ConfigException)

Aggregations

ApplicationConfig (org.apache.samza.config.ApplicationConfig)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StreamApplication (org.apache.samza.application.StreamApplication)1 ConfigException (org.apache.samza.config.ConfigException)1 TaskConfig (org.apache.samza.config.TaskConfig)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1