use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by cdapio.
the class AbstractArtifactLocalizer method openConnection.
/**
* Opens a connection to appfabric to fetch an artifact.
*
* @param artifactId the ArtifactId of the artifact to fetch
* @param remoteClient the remote client used to fetch the artifact
* @return the HttpURLConnection
* @throws IOException if there was an unexpected error
*/
private HttpURLConnection openConnection(ArtifactId artifactId, RemoteClient remoteClient) throws IOException {
String namespaceId = artifactId.getNamespace();
ArtifactScope scope = ArtifactScope.USER;
// as long as it exists. Using default because it will always be there
if (ArtifactScope.SYSTEM.toString().equalsIgnoreCase(namespaceId)) {
namespaceId = NamespaceId.DEFAULT.getEntityName();
scope = ArtifactScope.SYSTEM;
}
String url = String.format("namespaces/%s/artifacts/%s/versions/%s/download?scope=%s", namespaceId, artifactId.getArtifact(), artifactId.getVersion(), scope);
return remoteClient.openConnection(HttpMethod.GET, url);
}
use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by cdapio.
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.ArtifactScope in project cdap by cdapio.
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 io.cdap.cdap.api.artifact.ArtifactScope in project cdap by cdapio.
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 io.cdap.cdap.api.artifact.ArtifactScope in project cdap by cdapio.
the class Artifacts method toProtoArtifactId.
/**
* Converts a {@link ArtifactId} to {@link io.cdap.cdap.proto.id.ArtifactId}.
*
* @param namespaceId the user namespace to use
* @param artifactId the artifact id to convert
*/
public static io.cdap.cdap.proto.id.ArtifactId toProtoArtifactId(NamespaceId namespaceId, ArtifactId artifactId) {
ArtifactScope scope = artifactId.getScope();
NamespaceId artifactNamespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespaceId;
return artifactNamespace.artifact(artifactId.getName(), artifactId.getVersion().getVersion());
}
Aggregations