@Override public String stringFromValue(Object value) { if (value == null) return null; Vdc vdc = (Vdc) value; StringBuilder stringBuilder = new StringBuilder(); String separator = ""; for (Host host : vdc.getHosts()) { stringBuilder.append(separator).append(host.getName()); separator = ","; } return stringBuilder.toString(); } }
@Override public Host resolveHost() { return getVdcs().get(0).getHosts().get(0); }
@Override public String getAsText() { Vdc vdc = (Vdc) getValue(); if (vdc.getHosts().isEmpty()) return ""; List<String> names = new ArrayList<>(); for (Host host : vdc.getHosts()) { names.add(host.getName()); } if (vdc.getName() == null || vdc.getName().equals(vdc.getHosts().get(0).getName())) { return SyncUtil.join(names, ","); } else { return String.format("%s(%s)", vdc.getName(), SyncUtil.join(names, ",")); } }
@ConfigUriProperty(type = ConfigUriProperty.Type.Host) public String getHost() { if (getVdcs() == null || getVdcs().isEmpty()) return null; return getVdcs().get(0).getHosts().get(0).getName(); }
/** * Cloning constructor. */ public ObjectConfig(ObjectConfig<T> other) { this.protocol = other.protocol; // deep copy the VDCs to avoid two clients referencing the same host lists (SDK-122) this.vdcs = new ArrayList<Vdc>(); for (Vdc vdc : other.getVdcs()) { this.vdcs.add(new Vdc(vdc.getName(), vdc.getHosts())); } this.port = other.port; this.smartClient = other.smartClient; this.rootContext = other.rootContext; this.namespace = other.namespace; this.identity = other.identity; this.secretKey = other.secretKey; this.serverClockSkew = other.serverClockSkew; this.userAgent = other.userAgent; this.geoPinningEnabled = other.geoPinningEnabled; this.geoReadRetryFailover = other.geoReadRetryFailover; this.chunkedEncodingSize = other.chunkedEncodingSize; this.properties = new HashMap<String, Object>(other.properties); }
public List<Host> getHostList() { if (vdcs == null || vdcs.isEmpty()) return getDataNodes(loadBalancer.getTopHost(null)); List<Host> hostList = new ArrayList<Host>(); for (Vdc vdc : vdcs) { if (vdc.getHosts().isEmpty()) log.warn("VDC " + vdc.getName() + " has no hosts!"); boolean success = false; for (Host host : vdc) { if (!host.isHealthy()) { // the load balancer manages health checks log.warn("not retrieving node list from " + host.getName() + " because it's unhealthy"); continue; } try { updateVdcNodes(vdc, getDataNodes(host)); success = true; break; } catch (Throwable t) { log.warn("unable to retrieve node list from " + host.getName(), t); } } if (!success) log.warn("could not retrieve node list for VDC " + vdc.getName()); hostList.addAll(vdc.getHosts()); } return hostList; }
vdc.getHosts().add(new VdcHost(vdc, node.getName()));
public SmartConfig toSmartConfig() { List<Host> allHosts = new ArrayList<Host>(); for (Vdc vdc : vdcs) { allHosts.addAll(vdc.getHosts());