use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSet 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());
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSet in project kylo by Teradata.
the class SparkShellProxyController method addDataSourceInformation.
private DataSet addDataSourceInformation(@Nonnull DataSet dataSet) {
DataSet fetchedDataSet = fetchDataSet(dataSet.getId());
DataSetTemplate template = DataSetUtil.mergeTemplates(fetchedDataSet);
fetchedDataSet.getDataSource().setTemplate(template);
return new DataSet(fetchedDataSet);
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSet 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;
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSet in project kylo by Teradata.
the class App method catalogDataSetProvider.
@Bean
public CatalogDataSetProvider catalogDataSetProvider(final CatalogDataSetProviderFactory catalogDataSetProviderFactory, @Named("decryptionModule") final Module decryptionModule) throws IOException {
final List<DataSet> dataSets;
final String env = System.getenv("DATASETS");
if (env != null) {
dataSets = new ObjectMapper().registerModule(decryptionModule).readValue(env, TypeFactory.defaultInstance().constructCollectionType(List.class, DataSet.class));
} else {
dataSets = Collections.emptyList();
}
return catalogDataSetProviderFactory.getDataSetProvider(dataSets);
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSet in project kylo by Teradata.
the class DataSetProvider method createDataSet.
/**
* Creates a new data set using the specified template.
* @param encryptedCredentials
*
* @throws CatalogException if the data set is not valid
*/
@Nonnull
public DataSet createDataSet(@Nonnull final DataSet source, boolean encryptedCredentials) {
// Find data source
final DataSource dataSource = Optional.of(source).map(DataSet::getDataSource).map(DataSource::getId).flatMap(dataSourceProvider::findDataSource).orElseThrow(() -> new CatalogException("catalog.dataset.datasource.invalid"));
// Validate data set
final DataSet dataSet = new DataSet(source);
dataSet.setDataSource(dataSource);
validateDataSet(dataSet);
return metadataService.commit(() -> {
// Require admin permission if the results should include unencrypted credentials.
accessController.checkPermission(AccessController.SERVICES, encryptedCredentials ? FeedServicesAccessControl.ACCESS_DATASOURCES : FeedServicesAccessControl.ADMIN_DATASOURCES);
// Resolve the real data set if possible, otherwise create
com.thinkbiganalytics.metadata.api.catalog.DataSource.ID dataSourceId = dataSourceMetadataProvider.resolveId(dataSource.getId());
com.thinkbiganalytics.metadata.api.catalog.DataSet ds = modelTransform.buildDataSet(source, metadataProvider.build(dataSourceId));
return modelTransform.dataSetToRestModel(encryptedCredentials).apply(ds);
});
}
Aggregations