use of io.cdap.cdap.api.spark.SparkHttpServiceHandlerSpecification in project cdap by caskdata.
the class SparkSpecificationCodec method deserialize.
@Override
public SparkSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String className = jsonObj.get("className").getAsString();
String name = jsonObj.get("name").getAsString();
String description = jsonObj.get("description").getAsString();
Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
String mainClassName = jsonObj.has("mainClassName") ? jsonObj.get("mainClassName").getAsString() : null;
Set<String> datasets = deserializeSet(jsonObj.get("datasets"), context, String.class);
Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
Resources clientResources = deserializeResources(jsonObj, "client", context);
Resources driverResources = deserializeResources(jsonObj, "driver", context);
Resources executorResources = deserializeResources(jsonObj, "executor", context);
List<SparkHttpServiceHandlerSpecification> handlers = deserializeList(jsonObj.get("handlers"), context, SparkHttpServiceHandlerSpecification.class);
return new SparkSpecification(className, name, description, mainClassName, datasets, properties, clientResources, driverResources, executorResources, handlers, plugins);
}
use of io.cdap.cdap.api.spark.SparkHttpServiceHandlerSpecification in project cdap by caskdata.
the class SparkHttpServiceServer method createDelegatorContexts.
@Override
protected List<SparkHandlerDelegatorContext> createDelegatorContexts() throws Exception {
List<SparkHandlerDelegatorContext> contexts = new ArrayList<>();
InstantiatorFactory instantiatorFactory = new InstantiatorFactory(false);
for (SparkHttpServiceHandlerSpecification spec : context.getSpecification().getHandlers()) {
Class<?> handlerClass = getProgram().getClassLoader().loadClass(spec.getClassName());
@SuppressWarnings("unchecked") TypeToken<SparkHttpServiceHandler> type = TypeToken.of((Class<SparkHttpServiceHandler>) handlerClass);
MetricsContext handlerMetricsContext = runtimeContext.getProgramMetrics().childContext(Constants.Metrics.Tag.HANDLER, handlerClass.getSimpleName());
contexts.add(new SparkHandlerDelegatorContext(type, instantiatorFactory, spec, runtimeContext.getProgramMetrics(), handlerMetricsContext));
}
return contexts;
}
Aggregations