Search in sources :

Example 31 with ControllerServiceDTO

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);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Example 32 with ControllerServiceDTO

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);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Example 33 with ControllerServiceDTO

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;
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) DescribeTableControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.DescribeTableControllerServiceRequest.DescribeTableControllerServiceRequestBuilder)

Example 34 with ControllerServiceDTO

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();
    }
}
Also used : ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) List(java.util.List) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) DataAccessException(org.springframework.dao.DataAccessException) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) 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)

Example 35 with ControllerServiceDTO

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);
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Test(org.junit.Test)

Aggregations

ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)60 HashSet (java.util.HashSet)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)17 List (java.util.List)16 Set (java.util.Set)16 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)15 Collectors (java.util.stream.Collectors)14 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)14 Collections (java.util.Collections)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)13 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 Optional (java.util.Optional)12 Nonnull (javax.annotation.Nonnull)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10