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, ""));
}
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));
}
}
Aggregations