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);
}
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations