mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Bug 11522 - New agent manager
register/unregister resource state adapter in configure/stop of implementations
This commit is contained in:
		
							parent
							
								
									e8c13e10c7
								
							
						
					
					
						commit
						e5fca855c1
					
				| @ -25,6 +25,7 @@ import com.cloud.utils.fsm.StateMachine; | |||||||
| import com.cloud.utils.fsm.StateMachine2; | import com.cloud.utils.fsm.StateMachine2; | ||||||
| 
 | 
 | ||||||
| public enum Status { | public enum Status { | ||||||
|  | 	Creating(true, false, false), | ||||||
|     Connecting(true, false, false), |     Connecting(true, false, false), | ||||||
|     Up(true, false, false), |     Up(true, false, false), | ||||||
|     Down(true, true, true), |     Down(true, true, true), | ||||||
| @ -119,6 +120,7 @@ public enum Status { | |||||||
|     protected static final StateMachine2<Status, Event, Host> s_fsm = new StateMachine2<Status, Event, Host>(); |     protected static final StateMachine2<Status, Event, Host> s_fsm = new StateMachine2<Status, Event, Host>(); | ||||||
|     static { |     static { | ||||||
|         s_fsm.addTransition(null, Event.AgentConnected, Status.Connecting); |         s_fsm.addTransition(null, Event.AgentConnected, Status.Connecting); | ||||||
|  |         s_fsm.addTransition(Status.Creating, Event.AgentConnected, Status.Connecting); | ||||||
|         s_fsm.addTransition(Status.Connecting, Event.AgentConnected, Status.Connecting); |         s_fsm.addTransition(Status.Connecting, Event.AgentConnected, Status.Connecting); | ||||||
|         s_fsm.addTransition(Status.Connecting, Event.Ready, Status.Up); |         s_fsm.addTransition(Status.Connecting, Event.Ready, Status.Up); | ||||||
|         s_fsm.addTransition(Status.Connecting, Event.PingTimeout, Status.Alert); |         s_fsm.addTransition(Status.Connecting, Event.PingTimeout, Status.Alert); | ||||||
|  | |||||||
| @ -361,7 +361,7 @@ public class HostVO implements Host { | |||||||
| 
 | 
 | ||||||
|     public HostVO(String guid) { |     public HostVO(String guid) { | ||||||
|         this.guid = guid; |         this.guid = guid; | ||||||
|         this.status = Status.Up; |         this.status = Status.Creating; | ||||||
|         this.totalMemory = 0; |         this.totalMemory = 0; | ||||||
|         this.dom0MinMemory = 0; |         this.dom0MinMemory = 0; | ||||||
|         this.hostAllocationState = Host.HostAllocationState.Enabled; |         this.hostAllocationState = Host.HostAllocationState.Enabled; | ||||||
| @ -712,6 +712,10 @@ public class HostVO implements Host { | |||||||
|         return resourceState; |         return resourceState; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     public void setResourceState(ResourceState state) { | ||||||
|  |     	resourceState = state; | ||||||
|  |     } | ||||||
|  |      | ||||||
|     @Override |     @Override | ||||||
|     public boolean isInMaintenanceStates() { |     public boolean isInMaintenanceStates() { | ||||||
|         return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance |         return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance | ||||||
|  | |||||||
| @ -45,6 +45,18 @@ public class OvmDiscoverer extends DiscovererBase implements Discoverer, Resourc | |||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  |     @Override | ||||||
|  |     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | ||||||
|  |     	_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|  |     	return super.configure(name, params); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|  |         return super.stop(); | ||||||
|  |     } | ||||||
|  | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public Map<? extends ServerResource, Map<String, String>> find(long dcId, | 	public Map<? extends ServerResource, Map<String, String>> find(long dcId, | ||||||
| 			Long podId, Long clusterId, URI url, String username, | 			Long podId, Long clusterId, URI url, String username, | ||||||
|  | |||||||
| @ -27,6 +27,7 @@ import java.util.Map; | |||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
| 
 | 
 | ||||||
| import javax.ejb.Local; | import javax.ejb.Local; | ||||||
|  | import javax.naming.ConfigurationException; | ||||||
| 
 | 
 | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| @ -44,6 +45,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; | |||||||
| import com.cloud.network.Network; | import com.cloud.network.Network; | ||||||
| import com.cloud.resource.Discoverer; | import com.cloud.resource.Discoverer; | ||||||
| import com.cloud.resource.DiscovererBase; | import com.cloud.resource.DiscovererBase; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
| import com.cloud.resource.ResourceStateAdapter; | import com.cloud.resource.ResourceStateAdapter; | ||||||
| import com.cloud.resource.ServerResource; | import com.cloud.resource.ServerResource; | ||||||
| import com.cloud.resource.UnableDeleteHostException; | import com.cloud.resource.UnableDeleteHostException; | ||||||
| @ -61,6 +63,19 @@ public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, R | |||||||
| 	@Inject protected HostDao _hostDao; | 	@Inject protected HostDao _hostDao; | ||||||
| 	@Inject DataCenterDao _dcDao; | 	@Inject DataCenterDao _dcDao; | ||||||
|     @Inject VMInstanceDao _vmDao = null; |     @Inject VMInstanceDao _vmDao = null; | ||||||
|  |     @Inject ResourceManager _resourceMgr; | ||||||
|  | 	 | ||||||
|  |     @Override | ||||||
|  |     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | ||||||
|  |     	_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|  |     	return super.configure(name, params); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|  |         return super.stop(); | ||||||
|  |     } | ||||||
|      |      | ||||||
| 	@Override | 	@Override | ||||||
| 	public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) | 	public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) | ||||||
|  | |||||||
| @ -89,6 +89,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta | |||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | 	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | ||||||
|  | 		_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -99,6 +100,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta | |||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean stop() { | 	public boolean stop() { | ||||||
|  | 		_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,6 +36,7 @@ import com.cloud.deploy.DeployDestination; | |||||||
| import com.cloud.host.Host; | import com.cloud.host.Host; | ||||||
| import com.cloud.host.HostVO; | import com.cloud.host.HostVO; | ||||||
| import com.cloud.host.dao.HostDao; | import com.cloud.host.dao.HostDao; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
| import com.cloud.resource.ResourceStateAdapter; | import com.cloud.resource.ResourceStateAdapter; | ||||||
| import com.cloud.resource.ServerResource; | import com.cloud.resource.ServerResource; | ||||||
| import com.cloud.resource.UnableDeleteHostException; | import com.cloud.resource.UnableDeleteHostException; | ||||||
| @ -56,13 +57,14 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap | |||||||
| 	@Inject HostDao _hostDao; | 	@Inject HostDao _hostDao; | ||||||
| 	@Inject AgentManager _agentMgr; | 	@Inject AgentManager _agentMgr; | ||||||
| 	@Inject ExternalDhcpManager exDhcpMgr; | 	@Inject ExternalDhcpManager exDhcpMgr; | ||||||
| 	 | 	@Inject ResourceManager _resourceMgr; | ||||||
| 	@Inject(adapter=PxeServerService.class) | 	@Inject(adapter=PxeServerService.class) | ||||||
| 	protected Adapters<PxeServerService> _services; | 	protected Adapters<PxeServerService> _services; | ||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | 	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | ||||||
| 		_name = name; | 		_name = name; | ||||||
|  | 		_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -73,6 +75,7 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap | |||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean stop() { | 	public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -88,6 +88,7 @@ import com.cloud.network.NetworkVO; | |||||||
| import com.cloud.network.Networks.TrafficType; | import com.cloud.network.Networks.TrafficType; | ||||||
| import com.cloud.offerings.NetworkOfferingVO; | import com.cloud.offerings.NetworkOfferingVO; | ||||||
| import com.cloud.offerings.dao.NetworkOfferingDao; | import com.cloud.offerings.dao.NetworkOfferingDao; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
| import com.cloud.resource.ResourceStateAdapter; | import com.cloud.resource.ResourceStateAdapter; | ||||||
| import com.cloud.resource.ServerResource; | import com.cloud.resource.ServerResource; | ||||||
| import com.cloud.resource.UnableDeleteHostException; | import com.cloud.resource.UnableDeleteHostException; | ||||||
| @ -202,6 +203,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx | |||||||
|     StoragePoolDao _storagePoolDao; |     StoragePoolDao _storagePoolDao; | ||||||
|     @Inject |     @Inject | ||||||
|     UserVmDetailsDao _vmDetailsDao; |     UserVmDetailsDao _vmDetailsDao; | ||||||
|  |     @Inject | ||||||
|  |     ResourceManager _resourceMgr; | ||||||
| 
 | 
 | ||||||
|     private ConsoleProxyListener _listener; |     private ConsoleProxyListener _listener; | ||||||
| 
 | 
 | ||||||
| @ -1003,6 +1006,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx | |||||||
| 
 | 
 | ||||||
|         this._loadScanner.stop(); |         this._loadScanner.stop(); | ||||||
|         _allocProxyLock.releaseRef(); |         _allocProxyLock.releaseRef(); | ||||||
|  |         _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -1270,6 +1274,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx | |||||||
| 
 | 
 | ||||||
|         _loadScanner = new SystemVmLoadScanner<Long>(this); |         _loadScanner = new SystemVmLoadScanner<Long>(this); | ||||||
|         _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval); |         _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval); | ||||||
|  |     	_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
| 
 | 
 | ||||||
|         if (s_logger.isInfoEnabled()) { |         if (s_logger.isInfoEnabled()) { | ||||||
|             s_logger.info("Console Proxy Manager is configured."); |             s_logger.info("Console Proxy Manager is configured."); | ||||||
|  | |||||||
| @ -925,62 +925,70 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public boolean updateState(Status oldStatus, Event event, | 	public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Long id) { | ||||||
| 			Status newStatus, Host vo, Long id) { | 		HostVO host = (HostVO) vo; | ||||||
| 		 HostVO host = (HostVO)vo; | 		long oldPingTime = host.getLastPinged(); | ||||||
| 	        long oldPingTime = host.getLastPinged(); |  | ||||||
| 
 | 
 | ||||||
| 	        SearchBuilder<HostVO> sb = createSearchBuilder(); | 		SearchBuilder<HostVO> sb = createSearchBuilder(); | ||||||
| 	        sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ); | 		sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ); | ||||||
| 	        sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); | 		sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); | ||||||
| 	        if (newStatus.checkManagementServer()) { | 		if (newStatus.checkManagementServer()) { | ||||||
| 	            sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ); | 			sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ); | ||||||
| 	            sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL); | 			sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL); | ||||||
| 	            sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ); | 			sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ); | ||||||
| 	            sb.closeParen(); | 			sb.closeParen(); | ||||||
| 	        } | 		} | ||||||
| 	        sb.done(); | 		sb.done(); | ||||||
| 
 | 
 | ||||||
| 	        SearchCriteria<HostVO> sc = sb.create(); | 		SearchCriteria<HostVO> sc = sb.create(); | ||||||
| 
 | 
 | ||||||
| 	        sc.setParameters("status", oldStatus); | 		sc.setParameters("status", oldStatus); | ||||||
| 	        sc.setParameters("id", host.getId()); | 		sc.setParameters("id", host.getId()); | ||||||
| 	        if (newStatus.checkManagementServer()) { | 		if (newStatus.checkManagementServer()) { | ||||||
| 	            sc.setParameters("ping", oldPingTime); | 			sc.setParameters("ping", oldPingTime); | ||||||
| 	            sc.setParameters("msid", host.getManagementServerId()); | 			sc.setParameters("msid", host.getManagementServerId()); | ||||||
| 	        } | 		} | ||||||
| 
 | 
 | ||||||
| 	        UpdateBuilder ub = getUpdateBuilder(host); | 		UpdateBuilder ub = getUpdateBuilder(host); | ||||||
| 	        ub.set(host, _statusAttr, newStatus); | 		ub.set(host, _statusAttr, newStatus); | ||||||
| 	        if (newStatus.updateManagementServer()) { | 		if (newStatus.updateManagementServer()) { | ||||||
| 	            if (newStatus.lostConnection()) { | 			if (newStatus.lostConnection()) { | ||||||
| 	                ub.set(host, _msIdAttr, null); | 				ub.set(host, _msIdAttr, null); | ||||||
| 	            } else { | 			} else { | ||||||
| 	                ub.set(host, _msIdAttr, host.getManagementServerId()); | 				ub.set(host, _msIdAttr, host.getManagementServerId()); | ||||||
| 	            } | 			} | ||||||
| 	            if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) { | 			if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) { | ||||||
| 	                ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10); | 				ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10); | ||||||
| 	            } | 			} | ||||||
| 	        } | 		} | ||||||
| 	        if (event.equals(Event.ManagementServerDown)) { | 		if (event.equals(Event.ManagementServerDown)) { | ||||||
| 	            ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60))); | 			ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60))); | ||||||
| 	        } | 		} | ||||||
| 	        int result = update(ub, sc, null); | 		int result = update(ub, sc, null); | ||||||
| 	        assert result <= 1 : "How can this update " + result + " rows? "; | 		assert result <= 1 : "How can this update " + result + " rows? "; | ||||||
| 
 | 
 | ||||||
