use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project kylo by Teradata.
the class DBCPConnectionPoolService method executeQueryForDatasource.
/**
* Executes the specified SELECT query in the context of the specified data source.
*
* @param datasource the JDBC datasource
* @param query the query to execute
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the datasource is invalid
*/
@Nonnull
public QueryResult executeQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String query) {
final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
if (controllerService.isPresent()) {
final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get());
final ExecuteQueryControllerServiceRequest serviceProperties = builder.password(datasource.getPassword()).query(query).useEnvironmentProperties(false).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
return executeQueryForControllerService(dataSourceProperties, serviceProperties);
} else {
log.error("Cannot execute query for datasource: {}", datasource);
throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
}
}
use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project kylo by Teradata.
the class DBCPConnectionPoolService method executeQueryForControllerService.
/**
* Executes the specified SELECT query in the context of the specified controller service.
*
* @param serviceId a NiFi controller service id
* @param serviceName a NiFi controller service name
* @param query the query to execute
* @return the query results
* @throws DataAccessException if the query cannot be executed
* @throws IllegalArgumentException if the controller service cannot be found
*/
@Nonnull
public QueryResult executeQueryForControllerService(@Nonnull final String serviceId, @Nonnull final String serviceName, @Nonnull final String query) {
final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
if (controllerService != null) {
final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService);
final ExecuteQueryControllerServiceRequest serviceProperties = builder.query(query).build();
final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
return executeQueryForControllerService(dataSourceProperties, serviceProperties);
} else {
log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
}
}
use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project kylo by Teradata.
the class DBCPConnectionPoolService method describeTableForControllerService.
/**
* Describe the database table and fields available for a given NiFi controller service
*
* @param serviceId a NiFi controller service id
* @param serviceName a NiFi controller service name
* @param schema A schema to look for
* @param tableName A table to look for
* @return the database table and fields
*/
public TableSchema describeTableForControllerService(String serviceId, String serviceName, String schema, String tableName) {
ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
if (controllerService != null) {
DescribeTableControllerServiceRequestBuilder builder = new DescribeTableControllerServiceRequestBuilder(controllerService);
DescribeTableControllerServiceRequest serviceProperties = builder.schemaName(schema).tableName(tableName).build();
return describeTableForControllerService(serviceProperties);
} else {
log.error("Cannot describe Table for Controller Service. Unable to obtain Controller Service for serviceId or Name ({} , {})", serviceId, serviceName);
}
return null;
}
use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project kylo by Teradata.
the class NifiIntegrationRestController method getControllerServiceReferencesMap.
@GET
@Path("/controller-services/{serviceId}/references")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a controller service references in a map by component type. (i.e. Processor -> list, Controller Service -> list ...)", notes = "returns a map of the type and reference objects")
@ApiResponses({ @ApiResponse(code = 200, message = "returns a map of the type and reference objects", response = ControllerServiceDTO.class), @ApiResponse(code = 500, message = "Unable to find the controller service", response = RestResponseStatus.class) })
public Response getControllerServiceReferencesMap(@PathParam("serviceId") String serviceId) {
Map<String, List<ControllerServiceReferencingComponentDTO>> map = null;
try {
final ControllerServiceDTO controllerService = legacyNifiRestClient.getControllerService(null, serviceId);
if (controllerService != null) {
Optional<ControllerServiceReferencingComponentsEntity> optional = legacyNifiRestClient.getNiFiRestClient().controllerServices().getReferences(serviceId);
if (optional.isPresent()) {
ControllerServiceReferencingComponentsEntity entity = optional.get();
map = getReferencingComponents(entity.getControllerServiceReferencingComponents()).values().stream().map(c -> c.getComponent()).collect(Collectors.groupingBy(x -> x.getReferenceType()));
} else {
map = Collections.emptyMap();
}
}
return Response.ok(map).build();
} catch (Exception e) {
RestResponseStatus error = new RestResponseStatus.ResponseStatusBuilder().message("Unable to find controller service references for " + serviceId).buildError();
return Response.ok(error).build();
}
}
use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project kylo by Teradata.
the class AbstractNiFiControllerServicesRestClientTest method updateStateByIdWithTimeout.
/**
* Verify exception when updating the state of a controller service times out.
*/
@Test(expected = NifiClientRuntimeException.class)
public void updateStateByIdWithTimeout() {
// Mock NiFi REST client
final NiFiRestClient nifiClient = Mockito.mock(NiFiRestClient.class);
Mockito.when(nifiClient.getBulletins("MYID")).thenReturn(Collections.emptyList());
// Mock controller services
final ControllerServiceDTO response = new ControllerServiceDTO();
response.setState("ENABLING");
// Mock NiFi Controller Service REST client
final AbstractNiFiControllerServicesRestClient client = Mockito.mock(AbstractNiFiControllerServicesRestClient.class, Mockito.CALLS_REAL_METHODS);
Mockito.when(client.update(Mockito.any())).thenReturn(response);
Mockito.when(client.findById(Mockito.anyString())).thenReturn(Optional.of(response));
Mockito.when(client.getClient()).thenReturn(nifiClient);
// Test updating state
client.updateStateByIdWithRetries("MYID", "ENABLED", 1, 0, TimeUnit.NANOSECONDS);
}
Aggregations