use of java.net.InetSocketAddress in project flink by apache.
the class JobSubmitTest method testFailureWhenJarBlobsMissing.
@Test
public void testFailureWhenJarBlobsMissing() {
try {
// create a simple job graph
JobVertex jobVertex = new JobVertex("Test Vertex");
jobVertex.setInvokableClass(NoOpInvokable.class);
JobGraph jg = new JobGraph("test job", jobVertex);
// request the blob port from the job manager
Future<Object> future = jmGateway.ask(JobManagerMessages.getRequestBlobManagerPort(), timeout);
int blobPort = (Integer) Await.result(future, timeout);
// upload two dummy bytes and add their keys to the job graph as dependencies
BlobKey key1, key2;
BlobClient bc = new BlobClient(new InetSocketAddress("localhost", blobPort), jmConfig);
try {
key1 = bc.put(new byte[10]);
key2 = bc.put(new byte[10]);
// delete one of the blobs to make sure that the startup failed
bc.delete(key2);
} finally {
bc.close();
}
jg.addBlob(key1);
jg.addBlob(key2);
// submit the job
Future<Object> submitFuture = jmGateway.ask(new JobManagerMessages.SubmitJob(jg, ListeningBehaviour.EXECUTION_RESULT), timeout);
try {
Await.result(submitFuture, timeout);
} catch (JobExecutionException e) {
// that is what we expect
assertTrue(e.getCause() instanceof IOException);
} catch (Exception e) {
fail("Wrong exception type");
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class ZooKeeperLeaderRetrievalTest method testConnectingAddressRetrievalWithDelayedLeaderElection.
/**
* Tests that LeaderRetrievalUtils.findConnectingAdress finds the correct connecting address
* in case of an old leader address in ZooKeeper and a subsequent election of a new leader.
* The findConnectingAddress should block until the new leader has been elected and his
* address has been written to ZooKeeper.
*/
@Test
public void testConnectingAddressRetrievalWithDelayedLeaderElection() throws Exception {
FiniteDuration timeout = new FiniteDuration(1, TimeUnit.MINUTES);
Configuration config = new Configuration();
long sleepingTime = 1000;
config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
LeaderElectionService leaderElectionService = null;
LeaderElectionService faultyLeaderElectionService;
ServerSocket serverSocket;
InetAddress localHost;
Thread thread;
CuratorFramework[] client = new CuratorFramework[2];
try {
client[0] = ZooKeeperUtils.startCuratorFramework(config);
client[1] = ZooKeeperUtils.startCuratorFramework(config);
String wrongHostPort = NetUtils.unresolvedHostAndPortToNormalizedString("1.1.1.1", 1234);
String wrongAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), wrongHostPort, Option.<String>empty());
try {
localHost = InetAddress.getLocalHost();
serverSocket = new ServerSocket(0, 50, localHost);
} catch (UnknownHostException e) {
// may happen if disconnected. skip test.
System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
return;
} catch (IOException e) {
// may happen in certain test setups, skip test.
System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
return;
}
InetSocketAddress correctInetSocketAddress = new InetSocketAddress(localHost, serverSocket.getLocalPort());
String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(localHost.getHostName(), correctInetSocketAddress.getPort());
String correctAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), hostPort, Option.<String>empty());
faultyLeaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[0], config);
TestingContender wrongLeaderAddressContender = new TestingContender(wrongAddress, faultyLeaderElectionService);
faultyLeaderElectionService.start(wrongLeaderAddressContender);
FindConnectingAddress findConnectingAddress = new FindConnectingAddress(config, timeout);
thread = new Thread(findConnectingAddress);
thread.start();
leaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[1], config);
TestingContender correctLeaderAddressContender = new TestingContender(correctAddress, leaderElectionService);
Thread.sleep(sleepingTime);
faultyLeaderElectionService.stop();
leaderElectionService.start(correctLeaderAddressContender);
thread.join();
InetAddress result = findConnectingAddress.getInetAddress();
// check that we can connect to the localHost
Socket socket = new Socket();
try {
// port 0 = let the OS choose the port
SocketAddress bindP = new InetSocketAddress(result, 0);
// machine
socket.bind(bindP);
socket.connect(correctInetSocketAddress, 1000);
} finally {
socket.close();
}
} finally {
if (leaderElectionService != null) {
leaderElectionService.stop();
}
if (client[0] != null) {
client[0].close();
}
if (client[1] != null) {
client[1].close();
}
}
}
use of java.net.InetSocketAddress in project hadoop by apache.
the class SecurityUtil method buildDTServiceName.
/**
* create the service name for a Delegation token
* @param uri of the service
* @param defPort is used if the uri lacks a port
* @return the token service, or null if no authority
* @see #buildTokenService(InetSocketAddress)
*/
public static String buildDTServiceName(URI uri, int defPort) {
String authority = uri.getAuthority();
if (authority == null) {
return null;
}
InetSocketAddress addr = NetUtils.createSocketAddr(authority, defPort);
return buildTokenService(addr).toString();
}
use of java.net.InetSocketAddress in project flink by apache.
the class JobClient method retrieveClassLoader.
/**
* Reconstructs the class loader by first requesting information about it at the JobManager
* and then downloading missing jar files.
* @param jobID id of job
* @param jobManager gateway to the JobManager
* @param config the flink configuration
* @return A classloader that should behave like the original classloader
* @throws JobRetrievalException if anything goes wrong
*/
public static ClassLoader retrieveClassLoader(JobID jobID, ActorGateway jobManager, Configuration config) throws JobRetrievalException {
final Object jmAnswer;
try {
jmAnswer = Await.result(jobManager.ask(new JobManagerMessages.RequestClassloadingProps(jobID), AkkaUtils.getDefaultTimeoutAsFiniteDuration()), AkkaUtils.getDefaultTimeoutAsFiniteDuration());
} catch (Exception e) {
throw new JobRetrievalException(jobID, "Couldn't retrieve class loading properties from JobManager.", e);
}
if (jmAnswer instanceof JobManagerMessages.ClassloadingProps) {
JobManagerMessages.ClassloadingProps props = ((JobManagerMessages.ClassloadingProps) jmAnswer);
Option<String> jmHost = jobManager.actor().path().address().host();
String jmHostname = jmHost.isDefined() ? jmHost.get() : "localhost";
InetSocketAddress serverAddress = new InetSocketAddress(jmHostname, props.blobManagerPort());
final BlobCache blobClient;
try {
blobClient = new BlobCache(serverAddress, config);
} catch (IOException e) {
throw new JobRetrievalException(jobID, "Failed to setup blob cache", e);
}
final Collection<BlobKey> requiredJarFiles = props.requiredJarFiles();
final Collection<URL> requiredClasspaths = props.requiredClasspaths();
final URL[] allURLs = new URL[requiredJarFiles.size() + requiredClasspaths.size()];
int pos = 0;
for (BlobKey blobKey : props.requiredJarFiles()) {
try {
allURLs[pos++] = blobClient.getURL(blobKey);
} catch (Exception e) {
blobClient.shutdown();
throw new JobRetrievalException(jobID, "Failed to download BlobKey " + blobKey, e);
}
}
for (URL url : requiredClasspaths) {
allURLs[pos++] = url;
}
return new FlinkUserCodeClassLoader(allURLs, JobClient.class.getClassLoader());
} else if (jmAnswer instanceof JobManagerMessages.JobNotFound) {
throw new JobRetrievalException(jobID, "Couldn't retrieve class loader. Job " + jobID + " not found");
} else {
throw new JobRetrievalException(jobID, "Unknown response from JobManager: " + jmAnswer);
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class IPv6HostnamesITCase method getLocalIPv6Address.
private Inet6Address getLocalIPv6Address() {
try {
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements()) {
NetworkInterface netInterface = e.nextElement();
// for each address of the network interface
Enumeration<InetAddress> ee = netInterface.getInetAddresses();
while (ee.hasMoreElements()) {
InetAddress addr = ee.nextElement();
if (addr instanceof Inet6Address && (!addr.isLoopbackAddress()) && (!addr.isAnyLocalAddress())) {
// see if it is possible to bind to the address
InetSocketAddress socketAddress = new InetSocketAddress(addr, 0);
try {
log.info("Considering address " + addr);
// test whether we can bind a socket to that address
log.info("Testing whether sockets can bind to " + addr);
ServerSocket sock = new ServerSocket();
sock.bind(socketAddress);
sock.close();
// test whether Akka's netty can bind to the address
log.info("Testing whether Akka can use " + addr);
int port = NetUtils.getAvailablePort();
ActorSystem as = AkkaUtils.createActorSystem(new Configuration(), new Some<scala.Tuple2<String, Object>>(new scala.Tuple2<String, Object>(addr.getHostAddress(), port)));
as.shutdown();
log.info("Using address " + addr);
return (Inet6Address) addr;
} catch (IOException ignored) {
// fall through the loop
}
}
}
}
return null;
} catch (Exception e) {
return null;
}
}
Aggregations