Search in sources :

Example 1 with Connector

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

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

the class IntegrationTestBase method listConnectors.

protected Connector[] listConnectors() {
    Response response = given(ConnectorController.BASE).when().get();
    response.then().statusCode(HTTP_OK);
    return response.as(Connector[].class);
}
Also used : Response(com.jayway.restassured.response.Response) Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector)

Example 3 with Connector

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

the class DataSourceUtilTest method getPaths.

/**
 * Verify merging paths for a data source.
 */
@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);
    // Test retrieving data source paths
    Assert.assertEquals(Arrays.asList("datasource1.txt", "datasource2.txt"), DataSourceUtil.getPaths(dataSource).orElse(null));
    // Test retrieving connector paths
    dataSourceTemplate.setOptions(null);
    Assert.assertEquals(Arrays.asList("connector1.txt", "datasource2.txt"), DataSourceUtil.getPaths(dataSource).orElse(null));
    dataSourceTemplate.setPaths(null);
    Assert.assertEquals(Arrays.asList("connector1.txt", "connector2.txt"), DataSourceUtil.getPaths(dataSource).orElse(null));
    // Test retrieving empty paths
    connectorTemplate.setOptions(null);
    connectorTemplate.setPaths(null);
    Assert.assertEquals(Optional.empty(), DataSourceUtil.getPaths(dataSource));
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Test(org.junit.Test)

Example 4 with Connector

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

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

the class ConnectorController method getAllowedActions.

@GET
@Path("{id}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class), @ApiResponse(code = 404, message = "A connector with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("id") final String connectorIdStr, @QueryParam("user") final Set<String> userNames, @QueryParam("group") final Set<String> groupNames) {
    log.debug("Get allowed actions for connector: {}", connectorIdStr);
    Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
    Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
    return this.securityService.getAllowedConnectorActions(connectorIdStr, Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(g -> Response.ok(g).build()).orElseThrow(() -> new WebApplicationException("A connector with the given ID does not exist: " + connectorIdStr, Response.Status.NOT_FOUND));
}
Also used : XLogger(org.slf4j.ext.XLogger) Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ConnectorPluginManager(com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager) XLoggerFactory(org.slf4j.ext.XLoggerFactory) Path(javax.ws.rs.Path) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) Api(io.swagger.annotations.Api) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) CatalogModelTransform(com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform) ConnectorProvider(com.thinkbiganalytics.metadata.api.catalog.ConnectorProvider) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Component(org.springframework.stereotype.Component) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) ConnectorPluginDescriptor(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor) ApiResponse(io.swagger.annotations.ApiResponse) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Connector (com.thinkbiganalytics.kylo.catalog.rest.model.Connector)10 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)8 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)6 Test (org.junit.Test)5 DataSetFile (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile)2 JdbcDatasource (com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 CustomMatcher (org.hamcrest.CustomMatcher)2 Response (com.jayway.restassured.response.Response)1 SchemaParserDescriptor (com.thinkbiganalytics.discovery.model.SchemaParserDescriptor)1 DatasourceModelTransform (com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform)1 SecurityService (com.thinkbiganalytics.feedmgr.service.security.SecurityService)1 ConnectorPluginManager (com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager)1 DataSourceUtil (com.thinkbiganalytics.kylo.catalog.datasource.DataSourceUtil)1 CatalogModelTransform (com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform)1 ConnectorPluginDescriptor (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)1 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)1 DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)1