Search in sources :

Example 1 with FileModificationPollingMonitor

use of io.pravega.common.io.filesystem.FileModificationPollingMonitor in project pravega by pravega.

the class PravegaConnectionListenerTest method testUsesPollingMonitorForSymbolicLinks.

@Test
public void testUsesPollingMonitorForSymbolicLinks() {
    String pathToCertificateFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME;
    String pathToKeyFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME;
    @Cleanup PravegaConnectionListener listener = new PravegaConnectionListener(true, true, "whatever", -1, mock(StreamSegmentStore.class), mock(TableStore.class), SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), "dummy-tls-certificate-path", "dummy-tls-key-path", true, NoOpScheduledExecutor.get(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    AtomicReference<SslContext> dummySslCtx = new AtomicReference<>(null);
    FileModificationMonitor monitor = listener.prepareCertificateMonitor(true, pathToCertificateFile, pathToKeyFile, dummySslCtx);
    assertTrue("Unexpected type of FileModificationMonitor", monitor instanceof FileModificationPollingMonitor);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) FileModificationMonitor(io.pravega.common.io.filesystem.FileModificationMonitor) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) FileModificationPollingMonitor(io.pravega.common.io.filesystem.FileModificationPollingMonitor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Cleanup(lombok.Cleanup) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 2 with FileModificationPollingMonitor

use of io.pravega.common.io.filesystem.FileModificationPollingMonitor in project pravega by pravega.

the class AbstractConnectionListener method prepareCertificateMonitor.

@VisibleForTesting
FileModificationMonitor prepareCertificateMonitor(boolean isTLSCertPathSymLink, String tlsCertificatePath, String tlsKeyPath, AtomicReference<SslContext> sslCtx) {
    FileModificationMonitor result;
    try {
        if (isTLSCertPathSymLink) {
            // For symbolic links, the event-based watcher doesn't work, so we use a polling monitor.
            log.info("The path to certificate file [{}] was found to be a symbolic link, " + " so using [{}] to monitor for certificate changes", tlsCertificatePath, FileModificationPollingMonitor.class.getSimpleName());
            result = new FileModificationPollingMonitor(Paths.get(tlsCertificatePath), new TLSConfigChangeFileConsumer(sslCtx, tlsCertificatePath, tlsKeyPath, tlsProtocolVersion));
        } else {
            // For non symbolic links we'll use the event-based watcher, which is more efficient than a
            // polling-based monitor.
            result = new FileModificationEventWatcher(Paths.get(tlsCertificatePath), new TLSConfigChangeEventConsumer(sslCtx, tlsCertificatePath, tlsKeyPath, tlsProtocolVersion));
        }
        return result;
    } catch (FileNotFoundException e) {
        log.error("Failed to prepare a monitor for the certificate at path [{}]", tlsCertificatePath, e);
        throw new RuntimeException(e);
    }
}
Also used : FileModificationMonitor(io.pravega.common.io.filesystem.FileModificationMonitor) TLSConfigChangeEventConsumer(io.pravega.segmentstore.server.host.security.TLSConfigChangeEventConsumer) FileNotFoundException(java.io.FileNotFoundException) FileModificationPollingMonitor(io.pravega.common.io.filesystem.FileModificationPollingMonitor) FileModificationEventWatcher(io.pravega.common.io.filesystem.FileModificationEventWatcher) TLSConfigChangeFileConsumer(io.pravega.segmentstore.server.host.security.TLSConfigChangeFileConsumer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FileModificationMonitor (io.pravega.common.io.filesystem.FileModificationMonitor)2 FileModificationPollingMonitor (io.pravega.common.io.filesystem.FileModificationPollingMonitor)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SslContext (io.netty.handler.ssl.SslContext)1 FileModificationEventWatcher (io.pravega.common.io.filesystem.FileModificationEventWatcher)1 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)1 TLSConfigChangeEventConsumer (io.pravega.segmentstore.server.host.security.TLSConfigChangeEventConsumer)1 TLSConfigChangeFileConsumer (io.pravega.segmentstore.server.host.security.TLSConfigChangeFileConsumer)1 FileNotFoundException (java.io.FileNotFoundException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1