use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactClient method list.
/**
* Lists all artifacts in the given namespace, optionally including system artifacts.
*
* @param namespace the namespace to list artifacts in
* @param scope the scope of the artifacts to get. If {@code null}, both user and system artifacts are listed
* @return list of {@link ArtifactSummary}
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the namespace could not be found
*/
public List<ArtifactSummary> list(NamespaceId namespace, @Nullable ArtifactScope scope) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
URL url = scope == null ? config.resolveNamespacedURLV3(namespace, "artifacts") : config.resolveNamespacedURLV3(namespace, String.format("artifacts?scope=%s", scope.name()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(namespace);
}
return ObjectResponse.<List<ArtifactSummary>>fromJsonBody(response, ARTIFACT_SUMMARIES_TYPE).getResponseObject();
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactClient method listVersions.
/**
* Lists all versions of the given artifact in the given namespace.
*
* @param namespace the namespace to list artifact versions in
* @param artifactName the name of the artifact
* @param scope the scope of artifacts to get. If none is given, the scope defaults to the user scope
* @return list of {@link ArtifactSummary}
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the given artifact does not exist
*/
public List<ArtifactSummary> listVersions(NamespaceId namespace, String artifactName, @Nullable ArtifactScope scope) throws UnauthenticatedException, IOException, ArtifactNotFoundException, UnauthorizedException {
URL url = scope == null ? config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s", artifactName)) : config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s?scope=%s", artifactName, scope.name()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(namespace, artifactName);
}
return ObjectResponse.<List<ArtifactSummary>>fromJsonBody(response, ARTIFACT_SUMMARIES_TYPE).getResponseObject();
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class TestFrameworkTestRun method testAppVersionsCreation.
@Test
public void testAppVersionsCreation() throws Exception {
ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version1");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS1", "tD1", "tV1"));
ApplicationManager appManager = deployApplication(appId, createRequest);
ServiceManager serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
URL serviceURL = serviceManager.getServiceURL();
Gson gson = new Gson();
Assert.assertEquals("tV1", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version2");
createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS2", "tD2", "tV2"));
appManager = deployApplication(appId, createRequest);
serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
serviceURL = serviceManager.getServiceURL();
Assert.assertEquals("tV2", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class TestFrameworkTestRun method testInvalidAppWithDuplicateDatasets.
@Test
public void testInvalidAppWithDuplicateDatasets() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("invalid-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithDuplicateData.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("InvalidApp");
for (int choice = 4; choice > 0; choice /= 2) {
try {
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass((choice == 4), (choice == 2), (choice == 1)));
deployApplication(appId, createRequest);
// fail if we succeed with application deployment
Assert.fail();
} catch (Exception e) {
// expected
}
}
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass(false, false, false));
deployApplication(appId, createRequest);
}
use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugins.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions/{plugin-type}")
public void getArtifactPlugins(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
Id.Artifact artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
try {
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, artifactId, pluginType);
List<PluginSummary> pluginSummaries = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
for (PluginClass pluginClass : pluginsEntry.getValue()) {
pluginSummaries.add(new PluginSummary(pluginClass.getName(), pluginClass.getType(), pluginClass.getDescription(), pluginClass.getClassName(), pluginArtifactSummary));
}
}
responder.sendJson(HttpResponseStatus.OK, pluginSummaries);
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
Aggregations