Search in sources :

Example 1 with TagClient

use of com.hortonworks.streamline.registries.tag.client.TagClient in project streamline by hortonworks.

the class TagRestServiceTest method testTagResource.

@Test
public void testTagResource() throws Exception {
    TagClient tagClient = new TagClient(catalogRootUrl);
    long parentTagId = 10L;
    long childTagId = 11L;
    // create a "parent-tag"
    Tag parent = createTag(parentTagId, "parent-tag");
    Assert.assertTrue(tagClient.addTag(parent).getId() == parentTagId);
    // create a "child-tag" which is tagged under "parent-tag"
    Tag child = createTag(childTagId, "child-tag", ImmutableList.<Tag>of(parent));
    Assert.assertTrue(tagClient.addTag(child).getId() == childTagId);
    // update parent-tag
    parent = createTag(parentTagId, "parent-update-tag");
    Assert.assertTrue(tagClient.addOrUpdateTag(parent).getId() == parentTagId);
    // get a Tag by Id
    Tag tag = tagClient.getTag(parentTagId);
    Assert.assertTrue("Tag Id is different", tag.getId() == parentTagId);
    // get a unkonwn tag by Id
    tag = tagClient.getTag(100L);
    // add another tag
    Tag testTag = createTag(12L, "to-delete-tag");
    Assert.assertTrue(tagClient.addTag(testTag).getId() == 12L);
    // list all tags
    List<Tag> allTags = tagClient.listTags();
    Assert.assertTrue("tag count mismatch", allTags.size() == 3);
    // list tags with queryParams
    Map<String, Object> queryParams = new HashMap<>();
    queryParams.put("name", "child-tag");
    queryParams.put("description", "child-tag");
    allTags = tagClient.listTags(queryParams);
    Assert.assertTrue("tag count mismatch", allTags.size() == 1);
    // delete a tag
    tagClient.removeTag(12L);
    allTags = tagClient.listTags();
    Assert.assertTrue("count mismatch", allTags.size() == 2);
    // add Tag for Entity
    tagClient.addTagForEntity(new TaggedEntity("Device", 1L), parentTagId);
    tagClient.addTagForEntity(new TaggedEntity("Device", 2L), parentTagId);
    tagClient.addTagForEntity(new TaggedEntity("Device", 3L), parentTagId);
    // get All Entities For Tag
    List<TaggedEntity> allEntities = tagClient.getTaggedEntities(parentTagId);
    Assert.assertTrue("entity count mismatch", allEntities.size() == 3);
    // remove Tag for Entity
    tagClient.removeTagForEntity(new TaggedEntity("Device", 1L), parentTagId);
    allEntities = tagClient.getTaggedEntities(parentTagId);
    Assert.assertTrue("entity count mismatch", allEntities.size() == 2);
    // add new Tag to existing entity
    Tag newTag = createTag(13L, "new-tag");
    Assert.assertTrue(tagClient.addTag(newTag).getId() == 13L);
    tagClient.addTagForEntity(new TaggedEntity("Device", 2L), 13L);
    // get All Tags For a given Entity
    allTags = tagClient.getTags(new TaggedEntity("Device", 2L));
    Assert.assertTrue("tag count mismatch", allTags.size() == 2);
    // try adding unknown tag for a Entity
    try {
        tagClient.addTagForEntity(new TaggedEntity("Device", 1L), 100L);
        Assert.fail("should have thrown error");
    } catch (RuntimeException e) {
    }
    // try removing unknown tag for a Entity
    try {
        tagClient.removeTagForEntity(new TaggedEntity("Device", 1L), 100L);
        Assert.fail("should have thrown error");
    } catch (RuntimeException e) {
    }
}
Also used : TaggedEntity(com.hortonworks.streamline.registries.tag.TaggedEntity) TagClient(com.hortonworks.streamline.registries.tag.client.TagClient) HashMap(java.util.HashMap) Tag(com.hortonworks.streamline.registries.tag.Tag) IntegrationTest(com.hortonworks.streamline.common.test.IntegrationTest) Test(org.junit.Test)

Example 2 with TagClient

use of com.hortonworks.streamline.registries.tag.client.TagClient in project streamline by hortonworks.

the class StreamsModule method getResources.

