use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
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.api.artifact.ArtifactSummary in project cdap by caskdata.
the class UpdateAppCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String appName = arguments.get(ArgumentName.APP.toString());
ApplicationId appId = cliConfig.getCurrentNamespace().app(appName);
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactScope artifactScope = ArtifactScope.valueOf(arguments.get(ArgumentName.SCOPE.toString()).toUpperCase());
ArtifactSummary artifact = new ArtifactSummary(artifactName, artifactVersion, artifactScope);
JsonObject config = new JsonObject();
String configPath = arguments.getOptional(ArgumentName.APP_CONFIG_FILE.toString());
if (configPath != null) {
File configFile = resolver.resolvePathToFile(configPath);
try (FileReader reader = new FileReader(configFile)) {
AppRequest<JsonObject> appRequest = GSON.fromJson(reader, CONFIG_TYPE);
config = appRequest.getConfig();
}
}
AppRequest<JsonObject> appRequest = new AppRequest<>(artifact, config);
applicationClient.update(appId, appRequest);
output.println("Successfully updated application");
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class CreateAppCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
ApplicationId appId = parseApplicationId(arguments);
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactScope artifactScope = ArtifactScope.valueOf(arguments.get(ArgumentName.SCOPE.toString()).toUpperCase());
ArtifactSummary artifact = new ArtifactSummary(artifactName, artifactVersion, artifactScope);
JsonObject config = new JsonObject();
String ownerPrincipal = null;
Boolean updateSchedules = null;
PreviewConfig previewConfig = null;
String configPath = arguments.getOptional(ArgumentName.APP_CONFIG_FILE.toString());
if (configPath != null) {
File configFile = resolver.resolvePathToFile(configPath);
try (FileReader reader = new FileReader(configFile)) {
AppRequest<JsonObject> appRequest = GSON.fromJson(reader, configType);
config = appRequest.getConfig();
ownerPrincipal = appRequest.getOwnerPrincipal();
previewConfig = appRequest.getPreview();
updateSchedules = appRequest.canUpdateSchedules();
}
}
AppRequest<JsonObject> appRequest = new AppRequest<>(artifact, config, previewConfig, ownerPrincipal, updateSchedules);
applicationClient.deploy(appId, appRequest);
output.println("Successfully created application");
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method before.
@Before
public void before() throws Exception {
addAppArtifact(artifactId, AppWithDataset.class);
AppRequest<Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
appClient.deploy(application, appRequest);
// Ensure the system metadata has been processed
Tasks.waitFor(false, () -> getProperties(artifactId, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(application, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(pingService, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method getArtifactId.
/**
* Returns the artifact id of the deployed application. Need this because we don't know the exact version.
*/
private ArtifactId getArtifactId() throws Exception {
Iterable<ArtifactSummary> filtered = artifactClient.list(NamespaceId.DEFAULT).stream().filter(artifactSummary -> AllProgramsApp.class.getSimpleName().equals(artifactSummary.getName())).collect(Collectors.toList());
ArtifactSummary artifact = Iterables.getOnlyElement(filtered);
return NamespaceId.DEFAULT.artifact(artifact.getName(), artifact.getVersion());
}
Aggregations