Search in sources :

Example 16 with Datasource

use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.

the class MetadataClientProviderTest method testEnsureDirectoryDatasource.

@Test
public void testEnsureDirectoryDatasource() {
    this.provider.ensureDirectoryDatasource("test6", "", Paths.get("aaa", "bbb"));
    Datasource ds = this.provider.getDatasourceByName("test6");
    assertThat(ds).isNotNull();
    assertThat(ds).isInstanceOf(DirectoryDatasource.class);
    String dsId = ds.getId();
    DirectoryDatasource dds = (DirectoryDatasource) ds;
    assertThat(dds.getPath()).contains("aaa/bbb");
    ds = this.provider.ensureDirectoryDatasource("test6", "", Paths.get("aaa", "bbb"));
    assertThat(ds).isNotNull();
    assertThat(ds.getId()).isEqualTo(dsId);
}
Also used : DirectoryDatasource(com.thinkbiganalytics.metadata.rest.model.data.DirectoryDatasource) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) HiveTableDatasource(com.thinkbiganalytics.metadata.rest.model.data.HiveTableDatasource) DirectoryDatasource(com.thinkbiganalytics.metadata.rest.model.data.DirectoryDatasource) Test(org.junit.Test)

Example 17 with Datasource

use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.

the class AbstractTerminateFeed method onTrigger.

/* (non-Javadoc)
     * @see org.apache.nifi.processor.AbstractProcessor#onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSession)
     */
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    try {
        FlowFile flowFile = session.get();
        if (flowFile != null) {
            MetadataProvider provider = getProviderService(context).getProvider();
            // TODO Remove when we do more intelligent handling when the feed and datasource info has been
            // removed from the metadata store.
            // FeedDestination destination = this.feedDestination.get();
            Datasource ds = ensureDatasourceMetadata(context);
            FeedDestination destination = ensureFeedDestination(context, flowFile, ds);
            // TODO Begin re-caching this when the correct error can be surfaced from the client
            // when the destination no longer exists.
            // if (destination == null) {
            // Datasource ds = this.destinationDatasource.get();
            // this.feedDestination.compareAndSet(null, destination);
            // }
            String timeStr = flowFile.getAttribute(OPERATON_START_PROP);
            DateTime opStart = timeStr != null ? Formatters.parseDateTime(timeStr) : new DateTime();
            DataOperation op = provider.beginOperation(destination, opStart);
            op = completeOperation(context, flowFile, ds, op, getState(context, op));
            updateFeedState(context, flowFile);
            flowFile = session.putAttribute(flowFile, OPERATON_STOP_PROP, Formatters.print(new DateTime()));
            session.remove(flowFile);
        // session.transfer(flowFile, SUCCESS);
        } else {
            context.yield();
        }
    } catch (Exception e) {
        context.yield();
        session.rollback();
        getLog().error("Unexpected error processing feed completion", e);
        throw new ProcessException(e);
    }
}
Also used : Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) FlowFile(org.apache.nifi.flowfile.FlowFile) DataOperation(com.thinkbiganalytics.metadata.rest.model.op.DataOperation) ProcessException(org.apache.nifi.processor.exception.ProcessException) MetadataProvider(com.thinkbiganalytics.nifi.core.api.metadata.MetadataProvider) FeedDestination(com.thinkbiganalytics.metadata.rest.model.feed.FeedDestination) DateTime(org.joda.time.DateTime) ProcessException(org.apache.nifi.processor.exception.ProcessException)

Example 18 with Datasource

use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.

the class DefaultFeedExporter method exportFeed.

/**
 * Export a feed as a zip file
 *
 * @param feedId the id {@link Feed#getId()} of the feed to export
 * @return object containing the zip file with data about the feed.
 */
