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);
}
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);
}
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());
}
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());
}
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;
}
Aggregations