Search in sources :

Example 1 with HadoopSecurityGroup

use of com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup in project kylo by Teradata.

the class FeedData method setSecurityGroups.

public void setSecurityGroups(List<? extends HadoopSecurityGroup> hadoopSecurityGroups) {
    JcrPropertyUtil.setProperty(this.node, HADOOP_SECURITY_GROUPS, null);
    for (HadoopSecurityGroup securityGroup : hadoopSecurityGroups) {
        Node securityGroupNode = ((JcrHadoopSecurityGroup) securityGroup).getNode();
        JcrPropertyUtil.addToSetProperty(this.node, HADOOP_SECURITY_GROUPS, securityGroupNode, true);
    }
}
Also used : HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) Node(javax.jcr.Node) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup)

Example 2 with HadoopSecurityGroup

use of com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup in project kylo by Teradata.

the class CategoryModelTransform method feedCategoryToDomain.

/**
 * Transforms the specified Feed Manager category to a Metadata category.
 *
 * @param feedCategory the Feed Manager category
 * @param userFields   the user-defined fields
 * @return the Metadata category
 */
@Nonnull
private Category feedCategoryToDomain(@Nonnull final FeedCategory feedCategory, @Nonnull final Set<UserFieldDescriptor> userFields) {
    Category.ID domainId = feedCategory.getId() != null ? categoryProvider.resolveId(feedCategory.getId()) : null;
    Category category = null;
    if (domainId != null) {
        category = categoryProvider.findById(domainId);
    }
    if (category == null) {
        category = categoryProvider.ensureCategory(feedCategory.getSystemName());
    }
    if (category == null) {
        throw new CategoryNotFoundException("Unable to find Category ", domainId);
    }
    domainId = category.getId();
    feedCategory.setId(domainId.toString());
    category.setDisplayName(feedCategory.getName());
    category.setSystemName(feedCategory.getSystemName());
    category.setDescription(feedCategory.getDescription());
    category.setIcon(feedCategory.getIcon());
    category.setIconColor(feedCategory.getIconColor());
    category.setAllowIndexing(feedCategory.isAllowIndexing());
    category.setCreatedTime(new DateTime(feedCategory.getCreateDate()));
    category.setModifiedTime(new DateTime(feedCategory.getUpdateDate()));
    // Transforms the Feed Manager user-defined properties to domain user-defined properties
    if (feedCategory.getUserProperties() != null) {
        category.setUserProperties(UserPropertyTransform.toMetadataProperties(feedCategory.getUserProperties()), userFields);
    }
    // Set the hadoop security groups
    final List<HadoopSecurityGroup> securityGroups = new ArrayList<>();
    if (feedCategory.getSecurityGroups() != null) {
        for (com.thinkbiganalytics.feedmgr.rest.model.HadoopSecurityGroup securityGroup : feedCategory.getSecurityGroups()) {
            JcrHadoopSecurityGroup hadoopSecurityGroup = (JcrHadoopSecurityGroup) hadoopSecurityGroupProvider.ensureSecurityGroup(securityGroup.getName());
            hadoopSecurityGroup.setGroupId(securityGroup.getId());
            hadoopSecurityGroup.setDescription(securityGroup.getDescription());
            securityGroups.add(hadoopSecurityGroup);
        }
    }
    category.setSecurityGroups(securityGroups);
    return category;
}
Also used : HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) ArrayList(java.util.ArrayList) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) DateTime(org.joda.time.DateTime) Nonnull(javax.annotation.Nonnull)

Example 3 with HadoopSecurityGroup

use of com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup in project kylo by Teradata.

the class DefaultFeedManagerFeedService method saveFeed.

