List of usage examples for com.google.common.net HostAndPort fromString
public static HostAndPort fromString(String hostPortString)
From source file:org.apache.accumulo.server.util.VerifyTabletAssignments.java
private static void checkTable(final ClientContext context, final Opts opts, String tableName, HashSet<KeyExtent> check) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, InterruptedException { if (check == null) System.out.println("Checking table " + tableName); else/*from ww w. ja v a 2s . co m*/ System.out.println("Checking table " + tableName + " again, failures " + check.size()); TreeMap<KeyExtent, String> tabletLocations = new TreeMap<KeyExtent, String>(); String tableId = Tables.getNameToIdMap(context.getInstance()).get(tableName); MetadataServicer.forTableId(context, tableId).getTabletLocations(tabletLocations); final HashSet<KeyExtent> failures = new HashSet<KeyExtent>(); Map<HostAndPort, List<KeyExtent>> extentsPerServer = new TreeMap<HostAndPort, List<KeyExtent>>(); for (Entry<KeyExtent, String> entry : tabletLocations.entrySet()) { KeyExtent keyExtent = entry.getKey(); String loc = entry.getValue(); if (loc == null) System.out.println(" Tablet " + keyExtent + " has no location"); else if (opts.verbose) System.out.println(" Tablet " + keyExtent + " is located at " + loc); if (loc != null) { final HostAndPort parsedLoc = HostAndPort.fromString(loc); List<KeyExtent> extentList = extentsPerServer.get(parsedLoc); if (extentList == null) { extentList = new ArrayList<KeyExtent>(); extentsPerServer.put(parsedLoc, extentList); } if (check == null || check.contains(keyExtent)) extentList.add(keyExtent); } } ExecutorService tp = Executors.newFixedThreadPool(20); for (final Entry<HostAndPort, List<KeyExtent>> entry : extentsPerServer.entrySet()) { Runnable r = new Runnable() { @Override public void run() { try { checkTabletServer(context, entry, failures); } catch (Exception e) { log.error("Failure on tablet server '" + entry.getKey() + ".", e); failures.addAll(entry.getValue()); } } }; tp.execute(r); } tp.shutdown(); while (!tp.awaitTermination(1, TimeUnit.HOURS)) { } if (failures.size() > 0) checkTable(context, opts, tableName, failures); }
From source file:org.apache.tamaya.consul.AbstractConsulPropertySource.java
/** * Set the consol server to connect to./*from ww w.j ava 2 s . c o m*/ * @param server the server list, not null. */ public void setServer(List<String> server) { if (!Objects.equals(getServer(), server)) { List<HostAndPort> consulBackends = new ArrayList<>(); for (String s : server) { consulBackends.add(HostAndPort.fromString(s)); } this.consulBackends = consulBackends; refresh(); } }
From source file:com.streamsets.pipeline.lib.kafka.BaseKafkaValidationUtil.java
@Override public List<HostAndPort> validateZkConnectionString(List<Stage.ConfigIssue> issues, String connectString, String configGroupName, String configName, Stage.Context context) { List<HostAndPort> kafkaBrokers = new ArrayList<>(); if (connectString == null || connectString.isEmpty()) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_06, configName)); return kafkaBrokers; }//from www. j a va 2 s . c o m String chrootPath; int off = connectString.indexOf('/'); if (off >= 0) { chrootPath = connectString.substring(off); // ignore a single "/". Same as null. Anything longer must be validated if (chrootPath.length() > 1) { try { PathUtils.validatePath(chrootPath); } catch (IllegalArgumentException e) { LOG.error(Utils.format(KafkaErrors.KAFKA_09.getMessage(), connectString, e.toString())); issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, e.toString())); } } connectString = connectString.substring(0, off); } String brokers[] = connectString.split(","); for (String broker : brokers) { try { HostAndPort hostAndPort = HostAndPort.fromString(broker); if (!hostAndPort.hasPort() || hostAndPort.getPort() < 0) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, "Valid port must be specified")); } else { kafkaBrokers.add(hostAndPort); } } catch (IllegalArgumentException e) { LOG.error(Utils.format(KafkaErrors.KAFKA_09.getMessage(), connectString, e.toString())); issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, e.toString())); } } return kafkaBrokers; }
From source file:brooklyn.networking.vclouddirector.natservice.resources.NatServiceResource.java
@Override public Response closePortForwarding(String endpoint, String vDC, String identity, String credential, String protocol, String original, String translated) { LOG.info("deleting nat rule {} {} -> {}, on {} @ {} (vDC {})", new Object[] { protocol, original, translated, identity, endpoint, vDC }); // TODO throw 404 if not found HostAndPort originalHostAndPort = HostAndPort.fromString(original); HostAndPort translatedHostAndPort = HostAndPort.fromString(translated); Preconditions.checkArgument(originalHostAndPort.hasPort(), "original %s must include port", original); Preconditions.checkArgument(translatedHostAndPort.hasPort(), "translated %s must include port", translated); try {// w w w . ja va 2 s. c o m dispatcher().closePortForwarding(endpoint, vDC, identity, credential, new PortForwardingConfig().protocol(Protocol.valueOf(protocol.toUpperCase())) .publicEndpoint(originalHostAndPort).targetEndpoint(translatedHostAndPort)); return Response.status(Response.Status.OK).build(); } catch (Exception e) { throw Exceptions.propagate(e); } }
From source file:org.apache.accumulo.core.client.impl.Writer.java
public void update(Mutation m) throws AccumuloException, AccumuloSecurityException, ConstraintViolationException, TableNotFoundException { checkArgument(m != null, "m is null"); if (m.size() == 0) throw new IllegalArgumentException("Can not add empty mutations"); while (true) { TabletLocation tabLoc = TabletLocator.getLocator(context, tableId).locateTablet(context, new Text(m.getRow()), false, true); if (tabLoc == null) { log.trace("No tablet location found for row " + new String(m.getRow(), UTF_8)); sleepUninterruptibly(500, TimeUnit.MILLISECONDS); continue; }// w w w . j a va 2 s . c o m final HostAndPort parsedLocation = HostAndPort.fromString(tabLoc.tablet_location); try { updateServer(context, m, tabLoc.tablet_extent, parsedLocation); return; } catch (NotServingTabletException e) { log.trace("Not serving tablet, server = " + parsedLocation); TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent); } catch (ConstraintViolationException cve) { log.error("error sending update to " + parsedLocation + ": " + cve); // probably do not need to invalidate cache, but it does not hurt TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent); throw cve; } catch (TException e) { log.error("error sending update to " + parsedLocation + ": " + e); TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.tablet_extent); } sleepUninterruptibly(500, TimeUnit.MILLISECONDS); } }
From source file:com.basho.riak.presto.RiakClient.java
public void register() throws InterruptedException { String host = HostAndPort.fromString(config.getHost()).getHostText(); log.debug("presto port ===> %s:%s", host, config.getPrestoPort()); // riak.erlang.node => { presto.erlang.node, node.ip, http-server.http.port } PairwiseNode pairNode = new PairwiseNode(config.getLocalNode(), host, config.getPrestoPort()); RiakObject obj = new RiakObject(); obj.setContentType("application/json"); obj.setValue(BinaryValue.create(pairNode.toString())); log.debug("Registering membership: %s", pairNode.toString()); log.info("localnode: %s", config.getLocalNode()); BinaryValue localNode = BinaryValue.create(config.getLocalNode()); StoreOperation op = new StoreOperation.Builder(new Location(NAMESPACE, localNode)).withContent(obj).build(); cluster.execute(op);/*from w ww . j ava2 s . c om*/ op.await(); if (op.isSuccess()) { log.info("membership registered: %s => %s:%s", config.getLocalNode(), pairNode.getHost(), pairNode.getPort()); } else { log.error("failed to register membership"); } }
From source file:org.apache.accumulo.server.watcher.MonitorLog4jWatcher.java
/** * Read the host and port information for the Monitor's log4j socket and update the system properties so that, on logger refresh, it sees the new information. *///from w w w . jav a 2 s .c o m protected void updateMonitorLog4jLocation() { try { String hostPortString = new String(ZooReaderWriter.getInstance().getData(path, null), UTF_8); HostAndPort hostAndPort = HostAndPort.fromString(hostPortString); System.setProperty(HOST_PROPERTY_NAME, hostAndPort.getHostText()); System.setProperty(PORT_PROPERTY_NAME, Integer.toString(hostAndPort.getPort())); log.info("Changing monitor log4j address to " + hostAndPort.toString()); doOnChange(); } catch (NoNodeException e) { // Not sure on the synchronization guarantees for Loggers and Appenders // on configuration reload synchronized (lock) { // Don't need to try to re-disable'ing it. if (loggingDisabled) { return; } Logger logger = LogManager.getLogger("org.apache.accumulo"); if (null != logger) { // TODO ACCUMULO-2343 Create a specific appender for log-forwarding to the monitor // that can replace the AsyncAppender+SocketAppender. Appender appender = logger.getAppender("ASYNC"); if (null != appender) { log.info("Closing log-forwarding appender"); appender.close(); log.info("Removing log-forwarding appender"); logger.removeAppender(appender); loggingDisabled = true; } } } } catch (IllegalArgumentException e) { log.error("Could not parse host and port information", e); } catch (Exception e) { log.error("Error reading zookeeper data for Monitor Log4j watcher", e); } }
From source file:org.sonar.application.config.ClusterSettings.java
private static InetAddress convertToInetAddress(String text, String key) { InetAddress inetAddress;//from ww w . j ava 2 s .com HostAndPort hostAndPort = HostAndPort.fromString(text); if (!InetAddresses.isInetAddress(hostAndPort.getHostText())) { try { inetAddress = InetAddress.getByName(hostAndPort.getHostText()); } catch (UnknownHostException e) { throw new MessageException(format("The interface address [%s] of [%s] cannot be resolved : %s", text, key, e.getMessage())); } } else { inetAddress = forString(hostAndPort.getHostText()); } return inetAddress; }
From source file:io.druid.server.DruidNode.java
/** * Returns host and port together as something that can be used as part of a URI. *///w ww . ja v a2s . com public String getHostAndPort() { if (port < 0) { return HostAndPort.fromString(host).toString(); } else { return HostAndPort.fromParts(host, port).toString(); } }
From source file:org.apache.accumulo.server.master.state.ZooTabletStateStore.java
protected TServerInstance parse(byte[] current) { String str = new String(current, UTF_8); String[] parts = str.split("[|]", 2); HostAndPort address = HostAndPort.fromString(parts[0]); if (parts.length > 1 && parts[1] != null && parts[1].length() > 0) { return new TServerInstance(address, parts[1]); } else {/*from w ww . j a v a2 s. c om*/ // a 1.2 location specification: DO NOT WANT return null; } }