Search in sources :

Example 11 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed in project kylo by Teradata.

the class JcrFeedRolesTest method testRemoveMembership.

@Test
public void testRemoveMembership() {
    metadata.commit(() -> {
        this.feedProvider.findById(idA).getRoleMembership("testViewer").ifPresent(m -> m.addMember(TEST_USER3));
        this.feedProvider.findById(idA).getRoleMembership("testEditor").ifPresent(m -> m.addMember(TEST_USER3));
        this.feedProvider.findById(idB).getRoleMembership("testEditor").ifPresent(m -> m.addMember(TEST_USER3));
    }, JcrMetadataAccess.SERVICE);
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA.getDescription()).isNotNull().isEqualTo("Feed A");
        assertThat(feedA.getJson()).isNotNull();
        assertThat(feedA.getState()).isNotNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB.getDescription()).isNotNull().isEqualTo("Feed B");
        assertThat(feedB.getJson()).isNotNull();
        assertThat(feedB.getState()).isNotNull();
    }, TEST_USER3);
    metadata.commit(() -> {
        this.feedProvider.findById(idA).getRoleMembership("testEditor").ifPresent(m -> m.removeMember(TEST_USER3));
    }, JcrMetadataAccess.SERVICE);
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA.getDescription()).isNotNull().isEqualTo("Feed A");
        assertThat(feedA.getJson()).isNull();
        assertThat(feedA.getState()).isNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB.getDescription()).isNotNull().isEqualTo("Feed B");
        assertThat(feedB.getJson()).isNotNull();
        assertThat(feedB.getState()).isNotNull();
    }, TEST_USER3);
    metadata.commit(() -> {
        this.feedProvider.findById(idA).getRoleMembership("testViewer").ifPresent(m -> m.removeMember(TEST_USER3));
        this.feedProvider.findById(idB).getRoleMembership("testEditor").ifPresent(m -> m.removeMember(TEST_USER3));
    }, JcrMetadataAccess.SERVICE);
    metadata.read(() -> {
        Feed feedA = this.feedProvider.getFeed(idA);
        assertThat(feedA).isNull();
        Feed feedB = this.feedProvider.getFeed(idB);
        assertThat(feedB).isNull();
    }, TEST_USER3);
}
Also used : Feed(com.thinkbiganalytics.metadata.api.feed.Feed) Test(org.junit.Test)

Example 12 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed in project kylo by Teradata.

the class JcrFeedProvider method findByCategoryId.

@Override
public List<? extends Feed> findByCategoryId(Category.ID categoryId) {
    String query = "SELECT e.* from " + EntityUtil.asQueryProperty(JcrFeed.NODE_TYPE) + " as e " + "INNER JOIN [" + CategoryDetails.NODE_TYPE + "] as det on ISCHILDNODE(e, det)" + "INNER JOIN [" + JcrCategory.NODE_TYPE + "] as cat on ISCHILDNODE(det, cat)" + "WHERE cat.[mode:id] = $id";
    Map<String, String> bindParams = new HashMap<>();
    bindParams.put("id", categoryId.toString());
    try {
        QueryResult result = JcrQueryUtil.query(getSession(), query, bindParams);
        // not accessible.  For now filter the result based on the feed summary access.
        return JcrQueryUtil.queryResultStream(result, JcrFeed.class).filter(feed -> feed.getFeedSummary().isPresent()).collect(Collectors.toList());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to getFeeds for Category ", e);
    }
}
Also used : EntityUtil(com.thinkbiganalytics.metadata.modeshape.common.EntityUtil) Category(com.thinkbiganalytics.metadata.api.category.Category) DatasourceNotFoundException(com.thinkbiganalytics.metadata.api.datasource.DatasourceNotFoundException) ChangeType(com.thinkbiganalytics.metadata.api.event.MetadataChange.ChangeType) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) QueryResult(javax.jcr.query.QueryResult) FeedChange(com.thinkbiganalytics.metadata.api.event.feed.FeedChange) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) AbstractMetadataCriteria(com.thinkbiganalytics.metadata.modeshape.AbstractMetadataCriteria) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) JcrDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasource) Map(java.util.Map) FeedPropertyChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedPropertyChangeEvent) AccessController(com.thinkbiganalytics.security.AccessController) Pageable(org.springframework.data.domain.Pageable) UserFieldDescriptors(com.thinkbiganalytics.metadata.modeshape.common.UserFieldDescriptors) JcrAllowedEntityActionsProvider(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedEntityActionsProvider) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) FeedDestination(com.thinkbiganalytics.metadata.api.feed.FeedDestination) PreconditionBuilder(com.thinkbiganalytics.metadata.api.feed.PreconditionBuilder) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) CategoryDetails(com.thinkbiganalytics.metadata.modeshape.category.CategoryDetails) Session(javax.jcr.Session) FeedOpsAccessControlProvider(com.thinkbiganalytics.metadata.api.feed.security.FeedOpsAccessControlProvider) Set(java.util.Set) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) FeedCriteria(com.thinkbiganalytics.metadata.api.feed.FeedCriteria) Serializable(java.io.Serializable) SecurityRoleProvider(com.thinkbiganalytics.security.role.SecurityRoleProvider) List(java.util.List) Principal(java.security.Principal) Predicate(com.google.common.base.Predicate) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Optional(java.util.Optional) BaseJcrProvider(com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider) PropertyChange(com.thinkbiganalytics.metadata.api.event.feed.PropertyChange) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) NodeIterator(javax.jcr.NodeIterator) JcrEntity(com.thinkbiganalytics.metadata.modeshape.common.JcrEntity) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HashMap(java.util.HashMap) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ObligationGroupBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder) RepositoryException(javax.jcr.RepositoryException) Node(javax.jcr.Node) FeedChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedChangeEvent) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) Nonnull(javax.annotation.Nonnull) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) Datasource(com.thinkbiganalytics.metadata.api.datasource.Datasource) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) DateTime(org.joda.time.DateTime) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) JcrServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementProvider) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) Consumer(java.util.function.Consumer) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory) ID(com.thinkbiganalytics.metadata.api.feed.Feed.ID) Condition(com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) ObligationBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) VersionProviderMixin(com.thinkbiganalytics.metadata.modeshape.common.mixin.VersionProviderMixin) Collections(java.util.Collections) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) HashMap(java.util.HashMap) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 13 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed in project kylo by Teradata.

