Search in sources :

Example 16 with Resources

use of co.cask.cdap.api.Resources in project cdap by caskdata.

the class PurchaseHistoryBuilder method configure.

@Override
public void configure() {
    setDescription("Purchase History Builder");
    setDriverResources(new Resources(1024));
    setMapperResources(new Resources(1024));
    setReducerResources(new Resources(1024));
}
Also used : Resources(co.cask.cdap.api.Resources)

Example 17 with Resources

use of co.cask.cdap.api.Resources in project cdap by caskdata.

the class PurchaseHistoryBuilder method initialize.

@Override
public void initialize() throws Exception {
    MapReduceContext context = getContext();
    Job job = context.getHadoopJob();
    job.setReducerClass(PerUserReducer.class);
    context.addInput(Input.ofDataset("purchases"), PurchaseMapper.class);
    context.addOutput(Output.ofDataset("history"));
    // override default memory usage if the corresponding runtime arguments are set.
    Map<String, String> runtimeArgs = context.getRuntimeArguments();
    String mapperMemoryMBStr = runtimeArgs.get(MAPPER_MEMORY_MB);
    if (mapperMemoryMBStr != null) {
        context.setMapperResources(new Resources(Integer.parseInt(mapperMemoryMBStr)));
    }
    String reducerMemoryMBStr = runtimeArgs.get(REDUCER_MEMORY_MB);
    if (reducerMemoryMBStr != null) {
        context.setReducerResources(new Resources(Integer.parseInt(reducerMemoryMBStr)));
    }
}
Also used : MapReduceContext(co.cask.cdap.api.mapreduce.MapReduceContext) Resources(co.cask.cdap.api.Resources) Job(org.apache.hadoop.mapreduce.Job)

Example 18 with Resources

use of co.cask.cdap.api.Resources in project cdap by caskdata.

the class PurchaseStore method configure.

@Override
public void configure(FlowletConfigurer configurer) {
    super.configure(configurer);
    setDescription("Store the incoming Purchase objects in the purchases dataset");
    setResources(new Resources(1024));
}
Also used : Resources(co.cask.cdap.api.Resources)

Example 19 with Resources

use of co.cask.cdap.api.Resources in project cdap by caskdata.

the class FlowletSpecificationCodec method deserialize.

@Override
public FlowletSpecification 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();
    FailurePolicy policy = FailurePolicy.valueOf(jsonObj.get("failurePolicy").getAsString());
    Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class);
    return new DefaultFlowletSpecification(className, name, description, policy, dataSets, properties, resources);
}
Also used : JsonObject(com.google.gson.JsonObject) DefaultFlowletSpecification(co.cask.cdap.internal.flowlet.DefaultFlowletSpecification) Resources(co.cask.cdap.api.Resources) FailurePolicy(co.cask.cdap.api.flow.flowlet.FailurePolicy)

Example 20 with Resources

use of co.cask.cdap.api.Resources in project cdap by caskdata.

the class MapReduceSpecificationCodec method deserializeResources.

/**
   * Deserialize the resources field from the serialized object.
   *
   * @param jsonObj The object representing the MapReduceSpecification
   * @param prefix Field name prefix. Either "mapper" or "reducer"
   * @param context The context to deserialize object.
   * @return A {@link Resources} or {@code null}.
   */
private Resources deserializeResources(JsonObject jsonObj, String prefix, JsonDeserializationContext context) {
    // See if it of new format
    String name = prefix + "Resources";
    JsonElement element = jsonObj.get(name);
    if (element != null) {
        return context.deserialize(element, Resources.class);
    }
    // Try the old format, which is an int field representing the memory in MB.
    name = prefix + "MemoryMB";
    element = jsonObj.get(name);
    if (element != null) {
        return new Resources(element.getAsInt());
    }
    return null;
}
Also used : JsonElement(com.google.gson.JsonElement) Resources(co.cask.cdap.api.Resources)

Aggregations

Resources (co.cask.cdap.api.Resources)40 JsonObject (com.google.gson.JsonObject)9 Test (org.junit.Test)8 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 Connection (co.cask.cdap.etl.proto.Connection)4 UpgradeContext (co.cask.cdap.etl.proto.UpgradeContext)4 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)3 HttpServiceHandlerSpecification (co.cask.cdap.api.service.http.HttpServiceHandlerSpecification)3 ArtifactSelectorConfig (co.cask.cdap.etl.proto.ArtifactSelectorConfig)3 ETLPlugin (co.cask.cdap.etl.proto.v2.ETLPlugin)3 ArrayList (java.util.ArrayList)3 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)2 SchedulableProgramType (co.cask.cdap.api.schedule.SchedulableProgramType)2 ServiceHttpEndpoint (co.cask.cdap.api.service.http.ServiceHttpEndpoint)2 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)2 WorkerSpecification (co.cask.cdap.api.worker.WorkerSpecification)2 ScheduleProgramInfo (co.cask.cdap.api.workflow.ScheduleProgramInfo)2 WorkflowActionNode (co.cask.cdap.api.workflow.WorkflowActionNode)2 BatchPipelineSpec (co.cask.cdap.etl.batch.BatchPipelineSpec)2 Plugin (co.cask.cdap.etl.proto.v1.Plugin)2