Search in sources :

Example 1 with DataSourceNotFoundException

use of com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException in project kylo by Teradata.

the class DataSetControllerTest method createDataSetWithInvalid.

/**
 * Verify exception for creating an invalid data set.
 */
@Test(expected = BadRequestException.class)
public void createDataSetWithInvalid() {
    Mockito.when(dataSetBuilder.build()).thenThrow(new DataSourceNotFoundException(null));
    final com.thinkbiganalytics.kylo.catalog.rest.model.DataSource src = modelTransform.dataSourceToRestModel().apply(dataSource);
    controller.createDataSet(new com.thinkbiganalytics.kylo.catalog.rest.model.DataSet(src, ""));
}
Also used : DataSourceNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException) Test(org.junit.Test)

Example 2 with DataSourceNotFoundException

use of com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException in project kylo by Teradata.

the class DefaultFeedManagerFeedService method assignFeedDatasources.

/**
 * Assign the feed sources/destinations
 *
 * @param feed       the feed rest model
 * @param domainFeed the domain feed
 */
private void assignFeedDatasources(FeedMetadata feed, Feed domainFeed) {
    final Feed.ID domainFeedId = domainFeed.getId();
    Set<com.thinkbiganalytics.metadata.api.catalog.DataSet.ID> sourceDataSets = new HashSet<>();
    Set<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> sourceDatasources = new HashSet<>();
    Set<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> destinationDatasources = new HashSet<>();
    String uniqueName = FeedNameUtil.fullName(feed.getCategory().getSystemName(), feed.getSystemFeedName());
    RegisteredTemplate template = feed.getRegisteredTemplate();
    if (template == null) {
        // fetch it for checks
        template = templateRestProvider.getRegisteredTemplate(feed.getTemplateId());
    }
    // Collect the IDs of the legacy datasources the feed had referenced
    Set<Datasource.ID> previousSourceIds = domainFeed.getSources().stream().filter(fs -> fs.getDatasource().isPresent()).map(fs -> fs.getDatasource().get().getId()).collect(Collectors.toSet());
    Set<Datasource.ID> previousDestIds = domainFeed.getDestinations().stream().filter(// Currently will always be true as there are no destination data sets yet.
    fs -> fs.getDatasource().isPresent()).map(fs -> fs.getDatasource().get().getId()).collect(Collectors.toSet());
    boolean isSampleDataSet = isTreatSourceDataSetsAsSample(feed, template);
    // find Definition registration
    derivedDatasourceFactory.populateDatasources(feed, template, sourceDatasources, destinationDatasources);
    // Replace the older legacy datasource references with the new ones.
    previousSourceIds.stream().filter(id -> !sourceDatasources.contains(id)).forEach(id -> feedProvider.removeFeedSource(domainFeedId, id));
    sourceDatasources.stream().forEach(sourceId -> feedProvider.ensureFeedSource(domainFeedId, sourceId));
    previousDestIds.stream().filter(id -> !destinationDatasources.contains(id)).forEach(id -> feedProvider.removeFeedDestination(domainFeedId, id));
    destinationDatasources.stream().forEach(sourceId -> feedProvider.ensureFeedDestination(domainFeedId, sourceId));
    // Update data sets
    if (feed.getSourceDataSets() != null) {
        // Collect the IDs of source data sets the feed had referenced
        Set<com.thinkbiganalytics.metadata.api.catalog.DataSet.ID> currentDataSetIds = domainFeed.getSources().stream().map(FeedSource::getDataSet).filter(Optional::isPresent).map(Optional::get).map(com.thinkbiganalytics.metadata.api.catalog.DataSet::getId).collect(Collectors.toSet());
        Set<com.thinkbiganalytics.metadata.api.catalog.DataSet.ID> newDataSetIds = new HashSet<>();
        feed.getSourceDataSets().forEach(dataSet -> {
            com.thinkbiganalytics.metadata.api.catalog.DataSet addedDataSet;
            if (dataSet.getId() == null) {
                DataSource.ID dataSourceId = dataSourceProvider.resolveId(dataSet.getDataSource().getId());
                dataSourceProvider.find(dataSourceId).orElseThrow(() -> new DataSourceNotFoundException(dataSourceId));
                addedDataSet = catalogModelTransform.buildDataSet(dataSet, dataSetProvider.build(dataSourceId));
            } else {
                com.thinkbiganalytics.metadata.api.catalog.DataSet.ID dataSetId = dataSetProvider.resolveId(dataSet.getId());
                addedDataSet = dataSetProvider.find(dataSetId).orElseThrow(() -> new DataSetNotFoundException(dataSetId));
            }
            newDataSetIds.add(addedDataSet.getId());
            catalogModelTransform.updateDataSet(dataSet, addedDataSet);
            feedProvider.ensureFeedSource(domainFeedId, addedDataSet.getId(), isSampleDataSet);
        });
        // Remove any data set sources no longer referenced in the updated feed.
        currentDataSetIds.stream().filter(id -> !newDataSetIds.contains(id)).forEach(id -> feedProvider.removeFeedSource(domainFeedId, id));
    }
}
Also used : Action(com.thinkbiganalytics.security.action.Action) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Category(com.thinkbiganalytics.metadata.api.category.Category) DataSourceProvider(com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider) 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) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) 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) DraftEntityVersion(com.thinkbiganalytics.feedmgr.rest.model.DraftEntityVersion) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) DataSourceNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException) 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) Nullable(javax.annotation.Nullable) 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) ImmutableAllowableAction(com.thinkbiganalytics.security.role.ImmutableAllowableAction) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) 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) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) Pageable(org.springframework.data.domain.Pageable) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) CatalogModelTransform(com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform) FeedVersions(com.thinkbiganalytics.feedmgr.rest.model.FeedVersions) DeployResponseEntityVersion(com.thinkbiganalytics.feedmgr.rest.model.DeployResponseEntityVersion) FeedDestination(com.thinkbiganalytics.metadata.api.feed.FeedDestination) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) ImmutableAllowedActions(com.thinkbiganalytics.security.role.ImmutableAllowedActions) UserField(com.thinkbiganalytics.feedmgr.rest.model.UserField) ImmutableMap(com.google.common.collect.ImmutableMap) DataSetNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSetNotFoundException) 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) DataSource(com.thinkbiganalytics.metadata.api.catalog.DataSource) 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) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) 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) 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) AbstractMap(java.util.AbstractMap) 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) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) HashSet(java.util.HashSet) DataSetNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSetNotFoundException) Optional(java.util.Optional) DataSource(com.thinkbiganalytics.metadata.api.catalog.DataSource) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) DataSourceNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException)

Aggregations

DataSourceNotFoundException (com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 HadoopAuthorizationService (com.thinkbiganalytics.datalake.authorization.service.HadoopAuthorizationService)1 CreateFeedBuilder (com.thinkbiganalytics.feedmgr.nifi.CreateFeedBuilder)1 PropertyExpressionResolver (com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver)1 TemplateConnectionUtil (com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil)1 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)1 DeployResponseEntityVersion (com.thinkbiganalytics.feedmgr.rest.model.DeployResponseEntityVersion)1 DraftEntityVersion (com.thinkbiganalytics.feedmgr.rest.model.DraftEntityVersion)1 EntityVersion (com.thinkbiganalytics.feedmgr.rest.model.EntityVersion)1 EntityVersionDifference (com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)1 FeedVersions (com.thinkbiganalytics.feedmgr.rest.model.FeedVersions)1 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)1 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)1 RegisteredTemplateRequest (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest)1 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)1