private void saveFeed(final FeedMetadata feed) {
    metadataAccess.commit(() -> {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<? extends HadoopSecurityGroup> previousSavedSecurityGroups = null;
        // Store the old security groups before saving because we need to compare afterward
        if (!feed.isNew()) {
            Feed previousStateBeforeSaving = feedProvider.findById(feedProvider.resolveId(feed.getId()));
            Map<String, String> userProperties = previousStateBeforeSaving.getUserProperties();
            previousSavedSecurityGroups = previousStateBeforeSaving.getSecurityGroups();
        }
        // if this is the first time saving this feed create a new one
        Feed domainFeed = feedModelTransform.feedToDomain(feed);
        if (domainFeed.getState() == null) {
            domainFeed.setState(Feed.State.ENABLED);
        }
        stopwatch.stop();
        log.debug("Time to transform the feed to a domain object for saving: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // initially save the feed
        if (feed.isNew()) {
            stopwatch.start();
            domainFeed = feedProvider.update(domainFeed);
            stopwatch.stop();
            log.debug("Time to save the New feed: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            stopwatch.reset();
        }
        final String domainId = domainFeed.getId().toString();
        final String feedName = FeedNameUtil.fullName(domainFeed.getCategory().getSystemName(), domainFeed.getName());
        // Build preconditions
        stopwatch.start();
        assignFeedDependencies(feed, domainFeed);
        stopwatch.stop();
        log.debug("Time to assignFeedDependencies: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // Assign the datasources
        stopwatch.start();
        assignFeedDatasources(feed, domainFeed);
        stopwatch.stop();
        log.debug("Time to assignFeedDatasources: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        stopwatch.start();
        boolean isStream = feed.getRegisteredTemplate() != null ? feed.getRegisteredTemplate().isStream() : false;
        Long timeBetweenBatchJobs = feed.getRegisteredTemplate() != null ? feed.getRegisteredTemplate().getTimeBetweenStartingBatchJobs() : 0L;
        // sync the feed information to ops manager
        metadataAccess.commit(() -> opsManagerFeedProvider.save(opsManagerFeedProvider.resolveId(domainId), feedName, isStream, timeBetweenBatchJobs));
        stopwatch.stop();
        log.debug("Time to sync feed data with Operations Manager: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // Update hadoop security group polices if the groups changed
        if (!feed.isNew() && !ListUtils.isEqualList(previousSavedSecurityGroups, domainFeed.getSecurityGroups())) {
            stopwatch.start();
            List<? extends HadoopSecurityGroup> securityGroups = domainFeed.getSecurityGroups();
            List<String> groupsAsCommaList = securityGroups.stream().map(group -> group.getName()).collect(Collectors.toList());
            hadoopAuthorizationService.updateSecurityGroupsForAllPolicies(feed.getSystemCategoryName(), feed.getSystemFeedName(), groupsAsCommaList, domainFeed.getProperties());
            stopwatch.stop();
            log.debug("Time to update hadoop security groups: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            stopwatch.reset();
        }
        // Update Hive metastore
        stopwatch.start();
        final boolean hasHiveDestination = domainFeed.getDestinations().stream().map(FeedDestination::getDatasource).filter(DerivedDatasource.class::isInstance).map(DerivedDatasource.class::cast).anyMatch(datasource -> "HiveDatasource".equals(datasource.getDatasourceType()));
        if (hasHiveDestination) {
            try {
                feedHiveTableService.updateColumnDescriptions(feed);
            } catch (final DataAccessException e) {
                log.warn("Failed to update column descriptions for feed: {}", feed.getCategoryAndFeedDisplayName(), e);
            }
        }
        stopwatch.stop();
        log.debug("Time to update hive metastore: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // Update Kylo metastore
        stopwatch.start();
        domainFeed = feedProvider.update(domainFeed);
        stopwatch.stop();
        log.debug("Time to call feedProvider.update: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
    }, (e) -> {
        if (feed.isNew() && StringUtils.isNotBlank(feed.getId())) {
            // Rollback ops Manager insert if it is newly created
            metadataAccess.commit(() -> {
                opsManagerFeedProvider.delete(opsManagerFeedProvider.resolveId(feed.getId()));
            });
        }
    });
}
Also used : Action(com.thinkbiganalytics.security.action.Action) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Category(com.thinkbiganalytics.metadata.api.category.Category) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) Map(java.util.Map) FeedPropertyChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedPropertyChangeEvent) AccessController(com.thinkbiganalytics.security.AccessController) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) CategoryAccessControl(com.thinkbiganalytics.metadata.api.category.security.CategoryAccessControl) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) MetadataEventListener(com.thinkbiganalytics.metadata.api.event.MetadataEventListener) Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) LabelValue(com.thinkbiganalytics.rest.model.LabelValue) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) Page(org.springframework.data.domain.Page) EntityVersionDifference(com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Serializable(java.io.Serializable) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) DerivedDatasourceFactory(com.thinkbiganalytics.feedmgr.service.feed.datasource.DerivedDatasourceFactory) MetadataChange(com.thinkbiganalytics.metadata.api.event.MetadataChange) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup) Datasource(com.thinkbiganalytics.metadata.api.datasource.Datasource) Properties(java.util.Properties) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) FeedProperties(com.thinkbiganalytics.metadata.api.feed.FeedProperties) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) ID(com.thinkbiganalytics.metadata.api.feed.Feed.ID) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) HadoopAuthorizationService(com.thinkbiganalytics.datalake.authorization.service.HadoopAuthorizationService) ListUtils(org.apache.commons.collections.ListUtils) LoggerFactory(org.slf4j.LoggerFactory) FeedChange(com.thinkbiganalytics.metadata.api.event.feed.FeedChange) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) Precondition(com.thinkbiganalytics.policy.precondition.Precondition) PreDestroy(javax.annotation.PreDestroy) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) Pageable(org.springframework.data.domain.Pageable) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) FeedVersions(com.thinkbiganalytics.feedmgr.rest.model.FeedVersions) FeedDestination(com.thinkbiganalytics.metadata.api.feed.FeedDestination) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) UserField(com.thinkbiganalytics.feedmgr.rest.model.UserField) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NotFoundException(javax.ws.rs.NotFoundException) EntityVersion(com.thinkbiganalytics.feedmgr.rest.model.EntityVersion) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) InputOutputPort(com.thinkbiganalytics.nifi.feedmgr.InputOutputPort) List(java.util.List) Principal(java.security.Principal) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule) DataAccessException(org.springframework.dao.DataAccessException) Stopwatch(com.google.common.base.Stopwatch) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HashMap(java.util.HashMap) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) HashSet(java.util.HashSet) Inject(javax.inject.Inject) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) ServiceLevelAgreementService(com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementService) FeedChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedChangeEvent) Qualifier(org.springframework.beans.factory.annotation.Qualifier) FeedRollbackException(com.thinkbiganalytics.nifi.feedmgr.FeedRollbackException) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) Nonnull(javax.annotation.Nonnull) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) Logger(org.slf4j.Logger) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) CreateFeedBuilder(com.thinkbiganalytics.feedmgr.nifi.CreateFeedBuilder) FeedHistoryDataReindexingService(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedHistoryDataReindexingService) DateTime(org.joda.time.DateTime) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) TimeUnit(java.util.concurrent.TimeUnit) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) UserPropertyTransform(com.thinkbiganalytics.feedmgr.service.UserPropertyTransform) NiFiTemplateCache(com.thinkbiganalytics.feedmgr.service.template.NiFiTemplateCache) DependentFeedPrecondition(com.thinkbiganalytics.policy.precondition.DependentFeedPrecondition) PreconditionPolicyTransformer(com.thinkbiganalytics.policy.precondition.transform.PreconditionPolicyTransformer) Comparator(java.util.Comparator) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) Stopwatch(com.google.common.base.Stopwatch) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) DataAccessException(org.springframework.dao.DataAccessException) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed)

Example 4 with HadoopSecurityGroup

use of com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup 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 5 with HadoopSecurityGroup

use of com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup 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)

Aggregations

HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)11 ArrayList (java.util.ArrayList)9 JcrHadoopSecurityGroup (com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup)8 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)5 Category (com.thinkbiganalytics.metadata.api.category.Category)4 Nonnull (javax.annotation.Nonnull)4 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)3 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)3 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)3 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)3 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)3 Node (javax.jcr.Node)3 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)2 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)2 UserProperty (com.thinkbiganalytics.feedmgr.rest.model.UserProperty)2 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)2 DateTime (org.joda.time.DateTime)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1