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