Search in sources :

Example 1 with ArtifactScope

use of io.cdap.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);
}
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 2 with ArtifactScope

use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

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)

Example 3 with ArtifactScope

use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class ArtifactSelectorProvider method getArtifactSelector.

/**
 * Gets the corresponding {@link ArtifactSelector} for this config.
 * Validates that any given scope, name, and version are all valid or null. The scope must be an
 * {@link ArtifactScope}, the version must be an {@link ArtifactVersion}, and the name only contains
 * alphanumeric, '-', or '_'. Also checks that at least one field is non-null.
 *
 * @return an {@link ArtifactSelector} using these config settings
 * @throws IllegalArgumentException if any one of the fields are invalid
 */
private ArtifactSelector getArtifactSelector(ArtifactSelectorConfig config) {
    String name = config.getName();
    if (name != null && !nameMatcher.matchesAllOf(name)) {
        throw new IllegalArgumentException(String.format("'%s' is an invalid artifact name. " + "Must contain only alphanumeric, '-', '.', or '_' characters.", name));
    }
    String version = config.getVersion();
    ArtifactVersionRange range;
    try {
        range = version == null ? null : ArtifactVersionRange.parse(version);
    } catch (InvalidArtifactRangeException e) {
        throw new IllegalArgumentException(String.format("%s is an invalid artifact version." + "Must be an exact version or a version range " + "with a lower and upper bound.", version));
    }
    String scope = config.getScope();
    ArtifactScope artifactScope = scope == null ? null : ArtifactScope.valueOf(scope.toUpperCase());
    return new ArtifactSelector(artifactScope, name, range);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) InvalidArtifactRangeException(io.cdap.cdap.api.artifact.InvalidArtifactRangeException)

Example 4 with ArtifactScope

use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class DefaultAppConfigurer method createSpecification.

public ApplicationSpecification createSpecification(@Nullable String applicationName, @Nullable String applicationVersion) {
    // applicationName can be null only for apps before 3.2 that were not upgraded
    ArtifactScope scope = artifactId.getNamespace().equals(Id.Namespace.SYSTEM) ? ArtifactScope.SYSTEM : ArtifactScope.USER;
    ArtifactId artifactId = new ArtifactId(this.artifactId.getName(), this.artifactId.getVersion(), scope);
    String namespace = deployNamespace.toEntityId().getNamespace();
    String appName = applicationName == null ? name : applicationName;
    String appVersion = applicationVersion == null ? ApplicationId.DEFAULT_VERSION : applicationVersion;
    Map<String, ScheduleCreationSpec> builtScheduleSpecs = new HashMap<>();
    for (Map.Entry<String, ScheduleCreationSpec> entry : scheduleSpecs.entrySet()) {
        // If the ScheduleCreationSpec is really a builder, then build the ScheduleCreationSpec
        if (entry.getValue() instanceof DefaultScheduleBuilder.ScheduleCreationBuilder) {
            DefaultScheduleBuilder.ScheduleCreationBuilder builder = (DefaultScheduleBuilder.ScheduleCreationBuilder) entry.getValue();
            builtScheduleSpecs.put(entry.getKey(), builder.build(namespace, appName, appVersion));
        } else {
            builtScheduleSpecs.put(entry.getKey(), entry.getValue());
        }
    }
    return new DefaultApplicationSpecification(appName, appVersion, ProjectInfo.getVersion().toString(), description, configuration, artifactId, getDatasetModules(), getDatasetSpecs(), mapReduces, sparks, workflows, services, builtScheduleSpecs, workers, getPlugins());
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) DefaultScheduleBuilder(io.cdap.cdap.internal.app.runtime.schedule.DefaultScheduleBuilder) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ScheduleCreationSpec(io.cdap.cdap.internal.schedule.ScheduleCreationSpec) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ArtifactScope

use of io.cdap.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

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)

Aggregations

ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)16 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)6 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 File (java.io.File)4 Map (java.util.Map)4 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)3 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)3 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)3 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)3 FileReader (java.io.FileReader)3 ArrayList (java.util.ArrayList)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 JsonObject (com.google.gson.JsonObject)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 JsonWriter (com.google.gson.stream.JsonWriter)2 ApplicationConfigUpdateAction (io.cdap.cdap.api.app.ApplicationConfigUpdateAction)2 RowMaker (io.cdap.cdap.cli.util.RowMaker)2