Skip to content

Commit 0ee7e76

Browse files
author
Alex Huang
committed
Propagate fixes from 2.2.4
1 parent 2d52813 commit 0ee7e76

5 files changed

Lines changed: 74 additions & 41 deletions

File tree

‎core/src/com/cloud/host/HostVO.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public void setStorageIpAddressDeux(String deuxStorageIpAddress) {
153153
this.storageIpAddressDeux = deuxStorageIpAddress;
154154
}
155155

156-
public String getStorageNetmaskDeux() {
156+
@Override
157+
public String getStorageNetmaskDeux() {
157158
return storageNetmaskDeux;
158159
}
159160

@@ -170,15 +171,17 @@ public void setStorageNetmaskDeux(String deuxStorageNetmask) {
170171
this.storageNetmaskDeux = deuxStorageNetmask;
171172
}
172173

173-
public String getStorageMacAddressDeux() {
174+
@Override
175+
public String getStorageMacAddressDeux() {
174176
return storageMacAddressDeux;
175177
}
176178

177179
public void setStorageMacAddressDeux(String duexStorageMacAddress) {
178180
this.storageMacAddressDeux = duexStorageMacAddress;
179181
}
180182

181-
public String getPrivateMacAddress() {
183+
@Override
184+
public String getPrivateMacAddress() {
182185
return privateMacAddress;
183186
}
184187

@@ -194,6 +197,7 @@ public void setAvailable(boolean available) {
194197
this.available = available;
195198
}
196199

200+
@Override
197201
public String getPrivateNetmask() {
198202
return privateNetmask;
199203
}
@@ -202,6 +206,7 @@ public void setPrivateNetmask(String privateNetmask) {
202206
this.privateNetmask = privateNetmask;
203207
}
204208

209+
@Override
205210
public String getPublicNetmask() {
206211
return publicNetmask;
207212
}
@@ -210,6 +215,7 @@ public void setPublicNetmask(String publicNetmask) {
210215
this.publicNetmask = publicNetmask;
211216
}
212217

218+
@Override
213219
public String getPublicIpAddress() {
214220
return publicIpAddress;
215221
}
@@ -218,6 +224,7 @@ public void setPublicIpAddress(String publicIpAddress) {
218224
this.publicIpAddress = publicIpAddress;
219225
}
220226

227+
@Override
221228
public String getPublicMacAddress() {
222229
return publicMacAddress;
223230
}
@@ -235,6 +242,7 @@ public void setStorageIpAddress(String storageIpAddress) {
235242
this.storageIpAddress = storageIpAddress;
236243
}
237244

245+
@Override
238246
public String getStorageNetmask() {
239247
return storageNetmask;
240248
}
@@ -243,6 +251,7 @@ public void setStorageNetmask(String storageNetmask) {
243251
this.storageNetmask = storageNetmask;
244252
}
245253

254+
@Override
246255
public String getStorageMacAddress() {
247256
return storageMacAddress;
248257
}
@@ -648,7 +657,7 @@ public boolean equals(Object obj) {
648657

649658
@Override
650659
public String toString() {
651-
return new StringBuilder(type.toString()).append("-").append(id).append("-").append(name).toString();
660+
return new StringBuilder("Host[").append("-").append(id).append("-").append(type).append("]").toString();
652661
}
653662

654663
public void setHypervisorType(HypervisorType hypervisorType) {

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
import org.apache.log4j.Logger;
4444

4545
import com.cloud.agent.AgentManager;
46-
import com.cloud.agent.StartupCommandProcessor;
4746
import com.cloud.agent.Listener;
47+
import com.cloud.agent.StartupCommandProcessor;
4848
import com.cloud.agent.api.AgentControlAnswer;
4949
import com.cloud.agent.api.AgentControlCommand;
5050
import com.cloud.agent.api.Answer;
@@ -481,7 +481,11 @@ public void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers) {
481481
}
482482

483483
public AgentAttache findAttache(long hostId) {
484-
return _agents.get(hostId);
484+
AgentAttache attache = null;
485+
synchronized (_agents) {
486+
attache = _agents.get(hostId);
487+
}
488+
return attache;
485489
}
486490

487491
@Override
@@ -587,8 +591,9 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws Illegal
587591
String username = cmd.getUsername();
588592
String password = cmd.getPassword();
589593

590-
if(url != null)
591-
url = URLDecoder.decode(url);
594+
if(url != null) {
595+
url = URLDecoder.decode(url);
596+
}
592597

593598
URI uri = null;
594599

@@ -716,7 +721,7 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws Illegal
716721
break;
717722
}
718723

719-
AgentAttache attache = simulateStart(resource, entry.getValue(), true, null, null);
724+
AgentAttache attache = simulateStart(null, resource, entry.getValue(), true, null, null);
720725
if (attache != null) {
721726
hosts.add(_hostDao.findById(attache.getId()));
722727
}
@@ -950,7 +955,7 @@ private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, St
950955
}
951956
return null;
952957
}
953-
AgentAttache attache = simulateStart(resource, entry.getValue(), true, hostTags, allocationState);
958+
AgentAttache attache = simulateStart(null, resource, entry.getValue(), true, hostTags, allocationState);
954959
if (attache != null) {
955960
hosts.add(_hostDao.findById(attache.getId()));
956961
}
@@ -1694,11 +1699,9 @@ protected boolean handleDisconnect(AgentAttache attache, Status.Event event, boo
16941699
if (s_logger.isDebugEnabled()) {
16951700
s_logger.debug("Deregistering link for " + hostId + " with state " + nextState);
16961701
}
1697-
1698-
_hostDao.disconnect(host, event, _nodeId);
1699-
17001702
removeAgent(attache, nextState);
1701-
1703+
_hostDao.disconnect(host, event, _nodeId);
1704+
17021705
host = _hostDao.findById(host.getId());
17031706
if (host.getStatus() == Status.Alert || host.getStatus() == Status.Down) {
17041707
_haMgr.scheduleRestartForVmsOnHost(host, investigate);
@@ -1873,11 +1876,19 @@ protected void loadDirectlyConnectedHost(HostVO host) {
18731876
_executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails(), null));
18741877
}
18751878

1876-
protected AgentAttache simulateStart(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, String allocationState) throws IllegalArgumentException {
1879+
protected AgentAttache simulateStart(Long id, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, String allocationState) throws IllegalArgumentException {
18771880
StartupCommand[] cmds = resource.initialize();
18781881
if (cmds == null) {
18791882
return null;
18801883
}
1884+
1885+
if (id != null) {
1886+
HostVO host = _hostDao.findById(id);
1887+
if (!_hostDao.directConnect(host, _nodeId)) {
1888+
s_logger.info("Someone else is loading " + host);
1889+
return null;
1890+
}
1891+
}
18811892

18821893
AgentAttache attache = null;
18831894
if (s_logger.isDebugEnabled()) {
@@ -2386,7 +2397,7 @@ public Host addHost(long zoneId, ServerResource resource, Type hostType, Map<Str
23862397
}
23872398
}
23882399

2389-
AgentAttache attache = simulateStart(resource, hostDetails, true, null, null);
2400+
AgentAttache attache = simulateStart(null, resource, hostDetails, true, null, null);
23902401
return _hostDao.findById(attache.getId());
23912402
}
23922403

@@ -2559,8 +2570,7 @@ protected AgentAttache createAttache(long id, HostVO server, Link link) {
25592570
link.attach(attache);
25602571
AgentAttache old = null;
25612572
synchronized (_agents) {
2562-
old = _agents.get(id);
2563-
_agents.put(id, attache);
2573+
old = _agents.put(id, attache);
25642574
}
25652575
if (old != null) {
25662576
old.disconnect(Status.Removed);
@@ -2577,8 +2587,7 @@ protected AgentAttache createAttache(long id, HostVO server, ServerResource reso
25772587
|| server.getStatus() == Status.PrepareForMaintenance, this);
25782588
AgentAttache old = null;
25792589
synchronized (_agents) {
2580-
old = _agents.get(id);
2581-
_agents.put(id, attache);
2590+
old = _agents.put(id, attache);
25822591
}
25832592
if (old != null) {
25842593
old.disconnect(Status.Removed);
@@ -2959,23 +2968,17 @@ public SimulateStartTask(long id, ServerResource resource, Map<String, String> d
29592968

29602969
@Override
29612970
public void run() {
2962-
AgentAttache at = null;
29632971
try {
29642972
if (s_logger.isDebugEnabled()) {
29652973
s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
29662974
}
2967-
simulateStart(resource, details, false, null, null);
2975+
simulateStart(id, resource, details, false, null, null);
29682976
} catch (Exception e) {
29692977
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
29702978
} finally {
29712979
if (actionDelegate != null) {
29722980
actionDelegate.action(new Long(id));
29732981
}
2974-
if (at == null) {
2975-
HostVO host = _hostDao.findById(id);
2976-
host.setManagementServerId(null);
2977-
_hostDao.update(id, host);
2978-
}
29792982
StackMaid.current().exitCleanup();
29802983
}
29812984
}

‎server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ private void scanDirectAgentToLoad() {
125125
break;
126126
}
127127
}
128-
}
129-
}
130-
if (hosts != null && hosts.size() > 0) {
131-
for (HostVO host : hosts) {
132-
AgentAttache agentattache = findAttache(host.getId());
133-
if (agentattache != null) {
134-
// already loaded, skip
135-
if (agentattache.forForward()) {
136-
if (s_logger.isInfoEnabled()) {
137-
s_logger.info("Host " + host.getName() + " is detected down, but we have a forward attache running, disconnect this one before launching the host");
128+
}
129+
}
130+
if(hosts != null && hosts.size() > 0) {
131+
for(HostVO host: hosts) {
132+
AgentAttache agentattache = findAttache(host.getId());
133+
if(agentattache != null) {
134+
// already loaded, skip
135+
if(agentattache.forForward()) {
136+
if(s_logger.isInfoEnabled()) {
137+
s_logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host");
138138
}
139139
removeAgent(agentattache, Status.Disconnected);
140140
} else {

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,6 @@ public interface HostDao extends GenericDao<HostVO, Long> {
166166
long countRoutingHostsByDataCenter(long dcId);
167167

168168
List<HostVO> listSecondaryStorageHosts(long dataCenterId);
169+
170+
boolean directConnect(HostVO host, long msId);
169171
}

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
8787
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
8888
protected final SearchBuilder<HostVO> AvailHypevisorInZone;
8989

90+
protected final SearchBuilder<HostVO> DirectConnectSearch;
91+
9092
protected final GenericSearchBuilder<HostVO, Long> HostsInStatusSearch;
9193
protected final GenericSearchBuilder<HostVO, Long> CountRoutingByDc;
9294

@@ -204,7 +206,6 @@ public HostDaoImpl() {
204206
UnmanagedDirectConnectSearch.and("resource", UnmanagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
205207
UnmanagedDirectConnectSearch.and("server", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
206208
UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
207-
208209
/*
209210
UnmanagedDirectConnectSearch.op(SearchCriteria.Op.OR, "managementServerId", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
210211
UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
@@ -213,6 +214,12 @@ public HostDaoImpl() {
213214
*/
214215
UnmanagedDirectConnectSearch.done();
215216

217+
DirectConnectSearch = createSearchBuilder();
218+
DirectConnectSearch.and("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
219+
DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
220+
DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
221+
DirectConnectSearch.done();
222+
216223
UnmanagedExternalNetworkApplianceSearch = createSearchBuilder();
217224
UnmanagedExternalNetworkApplianceSearch.and("resource", UnmanagedExternalNetworkApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
218225
UnmanagedExternalNetworkApplianceSearch.and("server", UnmanagedExternalNetworkApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
@@ -433,7 +440,20 @@ public void loadDetails(HostVO host) {
433440
public void loadHostTags(HostVO host){
434441
List<String> hostTags = _hostTagsDao.gethostTags(host.getId());
435442
host.setHostTags(hostTags);
436-
}
443+
}
444+
445+
@Override
446+
public boolean directConnect(HostVO host, long msId) {
447+
SearchCriteria<HostVO> sc = DirectConnectSearch.create();
448+
sc.setParameters("id", host.getId());
449+
450+
host.setManagementServerId(msId);
451+
host.setLastPinged(System.currentTimeMillis() >> 10);
452+
UpdateBuilder ub = getUpdateBuilder(host);
453+
ub.set(host, _statusAttr, Status.Connecting);
454+
455+
return update(host, sc) > 0;
456+
}
437457

438458
@Override
439459
public boolean updateStatus(HostVO host, Event event, long msId) {
@@ -539,8 +559,7 @@ public HostVO findByName(String name) {
539559
public List<HostVO> findLostHosts(long timeout) {
540560
SearchCriteria<HostVO> sc = LastPingedSearch.create();
541561
sc.setParameters("ping", timeout);
542-
sc.setParameters("state", Status.Up.toString(), Status.Updating.toString(),
543-
Status.Disconnected.toString(), Status.Down.toString());
562+
sc.setParameters("state", Status.Up, Status.Updating, Status.Disconnected, Status.Down, Status.Connecting);
544563
return listBy(sc);
545564
}
546565

0 commit comments

Comments
 (0)