Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arnett, stu committed Jun 30, 2015
1 parent 956f6de commit 549aa22
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 13 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/emc/rest/smart/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Host> updatedHosts) throws Exception {
// don't modify the parameter
List<Host> hostList = new ArrayList<Host>(updatedHosts);
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/emc/rest/smart/ecs/EcsHostListProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,19 @@ protected String getSignature(String canonicalString, String secret) throws Exce
protected void updateVdcNodes(Vdc vdc, List<Host> nodeList) {
if (nodeList == null || nodeList.isEmpty()) throw new RuntimeException("node list is empty");

// make sure the hosts are associated with the VDC first
List<VdcHost> vdcNodeList = new ArrayList<VdcHost>();
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<Host> vdcI = vdc.iterator(); vdcI.hasNext(); ) {
Host vdcHost = vdcI.next();
for (Iterator<VdcHost> vdcI = vdc.iterator(); vdcI.hasNext(); ) {
VdcHost vdcHost = vdcI.next();
boolean hostPresent = false;
for (Iterator<Host> nodeI = nodeList.iterator(); nodeI.hasNext(); ) {
Host node = nodeI.next();
for (Iterator<VdcHost> nodeI = vdcNodeList.iterator(); nodeI.hasNext(); ) {
VdcHost node = nodeI.next();

// already aware of this node; remove from new node list
if (vdcHost.equals(node)) {
Expand All @@ -183,9 +189,9 @@ protected void updateVdcNodes(Vdc vdc, List<Host> 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()));
}
}

Expand Down
38 changes: 31 additions & 7 deletions src/main/java/com/emc/rest/smart/ecs/Vdc.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
import java.util.Iterator;
import java.util.List;

public class Vdc implements Iterable<Host> {
public class Vdc implements Iterable<VdcHost> {
private String name;
private List<Host> hosts;
private List<VdcHost> hosts;

public Vdc(String... hostNames) {
this.name = hostNames[0];
hosts = new ArrayList<Host>();
hosts = new ArrayList<VdcHost>();
for (String hostName : hostNames) {
hosts.add(new Host(hostName));
hosts.add(new VdcHost(this, hostName));
}
}

Expand All @@ -50,11 +50,11 @@ public Vdc(List<Host> hosts) {

public Vdc(String name, List<Host> hosts) {
this.name = name;
this.hosts = hosts;
this.hosts = createVdcHosts(hosts);
}

@Override
public Iterator<Host> iterator() {
public Iterator<VdcHost> iterator() {
return hosts.iterator();
}

Expand All @@ -65,6 +65,30 @@ public boolean isHealthy() {
return true;
}

protected List<VdcHost> createVdcHosts(List<Host> hosts) {
List<VdcHost> vdcHosts = new ArrayList<VdcHost>();
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;
}
Expand All @@ -73,7 +97,7 @@ public void setName(String name) {
this.name = name;
}

public List<Host> getHosts() {
public List<VdcHost> getHosts() {
return hosts;
}

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/com/emc/rest/smart/ecs/VdcHost.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 549aa22

Please sign in to comment.