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