| 	        if (s_logger.isDebugEnabled() && result == 0) { | 		if (s_logger.isDebugEnabled() && result == 0) { | ||||||
| 	            HostVO ho = findById(host.getId()); | 			HostVO ho = findById(host.getId()); | ||||||
| 	            assert ho != null : "How how how? : " + host.getId(); | 			assert ho != null : "How how how? : " + host.getId(); | ||||||
| 
 | 
 | ||||||
| 	            StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); | 			StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); | ||||||
| 	            str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()) | 			str.append(". New=[status=").append(newStatus.toString()).append(":msid=") | ||||||
| 	                    .append("]"); | 			        .append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]"); | ||||||
| 	            str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=").append(oldPingTime).append("]"); | 			str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=") | ||||||
| 	            str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]"); | 			        .append(oldPingTime).append("]"); | ||||||
| 	            s_logger.debug(str.toString()); | 			str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=") | ||||||
| 	        } | 			        .append(vo.getLastPinged()).append("]"); | ||||||
|  | 			s_logger.debug(str.toString()); | ||||||
|  | 		} | ||||||
| 		 | 		 | ||||||
| 	        return result > 0; | 		StringBuilder msg = new StringBuilder("Agent status update: ["); | ||||||
|  | 		msg.append("hostId = " + host.getId()); | ||||||
|  | 		msg.append("; old status = " + oldStatus); | ||||||
|  | 		msg.append("; event = " + event); | ||||||
|  | 		msg.append("; new status = " + newStatus + "]"); | ||||||
|  | 		s_logger.debug(msg.toString()); | ||||||
|  | 		 | ||||||
|  | 		return result > 0; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|     @Override |     @Override | ||||||
| @ -1009,6 +1017,13 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao | |||||||
|             /*TODO: add defbug info*/ |             /*TODO: add defbug info*/ | ||||||
|         } |         } | ||||||
|          |          | ||||||
|  | 		StringBuilder msg = new StringBuilder("Resource state update: ["); | ||||||
|  | 		msg.append("hostId = " + host.getId()); | ||||||
|  | 		msg.append("; old state = " + oldState); | ||||||
|  | 		msg.append("; event = " + event); | ||||||
|  | 		msg.append("; new status = " + newState + "]"); | ||||||
|  | 		s_logger.debug(msg.toString()); | ||||||
|  | 		 | ||||||
|         return result > 0; |         return result > 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -274,6 +274,7 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, | |||||||
| 		if (_hostIp == null) { | 		if (_hostIp == null) { | ||||||
| 			throw new ConfigurationException("Can't get host IP"); | 			throw new ConfigurationException("Can't get host IP"); | ||||||
| 		} | 		} | ||||||
|  |     	_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @ -355,4 +356,11 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, | |||||||
|         return new DeleteHostAnswer(true); |         return new DeleteHostAnswer(true); | ||||||
|     } |     } | ||||||
| 	 | 	 | ||||||
|  |     @Override | ||||||
|  |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|  |         return super.stop(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
| @ -230,8 +230,10 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer | |||||||
|          |          | ||||||
|         createVmwareToolsIso(); |         createVmwareToolsIso(); | ||||||
| 
 | 
 | ||||||
| 		if(s_logger.isInfoEnabled()) | 		if(s_logger.isInfoEnabled()) { | ||||||
| 			s_logger.info("VmwareServerDiscoverer has been successfully configured"); | 			s_logger.info("VmwareServerDiscoverer has been successfully configured"); | ||||||
|  | 		} | ||||||
|  | 		_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|      |      | ||||||
| @ -280,5 +282,11 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer | |||||||
| 	    // TODO Auto-generated method stub | 	    // TODO Auto-generated method stub | ||||||
| 	    return null; | 	    return null; | ||||||
|     } |     } | ||||||
|  | 	 | ||||||
|  |     @Override | ||||||
|  |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|  |         return super.stop(); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -456,6 +456,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
|         _agentMgr.registerForHostEvents(this, true, false, true); |         _agentMgr.registerForHostEvents(this, true, false, true); | ||||||
|          |          | ||||||
|         createXsToolsISO(); |         createXsToolsISO(); | ||||||
|  |         _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|      |      | ||||||
| @ -652,4 +653,10 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
| 	    // TODO Auto-generated method stub | 	    // TODO Auto-generated method stub | ||||||
| 	    return null; | 	    return null; | ||||||
|     } |     } | ||||||
|  | 	 | ||||||
|  |     @Override | ||||||
|  |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|  |         return super.stop(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -168,6 +168,7 @@ public class ExternalNetworkManagerImpl implements ExternalNetworkManager, Resou | |||||||
| 		if (_externalNetworkStatsInterval > 0){ | 		if (_externalNetworkStatsInterval > 0){ | ||||||
| 			_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ExternalNetworkMonitor"));		 | 			_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ExternalNetworkMonitor"));		 | ||||||
| 		} | 		} | ||||||
|  |     	_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|     	return true; |     	return true; | ||||||
|     } |     } | ||||||
| 	 | 	 | ||||||
| @ -181,6 +182,7 @@ public class ExternalNetworkManagerImpl implements ExternalNetworkManager, Resou | |||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
|     public boolean stop() { |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|     	return true; |     	return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -226,6 +226,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta | |||||||
|          |          | ||||||
|         _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()), 86400); |         _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()), 86400); | ||||||
|         _agentMgr.registerForHostEvents(new DirectNetworkStatsListener( _networkStatsInterval), true, false, false); |         _agentMgr.registerForHostEvents(new DirectNetworkStatsListener( _networkStatsInterval), true, false, false); | ||||||
|  |         _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -236,6 +237,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean stop() { |     public boolean stop() { | ||||||
|  |     	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -981,7 +981,6 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma | |||||||
|             throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event); |             throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         /*TODO: adding debug trace*/ |  | ||||||
|         return _hostDao.updateResourceState(currentState, event, nextState, host); |         return _hostDao.updateResourceState(currentState, event, nextState, host); | ||||||
|     } |     } | ||||||
|      |      | ||||||
| @ -1184,41 +1183,46 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma | |||||||
|         }    |         }    | ||||||
|     } |     } | ||||||
| 	 | 	 | ||||||
| 	 private Object dispatchToStateAdapters(ResourceStateAdapter.Event event, boolean singleTaker, Object...args) { | 	private Object dispatchToStateAdapters(ResourceStateAdapter.Event event, boolean singleTaker, Object... args) { | ||||||
| 	        synchronized (_resourceStateAdapters) { | 		synchronized (_resourceStateAdapters) { | ||||||
| 	            Iterator it = _resourceStateAdapters.entrySet().iterator(); | 			Iterator it = _resourceStateAdapters.entrySet().iterator(); | ||||||
| 	            Object result = null; | 			Object result = null; | ||||||
| 	            while (it.hasNext()) { | 			while (it.hasNext()) { | ||||||
| 	                Map.Entry<String, Pair<ResourceStateAdapter, List<String>>> item = (Map.Entry<String, Pair<ResourceStateAdapter, List<String>>>)it.next(); | 				Map.Entry<String, Pair<ResourceStateAdapter, List<String>>> item = (Map.Entry<String, Pair<ResourceStateAdapter, List<String>>>) it.next(); | ||||||
| 	                ResourceStateAdapter adapter = item.getValue().first(); | 				ResourceStateAdapter adapter = item.getValue().first(); | ||||||
| 	                if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED) { |  | ||||||
| 	                    result = adapter.createHostVOForConnectedAgent((HostVO)args[0], (StartupCommand[])args[1]); |  | ||||||
| 	                    if (result != null && singleTaker) { |  | ||||||
| 	                        break; |  | ||||||
| 	                    } |  | ||||||
| 	                } else if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT) { |  | ||||||
| 	                    result = adapter.createHostVOForDirectConnectAgent((HostVO)args[0], (StartupCommand[])args[1], (ServerResource)args[2], (Map<String, String>)args[3], (List<String>)args[4]); |  | ||||||
| 	                    if (result != null && singleTaker) { |  | ||||||
| 	                        break; |  | ||||||
| 	                    } |  | ||||||
| 	                } else if (event == ResourceStateAdapter.Event.DELETE_HOST) { |  | ||||||
| 	                    try { |  | ||||||
| 	                        result = adapter.deleteHost((HostVO) args[0], (Boolean) args[1], (Boolean) args[2]); |  | ||||||
| 	                        if (result != null) { |  | ||||||
| 	                            break; |  | ||||||
| 	                        } |  | ||||||
| 	                    } catch (UnableDeleteHostException e) { |  | ||||||
| 	                        s_logger.debug("Adapter " + adapter.getName() + " says unable to delete host", e); |  | ||||||
| 	                        result = new ResourceStateAdapter.DeleteHostAnswer(false, true); |  | ||||||
| 	                    } |  | ||||||
| 	                } else { |  | ||||||
| 	                    throw new CloudRuntimeException("Unknown resource state event:" + event); |  | ||||||
| 	                } |  | ||||||
| 	            } |  | ||||||
| 				 | 				 | ||||||
| 	            return result; | 				String msg = new String("Dispatching resource state event " + event + " to " + item.getKey()); | ||||||
| 	        } | 				s_logger.debug(msg); | ||||||
| 	    } | 				 | ||||||
|  | 				if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED) { | ||||||
|  | 					result = adapter.createHostVOForConnectedAgent((HostVO) args[0], (StartupCommand[]) args[1]); | ||||||
|  | 					if (result != null && singleTaker) { | ||||||
|  | 						break; | ||||||
|  | 					} | ||||||
|  | 				} else if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT) { | ||||||
|  | 					result = adapter.createHostVOForDirectConnectAgent((HostVO) args[0], (StartupCommand[]) args[1], (ServerResource) args[2], | ||||||
|  | 					        (Map<String, String>) args[3], (List<String>) args[4]); | ||||||
|  | 					if (result != null && singleTaker) { | ||||||
|  | 						break; | ||||||
|  | 					} | ||||||
|  | 				} else if (event == ResourceStateAdapter.Event.DELETE_HOST) { | ||||||
|  | 					try { | ||||||
|  | 						result = adapter.deleteHost((HostVO) args[0], (Boolean) args[1], (Boolean) args[2]); | ||||||
|  | 						if (result != null) { | ||||||
|  | 							break; | ||||||
|  | 						} | ||||||
|  | 					} catch (UnableDeleteHostException e) { | ||||||
|  | 						s_logger.debug("Adapter " + adapter.getName() + " says unable to delete host", e); | ||||||
|  | 						result = new ResourceStateAdapter.DeleteHostAnswer(false, true); | ||||||
|  | 					} | ||||||
|  | 				} else { | ||||||
|  | 					throw new CloudRuntimeException("Unknown resource state event:" + event); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			return result; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void checkCIDR(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask) throws IllegalArgumentException { | 	public void checkCIDR(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask) throws IllegalArgumentException { | ||||||
| @ -1283,13 +1287,13 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma | |||||||
| 	        ResourceStateAdapter.Event stateEvent) { | 	        ResourceStateAdapter.Event stateEvent) { | ||||||
| 		StartupCommand startup = cmds[0]; | 		StartupCommand startup = cmds[0]; | ||||||
| 		HostVO host = _hostDao.findByGuid(startup.getGuid()); | 		HostVO host = _hostDao.findByGuid(startup.getGuid()); | ||||||
|  | 		boolean isNew = false; | ||||||
| 		if (host == null) { | 		if (host == null) { | ||||||
| 			host = _hostDao.findByGuid(startup.getGuidWithoutResource()); | 			host = _hostDao.findByGuid(startup.getGuidWithoutResource()); | ||||||
| 		} | 		} | ||||||
| 		if (host == null) { | 		if (host == null) { | ||||||
| 			host = new HostVO(startup.getGuid()); | 			host = new HostVO(startup.getGuid()); | ||||||
| 			host.setResource(resource.getClass().getName()); | 			isNew = true; | ||||||
| 			host = _hostDao.persist(host); |  | ||||||
| 		} | 		} | ||||||
| 		// TODO: we don't allow to set ResourceState here? | 		// TODO: we don't allow to set ResourceState here? | ||||||
| 
 | 
 | ||||||
| @ -1375,9 +1379,19 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma | |||||||
| 			host.setStorageMacAddressDeux(startup.getStorageMacAddressDeux()); | 			host.setStorageMacAddressDeux(startup.getStorageMacAddressDeux()); | ||||||
| 			host.setStorageNetmaskDeux(startup.getStorageNetmaskDeux()); | 			host.setStorageNetmaskDeux(startup.getStorageNetmaskDeux()); | ||||||
| 		} | 		} | ||||||
|  | 		if (resource != null) { | ||||||
|  | 			/* null when agent is connected agent */ | ||||||
|  | 			host.setResource(resource.getClass().getName()); | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		host = (HostVO) dispatchToStateAdapters(stateEvent, true, host, cmds, resource, details, hostTags); | 		host = (HostVO) dispatchToStateAdapters(stateEvent, true, host, cmds, resource, details, hostTags); | ||||||
| 		_hostDao.update(host.getId(), host); | 		assert host != null : "No resource state adapter response"; | ||||||
|  | 		 | ||||||
|  | 		if (isNew) { | ||||||
|  | 			_hostDao.persist(host); | ||||||
|  | 		} else { | ||||||
|  | 			_hostDao.update(host.getId(), host); | ||||||
|  | 		} | ||||||
| 		/* Agent goes to Connecting status */ | 		/* Agent goes to Connecting status */ | ||||||
| 		_agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, _nodeId); | 		_agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, _nodeId); | ||||||
| 		try { | 		try { | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										2
									
								
								server/src/com/cloud/secstorage/PremiumSecondaryStorageManagerImpl.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @ -68,7 +68,7 @@ public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerI | |||||||
| 
 | 
 | ||||||
| 		HostSearch.done(); | 		HostSearch.done(); | ||||||
| 		ActiveCommandSearch.done(); | 		ActiveCommandSearch.done(); | ||||||
|          | 		_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|     	return true; |     	return true; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  | |||||||
| @ -72,6 +72,7 @@ import com.cloud.network.NetworkManager; | |||||||
| import com.cloud.network.NetworkVO; | import com.cloud.network.NetworkVO; | ||||||
| import com.cloud.network.Networks.TrafficType; | import com.cloud.network.Networks.TrafficType; | ||||||
| import com.cloud.offerings.NetworkOfferingVO; | import com.cloud.offerings.NetworkOfferingVO; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
| import com.cloud.resource.ResourceStateAdapter; | import com.cloud.resource.ResourceStateAdapter; | ||||||
| import com.cloud.resource.ServerResource; | import com.cloud.resource.ServerResource; | ||||||
| import com.cloud.resource.UnableDeleteHostException; | import com.cloud.resource.UnableDeleteHostException; | ||||||
| @ -197,6 +198,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V | |||||||
|     protected CapacityDao                         _capacityDao; |     protected CapacityDao                         _capacityDao; | ||||||
|     @Inject |     @Inject | ||||||
|     UserVmDetailsDao _vmDetailsDao; |     UserVmDetailsDao _vmDetailsDao; | ||||||
|  |     @Inject  | ||||||
|  |     protected ResourceManager _resourceMgr; | ||||||
| 
 | 
 | ||||||
|     private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL; |     private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL; | ||||||
| 
 | 
 | ||||||
| @ -738,6 +741,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V | |||||||
|     public boolean stop() { |     public boolean stop() { | ||||||
|         _loadScanner.stop(); |         _loadScanner.stop(); | ||||||
|         _allocLock.releaseRef(); |         _allocLock.releaseRef(); | ||||||
|  |         _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -813,6 +817,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V | |||||||
|         if (s_logger.isInfoEnabled()) { |         if (s_logger.isInfoEnabled()) { | ||||||
|             s_logger.info("Secondary storage vm Manager is configured."); |             s_logger.info("Secondary storage vm Manager is configured."); | ||||||
|         } |         } | ||||||
|  |         _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -699,6 +699,7 @@ CREATE TABLE  `cloud`.`host` ( | |||||||
|   `created` datetime COMMENT 'date the host first signed on', |   `created` datetime COMMENT 'date the host first signed on', | ||||||
|   `removed` datetime COMMENT 'date removed if not null', |   `removed` datetime COMMENT 'date removed if not null', | ||||||
|   `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this host enabled for allocation for new resources', |   `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this host enabled for allocation for new resources', | ||||||
|  |   `resource_state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'Is this host enabled for allocation for new resources', | ||||||
|   PRIMARY KEY  (`id`), |   PRIMARY KEY  (`id`), | ||||||
|   INDEX `i_host__removed`(`removed`), |   INDEX `i_host__removed`(`removed`), | ||||||
|   INDEX `i_host__last_ping`(`last_ping`), |   INDEX `i_host__last_ping`(`last_ping`), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user