@Override
public ExportFeed exportFeed(String feedId) throws IOException {
    this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EXPORT_FEEDS);
    this.metadataService.checkFeedPermission(feedId, FeedAccessControl.EXPORT);
    // Prepare feed metadata
    final FeedMetadata feed = metadataService.getFeedById(feedId);
    if (feed == null) {
        // feed will not be found when user is allowed to export feeds but has no entity access to feed with feed id
        throw new NotFoundException("Feed not found for id " + feedId);
    }
    final List<Datasource> userDatasources = Optional.ofNullable(feed.getDataTransformation()).map(FeedDataTransformation::getDatasourceIds).map(datasourceIds -> metadataAccess.read(() -> datasourceIds.stream().map(datasourceProvider::resolve).map(datasourceProvider::getDatasource).map(domain -> datasourceTransform.toDatasource(domain, DatasourceModelTransform.Level.FULL)).map(datasource -> {
        // Clear sensitive fields
        datasource.getDestinationForFeeds().clear();
        datasource.getSourceForFeeds().clear();
        return datasource;
    }).collect(Collectors.toList()))).orElse(null);
    if (userDatasources != null && !userDatasources.isEmpty()) {
        this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
        feed.setUserDatasources(userDatasources);
    }
    // Add feed json to template zip file
    final ExportTemplate exportTemplate = templateExporter.exportTemplateForFeedExport(feed.getTemplateId());
    final String feedJson = ObjectMapperSerializer.serialize(feed);
    final byte[] zipFile = ZipFileUtil.addToZip(exportTemplate.getFile(), feedJson, ImportFeed.FEED_JSON_FILE);
    return new ExportFeed(feed.getSystemFeedName() + ".feed.zip", zipFile);
}
Also used : Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) ExportFeed(com.thinkbiganalytics.metadata.api.feed.export.ExportFeed) DatasourceModelTransform(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) DefaultTemplateExporter(com.thinkbiganalytics.feedmgr.service.template.exporting.DefaultTemplateExporter) Inject(javax.inject.Inject) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) TemplateExporter(com.thinkbiganalytics.metadata.api.template.export.TemplateExporter) IOException(java.io.IOException) FeedExporter(com.thinkbiganalytics.metadata.api.feed.export.FeedExporter) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) ExportFeed(com.thinkbiganalytics.metadata.api.feed.export.ExportFeed) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) NotFoundException(javax.ws.rs.NotFoundException) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate)

Example 19 with Datasource

use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.

the class DBCPConnectionPoolService method evaluateWithUserDefinedDatasources.

private boolean evaluateWithUserDefinedDatasources(PoolingDataSourceService.DataSourceProperties dataSourceProperties, AbstractControllerServiceRequest serviceProperties) {
    boolean valid = (StringUtils.isNotBlank(dataSourceProperties.getPassword()) && !dataSourceProperties.getPassword().startsWith("**"));
    if (!valid) {
        List<Datasource> matchingDatasources = metadataAccess.read(() -> {
            // attempt to get the properties from the stored datatsource
            return datasetProvider.getDatasources(datasetProvider.datasetCriteria().type(com.thinkbiganalytics.metadata.api.datasource.UserDatasource.class).name(serviceProperties.getControllerServiceName())).stream().map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(datasource -> datasource instanceof JdbcDatasource).collect(Collectors.toList());
        }, MetadataAccess.SERVICE);
        if (matchingDatasources != null && !matchingDatasources.isEmpty()) {
            JdbcDatasource userDatasource = (JdbcDatasource) matchingDatasources.stream().filter(ds -> ((JdbcDatasource) ds).getDatabaseUser().equalsIgnoreCase(dataSourceProperties.getUser())).findFirst().orElse(null);
            if (userDatasource == null) {
                userDatasource = (JdbcDatasource) matchingDatasources.get(0);
            }
            if (userDatasource != null) {
                dataSourceProperties.setUser(userDatasource.getDatabaseUser());
                dataSourceProperties.setPassword(userDatasource.getPassword());
                log.info("Returned user defined datasource for {} service and user {} ", serviceProperties.getControllerServiceName(), userDatasource.getDatabaseUser());
                valid = true;
            }
        }
        if (!valid) {
            String propertyKey = nifiControllerServiceProperties.getEnvironmentControllerServicePropertyPrefix(serviceProperties.getControllerServiceName()) + ".password";
            String example = propertyKey + "=PASSWORD";
            log.error("Unable to connect to Controller Service {}, {}.  You need to specify a configuration property as {} with the password for user: {}. ", serviceProperties.getControllerServiceName(), serviceProperties.getControllerServiceId(), example, dataSourceProperties.getUser());
        }
    }
    return valid;
}
Also used : JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) DataAccessException(org.springframework.dao.DataAccessException) QueryRunner(com.thinkbiganalytics.schema.QueryRunner) LoggerFactory(org.slf4j.LoggerFactory) DatasourceModelTransform(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform) Autowired(org.springframework.beans.factory.annotation.Autowired) DescribeTableControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.DescribeTableControllerServiceRequest.DescribeTableControllerServiceRequestBuilder) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) DBSchemaParser(com.thinkbiganalytics.schema.DBSchemaParser) JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSource(javax.sql.DataSource) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiControllerServiceProperties(com.thinkbiganalytics.feedmgr.nifi.NifiControllerServiceProperties) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) Collectors(java.util.stream.Collectors) List(java.util.List) Validate(org.apache.commons.lang3.Validate) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) Optional(java.util.Optional) KerberosTicketConfiguration(com.thinkbiganalytics.kerberos.KerberosTicketConfiguration) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource)

