Search in sources :

Example 86 with NamespaceId

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

Example 87 with NamespaceId

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()));
    }
}
Also used : MapperInput(co.cask.cdap.internal.app.runtime.batch.dataset.input.MapperInput) Input(co.cask.cdap.api.data.batch.Input) StreamInputFormatProvider(co.cask.cdap.internal.app.runtime.batch.stream.StreamInputFormatProvider) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 88 with NamespaceId

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));
    }
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Id(co.cask.cdap.proto.Id) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetId(co.cask.cdap.proto.id.DatasetId) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap)

Example 89 with NamespaceId

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;
}
Also used : Action(co.cask.cdap.proto.security.Action) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Principal(co.cask.cdap.proto.security.Principal)

Example 90 with NamespaceId

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()))));
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArrayList(java.util.ArrayList) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Aggregations

NamespaceId (co.cask.cdap.proto.id.NamespaceId)234 Test (org.junit.Test)99 Path (javax.ws.rs.Path)47 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)43 ApplicationId (co.cask.cdap.proto.id.ApplicationId)35 IOException (java.io.IOException)34 StreamId (co.cask.cdap.proto.id.StreamId)30 DatasetId (co.cask.cdap.proto.id.DatasetId)27 TableId (co.cask.cdap.data2.util.TableId)26 Id (co.cask.cdap.proto.Id)24 ProgramId (co.cask.cdap.proto.id.ProgramId)24 NotFoundException (co.cask.cdap.common.NotFoundException)22 ArtifactId (co.cask.cdap.proto.id.ArtifactId)21 BadRequestException (co.cask.cdap.common.BadRequestException)20 TopicId (co.cask.cdap.proto.id.TopicId)19 GET (javax.ws.rs.GET)18 Location (org.apache.twill.filesystem.Location)18 ArrayList (java.util.ArrayList)15 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12