Java Code Examples for org.apache.nifi.controller.FlowController#serialize()

The following examples show how to use org.apache.nifi.controller.FlowController#serialize() . 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: StandardXMLFlowConfigurationDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void save(final FlowController flow, final OutputStream os) throws IOException {
    try {
        final StandardFlowSerializer xmlTransformer = new StandardFlowSerializer(encryptor);
        flow.serialize(xmlTransformer, os);
    } catch (final FlowSerializationException fse) {
        throw new IOException(fse);
    }
}
 
Example 2
Source File: StandardXMLFlowConfigurationDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void save(final FlowController controller, final boolean archive) throws IOException {
    if (null == controller) {
        throw new NullPointerException();
    }

    Path tempFile;
    Path configFile;

    configFile = flowXmlPath;
    tempFile = configFile.getParent().resolve(configFile.toFile().getName() + ".new.xml.gz");

    try (final OutputStream fileOut = Files.newOutputStream(tempFile);
            final OutputStream outStream = new GZIPOutputStream(fileOut)) {

        final StandardFlowSerializer xmlTransformer = new StandardFlowSerializer(encryptor);
        controller.serialize(xmlTransformer, outStream);

        Files.deleteIfExists(configFile);
        FileUtils.renameFile(tempFile.toFile(), configFile.toFile(), 5, true);
    } catch (final FlowSerializationException fse) {
        throw new IOException(fse);
    } finally {
        Files.deleteIfExists(tempFile);
    }

    if (archive) {
        try {
            archiveManager.archive();
        } catch (final Exception ex) {
            LOG.error("Unable to archive flow configuration as requested due to " + ex);
            if (LOG.isDebugEnabled()) {
                LOG.error("", ex);
            }
        }
    }
}
 
Example 3
Source File: StandardXMLFlowConfigurationDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void save(final FlowController flow, final OutputStream os) throws IOException {
    try {
        final StandardFlowSerializer xmlTransformer = new StandardFlowSerializer(encryptor);
        flow.serialize(xmlTransformer, os);
    } catch (final FlowSerializationException fse) {
        throw new IOException(fse);
    }
}
 
Example 4
Source File: StandardXMLFlowConfigurationDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void save(final FlowController controller, final boolean archive) throws IOException {
    if (null == controller) {
        throw new NullPointerException();
    }

    Path tempFile;
    Path configFile;

    configFile = flowXmlPath;
    tempFile = configFile.getParent().resolve(configFile.toFile().getName() + ".new.xml.gz");

    try (final OutputStream fileOut = Files.newOutputStream(tempFile);
            final OutputStream outStream = new GZIPOutputStream(fileOut)) {

        final StandardFlowSerializer xmlTransformer = new StandardFlowSerializer(encryptor);
        controller.serialize(xmlTransformer, outStream);

        Files.deleteIfExists(configFile);
        FileUtils.renameFile(tempFile.toFile(), configFile.toFile(), 5, true);
    } catch (final FlowSerializationException fse) {
        throw new IOException(fse);
    } finally {
        Files.deleteIfExists(tempFile);
    }

    if (archive) {
        try {
            archiveManager.archive();
        } catch (final Exception ex) {
            LOG.error("Unable to archive flow configuration as requested due to " + ex);
            if (LOG.isDebugEnabled()) {
                LOG.error("", ex);
            }
        }
    }
}