use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class Artifacts method toArtifactId.
/**
* Converts a {@link ArtifactId} to {@link co.cask.cdap.proto.id.ArtifactId}.
*
* @param namespaceId the user namespace to use
* @param artifactId the artifact id to convert
*/
public static co.cask.cdap.proto.id.ArtifactId toArtifactId(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 co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class BasicMapReduceContext method addInput.
@Override
public void addInput(Input input, @Nullable Class<?> mapperCls) {
if (input instanceof Input.DatasetInput) {
Input.DatasetInput datasetInput = (Input.DatasetInput) input;
Input.InputFormatProviderInput createdInput = createInput(datasetInput);
addInput(createdInput.getAlias(), createdInput.getInputFormatProvider(), mapperCls);
} else if (input instanceof Input.StreamInput) {
Input.StreamInput streamInput = (Input.StreamInput) input;
String namespace = streamInput.getNamespace();
if (namespace == null) {
namespace = getProgram().getNamespaceId();
}
addInput(input.getAlias(), new StreamInputFormatProvider(new NamespaceId(namespace), streamInput, streamAdmin), mapperCls);
} else if (input instanceof Input.InputFormatProviderInput) {
addInput(input.getAlias(), ((Input.InputFormatProviderInput) input).getInputFormatProvider(), mapperCls);
} else {
// shouldn't happen unless user defines their own Input class
throw new IllegalArgumentException(String.format("Input %s has unknown input class %s", input.getName(), input.getClass().getCanonicalName()));
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactStore method addArtifactsToList.
private void addArtifactsToList(List<ArtifactDetail> artifactDetails, Row row, int limit, @Nullable ArtifactRange range) throws IOException {
ArtifactKey artifactKey = ArtifactKey.parse(row.getRow());
for (Map.Entry<byte[], byte[]> columnVal : row.getColumns().entrySet()) {
if (limit != Integer.MAX_VALUE && artifactDetails.size() == limit) {
break;
}
String version = Bytes.toString(columnVal.getKey());
if (range != null && !range.versionIsInRange(new ArtifactVersion(version))) {
continue;
}
ArtifactData data = GSON.fromJson(Bytes.toString(columnVal.getValue()), ArtifactData.class);
Id.Artifact artifactId = new NamespaceId(artifactKey.namespace).artifact(artifactKey.name, version).toId();
artifactDetails.add(new ArtifactDetail(new ArtifactDescriptor(artifactId.toArtifactId(), Locations.getLocationFromAbsolutePath(locationFactory, data.getLocationPath())), data.meta));
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactRepository method addArtifact.
/**
* Inspects and builds plugin and application information for the given artifact, adding an additional set of
* plugin classes to the plugins found through inspection. This method is used when all plugin classes
* cannot be derived by inspecting the artifact but need to be explicitly set. This is true for 3rd party plugins
* like jdbc drivers.
*
* @param artifactId the id of the artifact to inspect and store
* @param artifactFile the artifact to inspect and store
* @param parentArtifacts artifacts the given artifact extends.
* If null, the given artifact does not extend another artifact
* @param additionalPlugins the set of additional plugin classes to add to the plugins found through inspection.
* If null, no additional plugin classes will be added
* @throws IOException if there was an exception reading from the artifact store
* @throws ArtifactRangeNotFoundException if none of the parent artifacts could be found
* @throws UnauthorizedException if the user is not authorized to add an artifact in the specified namespace. To add
* an artifact, a user must have {@link Action#WRITE} on the namespace in which
* the artifact is being added. If authorization is successful, and
* the artifact is added successfully, then the user gets all {@link Action privileges}
* on the added artifact.
*/
public ArtifactDetail addArtifact(Id.Artifact artifactId, File artifactFile, @Nullable Set<ArtifactRange> parentArtifacts, @Nullable Set<PluginClass> additionalPlugins) throws Exception {
// To add an artifact, a user must have write privileges on the namespace in which the artifact is being added
// This method is used to add user app artifacts, so enforce authorization on the specified, non-system namespace
Principal principal = authenticationContext.getPrincipal();
NamespaceId namespace = artifactId.getNamespace().toEntityId();
authorizationEnforcer.enforce(namespace, principal, Action.WRITE);
ArtifactDetail artifactDetail = addArtifact(artifactId, artifactFile, parentArtifacts, additionalPlugins, Collections.<String, String>emptyMap());
// artifact successfully added. now grant ALL permissions on the artifact to the current user
privilegesManager.grant(artifactId.toEntityId(), principal, EnumSet.allOf(Action.class));
return artifactDetail;
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactRepository method getArtifactSummaries.
/**
* Get all artifacts in the given artifact range. Will never return null.
*
* @param range the range of the artifact
* @param limit the limit number of the result
* @param order the order of the result
* @return an unmodifiable list of artifacts in the given namespace of the given name
* @throws IOException if there as an exception reading from the meta store
*/
public List<ArtifactSummary> getArtifactSummaries(final ArtifactRange range, int limit, ArtifactSortOrder order) throws Exception {
List<ArtifactSummary> summaries = new ArrayList<>();
List<ArtifactSummary> artifacts = convertAndAdd(summaries, artifactStore.getArtifacts(range, limit, order));
// todo - CDAP-11560 should filter in artifact store
return Collections.unmodifiableList(Lists.newArrayList(filterAuthorizedArtifacts(artifacts, new NamespaceId(range.getNamespace()))));
}
Aggregations