Search in sources :

Example 11 with FeedMetadata

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;
    });
}
Also used : ID(com.thinkbiganalytics.metadata.api.feed.Feed.ID) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed)

Example 12 with 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));
        }
    }
}
Also used : DataAccessException(org.springframework.dao.DataAccessException) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HiveUtils(com.thinkbiganalytics.hive.util.HiveUtils) Objects(java.util.Objects) List(java.util.List) Field(com.thinkbiganalytics.discovery.schema.Field) HiveService(com.thinkbiganalytics.hive.service.HiveService) Map(java.util.Map) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) Optional(java.util.Optional) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) Nonnull(javax.annotation.Nonnull) Field(com.thinkbiganalytics.discovery.schema.Field) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup)

Example 13 with FeedMetadata

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;
}
Also used : User(com.thinkbiganalytics.security.rest.model.User) Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) Nonnull(javax.annotation.Nonnull)

Example 14 with FeedMetadata

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;
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) ArrayList(java.util.ArrayList) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) HistoryReindexingStatus(com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingStatus) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Tag(com.thinkbiganalytics.discovery.schema.Tag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) Nonnull(javax.annotation.Nonnull)

Example 15 with FeedMetadata

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());
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)

Aggregations

FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)76 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)26 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)23 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)21 ArrayList (java.util.ArrayList)21 List (java.util.List)20 Collectors (java.util.stream.Collectors)20 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)18 Set (java.util.Set)18 StringUtils (org.apache.commons.lang3.StringUtils)18 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)17 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)17 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)16 Map (java.util.Map)16 Inject (javax.inject.Inject)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)15 AccessController (com.thinkbiganalytics.security.AccessController)15 Optional (java.util.Optional)15