Search in sources :

Example 6 with StandardFlowSerializer

use of org.apache.nifi.controller.serialization.StandardFlowSerializer in project nifi by apache.

the class StandardFlowServiceTest method testLoadExistingFlowWithUninheritableFlow.

@Test
public void testLoadExistingFlowWithUninheritableFlow() throws IOException {
    byte[] originalBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
    flowService.load(new StandardDataFlow(originalBytes, null, null, new HashSet<>()));
    try {
        byte[] updatedBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-uninheritable.xml"));
        flowService.load(new StandardDataFlow(updatedBytes, null, null, new HashSet<>()));
        fail("should have thrown " + UninheritableFlowException.class);
    } catch (UninheritableFlowException ufe) {
        FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
        String expectedFlow = new String(originalBytes).trim();
        String actualFlow = new String(baos.toByteArray()).trim();
        Assert.assertEquals(expectedFlow, actualFlow);
    }
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializer(org.apache.nifi.controller.serialization.FlowSerializer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with StandardFlowSerializer

use of org.apache.nifi.controller.serialization.StandardFlowSerializer in project nifi by apache.

the class StandardXMLFlowConfigurationDAO method save.

@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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) IOException(java.io.IOException) UninheritableFlowException(org.apache.nifi.controller.UninheritableFlowException) IOException(java.io.IOException) MissingBundleException(org.apache.nifi.controller.MissingBundleException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) FlowSynchronizationException(org.apache.nifi.controller.serialization.FlowSynchronizationException)

Example 8 with StandardFlowSerializer

use of org.apache.nifi.controller.serialization.StandardFlowSerializer in project nifi by apache.

the class StandardFlowSynchronizer method toBytes.

private byte[] toBytes(final FlowController flowController) throws FlowSerializationException {
    final ByteArrayOutputStream result = new ByteArrayOutputStream();
    final StandardFlowSerializer flowSerializer = new StandardFlowSerializer(encryptor);
    flowController.serialize(flowSerializer, result);
    return result.toByteArray();
}
Also used : StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

StandardFlowSerializer (org.apache.nifi.controller.serialization.StandardFlowSerializer)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FlowSerializer (org.apache.nifi.controller.serialization.FlowSerializer)5 HashSet (java.util.HashSet)4 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)4 Test (org.junit.Test)4 FlowSerializationException (org.apache.nifi.controller.serialization.FlowSerializationException)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 Path (java.nio.file.Path)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 MissingBundleException (org.apache.nifi.controller.MissingBundleException)1 UninheritableFlowException (org.apache.nifi.controller.UninheritableFlowException)1 FlowSynchronizationException (org.apache.nifi.controller.serialization.FlowSynchronizationException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1