Search in sources :

Example 6 with Resources

use of io.cdap.cdap.api.Resources in project cdap by caskdata.

the class ServiceSpecificationCodec method deserialize.

@Override
public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = (JsonObject) json;
    if (isOldSpec(jsonObj)) {
        return decodeOldSpec(jsonObj);
    }
    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);
    Map<String, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class);
    Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class);
    int instances = jsonObj.get("instances").getAsInt();
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    return new ServiceSpecification(className, name, description, handlers, resources, instances, plugins, properties);
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) JsonObject(com.google.gson.JsonObject) Resources(io.cdap.cdap.api.Resources) HttpServiceHandlerSpecification(io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 7 with Resources

use of io.cdap.cdap.api.Resources in project cdap by caskdata.

the class MapReduceResourcesTest method testProgrammatic.

@Test
public void testProgrammatic() {
    CConfiguration cConf = CConfiguration.create();
    cConf.setInt(Configs.Keys.JAVA_RESERVED_MEMORY_MB, 300);
    Configuration hConf = new Configuration();
    hConf.setInt(Job.MAP_MEMORY_MB, 3000);
    hConf.setInt(Job.MAP_CPU_VCORES, 5);
    // Always use configurations setup programmatically via job conf.
    MapReduceRuntimeService.TaskType.MAP.configure(hConf, cConf, Collections.emptyMap(), null);
    int maxHeapSize = org.apache.twill.internal.utils.Resources.computeMaxHeapSize(3000, cConf.getInt(Configs.Keys.JAVA_RESERVED_MEMORY_MB), 0);
    validateResources(cConf, hConf, 3000, 5, maxHeapSize);
    // Even resources is provided via context, it is ignored.
    hConf = new Configuration();
    hConf.setInt(Job.MAP_MEMORY_MB, 3000);
    hConf.setInt(Job.MAP_CPU_VCORES, 5);
    MapReduceRuntimeService.TaskType.MAP.configure(hConf, cConf, Collections.emptyMap(), new Resources(1234));
    maxHeapSize = org.apache.twill.internal.utils.Resources.computeMaxHeapSize(3000, cConf.getInt(Configs.Keys.JAVA_RESERVED_MEMORY_MB), 0);
    validateResources(cConf, hConf, 3000, 5, maxHeapSize);
    // Set the reserved memory via task arguments
    hConf = new Configuration();
    hConf.setInt(Job.MAP_MEMORY_MB, 3000);
    hConf.setInt(Job.MAP_CPU_VCORES, 5);
    MapReduceRuntimeService.TaskType.MAP.configure(hConf, cConf, Collections.singletonMap("system.resources.reserved.memory.override", "2000"), null);
    validateResources(cConf, hConf, 3000, 5, 3000 - 2000);
}
Also used : CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Resources(io.cdap.cdap.api.Resources) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 8 with Resources

use of io.cdap.cdap.api.Resources in project cdap by caskdata.

the class SystemArgumentsTest method testSystemResources.

@Test
public void testSystemResources() {
    Resources defaultResources = new Resources();
    // Nothing specified
    Resources resources = SystemArguments.getResources(ImmutableMap.of(), defaultResources);
    Assert.assertEquals(defaultResources, resources);
    // Specify memory
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "10"), defaultResources);
    Assert.assertEquals(new Resources(10), resources);
    // Specify cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.CORES_KEY, "8"), defaultResources);
    Assert.assertEquals(new Resources(defaultResources.getMemoryMB(), 8), resources);
    // Specify both memory and cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "10", SystemArguments.CORES_KEY, "8"), defaultResources);
    Assert.assertEquals(new Resources(10, 8), resources);
    // Specify invalid memory
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "-10"), defaultResources);
    Assert.assertEquals(defaultResources, resources);
    // Specify invalid cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.CORES_KEY, "abc"), defaultResources);
    Assert.assertEquals(defaultResources, resources);
    // Specify invalid memory and value cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "xyz", SystemArguments.CORES_KEY, "8"), defaultResources);
    Assert.assertEquals(new Resources(defaultResources.getMemoryMB(), 8), resources);
    // Specify valid memory and invalid cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "10", SystemArguments.CORES_KEY, "-8"), defaultResources);
    Assert.assertEquals(new Resources(10, defaultResources.getVirtualCores()), resources);
    // Specify invalid memory and invalid cores
    resources = SystemArguments.getResources(ImmutableMap.of(SystemArguments.MEMORY_KEY, "-1", SystemArguments.CORES_KEY, "-8"), defaultResources);
    Assert.assertEquals(defaultResources, resources);
    // Specify reserved memory size
    Map<String, String> configs = SystemArguments.getTwillContainerConfigs(ImmutableMap.of(SystemArguments.RESERVED_MEMORY_KEY_OVERRIDE, "200"), 300);
    Assert.assertEquals(ImmutableMap.of(Configs.Keys.JAVA_RESERVED_MEMORY_MB, "200", Configs.Keys.HEAP_RESERVED_MIN_RATIO, "0.33"), configs);
    // Specify invalid reserved memory size
    configs = SystemArguments.getTwillContainerConfigs(ImmutableMap.of(SystemArguments.RESERVED_MEMORY_KEY_OVERRIDE, "-1"), 300);
    Assert.assertTrue(configs.isEmpty());
    // Specify >= container memory size
    configs = SystemArguments.getTwillContainerConfigs(ImmutableMap.of(SystemArguments.RESERVED_MEMORY_KEY_OVERRIDE, "300"), 300);
    Assert.assertTrue(configs.isEmpty());
}
Also used : Resources(io.cdap.cdap.api.Resources) Test(org.junit.Test)

