use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class StandaloneTester method addSystemArtifact.
/**
* Adds a system artifact to CDAP instance that is used for testing.
*/
public void addSystemArtifact(String name, ArtifactVersion version, File artifactFile, @Nullable Set<ArtifactRange> parentArtifacts) throws Exception {
ArtifactRepository artifactRepository = standaloneMain.getInjector().getInstance(ArtifactRepository.class);
ArtifactId artifactId = NamespaceId.SYSTEM.artifact(name, version.getVersion());
artifactRepository.addArtifact(Id.Artifact.fromEntityId(artifactId), artifactFile, parentArtifacts, null);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class DistributedWorkflowProgramRunnerTest method createWorkflowProgram.
/**
* Creates a workflow {@link Program}.
*/
private Program createWorkflowProgram(CConfiguration cConf, ProgramRunner programRunner, String workflowName) throws IOException {
Location appJarLocation = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TEMP_FOLDER.newFolder()), DistributedWorkflowTestApp.class);
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("test", "1.0.0");
DistributedWorkflowTestApp app = new DistributedWorkflowTestApp();
DefaultAppConfigurer configurer = new DefaultAppConfigurer(Id.Namespace.DEFAULT, Id.Artifact.fromEntityId(artifactId), app);
app.configure(configurer, new DefaultApplicationContext<>());
ApplicationSpecification appSpec = configurer.createSpecification(null);
ProgramId programId = NamespaceId.DEFAULT.app(appSpec.getName()).program(ProgramType.WORKFLOW, workflowName);
return Programs.create(cConf, programRunner, new ProgramDescriptor(programId, appSpec), appJarLocation, TEMP_FOLDER.newFolder());
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class LocalArtifactManager method getArtifactLocation.
@Override
protected Location getArtifactLocation(ArtifactInfo artifactInfo, @Nullable String artifactNamespace) throws IOException {
NamespaceId namespace;
if (ArtifactScope.SYSTEM.equals(artifactInfo.getScope())) {
namespace = NamespaceId.SYSTEM;
} else if (artifactNamespace != null) {
namespace = new NamespaceId(artifactNamespace);
} else {
namespace = namespaceId;
}
ArtifactId artifactId = namespace.artifact(artifactInfo.getName(), artifactInfo.getVersion());
return Retries.callWithRetries(() -> {
try {
ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
return artifactDetail.getDescriptor().getLocation();
} catch (IOException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}, retryStrategy);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class RemotePluginFinder method findPlugin.
@Override
public Map.Entry<ArtifactDescriptor, PluginClass> findPlugin(NamespaceId pluginNamespaceId, ArtifactId parentArtifactId, String pluginType, String pluginName, PluginSelector selector) throws PluginNotExistsException {
try {
return Retries.callWithRetries(() -> {
List<PluginInfo> infos = getPlugins(pluginNamespaceId, parentArtifactId, pluginType, pluginName);
if (infos.isEmpty()) {
throw new PluginNotExistsException(pluginNamespaceId, pluginType, pluginName);
}
SortedMap<io.cdap.cdap.api.artifact.ArtifactId, PluginClass> plugins = new TreeMap<>();
for (PluginInfo info : infos) {
ArtifactSummary artifactSummary = info.getArtifact();
io.cdap.cdap.api.artifact.ArtifactId pluginArtifactId = new io.cdap.cdap.api.artifact.ArtifactId(artifactSummary.getName(), new ArtifactVersion(artifactSummary.getVersion()), artifactSummary.getScope());
PluginClass pluginClass = PluginClass.builder().setName(info.getName()).setType(info.getType()).setDescription(info.getDescription()).setClassName(info.getClassName()).setProperties(info.getProperties()).setConfigFieldName(info.getConfigFieldName()).build();
plugins.put(pluginArtifactId, pluginClass);
}
Map.Entry<io.cdap.cdap.api.artifact.ArtifactId, PluginClass> selected = selector.select(plugins);
if (selected == null) {
throw new PluginNotExistsException(pluginNamespaceId, pluginType, pluginName);
}
Location artifactLocation = getArtifactLocation(Artifacts.toProtoArtifactId(pluginNamespaceId, selected.getKey()));
return Maps.immutableEntry(new ArtifactDescriptor(pluginNamespaceId.getEntityName(), selected.getKey(), artifactLocation), selected.getValue());
}, retryStrategy);
} catch (PluginNotExistsException e) {
throw e;
} catch (ArtifactNotFoundException e) {
throw new PluginNotExistsException(pluginNamespaceId, pluginType, pluginName);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class RemoteConfiguratorTest method testBadAppConfig.
@Test(expected = ExecutionException.class)
public void testBadAppConfig() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, ConfigTestApp.class);
ArtifactId artifactId = NamespaceId.DEFAULT.artifact(ConfigTestApp.class.getSimpleName(), "1.0.0");
artifacts.put(artifactId, new ArtifactDetail(new ArtifactDescriptor(artifactId.getNamespace(), artifactId.toApiArtifactId(), appJar), new ArtifactMeta(ArtifactClasses.builder().build())));
AppDeploymentInfo info = new AppDeploymentInfo(artifactId, appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), "BadApp", null, GSON.toJson("invalid"));
Configurator configurator = new RemoteConfigurator(cConf, metricsCollectionService, info, remoteClientFactory);
// Expect the future.get would throw an exception
configurator.config().get(10, TimeUnit.SECONDS);
}
Aggregations