Example 20 with Datasource

use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.

the class FeedLineageBuilder method build.

private com.thinkbiganalytics.metadata.rest.model.feed.Feed build(Feed domainFeed) {
    com.thinkbiganalytics.metadata.rest.model.feed.Feed feed = restFeeds.containsKey(domainFeed.getId().toString()) ? restFeeds.get(domainFeed.getId().toString()) : model.domainToFeed(domainFeed);
    restFeeds.put(feed.getId(), feed);
    @SuppressWarnings("unchecked") List<? extends com.thinkbiganalytics.metadata.api.feed.FeedSource> sources = domainFeed.getSources();
    Set<FeedSource> feedSources = new HashSet<FeedSource>();
    if (sources != null) {
        sources.stream().forEach(feedSource -> {
            FeedSource src = new FeedSource();
            Datasource ds = buildDatasource(feedSource.getDatasource());
            src.setDatasource(ds);
            feedSources.add(src);
        });
    }
    feed.setSources(feedSources);
    Set<FeedDestination> feedDestinations = new HashSet<FeedDestination>();
    List<? extends com.thinkbiganalytics.metadata.api.feed.FeedDestination> destinations = domainFeed.getDestinations();
    if (destinations != null) {
        destinations.stream().forEach(feedDestination -> {
            FeedDestination dest = new FeedDestination();
            Datasource ds = buildDatasource(feedDestination.getDatasource());
            dest.setDatasource(ds);
            feedDestinations.add(dest);
        });
    }
    feed.setDestinations(feedDestinations);
    if (domainFeed.getDependentFeeds() != null) {
        List<Feed> depFeeds = domainFeed.getDependentFeeds();
        depFeeds.stream().forEach(depFeed -> {
            com.thinkbiganalytics.metadata.rest.model.feed.Feed restFeed = restFeeds.get(depFeed.getId().toString());
            if (restFeed == null) {
                com.thinkbiganalytics.metadata.rest.model.feed.Feed depRestFeed = model.domainToFeed(depFeed);
                restFeeds.put(depRestFeed.getId(), depRestFeed);
                feed.getDependentFeeds().add(depRestFeed);
                build(depFeed);
            } else {
                feed.getDependentFeeds().add(restFeed);
            }
        });
    }
    if (domainFeed.getUsedByFeeds() != null) {
        List<Feed> usedByFeeds = domainFeed.getUsedByFeeds();
        usedByFeeds.stream().forEach(usedByFeed -> {
            com.thinkbiganalytics.metadata.rest.model.feed.Feed restFeed = restFeeds.get(usedByFeed.getId().toString());
            if (restFeed == null) {
                com.thinkbiganalytics.metadata.rest.model.feed.Feed usedByRestFeed = model.domainToFeed(usedByFeed);
                restFeeds.put(usedByRestFeed.getId(), usedByRestFeed);
                feed.getUsedByFeeds().add(usedByRestFeed);
                build(usedByFeed);
            } else {
                feed.getUsedByFeeds().add(restFeed);
            }
        });
    }
    return feed;
}
Also used : Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) FeedDestination(com.thinkbiganalytics.metadata.rest.model.feed.FeedDestination) FeedSource(com.thinkbiganalytics.metadata.rest.model.feed.FeedSource) HashSet(java.util.HashSet) Feed(com.thinkbiganalytics.metadata.api.feed.Feed)

Aggregations

Datasource (com.thinkbiganalytics.metadata.rest.model.data.Datasource)25 DatasourceModelTransform (com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform)10 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)10 DatasourceProvider (com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider)10 JdbcDatasource (com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource)10 List (java.util.List)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Inject (javax.inject.Inject)10 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)9 AccessController (com.thinkbiganalytics.security.AccessController)9 HashSet (java.util.HashSet)9 NotFoundException (javax.ws.rs.NotFoundException)9 StringUtils (org.apache.commons.lang3.StringUtils)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 QueryResult (com.thinkbiganalytics.discovery.schema.QueryResult)8 TableSchema (com.thinkbiganalytics.discovery.schema.TableSchema)8 AccessControlled (com.thinkbiganalytics.metadata.api.security.AccessControlled)8 DatasourceCriteria (com.thinkbiganalytics.metadata.rest.model.data.DatasourceCriteria)8