Search in sources :

Example 1 with DatasourceDefinition

use of com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition in project kylo by Teradata.

the class TemplatesRestController method getNiFiTemplateFlowInfo.

/**
 * Returns data about the NiFiTemplate and its processors related to the input connections, along with the Datasources in the flow
 */
@POST
@Path("/nifi/{templateId}/flow-info")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the flow for the specified template.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the flow.", response = NiFiTemplateFlowResponse.class), @ApiResponse(code = 500, message = "NiFi is unavailable.", response = RestResponseStatus.class) })
public Response getNiFiTemplateFlowInfo(@PathParam("templateId") String templateId, NiFiTemplateFlowRequest flowRequest) {
    this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
    List<TemplateProcessorDatasourceDefinition> templateProcessorDatasourceDefinitions = new ArrayList<>();
    NiFiTemplateFlowResponse response = new NiFiTemplateFlowResponse();
    response.setRequest(flowRequest);
    if (StringUtils.isNotBlank(templateId)) {
        List<RegisteredTemplate.FlowProcessor> processors = feedManagerTemplateService.getNiFiTemplateFlowProcessors(templateId, flowRequest.getConnectionInfo());
        Set<DatasourceDefinition> defs = datasourceService.getDatasourceDefinitions();
        Map<String, DatasourceDefinition> datasourceDefinitionMap = new HashMap<>();
        if (defs != null) {
            defs.stream().forEach(def -> datasourceDefinitionMap.put(def.getProcessorType(), def));
        }
        templateProcessorDatasourceDefinitions = processors.stream().filter(processor -> datasourceDefinitionMap.containsKey(processor.getType())).map(p -> {
            TemplateProcessorDatasourceDefinition definition = new TemplateProcessorDatasourceDefinition();
            definition.setProcessorType(p.getType());
            definition.setProcessorName(p.getName());
            definition.setProcessorId(p.getId());
            definition.setDatasourceDefinition(datasourceDefinitionMap.get(p.getType()));
            return definition;
        }).collect(Collectors.toList());
        response.setProcessors(processors);
        response.setTemplateProcessorDatasourceDefinitions(templateProcessorDatasourceDefinitions);
    }
    return Response.ok(response).build();
}
Also used : Arrays(java.util.Arrays) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) ApiOperation(io.swagger.annotations.ApiOperation) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) ChangeType(com.thinkbiganalytics.security.rest.model.PermissionsChange.ChangeType) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) DELETE(javax.ws.rs.DELETE) MetadataService(com.thinkbiganalytics.feedmgr.service.MetadataService) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) ImmutableMap(com.google.common.collect.ImmutableMap) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Predicate(com.google.common.base.Predicate) TemplateOrder(com.thinkbiganalytics.feedmgr.rest.model.TemplateOrder) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) NiFiTemplateFlowRequest(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowRequest) Iterables(com.google.common.collect.Iterables) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Status(javax.ws.rs.core.Response.Status) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) DatasourceService(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) TemplateDtoWrapper(com.thinkbiganalytics.feedmgr.rest.model.TemplateDtoWrapper) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Cache(com.google.common.cache.Cache) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NiFiTemplateFlowResponse(com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Predicate (com.google.common.base.Predicate)1 Cache (com.google.common.cache.Cache)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)1 NiFiTemplateFlowRequest (com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowRequest)1 NiFiTemplateFlowResponse (com.thinkbiganalytics.feedmgr.rest.model.NiFiTemplateFlowResponse)1 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)1 RegisteredTemplateRequest (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest)1 TemplateDtoWrapper (com.thinkbiganalytics.feedmgr.rest.model.TemplateDtoWrapper)1 TemplateOrder (com.thinkbiganalytics.feedmgr.rest.model.TemplateOrder)1 TemplateProcessorDatasourceDefinition (com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 MetadataService (com.thinkbiganalytics.feedmgr.service.MetadataService)1 DatasourceService (com.thinkbiganalytics.feedmgr.service.datasource.DatasourceService)1 SecurityService (com.thinkbiganalytics.feedmgr.service.security.SecurityService)1 FeedManagerTemplateService (com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService)1 RegisteredTemplateService (com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService)1 DatasourceDefinition (com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition)1