use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.
the class FindPluginHelper method getPlugin.
private static Plugin getPlugin(Map.Entry<ArtifactDescriptor, PluginClass> pluginEntry, PluginProperties properties, String pluginType, String pluginName, PluginInstantiator pluginInstantiator) {
CollectMacroEvaluator collectMacroEvaluator = new CollectMacroEvaluator();
// No type checking is done for now.
for (PluginPropertyField field : pluginEntry.getValue().getProperties().values()) {
Preconditions.checkArgument(!field.isRequired() || (properties.getProperties().containsKey(field.getName())), "Required property '%s' missing for plugin of type %s, name %s.", field.getName(), pluginType, pluginName);
if (field.isMacroSupported()) {
MacroParser parser = new MacroParser(collectMacroEvaluator, field.isMacroEscapingEnabled());
parser.parse(properties.getProperties().get(field.getName()));
}
}
ArtifactId artifact = pluginEntry.getKey().getArtifactId();
try {
pluginInstantiator.addArtifact(pluginEntry.getKey().getLocation(), artifact);
} catch (IOException e) {
Throwables.propagate(e);
}
return new Plugin(artifact, pluginEntry.getValue(), properties.setMacros(collectMacroEvaluator.getMacros()));
}
use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.
the class AppSystemMetadataWriter method getSystemPropertiesToAdd.
@Override
protected Map<String, String> getSystemPropertiesToAdd() {
ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
properties.put(ENTITY_NAME_KEY, appSpec.getName());
properties.put(VERSION_KEY, appId.getVersion());
String description = appSpec.getDescription();
if (!Strings.isNullOrEmpty(description)) {
properties.put(DESCRIPTION_KEY, description);
}
if (!existing) {
properties.put(CREATION_TIME_KEY, String.valueOf(System.currentTimeMillis()));
}
addPrograms(properties);
addSchedules(properties);
// appSpec.getPlugins() returns all instances of all plugins, so there may be duplicates.
// we only store unique plugins right now
Set<PluginClass> existingPluginClasses = new HashSet<>();
for (Plugin plugin : appSpec.getPlugins().values()) {
if (!existingPluginClasses.contains(plugin.getPluginClass())) {
addPlugin(plugin.getPluginClass(), null, properties);
existingPluginClasses.add(plugin.getPluginClass());
}
}
return properties.build();
}
use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.
the class FindPluginHelper method getPlugin.
/**
* Get the Plugin information from the specified information.
*
* @param parents plugin parents of the plugin. Each item in the iterable must be the parent of the item before it,
* with the first item as the direct parent of the plugin
* @param pluginEntry artifact and class information for the plugin
* @param properties plugin properties
* @param pluginType plugin type
* @param pluginName plugin name
* @param pluginInstantiator instantiator to add the plugin artifact to
* @return plugin information
*/
public static Plugin getPlugin(Iterable<ArtifactId> parents, Map.Entry<ArtifactDescriptor, PluginClass> pluginEntry, PluginProperties properties, String pluginType, String pluginName, PluginInstantiator pluginInstantiator) {
CollectMacroEvaluator collectMacroEvaluator = new CollectMacroEvaluator();
// No type checking is done for now.
for (PluginPropertyField field : pluginEntry.getValue().getProperties().values()) {
Preconditions.checkArgument(!field.isRequired() || (properties.getProperties().containsKey(field.getName())), "Required property '%s' missing for plugin of type %s, name %s.", field.getName(), pluginType, pluginName);
if (field.isMacroSupported()) {
MacroParser parser = new MacroParser(collectMacroEvaluator, field.isMacroEscapingEnabled());
parser.parse(properties.getProperties().get(field.getName()));
}
}
ArtifactId artifact = pluginEntry.getKey().getArtifactId();
try {
pluginInstantiator.addArtifact(pluginEntry.getKey().getLocation(), artifact);
} catch (IOException e) {
throw Throwables.propagate(e);
}
return new Plugin(parents, artifact, pluginEntry.getValue(), properties.setMacros(collectMacroEvaluator.getMacros()));
}
use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.
the class ApplicationLifecycleService method getPlugins.
/**
* Get detail about the plugin in the specified application
*
* @param appId the id of the application
* @return list of plugins in the application
* @throws ApplicationNotFoundException if the specified application does not exist
*/
public List<PluginInstanceDetail> getPlugins(ApplicationId appId) throws ApplicationNotFoundException {
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
List<PluginInstanceDetail> pluginInstanceDetails = new ArrayList<>();
for (Map.Entry<String, Plugin> entry : appSpec.getPlugins().entrySet()) {
pluginInstanceDetails.add(new PluginInstanceDetail(entry.getKey(), entry.getValue()));
}
return pluginInstanceDetails;
}
use of co.cask.cdap.api.plugin.Plugin in project cdap by caskdata.
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 || appSpec.getPlugins().isEmpty()) {
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.toArtifactId(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());
}
Aggregations