public void start() throws IOException { md.start(); InetSocketAddress sockAddr = md.getLocalAddress(); localNetworkAddress = new NetworkAddress(sockAddr.getHostString(), sockAddr.getPort()); // See if the public address was explicitly specified, and if not, // make it a copy of localNetworkAddress if (publicNetworkAddress.getAddress() == null) { publicNetworkAddress = localNetworkAddress; } else { // Likewise for public port if (publicNetworkAddress.getPort() == 0) { publicNetworkAddress = new NetworkAddress(publicNetworkAddress.getAddress(), sockAddr.getPort()); } } }
public static SocketAddress getSocketAddress(NetworkAddress netAddr) throws UnknownHostException { return new InetSocketAddress(InetAddress.getByAddress(netAddr.lookupIpAddress()), netAddr.getPort()); }
public static NetworkAddress create(DataInput dis) throws IOException { NetworkAddress networkAddress = new NetworkAddress(); networkAddress.readFields(dis); return networkAddress; }
private static void writeNetworkAddress(DataOutputStream dos, NetworkAddress networkAddress) throws IOException { dos.writeUTF(networkAddress.getAddress()); dos.writeInt(networkAddress.getPort()); } }
public static Map<String, NodeControllerInfo> generateNodeControllerInfo(int numberOfNodes, String ncNamePrefix, String addressPrefix, int netPort, int dataPort, int messagingPort) { Map<String, NodeControllerInfo> ncNameToNcInfos = new HashMap<>(); for (int i = 1; i <= numberOfNodes; i++) { String ncId = ncNamePrefix + i; String ncAddress = addressPrefix + i; ncNameToNcInfos.put(ncId, new NodeControllerInfo(ncId, NodeStatus.ACTIVE, new NetworkAddress(ncAddress, netPort), new NetworkAddress(ncAddress, dataPort), new NetworkAddress(ncAddress, messagingPort), 2)); } return ncNameToNcInfos; }
String ipAddr = InetAddress.getByAddress(entry.getValue().getNetworkAddress().lookupIpAddress()) .getHostAddress(); List<String> matchedNCs = ipToNcMapping.computeIfAbsent(ipAddr, k -> new ArrayList<>());
/** * Read the hostname and the ip address of every node from the xml cluster configuration file. * Save the information inside nodes. * * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public void readNodesFromXML() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder; dBuilder = dbFactory.newDocumentBuilder(); nodes = new ArrayList<ArrayList<String>>(); for (NodeControllerInfo ncInfo : nodeControllerInfos.values()) { //Will this include the master node? Is that bad? ArrayList<String> info = new ArrayList<String>(); info.add(ncInfo.getNodeId()); info.add(ncInfo.getNetworkAddress().getAddress()); nodes.add(info); } }
inputPartitionLocations[i] = new NetworkAddress[columns]; for (int j = 0; j < columns; j++) { inputPartitionLocations[i][j] = NetworkAddress.create(input);
public ResultSet(IHyracksClientConnection hcc, ISocketChannelFactory socketChannelFactory, int frameSize, int nReaders) throws Exception { NetworkAddress ddsAddress = hcc.getResultDirectoryAddress(); resultDirectory = new ResultDirectory(ddsAddress.getAddress(), ddsAddress.getPort(), socketChannelFactory); netManager = new ClientNetworkManager(nReaders, socketChannelFactory); netManager.start(); resultClientCtx = new ResultClientContext(frameSize); }
private static NetworkAddress readNetworkAddress(DataInputStream dis) throws IOException { String address = dis.readUTF(); int port = dis.readInt(); NetworkAddress networkAddress = new NetworkAddress(address, port); return networkAddress; }
String ipAddr = InetAddress.getByAddress(entry.getValue().getNetworkAddress().lookupIpAddress()) .getHostAddress(); List<String> matchedNCs = ipToNcMapping.computeIfAbsent(ipAddr, k -> new ArrayList<>());
private void formResponseObject(ObjectNode jsonResponse, FileSplit[] fileSplits, ARecordType recordType, String primaryKeys, Map<String, NodeControllerInfo> nodeMap) { ArrayNode partititons = OBJECT_MAPPER.createArrayNode(); // Adds a primary key. jsonResponse.put("keys", primaryKeys); // Adds record type. jsonResponse.set("type", recordType.toJSON()); // Generates file partitions. for (FileSplit split : fileSplits) { String ipAddress = nodeMap.get(split.getNodeName()).getNetworkAddress().getAddress(); String path = split.getPath(); FilePartition partition = new FilePartition(ipAddress, path); partititons.add(partition.toObjectNode()); } // Generates the response object which contains the splits. jsonResponse.set("splits", partititons); } }
public void start() throws IOException { md.start(); InetSocketAddress sockAddr = md.getLocalAddress(); localNetworkAddress = new NetworkAddress(sockAddr.getHostString(), sockAddr.getPort()); // See if the public address was explicitly specified, and if not, // make it a copy of localNetworkAddress if (publicNetworkAddress.getAddress() == null) { publicNetworkAddress = localNetworkAddress; } else { // Likewise for public port if (publicNetworkAddress.getPort() == 0) { publicNetworkAddress = new NetworkAddress(publicNetworkAddress.getAddress(), sockAddr.getPort()); } } }
private IChannelControlBlock establishNewConnection(String nodeId) throws Exception { Map<String, NodeControllerInfo> nodeControllers = ncs.getNodeControllersInfo(); // Get the node messaging address from its info NodeControllerInfo nodeControllerInfo = nodeControllers.get(nodeId); if (nodeControllerInfo == null) { throw new NetException("Could not find node: " + nodeId); } NetworkAddress nodeMessagingNeAddress = nodeControllerInfo.getMessagingNetworkAddress(); SocketAddress nodeAddress = new InetSocketAddress(InetAddress.getByName(nodeMessagingNeAddress.getAddress()), nodeMessagingNeAddress.getPort()); // Open the channel IChannelControlBlock ccb = connect(nodeAddress); try { // Prepare the initial message buffer ByteBuffer initialBuffer = ccb.getReadInterface().getBufferFactory().createBuffer(); prepareMessagingInitialMessage(ncs.getId(), initialBuffer); // Send the initial messaging channel handshake message to register the opened channel on both nodes ccb.getWriteInterface().getFullBufferAcceptor().accept(initialBuffer); return ccb; } catch (NetException e) { closeChannel(ccb); throw e; } }
public MessagingNetworkManager(NodeControllerService ncs, String inetAddress, int inetPort, int nThreads, String publicInetAddress, int publicInetPort, IChannelInterfaceFactory channelInterfaceFactory, ISocketChannelFactory socketChannelFactory) { this.ncs = ncs; md = new MuxDemux(new InetSocketAddress(inetAddress, inetPort), new ChannelOpenListener(), nThreads, MAX_CONNECTION_ATTEMPTS, channelInterfaceFactory, socketChannelFactory); publicNetworkAddress = new NetworkAddress(publicInetAddress, publicInetPort); }
private SocketAddress getSocketAddress(ResultDirectoryRecord record) throws HyracksDataException { try { final NetworkAddress netAddr = record.getNetworkAddress(); return new InetSocketAddress(InetAddress.getByAddress(netAddr.lookupIpAddress()), netAddr.getPort()); } catch (UnknownHostException e) { throw HyracksDataException.create(e); } }
byte[] rawip; try { rawip = ncNameToNcInfos.get(NCs[i]).getNetworkAddress().lookupIpAddress(); } catch (UnknownHostException e) {
public void start() throws IOException { md.start(); InetSocketAddress sockAddr = md.getLocalAddress(); localNetworkAddress = new NetworkAddress(sockAddr.getHostString(), sockAddr.getPort()); // See if the public address was explicitly specified, and if not, // make it a copy of localNetworkAddress if (publicNetworkAddress.getAddress() == null) { publicNetworkAddress = localNetworkAddress; } else { // Likewise for public port if (publicNetworkAddress.getPort() == 0) { publicNetworkAddress = new NetworkAddress(publicNetworkAddress.getAddress(), sockAddr.getPort()); } } }
@Test public void failedJobPartitionRequestTest() throws Exception { final NodeControllerService nc1 = integrationUtil.ncs[0]; final NodeControllerService nc2 = integrationUtil.ncs[1]; final JobId failedJob = new JobId(-1); nc2.getPartitionManager().jobCompleted(failedJob, JobStatus.FAILURE); final NetworkAddress localNetworkAddress = nc2.getNetworkManager().getPublicNetworkAddress(); final InetSocketAddress nc2Address = new InetSocketAddress(localNetworkAddress.getAddress(), localNetworkAddress.getPort()); PartitionId id = new PartitionId(failedJob, new ConnectorDescriptorId(1), 0, 1); NetworkInputChannel inputChannel = new NetworkInputChannel(nc1.getNetworkManager(), nc2Address, id, 1); InputChannelFrameReader frameReader = new InputChannelFrameReader(inputChannel); inputChannel.registerMonitor(frameReader); AtomicBoolean failed = new AtomicBoolean(false); Thread reader = new Thread(() -> { try { failed.set(!frameReader.nextFrame(new FixedSizeFrame())); } catch (HyracksDataException e) { e.printStackTrace(); } }); reader.start(); final IHyracksCommonContext context = Mockito.mock(IHyracksCommonContext.class); Mockito.when(context.getInitialFrameSize()).thenReturn(2000); inputChannel.open(context); reader.join(5000); Assert.assertTrue(failed.get()); } }
public NetworkManager(String inetAddress, int inetPort, PartitionManager partitionManager, int nThreads, int nBuffers, String publicInetAddress, int publicInetPort, IChannelInterfaceFactory channelInterfaceFactory, ISocketChannelFactory socketChannelFactory) { this.partitionManager = partitionManager; this.nBuffers = nBuffers; md = new MuxDemux(new InetSocketAddress(inetAddress, inetPort), new ChannelOpenListener(), nThreads, MAX_CONNECTION_ATTEMPTS, channelInterfaceFactory, socketChannelFactory); // Just save these values for the moment; may be reset in start() publicNetworkAddress = new NetworkAddress(publicInetAddress, publicInetPort); }