Example 9 with Resources

use of io.cdap.cdap.api.Resources in project cdap by caskdata.

the class MapReduceSpecificationCodec method deserialize.

@Override
public MapReduceSpecification 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);
    Resources driverResources = deserializeResources(jsonObj, "driver", context);
    Resources mapperResources = deserializeResources(jsonObj, "mapper", context);
    Resources reducerResources = deserializeResources(jsonObj, "reducer", context);
    JsonElement inputDataSetElem = jsonObj.get("inputDataSet");
    String inputDataSet = inputDataSetElem == null ? null : inputDataSetElem.getAsString();
    JsonElement outputDataSetElem = jsonObj.get("outputDataSet");
    String outputDataSet = outputDataSetElem == null ? null : outputDataSetElem.getAsString();
    Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    return new MapReduceSpecification(className, name, description, inputDataSet, outputDataSet, dataSets, properties, driverResources, mapperResources, reducerResources, plugins);
}
Also used : JsonElement(com.google.gson.JsonElement) MapReduceSpecification(io.cdap.cdap.api.mapreduce.MapReduceSpecification) JsonObject(com.google.gson.JsonObject) Resources(io.cdap.cdap.api.Resources) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 10 with Resources

use of io.cdap.cdap.api.Resources in project cdap by cdapio.

the class ServiceSpecificationCodec method deserialize.

@Override
public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = (JsonObject) json;
    if (isOldSpec(jsonObj)) {
        return decodeOldSpec(jsonObj);
    }
    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);
    Map<String, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class);
    Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class);
    int instances = jsonObj.get("instances").getAsInt();
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    return new ServiceSpecification(className, name, description, handlers, resources, instances, plugins, properties);
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) JsonObject(com.google.gson.JsonObject) Resources(io.cdap.cdap.api.Resources) HttpServiceHandlerSpecification(io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification) Plugin(io.cdap.cdap.api.plugin.Plugin)

Aggregations

Resources (io.cdap.cdap.api.Resources)38 Test (org.junit.Test)18 JsonObject (com.google.gson.JsonObject)14 Plugin (io.cdap.cdap.api.plugin.Plugin)12 PluginSpec (io.cdap.cdap.etl.proto.v2.spec.PluginSpec)8 HttpServiceHandlerSpecification (io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification)6 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)6 BatchPipelineSpec (io.cdap.cdap.etl.batch.BatchPipelineSpec)6 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)6 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)6 Configuration (org.apache.hadoop.conf.Configuration)6 JsonElement (com.google.gson.JsonElement)4 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)4 ServiceSpecification (io.cdap.cdap.api.service.ServiceSpecification)4 WorkflowConditionNode (io.cdap.cdap.api.workflow.WorkflowConditionNode)4 WorkflowForkNode (io.cdap.cdap.api.workflow.WorkflowForkNode)4 WorkflowNode (io.cdap.cdap.api.workflow.WorkflowNode)4 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)4 Connection (io.cdap.cdap.etl.proto.Connection)4 UpgradeContext (io.cdap.cdap.etl.proto.UpgradeContext)4