Search in sources :

Example 1 with RestResponseStatus

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

the class FeedRestController method startFeed.

@POST
@Path("/start/{feedId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Starts a feed.")
@ApiResponses({ @ApiResponse(code = 200, message = "The feed was started.", response = FeedSummary.class), @ApiResponse(code = 500, message = "The feed could not be started.", response = RestResponseStatus.class) })
public Response startFeed(@PathParam("feedId") String feedId) {
    try {
        FeedSummary feed = getMetadataService().startFeed(feedId);
        RestResponseStatus.ResponseStatusBuilder builder = new RestResponseStatus.ResponseStatusBuilder();
        RestResponseStatus status = null;
        if (feed != null) {
            status = builder.message("Feed " + feed.getCategoryAndFeedDisplayName() + " started successfully").buildSuccess();
        } else {
            status = builder.message("Error starting feed for id " + feedId).buildError();
        }
        return Response.ok(status).build();
    } catch (Exception e) {
        log.error("Exception starting the feed ", e);
        throw new InternalServerErrorException("Unexpected exception starting the feed " + feedId + " " + e.getMessage());
    }
}
Also used : InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) FeedCleanupTimeoutException(com.thinkbiganalytics.feedmgr.service.FeedCleanupTimeoutException) FeedCleanupFailedException(com.thinkbiganalytics.feedmgr.service.FeedCleanupFailedException) WebApplicationException(javax.ws.rs.WebApplicationException) AccessDeniedException(java.nio.file.AccessDeniedException) DeployFeedException(com.thinkbiganalytics.feedmgr.service.feed.DeployFeedException) DuplicateFeedNameException(com.thinkbiganalytics.feedmgr.service.feed.DuplicateFeedNameException) IOException(java.io.IOException) FeedCurrentlyRunningException(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedCurrentlyRunningException) ClientErrorException(javax.ws.rs.ClientErrorException) JDBCException(org.hibernate.JDBCException) FeedHistoryDataReindexingNotEnabledException(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedHistoryDataReindexingNotEnabledException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) AccessControlException(java.security.AccessControlException) DataAccessException(org.springframework.dao.DataAccessException) VersionNotFoundException(com.thinkbiganalytics.metadata.api.versioning.VersionNotFoundException) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) NifiConnectionException(com.thinkbiganalytics.nifi.rest.client.NifiConnectionException) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with RestResponseStatus

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

the class NifiIntegrationRestController method autoAlign.

@GET
@Path("/auto-align/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Organizes the components of the specified process group.")
@ApiResponses(@ApiResponse(code = 200, message = "The result of the operation.", response = RestResponseStatus.class))
public Response autoAlign(@PathParam("processGroupId") String processGroupId) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
    RestResponseStatus status;
    if ("all".equals(processGroupId)) {
        AlignNiFiComponents alignNiFiComponents = new AlignNiFiComponents();
        alignNiFiComponents.setNiFiRestClient(legacyNifiRestClient.getNiFiRestClient());
        alignNiFiComponents.autoLayout();
        String message = "";
        if (alignNiFiComponents.isAligned()) {
            message = "Aligned All of NiFi.  " + alignNiFiComponents.getAlignedProcessGroups() + " process groups were aligned ";
        } else {
            message = "Alignment failed while attempting to align all of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " were successfully aligned. Please look at the logs for more information";
        }
        status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
    } else {
        AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(legacyNifiRestClient.getNiFiRestClient(), processGroupId);
        ProcessGroupDTO alignedGroup = alignProcessGroupComponents.autoLayout();
        String message = "";
        if (alignProcessGroupComponents.isAligned()) {
            message = "Aligned " + alignedGroup.getContents().getProcessGroups().size() + " process groups under " + alignedGroup.getName();
        } else {
            message = "Alignment failed for process group " + processGroupId + ". Please look at the logs for more information";
        }
        status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
    }
    return Response.ok(status).build();
}
Also used : AlignNiFiComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignNiFiComponents) AlignProcessGroupComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) 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 3 with RestResponseStatus

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

the class NifiIntegrationRestController method cleanupVersionedProcessGroups.

@GET
@Path("/cleanup-versions/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Performs a cleanup of the specified process group.", notes = "This method will list all of the child process groups and delete the ones where the name matches the regular expression: .* - \\d{13}")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the number of process groups deleted.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "The process group is unavailable.", response = RestResponseStatus.class) })
public Response cleanupVersionedProcessGroups(@PathParam("processGroupId") String processGroupId) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
    RestResponseStatus status;
    CleanupStaleFeedRevisions cleanupStaleFeedRevisions = new CleanupStaleFeedRevisions(legacyNifiRestClient, processGroupId, propertyDescriptorTransform);
    cleanupStaleFeedRevisions.cleanup();
    String msg = "Cleaned up " + cleanupStaleFeedRevisions.getDeletedProcessGroups().size() + " Process Groups";
    status = new RestResponseStatus.ResponseStatusBuilder().message(msg).buildSuccess();
    return Response.ok(status).build();
}
Also used : CleanupStaleFeedRevisions(com.thinkbiganalytics.feedmgr.nifi.CleanupStaleFeedRevisions) 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 4 with RestResponseStatus

use of com.thinkbiganalytics.rest.model.RestResponseStatus 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) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) DataAccessException(org.springframework.dao.DataAccessException) SQLException(java.sql.SQLException) InvalidControllerServiceLookupException(com.thinkbiganalytics.feedmgr.nifi.controllerservice.InvalidControllerServiceLookupException) 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 5 with RestResponseStatus

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

