Search in sources :

Example 1 with ArtifactId

use of co.cask.cdap.api.artifact.ArtifactId 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 ArtifactId

use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ArtifactRepositoryTest method getFile.

private static File getFile() throws Exception {
    File pluginDir = DirUtils.createTempDir(tmpDir);
    // Create the plugin jar. There should be two plugins there (TestPlugin and TestPlugin2).
    Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, TestPlugin.class.getPackage().getName());
    File jarFile = createPluginJar(TestPlugin.class, new File(tmpDir, "myPlugin-1.0.jar"), manifest);
    // add the artifact
    Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace().getId(), APP_ARTIFACT_ID.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "myPlugin", "1.0");
    artifactRepository.addArtifact(artifactId, jarFile, parents);
    return pluginDir;
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 3 with ArtifactId

use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ArtifactStore method addArtifactsToList.

private void addArtifactsToList(List<ArtifactDetail> artifactDetails, Row row, int limit, @Nullable ArtifactRange range) throws IOException {
    ArtifactKey artifactKey = ArtifactKey.parse(row.getRow());
    for (Map.Entry<byte[], byte[]> columnVal : row.getColumns().entrySet()) {
        if (limit != Integer.MAX_VALUE && artifactDetails.size() == limit) {
            break;
        }
        String version = Bytes.toString(columnVal.getKey());
        if (range != null && !range.versionIsInRange(new ArtifactVersion(version))) {
            continue;
        }
        ArtifactData data = GSON.fromJson(Bytes.toString(columnVal.getValue()), ArtifactData.class);
        Id.Artifact artifactId = new NamespaceId(artifactKey.namespace).artifact(artifactKey.name, version).toId();
        artifactDetails.add(new ArtifactDetail(new ArtifactDescriptor(artifactId.toArtifactId(), Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath())), data.meta));
    }
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetId(co.cask.cdap.proto.id.DatasetId) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap)

Example 4 with ArtifactId

use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ArtifactStore method addAndSortArtifacts.

private void addAndSortArtifacts(List<ArtifactDetail> artifacts, Row row, int limit, final ArtifactSortOrder order, @Nullable ArtifactRange range) {
    ArtifactKey artifactKey = ArtifactKey.parse(row.getRow());
    PriorityQueue<ArtifactDetail> queue = getPriorityQueue(limit, order);
    for (Map.Entry<byte[], byte[]> columnEntry : row.getColumns().entrySet()) {
        String version = Bytes.toString(columnEntry.getKey());
        if (range != null && !range.versionIsInRange(new ArtifactVersion(version))) {
            continue;
        }
        ArtifactData data = GSON.fromJson(Bytes.toString(columnEntry.getValue()), ArtifactData.class);
        ArtifactId artifactId = new ArtifactId(artifactKey.name, new ArtifactVersion(version), artifactKey.namespace.equals(NamespaceId.SYSTEM.getNamespace()) ? ArtifactScope.SYSTEM : ArtifactScope.USER);
        queue.add(new ArtifactDetail(new ArtifactDescriptor(artifactId, Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath())), data.meta));
        if (limit != Integer.MAX_VALUE && queue.size() > limit) {
            queue.poll();
        }
    }
    while (!queue.isEmpty()) {
        artifacts.add(queue.poll());
    }
    Collections.reverse(artifacts.subList(0, artifacts.size()));
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap)

Example 5 with ArtifactId

use of co.cask.cdap.api.artifact.ArtifactId in project cdap by caskdata.

the class ArtifactRepository method getArtifactsInfo.

/**
   * return list of {@link ArtifactInfo} in the namespace
   * @param namespace
   * @return list of {@link ArtifactInfo}
   * @throws Exception
   */
public List<ArtifactInfo> getArtifactsInfo(NamespaceId namespace) throws Exception {
    final List<ArtifactDetail> artifactDetails = artifactStore.getArtifacts(namespace);
    List<ArtifactInfo> artifactInfoList = Lists.transform(artifactDetails, new Function<ArtifactDetail, ArtifactInfo>() {

        @Nullable
        @Override
        public ArtifactInfo apply(@Nullable ArtifactDetail input) {
            // transform artifactDetail to artifactInfo
            ArtifactId artifactId = input.getDescriptor().getArtifactId();
            return new ArtifactInfo(artifactId.getName(), artifactId.getVersion().getVersion(), artifactId.getScope(), input.getMeta().getClasses(), input.getMeta().getProperties(), input.getMeta().getUsableBy());
        }
    });
    // todo - CDAP-11560 should filter in artifact store
    return Collections.unmodifiableList(filterAuthorizedArtifactInfos(artifactInfoList, namespace));
}
Also used : ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Nullable(javax.annotation.Nullable)

Aggregations

ArtifactId (co.cask.cdap.api.artifact.ArtifactId)34 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)14 Test (org.junit.Test)13 File (java.io.File)11 NamespaceId (co.cask.cdap.proto.id.NamespaceId)9 PluginClass (co.cask.cdap.api.plugin.PluginClass)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Plugin (co.cask.cdap.api.plugin.Plugin)7 SortedMap (java.util.SortedMap)7 Id (co.cask.cdap.common.id.Id)5 AppDeploymentInfo (co.cask.cdap.internal.app.deploy.pipeline.AppDeploymentInfo)4 TestPlugin (co.cask.cdap.internal.app.plugins.test.TestPlugin)4 ArtifactDescriptor (co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor)4 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashSet (java.util.HashSet)4 Manifest (java.util.jar.Manifest)4 Location (org.apache.twill.filesystem.Location)4 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)3