Search in sources :

Example 1 with DataSource

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.

the class DataSetIT method testUpload.

/**
 * Verify uploading files.
 */
// TODO create local-files data source
@Ignore
@Test
public void testUpload() {
    // Create a data set
    final DataSet request = new DataSet();
    request.setDataSource(new DataSource());
    request.getDataSource().setId("local-files");
    final DataSet dataSet = given(DataSetController.BASE).when().body(request).post().then().statusCode(200).extract().as(DataSet.class);
    final String id = dataSet.getId();
    // Test empty data set
    List<DataSetFile> files = listUploads(id);
    Assert.assertEquals(0, files.size());
    // Upload sample files
    uploadFile(id, getSampleFile("userdata1.csv"));
    uploadFile(id, getSampleFile("userdata2.csv"));
    files = listUploads(id);
    Assert.assertThat(files, CoreMatchers.hasItem(nameEquals("userdata1.csv")));
    Assert.assertThat(files, CoreMatchers.hasItem(nameEquals("userdata2.csv")));
    Assert.assertEquals(2, files.size());
    // Delete a file
    given(DataSetController.BASE).when().delete(id + "/uploads/userdata1.csv").then().statusCode(204);
    files = listUploads(id);
    Assert.assertThat(files, CoreMatchers.hasItem(nameEquals("userdata2.csv")));
    Assert.assertEquals(1, files.size());
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DataSource

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.

the class DataSourceIT method testFindAll.

/**
 * Verifying retrieving all data sources.
 */
@Test
public void testFindAll() {
    // Create a feed data source
    final Connector[] connectors = listConnectors();
    Connector jdbcConnector = Arrays.asList(connectors).stream().filter(c -> c.getPluginId().equalsIgnoreCase("jdbc")).findFirst().orElse(null);
    DataSource ds = new DataSource();
    ds.setConnector(jdbcConnector);
    ds.setTitle("MySql Test");
    DefaultDataSetTemplate dsTemplate = new DefaultDataSetTemplate();
    Map<String, String> options = new HashMap<>();
    options.put("driver", "org.mariadb.jdbc.Driver");
    options.put("user", "root");
    options.put("password", "secret");
    options.put("url", "jdbc:mysql://localhost:3306/kylo");
    dsTemplate.setOptions(options);
    ds.setTemplate(dsTemplate);
    final DataSource jdbcDatasource = createDataSource(ds);
    // Find all data sources
    final SearchResult<DataSource> searchResult = given(DataSourceController.BASE).when().get().then().statusCode(200).extract().as(DataSourceSearchResult.class);
    final Matcher<DataSource> isHive = new CustomMatcher<DataSource>("is hive data source") {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof DataSource && "Hive".equals(((DataSource) item).getTitle()));
        }
    };
    final Matcher<DataSource> isJdbc = new CustomMatcher<DataSource>("is jdbc data source") {

        @Override
        public boolean matches(final Object item) {
            final DataSource dataSource = (item instanceof DataSource) ? (DataSource) item : null;
            return (dataSource != null && jdbcDatasource.getId().equals(dataSource.getId()) && jdbcDatasource.getTitle().equals(dataSource.getTitle()));
        }
    };
    Assert.assertThat(searchResult.getData(), CoreMatchers.hasItem(isHive));
    Assert.assertThat(searchResult.getData(), CoreMatchers.hasItem(isJdbc));
    Assert.assertEquals(searchResult.getData().size(), searchResult.getRecordsTotal().longValue());
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) CustomMatcher(org.hamcrest.CustomMatcher) HashMap(java.util.HashMap) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) Test(org.junit.Test)

Example 3 with DataSource

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource 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 4 with DataSource

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.

the class FeedModelTransform method updateDataSets.

/**
 * Updates the data sets of the specified feed.
 */
public void updateDataSets(@Nullable final FeedMetadata feed) {
    if (feed != null && feed.getSourceDataSets() != null) {
        feed.setSourceDataSets(feed.getSourceDataSets().stream().peek(dataSet -> {
            com.thinkbiganalytics.metadata.api.catalog.DataSource dataSource = null;
            if (dataSet.getDataSource() != null && dataSet.getDataSource().getId() != null) {
                final com.thinkbiganalytics.metadata.api.catalog.DataSource.ID dataSourceId = dataSourceProvider.resolveId(dataSet.getDataSource().getId());
                dataSource = dataSourceProvider.find(dataSourceId).orElse(null);
            }
            // add empty datasource if user doesnt have access
            if (dataSource == null && !accessController.hasPermission(dataSource, DatasourceAccessControl.ACCESS_DATASOURCE, DatasourceAccessControl.ACCESS_DETAILS)) {
                dataSet.setDataSource(new com.thinkbiganalytics.kylo.catalog.rest.model.DataSource());
                dataSet.getDataSource().setAllowedActions(new ActionGroup());
            }
        }).collect(Collectors.toList()));
    }
}
Also used : ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)

Example 5 with DataSource

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.

the class App method datasourceProvider.

/**
 * Creates a data source provider.
 *
 * @param datasourceProviderFactory the data source provider factory
 * @return the data source provider
 * @throws IOException if an I/O error occurs
 */
@Bean
public DatasourceProvider datasourceProvider(final DatasourceProviderFactory datasourceProviderFactory, @Named("decryptionModule") final Module decryptionModule) throws IOException {
    final List<Datasource> datasources;
    final String env = System.getenv("DATASOURCES");
    final List<DataSource> catalogDataSources;
    final String catalogDatasourcesEnv = System.getenv("CATALOG_DATASOURCES");
    if (env != null) {
        datasources = new ObjectMapper().registerModule(decryptionModule).readValue(env, TypeFactory.defaultInstance().constructCollectionType(List.class, Datasource.class));
    } else {
        datasources = Collections.emptyList();
    }
    if (catalogDatasourcesEnv != null) {
        catalogDataSources = new ObjectMapper().registerModule(decryptionModule).readValue(catalogDatasourcesEnv, TypeFactory.defaultInstance().constructCollectionType(List.class, DataSource.class));
    } else {
        catalogDataSources = Collections.emptyList();
    }
    return datasourceProviderFactory.getDatasourceProvider(datasources, catalogDataSources);
}
Also used : Datasource(com.thinkbiganalytics.spark.rest.model.Datasource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Bean(org.springframework.context.annotation.Bean)

Aggregations

DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)41 ApiOperation (io.swagger.annotations.ApiOperation)15 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)14 ApiResponses (io.swagger.annotations.ApiResponses)14 Nonnull (javax.annotation.Nonnull)14 Path (javax.ws.rs.Path)13 Connector (com.thinkbiganalytics.kylo.catalog.rest.model.Connector)11 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)10 GET (javax.ws.rs.GET)9 BadRequestException (javax.ws.rs.BadRequestException)8 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)7 DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Nullable (javax.annotation.Nullable)7 StringUtils (org.apache.commons.lang3.StringUtils)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 CatalogModelTransform (com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform)5 ConnectorPluginDescriptor (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)5