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);
}
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());
}
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);
}
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());
}
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);
}
Aggregations