Java Code Examples for org.apache.nifi.groups.ProcessGroup#getTemplate()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#getTemplate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void addLocalTemplates(final Element processGroupElement, final ProcessGroup processGroup, final FlowEncodingVersion encodingVersion) {
    // Replace the templates with those from the proposed flow
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    if (templateNodeList != null) {
        for (final Element templateElement : templateNodeList) {
            final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
            final Template template = new Template(templateDto);

            // If the Process Group does not have the template, add it.
            if (processGroup.getTemplate(template.getIdentifier()) == null) {
                processGroup.addTemplate(template);
            }
        }
    }

    final List<Element> childGroupElements = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element childGroupElement : childGroupElements) {
        final String childGroupId = getString(childGroupElement, "id");
        final ProcessGroup childGroup = processGroup.getProcessGroup(childGroupId);
        addLocalTemplates(childGroupElement, childGroup, encodingVersion);
    }
}
 
Example 2
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void addLocalTemplates(final Element processGroupElement, final ProcessGroup processGroup) {
    // Replace the templates with those from the proposed flow
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    if (templateNodeList != null) {
        for (final Element templateElement : templateNodeList) {
            final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
            final Template template = new Template(templateDto);

            // If the Process Group does not have the template, add it.
            if (processGroup.getTemplate(template.getIdentifier()) == null) {
                processGroup.addTemplate(template);
            }
        }
    }

    final List<Element> childGroupElements = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element childGroupElement : childGroupElements) {
        final String childGroupId = getString(childGroupElement, "id");
        final ProcessGroup childGroup = processGroup.getProcessGroup(childGroupId);
        addLocalTemplates(childGroupElement, childGroup);
    }
}
 
Example 3
Source File: StandardFlowService.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void loadFromBytes(final DataFlow proposedFlow, final boolean allowEmptyFlow)
        throws IOException, FlowSerializationException, FlowSynchronizationException, UninheritableFlowException {
    logger.trace("Loading flow from bytes");

    // resolve the given flow (null means load flow from disk)
    final DataFlow actualProposedFlow;
    final byte[] flowBytes;
    final byte[] authorizerFingerprint;
    if (proposedFlow == null) {
        final ByteArrayOutputStream flowOnDisk = new ByteArrayOutputStream();
        copyCurrentFlow(flowOnDisk);
        flowBytes = flowOnDisk.toByteArray();
        authorizerFingerprint = getAuthorizerFingerprint();
        logger.debug("Loaded Flow from bytes");
    } else {
        flowBytes = proposedFlow.getFlow();
        authorizerFingerprint = proposedFlow.getAuthorizerFingerprint();
        logger.debug("Loaded flow from proposed flow");
    }

    actualProposedFlow = new StandardDataFlow(flowBytes, null, authorizerFingerprint);

    if (firstControllerInitialization) {
        // load the controller services
        logger.debug("Loading controller services");
    }

    // load the flow
    logger.debug("Loading proposed flow into FlowController");
    dao.load(controller, actualProposedFlow);

    final ProcessGroup rootGroup = controller.getGroup(controller.getRootGroupId());
    if (rootGroup.isEmpty() && !allowEmptyFlow) {
        throw new FlowSynchronizationException("Failed to load flow because unable to connect to cluster and local flow is empty");
    }

    final List<Template> templates = loadTemplates();
    for (final Template template : templates) {
        final Template existing = rootGroup.getTemplate(template.getIdentifier());
        if (existing == null) {
            logger.info("Imported Template '{}' to Root Group", template.getDetails().getName());
            rootGroup.addTemplate(template);
        } else {
            logger.info("Template '{}' was already present in Root Group so will not import from file", template.getDetails().getName());
        }
    }

    // lazy initialization of controller tasks and flow
    if (firstControllerInitialization) {
        logger.debug("First controller initialization. Loading reporting tasks and initializing controller.");

        // initialize the flow
        controller.initializeFlow();

        firstControllerInitialization = false;
    }
}
 
Example 4
Source File: StandardFlowService.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void loadFromBytes(final DataFlow proposedFlow, final boolean allowEmptyFlow)
        throws IOException, FlowSerializationException, FlowSynchronizationException, UninheritableFlowException, MissingBundleException {
    logger.trace("Loading flow from bytes");

    // resolve the given flow (null means load flow from disk)
    final DataFlow actualProposedFlow;
    final byte[] flowBytes;
    final byte[] authorizerFingerprint;
    final Set<String> missingComponents;

    if (proposedFlow == null) {
        final ByteArrayOutputStream flowOnDisk = new ByteArrayOutputStream();
        copyCurrentFlow(flowOnDisk);
        flowBytes = flowOnDisk.toByteArray();
        authorizerFingerprint = getAuthorizerFingerprint();
        missingComponents = new HashSet<>();
        logger.debug("Loaded Flow from bytes");
    } else {
        flowBytes = proposedFlow.getFlow();
        authorizerFingerprint = proposedFlow.getAuthorizerFingerprint();
        missingComponents = proposedFlow.getMissingComponents();
        logger.debug("Loaded flow from proposed flow");
    }

    actualProposedFlow = new StandardDataFlow(flowBytes, null, authorizerFingerprint, missingComponents);

    // load the flow
    logger.debug("Loading proposed flow into FlowController");
    dao.load(controller, actualProposedFlow, this);

    final ProcessGroup rootGroup = controller.getFlowManager().getRootGroup();
    if (rootGroup.isEmpty() && !allowEmptyFlow) {
        throw new FlowSynchronizationException("Failed to load flow because unable to connect to cluster and local flow is empty");
    }



    final List<Template> templates = loadTemplates();
    for (final Template template : templates) {
        final Template existing = rootGroup.getTemplate(template.getIdentifier());
        if (existing == null) {
            logger.info("Imported Template '{}' to Root Group", template.getDetails().getName());
            rootGroup.addTemplate(template);
        } else {
            logger.info("Template '{}' was already present in Root Group so will not import from file", template.getDetails().getName());
        }
    }
}