Search in sources :

Example 16 with FeedManagerTemplate

use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.

the class RegisteredTemplateService method findRegisteredTemplateByNiFiIdentifier.

/**
 * Find a template by the nifi id
 *
 * @param nifiTemplateId the nifi id
 * @param principals     list of principals required to access
 * @return the RegisteredTemplate matching the passed in nifiTemplateId, or null if not found
 */
private RegisteredTemplate findRegisteredTemplateByNiFiIdentifier(final String nifiTemplateId, TEMPLATE_TRANSFORMATION_TYPE transformationType, Principal... principals) {
    if (StringUtils.isBlank(nifiTemplateId)) {
        return null;
    }
    return metadataAccess.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
        RegisteredTemplate registeredTemplate = null;
        FeedManagerTemplate template = templateProvider.findByNifiTemplateId(nifiTemplateId);
        if (template != null) {
            registeredTemplate = templateModelTransform.getTransformationFunction(transformationType).apply(template);
        }
        return registeredTemplate;
    }, principals);
}
Also used : RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)

Example 17 with FeedManagerTemplate

use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.

the class RegisteredTemplateService method findRegisteredTemplateById.

/**
 * Find a template by the Kylo Id
 *
 * @param templateId The Kylo {@link RegisteredTemplate#id}
 * @param principals list or principals required to access
 * @return the RegisteredTemplate matching the id or null if not found
 */
private RegisteredTemplate findRegisteredTemplateById(final String templateId, TEMPLATE_TRANSFORMATION_TYPE transformationType, Principal... principals) {
    if (StringUtils.isBlank(templateId)) {
        return null;
    } else {
        return metadataAccess.read(() -> {
            this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
            RegisteredTemplate registeredTemplate = null;
            FeedManagerTemplate.ID domainId = templateProvider.resolveId(templateId);
            FeedManagerTemplate domainTemplate = templateProvider.findById(domainId);
            if (domainTemplate != null) {
                // transform it
                registeredTemplate = templateModelTransform.getTransformationFunction(transformationType).apply(domainTemplate);
            }
            if (registeredTemplate != null) {
                registeredTemplate.initializeProcessors();
                ensureNifiTemplate(registeredTemplate);
            }
            return registeredTemplate;
        }, principals);
    }
}
Also used : RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)

Example 18 with FeedManagerTemplate

use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.

the class JcrFeedTemplateProvider method addPostFeedChangeAction.

/**
 * Registers an action that produces a template change event upon a successful transaction commit.
 *
 * @param template the feed to being created
 */
private void addPostFeedChangeAction(FeedManagerTemplate template, ChangeType changeType) {
    FeedManagerTemplate.State state = template.getState();
    FeedManagerTemplate.ID id = template.getId();
    String desc = template.getName();
    DateTime createTime = template.getCreatedTime();
    final Principal principal = SecurityContextHolder.getContext().getAuthentication() != null ? SecurityContextHolder.getContext().getAuthentication() : null;
    Consumer<Boolean> action = (success) -> {
        if (success) {
            TemplateChange change = new TemplateChange(changeType, desc, id, state);
            TemplateChangeEvent event = new TemplateChangeEvent(change, createTime, principal);
            metadataEventService.notify(event);
        }
    };
    JcrMetadataAccess.addPostTransactionAction(action);
}
Also used : EntityUtil(com.thinkbiganalytics.metadata.modeshape.common.EntityUtil) ChangeType(com.thinkbiganalytics.metadata.api.event.MetadataChange.ChangeType) HashMap(java.util.HashMap) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) StringUtils(org.apache.commons.lang3.StringUtils) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) Inject(javax.inject.Inject) TemplateChangeEvent(com.thinkbiganalytics.metadata.api.event.template.TemplateChangeEvent) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) Map(java.util.Map) TemplateAccessControl(com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl) AccessController(com.thinkbiganalytics.security.AccessController) JcrAllowedEntityActionsProvider(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedEntityActionsProvider) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) DateTime(org.joda.time.DateTime) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Serializable(java.io.Serializable) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Consumer(java.util.function.Consumer) SecurityRoleProvider(com.thinkbiganalytics.security.role.SecurityRoleProvider) List(java.util.List) Principal(java.security.Principal) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) TemplateChange(com.thinkbiganalytics.metadata.api.event.template.TemplateChange) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) TemplateDeletionException(com.thinkbiganalytics.metadata.api.template.TemplateDeletionException) BaseJcrProvider(com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) JcrEntity(com.thinkbiganalytics.metadata.modeshape.common.JcrEntity) TemplateChange(com.thinkbiganalytics.metadata.api.event.template.TemplateChange) TemplateChangeEvent(com.thinkbiganalytics.metadata.api.event.template.TemplateChangeEvent) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) DateTime(org.joda.time.DateTime) Principal(java.security.Principal)

