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