Search in sources :

Example 1 with StandardFlowSerializer

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

the class FingerprintFactoryTest method serializeElement.

private <T> Element serializeElement(final StringEncryptor encryptor, final Class<T> componentClass, final T component, final String serializerMethodName, ScheduledStateLookup scheduledStateLookup) throws Exception {
    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    final Document doc = docBuilder.newDocument();
    final FlowSerializer flowSerializer = new StandardFlowSerializer(encryptor);
    final Method serializeMethod = StandardFlowSerializer.class.getDeclaredMethod(serializerMethodName, Element.class, componentClass, ScheduledStateLookup.class);
    serializeMethod.setAccessible(true);
    final Element rootElement = doc.createElement("root");
    serializeMethod.invoke(flowSerializer, rootElement, component, scheduledStateLookup);
    return rootElement;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) Method(java.lang.reflect.Method) Document(org.w3c.dom.Document) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializer(org.apache.nifi.controller.serialization.FlowSerializer)

Example 2 with StandardFlowSerializer

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

the class StandardFlowServiceTest method testLoadExistingFlow.

@Test
public void testLoadExistingFlow() throws IOException {
    byte[] flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
    flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
    flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-inheritable.xml"));
    flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
    FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
    String expectedFlow = new String(flowBytes).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 3 with StandardFlowSerializer

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

the class StandardFlowServiceTest method testLoadExistingFlowWithCorruptFlow.

@Test
public void testLoadExistingFlowWithCorruptFlow() 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-corrupt.xml"));
        flowService.load(new StandardDataFlow(updatedBytes, null, null, new HashSet<>()));
        fail("should have thrown " + FlowSerializationException.class);
    } catch (FlowSerializationException 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) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) 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 4 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 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);
    }
}
Also used : StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) IOException(java.io.IOException)

Example 5 with StandardFlowSerializer

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

the class StandardFlowServiceTest method testLoadWithFlow.

@Test
public void testLoadWithFlow() throws IOException {
    byte[] flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
    flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
    FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
    String expectedFlow = new String(flowBytes).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)

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