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());
}
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);
}
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));
}
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));
}
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));
}
Aggregations