Search in sources :

Example 6 with FeedSummary

use of com.thinkbiganalytics.feedmgr.rest.model.FeedSummary 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, @Nullable ActionGroup actionGroup) {
    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());
    }
    setFeedMetadataRegisteredTemplate(domain, feed);
    Category category = domain.getCategory();
    if (category != null) {
        feed.setCategory(categoryModelTransform.domainToFeedCategorySimple(category));
    }
    feed.setState(domain.getState() != null ? domain.getState().name() : 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);
    }
    List<DataSet> srcDataSets = domain.getSources().stream().map(FeedConnection::getDataSet).filter(Optional::isPresent).map(Optional::get).map(dataSet -> {
        try {
            return catalogModelTransform.dataSetToRestModel().apply(dataSet);
        } catch (final AccessControlException e) {
            log.debug("Denied access to data set: {}: {}", domain.getId(), e);
            final DataSource dataSource = new DataSource();
            dataSource.setAllowedActions(new ActionGroup());
            dataSource.getAllowedActions().setActions(Collections.emptyList());
            final DataSet model = new DataSet();
            model.setId(domain.getId().toString());
            model.setDataSource(dataSource);
            return model;
        }
    }).collect(Collectors.toList());
    feed.setSourceDataSets(srcDataSets);
    if (actionGroup == null) {
        // add in access control items
        securityTransform.applyAccessControl(domain, feed);
    } else {
        feed.setAllowedActions(actionGroup);
    }
    return feed;
}
Also used : Category(com.thinkbiganalytics.metadata.api.category.Category) DataSourceProvider(com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) HiveService(com.thinkbiganalytics.hive.service.HiveService) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) JsonNode(com.fasterxml.jackson.databind.JsonNode) Pageable(org.springframework.data.domain.Pageable) Tag(com.thinkbiganalytics.discovery.schema.Tag) CatalogModelTransform(com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) FeedVersions(com.thinkbiganalytics.feedmgr.rest.model.FeedVersions) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Collection(java.util.Collection) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) Page(org.springframework.data.domain.Page) EntityVersionDifference(com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) List(java.util.List) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) AccessControlException(java.security.AccessControlException) Optional(java.util.Optional) PageImpl(org.springframework.data.domain.PageImpl) JsonDiff(com.flipkart.zjsonpatch.JsonDiff) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) SearchResultImpl(com.thinkbiganalytics.rest.model.search.SearchResultImpl) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HistoryReindexingStatus(com.thinkbiganalytics.metadata.api.feed.reindex.HistoryReindexingStatus) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) EntityVersion(com.thinkbiganalytics.metadata.api.versioning.EntityVersion) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) ArrayList(java.util.ArrayList) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) Inject(javax.inject.Inject) FeedConnection(com.thinkbiganalytics.metadata.api.feed.FeedConnection) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) TemplateModelTransform(com.thinkbiganalytics.feedmgr.service.template.TemplateModelTransform) User(com.thinkbiganalytics.security.rest.model.User) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) Maps(com.google.common.collect.Maps) SearchResult(com.thinkbiganalytics.rest.model.search.SearchResult) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) EncryptionService(com.thinkbiganalytics.security.core.encrypt.EncryptionService) CategoryModelTransform(com.thinkbiganalytics.feedmgr.service.category.CategoryModelTransform) UserPropertyTransform(com.thinkbiganalytics.feedmgr.service.UserPropertyTransform) DatasourceAccessControl(com.thinkbiganalytics.metadata.api.datasource.security.DatasourceAccessControl) JcrHadoopSecurityGroup(com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup) HadoopSecurityGroupProvider(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroupProvider) Collections(java.util.Collections) User(com.thinkbiganalytics.security.rest.model.User) Category(com.thinkbiganalytics.metadata.api.category.Category) FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) 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) Optional(java.util.Optional) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) FeedConnection(com.thinkbiganalytics.metadata.api.feed.FeedConnection) AccessControlException(java.security.AccessControlException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) Nonnull(javax.annotation.Nonnull)

Example 7 with FeedSummary

use of com.thinkbiganalytics.feedmgr.rest.model.FeedSummary 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());
    } else {
        FeedMetadata previousFeed = feeds.get(feed.getId());
        feed.setId(previousFeed.getId());
    }
    // 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)

Example 8 with FeedSummary

use of com.thinkbiganalytics.feedmgr.rest.model.FeedSummary in project kylo by Teradata.

the class InMemoryFeedManagerFeedService method postConstruct.

@PostConstruct
private void postConstruct() {
    Collection<FeedMetadata> savedFeeds = FileObjectPersistence.getInstance().getFeedsFromFile();
    if (savedFeeds != null) {
        Long maxId = 0L;
        for (FeedMetadata feed : savedFeeds) {
            // update the category mappings
            String categoryId = feed.getCategory().getId();
            FeedCategory category = categoryProvider.getCategoryById(categoryId);
            feed.setCategory(category);
            category.addRelatedFeed(new FeedSummary(feed));
            // add it to the map
            feeds.put(feed.getId(), feed);
        }
        loadSavedFeedsToMetaClientStore();
    }
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) PostConstruct(javax.annotation.PostConstruct)

Example 9 with FeedSummary

use of com.thinkbiganalytics.feedmgr.rest.model.FeedSummary in project kylo by Teradata.

the class InMemoryFeedManagerFeedService method getFeedSummaryForCategory.

public List<FeedSummary> getFeedSummaryForCategory(String categoryId) {
    List<FeedSummary> summaryList = new ArrayList<>();
    FeedCategory category = categoryProvider.getCategoryById(categoryId);
    if (category != null && category.getFeeds() != null) {
        summaryList.addAll(category.getFeeds());
    }
    return summaryList;
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) ArrayList(java.util.ArrayList) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)

Example 10 with FeedSummary

use of com.thinkbiganalytics.feedmgr.rest.model.FeedSummary in project kylo by Teradata.

the class IntegrationTestBase method disableExistingFeeds.

protected void disableExistingFeeds() {
    LOG.info("Disabling existing feeds");
    // start clean - disable all feeds before deleting them - this
    // will give time for processors to stop before they are deleted, otherwise
    // will get an error if processor is still running while we try to delete the process group
    FeedSummary[] feeds = getFeeds();
    for (FeedSummary feed : feeds) {
        disableFeed(feed.getFeedId());
    }
    if (feeds.length > 0) {
        // give time for processors to stop
        waitFor(PROCESSOR_STOP_WAIT_DELAY, TimeUnit.SECONDS, "for processors to stop");
    }
}
Also used : FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)

Aggregations

FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)22 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)11 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)10 ArrayList (java.util.ArrayList)9 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)6 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)5 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)4 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)4 UserProperty (com.thinkbiganalytics.feedmgr.rest.model.UserProperty)4 Category (com.thinkbiganalytics.metadata.api.category.Category)4 FeedNotFoundException (com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException)4 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)4 NotFoundException (javax.ws.rs.NotFoundException)4 Response (com.jayway.restassured.response.Response)3 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)3 EntityVersionDifference (com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference)3 FeedVersions (com.thinkbiganalytics.feedmgr.rest.model.FeedVersions)3 HadoopSecurityGroup (com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup)3 JcrHadoopSecurityGroup (com.thinkbiganalytics.metadata.modeshape.security.JcrHadoopSecurityGroup)3 FieldRuleProperty (com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)3