the class DataSourceController method createJdbcTableDataSet.

/**
 * Gets the schema of the specified table using the specified data source.
 *
 * @param dataSourceId the data source id
 * @param tableName    the table name
 * @param schema       the schema name, or {@code null} to search all schemas
 * @return the table and field details
 */
@POST
@Path("{id}/tables/{tableName}/dataset")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the schema of the specified table.", notes = "Connects to the database specified by the data source.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the table schema.", response = DataSetWithTableSchema.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "A JDBC data source with that id does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "NiFi or the database are unavailable.", response = RestResponseStatus.class) })
public Response createJdbcTableDataSet(@PathParam("id") final String dataSourceId, @PathParam("tableName") final String tableName, @QueryParam("schema") final String schema) {
    // TODO Verify user has access to data source
    // Require admin permission if the results should include unencrypted credentials.
    final boolean encryptCredentials = true;
    accessController.checkPermission(AccessController.SERVICES, encryptCredentials ? FeedServicesAccessControl.ACCESS_DATASOURCES : FeedServicesAccessControl.ADMIN_DATASOURCES);
    DataSetWithTableSchema dataSetWithTableSchema = null;
    boolean hasAccess = false;
    try {
        // ensure the user can read teh datasource
        DataSource encryptedSource = metadataService.read(() -> {
            return findDataSource(dataSourceId, true);
        });
        hasAccess = encryptedSource != null;
        if (hasAccess) {
            // fetch the datasource as a service account to get the creds.
            DataSource dataSource = metadataService.read(() -> {
                return findDataSource(dataSourceId, false);
            }, MetadataAccess.SERVICE);
            // describe the datasource and table
            CatalogTableSchema tableSchema = tableManager.describeTable(dataSource, schema, tableName);
            if (tableSchema != null) {
                DataSet dataSet = new DataSet();
                // assign the datasource to this dataset with encrypted credentials
                dataSet.setDataSource(encryptedSource);
                String fullTableName = (tableSchema.getTable() != null) ? tableSchema.getTable().getQualifiedIdentifier() : HiveUtils.quoteIdentifier(tableSchema.getSchemaName(), tableSchema.getName());
                dataSet.setTitle(tableSchema.getSchemaName() + "." + tableSchema.getName());
                DefaultDataSetTemplate defaultDataSetTemplate = DataSetUtil.mergeTemplates(dataSet);
                List<String> paths = defaultDataSetTemplate.getPaths();
                String format = defaultDataSetTemplate.getFormat();
                Map<String, String> options = defaultDataSetTemplate.getOptions();
                if (options == null) {
                    options = new HashMap<>();
                }
                if ("hive".equalsIgnoreCase(format.toLowerCase())) {
                    if (paths == null) {
                        paths = new ArrayList<>();
                    }
                    paths.add(fullTableName);
                }
                options.put("dbtable", fullTableName);
                dataSet.setFormat(format);
                dataSet.setPaths(paths);
                dataSet.setOptions(options);
                DataSet dataSet1 = dataSetService.findOrCreateDataSet(dataSet, encryptCredentials);
                dataSetWithTableSchema = new DataSetWithTableSchema(dataSet1, tableSchema);
            } else {
                if (log.isErrorEnabled()) {
                    log.error("Failed to describe tables for schema [" + schema + "], table [" + tableName + "], dataSource [" + dataSourceId + "] ");
                }
                final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.describeTable.error", tableName, schema)).url(request.getRequestURI()).buildError();
                throw new InternalServerErrorException(Response.serverError().entity(status).build());
            }
        // });
        } else {
            // no acceess
            final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.forbidden")).url(request.getRequestURI()).buildError();
            throw new InternalServerErrorException(Response.serverError().entity(status).build());
        }
    } catch (Exception e) {
        if (exceptionTransformer.causesInChain(e)) {
            throw new ThriftConnectionException(e);
        }
        final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.describeTable.error", tableName, schema)).url(request.getRequestURI()).buildError();
        throw new InternalServerErrorException(Response.serverError().entity(status).build());
    }
    return Response.ok(dataSetWithTableSchema).build();
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) TTransportException(org.apache.thrift.transport.TTransportException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) AccessDeniedException(java.nio.file.AccessDeniedException) SQLException(java.sql.SQLException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) PotentialControllerServiceConflictException(com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException) ForbiddenException(javax.ws.rs.ForbiddenException) DataSourceAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) DataSetWithTableSchema(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetWithTableSchema) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) CatalogTableSchema(com.thinkbiganalytics.discovery.model.CatalogTableSchema) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RestResponseStatus (com.thinkbiganalytics.rest.model.RestResponseStatus)11 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)6 NotFoundException (javax.ws.rs.NotFoundException)6 Path (javax.ws.rs.Path)6 AccessDeniedException (java.nio.file.AccessDeniedException)5 SQLException (java.sql.SQLException)5 BadRequestException (javax.ws.rs.BadRequestException)5 Produces (javax.ws.rs.Produces)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 ThriftConnectionException (com.thinkbiganalytics.hive.exceptions.ThriftConnectionException)4 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)4 PotentialControllerServiceConflictException (com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException)4 DataSourceAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException)4 ForbiddenException (javax.ws.rs.ForbiddenException)4 GET (javax.ws.rs.GET)4 TTransportException (org.apache.thrift.transport.TTransportException)4 Response (com.jayway.restassured.response.Response)3 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)2