public PluginNotExistsException(ArtifactId artifactId, String type, String name) { super("plugin", String.format("%s:%s:%s:%s:%s", artifactId.getNamespace(), type, name, artifactId.getArtifact(), artifactId.getVersion())); } }
private void addArtifact(ArtifactId artifactId, Location jar) throws Exception { File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(jar), destination); jar.delete(); artifactRepository.addArtifact(Id.Artifact.fromEntityId(artifactId), destination); Preconditions.checkState(destination.delete()); } }
private File createPluginJar(ArtifactId artifactId, Class<?> pluginClass, Class<?>... pluginClasses) throws IOException { Manifest manifest = createManifest(pluginClass, pluginClasses); Location appJar = PluginJarHelper.createPluginJar(locationFactory, manifest, pluginClass, pluginClasses); File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(appJar), destination); appJar.delete(); return destination; }
private Set<ArtifactRange> toRange(ArtifactId parent) { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange(parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); return parents; } }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
private static void createSystemArtifact(File systemArtifactsDir) throws IOException { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, PluginTestRunnable.class.getPackage().getName()); File systemArtifact = new File( systemArtifactsDir, String.format("%s-%s.jar", SYSTEM_ARTIFACT.getArtifact(), SYSTEM_ARTIFACT.getVersion()) ); createAppJar(PluginTestApp.class, systemArtifact, manifest); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return new RemoteArtifactManager(clientConfig, restClient, artifactId); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
boolean isUsableBy(co.cask.cdap.proto.id.ArtifactId artifactId) { if (usableBy == null) { return true; } return usableBy.getNamespace().equals(artifactId.getNamespace()) && usableBy.getName().equals(artifactId.getArtifact()) && usableBy.versionIsInRange(new ArtifactVersion(artifactId.getVersion())); } }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, pluginClass, pluginClasses); return new RemoteArtifactManager(clientConfig, restClient, artifactId); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
@Override public boolean apply(ArtifactId input) { // should check if the artifact is from SYSTEM namespace, if not, check if it is from the scoped namespace. // 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())))); } };
@Override public boolean apply(ArtifactId input) { // should check if the artifact is from SYSTEM namespace, if not, check if it is from the scoped namespace. // 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())))); } };
private Map<String, String> getArtifactProperties(ArtifactId artifact) throws URISyntaxException, IOException { URL endpoint = getEndPoint(String.format("%s/namespaces/%s/artifacts/%s/versions/%s/properties", Constants.Gateway.API_VERSION_3, artifact.getNamespace(), artifact.getArtifact(), artifact.getVersion())).toURL(); return getResults(endpoint, MAP_STRING_STRING_TYPE); }
private void deleteArtifact(ArtifactId artifact, boolean deleteArtifact, @Nullable String property) throws Exception { String path = String.format("artifacts/%s/versions/%s/", artifact.getArtifact(), artifact.getVersion()); if (!deleteArtifact) { path += property == null ? "properties" : String.format("properties/%s", property); } HttpResponse response = doDelete(getVersionedAPIPath(path, artifact.getNamespace())); Assert.assertEquals(200, response.getResponseCode()); }
/** * @return {@link ArtifactInfo} of the given artifactId in the given scope */ ArtifactInfo getArtifact(ArtifactId artifactId, ArtifactScope scope) throws URISyntaxException, IOException { // get /artifacts/{name}/versions/{version}?scope={scope} URL endpoint = getEndPoint(String.format("%s/namespaces/%s/artifacts/%s/versions/%s%s", Constants.Gateway.API_VERSION_3, artifactId.getNamespace(), artifactId.getArtifact(), artifactId.getVersion(), getScopeQuery(scope))).toURL(); return getResults(endpoint, ArtifactInfo.class); }
private Set<String> getPluginTypes(ArtifactId artifactId, ArtifactScope scope) throws URISyntaxException, IOException { URL endpoint = getEndPoint(String.format("%s/namespaces/%s/artifacts/%s/versions/%s/extensions%s", Constants.Gateway.API_VERSION_3, artifactId.getNamespace(), artifactId.getArtifact(), artifactId.getVersion(), getScopeQuery(scope)) ).toURL(); return getResults(endpoint, PLUGIN_TYPES_TYPE); }
/** * Deploys an {@link Application} using the given artifact jar with an optional config object. */ protected static <T> ApplicationManager deployWithArtifact(NamespaceId namespaceId, Class<? extends Application> appClass, File artifactJar, @Nullable T config) throws Exception { ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT"); addArtifact(artifactId, artifactJar); AppRequest<T> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), config); return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest); }
private ApplicationManager deploy(NamespaceId namespaceId, Class<? extends Application> appClass) throws Exception { ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT"); addArtifact(artifactId, ARTIFACTS.get(appClass)); AppRequest<?> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), null); return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest); }
@Test public void testAppFromArtifact() throws Exception { ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT"); addAppArtifact(artifactId, ConfigTestApp.class); ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact"); AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>( new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset") ); ApplicationManager appManager = deployApplication(appId, createRequest); testAppConfig(appId.getApplication(), appManager, createRequest.getConfig()); }