use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.
the class EnsureTemplateFeedRelationshipsUpgradeAction method ensureFeedTemplateFeedRelationships.
private void ensureFeedTemplateFeedRelationships() {
// ensure the templates have the feed relationships
List<Feed> feeds = feedProvider.findAll();
if (feeds != null) {
feeds.stream().forEach(feed -> {
FeedManagerTemplate template = feed.getTemplate();
if (template != null) {
// ensure the template has feeds.
List<Feed> templateFeeds = null;
try {
templateFeeds = template.getFeeds();
} catch (MetadataRepositoryException e) {
// templateFeeds are weak references.
// if the template feeds return itemNotExists we need to reset it
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (rootCause != null && rootCause instanceof ItemNotFoundException) {
// reset the reference collection. It will be rebuilt in the subsequent call
JcrPropertyUtil.removeAllFromSetProperty(((JcrFeedTemplate) template).getNode(), JcrFeedTemplate.FEEDS);
}
}
if (templateFeeds == null || !templateFeeds.contains(feed)) {
log.info("Updating relationship temlate: {} -> feed: {}", template.getName(), feed.getName());
template.addFeed(feed);
feedManagerTemplateProvider.update(template);
}
}
});
}
feedProvider.populateInverseFeedDependencies();
}
use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.
the class CheckEntityAccessControlAction method ensureTemplateAccessControl.
private void ensureTemplateAccessControl() {
List<FeedManagerTemplate> templates = feedManagerTemplateProvider.findAll();
if (templates != null) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.TEMPLATE);
Optional<AllowedActions> allowedActions = this.actionsProvider.getAvailableActions(AllowedActions.TEMPLATE);
templates.stream().forEach(template -> {
Principal owner = template.getOwner() != null ? template.getOwner() : JcrMetadataAccess.getActiveUser();
allowedActions.ifPresent(actions -> ((JcrFeedTemplate) template).enableAccessControl((JcrAllowedActions) actions, owner, roles));
});
}
}
use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.
the class FeedModelTransform method domainToFeedMetadata.
/**
* Transforms the specified Metadata feed to a Feed Manager feed.
*
* @param domain the Metadata feed
* @param userFieldMap cache map from category to user-defined fields, or {@code null}
* @return the Feed Manager feed
*/
@Nonnull
private FeedMetadata domainToFeedMetadata(@Nonnull final Feed domain, @Nullable final Map<Category, Set<UserFieldDescriptor>> userFieldMap) {
FeedMetadata feed = deserializeFeedMetadata(domain, false);
feed.setId(domain.getId().toString());
feed.setFeedId(domain.getId().toString());
feed.setFeedName(domain.getDisplayName());
feed.setSystemFeedName(domain.getName());
feed.setDescription(domain.getDescription());
feed.setAllowIndexing(domain.isAllowIndexing());
feed.setHistoryReindexingStatus(domain.getCurrentHistoryReindexingStatus().getHistoryReindexingState().toString());
feed.setOwner(domain.getOwner() != null ? new User(domain.getOwner().getName()) : null);
if (domain.getCreatedTime() != null) {
feed.setCreateDate(domain.getCreatedTime().toDate());
}
if (domain.getModifiedTime() != null) {
feed.setUpdateDate(domain.getModifiedTime().toDate());
}
FeedManagerTemplate template = domain.getTemplate();
if (template != null) {
RegisteredTemplate registeredTemplate = templateModelTransform.DOMAIN_TO_REGISTERED_TEMPLATE.apply(template);
feed.setRegisteredTemplate(registeredTemplate);
feed.setTemplateId(registeredTemplate.getId());
feed.setTemplateName(registeredTemplate.getTemplateName());
}
Category category = domain.getCategory();
if (category != null) {
feed.setCategory(categoryModelTransform.domainToFeedCategorySimple(category));
}
feed.setState(domain.getState() != null ? domain.getState().name() : null);
feed.setVersionName(domain.getVersionName() != null ? domain.getVersionName() : null);
// Set user-defined properties
final Set<UserFieldDescriptor> userFields;
if (userFieldMap == null) {
userFields = getUserFields(category);
} else if (userFieldMap.containsKey(category)) {
userFields = userFieldMap.get(category);
} else {
userFields = getUserFields(category);
userFieldMap.put(category, userFields);
}
@SuppressWarnings("unchecked") final Set<UserProperty> userProperties = UserPropertyTransform.toUserProperties(domain.getUserProperties(), userFields);
feed.setUserProperties(userProperties);
// Convert JCR securitygroup to DTO
List<com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup> restSecurityGroups = new ArrayList<>();
if (domain.getSecurityGroups() != null && domain.getSecurityGroups().size() > 0) {
for (Object group : domain.getSecurityGroups()) {
HadoopSecurityGroup hadoopSecurityGroup = (HadoopSecurityGroup) group;
com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup restSecurityGroup = new com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup();
restSecurityGroup.setDescription(hadoopSecurityGroup.getDescription());
restSecurityGroup.setId(hadoopSecurityGroup.getGroupId());
restSecurityGroup.setName(hadoopSecurityGroup.getName());
restSecurityGroups.add(restSecurityGroup);
}
}
feed.setSecurityGroups(restSecurityGroups);
feed.setTags(domain.getTags().stream().map(name -> new DefaultTag(name)).collect(Collectors.toList()));
if (domain.getUsedByFeeds() != null) {
final List<FeedSummary> usedByFeeds = domain.getUsedByFeeds().stream().map(this::domainToFeedSummary).collect(Collectors.toList());
feed.setUsedByFeeds(usedByFeeds);
}
// add in access control items
securityTransform.applyAccessControl(domain, feed);
return feed;
}
use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.
the class DefaultFeedManagerFeedService method saveDraftFeed.
/* (non-Javadoc)
* @see com.thinkbiganalytics.feedmgr.service.feed.FeedManagerFeedService#saveDraftFeed(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)
*/
@Override
public FeedMetadata saveDraftFeed(FeedMetadata feedMetadata) {
if (StringUtils.isBlank(feedMetadata.getId())) {
feedMetadata.setIsNew(true);
// new feeds are always disabled
feedMetadata.setState(Feed.State.DISABLED.name());
}
// Check existence of required category and template entities with service privileges.
metadataAccess.read(() -> {
// Read all the feeds as System Service account to ensure the feed name is unique
Feed existing = feedProvider.findBySystemName(feedMetadata.getCategory().getSystemName(), feedMetadata.getSystemFeedName());
if (existing != null && !existing.getId().toString().equalsIgnoreCase(feedMetadata.getId())) {
throw new DuplicateFeedNameException(feedMetadata.getCategoryName(), feedMetadata.getFeedName());
}
if (feedMetadata.isNew()) {
// Ensure the template exists
FeedManagerTemplate domainTemplate = templateProvider.findById(templateProvider.resolveId(feedMetadata.getTemplateId()));
if (domainTemplate == null) {
throw new MetadataRepositoryException("Unable to find the template " + feedMetadata.getTemplateId());
}
// Ensure the category exists
Category domainCategory = categoryProvider.findById(categoryProvider.resolveId(feedMetadata.getCategory().getId()));
if (domainCategory == null) {
// throw exception
throw new MetadataRepositoryException("Unable to find the category " + feedMetadata.getCategory().getSystemName());
}
}
}, MetadataAccess.SERVICE);
FeedMetadata metadata = metadataAccess.commit(() -> {
// Check services access to be able to create a feed
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_FEEDS);
if (feedMetadata.isNew()) {
Category domainCategory = categoryProvider.findById(categoryProvider.resolveId(feedMetadata.getCategory().getId()));
// ensure the user has rights to create feeds under the category
accessController.checkPermission(domainCategory, CategoryAccessControl.CREATE_FEED);
} else {
// Check user has access to edit the feed
Feed.ID domainId = feedProvider.resolveId(feedMetadata.getId());
Feed domainFeed = feedProvider.findById(domainId);
if (domainFeed != null) {
accessController.checkPermission(domainFeed, FeedAccessControl.EDIT_DETAILS);
} else {
throw new NotFoundException("Feed not found for id " + feedMetadata.getId());
}
}
// replace expressions with values
if (feedMetadata.getTable() != null) {
feedMetadata.getTable().updateMetadataFieldValues();
}
// Encrypt the metadata properties
feedModelTransform.encryptSensitivePropertyValues(feedMetadata);
// Save to the metadata store.
Feed domainFeed = saveFeedMetadata(feedMetadata);
if (feedMetadata.getRegisteredTemplate() == null) {
// populate it
feedModelTransform.setFeedMetadataRegisteredTemplate(domainFeed, feedMetadata);
}
// Register the audit for the update event
if (!feedMetadata.isNew()) {
Feed.State state = Feed.State.valueOf(feedMetadata.getState());
Feed.ID id = feedProvider.resolveId(feedMetadata.getId());
notifyFeedStateChange(feedMetadata, id, state, MetadataChange.ChangeType.UPDATE);
} else if (feedMetadata.isNew()) {
// update the access control
feedMetadata.toRoleMembershipChangeList().stream().forEach(roleMembershipChange -> securityService.changeFeedRoleMemberships(feedMetadata.getId(), roleMembershipChange));
}
return feedMetadata;
});
if (feedMetadata.isNew()) {
// requery it
return metadataAccess.read(() -> {
return getFeedById(metadata.getId());
});
} else {
return metadata;
}
}
use of com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate in project kylo by Teradata.
the class FeedManagerFeedTest method testMultiThreadFeedDelete.
@Test
public void testMultiThreadFeedDelete() throws InterruptedException {
CountDownLatch goLatch = new CountDownLatch(2);
CountDownLatch doneLatch = new CountDownLatch(2);
String categorySystemName = "Category1";
String templateName = "Template1";
String feedName1 = "Feed1";
String feedName2 = "Feed2";
setupFeedAndTemplate(categorySystemName, feedName1, templateName);
setupFeedAndTemplate(categorySystemName, feedName2, templateName);
metadata.read(() -> {
FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
assertThat(template).isNotNull();
assertThat(template.getFeeds()).hasSize(2).extracting("name").contains(feedName1, feedName2);
}, MetadataAccess.SERVICE);
for (int i = 1; i <= 2; i++) {
int tag = i;
new Thread(() -> {
metadata.commit(() -> {
Feed feed = feedTestUtil.findFeed(categorySystemName, "Feed" + tag);
FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
goLatch.await();
template.removeFeed(feed);
}, MetadataAccess.SERVICE);
doneLatch.countDown();
}).start();
}
goLatch.countDown();
goLatch.countDown();
doneLatch.await();
metadata.read(() -> {
FeedManagerTemplate template = feedTestUtil.findOrCreateTemplate(templateName);
assertThat(template.getFeeds()).isEmpty();
}, MetadataAccess.SERVICE);
}
Aggregations