Skip to content

Commit ce091de

Browse files
author
Alex Huang
committed
more changes for refactor
1 parent 634b67c commit ce091de

51 files changed

Lines changed: 3564 additions & 471 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎agent/src/com/cloud/agent/Agent.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.cloud.agent.api.UpgradeCommand;
5050
import com.cloud.agent.transport.Request;
5151
import com.cloud.agent.transport.Response;
52-
import com.cloud.agent.transport.UpgradeResponse;
5352
import com.cloud.exception.AgentControlChannelException;
5453
import com.cloud.resource.ServerResource;
5554
import com.cloud.utils.PropertiesUtil;
@@ -302,7 +301,7 @@ public void sendStartup(Link link) {
302301
commands[i] = startup[i];
303302
}
304303

305-
final Request request = new Request(getNextSequence(), _id != null ? _id : -1, -1, commands, false);
304+
final Request request = new Request(getNextSequence(), _id != null ? _id : -1, -1, commands, false, false, false);
306305

307306
if (s_logger.isDebugEnabled()) {
308307
s_logger.debug("Sending Startup: " + request.toString());
@@ -624,7 +623,7 @@ public void unregisterControlListener(IAgentControlListener listener) {
624623
@Override
625624
public AgentControlAnswer sendRequest(AgentControlCommand cmd, int timeoutInMilliseconds) throws AgentControlChannelException {
626625
Request request = new Request(this.getNextSequence(), this.getId(),
627-
-1, new Command[] {cmd}, true, false);
626+
-1, new Command[] {cmd}, true, false, false);
628627
AgentControlListener listener = new AgentControlListener(request);
629628

630629
registerControlListener(listener);
@@ -647,7 +646,7 @@ public AgentControlAnswer sendRequest(AgentControlCommand cmd, int timeoutInMill
647646
@Override
648647
public void postRequest(AgentControlCommand cmd) throws AgentControlChannelException {
649648
Request request = new Request(this.getNextSequence(), this.getId(),
650-
-1, new Command[] {cmd}, true, false);
649+
-1, new Command[] {cmd}, true, false, false);
651650
postRequest(request);
652651
}
653652

@@ -676,11 +675,13 @@ public AgentControlAnswer getAnswer() {
676675
return _answer;
677676
}
678677

679-
public Answer processControlRequest(Request request, AgentControlCommand cmd) {
678+
@Override
679+
public Answer processControlRequest(Request request, AgentControlCommand cmd) {
680680
return null;
681681
}
682682

683-
public void processControlResponse(Response response, AgentControlAnswer answer) {
683+
@Override
684+
public void processControlResponse(Response response, AgentControlAnswer answer) {
684685
if(_request.getSequence() == response.getSequence()) {
685686
_answer = answer;
686687
synchronized(this) {
@@ -778,9 +779,7 @@ public void doTask(final Task task) {
778779
Request request;
779780
try {
780781
request = Request.parse(task.getData());
781-
if (request instanceof UpgradeResponse) {
782-
upgradeAgent(((UpgradeResponse)request).getUpgradeUrl(), null);
783-
} else if (request instanceof Response) {
782+
if (request instanceof Response) {
784783
processResponse((Response)request, task.getLink());
785784
} else {
786785
processRequest(request, task.getLink());

‎api/src/com/cloud/deploy/DeploymentPlanner.java‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,92 @@
33
*/
44
package com.cloud.deploy;
55

6+
import java.util.HashSet;
67
import java.util.Set;
78

9+
import com.cloud.exception.InsufficientServerCapacityException;
10+
import com.cloud.host.Host;
811
import com.cloud.utils.component.Adapter;
912
import com.cloud.vm.VirtualMachineProfile;
1013

14+
/**
15+
* Returns a deployment destination for the VM.
16+
*/
1117
public interface DeploymentPlanner extends Adapter {
12-
DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, Set<DeployDestination> avoid);
18+
/**
19+
* plan is called to determine where a virtual machine should be running.
20+
*
21+
* @param vm virtual machine.
22+
* @param plan deployment plan that tells you where it's being deployed to.
23+
* @param avoid avoid these data centers, pods, clusters, or hosts.
24+
* @return DeployDestination for that virtual machine.
25+
*/
26+
DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException;
27+
28+
/**
29+
* check() is called right before the virtual machine starts to make sure
30+
* the host has enough capacity.
31+
*
32+
* @param vm virtual machine in question.
33+
* @param plan deployment plan used to determined the deploy destination.
34+
* @param dest destination returned by plan.
35+
* @param avoid what to avoid.
36+
* @return true if it's okay to start; false if not. If false, the exclude list will include what should be excluded.
37+
*/
38+
boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude);
39+
40+
public static class ExcludeList {
41+
Set<Long> _dcIds;
42+
Set<Long> _podIds;
43+
Set<Long> _clusterIds;
44+
Set<Long> _hostIds;
45+
46+
public void adddDataCenter(long dataCenterId) {
47+
if (_dcIds == null) {
48+
_dcIds = new HashSet<Long>();
49+
}
50+
_dcIds.add(dataCenterId);
51+
}
52+
53+
public void addPod(long podId) {
54+
if (_podIds == null) {
55+
_podIds = new HashSet<Long>();
56+
}
57+
_podIds.add(podId);
58+
}
59+
60+
public void addCluster(long clusterId) {
61+
if (_clusterIds == null) {
62+
_clusterIds = new HashSet<Long>();
63+
}
64+
_clusterIds.add(clusterId);
65+
}
66+
67+
public void addHost(long hostId) {
68+
if (_hostIds == null) {
69+
_hostIds = new HashSet<Long>();
70+
}
71+
_hostIds.add(hostId);
72+
}
73+
74+
public boolean shouldAvoid(Host host) {
75+
if (_dcIds != null && _dcIds.contains(host.getDataCenterId())) {
76+
return true;
77+
}
78+
79+
if (_podIds != null && _podIds.contains(host.getPodId())) {
80+
return true;
81+
}
82+
83+
if (_clusterIds != null && _clusterIds.contains(host.getClusterId())) {
84+
return true;
85+
}
86+
87+
if (_hostIds != null && _hostIds.contains(host.getId())) {
88+
return true;
89+
}
90+
91+
return false;
92+
}
93+
}
1394
}

core/src/com/cloud/host/InsufficientServerCapacityException.java renamed to api/src/com/cloud/exception/InsufficientServerCapacityException.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*
1717
*/
18-
package com.cloud.host;
18+
package com.cloud.exception;
1919

20-
import com.cloud.exception.InsufficientCapacityException;
2120
import com.cloud.utils.SerialVersionUID;
22-
import com.cloud.vm.VirtualMachine;
2321

2422
/**
2523
* This exception is thrown when a server cannot be found to host the
@@ -30,13 +28,7 @@ public class InsufficientServerCapacityException extends InsufficientCapacityExc
3028

3129
private static final long serialVersionUID = SerialVersionUID.InsufficientServerCapacityException;
3230

33-
VirtualMachine.Type type;
34-
public InsufficientServerCapacityException(VirtualMachine.Type type, String msg) {
31+
public InsufficientServerCapacityException(String msg) {
3532
super(msg);
36-
this.type = type;
37-
}
38-
39-
VirtualMachine.Type getType() {
40-
return type;
4133
}
4234
}

‎api/src/com/cloud/storage/StoragePool.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public interface StoragePool {
7676
* @return available storage in bytes
7777
*/
7878
long getAvailableBytes();
79+
80+
81+
Long getClusterId();
7982

8083
/**
8184
* @return the fqdn or ip address of the storage host

‎api/src/com/cloud/vm/VirtualMachineProfiler.java‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎core/src/com/cloud/agent/Listener.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.cloud.host.Status;
2727

2828
/**
29-
* Listener is a multipurpose interface for hooking into the AgentManager.
29+
* Listener is a multi-purpose interface for hooking into the AgentManager.
3030
* There are several types of events that the AgentManager forwards
3131
* to the listener.
3232
*
@@ -45,7 +45,7 @@ public interface Listener {
4545
* @param answers answers to the commands.
4646
* @return true if processed. false if not.
4747
*/
48-
boolean processAnswer(long agentId, long seq, Answer[] answers);
48+
boolean processAnswers(long agentId, long seq, Answer[] answers);
4949

5050
/**
5151
* This method is called by the AgentManager when an agent sent
@@ -57,7 +57,7 @@ public interface Listener {
5757
* @param commands commands that were sent.
5858
* @return true if you processed the commands. false if not.
5959
*/
60-
boolean processCommand(long agentId, long seq, Command[] commands);
60+
boolean processCommands(long agentId, long seq, Command[] commands);
6161

6262
/**
6363
* process control command sent from agent under its management
@@ -89,7 +89,7 @@ public interface Listener {
8989
boolean processDisconnect(long agentId, Status state);
9090

9191
/**
92-
* If ths Listener is passed to the send() method, this method
92+
* If this Listener is passed to the send() method, this method
9393
* is called by AgentManager after processing an answer
9494
* from the agent. Returning true means you're expecting more
9595
* answers from the agent using the same sequence number.

0 commit comments

Comments
 (0)