@Override
public List<Object> getResources() {
    List<Object> result = new ArrayList<>();
    String catalogRootUrl = (String) config.get(Constants.CONFIG_CATALOG_ROOT_URL);
    // Authorized subject
    final Subject subject = (Subject) config.get(Constants.CONFIG_SUBJECT);
    MLModelRegistryClient modelRegistryClient = new MLModelRegistryClient(catalogRootUrl, subject);
    final StreamCatalogService streamcatalogService = new StreamCatalogService(storageManager, fileStorage, modelRegistryClient);
    final EnvironmentService environmentService = new EnvironmentService(storageManager);
    TagClient tagClient = new TagClient(catalogRootUrl);
    final CatalogService catalogService = new CatalogService(storageManager, fileStorage, tagClient);
    final TopologyActionsService topologyActionsService = new TopologyActionsService(streamcatalogService, environmentService, fileStorage, modelRegistryClient, config, subject, transactionManager);
    final TopologyMetricsService topologyMetricsService = new TopologyMetricsService(environmentService, subject);
    final TopologyLogSearchService topologyLogSearchService = new TopologyLogSearchService(environmentService, subject);
    environmentService.addNamespaceAwareContainer(topologyActionsService);
    environmentService.addNamespaceAwareContainer(topologyMetricsService);
    environmentService.addNamespaceAwareContainer(topologyLogSearchService);
    // authorizer
    final StreamlineAuthorizer authorizer = (StreamlineAuthorizer) config.get(Constants.CONFIG_AUTHORIZER);
    if (authorizer == null) {
        throw new IllegalStateException("Authorizer not set");
    }
    final SecurityCatalogService securityCatalogService = (SecurityCatalogService) config.get(Constants.CONFIG_SECURITY_CATALOG_SERVICE);
    result.addAll(getAuthorizerResources(authorizer, securityCatalogService));
    result.add(new MetricsResource(authorizer, streamcatalogService, topologyMetricsService));
    result.addAll(getClusterRelatedResources(authorizer, environmentService));
    result.add(new FileCatalogResource(authorizer, catalogService));
    result.addAll(getTopologyRelatedResources(authorizer, streamcatalogService, environmentService, topologyActionsService, topologyMetricsService, topologyLogSearchService, securityCatalogService, subject));
    result.add(new UDFCatalogResource(authorizer, streamcatalogService, fileStorage));
    result.addAll(getNotificationsRelatedResources(authorizer, streamcatalogService));
    result.add(new SchemaResource(createSchemaRegistryClient()));
    result.addAll(getServiceMetadataResources(authorizer, environmentService, subject));
    result.add(new NamespaceCatalogResource(authorizer, streamcatalogService, topologyActionsService, environmentService));
    result.add(new SearchCatalogResource(authorizer, streamcatalogService, environmentService, topologyActionsService, topologyMetricsService));
    watchFiles(streamcatalogService);
    setupPlaceholderEntities(streamcatalogService, environmentService);
    return result;
}
Also used : TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) TagClient(com.hortonworks.streamline.registries.tag.client.TagClient) ArrayList(java.util.ArrayList) SecurityCatalogService(com.hortonworks.streamline.streams.security.service.SecurityCatalogService) CatalogService(com.hortonworks.streamline.streams.catalog.service.CatalogService) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) MLModelRegistryClient(com.hortonworks.streamline.registries.model.client.MLModelRegistryClient) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) Subject(javax.security.auth.Subject) TopologyMetricsService(com.hortonworks.streamline.streams.metrics.topology.service.TopologyMetricsService) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) SecurityCatalogService(com.hortonworks.streamline.streams.security.service.SecurityCatalogService) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyLogSearchService(com.hortonworks.streamline.streams.logsearch.topology.service.TopologyLogSearchService)

Aggregations

TagClient (com.hortonworks.streamline.registries.tag.client.TagClient)2 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)1 MLModelRegistryClient (com.hortonworks.streamline.registries.model.client.MLModelRegistryClient)1 Tag (com.hortonworks.streamline.registries.tag.Tag)1 TaggedEntity (com.hortonworks.streamline.registries.tag.TaggedEntity)1 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)1 CatalogService (com.hortonworks.streamline.streams.catalog.service.CatalogService)1 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)1 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)1 TopologyLogSearchService (com.hortonworks.streamline.streams.logsearch.topology.service.TopologyLogSearchService)1 TopologyMetricsService (com.hortonworks.streamline.streams.metrics.topology.service.TopologyMetricsService)1 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)1 SecurityCatalogService (com.hortonworks.streamline.streams.security.service.SecurityCatalogService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Subject (javax.security.auth.Subject)1 Test (org.junit.Test)1