/** * Returns a list of LogMessages from the thrift version. */ static List<NetworkAddress> fromThrift(List<TNetworkAddress> list) { List<NetworkAddress> result = new ArrayList<NetworkAddress>(); for (TNetworkAddress l: list) { result.add(new NetworkAddress(l)); } return result; } }
Task(TTask t) { localHosts = NetworkAddress.fromThrift(t.local_hosts); task = t.task.array(); taskId = new UniqueId(t.task_id); resultsOrdered = t.results_ordered; taskSize = t.task_size; }
@Override public void readFields(DataInput in) throws IOException { task_ = Task.deserialize(in); int numWorkers = in.readInt(); workerAddresses_ = new ArrayList<NetworkAddress>(); for (int i = 0; i < numWorkers; ++i) { int hostnameLen = in.readInt(); byte[] hostnameBuffer = new byte[hostnameLen]; in.readFully(hostnameBuffer); int port = in.readInt(); workerAddresses_.add(new NetworkAddress(new String(hostnameBuffer), port)); } } }
public PlanRequestResult(TPlanRequestResult result) { tasks = Task.fromThrift(result.tasks); schema = new Schema(result.schema); requestId = new UniqueId(result.request_id); hosts = NetworkAddress.fromThrift(result.hosts); warnings = LogMessage.fromThrift(result.warnings); } }
/** * Returns a random hostport from plannerHostPortsStr. Each hostport should be * comma separated. */ public static List<NetworkAddress> getPlannerHostPort(String plannerHostPortsStr) throws IOException { String[] plannerHostPorts = plannerHostPortsStr.trim().split(","); if (plannerHostPorts.length == 0) { throw new IOException("Invalid planner host port list: " + plannerHostPortsStr); } List<NetworkAddress> result = new ArrayList<NetworkAddress>(); for (String hostPortStr: plannerHostPorts) { if (hostPortStr.length() == 0) continue; String[] hostPort = hostPortStr.split(":"); if (hostPort.length != 2) { throw new IOException("Invalid hostport: " + hostPortStr); } String host = hostPort[0]; int port = 0; try { port = Integer.parseInt(hostPort[1]); } catch (NumberFormatException e) { throw new IOException("Invalid hostport: " + hostPortStr); } result.add(new NetworkAddress(host, port)); } return result; } }
/** * Parse ZK path string in the format of * <code>/recordservice/planners/recordserviced@hostname:port</code> * to a corresponding <code>NetWorkAddress</code> * Returns null if the path is of illegal format. */ private static NetworkAddress parsePath(String path) { String hostname; int port; try { int atIdx = path.indexOf('@'); if (atIdx < 0) { throw new IOException("Couldn't locate '@' in path: " + path); } int colonIdx = path.indexOf(':', atIdx + 1); if (colonIdx < 0) { throw new IOException("Couldn't locate ':' in path: " + path); } hostname = path.substring(atIdx + 1, colonIdx); try { port = Integer.parseInt(path.substring(colonIdx + 1, path.length())); } catch (NumberFormatException e) { throw new IOException("Couldn't parse port number in path: " + path, e); } } catch (IOException e) { LOGGER.warn("Error while parsing input path", e); return null; } return new NetworkAddress(hostname, port); }
/** * Deserializes Task from 'in' */ public static Task deserialize(DataInput in) throws IOException { int numLocalHosts = in.readInt(); List<NetworkAddress> localHosts = new ArrayList<NetworkAddress>(); for (int i = 0; i < numLocalHosts; ++i) { int hostnameLen = in.readInt(); byte[] hostnameBuffer = new byte[hostnameLen]; in.readFully(hostnameBuffer); int port = in.readInt(); localHosts.add(new NetworkAddress(new String(hostnameBuffer), port)); } int taskLen = in.readInt(); byte[] taskBuffer = new byte[taskLen]; in.readFully(taskBuffer); UniqueId id = new UniqueId(in.readLong(), in.readLong()); boolean resultsOrdered = in.readBoolean(); long taskSize = in.readLong(); int tagLen = in.readInt(); byte[] tagBuffer = new byte[tagLen]; in.readFully(tagBuffer); String tag = new String(tagBuffer); return new Task(localHosts, taskBuffer, id, resultsOrdered, taskSize, tag); }