Search in sources :

Example 1 with StandardVersionNegotiator

use of org.apache.nifi.remote.StandardVersionNegotiator in project nifi by apache.

the class DistributedSetCacheClientService method leaseCommsSession.

private CommsSession leaseCommsSession() throws IOException {
    CommsSession session = queue.poll();
    if (session != null && !session.isClosed()) {
        return session;
    }
    session = createCommsSession(configContext);
    final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(1);
    try {
        ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator);
        session.setProtocolVersion(versionNegotiator.getVersion());
    } catch (final HandshakeException e) {
        IOUtils.closeQuietly(session);
        throw new IOException(e);
    }
    return session;
}
Also used : VersionNegotiator(org.apache.nifi.remote.VersionNegotiator) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) IOException(java.io.IOException) HandshakeException(org.apache.nifi.distributed.cache.protocol.exception.HandshakeException)

Example 2 with StandardVersionNegotiator

use of org.apache.nifi.remote.StandardVersionNegotiator in project nifi by apache.

the class TestSocketFlowFileServerProtocol method getDefaultSocketFlowFileServerProtocol.

private SocketFlowFileServerProtocol getDefaultSocketFlowFileServerProtocol() {
    final StandardVersionNegotiator versionNegotiator = new StandardVersionNegotiator(5, 4, 3, 2, 1);
    final SocketFlowFileServerProtocol protocol = spy(new SocketFlowFileServerProtocol());
    return protocol;
}
Also used : StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator)

Example 3 with StandardVersionNegotiator

use of org.apache.nifi.remote.StandardVersionNegotiator in project nifi by apache.

the class DistributedMapCacheClientService method leaseCommsSession.

private CommsSession leaseCommsSession() throws IOException {
    CommsSession session = queue.poll();
    if (session != null && !session.isClosed()) {
        return session;
    }
    session = createCommsSession(configContext);
    final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(3, 2, 1);
    try {
        ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator);
        session.setProtocolVersion(versionNegotiator.getVersion());
    } catch (final HandshakeException e) {
        try {
            session.close();
        } catch (final IOException ioe) {
        }
        throw new IOException(e);
    }
    return session;
}
Also used : VersionNegotiator(org.apache.nifi.remote.VersionNegotiator) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) IOException(java.io.IOException) HandshakeException(org.apache.nifi.distributed.cache.protocol.exception.HandshakeException)

Example 4 with StandardVersionNegotiator

use of org.apache.nifi.remote.StandardVersionNegotiator in project nifi by apache.

the class TestServerAndClient method testBackwardCompatibility.

@Test
public void testBackwardCompatibility() throws Exception {
    /**
     * This bypasses the test for build environments in OS X running Java 1.8 due to a JVM bug
     * See:  https://issues.apache.org/jira/browse/NIFI-437
     */
    Assume.assumeFalse("test is skipped due to build environment being OS X with JDK 1.8. See https://issues.apache.org/jira/browse/NIFI-437", SystemUtils.IS_OS_MAC && SystemUtils.IS_JAVA_1_8);
    LOGGER.info("Testing " + Thread.currentThread().getStackTrace()[1].getMethodName());
    final TestRunner runner = TestRunners.newTestRunner(Mockito.mock(Processor.class));
    // Create a server that only supports protocol version 1.
    final DistributedMapCacheServer server = new MapServer() {

        @Override
        protected MapCacheServer createMapCacheServer(int port, int maxSize, SSLContext sslContext, EvictionPolicy evictionPolicy, File persistenceDir) throws IOException {
            return new MapCacheServer(getIdentifier(), sslContext, port, maxSize, evictionPolicy, persistenceDir) {

                @Override
                protected StandardVersionNegotiator getVersionNegotiator() {
                    return new StandardVersionNegotiator(1);
                }
            };
        }
    };
    runner.addControllerService("server", server);
    runner.enableControllerService(server);
    DistributedMapCacheClientService client = new DistributedMapCacheClientService();
    MockControllerServiceInitializationContext clientInitContext1 = new MockControllerServiceInitializationContext(client, "client");
    client.initialize(clientInitContext1);
    final Map<PropertyDescriptor, String> clientProperties = new HashMap<>();
    clientProperties.put(DistributedMapCacheClientService.HOSTNAME, "localhost");
    clientProperties.put(DistributedMapCacheClientService.PORT, String.valueOf(server.getPort()));
    clientProperties.put(DistributedMapCacheClientService.COMMUNICATIONS_TIMEOUT, "360 secs");
    MockConfigurationContext clientContext = new MockConfigurationContext(clientProperties, clientInitContext1.getControllerServiceLookup());
    client.cacheConfig(clientContext);
    final Serializer<String> stringSerializer = new StringSerializer();
    final Deserializer<String> stringDeserializer = new StringDeserializer();
    final String key = "test-backward-compatibility";
    // Version 1 operations should work
    client.put(key, "value1", stringSerializer, stringSerializer);
    assertEquals("value1", client.get(key, stringSerializer, stringDeserializer));
    assertTrue(client.containsKey(key, stringSerializer));
    try {
        client.fetch(key, stringSerializer, stringDeserializer);
        fail("Version 2 operations should NOT work.");
    } catch (UnsupportedOperationException e) {
    }
    try {
        AtomicCacheEntry<String, String, Long> entry = new AtomicCacheEntry<>(key, "value2", 0L);
        client.replace(entry, stringSerializer, stringSerializer);
        fail("Version 2 operations should NOT work.");
    } catch (UnsupportedOperationException e) {
    }
    try {
        Set<String> keys = client.keySet(stringDeserializer);
        fail("Version 3 operations should NOT work.");
    } catch (UnsupportedOperationException e) {
    }
    try {
        String removed = client.removeAndGet("v.*", stringSerializer, stringDeserializer);
        fail("Version 3 operations should NOT work.");
    } catch (UnsupportedOperationException e) {
    }
    try {
        Map<String, String> removed = client.removeByPatternAndGet("v.*", stringDeserializer, stringDeserializer);
        fail("Version 3 operations should NOT work.");
    } catch (UnsupportedOperationException e) {
    }
    client.close();
    server.shutdownServer();
}
Also used : Processor(org.apache.nifi.processor.Processor) HashMap(java.util.HashMap) DistributedMapCacheClientService(org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) MapCacheServer(org.apache.nifi.distributed.cache.server.map.MapCacheServer) DistributedMapCacheServer(org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer) DistributedMapCacheServer(org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer) SSLContext(javax.net.ssl.SSLContext) AtomicCacheEntry(org.apache.nifi.distributed.cache.client.AtomicCacheEntry) MockControllerServiceInitializationContext(org.apache.nifi.util.MockControllerServiceInitializationContext) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) File(java.io.File) Test(org.junit.Test)

