Search in sources :

Example 11 with Plugin

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

the class SparkContainerDriverLauncher method localizeArtifactsFromAppfabric.

private static void localizeArtifactsFromAppfabric(CConfiguration cConf, Configuration hConf) throws Exception {
    ArtifactLocalizerClient fetchArtifacts = createArtifactLocalizerClient(cConf, hConf);
    ApplicationSpecification spec = GSON.fromJson(hConf.getRaw(CDAP_APP_SPEC_KEY), ApplicationSpecification.class);
    ProgramId programId = GSON.fromJson(hConf.getRaw(PROGRAM_ID_KEY), ProgramId.class);
    // Create plugin location for storing plugin jars
    Path pluginsLocation = new File(WORKING_DIRECTORY).getAbsoluteFile().toPath().resolve(SparkRuntimeContextProvider.ARTIFACTS_DIRECTORY_NAME).toAbsolutePath();
    Files.createDirectories(pluginsLocation);
    // Fetching plugin artifacts from app-fabric
    Set<String> localizedPlugins = new HashSet<>();
    for (Plugin plugin : spec.getPlugins().values()) {
        String pluginName = String.format("%s-%s-%s.jar", plugin.getArtifactId().getScope().toString(), plugin.getArtifactId().getName(), plugin.getArtifactId().getVersion().toString());
        if (localizedPlugins.contains(pluginName)) {
            // skip localizing existing artifacts
            continue;
        }
        File tempLocation = fetchArtifacts.localizeArtifact(plugin.getArtifactId(), programId.getNamespace());
        BundleJarUtil.unJar(tempLocation, pluginsLocation.resolve(pluginName).toFile());
        localizedPlugins.add(pluginName);
    }
    // Fetching program.jar from app-fabric and expand it
    Path programJarLocation = new File(WORKING_DIRECTORY).getAbsoluteFile().toPath();
    File tempLocation = fetchArtifacts.localizeArtifact(spec.getArtifactId(), programId.getNamespace());
    BundleJarUtil.unJar(tempLocation, programJarLocation.resolve(PROGRAM_JAR_EXPANDED_NAME).toFile());
    Files.copy(tempLocation.toPath(), programJarLocation.resolve(PROGRAM_JAR_NAME));
}
Also used : Path(java.nio.file.Path) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramId(io.cdap.cdap.proto.id.ProgramId) File(java.io.File) HashSet(java.util.HashSet) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 12 with Plugin

use of io.cdap.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.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<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(), datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 13 with Plugin

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

the class ArtifactRepositoryTest method testPlugin.

@Test
public void testPlugin() throws Exception {
    File pluginDir = TMP_FOLDER.newFolder();
    addPluginArtifact();
    SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = getPlugins();
    copyArtifacts(pluginDir, plugins);
    // Instantiate the plugins and execute them
    try (PluginInstantiator instantiator = new PluginInstantiator(cConf, appClassLoader, pluginDir)) {
        for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> entry : plugins.entrySet()) {
            for (PluginClass pluginClass : entry.getValue()) {
                Plugin pluginInfo = new Plugin(new ArrayList<>(), entry.getKey().getArtifactId(), pluginClass, PluginProperties.builder().add("class.name", TEST_EMPTY_CLASS).add("nullableLongFlag", "10").add("host", "example.com").add("aBoolean", "${aBoolean}").add("aByte", "${aByte}").add("aChar", "${aChar}").add("aDouble", "${aDouble}").add("anInt", "${anInt}").add("aFloat", "${aFloat}").add("aLong", "${aLong}").add("aShort", "${aShort}").build());
                Callable<String> plugin = instantiator.newInstance(pluginInfo);
                Assert.assertEquals("example.com,false,0,\u0000,0.0,0.0,0,0,0,null", plugin.call());
            }
        }
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) PluginInstantiator(io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator) PluginClass(io.cdap.cdap.api.plugin.PluginClass) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TestPlugin(io.cdap.cdap.internal.app.plugins.test.TestPlugin) NestedConfigPlugin(io.cdap.cdap.internal.app.runtime.artifact.plugin.nested.NestedConfigPlugin) Plugin(io.cdap.cdap.api.plugin.Plugin) Test(org.junit.Test)

Example 14 with Plugin

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

the class RemotePluginConfigurer method addPlugin.

@Override
protected Plugin addPlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) throws PluginNotExistsException {
    validateExistingPlugin(pluginId);
    // plugin
    if (!localPlugins.containsKey(pluginId)) {
        return super.addPlugin(pluginType, pluginName, pluginId, properties, selector);
    }
    Plugin existingPlugin = localPlugins.get(pluginId);
    File existingPluginLocation = new File(localPluginDir, Artifacts.getFileName(existingPlugin.getArtifactId()));
    // need to regenerate this plugin to ensure the plugin has updated properties with macro resolved, also
    // register it to plugin instantiator
    io.cdap.cdap.api.artifact.ArtifactId artifactId = existingPlugin.getArtifactId();
    String namespace = artifactId.getScope().equals(ArtifactScope.SYSTEM) ? NamespaceId.SYSTEM.getNamespace() : pluginNamespaceId.getNamespace();
    Location pluginLocation = Locations.toLocation(existingPluginLocation);
    SortedMap<io.cdap.cdap.api.artifact.ArtifactId, PluginClass> selectedPlugin = new TreeMap<>();
    selectedPlugin.put(artifactId, existingPlugin.getPluginClass());
    selector.select(selectedPlugin);
    Plugin plugin = FindPluginHelper.getPlugin(existingPlugin.getParents(), Maps.immutableEntry(new ArtifactDescriptor(namespace, artifactId, pluginLocation), existingPlugin.getPluginClass()), properties, pluginInstantiator);
    plugins.put(pluginId, new PluginWithLocation(plugin, pluginLocation));
    return plugin;
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) TreeMap(java.util.TreeMap) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) PluginClass(io.cdap.cdap.api.plugin.PluginClass) File(java.io.File) Plugin(io.cdap.cdap.api.plugin.Plugin) Location(org.apache.twill.filesystem.Location)

Example 15 with Plugin

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

the class ServiceSpecificationCodec method deserialize.

@Override
public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = (JsonObject) json;
    if (isOldSpec(jsonObj)) {
        return decodeOldSpec(jsonObj);
    }
    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, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class);
    Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class);
    int instances = jsonObj.get("instances").getAsInt();
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    return new ServiceSpecification(className, name, description, handlers, resources, instances, plugins, properties);
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) JsonObject(com.google.gson.JsonObject) Resources(io.cdap.cdap.api.Resources) HttpServiceHandlerSpecification(io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification) 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