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