the class JcrFeedProvider method enableFeed.

// 
// @Override
// public com.thinkbiganalytics.metadata.api.feed.FeedSource.ID resolveSource(Serializable sid) {
// return new JcrFeedSource.FeedSourceId((sid));
// }
// 
// @Override
// public com.thinkbiganalytics.metadata.api.feed.FeedDestination.ID resolveDestination(Serializable sid) {
// return new JcrFeedDestination.FeedDestinationId(sid);
// }
@Override
public boolean enableFeed(Feed.ID id) {
    Feed feed = getFeed(id);
    if (accessController.isEntityAccessControlled()) {
        feed.getAllowedActions().checkPermission(FeedAccessControl.ENABLE_DISABLE);
    }
    if (!feed.getState().equals(Feed.State.ENABLED)) {
        feed.setState(Feed.State.ENABLED);
        // Enable any SLAs on this feed
        List<ServiceLevelAgreement> serviceLevelAgreements = feed.getServiceLevelAgreements();
        if (serviceLevelAgreements != null) {
            for (ServiceLevelAgreement sla : serviceLevelAgreements) {
                JcrServiceLevelAgreement jcrSla = (JcrServiceLevelAgreement) sla;
                jcrSla.enable();
            }
        }
        return true;
    }
    return false;
}
Also used : JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Example 14 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed in project kylo by Teradata.

the class JcrFeedProvider method addPostFeedChangeAction.

/**
 * Registers an action that produces a feed change event upon a successful transaction commit.
 *
 * @param feed the feed to being created
 */
