From 549aa22060710fa39f360a8aa7b8321955ead860 Mon Sep 17 00:00:00 2001 From: "arnett, stu" Date: Tue, 30 Jun 2015 12:06:06 -0400 Subject: [PATCH] v2.0.1 --- .../java/com/emc/rest/smart/LoadBalancer.java | 24 +++++++ .../rest/smart/ecs/EcsHostListProvider.java | 18 +++-- src/main/java/com/emc/rest/smart/ecs/Vdc.java | 38 +++++++++-- .../java/com/emc/rest/smart/ecs/VdcHost.java | 66 +++++++++++++++++++ 4 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/emc/rest/smart/ecs/VdcHost.java diff --git a/src/main/java/com/emc/rest/smart/LoadBalancer.java b/src/main/java/com/emc/rest/smart/LoadBalancer.java index 94e8532..14ccf1c 100644 --- a/src/main/java/com/emc/rest/smart/LoadBalancer.java +++ b/src/main/java/com/emc/rest/smart/LoadBalancer.java @@ -105,6 +105,30 @@ public void resetStats() { } } + public long getTotalConnections() { + long totalConnections = 0; + for (Host host : getAllHosts()) { + totalConnections += host.getTotalConnections(); + } + return totalConnections; + } + + public long getTotalErrors() { + long totalErrors = 0; + for (Host host : getAllHosts()) { + totalErrors += host.getTotalErrors(); + } + return totalErrors; + } + + public long getOpenConnections() { + long openConnections = 0; + for (Host host : getAllHosts()) { + openConnections += host.getOpenConnections(); + } + return openConnections; + } + protected void updateHosts(List updatedHosts) throws Exception { // don't modify the parameter List hostList = new ArrayList(updatedHosts); diff --git a/src/main/java/com/emc/rest/smart/ecs/EcsHostListProvider.java b/src/main/java/com/emc/rest/smart/ecs/EcsHostListProvider.java index bb0f33b..820bf82 100644 --- a/src/main/java/com/emc/rest/smart/ecs/EcsHostListProvider.java +++ b/src/main/java/com/emc/rest/smart/ecs/EcsHostListProvider.java @@ -160,13 +160,19 @@ protected String getSignature(String canonicalString, String secret) throws Exce protected void updateVdcNodes(Vdc vdc, List nodeList) { if (nodeList == null || nodeList.isEmpty()) throw new RuntimeException("node list is empty"); + // make sure the hosts are associated with the VDC first + List vdcNodeList = new ArrayList(); + for (Host host : nodeList) { + vdcNodeList.add(new VdcHost(vdc, host.getName())); + } + // we need to maintain references to existing hosts to preserve health status, which is managed by the load // balancer - for (Iterator vdcI = vdc.iterator(); vdcI.hasNext(); ) { - Host vdcHost = vdcI.next(); + for (Iterator vdcI = vdc.iterator(); vdcI.hasNext(); ) { + VdcHost vdcHost = vdcI.next(); boolean hostPresent = false; - for (Iterator nodeI = nodeList.iterator(); nodeI.hasNext(); ) { - Host node = nodeI.next(); + for (Iterator nodeI = vdcNodeList.iterator(); nodeI.hasNext(); ) { + VdcHost node = nodeI.next(); // already aware of this node; remove from new node list if (vdcHost.equals(node)) { @@ -183,9 +189,9 @@ protected void updateVdcNodes(Vdc vdc, List nodeList) { } // add any remaining new hosts we weren't previously aware of - for (Host node : nodeList) { + for (VdcHost node : vdcNodeList) { l4j.info("adding host " + node.getName() + " to VDC " + vdc.getName()); - vdc.getHosts().add(node); + vdc.getHosts().add(new VdcHost(vdc, node.getName())); } } diff --git a/src/main/java/com/emc/rest/smart/ecs/Vdc.java b/src/main/java/com/emc/rest/smart/ecs/Vdc.java index d6213fc..30f1343 100644 --- a/src/main/java/com/emc/rest/smart/ecs/Vdc.java +++ b/src/main/java/com/emc/rest/smart/ecs/Vdc.java @@ -32,15 +32,15 @@ import java.util.Iterator; import java.util.List; -public class Vdc implements Iterable { +public class Vdc implements Iterable { private String name; - private List hosts; + private List hosts; public Vdc(String... hostNames) { this.name = hostNames[0]; - hosts = new ArrayList(); + hosts = new ArrayList(); for (String hostName : hostNames) { - hosts.add(new Host(hostName)); + hosts.add(new VdcHost(this, hostName)); } } @@ -50,11 +50,11 @@ public Vdc(List hosts) { public Vdc(String name, List hosts) { this.name = name; - this.hosts = hosts; + this.hosts = createVdcHosts(hosts); } @Override - public Iterator iterator() { + public Iterator iterator() { return hosts.iterator(); } @@ -65,6 +65,30 @@ public boolean isHealthy() { return true; } + protected List createVdcHosts(List hosts) { + List vdcHosts = new ArrayList(); + for (Host host : hosts) { + vdcHosts.add(new VdcHost(this, host.getName())); + } + return vdcHosts; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Vdc)) return false; + + Vdc vdc = (Vdc) o; + + return getName().equals(vdc.getName()); + + } + + @Override + public int hashCode() { + return getName().hashCode(); + } + public String getName() { return name; } @@ -73,7 +97,7 @@ public void setName(String name) { this.name = name; } - public List getHosts() { + public List getHosts() { return hosts; } diff --git a/src/main/java/com/emc/rest/smart/ecs/VdcHost.java b/src/main/java/com/emc/rest/smart/ecs/VdcHost.java new file mode 100644 index 0000000..d51274c --- /dev/null +++ b/src/main/java/com/emc/rest/smart/ecs/VdcHost.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, EMC Corporation. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * + Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + The name of EMC Corporation may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.emc.rest.smart.ecs; + +import com.emc.rest.smart.Host; + +public class VdcHost extends Host { + private Vdc vdc; + + public VdcHost(Vdc vdc, String name) { + super(name); + this.vdc = vdc; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof VdcHost)) return false; + if (!super.equals(o)) return false; + + VdcHost vdcHost = (VdcHost) o; + + return getVdc().equals(vdcHost.getVdc()); + + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + getVdc().hashCode(); + return result; + } + + @Override + public String toString() { + return vdc.getName() + ":" + super.toString(); + } + + public Vdc getVdc() { + return vdc; + } +}