Search in sources :

Example 1 with TemplateProcessorDatasourceDefinition

use of com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition 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) 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) 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) 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) 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) 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)

Example 2 with TemplateProcessorDatasourceDefinition

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

the class DerivedDatasourceFactory method ensureDatasource.

public Datasource.ID ensureDatasource(TemplateProcessorDatasourceDefinition definition, FeedMetadata feedMetadata, List<NifiProperty> allProperties) {
    return metadataAccess.commit(() -> {
        List<NifiProperty> propertiesToEvalulate = new ArrayList<NifiProperty>();
        // fetch the def
        DatasourceDefinition datasourceDefinition = datasourceDefinitionProvider.findByProcessorType(definition.getProcessorType());
        if (datasourceDefinition != null) {
            // find out if there are any saved properties on the Feed that match the datasourceDef
            List<NifiProperty> feedProperties = feedMetadata.getProperties().stream().filter(property -> matchesDefinition(definition, property) && datasourceDefinition.getDatasourcePropertyKeys().contains(property.getKey())).collect(Collectors.toList());
            // resolve any ${metadata.} properties
            List<NifiProperty> resolvedFeedProperties = propertyExpressionResolver.resolvePropertyExpressions(feedProperties, feedMetadata);
            List<NifiProperty> resolvedAllProperties = propertyExpressionResolver.resolvePropertyExpressions(allProperties, feedMetadata);
            // propetyHash
            propertiesToEvalulate.addAll(feedProperties);
            propertiesToEvalulate.addAll(allProperties);
            propertyExpressionResolver.resolveStaticProperties(propertiesToEvalulate);
            String identityString = datasourceDefinition.getIdentityString();
            String desc = datasourceDefinition.getDescription();
            String title = datasourceDefinition.getTitle();
            PropertyExpressionResolver.ResolvedVariables identityStringPropertyResolution = propertyExpressionResolver.resolveVariables(identityString, propertiesToEvalulate);
            identityString = identityStringPropertyResolution.getResolvedString();
            PropertyExpressionResolver.ResolvedVariables titlePropertyResolution = propertyExpressionResolver.resolveVariables(title, propertiesToEvalulate);
            title = titlePropertyResolution.getResolvedString();
            if (desc != null) {
                PropertyExpressionResolver.ResolvedVariables descriptionPropertyResolution = propertyExpressionResolver.resolveVariables(desc, propertiesToEvalulate);
                desc = descriptionPropertyResolution.getResolvedString();
            }
            // if the identityString still contains unresolved variables then make the title readable and replace the idstring with the feed.id
            if (propertyExpressionResolver.containsVariablesPatterns(identityString)) {
                title = propertyExpressionResolver.replaceAll(title, " {runtime variable} ");
                identityString = propertyExpressionResolver.replaceAll(identityString, feedMetadata.getId());
            }
            // if it is the Source ensure the feed matches this ds
            if (isCreateDatasource(datasourceDefinition, feedMetadata)) {
                Map<String, String> controllerServiceProperties = parseControllerServiceProperties(datasourceDefinition, feedProperties);
                Map<String, Object> properties = new HashMap<String, Object>(identityStringPropertyResolution.getResolvedVariables());
                properties.putAll(controllerServiceProperties);
                DerivedDatasource derivedDatasource = datasourceProvider.ensureDerivedDatasource(datasourceDefinition.getDatasourceType(), identityString, title, desc, properties);
                if (derivedDatasource != null) {
                    if ("HiveDatasource".equals(derivedDatasource.getDatasourceType()) && Optional.ofNullable(feedMetadata.getTable()).map(TableSetup::getTableSchema).map(TableSchema::getFields).isPresent()) {
                        derivedDatasource.setGenericProperties(Collections.singletonMap("columns", (Serializable) feedMetadata.getTable().getTableSchema().getFields()));
                    }
                    return derivedDatasource.getId();
                }
            }
            return null;
        } else {
            return null;
        }
    }, MetadataAccess.SERVICE);
}
Also used : FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) DatasourceDefinitionProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceDefinitionProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DatasourceDefinition(com.thinkbiganalytics.metadata.api.datasource.DatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) Map(java.util.Map) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Nonnull(javax.annotation.Nonnull) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) Datasource(com.thinkbiganalytics.metadata.api.datasource.Datasource) Logger(org.slf4j.Logger) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) NifiControllerServiceProperties(com.thinkbiganalytics.feedmgr.nifi.NifiControllerServiceProperties) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) List(java.util.List) Stream(java.util.stream.Stream) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) Optional(java.util.Optional) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) Collections(java.util.Collections) Serializable(java.io.Serializable) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) DatasourceDefinition(com.thinkbiganalytics.metadata.api.datasource.DatasourceDefinition) TemplateProcessorDatasourceDefinition(com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty)

Aggregations

RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)2 TemplateProcessorDatasourceDefinition (com.thinkbiganalytics.feedmgr.rest.model.TemplateProcessorDatasourceDefinition)2 FeedManagerTemplateService (com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService)2 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Predicate (com.google.common.base.Predicate)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 TableSchema (com.thinkbiganalytics.discovery.schema.TableSchema)1