Skip to content

Commit efedf01

Browse files
author
Alex Huang
committed
propagate b3aea1878395af343e18382b7f1c376b5be04567
1 parent 6805788 commit efedf01

5 files changed

Lines changed: 180 additions & 162 deletions

File tree

‎core/src/com/cloud/event/dao/UsageEventDaoImpl.java‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/**
22
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3-
*
3+
*
44
* This software is licensed under the GNU General Public License v3 or later.
5-
*
5+
*
66
* It is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
88
* the Free Software Foundation, either version 3 of the License, or any later version.
99
* This program is distributed in the hope that it will be useful,
1010
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
* GNU General Public License for more details.
13-
*
13+
*
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*
16+
*
1717
*/
1818

19-
package com.cloud.event.dao;
20-
19+
package com.cloud.event.dao;
20+
2121
import java.sql.PreparedStatement;
2222
import java.util.Date;
2323
import java.util.List;
@@ -36,24 +36,24 @@
3636
import com.cloud.utils.db.SearchBuilder;
3737
import com.cloud.utils.db.SearchCriteria;
3838
import com.cloud.utils.db.Transaction;
39-
40-
@Local(value={UsageEventDao.class})
41-
public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implements UsageEventDao {
39+
40+
@Local(value={UsageEventDao.class})
41+
public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implements UsageEventDao {
4242
public static final Logger s_logger = Logger.getLogger(UsageEventDaoImpl.class.getName());
4343

4444
private final SearchBuilder<UsageEventVO> latestEventsSearch;
4545
private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
4646
"SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id > ? and vmevt.created <= ? ";
4747
private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
4848
"SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event where id <= ? ";
49-
50-
49+
50+
5151
public UsageEventDaoImpl () {
5252
latestEventsSearch = createSearchBuilder();
5353
latestEventsSearch.and("processed", latestEventsSearch.entity().isProcessed(), SearchCriteria.Op.EQ);
5454
latestEventsSearch.and("enddate", latestEventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
5555
latestEventsSearch.done();
56-
}
56+
}
5757

5858
@Override
5959
public List<UsageEventVO> listLatestEvents(Date endDate) {
@@ -70,6 +70,7 @@ public List<UsageEventVO> getLatestEvent() {
7070
return listAll(filter);
7171
}
7272

73+
@Override
7374
@DB
7475
public synchronized List<UsageEventVO> getRecentEvents(Date endDate) throws UsageServerException {
7576
Transaction txn = Transaction.open(Transaction.USAGE_DB);
@@ -135,5 +136,5 @@ private List<UsageEventVO> findRecentEvents(Date endDate) throws UsageServerExce
135136
txn.close();
136137
}
137138
}
138-
139-
}
139+
140+
}

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
22
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3-
*
3+
*
44
* This software is licensed under the GNU General Public License v3 or later.
5-
*
5+
*
66
* It is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
88
* the Free Software Foundation, either version 3 of the License, or any later version.
99
* This program is distributed in the hope that it will be useful,
1010
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
* GNU General Public License for more details.
13-
*
13+
*
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*
16+
*
1717
*/
1818
package com.cloud.agent.manager;
1919

@@ -179,7 +179,7 @@
179179

