use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRepositoryTest method testNamespaceIsolation.
@Test
public void testNamespaceIsolation() throws Exception {
// create system app artifact
Id.Artifact systemAppArtifactId = Id.Artifact.from(Id.Namespace.SYSTEM, "PluginTest", "1.0.0");
File jar = createAppJar(PluginTestApp.class, new File(systemArtifactsDir1, "PluginTest-1.0.0.jar"), createManifest(ManifestFields.EXPORT_PACKAGE, PluginTestRunnable.class.getPackage().getName()));
artifactRepository.addSystemArtifacts();
Assert.assertTrue(jar.delete());
Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(systemAppArtifactId.getNamespace().getId(), systemAppArtifactId.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
NamespaceId namespace1 = Ids.namespace("ns1");
NamespaceId namespace2 = Ids.namespace("ns2");
Id.Artifact pluginArtifactId1 = Id.Artifact.from(namespace1.toId(), "myPlugin", "1.0");
Id.Artifact pluginArtifactId2 = Id.Artifact.from(namespace2.toId(), "myPlugin", "1.0");
try {
// create plugin artifact in namespace1 that extends the system artifact
// 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);
artifactRepository.addArtifact(pluginArtifactId1, jarFile, parents);
// create plugin artifact in namespace2 that extends the system artifact
artifactRepository.addArtifact(pluginArtifactId2, jarFile, parents);
// check that only plugins from the artifact in the namespace are returned, and not plugins from both
SortedMap<ArtifactDescriptor, Set<PluginClass>> extensions = artifactRepository.getPlugins(namespace1, systemAppArtifactId);
Assert.assertEquals(1, extensions.keySet().size());
Assert.assertEquals(2, extensions.values().iterator().next().size());
extensions = artifactRepository.getPlugins(namespace2, systemAppArtifactId);
Assert.assertEquals(1, extensions.keySet().size());
Assert.assertEquals(2, extensions.values().iterator().next().size());
} finally {
artifactRepository.clear(NamespaceId.SYSTEM);
artifactRepository.clear(namespace1);
artifactRepository.clear(namespace2);
}
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRepositoryTest method testGrandparentsAreInvalid.
@Test(expected = InvalidArtifactException.class)
public void testGrandparentsAreInvalid() throws Exception {
// create child artifact
Id.Artifact childId = Id.Artifact.from(Id.Namespace.DEFAULT, "child", "1.0.0");
Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
File jarFile = createPluginJar(Plugin1.class, new File(tmpDir, "child-1.0.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")));
artifactRepository.addArtifact(childId, jarFile, parents);
// try and create grandchild, should throw exception
Id.Artifact grandchildId = Id.Artifact.from(Id.Namespace.DEFAULT, "grandchild", "1.0.0");
manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin2.class.getPackage().getName());
jarFile = createPluginJar(Plugin2.class, new File(tmpDir, "grandchild-1.0.0.jar"), manifest);
parents = ImmutableSet.of(new ArtifactRange(childId.getNamespace().getId(), childId.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
artifactRepository.addArtifact(grandchildId, jarFile, parents);
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class ArtifactRangeTest method testIsInRange.
@Test
public void testIsInRange() {
ArtifactRange range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "test", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.0.9")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.9.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("0.9")));
// 1 < 1.0 < 1.0.0-SNAPSHOT < 1.0.0
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("1.0.0-SNAPSHOT")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.0")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.1-SNAPSHOT")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.0.1")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("1.1.0")));
// 2 < 2.0 < 2.0.0-SNAPSHOT < 2.0.0
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2.0")));
Assert.assertTrue(range.versionIsInRange(new ArtifactVersion("2.0.0-SNAPSHOT")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("2.0.0")));
Assert.assertFalse(range.versionIsInRange(new ArtifactVersion("2.0.1")));
}
use of co.cask.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.
the class AppFabricTestHelper method deployApplicationWithManager.
public static ApplicationWithPrograms deployApplicationWithManager(Id.Namespace namespace, Class<?> appClass, Supplier<File> folderSupplier, Config config) throws Exception {
ensureNamespaceExists(namespace.toEntityId());
Location deployedJar = createAppJar(appClass, folderSupplier);
ArtifactVersion artifactVersion = new ArtifactVersion(String.format("1.0.%d", System.currentTimeMillis()));
ArtifactId artifactId = new ArtifactId(appClass.getSimpleName(), artifactVersion, ArtifactScope.USER);
ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
ArtifactRepository artifactRepository = getInjector().getInstance(ArtifactRepository.class);
artifactRepository.addArtifact(Artifacts.toArtifactId(namespace.toEntityId(), artifactId).toId(), new File(deployedJar.toURI()));
AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, namespace.toEntityId(), appClass.getName(), null, null, config == null ? null : new Gson().toJson(config));
return getLocalManager().deploy(info).get();
}
use of co.cask.cdap.api.artifact.ArtifactVersion 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);
Id.Artifact 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, 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.getName(), pluginClass.getType(), pluginClass.getDescription(), pluginClass.getClassName(), pluginArtifactSummary, pluginClass.getProperties(), pluginClass.getEndpoints()));
}
responder.sendJson(HttpResponseStatus.OK, 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