Search in sources :

Example 21 with Plugin

use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.

the class AbstractProgramRuntimeService method createPluginSnapshot.

/**
 * Return the copy of the {@link ProgramOptions} including locations of plugin artifacts in it.
 * @param options the {@link ProgramOptions} in which the locations of plugin artifacts needs to be included
 * @param programId Id of the Program
 * @param tempDir Temporary Directory to create the plugin artifact snapshot
 * @param appSpec program's Application Specification
 * @return the copy of the program options with locations of plugin artifacts included in them
 */
private ProgramOptions createPluginSnapshot(ProgramOptions options, ProgramId programId, File tempDir, @Nullable ApplicationSpecification appSpec) throws Exception {
    // appSpec is null in an unit test
    if (appSpec == null) {
        return options;
    }
    Set<String> files = Sets.newHashSet();
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.putAll(options.getArguments().asMap());
    for (Map.Entry<String, Plugin> pluginEntry : appSpec.getPlugins().entrySet()) {
        Plugin plugin = pluginEntry.getValue();
        File destFile = new File(tempDir, Artifacts.getFileName(plugin.getArtifactId()));
        // Skip if the file has already been copied.
        if (!files.add(destFile.getName())) {
            continue;
        }
        try {
            ArtifactId artifactId = Artifacts.toProtoArtifactId(programId.getNamespaceId(), plugin.getArtifactId());
            copyArtifact(artifactId, noAuthArtifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)), destFile);
        } catch (ArtifactNotFoundException e) {
            throw new IllegalArgumentException(String.format("Artifact %s could not be found", plugin.getArtifactId()), e);
        }
    }
    LOG.debug("Plugin artifacts of {} copied to {}", programId, tempDir.getAbsolutePath());
    builder.put(ProgramOptionConstants.PLUGIN_DIR, tempDir.getAbsolutePath());
    return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(builder.build()), options.getUserArguments(), options.isDebug());
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ImmutableMap(com.google.common.collect.ImmutableMap) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) File(java.io.File) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 22 with Plugin

use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.

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 23 with Plugin

use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.

the class WorkerSpecificationCodec method deserialize.

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

Example 24 with Plugin

use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.

the class WorkflowSpecificationCodec method deserialize.

@Override
public WorkflowSpecification 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);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    List<WorkflowNode> nodes = deserializeList(jsonObj.get("nodes"), context, WorkflowNode.class);
    Map<String, DatasetCreationSpec> localDatasetSpec = deserializeMap(jsonObj.get("localDatasetSpecs"), context, DatasetCreationSpec.class);
    return new WorkflowSpecification(className, name, description, properties, nodes, localDatasetSpec, plugins);
}
Also used : DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) JsonObject(com.google.gson.JsonObject) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 25 with Plugin

use of io.cdap.cdap.api.plugin.Plugin in project cdap by cdapio.

the class DefaultPluginContext method getPlugin.

private Plugin getPlugin(String pluginId) {
    Plugin plugin = plugins.get(pluginId);
    Preconditions.checkArgument(plugin != null, "Plugin with id %s does not exist in program %s of application %s.", pluginId, programId.getProgram(), programId.getApplication());
    return plugin;
}
Also used : Plugin(io.cdap.cdap.api.plugin.Plugin)

Aggregations

Plugin (io.cdap.cdap.api.plugin.Plugin)50 Map (java.util.Map)18 HashMap (java.util.HashMap)16 PluginClass (io.cdap.cdap.api.plugin.PluginClass)14 File (java.io.File)14 ImmutableMap (com.google.common.collect.ImmutableMap)12 JsonObject (com.google.gson.JsonObject)12 HashSet (java.util.HashSet)12 Test (org.junit.Test)10 ImmutableSet (com.google.common.collect.ImmutableSet)8 Resources (io.cdap.cdap.api.Resources)8 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)8 TestPlugin (io.cdap.cdap.internal.app.plugins.test.TestPlugin)8 NestedConfigPlugin (io.cdap.cdap.internal.app.runtime.artifact.plugin.nested.NestedConfigPlugin)8 PluginInstantiator (io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator)8 Set (java.util.Set)8 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 SortedMap (java.util.SortedMap)6