Search in sources :

Example 26 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class AuditPublishTest method testPublish.

@Test
public void testPublish() throws Exception {
    String defaultNs = NamespaceId.DEFAULT.getNamespace();
    String appName = WordCountApp.class.getSimpleName();
    // Define expected values
    Set<? extends EntityId> expectedMetadataChangeEntities = ImmutableSet.of(Ids.namespace(defaultNs).artifact(WordCountApp.class.getSimpleName(), "1"), Ids.namespace(defaultNs).app(appName), Ids.namespace(defaultNs).app(appName).flow(WordCountApp.WordCountFlow.class.getSimpleName()), Ids.namespace(defaultNs).app(appName).mr(WordCountApp.VoidMapReduceJob.class.getSimpleName()), Ids.namespace(defaultNs).app(appName).service(WordCountApp.WordFrequencyService.class.getSimpleName()), Ids.namespace(defaultNs).dataset("mydataset"), Ids.namespace(defaultNs).stream("text"));
    Multimap<AuditType, EntityId> expectedAuditEntities = HashMultimap.create();
    expectedAuditEntities.putAll(AuditType.METADATA_CHANGE, expectedMetadataChangeEntities);
    expectedAuditEntities.putAll(AuditType.CREATE, ImmutableSet.of(Ids.namespace(defaultNs).dataset("mydataset"), Ids.namespace(defaultNs).stream("text")));
    // Deploy application
    AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, WordCountApp.class, null, cConf);
    // Verify audit messages
    List<AuditMessage> publishedMessages = fetchAuditMessages();
    Multimap<AuditType, EntityId> actualAuditEntities = HashMultimap.create();
    for (AuditMessage message : publishedMessages) {
        EntityId entityId = message.getEntityId();
        if (entityId instanceof NamespacedEntityId) {
            if (((NamespacedEntityId) entityId).getNamespace().equals(NamespaceId.SYSTEM.getNamespace())) {
                // Ignore system audit messages
                continue;
            }
        }
        if (entityId.getEntityType() == EntityType.ARTIFACT && entityId instanceof ArtifactId) {
            ArtifactId artifactId = (ArtifactId) entityId;
            // Version is dynamic for deploys in test cases
            entityId = Ids.namespace(artifactId.getNamespace()).artifact(artifactId.getArtifact(), "1");
        }
        actualAuditEntities.put(message.getType(), entityId);
    }
    Assert.assertEquals(expectedAuditEntities, actualAuditEntities);
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) EntityId(co.cask.cdap.proto.id.EntityId) AuditMessage(co.cask.cdap.proto.audit.AuditMessage) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) AuditType(co.cask.cdap.proto.audit.AuditType) WordCountApp(co.cask.cdap.WordCountApp) Test(org.junit.Test)

Example 27 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class ApplicationLifecycleService method filterApplicationDetail.

/**
 * Filter the {@link ApplicationDetail} by only returning the visible entities
 */
private ApplicationDetail filterApplicationDetail(final ApplicationId appId, ApplicationDetail applicationDetail) throws Exception {
    Principal principal = authenticationContext.getPrincipal();
    List<ProgramRecord> filteredPrograms = AuthorizationUtil.isVisible(applicationDetail.getPrograms(), authorizationEnforcer, principal, new Function<ProgramRecord, EntityId>() {

        @Override
        public EntityId apply(ProgramRecord input) {
            return appId.program(input.getType(), input.getName());
        }
    }, null);
    List<StreamDetail> filteredStreams = AuthorizationUtil.isVisible(applicationDetail.getStreams(), authorizationEnforcer, principal, new Function<StreamDetail, EntityId>() {

        @Override
        public EntityId apply(StreamDetail input) {
            return appId.getNamespaceId().stream(input.getName());
        }
    }, null);
    List<DatasetDetail> filteredDatasets = AuthorizationUtil.isVisible(applicationDetail.getDatasets(), authorizationEnforcer, principal, new Function<DatasetDetail, EntityId>() {

        @Override
        public EntityId apply(DatasetDetail input) {
            return appId.getNamespaceId().dataset(input.getName());
        }
    }, null);
    return new ApplicationDetail(applicationDetail.getName(), applicationDetail.getAppVersion(), applicationDetail.getDescription(), applicationDetail.getConfiguration(), filteredStreams, filteredDatasets, filteredPrograms, applicationDetail.getPlugins(), applicationDetail.getArtifact(), applicationDetail.getOwnerPrincipal());
}
Also used : DatasetDetail(co.cask.cdap.proto.DatasetDetail) StreamDetail(co.cask.cdap.proto.StreamDetail) EntityId(co.cask.cdap.proto.id.EntityId) ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ProgramRecord(co.cask.cdap.proto.ProgramRecord) Principal(co.cask.cdap.proto.security.Principal)

Example 28 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class GetMetadataTagsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Set<String> tags = scope == null ? client.getTags(entity) : client.getTags(entity, MetadataScope.valueOf(scope.toUpperCase()));
    Table table = Table.builder().setHeader("tags").setRows(Iterables.transform(tags, new Function<String, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(@Nullable String tag) {
            return Lists.newArrayList(tag);
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) Table(co.cask.cdap.cli.util.table.Table) List(java.util.List) Nullable(javax.annotation.Nullable)

Example 29 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class RemoveMetadataTagCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String tag = arguments.get("tag");
    client.removeTag(entity, tag);
    output.println("Successfully removed metadata tag");
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId)

Example 30 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class AddMetadataTagsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    Set<String> tags = ImmutableSet.copyOf(parseList(arguments.get("tags")));
    client.addTags(entity, tags);
    output.println("Successfully added metadata tags");
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId)

Aggregations

EntityId (co.cask.cdap.proto.id.EntityId)62 Principal (co.cask.cdap.proto.security.Principal)21 EnumSet (java.util.EnumSet)18 HashSet (java.util.HashSet)18 Set (java.util.Set)18 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)17 ImmutableSet (com.google.common.collect.ImmutableSet)17 Test (org.junit.Test)17 Action (co.cask.cdap.proto.security.Action)14 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)13 DatasetId (co.cask.cdap.proto.id.DatasetId)12 ProgramId (co.cask.cdap.proto.id.ProgramId)11 ApplicationManager (co.cask.cdap.test.ApplicationManager)11 ApplicationId (co.cask.cdap.proto.id.ApplicationId)10 StreamId (co.cask.cdap.proto.id.StreamId)9 NamespaceId (co.cask.cdap.proto.id.NamespaceId)8 PrivilegedAction (java.security.PrivilegedAction)8 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)7 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)7 Authorizer (co.cask.cdap.security.spi.authorization.Authorizer)7