180180
/**
181181
* Implementation of the Agent Manager. This class controls the connection to the agents.
182-
*
182+
*
183183
* @config {@table || Param Name | Description | Values | Default || || port | port to listen on for agent connection. | Integer
184184
* | 8250 || || workers | # of worker threads | Integer | 5 || || router.template.id | default id for template | Integer
185185
* | 1 || || router.ram.size | default ram for router vm in mb | Integer | 128 || || router.ip.address | ip address for
@@ -1635,7 +1635,7 @@ protected boolean handleDisconnect(AgentAttache attache, Status.Event event, boo
16351635
}
16361636
removeAgent(attache, nextState);
16371637
_hostDao.disconnect(host, event, _nodeId);
1638-
1638+
16391639
host = _hostDao.findById(host.getId());
16401640
if (host.getStatus() == Status.Alert || host.getStatus() == Status.Down) {
16411641
_haMgr.scheduleRestartForVmsOnHost(host, investigate);
@@ -1810,20 +1810,25 @@ protected AgentAttache simulateStart(Long id, ServerResource resource, Map<Strin
18101810
HostVO host = null;
18111811
if (id != null) {
18121812
host = _hostDao.findById(id);
1813-
if (host.getManagementServerId() != null) {
1813+
if (!_hostDao.directConnect(host, _nodeId, false)) {
18141814
s_logger.info("MS " + host.getManagementServerId() + " is loading " + host);
18151815
return null;
18161816
}
18171817
}
1818-
1818+
18191819
StartupCommand[] cmds = resource.initialize();
18201820
if (cmds == null) {
1821+
s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned");
1822+
if (id != null) {
1823+
_hostDao.updateStatus(host, Event.AgentDisconnected, _nodeId);
1824+
}
18211825
return null;
18221826
}
1823-
1827+
18241828
if (host != null) {
1825-
if (!_hostDao.directConnect(host, _nodeId)) {
1826-
s_logger.info("Someone else is loading " + host);
1829+
if (!_hostDao.directConnect(host, _nodeId, true)) {
1830+
host = _hostDao.findById(id);
1831+
s_logger.info("MS " + host.getManagementServerId() + " is loading " + host + " after it has been initialized.");
18271832
resource.disconnected();
18281833
return null;
18291834
}
@@ -2430,7 +2435,7 @@ public HostVO createHost(final StartupCommand startup, ServerResource resource,
24302435
* !"0.0.0.0".equals(startup.getStorageIpAddress())) { if (_hostDao.findByPrivateIpAddressInDataCenter
24312436
* (server.getDataCenterId(), startup.getPrivateIpAddress()) != null) { throw newIllegalArgumentException(
24322437
* "The private ip address is already in used: " + startup.getPrivateIpAddress()); }
2433-
*
2438+
*
24342439
* if (_hostDao.findByPrivateIpAddressInDataCenter(server.getDataCenterId (), startup.getStorageIpAddress()) !=
24352440
* null) { throw new IllegalArgumentException ("The private ip address is already in used: " +
24362441
* startup.getStorageIpAddress()); } }

‎server/src/com/cloud/ha/XenServerFencer.java‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
22
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3-
*
3+
*
44
* This software is licensed under the GNU General Public License v3 or later.
5-
*
5+
*
66
* It is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
88
* the Free Software Foundation, either version 3 of the License, or any later version.
99
* This program is distributed in the hope that it will be useful,
1010
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
* GNU General Public License for more details.
13-
*
13+
*
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*
16+
*
1717
*/
1818
package com.cloud.ha;
1919

@@ -26,6 +26,7 @@
2626
import org.apache.log4j.Logger;
2727

2828
import com.cloud.agent.AgentManager;
29+
import com.cloud.agent.api.Answer;
2930
import com.cloud.agent.api.FenceAnswer;
3031
import com.cloud.agent.api.FenceCommand;
3132
import com.cloud.exception.AgentUnavailableException;
@@ -41,20 +42,20 @@
4142
public class XenServerFencer implements FenceBuilder {
4243
private static final Logger s_logger = Logger.getLogger(XenServerFencer.class);
4344
String _name;
44-
45+
4546
@Inject HostDao _hostDao;
4647
@Inject AgentManager _agentMgr;
47-
48+
4849
@Override
4950
public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
5051
if (host.getHypervisorType() != HypervisorType.XenServer) {
5152
s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
5253
return null;
5354
}
54-
55+
5556
List<HostVO> hosts = _hostDao.listByCluster(host.getClusterId());
5657
FenceCommand fence = new FenceCommand(vm, host);
57-
58+
5859
for (HostVO h : hosts) {
5960
if (h.getHypervisorType() == HypervisorType.XenServer) {
6061
if( h.getStatus() != Status.Up ) {
@@ -65,7 +66,12 @@ public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
6566
}
6667
FenceAnswer answer;
6768
try {
68-
answer = (FenceAnswer)_agentMgr.send(h.getId(), fence);
69+
Answer ans = _agentMgr.send(h.getId(), fence);
70+
if (!(ans instanceof FenceAnswer)) {
71+
s_logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails());
72+
continue;
73+
}
74+
answer = (FenceAnswer) ans;
6975
} catch (AgentUnavailableException e) {
7076
if (s_logger.isDebugEnabled()) {
7177
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
@@ -82,14 +88,14 @@ public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
8288
}
8389
}
8490
}
85-
91+
8692
if (s_logger.isDebugEnabled()) {
8793
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
8894
}
89-
95+
9096
return false;
9197
}
92-
98+
9399
public XenServerFencer() {
94100
super();
95101
}

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
22
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3-
*
3+
*
44
* This software is licensed under the GNU General Public License v3 or later.
5-
*
5+
*
66
* It is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
88
* the Free Software Foundation, either version 3 of the License, or any later version.
99
* This program is distributed in the hope that it will be useful,
1010
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
* GNU General Public License for more details.
13-
*
13+
*
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*
16+
*
1717
*/
1818
package com.cloud.host.dao;
1919

