Search in sources :

Example 26 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobClient method uploadJarFiles.

/**
	 * Retrieves the {@link BlobServer} address from the JobManager and uploads
	 * the JAR files to it.
	 *
	 * @param jobManager   Server address of the {@link BlobServer}
	 * @param askTimeout   Ask timeout for blob server address retrieval
	 * @param clientConfig Any additional configuration for the blob client
	 * @param jars         List of JAR files to upload
	 * @throws IOException Thrown if the address retrieval or upload fails
	 */
public static List<BlobKey> uploadJarFiles(ActorGateway jobManager, FiniteDuration askTimeout, Configuration clientConfig, List<Path> jars) throws IOException {
    if (jars.isEmpty()) {
        return Collections.emptyList();
    } else {
        Object msg = JobManagerMessages.getRequestBlobManagerPort();
        Future<Object> futureBlobPort = jobManager.ask(msg, askTimeout);
        try {
            // Retrieve address
            Object result = Await.result(futureBlobPort, askTimeout);
            if (result instanceof Integer) {
                int port = (Integer) result;
                LOG.info("Blob client connecting to " + jobManager.path());
                Option<String> jmHost = jobManager.actor().path().address().host();
                String jmHostname = jmHost.isDefined() ? jmHost.get() : "localhost";
                InetSocketAddress serverAddress = new InetSocketAddress(jmHostname, port);
                // Now, upload
                return uploadJarFiles(serverAddress, clientConfig, jars);
            } else {
                throw new Exception("Expected port number (int) as answer, received " + result);
            }
        } catch (Exception e) {
            throw new IOException("Could not retrieve the JobManager's blob port.", e);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException)

Example 27 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobClientSslTest method testRegularStream.

/**
	 * Tests the PUT/GET operations for regular (non-content-addressable) streams.
	 */
@Test
public void testRegularStream() {
    final JobID jobID = JobID.generate();
    final String key = "testkey3";
    try {
        final File testFile = File.createTempFile("testfile", ".dat");
        testFile.deleteOnExit();
        prepareTestFile(testFile);
        BlobClient client = null;
        InputStream is = null;
        try {
            final InetSocketAddress serverAddress = new InetSocketAddress("localhost", BLOB_SSL_SERVER.getPort());
            client = new BlobClient(serverAddress, sslClientConfig);
            // Store the data
            is = new FileInputStream(testFile);
            client.put(jobID, key, is);
            is.close();
            is = null;
            // Retrieve the data
            is = client.get(jobID, key);
            validateGet(is, testFile);
        } finally {
            if (is != null) {
                is.close();
            }
            if (client != null) {
                client.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) JobID(org.apache.flink.api.common.JobID) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobClientSslTest method uploadJarFile.

/**
	 * Tests the static {@link BlobClient#uploadJarFiles(InetSocketAddress, Configuration, List)} helper.
	 */
private void uploadJarFile(BlobServer blobServer, Configuration blobClientConfig) throws Exception {
    final File testFile = File.createTempFile("testfile", ".dat");
    testFile.deleteOnExit();
    prepareTestFile(testFile);
    InetSocketAddress serverAddress = new InetSocketAddress("localhost", blobServer.getPort());
    List<BlobKey> blobKeys = BlobClient.uploadJarFiles(serverAddress, blobClientConfig, Collections.singletonList(new Path(testFile.toURI())));
    assertEquals(1, blobKeys.size());
    try (BlobClient blobClient = new BlobClient(serverAddress, blobClientConfig)) {
        InputStream is = blobClient.get(blobKeys.get(0));
        validateGet(is, testFile);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) InetSocketAddress(java.net.InetSocketAddress) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File)

Example 29 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobClientTest method testContentAddressableBuffer.

/**
	 * Tests the PUT/GET operations for content-addressable buffers.
	 */
@Test
public void testContentAddressableBuffer() {
    BlobClient client = null;
    try {
        byte[] testBuffer = createTestBuffer();
        MessageDigest md = BlobUtils.createMessageDigest();
        md.update(testBuffer);
        BlobKey origKey = new BlobKey(md.digest());
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", BLOB_SERVER.getPort());
        client = new BlobClient(serverAddress, blobServiceConfig);
        // Store the data
        BlobKey receivedKey = client.put(testBuffer);
        assertEquals(origKey, receivedKey);
        // Retrieve the data
        InputStream is = client.get(receivedKey);
        validateGet(is, testBuffer);
        // Check reaction to invalid keys
        try {
            client.get(new BlobKey());
            fail("Expected IOException did not occur");
        } catch (IOException fnfe) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) IOException(java.io.IOException) EOFException(java.io.EOFException) Test(org.junit.Test)

Example 30 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobClientTest method testUploadJarFilesHelper.

/**
	 * Tests the static {@link BlobClient#uploadJarFiles(InetSocketAddress, Configuration, List)} helper.
	 */
@Test
public void testUploadJarFilesHelper() throws Exception {
    final File testFile = File.createTempFile("testfile", ".dat");
    testFile.deleteOnExit();
    prepareTestFile(testFile);
    InetSocketAddress serverAddress = new InetSocketAddress("localhost", BLOB_SERVER.getPort());
    List<BlobKey> blobKeys = BlobClient.uploadJarFiles(serverAddress, blobServiceConfig, Collections.singletonList(new Path(testFile.toURI())));
    assertEquals(1, blobKeys.size());
    try (BlobClient blobClient = new BlobClient(serverAddress, blobServiceConfig)) {
        InputStream is = blobClient.get(blobKeys.get(0));
        validateGet(is, testFile);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) InetSocketAddress(java.net.InetSocketAddress) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2586 Test (org.junit.Test)595 IOException (java.io.IOException)592 Socket (java.net.Socket)345 InetAddress (java.net.InetAddress)242 SocketAddress (java.net.SocketAddress)176 ServerSocket (java.net.ServerSocket)170 ArrayList (java.util.ArrayList)168 Configuration (org.apache.hadoop.conf.Configuration)140 ByteBuffer (java.nio.ByteBuffer)129 UnknownHostException (java.net.UnknownHostException)122 InputStream (java.io.InputStream)102 OutputStream (java.io.OutputStream)101 SocketChannel (java.nio.channels.SocketChannel)101 SocketException (java.net.SocketException)89 File (java.io.File)88 HashMap (java.util.HashMap)78 URI (java.net.URI)72 Proxy (java.net.Proxy)65 SocketTimeoutException (java.net.SocketTimeoutException)65