private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeObject(location.toString()); }
public AssignmentTask(Map<Path,List<KeyExtent>> assignmentFailures, String location, Map<KeyExtent,List<PathSize>> assignmentsPerTablet) { this.assignmentFailures = assignmentFailures; this.location = HostAndPort.fromString(location); this.assignmentsPerTablet = assignmentsPerTablet; }
/** * Creates a TThreadPoolServer for normal unsecure operation. Useful for comparing performance * against SSL or SASL transports. * * @param address * Address to bind to * @param processor * TProcessor for the server * @param maxMessageSize * Maximum size of a Thrift message allowed * @return A configured TThreadPoolServer and its bound address information */ public static ServerAddress createBlockingServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long maxMessageSize, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws TTransportException { InetSocketAddress isa = new InetSocketAddress(address.getHost(), address.getPort()); // Must use an ISA, providing only a port would ignore the hostname given TServerSocket transport = new TServerSocket(isa); ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSimpleTimerThreads, timeBetweenThreadChecks); TThreadPoolServer server = createTThreadPoolServer(transport, processor, ThriftUtil.transportFactory(maxMessageSize), protocolFactory, pool); if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort()); log.info("Blocking Server bound on {}", address); } return new ServerAddress(server, address); }
public static HostAndPort parseAddress(String address, boolean ignoreMissingPort) throws NumberFormatException { address = address.replace('+', ':'); HostAndPort hap = HostAndPort.fromString(address); if (!ignoreMissingPort && !hap.hasPort()) throw new IllegalArgumentException( "Address was expected to contain port. address=" + address); return hap; }
/** * Build a HostAndPort instance from separate host and port values. * * <p> * Note: Non-bracketed IPv6 literals are allowed. Use #requireBracketsForIPv6() to prohibit these. * * @param host * the host string to parse. Must not contain a port number. * @param port * a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException * if {@code host} contains a port number, or {@code port} is out of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
try { String hostPortString = new String(ZooReaderWriter.getInstance().getData(path, null), UTF_8); HostAndPort hostAndPort = HostAndPort.fromString(hostPortString); System.setProperty(HOST_PROPERTY_NAME, hostAndPort.getHost()); System.setProperty(PORT_PROPERTY_NAME, Integer.toString(hostAndPort.getPort())); log.info("Changing monitor log4j address to " + hostAndPort.toString());
public static MasterClientService.Client getConnection(ClientContext context) { checkArgument(context != null, "context is null"); List<String> locations = context.getMasterLocations(); if (locations.size() == 0) { log.debug("No masters..."); return null; } HostAndPort master = HostAndPort.fromString(locations.get(0)); if (master.getPort() == 0) return null; try { // Master requests can take a long time: don't ever time out return ThriftUtil.getClientNoTimeout(new MasterClientService.Client.Factory(), master, context); } catch (TTransportException tte) { Throwable cause = tte.getCause(); if (cause != null && cause instanceof UnknownHostException) { // do not expect to recover from this throw new RuntimeException(tte); } log.debug("Failed to connect to master=" + master + ", will retry... ", tte); return null; } }
final long MAX = 700L; long total = 0; final HostAndPort hostAndPort = HostAndPort.fromString(zooKeepers); for (int i = 0; i < 5; i++) { Socket socket = new Socket(hostAndPort.getHost(), hostAndPort.getPort()); try { socket.getOutputStream().write("wchs\n".getBytes(), 0, 5);
public String host() { return getLocation().getHost(); }
/** * * @param hostname * name of the host * @param ports * array of ports * @return array of HostAndPort objects */ public static HostAndPort[] getHostAndPorts(String hostname, int[] ports) { HostAndPort[] addresses = new HostAndPort[ports.length]; for (int i = 0; i < ports.length; i++) { addresses[i] = HostAndPort.fromParts(hostname, ports[i]); } return addresses; }
private void addBlocks(VolumeManager fs, String host, ArrayList<String> files, Map<String,Long> totalBlocks, Map<String,Long> localBlocks) throws Exception { long allBlocks = 0; long matchingBlocks = 0; if (!totalBlocks.containsKey(host)) { totalBlocks.put(host, 0L); localBlocks.put(host, 0L); } for (String file : files) { Path filePath = new Path(file); FileSystem ns = fs.getVolumeByPath(filePath).getFileSystem(); FileStatus fileStatus = ns.getFileStatus(filePath); BlockLocation[] fileBlockLocations = ns.getFileBlockLocations(fileStatus, 0, fileStatus.getLen()); for (BlockLocation blockLocation : fileBlockLocations) { allBlocks++; for (String location : blockLocation.getHosts()) { HostAndPort hap = HostAndPort.fromParts(location, 0); if (hap.getHost().equals(host)) { matchingBlocks++; break; } } } } totalBlocks.put(host, allBlocks + totalBlocks.get(host)); localBlocks.put(host, matchingBlocks + localBlocks.get(host)); }
@Override public AppenderSkeleton apply(MonitorLocation loc) { int defaultPort = Integer.parseUnsignedInt(Property.MONITOR_LOG4J_PORT.getDefaultValue()); HostAndPort remote = HostAndPort.fromString(loc.getLocation()); SocketAppender socketAppender = new SocketAppender(); socketAppender.setApplication(System.getProperty("accumulo.application", "unknown")); socketAppender.setRemoteHost(remote.getHost()); socketAppender.setPort(remote.getPortOrDefault(defaultPort)); return socketAppender; } }
? Property.TSERV_MAX_MESSAGE_SIZE : Property.GENERAL_MAX_MESSAGE_SIZE); ServerAddress sp = TServerUtils.startServer(context, clientAddress.getHost(), Property.REPLICATION_RECEIPT_SERVICE_PORT, processor, "ReplicationServicerHandler", "Replication Servicer", Property.TSERV_PORTSEARCH, Property.REPLICATION_MIN_THREADS, sp.address.toString().getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); } catch (Exception e) { log.error("Could not advertise replication service port", e);
HostAndPort address = HostAndPort.fromString(tl.tablet_location); throw new AccumuloServerException(address.toString(), tae); } catch (TTransportException e) { tabLocator.invalidateCache(context, tl.tablet_location);
private static List<KeyExtent> findTablets(ClientContext context, boolean selectLocalTablets, String tableName, SortedMap<KeyExtent,String> tabletLocations) throws Exception { String tableId = Tables.getNameToIdMap(context.getInstance()).get(tableName); MetadataServicer.forTableId(context, tableId).getTabletLocations(tabletLocations); InetAddress localaddress = InetAddress.getLocalHost(); List<KeyExtent> candidates = new ArrayList<>(); for (Entry<KeyExtent,String> entry : tabletLocations.entrySet()) { String loc = entry.getValue(); if (loc != null) { boolean isLocal = HostAndPort.fromString(entry.getValue()).getHost() .equals(localaddress.getHostName()); if (selectLocalTablets && isLocal) { candidates.add(entry.getKey()); } else if (!selectLocalTablets && !isLocal) { candidates.add(entry.getKey()); } } } return candidates; }
for (int port = last.getPort() + 1; port < last.getPort() + 1001; port++) { if (port > 65535) { break; HostAndPort addr = HostAndPort.fromParts(hostname, port); return TServerUtils.startTServer(serverType, timedProcessor, serverName, threadName, minThreads, simpleTimerThreadpoolSize, timeBetweenThreadChecks, maxMessageSize,
@Override public boolean equals(Object rhsObject) { if (!(rhsObject instanceof SuspendingTServer)) { return false; } SuspendingTServer rhs = (SuspendingTServer) rhsObject; return server.equals(rhs.server) && suspensionTime == rhs.suspensionTime; }
log.info("Restarting " + restartedServer); getCluster().getClusterControl().start(ServerType.TABLET_SERVER, null, ImmutableMap.of(Property.TSERV_CLIENTPORT.getKey(), "" + restartedServer.getPort(), Property.TSERV_PORTSEARCH.getKey(), "false"), 1);