Search in sources :

Example 11 with ArtifactScope

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);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope)

Example 12 with ArtifactScope

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");
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) JsonObject(com.google.gson.JsonObject) FileReader(java.io.FileReader) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) AppRequest(io.cdap.cdap.proto.artifact.AppRequest)

Example 13 with ArtifactScope

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);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo)

Example 14 with ArtifactScope

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);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 15 with ArtifactScope

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());
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Aggregations

ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)32 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)12 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)8 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 File (java.io.File)8 Map (java.util.Map)8 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)6 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)6 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)6 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)6 ArrayList (java.util.ArrayList)6 FileReader (java.io.FileReader)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonObject (com.google.gson.JsonObject)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 JsonWriter (com.google.gson.stream.JsonWriter)4 ApplicationConfigUpdateAction (io.cdap.cdap.api.app.ApplicationConfigUpdateAction)4 AccessException (io.cdap.cdap.api.security.AccessException)4