Example 5 with StandardVersionNegotiator

use of org.apache.nifi.remote.StandardVersionNegotiator in project nifi by apache.

the class DataTransferResource method initiateServerProtocol.

private HttpFlowFileServerProtocol initiateServerProtocol(final HttpServletRequest req, final Peer peer, final Integer transportProtocolVersion) throws IOException {
    // Switch transaction protocol version based on transport protocol version.
    TransportProtocolVersionNegotiator negotiatedTransportProtocolVersion = new TransportProtocolVersionNegotiator(transportProtocolVersion);
    VersionNegotiator versionNegotiator = new StandardVersionNegotiator(negotiatedTransportProtocolVersion.getTransactionProtocolVersion());
    final String dataTransferUrl = req.getRequestURL().toString();
    ((HttpCommunicationsSession) peer.getCommunicationsSession()).setDataTransferUrl(dataTransferUrl);
    HttpFlowFileServerProtocol serverProtocol = getHttpFlowFileServerProtocol(versionNegotiator);
    HttpRemoteSiteListener.getInstance(nifiProperties).setupServerProtocol(serverProtocol);
    serverProtocol.handshake(peer);
    return serverProtocol;
}
Also used : TransportProtocolVersionNegotiator(org.apache.nifi.remote.client.http.TransportProtocolVersionNegotiator) VersionNegotiator(org.apache.nifi.remote.VersionNegotiator) TransportProtocolVersionNegotiator(org.apache.nifi.remote.client.http.TransportProtocolVersionNegotiator) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator) HttpCommunicationsSession(org.apache.nifi.remote.io.http.HttpCommunicationsSession) StandardHttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.StandardHttpFlowFileServerProtocol) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) StandardVersionNegotiator(org.apache.nifi.remote.StandardVersionNegotiator)

Aggregations

StandardVersionNegotiator (org.apache.nifi.remote.StandardVersionNegotiator)5 VersionNegotiator (org.apache.nifi.remote.VersionNegotiator)3 IOException (java.io.IOException)2 HandshakeException (org.apache.nifi.distributed.cache.protocol.exception.HandshakeException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 SSLContext (javax.net.ssl.SSLContext)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1 AtomicCacheEntry (org.apache.nifi.distributed.cache.client.AtomicCacheEntry)1 DistributedMapCacheClientService (org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService)1 DistributedMapCacheServer (org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer)1 MapCacheServer (org.apache.nifi.distributed.cache.server.map.MapCacheServer)1 Processor (org.apache.nifi.processor.Processor)1 TransportProtocolVersionNegotiator (org.apache.nifi.remote.client.http.TransportProtocolVersionNegotiator)1 HttpCommunicationsSession (org.apache.nifi.remote.io.http.HttpCommunicationsSession)1 HttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol)1 StandardHttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.StandardHttpFlowFileServerProtocol)1 MockConfigurationContext (org.apache.nifi.util.MockConfigurationContext)1 MockControllerServiceInitializationContext (org.apache.nifi.util.MockControllerServiceInitializationContext)1 TestRunner (org.apache.nifi.util.TestRunner)1