Skip to content

Commit 55692fd

Browse files
committed
bug 9127: intermediate checkin for agent load balancer
1 parent 4696e50 commit 55692fd

29 files changed

Lines changed: 1731 additions & 538 deletions

api/src/com/cloud/agent/api/Command.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ public void setContextParam(String name, String value) {
5656
public String getContextParam(String name) {
5757
return contextMap.get(name);
5858
}
59+
60+
public boolean allowCaching() {
61+
return true;
62+
}
5963
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.agent.api;
19+
20+
import com.cloud.host.Status.Event;
21+
22+
public class TransferAgentCommand extends Command {
23+
protected long agentId;
24+
protected long futureOwner;
25+
Event event;
26+
27+
protected TransferAgentCommand() {
28+
}
29+
30+
public TransferAgentCommand(long agentId, long futureOwner, Event event) {
31+
this.agentId = agentId;
32+
this.futureOwner = futureOwner;
33+
this.event = event;
34+
}
35+
36+
public long getAgentId() {
37+
return agentId;
38+
}
39+
40+
public long getFutureOwner() {
41+
return futureOwner;
42+
}
43+
44+
public Event getEvent() {
45+
return event;
46+
}
47+
48+
@Override
49+
public boolean executeInSequence() {
50+
return false;
51+
}
52+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
20+
package com.cloud.cluster;
21+
22+
23+
public interface ManagementServerHost {
24+
25+
public static enum State { Up, Starting, Down };
26+
27+
long getMsid();
28+
29+
State getState();
30+
31+
String getVersion();
32+
33+
}

api/src/com/cloud/host/Status.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public enum Status {
3232
ErrorInMaintenance(false, false, false),
3333
Maintenance(false, false, false),
3434
Alert(true, true, true),
35-
Removed(true, false, true);
35+
Removed(true, false, true),
36+
Rebalance(false, false, false);
3637

3738
private final boolean updateManagementServer;
3839
private final boolean checkManagementServer;
@@ -72,7 +73,11 @@ public enum Event {
7273
WaitedTooLong(false, "Waited too long from the agent to reconnect on its own. Time to do HA"),
7374
Remove(true, "Host is removed"),
7475
Ready(false, "Host is ready for commands"),
75-
UpdatePassword(false, "Update host password from db");
76+
UpdatePassword(false, "Update host password from db"),
77+
RequestAgentRebalance(false, "Request rebalance for the certain host"),
78+
StartAgentRebalance(false, "Start rebalance for the certain host"),
79+
RebalanceCompleted(false, "Host is rebalanced successfully"),
80+
RebalanceFailed(false, "Failed to rebalance the host");
7681

7782
private final boolean isUserRequest;
7883
private final String comment;
@@ -132,6 +137,7 @@ public static String[] toStrings(Status... states) {
132137
s_fsm.addTransition(Status.Up, Event.Ping, Status.Up);
133138
s_fsm.addTransition(Status.Up, Event.AgentConnected, Status.Connecting);
134139
s_fsm.addTransition(Status.Up, Event.ManagementServerDown, Status.Disconnected);
140+
s_fsm.addTransition(Status.Up, Event.StartAgentRebalance, Status.Rebalance);
135141
s_fsm.addTransition(Status.Updating, Event.PingTimeout, Status.Alert);
136142
s_fsm.addTransition(Status.Updating, Event.Ping, Status.Updating);
137143
s_fsm.addTransition(Status.Updating, Event.AgentConnected, Status.Connecting);
@@ -177,6 +183,8 @@ public static String[] toStrings(Status... states) {
177183
s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up);
178184
s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed);
179185
s_fsm.addTransition(Status.Alert, Event.ManagementServerDown, Status.Alert);
186+
s_fsm.addTransition(Status.Rebalance, Event.RebalanceFailed, Status.Alert);
187+
s_fsm.addTransition(Status.Rebalance, Event.RebalanceCompleted, Status.Connecting);
180188
}
181189

182190
public static void main(String[] args) {

client/tomcatconf/components.xml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
<adapters key="com.cloud.acl.SecurityChecker">
9494
<adapter name="DomainChecker" class="com.cloud.acl.DomainChecker"/>
9595
</adapters>
96+
<adapters key="com.cloud.cluster.agentlb">
97+
<adapter name="ClusterBasedAgentLbPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner"/>
98+
</adapters>
9699

97100
</management-server>
98101

deps/XenServerJava/com/xensource/xenapi/Event.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@
3333

3434
package com.xensource.xenapi;
3535

36-
import com.xensource.xenapi.Types.BadServerResponse;
37-
import com.xensource.xenapi.Types.VersionException;
38-
import com.xensource.xenapi.Types.XenAPIException;
39-
4036
import java.io.PrintWriter;
4137
import java.io.StringWriter;
4238
import java.util.Date;
4339
import java.util.HashMap;
44-
import java.util.LinkedHashSet;
4540
import java.util.Map;
4641
import java.util.Set;
4742

4843
import org.apache.xmlrpc.XmlRpcException;
4944

45+
import com.xensource.xenapi.Types.BadServerResponse;
46+
import com.xensource.xenapi.Types.XenAPIException;
47+
5048
/**
5149
* Asynchronous event registration and handling
5250
*
@@ -66,6 +64,7 @@ public class Event extends XenAPIObject {
6664
this.ref = ref;
6765
}
6866

67+
@Override
6968
public String toWireString() {
7069
return this.ref;
7170
}
@@ -96,6 +95,7 @@ public int hashCode()
9695
* Represents all the fields in a Event
9796
*/
9897
public static class Record implements Types.Record {
98+
@Override
9999
public String toString() {
100100
StringWriter writer = new StringWriter();
101101
PrintWriter print = new PrintWriter(writer);
@@ -112,6 +112,7 @@ public String toString() {
112112
/**
113113
* Convert a event.Record to a Map
114114
*/
115+
@Override
115116
public Map<String,Object> toMap() {
116117
Map<String,Object> map = new HashMap<String,Object>();
117118
map.put("id", this.id == null ? 0 : this.id);

server/src/com/cloud/agent/manager/AgentAttache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ public long getId() {
237237
public int getQueueSize() {
238238
return _requests.size();
239239
}
240+
241+
public int getListenersSize() {
242+
return _waitForList.size();
243+
}
240244

241245
public boolean processAnswers(final long seq, final Response resp) {
242246
resp.logD("Processing: ", true);

0 commit comments

Comments
 (0)