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