use of co.cask.cdap.api.artifact.ArtifactInfo 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));
}
use of co.cask.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class ArtifactRepository method addArtifact.
/**
* Inspects and builds plugin and application information for the given artifact, adding an additional set of
* plugin classes to the plugins found through inspection. This method is used when all plugin classes
* cannot be derived by inspecting the artifact but need to be explicitly set. This is true for 3rd party plugins
* like jdbc drivers.
*
* @param artifactId the id of the artifact to inspect and store
* @param artifactFile the artifact to inspect and store
* @param parentArtifacts artifacts the given artifact extends.
* If null, the given artifact does not extend another artifact
* @param additionalPlugins the set of additional plugin classes to add to the plugins found through inspection.
* If null, no additional plugin classes will be added
* @param properties properties for the artifact
* @throws IOException if there was an exception reading from the artifact store
* @throws ArtifactRangeNotFoundException if none of the parent artifacts could be found
* @throws UnauthorizedException if the user is not authorized to add an artifact in the specified namespace. To add
* an artifact, a user must have {@link Action#WRITE} on the namespace in which
* the artifact is being added. If authorization is successful, and
* the artifact is added successfully, then the user gets all {@link Action privileges}
* on the added artifact.
*/
@VisibleForTesting
public ArtifactDetail addArtifact(final Id.Artifact artifactId, final File artifactFile, @Nullable Set<ArtifactRange> parentArtifacts, @Nullable Set<PluginClass> additionalPlugins, Map<String, String> properties) throws Exception {
if (additionalPlugins != null) {
validatePluginSet(additionalPlugins);
}
parentArtifacts = parentArtifacts == null ? Collections.<ArtifactRange>emptySet() : parentArtifacts;
CloseableClassLoader parentClassLoader = null;
EntityImpersonator entityImpersonator = new EntityImpersonator(artifactId.toEntityId(), impersonator);
if (!parentArtifacts.isEmpty()) {
validateParentSet(artifactId, parentArtifacts);
parentClassLoader = createParentClassLoader(artifactId, parentArtifacts, entityImpersonator);
}
try {
ArtifactClasses artifactClasses = inspectArtifact(artifactId, artifactFile, additionalPlugins, parentClassLoader);
ArtifactMeta meta = new ArtifactMeta(artifactClasses, parentArtifacts, properties);
ArtifactDetail artifactDetail = artifactStore.write(artifactId, meta, Files.newInputStreamSupplier(artifactFile), entityImpersonator);
ArtifactDescriptor descriptor = artifactDetail.getDescriptor();
// info hides some fields that are available in detail, such as the location of the artifact
ArtifactInfo artifactInfo = new ArtifactInfo(descriptor.getArtifactId(), artifactDetail.getMeta().getClasses(), artifactDetail.getMeta().getProperties());
// add system metadata for artifacts
writeSystemMetadata(artifactId.toEntityId(), artifactInfo);
return artifactDetail;
} finally {
Closeables.closeQuietly(parentClassLoader);
}
}
use of co.cask.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class ServiceArtifactTestRun method testServiceArtifact.
@Test
public void testServiceArtifact() throws Exception {
ApplicationManager appManager = deployWithArtifact(ServiceArtifactApp.class, artifactJar);
ServiceManager serviceManager = appManager.getServiceManager("artifact").start();
URL serviceURL = serviceManager.getServiceURL(30, TimeUnit.SECONDS);
Assert.assertNotNull(serviceURL);
URL listURL = serviceURL.toURI().resolve("list").toURL();
try (Reader reader = new InputStreamReader(listURL.openStream(), StandardCharsets.UTF_8)) {
List<ArtifactInfo> artifacts = new Gson().fromJson(reader, new TypeToken<List<ArtifactInfo>>() {
}.getType());
// It should have the test app, and two plugin artifacts
Assert.assertEquals(3, artifacts.size());
Assert.assertTrue(artifacts.stream().anyMatch(info -> info.getName().equals(ServiceArtifactApp.class.getSimpleName())));
Assert.assertTrue(artifacts.stream().anyMatch(info -> info.getName().equals("dummybase")));
Assert.assertTrue(artifacts.stream().anyMatch(info -> info.getName().equals("dummy")));
}
URL loadURL = serviceURL.toURI().resolve("load?parent=dummybase&plugin=dummy&class=" + DummyPlugin.class.getName()).toURL();
HttpURLConnection urlConn = (HttpURLConnection) loadURL.openConnection();
Assert.assertEquals(200, urlConn.getResponseCode());
try (Reader reader = new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8)) {
Assert.assertEquals(DummyPlugin.class.getName(), CharStreams.toString(reader));
}
serviceManager.stop();
serviceManager.waitForStatus(false);
}
use of co.cask.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class LocalArtifactManager method listArtifacts.
@Override
public List<ArtifactInfo> listArtifacts() throws IOException {
return Retries.callWithRetries(() -> {
try {
List<ArtifactInfo> result = new ArrayList<>(artifactRepository.getArtifactsInfo(namespaceId));
result.addAll(artifactRepository.getArtifactsInfo(NamespaceId.SYSTEM));
return result;
} catch (IOException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}, retryStrategy);
}
use of co.cask.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForArtifacts.
private void writeSystemMetadataForArtifacts(NamespaceId namespace) throws IOException {
for (ArtifactDetail artifactDetail : artifactStore.getArtifacts(namespace)) {
co.cask.cdap.api.artifact.ArtifactId artifact = artifactDetail.getDescriptor().getArtifactId();
ArtifactInfo artifactInfo = new ArtifactInfo(artifact, artifactDetail.getMeta().getClasses(), artifactDetail.getMeta().getProperties());
ArtifactId artifactId = namespace.artifact(artifact.getName(), artifact.getVersion().getVersion());
SystemMetadataWriter writer = new ArtifactSystemMetadataWriter(metadataStore, artifactId, artifactInfo);
writer.write();
}
}
Aggregations