Search in sources :

Example 6 with Plugin

use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.

the class DefaultPluginConfigurer method usePluginClass.

@Nullable
@Override
public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
    Plugin plugin;
    try {
        plugin = findPlugin(pluginType, pluginName, pluginId, properties, selector);
    } catch (PluginNotExistsException e) {
        // Plugin not found, hence return null
        return null;
    } catch (ArtifactNotFoundException e) {
        // this shouldn't happen, it means the artifact for this app does not exist.
        throw new IllegalStateException(String.format("Application artifact '%s' no longer exists. Please check if it was deleted.", artifactId));
    }
    try {
        Class<T> cls = pluginInstantiator.loadClass(plugin);
        plugins.put(pluginId, plugin);
        return cls;
    } catch (IOException e) {
        // If the plugin jar is deleted without notifying the artifact service.
        return null;
    } catch (ClassNotFoundException e) {
        // Shouldn't happen
        throw Throwables.propagate(e);
    }
}
Also used : PluginNotExistsException(co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException) IOException(java.io.IOException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) Plugin(co.cask.cdap.api.plugin.Plugin) Nullable(javax.annotation.Nullable)

Example 7 with Plugin

use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.

the class DefaultPluginConfigurer method usePlugin.

@Nullable
@Override
public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
    Plugin plugin;
    try {
        plugin = findPlugin(pluginType, pluginName, pluginId, properties, selector);
    } catch (PluginNotExistsException e) {
        // Plugin not found, hence return null
        return null;
    } catch (ArtifactNotFoundException e) {
        // this shouldn't happen, it means the artifact for this app does not exist.
        throw new IllegalStateException(String.format("Application artifact '%s' no longer exists. Please check if it was deleted.", artifactId));
    }
    try {
        T instance = pluginInstantiator.newInstance(plugin);
        plugins.put(pluginId, plugin);
        return instance;
    } catch (IOException e) {
        // If the plugin jar is deleted without notifying the artifact service.
        return null;
    } catch (ClassNotFoundException e) {
        // Shouldn't happen
        throw Throwables.propagate(e);
    }
}
Also used : PluginNotExistsException(co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException) IOException(java.io.IOException) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) Plugin(co.cask.cdap.api.plugin.Plugin) Nullable(javax.annotation.Nullable)

Example 8 with Plugin

use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getFlows().values()) {
        programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
        programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getServices().values()) {
        programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getSpark().values()) {
        programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkers().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    List<StreamDetail> streams = new ArrayList<>();
    for (StreamSpecification streamSpec : spec.getStreams().values()) {
        streams.add(new StreamDetail(streamSpec.getName()));
    }
    List<DatasetDetail> datasets = new ArrayList<>();
    for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
        datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
    }
    List<PluginDetail> plugins = new ArrayList<>();
    for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
        plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
    }
    // this is only required if there are old apps lying around that failed to get upgrading during
    // the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
    // in the meantime, we don't want this api call to null pointer exception.
    ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
    return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 9 with Plugin

use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.

the class ApplicationSpecificationCodec method deserialize.

@Override
public ApplicationSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    String appVersion = ApplicationId.DEFAULT_VERSION;
    if (jsonObj.has("appVersion")) {
        appVersion = jsonObj.get("appVersion").getAsString();
    }
    String description = jsonObj.get("description").getAsString();
    String configuration = null;
    if (jsonObj.has("configuration")) {
        configuration = jsonObj.get("configuration").getAsString();
    }
    ArtifactId artifactId = context.deserialize(jsonObj.get("artifactId"), ArtifactId.class);
    Map<String, StreamSpecification> streams = deserializeMap(jsonObj.get("streams"), context, StreamSpecification.class);
    Map<String, String> datasetModules = deserializeMap(jsonObj.get("datasetModules"), context, String.class);
    Map<String, DatasetCreationSpec> datasetInstances = deserializeMap(jsonObj.get("datasetInstances"), context, DatasetCreationSpec.class);
    Map<String, FlowSpecification> flows = deserializeMap(jsonObj.get("flows"), context, FlowSpecification.class);
    Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context, MapReduceSpecification.class);
    Map<String, SparkSpecification> sparks = deserializeMap(jsonObj.get("sparks"), context, SparkSpecification.class);
    Map<String, WorkflowSpecification> workflows = deserializeMap(jsonObj.get("workflows"), context, WorkflowSpecification.class);
    Map<String, ServiceSpecification> services = deserializeMap(jsonObj.get("services"), context, ServiceSpecification.class);
    Map<String, ScheduleCreationSpec> programSchedules = deserializeMap(jsonObj.get("programSchedules"), context, ScheduleCreationSpec.class);
    Map<String, WorkerSpecification> workers = deserializeMap(jsonObj.get("workers"), context, WorkerSpecification.class);
    Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);
    return new DefaultApplicationSpecification(name, appVersion, description, configuration, artifactId, streams, datasetModules, datasetInstances, flows, mapReduces, sparks, workflows, services, programSchedules, workers, plugins);
}
Also used : ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) JsonObject(com.google.gson.JsonObject) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) WorkerSpecification(co.cask.cdap.api.worker.WorkerSpecification) MapReduceSpecification(co.cask.cdap.api.mapreduce.MapReduceSpecification) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 10 with Plugin

use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.

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(co.cask.cdap.api.plugin.Plugin)

Aggregations

Plugin (co.cask.cdap.api.plugin.Plugin)16 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)7 Map (java.util.Map)7 PluginClass (co.cask.cdap.api.plugin.PluginClass)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)4 File (java.io.File)4 HashSet (java.util.HashSet)4 TestPlugin (co.cask.cdap.internal.app.plugins.test.TestPlugin)3 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)3 PluginNotExistsException (co.cask.cdap.internal.app.runtime.plugin.PluginNotExistsException)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 SortedMap (java.util.SortedMap)3 Test (org.junit.Test)3 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)2 PluginPropertyField (co.cask.cdap.api.plugin.PluginPropertyField)2