Search in sources :

Example 1 with SparkHttpServiceHandlerSpecification

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);
}
Also used : SparkSpecification(io.cdap.cdap.api.spark.SparkSpecification) JsonObject(com.google.gson.JsonObject) Resources(io.cdap.cdap.api.Resources) SparkHttpServiceHandlerSpecification(io.cdap.cdap.api.spark.SparkHttpServiceHandlerSpecification) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 2 with SparkHttpServiceHandlerSpecification

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;
}
Also used : InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) SparkHttpServiceHandler(io.cdap.cdap.api.spark.service.SparkHttpServiceHandler) MetricsContext(io.cdap.cdap.api.metrics.MetricsContext) ArrayList(java.util.ArrayList) SparkHttpServiceHandlerSpecification(io.cdap.cdap.api.spark.SparkHttpServiceHandlerSpecification)

Aggregations

SparkHttpServiceHandlerSpecification (io.cdap.cdap.api.spark.SparkHttpServiceHandlerSpecification)2 JsonObject (com.google.gson.JsonObject)1 Resources (io.cdap.cdap.api.Resources)1 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)1 Plugin (io.cdap.cdap.api.plugin.Plugin)1 SparkSpecification (io.cdap.cdap.api.spark.SparkSpecification)1 SparkHttpServiceHandler (io.cdap.cdap.api.spark.service.SparkHttpServiceHandler)1 InstantiatorFactory (io.cdap.cdap.common.lang.InstantiatorFactory)1 ArrayList (java.util.ArrayList)1