Example 19 with FeedManagerTemplate

use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.

the class FeedManagerFeedTest method setupFeedAndTemplate.

private void setupFeedAndTemplate(String categorySystemName, String feedName, String templateName) {
    // first create the category
    metadata.commit(() -> {
        Category category = feedTestUtil.findOrCreateCategory(categorySystemName);
        return category.getId();
    }, MetadataAccess.SERVICE);
    // creqte the feed
    metadata.commit(() -> {
        Feed feed = feedTestUtil.findOrCreateFeed(categorySystemName, feedName, templateName);
        return feed.getId();
    }, MetadataAccess.SERVICE);
    // ensure the feed relates to the template
    metadata.read(() -> {
        FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
        List<Feed> feeds = template.getFeeds();
        Assert.assertTrue(feeds != null && feeds.size() > 0);
    }, MetadataAccess.SERVICE);
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Example 20 with FeedManagerTemplate

use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.

the class FeedManagerFeedTest method testLotsOfFeeds.

/**
 * Test querying a large number of feeds
 */
@Test
public void testLotsOfFeeds() {
    // increase to query more .. i.e. 1000
    int numberOfFeeds = 5;
    int numberOfFeedsPerCategory = 20;
    String templateName = "my_template";
    int categories = numberOfFeeds / numberOfFeedsPerCategory;
    // create all the categories
    metadata.commit(() -> {
        for (int i = 1; i <= categories; i++) {
            Category category = feedTestUtil.createCategory("category_" + i);
        }
    }, MetadataAccess.ADMIN);
    metadata.commit(() -> {
        FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
    }, MetadataAccess.ADMIN);
    // create the feeds
    metadata.commit(() -> {
        FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
        Category category = null;
        int categoryNum = 0;
        String categoryName = "category" + categoryNum;
        for (int i = 0; i < numberOfFeeds; i++) {
            if (i % numberOfFeedsPerCategory == 0) {
                categoryNum++;
                categoryName = "category_" + categoryNum;
                category = feedTestUtil.findOrCreateCategory(categoryName);
            }
            Feed feed = feedTestUtil.findOrCreateFeed(category, "feed_" + i, template);
        }
    }, MetadataAccess.ADMIN);
    // now query it
    long time = System.currentTimeMillis();
    Integer size = metadata.read(() -> {
        List<Feed> feeds = feedProvider.findAll();
        return feeds.size();
    }, MetadataAccess.SERVICE);
    long stopTime = System.currentTimeMillis();
    log.info("Time to query {} feeds was {} ms", size, (stopTime - time));
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) Test(org.junit.Test)

Aggregations

FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)21 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)8 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)7 Category (com.thinkbiganalytics.metadata.api.category.Category)6 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)3 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)3 Principal (java.security.Principal)3 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)2 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)2 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)2 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)2 UserProperty (com.thinkbiganalytics.feedmgr.rest.model.UserProperty)2 MetadataEventService (com.thinkbiganalytics.metadata.api.event.MetadataEventService)2 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)2 HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)2 FeedManagerTemplateProvider (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider)2 JcrHadoopSecurityGroup (com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup)2 AccessController (com.thinkbiganalytics.security.AccessController)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2