use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class SetArtifactPropertiesCommand 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());
String scopeStr = arguments.get(ArgumentName.SCOPE.toString());
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
NamespaceId namespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : cliConfig.getCurrentNamespace();
ArtifactId artifactId = namespace.artifact(artifactName, artifactVersion);
String propertiesFilePath = arguments.get(ArgumentName.LOCAL_FILE_PATH.toString());
File propertiesFile = resolver.resolvePathToFile(propertiesFilePath);
try (Reader reader = new FileReader(propertiesFile)) {
ArtifactProperties properties;
try {
properties = GSON.fromJson(reader, ArtifactProperties.class);
} catch (Exception e) {
throw new RuntimeException("Error parsing file contents. Please check that it is a valid JSON object, " + "and that it contains a 'properties' key whose value is a JSON object of the " + "artifact properties.", e);
}
artifactClient.writeProperties(artifactId, properties.properties);
}
}
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");
}
use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.
the class DescribeArtifactCommand 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);
}
Table table = Table.builder().setHeader("name", "version", "scope", "app classes", "plugin classes", "properties", "parents").setRows(ImmutableList.of((List<String>) ImmutableList.of(info.getName(), info.getVersion(), info.getScope().name(), GSON.toJson(info.getClasses().getApps()), GSON.toJson(info.getClasses().getPlugins()), GSON.toJson(info.getProperties()), Joiner.on('/').join(info.getParents())))).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.api.artifact.ArtifactScope 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");
}
Aggregations