Search in sources :

Example 61 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiProcessGroup method validateInputProcessor.

public void validateInputProcessor() {
    if (this.errors == null) {
        errors = new ArrayList<>();
    }
    if (processGroupEntity == null) {
        processGroupEntity = new ProcessGroupDTO();
        processGroupEntity.setName("Process Group");
        if (inputProcessor != null) {
            processGroupEntity.setId(inputProcessor.getParentGroupId());
        }
    }
    if (this.inputProcessor != null && this.processGroupEntity != null) {
        NiFiComponentErrors error = NifiProcessorValidationUtil.getProcessorValidationErrors(this.inputProcessor, false);
        if (error != null && !error.getValidationErrors().isEmpty()) {
            if (!isErrorAlreadyRecorded(error)) {
                errors.add(error);
            }
        }
    }
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 62 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class TestFlowBuilder method processGroupDTO.

private ProcessGroupDTO processGroupDTO() {
    ProcessGroupDTO groupDTO = new ProcessGroupDTO();
    groupDTO.setName("Group " + groupCounter.incrementAndGet());
    groupDTO.setId(UUID.randomUUID().toString());
    return groupDTO;
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 63 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiFlowBuilder method build.

/**
 * Build the {@link NifiFlowProcessGroup} from the visited {@link NifiVisitableProcessGroup} returning the simplified graph of objects that make up the flow
 *
 * @param group the visited process group and its flow connecting processors together
 * @return the simplified graph representing the flow starting with the supplied visited process group
 */
public NifiFlowProcessGroup build(NifiVisitableProcessGroup group) {
    NifiFlowProcessGroup flowProcessGroup = toFlowProcessGroup(group);
    flowProcessGroup.setProcessorMap(cache);
    flowProcessGroup.addConnections(group.getConnections());
    ProcessGroupDTO groupDTO = group.getParentProcessGroup();
    if (groupDTO != null) {
        flowProcessGroup.setParentGroupId(groupDTO.getId());
        flowProcessGroup.setParentGroupName(groupDTO.getName());
    }
    flowProcessGroup.assignFlowIds();
    return flowProcessGroup;
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 64 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class TemplateCreationHelper method createTemporaryTemplateFlow.

/**
 * Creates an instance of the supplied template under the temporary inspection group inside its own process group
 *
 * @param templateId the template to instantiate
 * @return the process group holding this template
 */
public ProcessGroupDTO createTemporaryTemplateFlow(@Nonnull final String templateId) {
    ProcessGroupDTO temporaryTemplateInspectionGroup = nifiObjectCache.getOrCreateTemporaryTemplateInspectionGroup();
    // next create the temp group
    snapshotControllerServiceReferences();
    ProcessGroupDTO tempGroup = null;
    try {
        tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
    } catch (NifiComponentNotFoundException e) {
        nifiObjectCache.resetTemporaryTemplateInspectionGroup();
        tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
    }
    TemplateInstance instance = instantiateFlowFromTemplate(tempGroup.getId(), templateId);
    FlowSnippetDTO snippet = instance.getFlowSnippetDTO();
    identifyNewlyCreatedControllerServiceReferences(instance);
    tempGroup.setContents(snippet);
    // now delete it
    nifiRestClient.processGroups().delete(tempGroup);
    cleanupControllerServices();
    return tempGroup;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 65 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class TemplateInstanceCreator method createTemplate.

public NifiProcessGroup createTemplate() throws TemplateCreationException {
    try {
        NifiProcessGroup newProcessGroup = null;
        TemplateDTO template = restClient.getTemplateById(templateId);
        VersionedProcessGroup versionedProcessGroup = null;
        if (template != null) {
            TemplateCreationHelper templateCreationHelper = new TemplateCreationHelper(this.restClient);
            templateCreationHelper.setTemplateProperties(templateProperties);
            String processGroupId = null;
            ProcessGroupDTO group = null;
            if (isCreateReusableFlow()) {
                log.info("Creating a new Reusable flow instance for template: {} ", template.getName());
                // 1 get/create the parent "reusable_templates" processgroup
                ProcessGroupDTO reusableParentGroup = restClient.getProcessGroupByName("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
                if (reusableParentGroup == null) {
                    reusableParentGroup = restClient.createProcessGroup("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
                }
                ProcessGroupDTO thisGroup = restClient.getProcessGroupByName(reusableParentGroup.getId(), template.getName());
                if (thisGroup != null) {
                    // version the group
                    log.info("A previous Process group of with this name {} was found.  Versioning it before continuing", thisGroup.getName());
                    versionedProcessGroup = templateCreationHelper.versionProcessGroup(thisGroup, this.getVersionIdentifier());
                }
                group = restClient.createProcessGroup(reusableParentGroup.getId(), template.getName());
            } else {
                String tmpName = template.getName() + "_" + System.currentTimeMillis();
                group = restClient.createProcessGroup(tmpName);
                log.info("Creating a temporary process group with name {} for template {} ", tmpName, template.getName());
            }
            processGroupId = group.getId();
            if (StringUtils.isNotBlank(processGroupId)) {
                // snapshot the existing controller services
                templateCreationHelper.snapshotControllerServiceReferences();
                log.info("Successfully Snapshot of controller services");
                // create the flow from the template
                TemplateInstance instance = templateCreationHelper.instantiateFlowFromTemplate(processGroupId, templateId);
                FlowSnippetDTO flowSnippetDTO = instance.getFlowSnippetDTO();
                log.info("Successfully created the temp flow");
                if (this.createReusableFlow) {
                    ensureInputPortsForReuseableTemplate(processGroupId);
                    log.info("Reusable flow, input ports created successfully.");
                }
                // mark the new services that were created as a result of creating the new flow from the template
                templateCreationHelper.identifyNewlyCreatedControllerServiceReferences(instance);
                ProcessGroupDTO entity = restClient.getProcessGroup(processGroupId, true, true);
                // replace static properties and inject values into the flow
                List<NifiProperty> processorProperties = NifiPropertyUtil.getProperties(entity, restClient.getPropertyDescriptorTransform());
                if (processorProperties != null) {
                    boolean didReplace = false;
                    for (NifiProperty property : processorProperties) {
                        boolean replaced = ConfigurationPropertyReplacer.resolveStaticConfigurationProperty(property, staticConfigPropertyMap);
                        if (replaced) {
                            // update the properties that are replaced
                            if (property.getPropertyDescriptor() != null && StringUtils.isNotBlank(property.getPropertyDescriptor().getIdentifiesControllerService())) {
                                // verify the property is a valid cs property
                                String value = property.getValue();
                                if (templateCreationHelper.getEnabledServiceNameMap().containsKey(value)) {
                                    property.setValue(templateCreationHelper.getEnabledServiceNameMap().get(value).get(0).getId());
                                }
                            }
                            restClient.updateProcessorProperty(property.getProcessGroupId(), property.getProcessorId(), property);
                            didReplace = true;
                        }
                    }
                    // if we replaced any properties, refetch to get the latest data
                    if (didReplace) {
                        entity = restClient.getProcessGroup(processGroupId, true, true);
                    }
                }
                // identify the various processors (first level initial processors)
                List<ProcessorDTO> inputProcessors = NifiProcessUtil.getInputProcessors(entity);
                ProcessorDTO input = null;
                List<ProcessorDTO> nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                // if the input is null attempt to get the first input available on the template
                if (input == null && inputProcessors != null && !inputProcessors.isEmpty()) {
                    input = inputProcessors.get(0);
                }
                log.info("Attempt to update/validate controller services for template.");
                // update any references to the controller services and try to assign the value to an enabled service if it is not already
                boolean updatedControllerServices = false;
                if (input != null) {
                    log.info("attempt to update controllerservices on {} input processor ", input.getName());
                    List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(Lists.newArrayList(inputProcessors), staticConfigPropertyStringMap, instance);
                    updatedControllerServices = !updatedProperties.isEmpty();
                }
                log.info("attempt to update controllerservices on {} processors ", (nonInputProcessors != null ? nonInputProcessors.size() : 0));
                List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(nonInputProcessors, staticConfigPropertyStringMap, instance);
                if (!updatedControllerServices) {
                    updatedControllerServices = !updatedProperties.isEmpty();
                }
                log.info("Controller service validation complete");
                // refetch processors for updated errors
                entity = restClient.getProcessGroup(processGroupId, true, true);
                nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                inputProcessors = NifiProcessUtil.getInputProcessors(entity);
                if (inputProcessors != null && !inputProcessors.isEmpty()) {
                    input = inputProcessors.get(0);
                }
                // /make the input/output ports in the category group as running
                if (isCreateReusableFlow()) {
                    log.info("Reusable flow, attempt to mark the connection ports as running.");
                    templateCreationHelper.startProcessGroupAndParentInputPorts(entity);
                    // templateCreationHelper.markConnectionPortsAsRunning(entity);
                    log.info("Reusable flow.  Successfully marked the ports as running.");
                }
                newProcessGroup = new NifiProcessGroup(entity, input, nonInputProcessors);
                newProcessGroup.setVersionedProcessGroup(versionedProcessGroup);
                newProcessGroup.setReusableFlowInstance(isCreateReusableFlow());
                if (isCreateReusableFlow()) {
                    // call listeners notify of before mark as running  processing
                    if (creationCallback != null) {
                        try {
                            creationCallback.beforeMarkAsRunning(template.getName(), entity);
                        } catch (Exception e) {
                            log.error("Error calling callback beforeMarkAsRunning ", e);
                        }
                    }
                    log.info("Reusable flow, attempt to mark the Processors as running.");
                    templateCreationHelper.markProcessorsAsRunning(newProcessGroup);
                    log.info("Reusable flow.  Successfully marked the Processors as running.");
                    // align items
                    AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(restClient.getNiFiRestClient(), entity.getParentGroupId());
                    alignProcessGroupComponents.autoLayout();
                }
                templateCreationHelper.cleanupControllerServices();
                log.info("Controller service cleanup complete");
                List<NifiError> errors = templateCreationHelper.getErrors();
                // add any global errors to the object
                if (errors != null && !errors.isEmpty()) {
                    for (NifiError error : errors) {
                        newProcessGroup.addError(error);
                    }
                }
                newProcessGroup.setSuccess(!newProcessGroup.hasFatalErrors());
                if (!newProcessGroup.isSuccess()) {
                    log.info("Errors while importing the template. {} errors found. {}", (errors != null ? errors.size() : 0), (errors != null ? " - " + StringUtils.join(errors, ",") : ""));
                } else {
                    log.info("Success.  Finished importing template ");
                }
                return newProcessGroup;
            }
        }
    } catch (final Exception e) {
        if (log.isDebugEnabled() && e instanceof WebApplicationException) {
            final Response response = ((WebApplicationException) e).getResponse();
            log.debug("NiFi server returned error: {}", response.readEntity(String.class), e);
        }
        throw new TemplateCreationException("Unable to create the template for the Id of [" + templateId + "]. " + e.getMessage(), e);
    }
    return null;
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) WebApplicationException(javax.ws.rs.WebApplicationException) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) WebApplicationException(javax.ws.rs.WebApplicationException) Response(javax.ws.rs.core.Response) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) AlignProcessGroupComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Aggregations

ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)96 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)35 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)32 ArrayList (java.util.ArrayList)29 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)29 PortDTO (org.apache.nifi.web.api.dto.PortDTO)27 HashSet (java.util.HashSet)25 HashMap (java.util.HashMap)20 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)18 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)18 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)16 List (java.util.List)16 Set (java.util.Set)16 Collectors (java.util.stream.Collectors)15 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)15 Map (java.util.Map)14 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)13 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13