Skip to content

Commit 46e644e

Browse files
author
Alex Huang
committed
Separate agentmanager from server code. Moved out ssvm. Remove methods that shouldn't be used
1 parent f0f5522 commit 46e644e

10 files changed

Lines changed: 23 additions & 293 deletions

File tree

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager {
6060
private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class);
61-
private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
61+
private final Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
6262
@Inject
6363
HostDao hostDao;
6464
@Inject
@@ -222,12 +222,6 @@ public void unregisterForHostEvents(int id) {
222222

223223
}
224224

225-
@Override
226-
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
227-
// TODO Auto-generated method stub
228-
return false;
229-
}
230-
231225
@Override
232226
public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
233227
// TODO Auto-generated method stub
@@ -253,12 +247,6 @@ public boolean agentStatusTransitTo(HostVO host, Event e, long msId) {
253247
return false;
254248
}
255249

256-
@Override
257-
public AgentAttache findAttache(long hostId) {
258-
// TODO Auto-generated method stub
259-
return null;
260-
}
261-
262250
@Override
263251
public void disconnectWithoutInvestigation(long hostId, Event event) {
264252
// TODO Auto-generated method stub
@@ -284,15 +272,9 @@ public boolean reconnect(long hostId) {
284272
}
285273

286274
@Override
287-
public Answer sendToSSVM(Long dcId, Command cmd) {
288-
// TODO Auto-generated method stub
289-
return null;
290-
}
291-
292-
@Override
293-
public void disconnectWithInvestigation(long hostId, Event event) {
275+
public boolean isAgentAttached(long hostId) {
294276
// TODO Auto-generated method stub
295-
277+
return false;
296278
}
297279

298280
}

server/src/com/cloud/agent/AgentManager.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package com.cloud.agent;
1818

19-
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
20-
2119
import com.cloud.agent.api.Answer;
2220
import com.cloud.agent.api.Command;
2321
import com.cloud.agent.api.StartupCommand;
@@ -28,7 +26,6 @@
2826
import com.cloud.exception.OperationTimedoutException;
2927
import com.cloud.host.HostVO;
3028
import com.cloud.host.Status;
31-
import com.cloud.host.Status.Event;
3229
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3330
import com.cloud.resource.ServerResource;
3431
import com.cloud.utils.component.Manager;
@@ -133,8 +130,6 @@ public enum TapAgentsAction {
133130
*/
134131
void unregisterForHostEvents(int id);
135132

136-
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException;
137-
138133
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
139134

140135

@@ -145,7 +140,7 @@ public enum TapAgentsAction {
145140

146141
public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId);
147142

148-
public AgentAttache findAttache(long hostId);
143+
boolean isAgentAttached(long hostId);
149144

150145
void disconnectWithoutInvestigation(long hostId, Status.Event event);
151146

@@ -154,7 +149,4 @@ public enum TapAgentsAction {
154149
public void pullAgentOutMaintenance(long hostId);
155150

156151
boolean reconnect(long hostId);
157-
Answer sendToSSVM(Long dcId, final Command cmd);
158-
159-
void disconnectWithInvestigation(final long hostId, final Status.Event event);
160152
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public void cleanup(final Status state) {
329329
public boolean equals(Object obj) {
330330
try {
331331
AgentAttache that = (AgentAttache) obj;
332-
return this._id == that._id;
332+
return _id == that._id;
333333
} catch (ClassCastException e) {
334334
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to AgentAttache.equals()? ";
335335
return false;
@@ -485,12 +485,6 @@ public void process(Answer[] answers) {
485485
*/
486486
public abstract void send(Request req) throws AgentUnavailableException;
487487

488-
/**
489-
* Update password.
490-
* @param new/changed password.
491-
*/
492-
public abstract void updatePassword(Command new_password);
493-
494488
/**
495489
* Process disconnect.
496490
* @param state state of the agent.

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

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@
123123
import com.cloud.vm.VirtualMachineManager;
124124
import com.cloud.vm.dao.VMInstanceDao;
125125

126-
import edu.emory.mathcs.backport.java.util.Collections;
127-
128126
/**
129127
* Implementation of the Agent Manager. This class controls the connection to the agents.
130128
*
@@ -372,7 +370,6 @@ public void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers) {
372370
}
373371
}
374372

375-
@Override
376373
public AgentAttache findAttache(long hostId) {
377374
AgentAttache attache = null;
378375
synchronized (_agents) {
@@ -381,29 +378,6 @@ public AgentAttache findAttache(long hostId) {
381378
return attache;
382379
}
383380

384-
385-
386-
private void sendToSSVM(final long dcId, final Command cmd, final Listener listener) throws AgentUnavailableException {
387-
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
388-
if (ssAHosts == null || ssAHosts.isEmpty() ) {
389-
throw new AgentUnavailableException("No ssvm host found", -1);
390-
}
391-
Collections.shuffle(ssAHosts);
392-
HostVO ssAhost = ssAHosts.get(0);
393-
send(ssAhost.getId(), new Commands(cmd), listener);
394-
}
395-
396-
@Override
397-
public Answer sendToSSVM(final Long dcId, final Command cmd) {
398-
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
399-
if (ssAHosts == null || ssAHosts.isEmpty() ) {
400-
return new Answer(cmd, false, "can not find secondary storage VM agent for data center " + dcId);
401-
}
402-
Collections.shuffle(ssAHosts);
403-
HostVO ssAhost = ssAHosts.get(0);
404-
return easySend(ssAhost.getId(), cmd);
405-
}
406-
407381
@Override
408382
public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
409383
List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, type.toString());
@@ -1044,7 +1018,6 @@ public boolean reconnect(final long hostId) {
10441018
return true;
10451019
}
10461020

1047-
@Override
10481021
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
10491022
if (event == Event.AgentDisconnected) {
10501023
if (s_logger.isDebugEnabled()) {
@@ -1062,6 +1035,11 @@ public boolean executeUserRequest(long hostId, Event event) throws AgentUnavaila
10621035
return false;
10631036
}
10641037

1038+
@Override
1039+
public boolean isAgentAttached(long hostId) {
1040+
return findAttache(hostId) != null;
1041+
}
1042+
10651043
protected AgentAttache createAttacheForConnect(HostVO host, Link link) throws ConnectionException {
10661044
s_logger.debug("create ConnectedAgentAttache for " + host.getId());
10671045
AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), link, host.isInMaintenanceStates());
@@ -1462,7 +1440,6 @@ private void disconnectInternal(final long hostId, final Status.Event event, boo
14621440
}
14631441
}
14641442

1465-
@Override
14661443
public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
14671444
disconnectInternal(hostId, event, true);
14681445
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626
import org.apache.log4j.Logger;
2727
import org.springframework.stereotype.Component;
2828

29-
import com.cloud.agent.AgentManager;
30-
import com.cloud.agent.Listener;
3129
import com.cloud.agent.api.AgentControlAnswer;
3230
import com.cloud.agent.api.AgentControlCommand;
3331
import com.cloud.agent.api.Answer;
3432
import com.cloud.agent.api.Command;
3533
import com.cloud.agent.api.PingCommand;
3634
import com.cloud.agent.api.StartupCommand;
3735
import com.cloud.alert.AlertManager;
38-
import com.cloud.configuration.dao.ConfigurationDao;
3936
import com.cloud.dc.DataCenterVO;
4037
import com.cloud.dc.HostPodVO;
4138
import com.cloud.dc.dao.ClusterDao;
@@ -48,10 +45,9 @@
4845
import com.cloud.host.dao.HostDao;
4946
import com.cloud.resource.ResourceManager;
5047
import com.cloud.resource.ResourceState;
51-
import com.cloud.utils.db.ConnectionConcierge;
5248
import com.cloud.utils.db.DB;
53-
import com.cloud.utils.db.SearchCriteria2;
5449
import com.cloud.utils.db.SearchCriteria.Op;
50+
import com.cloud.utils.db.SearchCriteria2;
5551
import com.cloud.utils.db.SearchCriteriaService;
5652
import com.cloud.utils.time.InaccurateClock;
5753
import com.cloud.vm.VMInstanceVO;
@@ -64,17 +60,18 @@ public class AgentMonitor extends Thread implements AgentMonitorService {
6460
private long _pingTimeout = 120; // Default set to 120 seconds
6561
@Inject private HostDao _hostDao;
6662
private boolean _stop;
67-
@Inject private AgentManager _agentMgr;
63+
@Inject
64+
private AgentManagerImpl _agentMgr;
6865
@Inject private VMInstanceDao _vmDao;
69-
@Inject private DataCenterDao _dcDao = null;
70-
@Inject private HostPodDao _podDao = null;
66+
@Inject private final DataCenterDao _dcDao = null;
67+
@Inject private final HostPodDao _podDao = null;
7168
@Inject private AlertManager _alertMgr;
7269
private long _msId;
7370
@Inject ClusterDao _clusterDao;
7471
@Inject ResourceManager _resourceMgr;
7572

7673
// private ConnectionConcierge _concierge;
77-
private Map<Long, Long> _pingMap;
74+
private final Map<Long, Long> _pingMap;
7875

7976
public AgentMonitor() {
8077
_pingMap = new ConcurrentHashMap<Long, Long>(10007);
@@ -87,6 +84,7 @@ public AgentMonitor() {
8784
* agent or host id.
8885
* @return null if the agent is not kept here. true if behind; false if not.
8986
*/
87+
@Override
9088
public Boolean isAgentBehindOnPing(long agentId) {
9189
Long pingTime = _pingMap.get(agentId);
9290
if (pingTime == null) {
@@ -95,10 +93,12 @@ public Boolean isAgentBehindOnPing(long agentId) {
9593
return pingTime < (InaccurateClock.getTimeInSeconds() - _pingTimeout);
9694
}
9795

96+
@Override
9897
public Long getAgentPingTime(long agentId) {
9998
return _pingMap.get(agentId);
10099
}
101100

101+
@Override
102102
public void pingBy(long agentId) {
103103
_pingMap.put(agentId, InaccurateClock.getTimeInSeconds());
104104
}
@@ -168,6 +168,7 @@ public void run() {
168168
s_logger.info("Agent Monitor is leaving the building!");
169169
}
170170

171+
@Override
171172
public void signalStop() {
172173
_stop = true;
173174
interrupt();

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import org.apache.log4j.Logger;
2222

23-
import com.cloud.agent.AgentManager;
24-
import com.cloud.agent.api.Command;
2523
import com.cloud.agent.transport.Request;
2624
import com.cloud.exception.AgentUnavailableException;
2725
import com.cloud.host.Status;
@@ -72,7 +70,7 @@ public void disconnect(final Status state) {
7270
public boolean equals(Object obj) {
7371
try {
7472
ConnectedAgentAttache that = (ConnectedAgentAttache) obj;
75-
return super.equals(obj) && this._link == that._link && this._link != null;
73+
return super.equals(obj) && _link == that._link && _link != null;
7674
} catch (ClassCastException e) {
7775
assert false : "Who's sending an " + obj.getClass().getSimpleName() + " to " + this.getClass().getSimpleName() + ".equals()? ";
7876
return false;
@@ -94,8 +92,4 @@ protected void finalize() throws Throwable {
9492
}
9593
}
9694

97-
@Override
98-
public void updatePassword(Command newPassword) {
99-
throw new IllegalStateException("Should not have come here ");
100-
}
10195
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,4 @@ public void run() {
212212
}
213213
}
214214

215-
216-
@Override
217-
public void updatePassword(Command new_password) {
218-
_resource.executeRequest(new_password);
219-
}
220215
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package com.cloud.agent.manager;
1818

19-
import com.cloud.agent.AgentManager;
20-
import com.cloud.agent.api.Command;
2119
import com.cloud.agent.transport.Request;
2220
import com.cloud.exception.AgentUnavailableException;
2321
import com.cloud.host.Status;
@@ -47,10 +45,4 @@ public void send(Request req) throws AgentUnavailableException {
4745

4846
}
4947

50-
51-
@Override
52-
public void updatePassword(Command newPassword) {
53-
throw new IllegalStateException("Should not have come here ");
54-
}
55-
5648
}

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,6 @@ protected boolean doDeleteHost(long hostId, boolean isForced, boolean isForceDel
819819
if (!isForced && host.getResourceState() != ResourceState.Maintenance) {
820820
throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
821821
}
822-
/*
823-
* TODO: check current agent status and updateAgentStatus to removed. If
824-
* it was already removed, that means someone is deleting host
825-
* concurrently, return. And consider the situation of CloudStack
826-
* shutdown during delete. A global lock?
827-
*/
828-
AgentAttache attache = _agentMgr.findAttache(hostId);
829822
// Get storage pool host mappings here because they can be removed as a
830823
// part of handleDisconnect later
831824
// TODO: find out the bad boy, what's a buggy logic!
@@ -2204,8 +2197,7 @@ public boolean umanageHost(long hostId) {
22042197
}
22052198

22062199
private boolean doUpdateHostPassword(long hostId) {
2207-
AgentAttache attache = _agentMgr.findAttache(hostId);
2208-
if (attache == null) {
2200+
if (_agentMgr.isAgentAttached(hostId)) {
22092201
return false;
22102202
}
22112203

@@ -2214,7 +2206,7 @@ private boolean doUpdateHostPassword(long hostId) {
22142206
nv = _hostDetailsDao.findDetail(hostId, ApiConstants.PASSWORD);
22152207
String password = nv.getValue();
22162208
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
2217-
attache.updatePassword(cmd);
2209+
_agentMgr.easySend(hostId, cmd);
22182210
return true;
22192211
}
22202212

0 commit comments

Comments
 (0)