Search in sources :

Example 31 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class VersionedProcessGroupSerializer method deserialize.

@Override
public VersionedProcessGroup deserialize(final InputStream input) throws SerializationException {
    final int headerLength = 9;
    final byte[] buffer = new byte[headerLength];
    int bytesRead = -1;
    try {
        bytesRead = input.read(buffer, 0, headerLength);
    } catch (final IOException e) {
        throw new SerializationException("Unable to read header while deserializing process group", e);
    }
    if (bytesRead < headerLength) {
        throw new SerializationException("Unable to read header while deserializing process group, expected" + headerLength + " bytes, but found " + bytesRead);
    }
    final ByteBuffer bb = ByteBuffer.wrap(buffer);
    final int version = bb.getInt(MAGIC_HEADER_BYTES.length);
    final Serializer<VersionedProcessGroup> serializer = serializersByVersion.get(Integer.valueOf(version));
    if (serializer == null) {
        throw new SerializationException("No process group serializer for version " + version);
    }
    return serializer.deserialize(input);
}
Also used : VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 32 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class VersionedProcessGroupSerializer method serialize.

@Override
public void serialize(final VersionedProcessGroup versionedProcessGroup, final OutputStream out) throws SerializationException {
    final ByteBuffer byteBuffer = ByteBuffer.allocate(9);
    byteBuffer.put(MAGIC_HEADER_BYTES);
    byteBuffer.putInt(CURRENT_VERSION);
    try {
        out.write(byteBuffer.array());
    } catch (final IOException e) {
        throw new SerializationException("Unable to write header while serializing process group", e);
    }
    final Serializer<VersionedProcessGroup> serializer = serializersByVersion.get(CURRENT_VERSION);
    if (serializer == null) {
        throw new SerializationException("No process group serializer for version " + CURRENT_VERSION);
    }
    serializer.serialize(versionedProcessGroup, out);
}
Also used : VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 33 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class TestVersionedProcessGroupSerializer method testSerializeDeserializeFlowSnapshot.

@Test
public void testSerializeDeserializeFlowSnapshot() throws SerializationException {
    final Serializer<VersionedProcessGroup> serializer = new VersionedProcessGroupSerializer();
    final VersionedProcessGroup processGroup1 = new VersionedProcessGroup();
    processGroup1.setIdentifier("pg1");
    processGroup1.setName("My Process Group");
    final VersionedProcessor processor1 = new VersionedProcessor();
    processor1.setIdentifier("processor1");
    processor1.setName("My Processor 1");
    // make sure nested objects are serialized/deserialized
    processGroup1.getProcessors().add(processor1);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    serializer.serialize(processGroup1, out);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final VersionedProcessGroup deserializedProcessGroup1 = serializer.deserialize(in);
    Assert.assertEquals(processGroup1.getIdentifier(), deserializedProcessGroup1.getIdentifier());
    Assert.assertEquals(processGroup1.getName(), deserializedProcessGroup1.getName());
    Assert.assertEquals(1, deserializedProcessGroup1.getProcessors().size());
    final VersionedProcessor deserializedProcessor1 = deserializedProcessGroup1.getProcessors().iterator().next();
    Assert.assertEquals(processor1.getIdentifier(), deserializedProcessor1.getIdentifier());
    Assert.assertEquals(processor1.getName(), deserializedProcessor1.getName());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) Test(org.junit.Test)

Example 34 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class TestJAXBVersionedProcessGroupSerializer method testSerializeDeserializeFlowSnapshot.

@Test
public void testSerializeDeserializeFlowSnapshot() throws SerializationException {
    final Serializer<VersionedProcessGroup> serializer = new JAXBVersionedProcessGroupSerializer();
    final VersionedProcessGroup processGroup1 = new VersionedProcessGroup();
    processGroup1.setIdentifier("pg1");
    processGroup1.setName("My Process Group");
    final VersionedProcessor processor1 = new VersionedProcessor();
    processor1.setIdentifier("processor1");
    processor1.setName("My Processor 1");
    // make sure nested objects are serialized/deserialized
    processGroup1.getProcessors().add(processor1);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    serializer.serialize(processGroup1, out);
    final String snapshotStr = new String(out.toByteArray(), StandardCharsets.UTF_8);
    // System.out.println(snapshotStr);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final VersionedProcessGroup deserializedProcessGroup1 = serializer.deserialize(in);
    Assert.assertEquals(processGroup1.getIdentifier(), deserializedProcessGroup1.getIdentifier());
    Assert.assertEquals(processGroup1.getName(), deserializedProcessGroup1.getName());
    Assert.assertEquals(1, deserializedProcessGroup1.getProcessors().size());
    final VersionedProcessor deserializedProcessor1 = deserializedProcessGroup1.getProcessors().iterator().next();
    Assert.assertEquals(processor1.getIdentifier(), deserializedProcessor1.getIdentifier());
    Assert.assertEquals(processor1.getName(), deserializedProcessor1.getName());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) Test(org.junit.Test)

Example 35 with VersionedProcessGroup

use of org.apache.nifi.registry.flow.VersionedProcessGroup in project nifi-registry by apache.

the class TestRegistryService method createProcessGroup.

private VersionedProcessGroup createProcessGroup(String identifier) {
    VersionedProcessGroup processGroup = new VersionedProcessGroup();
    processGroup.setIdentifier(identifier);
    return processGroup;
}
Also used : VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup)

Aggregations

VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)36 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)17 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)13 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)12 HashMap (java.util.HashMap)11 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Set (java.util.Set)9 Bucket (org.apache.nifi.registry.bucket.Bucket)9 LinkedHashSet (java.util.LinkedHashSet)8 Collections (java.util.Collections)7 VersionedProcessor (org.apache.nifi.registry.flow.VersionedProcessor)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)6 List (java.util.List)5 Optional (java.util.Optional)5 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)5 StandardVersionControlInformation (org.apache.nifi.registry.flow.StandardVersionControlInformation)5