Search in sources :

Example 6 with DataSet

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

the class DataSetController method getDataSet.

@GET
@Path("{id}")
@ApiOperation("Retrieves the specified data set")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data set", response = DataSet.class), @ApiResponse(code = 404, message = "Data set not found", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
public Response getDataSet(@PathParam("id") @UUID final String dataSetId) {
    log.entry(dataSetId);
    final boolean encryptCredentials = true;
    final DataSet dataSet = findDataSet(dataSetId, encryptCredentials);
    return Response.ok(log.exit(dataSet)).build();
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with DataSet

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

the class DataSetController method updateDataSet.

@PUT
@ApiOperation("Updates an existing data set")
@ApiResponses({ @ApiResponse(code = 200, message = "Data set updated", response = DataSet.class), @ApiResponse(code = 400, message = "Invalid data source", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateDataSet(@Nonnull final DataSet source) {
    log.entry(source);
    final boolean encryptCredentials = true;
    final DataSet dataSet;
    try {
        dataSet = dataSetService.updateDataSet(source, encryptCredentials);
    } catch (final CatalogException e) {
        throw new BadRequestException(getMessage(e));
    }
    return Response.ok(log.exit(dataSet)).build();
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with DataSet

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

the class DataSetUtilTest method getPaths.

/**
 * Verify merging paths for a data set.
 */
@Test
public void getPaths() {
    // Create mock connector
    final DefaultDataSetTemplate connectorTemplate = new DefaultDataSetTemplate();
    connectorTemplate.setOptions(Collections.singletonMap("path", "connector1.txt"));
    connectorTemplate.setPaths(Collections.singletonList("connector2.txt"));
    final Connector connector = new Connector();
    connector.setTemplate(connectorTemplate);
    // Create mock data source
    final DefaultDataSetTemplate dataSourceTemplate = new DefaultDataSetTemplate();
    dataSourceTemplate.setOptions(Collections.singletonMap("path", "datasource1.txt"));
    dataSourceTemplate.setPaths(Collections.singletonList("datasource2.txt"));
    final DataSource dataSource = new DataSource();
    dataSource.setConnector(connector);
    dataSource.setTemplate(dataSourceTemplate);
    // Create mock data set
    final DataSet dataSet = new DataSet();
    dataSet.setDataSource(dataSource);
    dataSet.setOptions(Collections.singletonMap("path", "dataset1.txt"));
    dataSet.setPaths(Collections.singletonList("dataset2.txt"));
    // Test retrieving data set paths
    Assert.assertEquals(Arrays.asList("dataset1.txt", "dataset2.txt"), DataSetUtil.getPaths(dataSet).orElse(null));
    // Test retrieving data source paths
    dataSet.setOptions(null);
    Assert.assertEquals(Arrays.asList("datasource1.txt", "dataset2.txt"), DataSetUtil.getPaths(dataSet).orElse(null));
    dataSet.setPaths(null);
    Assert.assertEquals(Arrays.asList("datasource1.txt", "datasource2.txt"), DataSetUtil.getPaths(dataSet).orElse(null));
    // Test retrieving connector paths
    dataSourceTemplate.setOptions(null);
    Assert.assertEquals(Arrays.asList("connector1.txt", "datasource2.txt"), DataSetUtil.getPaths(dataSet).orElse(null));
    dataSourceTemplate.setPaths(null);
    Assert.assertEquals(Arrays.asList("connector1.txt", "connector2.txt"), DataSetUtil.getPaths(dataSet).orElse(null));
    // Test retrieving empty paths
    connectorTemplate.setOptions(null);
    connectorTemplate.setPaths(null);
    Assert.assertEquals(Optional.empty(), DataSetUtil.getPaths(dataSet));
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Test(org.junit.Test)

Example 9 with DataSet

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

the class CatalogFileManagerTest method createUpload.

/**
 * Verify uploading a file.
 */
@Test
public void createUpload() throws IOException {
    final DataSet dataSet = createDataSet();
    final String src = "Hello world!";
    // Test uploading a file
    final CatalogFileManager fileManager = new MockCatalogFileManager();
    final DataSetFile upload = fileManager.createUpload(dataSet, "file-upload.txt", new ByteArrayInputStream(src.getBytes(StandardCharsets.UTF_8)));
    final File file = datasetsFolder.getRoot().toPath().resolve(dataSet.getId()).resolve("file-upload.txt").toFile();
    Assert.assertFalse("Expected uploaded file to not be a directory", upload.isDirectory());
    Assert.assertEquals(src.length(), upload.getLength().longValue());
    Assert.assertEquals("file-upload.txt", upload.getName());
    Assert.assertEquals(file.toURI(), URI.create(upload.getPath()));
    Assert.assertEquals(src, Files.toString(file, StandardCharsets.UTF_8));
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) File(java.io.File) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) Test(org.junit.Test)

Example 10 with DataSet

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

the class CatalogFileManagerTest method deleteUpload.

/**
 * Verify deleting an uploaded file.
 */
@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void deleteUpload() throws IOException {
    // Create data set including files
    final DataSet dataSet = createDataSet();
    final File file = new File(datasetsFolder.newFolder(dataSet.getId()), "test-file.txt");
    file.createNewFile();
    Assert.assertTrue("Expected file to exist", file.exists());
    // Test deleting a file
    final CatalogFileManager fileManager = new MockCatalogFileManager();
    fileManager.deleteUpload(dataSet, "test-file.txt");
    Assert.assertFalse("Expected file to be deleted", file.exists());
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) File(java.io.File) Test(org.junit.Test)

Aggregations

DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)21 ApiOperation (io.swagger.annotations.ApiOperation)9 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Path (javax.ws.rs.Path)8 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)7 DataSetFile (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile)6 BadRequestException (javax.ws.rs.BadRequestException)6 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)5 Nonnull (javax.annotation.Nonnull)5 POST (javax.ws.rs.POST)5 Test (org.junit.Test)5 Produces (javax.ws.rs.Produces)4 File (java.io.File)3 Consumes (javax.ws.rs.Consumes)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)3 NotFoundException (javax.ws.rs.NotFoundException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2