use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class DefaultFeedManagerFeedService method getFeedById.
@Override
public FeedMetadata getFeedById(final String id, final boolean refreshTargetTableSchema) {
return metadataAccess.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_FEEDS);
FeedMetadata feedMetadata = null;
Feed.ID domainId = feedProvider.resolveId(id);
Feed domainFeed = feedProvider.findById(domainId);
if (domainFeed != null) {
feedMetadata = feedModelTransform.domainToFeedMetadata(domainFeed);
}
if (refreshTargetTableSchema && feedMetadata != null) {
// commented out for now as some issues were found with feeds with TEXTFILE as their output
// this will attempt to sync the schema stored in modeshape with that in Hive
// feedModelTransform.refreshTableSchemaFromHive(feedMetadata);
}
return feedMetadata;
});
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedHiveTableService method updateColumnDescriptions.
/**
* Updates the column descriptions in the Hive metastore for the specified feed.
*
* @param feed the feed to update
* @throws DataAccessException if there is any problem
*/
public void updateColumnDescriptions(@Nonnull final FeedMetadata feed) {
final List<Field> feedFields = Optional.ofNullable(feed.getTable()).map(TableSetup::getTableSchema).map(TableSchema::getFields).orElse(null);
if (feedFields != null && !feedFields.isEmpty()) {
final TableSchema hiveSchema = hiveService.getTableSchema(feed.getSystemCategoryName(), feed.getSystemFeedName());
if (hiveSchema != null) {
final Map<String, Field> hiveFieldMap = hiveSchema.getFields().stream().collect(Collectors.toMap(field -> field.getName().toLowerCase(), Function.identity()));
feedFields.stream().filter(feedField -> {
final Field hiveField = hiveFieldMap.get(feedField.getName().toLowerCase());
return hiveField != null && (StringUtils.isNotEmpty(feedField.getDescription()) || StringUtils.isNotEmpty(hiveField.getDescription())) && !Objects.equals(feedField.getDescription(), hiveField.getDescription());
}).forEach(feedField -> changeColumn(feed, feedField.getName(), feedField));
}
}
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata 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.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedModelTransform method feedToDomain.
/**
* Transforms the specified Feed Manager feed to a Metadata feed.
*
* @param feedMetadata the Feed Manager feed
* @return the Metadata feed
*/
@Nonnull
public Feed feedToDomain(@Nonnull final FeedMetadata feedMetadata) {
// resolve the id
Feed.ID domainId = feedMetadata.getId() != null ? feedProvider.resolveId(feedMetadata.getId()) : null;
Feed domain = domainId != null ? feedProvider.findById(domainId) : null;
FeedCategory restCategoryModel = feedMetadata.getCategory();
Category category = null;
if (restCategoryModel != null && (domain == null || domain.getCategory() == null)) {
category = categoryProvider.findById(categoryProvider.resolveId(restCategoryModel.getId()));
}
if (domain == null) {
// ensure the Category exists
if (category == null) {
final String categoryId = (restCategoryModel != null) ? restCategoryModel.getId() : "(null)";
throw new RuntimeException("Category cannot be found while creating feed " + feedMetadata.getSystemFeedName() + ". Category Id is " + categoryId);
}
domain = feedProvider.ensureFeed(category.getId(), feedMetadata.getSystemFeedName());
domainId = domain.getId();
Feed.State state = Feed.State.valueOf(feedMetadata.getState());
domain.setState(state);
// reassign the domain data back to the ui model....
feedMetadata.setFeedId(domainId.toString());
feedMetadata.setState(state.name());
}
domain.setDisplayName(feedMetadata.getFeedName());
if (feedMetadata.getDescription() == null) {
feedMetadata.setDescription("");
}
domain.setDescription(feedMetadata.getDescription());
domain.setAllowIndexing(feedMetadata.isAllowIndexing());
if (StringUtils.isNotBlank(feedMetadata.getHistoryReindexingStatus())) {
domain.updateHistoryReindexingStatus(new HistoryReindexingStatus(com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingState.valueOf(feedMetadata.getHistoryReindexingStatus())));
}
feedMetadata.setId(domain.getId().toString());
if (StringUtils.isNotBlank(feedMetadata.getState())) {
Feed.State state = Feed.State.valueOf(feedMetadata.getState().toUpperCase());
domain.setState(state);
}
domain.setNifiProcessGroupId(feedMetadata.getNifiProcessGroupId());
// clear out the state as that
RegisteredTemplate template = feedMetadata.getRegisteredTemplate();
prepareForSave(feedMetadata);
feedMetadata.setRegisteredTemplate(template);
if (domain.getTemplate() == null) {
FeedManagerTemplate.ID templateId = templateProvider.resolveId(feedMetadata.getTemplateId());
FeedManagerTemplate domainTemplate = templateProvider.findById(templateId);
domain.setTemplate(domainTemplate);
}
// Set user-defined properties
if (feedMetadata.getUserProperties() != null) {
final Set<UserFieldDescriptor> userFields = getUserFields(category);
domain.setUserProperties(UserPropertyTransform.toMetadataProperties(feedMetadata.getUserProperties()), userFields);
}
// Set the hadoop security groups
final List<HadoopSecurityGroup> securityGroups = new ArrayList<>();
if (feedMetadata.getSecurityGroups() != null) {
for (com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup securityGroup : feedMetadata.getSecurityGroups()) {
JcrHadoopSecurityGroup hadoopSecurityGroup = (JcrHadoopSecurityGroup) hadoopSecurityGroupProvider.ensureSecurityGroup(securityGroup.getName());
hadoopSecurityGroup.setGroupId(securityGroup.getId());
hadoopSecurityGroup.setDescription(securityGroup.getDescription());
securityGroups.add(hadoopSecurityGroup);
}
}
domain.setSecurityGroups(securityGroups);
domain.setVersionName(domain.getVersionName());
if (feedMetadata.getTags() != null) {
domain.setTags(feedMetadata.getTags().stream().map(Tag::getName).collect(Collectors.toSet()));
}
// Create a new feed metadata stripped of any excess data that does
// not need to be serialized and stored in the feed domain entity.
FeedMetadata stripped = stripMetadata(feedMetadata);
domain.setJson(ObjectMapperSerializer.serialize(stripped));
return domain;
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class InMemoryFeedManagerFeedService method saveFeed.
public void saveFeed(FeedMetadata feed) {
if (feed.getId() == null || !feeds.containsKey(feed.getId())) {
feed.setId(UUID.randomUUID().toString());
feed.setVersion(new Long(1));
} else {
FeedMetadata previousFeed = feeds.get(feed.getId());
feed.setId(previousFeed.getId());
feed.setVersion(previousFeed.getVersion() + 1L);
}
// match up the related category
String categoryId = feed.getCategory().getId();
FeedCategory category = null;
if (categoryId != null) {
category = categoryProvider.getCategoryById(categoryId);
}
if (category == null) {
final String categoryName = feed.getCategory().getSystemName();
category = categoryProvider.getCategoryBySystemName(categoryName);
feed.setCategory(category);
}
if (category != null) {
category.addRelatedFeed(new FeedSummary(feed));
}
// saveToMetadataStore(feed);
feeds.put(feed.getId(), feed);
FileObjectPersistence.getInstance().writeFeedsToFile(feeds.values());
}
Aggregations