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