Search in sources :

Example 1 with Plugin

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()));
}
Also used : ArtifactId(co.cask.cdap.api.artifact.ArtifactId) IOException(java.io.IOException) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 2 with Plugin

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();
}
Also used : PluginClass(co.cask.cdap.api.plugin.PluginClass) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 3 with Plugin

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()));
}
Also used : ArtifactId(co.cask.cdap.api.artifact.ArtifactId) IOException(java.io.IOException) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 4 with Plugin

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;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ArrayList(java.util.ArrayList) PluginInstanceDetail(co.cask.cdap.proto.PluginInstanceDetail) Map(java.util.Map) HashMap(java.util.HashMap) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 5 with Plugin

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());
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) ImmutableMap(com.google.common.collect.ImmutableMap) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) File(java.io.File) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) 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