private void addPostFeedChangeAction(Feed feed, ChangeType changeType) {
    Feed.State state = feed.getState();
    Feed.ID id = feed.getId();
    String feedName = feed.getQualifiedName();
    final Principal principal = SecurityContextHolder.getContext().getAuthentication();
    Consumer<Boolean> action = (success) -> {
        if (success) {
            FeedChange change = new FeedChange(changeType, feedName, feedName, id, state);
            FeedChangeEvent event = new FeedChangeEvent(change, DateTime.now(), principal);
            metadataEventService.notify(event);
        }
    };
    JcrMetadataAccess.addPostTransactionAction(action);
}
Also used : ID(com.thinkbiganalytics.metadata.api.feed.Feed.ID) EntityUtil(com.thinkbiganalytics.metadata.modeshape.common.EntityUtil) Category(com.thinkbiganalytics.metadata.api.category.Category) DatasourceNotFoundException(com.thinkbiganalytics.metadata.api.datasource.DatasourceNotFoundException) ChangeType(com.thinkbiganalytics.metadata.api.event.MetadataChange.ChangeType) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration) QueryResult(javax.jcr.query.QueryResult) FeedChange(com.thinkbiganalytics.metadata.api.event.feed.FeedChange) Obligation(com.thinkbiganalytics.metadata.sla.api.Obligation) AbstractMetadataCriteria(com.thinkbiganalytics.metadata.modeshape.AbstractMetadataCriteria) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) JcrDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasource) Map(java.util.Map) FeedPropertyChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedPropertyChangeEvent) AccessController(com.thinkbiganalytics.security.AccessController) Pageable(org.springframework.data.domain.Pageable) UserFieldDescriptors(com.thinkbiganalytics.metadata.modeshape.common.UserFieldDescriptors) JcrAllowedEntityActionsProvider(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedEntityActionsProvider) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) FeedDestination(com.thinkbiganalytics.metadata.api.feed.FeedDestination) PreconditionBuilder(com.thinkbiganalytics.metadata.api.feed.PreconditionBuilder) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) CategoryDetails(com.thinkbiganalytics.metadata.modeshape.category.CategoryDetails) Session(javax.jcr.Session) FeedOpsAccessControlProvider(com.thinkbiganalytics.metadata.api.feed.security.FeedOpsAccessControlProvider) Set(java.util.Set) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) FeedCriteria(com.thinkbiganalytics.metadata.api.feed.FeedCriteria) Serializable(java.io.Serializable) SecurityRoleProvider(com.thinkbiganalytics.security.role.SecurityRoleProvider) List(java.util.List) Principal(java.security.Principal) Predicate(com.google.common.base.Predicate) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Optional(java.util.Optional) BaseJcrProvider(com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider) PropertyChange(com.thinkbiganalytics.metadata.api.event.feed.PropertyChange) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) NodeIterator(javax.jcr.NodeIterator) JcrEntity(com.thinkbiganalytics.metadata.modeshape.common.JcrEntity) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HashMap(java.util.HashMap) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ObligationGroupBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationGroupBuilder) RepositoryException(javax.jcr.RepositoryException) Node(javax.jcr.Node) FeedChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedChangeEvent) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) Nonnull(javax.annotation.Nonnull) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) Datasource(com.thinkbiganalytics.metadata.api.datasource.Datasource) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) DateTime(org.joda.time.DateTime) ServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) JcrServiceLevelAgreementProvider(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreementProvider) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) Consumer(java.util.function.Consumer) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory) ID(com.thinkbiganalytics.metadata.api.feed.Feed.ID) Condition(com.thinkbiganalytics.metadata.sla.api.ObligationGroup.Condition) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) ObligationBuilder(com.thinkbiganalytics.metadata.sla.spi.ObligationBuilder) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) VersionProviderMixin(com.thinkbiganalytics.metadata.modeshape.common.mixin.VersionProviderMixin) Collections(java.util.Collections) FeedChange(com.thinkbiganalytics.metadata.api.event.feed.FeedChange) FeedChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedChangeEvent) Principal(java.security.Principal) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Example 15 with Feed

use of com.thinkbiganalytics.metadata.api.feed.Feed in project kylo by Teradata.

the class JobRepoFeedOperationsProvider method findLatestCompleted.

@Override
public List<FeedOperation> findLatestCompleted(Feed.ID feedId) {
    return metadata.read(() -> {
        List<FeedOperation> operations = new ArrayList<>();
        Feed feed = this.feedProvider.getFeed(feedId);
        if (feed != null) {
            BatchJobExecution latestJobExecution = this.jobExecutionProvider.findLatestCompletedJobForFeed(feed.getQualifiedName());
            if (latestJobExecution != null) {
                LOG.debug("Latest completed job execution id {} ", latestJobExecution.getJobExecutionId());
                operations.add(createOperation(latestJobExecution));
            }
        }
        return operations;
    });
}
Also used : BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) ArrayList(java.util.ArrayList) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Aggregations

Feed (com.thinkbiganalytics.metadata.api.feed.Feed)69 ArrayList (java.util.ArrayList)19 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)17 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)15 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)15 Category (com.thinkbiganalytics.metadata.api.category.Category)14 FeedNotFoundException (com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException)14 FeedManagerTemplate (com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate)13 List (java.util.List)13 FeedProvider (com.thinkbiganalytics.metadata.api.feed.FeedProvider)12 HashMap (java.util.HashMap)12 DateTime (org.joda.time.DateTime)12 ID (com.thinkbiganalytics.metadata.api.feed.Feed.ID)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11 Test (org.junit.Test)11 FeedAccessControl (com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl)10 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)10 AccessController (com.thinkbiganalytics.security.AccessController)10 HashSet (java.util.HashSet)10