Propagate fix on 2.2.4

This commit is contained in:
Alex Huang 2011-05-09 17:54:11 -07:00
parent 8d9254c2bb
commit dc3e42855b
3 changed files with 42 additions and 29 deletions

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.host.dao;
@ -21,22 +21,22 @@ import java.util.Date;
import java.util.List;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.Host.Type;
import com.cloud.host.Status.Event;
import com.cloud.info.RunningHostCountInfo;
import com.cloud.utils.db.GenericDao;
/**
* Data Access Object for server
*
*
*/
public interface HostDao extends GenericDao<HostVO, Long> {
List<HostVO> listBy(Host.Type type, Long clusterId, Long podId, long dcId);
long countBy(long clusterId, Status... statuses);
List<HostVO> listByDataCenter(long dcId);
List<HostVO> listByHostPod(long podId);
List<HostVO> listByStatus(Status... status);
@ -48,27 +48,28 @@ public interface HostDao extends GenericDao<HostVO, Long> {
* @return list of Hosts
*/
List<HostVO> listSecondaryStorageHosts();
/**
* Mark all hosts in Up or Orphaned state as disconnected. This method
* is used at AgentManager startup to reset all of the connections.
*
*
* @param msId management server id.
* @param statuses states of the host.
*/
void markHostsAsDisconnected(long msId, Status... states);
List<HostVO> findLostHosts(long timeout);
List<HostVO> findHostsLike(String hostName);
/**
* Find hosts that are directly connected.
*/
List<HostVO> findDirectlyConnectedHosts();
List<HostVO> findDirectAgentToLoad(long msid, long lastPingSecondsAfter, Long limit);
boolean directConnect(HostVO host, long msId);
boolean directConnect(HostVO host, long msId, boolean secondConnect);
/**
* Mark the host as disconnected if it is in one of these states.
@ -76,16 +77,16 @@ public interface HostDao extends GenericDao<HostVO, Long> {
* The lastPinged timestamp is set to current.
* The state is set to the state passed in.
* The disconnectedOn timestamp is set to current.
*
*
* @param host host to be marked
* @param state state to be set to.
* @param ifStates only if it is one of these states.
* @return true if it's updated; false if not.
*/
boolean disconnect(HostVO host, Event event, long msId);
boolean connect(HostVO host, long msId);
HostVO findByStorageIpAddressInDataCenter(long dcId, String privateIpAddress);
HostVO findByPrivateIpAddressInDataCenter(long dcId, String privateIpAddress);
@ -95,7 +96,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
* @return HostVO or null if not found.
*/
public HostVO findByGuid(String macAddress);
/**
* find all hosts of a certain type in a data center
@ -120,7 +121,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
* @return
*/
List<HostVO> findLostHosts2(long timeout, Type type);
/**
* update the host and changes the status depending on the Event and
* the current status. If the status changed between
@ -130,11 +131,11 @@ public interface HostDao extends GenericDao<HostVO, Long> {
* @return true if updated; false if not.
*/
boolean updateStatus(HostVO host, Event event, long msId);
List<RunningHostCountInfo> getRunningHostCounts(Date cutTime);
long getNextSequence(long hostId);
void loadDetails(HostVO host);
void loadHostTags(HostVO host);

View File

@ -47,6 +47,7 @@ import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.UpdateBuilder;
@ -193,9 +194,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
UnmanagedDirectConnectSearch.done();
DirectConnectSearch = createSearchBuilder();
DirectConnectSearch.and("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
DirectConnectSearch.op(Op.AND, "nullserver", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
DirectConnectSearch.or("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
DirectConnectSearch.cp();
DirectConnectSearch.done();
_statusAttr = _allAttributes.get("status");
@ -218,9 +221,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
}
@Override
public boolean directConnect(HostVO host, long msId) {
public boolean directConnect(HostVO host, long msId, boolean secondConnect) {
SearchCriteria sc = DirectConnectSearch.create();
sc.setParameters("id", host.getId());
if (secondConnect) {
sc.setParameters("server", msId);
}
host.setManagementServerId(msId);
host.setLastPinged(System.currentTimeMillis() >> 10);
UpdateBuilder ub = getUpdateBuilder(host);

View File

@ -1230,17 +1230,23 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
HostVO host = null;
if (id != null) {
host = _hostDao.findById(id);
if (host.getManagementServerId() != null) {
if (!_hostDao.directConnect(host, _nodeId, false)) {
s_logger.info("MS " + host.getManagementServerId() + " is loading " + host);
return null;
}
}
StartupCommand[] cmds = resource.initialize();
if (cmds == null)
return null;
if (cmds == null) {
s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned");
if (id != null) {
_hostDao.updateStatus(host, Event.AgentDisconnected, _nodeId);
}
}
if (host != null) {
if (!_hostDao.directConnect(host, _nodeId)) {
s_logger.info("Someone else is loading " + host);
if (!_hostDao.directConnect(host, _nodeId, true)) {
host = _hostDao.findById(id);
s_logger.info("MS " + host.getManagementServerId() + " is loading " + host + " after it has been initialized.");
resource.disconnected();
return null;
}