@@ -31,13 +31,13 @@
3131

3232
/**
3333
* Data Access Object for server
34-
*
34+
*
3535
*/
3636
public interface HostDao extends GenericDao<HostVO, Long> {
3737
List<HostVO> listBy(Host.Type type, Long clusterId, Long podId, long dcId);
38-
38+
3939
long countBy(long clusterId, Status... statuses);
40-
40+
4141
List<HostVO> listByDataCenter(long dcId);
4242
List<HostVO> listByHostPod(long podId);
4343
List<HostVO> listByStatus(Status... status);
@@ -50,25 +50,25 @@ public interface HostDao extends GenericDao<HostVO, Long> {
5050
* @return list of Hosts
5151
*/
5252
List<HostVO> listSecondaryStorageHosts();
53-
53+
5454
/**
5555
* Mark all hosts in Up or Orphaned state as disconnected. This method
5656
* is used at AgentManager startup to reset all of the connections.
57-
*
57+
*
5858
* @param msId management server id.
5959
* @param statuses states of the host.
6060
*/
6161
void markHostsAsDisconnected(long msId, Status... states);
62-
62+
6363
List<HostVO> findLostHosts(long timeout);
64-
64+
6565
List<HostVO> findHostsLike(String hostName);
6666

6767
/**
6868
* Find hosts that are directly connected.
6969
*/
7070
List<HostVO> findDirectlyConnectedHosts();
71-
71+
7272
List<HostVO> findDirectAgentToLoad(long msid, long lastPingSecondsAfter, Long limit);
7373

7474
/**
@@ -77,16 +77,16 @@ public interface HostDao extends GenericDao<HostVO, Long> {
7777
* The lastPinged timestamp is set to current.
7878
* The state is set to the state passed in.
7979
* The disconnectedOn timestamp is set to current.
80-
*
80+
*
8181
* @param host host to be marked
8282
* @param state state to be set to.
8383
* @param ifStates only if it is one of these states.
8484
* @return true if it's updated; false if not.
8585
*/
8686
boolean disconnect(HostVO host, Event event, long msId);
87-
87+
8888
boolean connect(HostVO host, long msId);
89-
89+
9090
HostVO findByStorageIpAddressInDataCenter(long dcId, String privateIpAddress);
9191
HostVO findByPrivateIpAddressInDataCenter(long dcId, String privateIpAddress);
9292

@@ -123,7 +123,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
123123
* @return
124124
*/
125125
List<HostVO> findLostHosts2(long timeout, Type type);
126-
126+
127127
/**
128128
* update the host and changes the status depending on the Event and
129129
* the current status. If the status changed between
@@ -133,11 +133,11 @@ public interface HostDao extends GenericDao<HostVO, Long> {
133133
* @return true if updated; false if not.
134134
*/
135135
boolean updateStatus(HostVO host, Event event, long msId);
136-
136+
137137
List<RunningHostCountInfo> getRunningHostCounts(Date cutTime);
138-
138+
139139
long getNextSequence(long hostId);
140-
140+
141141
void loadDetails(HostVO host);
142142

143143
void saveDetails(HostVO host);
@@ -158,14 +158,15 @@ public interface HostDao extends GenericDao<HostVO, Long> {
158158
List<Long> listBy(Long dataCenterId, Long podId, Long clusterId, Type hostType, Status... statuses);
159159

160160
List<HostVO> listBy(Long clusterId, Long podId, long dcId);
161-
161+
162162
void loadHostTags(HostVO host);
163-
163+
164164
List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag);
165165

166166
long countRoutingHostsByDataCenter(long dcId);
167167

168168
List<HostVO> listSecondaryStorageHosts(long dataCenterId);
169169

170-
boolean directConnect(HostVO host, long msId);
170+
boolean directConnect(HostVO host, long msId, boolean secondConnect);
171+
171172
}

0 commit comments

Comments
 (0)