use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class Artifacts method toArtifactId.
/**
* Converts a {@link ArtifactId} to {@link co.cask.cdap.proto.id.ArtifactId}.
*
* @param namespaceId the user namespace to use
* @param artifactId the artifact id to convert
*/
public static co.cask.cdap.proto.id.ArtifactId toArtifactId(NamespaceId namespaceId, ArtifactId artifactId) {
ArtifactScope scope = artifactId.getScope();
NamespaceId artifactNamespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespaceId;
return artifactNamespace.artifact(artifactId.getName(), artifactId.getVersion().getVersion());
}
use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class ListArtifactVersionsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
List<ArtifactSummary> artifactSummaries;
if (scopeStr == null) {
artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName);
} else {
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName, scope);
}
Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {
@Override
public List<?> makeRow(ArtifactSummary object) {
return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class GetArtifactPropertiesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
ArtifactInfo info;
if (scopeStr == null) {
info = artifactClient.getArtifactInfo(artifactId);
} else {
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
info = artifactClient.getArtifactInfo(artifactId, scope);
}
List<Map.Entry<String, String>> rows = new ArrayList<>(info.getProperties().size());
rows.addAll(info.getProperties().entrySet());
Table table = Table.builder().setHeader("key", "value").setRows(rows, new RowMaker<Map.Entry<String, String>>() {
@Override
public List<String> makeRow(Map.Entry<String, String> entry) {
List<String> columns = new ArrayList<>(2);
columns.add(entry.getKey());
columns.add(entry.getValue());
return columns;
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class PluginSpec method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
type = in.readUTF();
name = in.readUTF();
properties = (Map<String, String>) in.readObject();
boolean artifactExists = in.readBoolean();
if (artifactExists) {
String artifactName = in.readUTF();
ArtifactVersion artifactVersion = new ArtifactVersion(in.readUTF());
ArtifactScope artifactScope = ArtifactScope.valueOf(in.readUTF());
artifact = new ArtifactId(artifactName, artifactVersion, artifactScope);
}
}
use of co.cask.cdap.api.artifact.ArtifactScope 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");
}
Aggregations