use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor in project cdap by caskdata.
the class LocalApplicationManagerTest method testImproperOrNoManifestFile.
/**
* Improper Manifest file should throw an exception.
*/
@Test(expected = ExecutionException.class)
public void testImproperOrNoManifestFile() throws Exception {
// Create an JAR without the MainClass set.
File deployFile = TMP_FOLDER.newFile();
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(deployFile), new Manifest())) {
output.putNextEntry(new JarEntry("dummy"));
}
Location jarLoc = Locations.toLocation(deployFile);
ArtifactId artifactId = new ArtifactId("dummy", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, jarLoc);
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, "some.class.name", null, null, null);
AppFabricTestHelper.getLocalManager().deploy(info).get();
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor in project cdap by caskdata.
the class LocalApplicationManagerTest method testGoodPipeline.
/**
* Good pipeline with good tests.
*/
@Test
public void testGoodPipeline() throws Exception {
Location deployedJar = AppJarHelper.createDeploymentJar(lf, ToyApp.class);
ArtifactId artifactId = new ArtifactId("toyapp", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ToyApp.class.getName(), null, null, null);
ApplicationWithPrograms input = AppFabricTestHelper.getLocalManager().deploy(info).get();
Assert.assertEquals(input.getPrograms().iterator().next().getProgramId().getType(), ProgramType.FLOW);
Assert.assertEquals(input.getPrograms().iterator().next().getProgramId().getProgram(), "ToyFlow");
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor in project cdap by caskdata.
the class LocalApplicationManagerTest method testValidConfigPipeline.
@Test
public void testValidConfigPipeline() throws Exception {
Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class);
ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myStream", "myTable");
ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "MyApp", null, GSON.toJson(config));
AppFabricTestHelper.getLocalManager().deploy(info).get();
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor in project cdap by caskdata.
the class LocalApplicationManagerTest method testInvalidConfigPipeline.
@Test(expected = ExecutionException.class)
public void testInvalidConfigPipeline() throws Exception {
Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class);
ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "BadApp", null, GSON.toJson("invalid"));
AppFabricTestHelper.getLocalManager().deploy(info).get();
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugin.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/" + "versions/{artifact-version}/extensions/{plugin-type}/plugins/{plugin-name}")
public void getArtifactPlugin(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @PathParam("plugin-name") String pluginName, @QueryParam("scope") @DefaultValue("user") final String scope, @QueryParam("artifactName") final String pluginArtifactName, @QueryParam("artifactVersion") String pluginVersion, @QueryParam("artifactScope") final String pluginScope, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException, InvalidArtifactRangeException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
final NamespaceId pluginArtifactNamespace = validateAndGetScopedNamespace(namespace, pluginScope);
ArtifactId parentArtifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
final ArtifactVersionRange pluginRange = pluginVersion == null ? null : ArtifactVersionRange.parse(pluginVersion);
int limitNumber = Integer.valueOf(limit);
limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber;
ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
Predicate<ArtifactId> predicate = new Predicate<ArtifactId>() {
@Override
public boolean apply(ArtifactId input) {
// by default, the scoped namespace is for USER scope
return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion()))));
}
};
try {
SortedMap<ArtifactDescriptor, PluginClass> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(parentArtifactId), pluginType, pluginName, predicate, limitNumber, sortOrder);
List<PluginInfo> pluginInfos = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, PluginClass> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
PluginClass pluginClass = pluginsEntry.getValue();
pluginInfos.add(new PluginInfo(pluginClass, pluginArtifactSummary));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginInfos));
} catch (PluginNotExistsException e) {
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", parentArtifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
Aggregations