public static Artifact fromEntityId(ArtifactId artifactId) { return from(Namespace.fromEntityId(artifactId.getParent()), artifactId.getArtifact(), artifactId.getVersion()); }
protected static void setupStreamingArtifacts(ArtifactId artifactId, Class<?> appClass) throws Exception { // add the app artifact addAppArtifact(artifactId, appClass, StreamingSource.class.getPackage().getName(), Transform.class.getPackage().getName(), SparkCompute.class.getPackage().getName(), PipelineConfigurable.class.getPackage().getName()); // add plugins artifact addPluginArtifact(new ArtifactId(artifactId.getNamespace(), artifactId.getArtifact() + "-mocks", "1.0.0"), artifactId, STREAMING_MOCK_PLUGINS, co.cask.cdap.etl.mock.spark.streaming.MockSource.class, co.cask.cdap.etl.mock.batch.MockSink.class, co.cask.cdap.etl.mock.spark.streaming.MockSink.class, DoubleTransform.class, AllErrorTransform.class, IdentityTransform.class, IntValueFilterTransform.class, StringValueFilterTransform.class, StringValueFilterCompute.class, Window.class, NullFieldSplitterTransform.class, NullAlertTransform.class); }
public ArtifactSystemMetadataWriter(MetadataStore metadataStore, ArtifactId artifactId, ArtifactInfo artifactInfo) { super(metadataStore, artifactId); this.artifactInfo = artifactInfo; this.existing = !metadataStore.getProperties(MetadataScope.SYSTEM, artifactId.toMetadataEntity()).isEmpty(); }
@SuppressWarnings("unused") public static ArtifactId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new ArtifactId( next(iterator, "namespace"), next(iterator, "artifact"), remaining(iterator, "version")); }
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())); } }
@Override public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) { Preconditions.checkNotNull(applicationClz, "Application class cannot be null."); Type configType = Artifacts.getConfigType(applicationClz); try { ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT"); addAppArtifact(artifactId, applicationClz, new Manifest(), bundleEmbeddedJars); if (configObject == null) { configObject = (Config) TypeToken.of(configType).getRawType().newInstance(); } Application app = applicationClz.newInstance(); MockAppConfigurer configurer = new MockAppConfigurer(app); app.configure(configurer, new DefaultApplicationContext<>(configObject)); ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName()); ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()); appFabricClient.deployApplication(Id.Application.fromEntityId(applicationId), new AppRequest(artifactSummary, configObject)); return appManagerFactory.create(applicationId); } catch (Exception e) { throw Throwables.propagate(e); } }
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()); } }
ArtifactId artifactId = (ArtifactId) entityId; ArtifactId thatArtifactId = (ArtifactId) thatEntityId; return Objects.equals(artifactId.getNamespace(), thatArtifactId.getNamespace()) && Objects.equals(artifactId.getArtifact(), thatArtifactId.getArtifact());
throw new IllegalArgumentException("If a name is specified, a version must also be specified."); } else if (name == null) { artifactId = new ArtifactId(cliConfig.getCurrentNamespace().getNamespace(), artifactFile.getName()); } else { artifactId = cliConfig.getCurrentNamespace().artifact(name, version); NamespaceId namespace = artifactId.getParent(); if (configPath == null) { artifactClient.add(namespace, artifactId.getEntityName(), () -> new FileInputStream(artifactFile), artifactId.getVersion()); } else { File configFile = resolver.resolvePathToFile(configPath); ArtifactConfig artifactConfig = configReader.read(Id.Namespace.fromEntityId(namespace), configFile); artifactClient.add(namespace, artifactId.getEntityName(), () -> new FileInputStream(artifactFile), artifactId.getVersion(), artifactConfig.getParents(), artifactConfig.getPlugins()); output.printf("Successfully added artifact with name '%s'\n", artifactId.getEntityName());
new ArtifactRange(appArtifactId.getNamespace(), appArtifactId.getArtifact(), new ArtifactVersion(appArtifactId.getVersion()), true, new ArtifactVersion(appArtifactId.getVersion()), true)), null); Assert.assertEquals(pluginArtifactId.toApiArtifactId(), entry.getKey().getArtifactId()); Assert.assertEquals("Plugin1", entry.getValue().getName()); Assert.assertEquals("dummy", entry.getValue().getType()); Assert.assertEquals(pluginArtifactId.toApiArtifactId(), entry.getKey().getArtifactId()); Assert.assertEquals("Plugin1", entry.getValue().getName()); Assert.assertEquals("dummy", entry.getValue().getType()); Assert.assertEquals(systemPluginArtifactId.toApiArtifactId(), entry.getKey().getArtifactId()); Assert.assertEquals("Plugin1", entry.getValue().getName()); Assert.assertEquals("dummy", entry.getValue().getType());
HttpMethod.GET, String.format("namespaces/%s/artifacts/%s/versions/%s/extensions/%s/plugins/%s?scope=%s&pluginScope=%s", namespaceId.getNamespace(), parentArtifactId.getArtifact(), parentArtifactId.getVersion(), pluginType, pluginName, NamespaceId.SYSTEM.equals(parentArtifactId.getNamespaceId()) ? ArtifactScope.SYSTEM : ArtifactScope.USER, NamespaceId.SYSTEM.equals(namespaceId.getNamespaceId())
public ArtifactId artifact(String artifact, String version) { return new ArtifactId(namespace, artifact, version); }
@Override public int hashCode() { if (entityId.getEntityType().equals(EntityType.ARTIFACT)) { ArtifactId artifactId = (ArtifactId) entityId; return Objects.hash(artifactId.getEntityType(), artifactId.getNamespace(), artifactId.getArtifact()); } if (entityId.getEntityType().equals(EntityType.APPLICATION)) { ApplicationId applicationId = (ApplicationId) entityId; return Objects.hash(applicationId.getEntityType(), applicationId.getNamespace(), applicationId.getApplication()); } if (entityId.getEntityType().equals(EntityType.PROGRAM)) { ProgramId programId = (ProgramId) entityId; return Objects.hash(programId.getEntityType(), programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram()); } return Objects.hash(entityId); } }
@Test public void testSearchIncludesSystemEntities() throws InterruptedException, TransactionFailureException { final MetadataEntity sysArtifact = NamespaceId.SYSTEM.artifact("artifact", "1.0").toMetadataEntity(); final MetadataEntity ns2Artifact = new ArtifactId("ns2", "artifact", "1.0").toMetadataEntity(); final String multiWordKey = "multiword"; final String multiWordValue = "aV1 av2 , - , av3 - av4_av5 av6";
@Override public String getEntityName() { return getArtifact(); }
private void addPluginsInRangeToMap(final NamespaceId namespace, List<Id.Artifact> parentArtifacts, Iterator<StructuredRow> iterator, SortedMap<ArtifactDescriptor, PluginClass> plugins, @Nullable Predicate<co.cask.cdap.proto.id.ArtifactId> range, int limit) { // if predicate is null, // filter out plugins whose artifacts are not in the system namespace and not in this namespace range = range != null ? range : input -> NamespaceId.SYSTEM.equals(input.getParent()) || input.getParent().equals(namespace); while (iterator.hasNext()) { StructuredRow row = iterator.next(); ImmutablePair<ArtifactDescriptor, PluginData> pluginPair = getPlugin(row, range); if (pluginPair == null) { continue; } PluginData pluginData = pluginPair.getSecond(); // filter out plugins that don't extend this version of the parent artifact for (Id.Artifact parentArtifactId : parentArtifacts) { if (pluginData.isUsableBy(parentArtifactId.toEntityId()) && isAllowed(pluginData.pluginClass)) { plugins.put(pluginPair.getFirst(), pluginData.pluginClass); break; } } if (limit < plugins.size()) { plugins.remove(plugins.lastKey()); } } }
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())); } }
@Override public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) { Preconditions.checkNotNull(applicationClz, "Application class cannot be null."); Type configType = Artifacts.getConfigType(applicationClz); try { ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT"); addAppArtifact(artifactId, applicationClz, new Manifest(), bundleEmbeddedJars); if (configObject == null) { configObject = (Config) TypeToken.of(configType).getRawType().newInstance(); } Application app = applicationClz.newInstance(); MockAppConfigurer configurer = new MockAppConfigurer(app); app.configure(configurer, new DefaultApplicationContext<>(configObject)); ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName()); ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()); appFabricClient.deployApplication(Id.Application.fromEntityId(applicationId), new AppRequest(artifactSummary, configObject)); return appManagerFactory.create(applicationId); } catch (Exception e) { throw Throwables.propagate(e); } }
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()); } }
ArtifactId artifactId = (ArtifactId) entityId; entityId = Ids.namespace(artifactId.getNamespace()).artifact(artifactId.getArtifact(), "1");