diff --git a/engine/components-api/src/com/cloud/agent/AgentManager.java b/engine/components-api/src/com/cloud/agent/AgentManager.java index f820227523e..a6a69256db8 100755 --- a/engine/components-api/src/com/cloud/agent/AgentManager.java +++ b/engine/components-api/src/com/cloud/agent/AgentManager.java @@ -20,24 +20,29 @@ import org.apache.cloudstack.framework.config.ConfigKey; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; +import com.cloud.agent.api.StartupCommand; import com.cloud.agent.manager.Commands; import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.ConnectionException; import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.resource.ServerResource; /** * AgentManager manages hosts. It directly coordinates between the DAOs and the connections it manages. */ public interface AgentManager { - final static String WaitCK = "wait"; - static final ConfigKey Wait = new ConfigKey("Advanced", Integer.class, WaitCK, "1800", "Time in seconds to wait for control commands to return", true); + static final ConfigKey Wait = new ConfigKey("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return", true); public enum TapAgentsAction { Add, Del, Contains, } + boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException; + /** * easy send method that returns null if there's any errors. It handles all exceptions. * diff --git a/engine/components-api/src/com/cloud/resource/ResourceManager.java b/engine/components-api/src/com/cloud/resource/ResourceManager.java index 85af36f502a..97d9a59d4e2 100755 --- a/engine/components-api/src/com/cloud/resource/ResourceManager.java +++ b/engine/components-api/src/com/cloud/resource/ResourceManager.java @@ -109,8 +109,6 @@ public interface ResourceManager extends ResourceService { public HostVO findHostByName(String name); - public List listHostsByNameLike(String name); - HostStats getHostStatistics(long hostId); Long getGuestOSCategoryId(long hostId); diff --git a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java index 7bdc6ffc335..811ff133f74 100755 --- a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -41,7 +41,6 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.apache.cloudstack.context.ServerContexts; -import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -166,9 +165,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Inject ResourceManager _resourceMgr; - @Inject - protected ConfigDepot _configDepot; - protected final ConfigKey Workers = new ConfigKey(Integer.class, "workers", "Advance", "5", "Number of worker threads handling remote agent connections.", false); protected final ConfigKey Port = new ConfigKey(Integer.class, "port", "Advance", "8250", "Port to listen on for remote agent connections.", false); @@ -678,7 +674,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } - protected AgentAttache createAttacheForDirectConnect(HostVO host, ServerResource resource) + protected AgentAttache createAttacheForDirectConnect(Host host, ServerResource resource) throws ConnectionException { // if (resource instanceof DummySecondaryStorageResource || resource instanceof KvmDummyResourceBase) { // return new DummyAttache(this, host.getId(), false); @@ -1383,7 +1379,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl disconnectInternal(hostId, event, false); } - public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException { + @Override + public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException { AgentAttache attache; attache = createAttacheForDirectConnect(host, resource); @@ -1394,7 +1391,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl attache.process(answers); attache = notifyMonitorsOfConnection(attache, cmds, forRebalance); - return attache; + return attache != null; } @Override diff --git a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index ca94fbc50df..61066ec7dbc 100755 --- a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -279,7 +279,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } @Override - protected AgentAttache createAttacheForDirectConnect(HostVO host, ServerResource resource) { + protected AgentAttache createAttacheForDirectConnect(Host host, ServerResource resource) { // if (resource instanceof DummySecondaryStorageResource) { // return new DummyAttache(this, host.getId(), false); // } diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java index 62bd077ca1c..ec681192aae 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java @@ -26,10 +26,6 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.host.Host; -import com.cloud.host.Status; -import com.cloud.utils.fsm.NoTransitionException; -import com.cloud.utils.fsm.StateMachine2; import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; @@ -38,15 +34,19 @@ import com.cloud.agent.StartupCommandProcessor; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; import com.cloud.agent.api.SetupCommand; +import com.cloud.agent.api.StartupCommand; import com.cloud.agent.manager.Commands; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.dao.ClusterDao; import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.ConnectionException; import com.cloud.exception.DiscoveryException; import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; import com.cloud.host.HostEnvironment; import com.cloud.host.HostVO; +import com.cloud.host.Status; import com.cloud.host.Status.Event; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -56,6 +56,8 @@ import com.cloud.hypervisor.xen.resource.XcpOssResource; import com.cloud.resource.ServerResource; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.utils.fsm.StateMachine2; public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager { private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class); @@ -276,4 +278,10 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa return false; } + @Override + public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException { + // TODO Auto-generated method stub + return false; + } + } diff --git a/framework/cluster/src/com/cloud/cluster/ClusterManager.java b/framework/cluster/src/com/cloud/cluster/ClusterManager.java index 90846a48045..d843f2a4129 100644 --- a/framework/cluster/src/com/cloud/cluster/ClusterManager.java +++ b/framework/cluster/src/com/cloud/cluster/ClusterManager.java @@ -26,6 +26,7 @@ public interface ClusterManager extends Manager { "Interval to check for the heart beat between management server nodes", false); final ConfigKey HeartbeatThreshold = new ConfigKey(Integer.class, "cluster.heartbeat.threshold", "management-server", "150000", "Threshold before self-fence the management server", true); + final ConfigKey ManagementHostIPAdr = new ConfigKey("Advanced", String.class, "host", "localhost", "The ip address of management server", true); void OnReceiveClusterServicePdu(ClusterServicePdu pdu); diff --git a/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java b/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java index ec74489a39a..98d5b79f1e7 100644 --- a/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java +++ b/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java @@ -1108,7 +1108,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {HeartbeatInterval, HeartbeatThreshold}; + return new ConfigKey[] {HeartbeatInterval, HeartbeatThreshold, ManagementHostIPAdr}; } private boolean pingManagementNode(ManagementServerHostVO mshost) { diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java index 8021f2ff933..c13d8610c54 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java @@ -81,7 +81,7 @@ public class ConfigKey { static ConfigDepotImpl s_depot = null; - static void init(ConfigDepotImpl depot) { + static public void init(ConfigDepotImpl depot) { s_depot = depot; } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/Configurable.java b/framework/config/src/org/apache/cloudstack/framework/config/Configurable.java index f99e8a11cfa..4db1c9470fd 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/Configurable.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/Configurable.java @@ -26,7 +26,15 @@ package org.apache.cloudstack.framework.config; */ public interface Configurable { + /** + * @return The name of the component that provided this configuration + * variable. This value is saved in the database so someone can easily + * identify who provides this variable. + **/ String getConfigComponentName(); + /** + * @return The list of config keys provided by this configuable. + */ ConfigKey[] getConfigKeys(); } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java index 0def7f498bb..b516596febc 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java @@ -55,7 +55,14 @@ import com.cloud.utils.exception.CloudRuntimeException; * - Move all of the configurations to using ConfigDepot * - Completely eliminate Config.java * - Figure out the correct categories. - * + * - Add a scope for management server, where if the scope is management server + * then the override is retrieved from a properties file. Imagine adding a + * new management server node and it is much more capable system than previous + * management servers, you want the adjustments to thread pools etc to be + * very different than other management serves. + * - Add validation methods to ConfigKey. If a validation class is declared + * when constructing a ConfigKey then configuration server should use the + * validation class to validate the value the admin input for the key. */ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker { private final static Logger s_logger = Logger.getLogger(ConfigDepotImpl.class); @@ -69,6 +76,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemInt HashMap>> _allKeys = new HashMap>>(1007); public ConfigDepotImpl() { + ConfigKey.init(this); } @Override diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index bfeec487adc..ecd6006edad 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -51,6 +51,7 @@ import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.manager.Commands; +import com.cloud.cluster.ClusterManager; import com.cloud.configuration.Config; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; @@ -210,7 +211,6 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast ServiceOfferingVO _elasticLbVmOffering; ScheduledExecutorService _gcThreadPool; String _mgmtCidr; - String _mgmtHost; Set _gcCandidateElbVmIds = Collections.newSetFromMap(new ConcurrentHashMap()); @@ -403,7 +403,6 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast _instance = "VM"; } _mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key()); - _mgmtHost = _configDao.getValue(Config.ManagementHostIPAdr.key()); boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); @@ -812,8 +811,9 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast // control command is sent over management network in VMware if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { if (s_logger.isInfoEnabled()) { - s_logger.info("Check if we need to add management server explicit route to ELB vm. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() - + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmtHost); + s_logger.info("Check if we need to add management server explicit route to ELB vm. pod cidr: " + dest.getPod().getCidrAddress() + "/" + + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + + ClusterManager.ManagementHostIPAdr.value()); } if (s_logger.isDebugEnabled()) { diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 9eca56f32b6..f867e2ce29e 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -176,7 +176,6 @@ public enum Config { SystemVMRandomPassword("Advanced", ManagementServer.class, Boolean.class, "system.vm.random.password", "false", "Randomize system vm password the first time management server starts", null), LinkLocalIpNums("Advanced", ManagementServer.class, Integer.class, "linkLocalIp.nums", "10", "The number of link local ip that needed by domR(in power of 2)", null), HypervisorList("Advanced", ManagementServer.class, String.class, "hypervisor.list", HypervisorType.Hyperv + "," + HypervisorType.KVM + "," + HypervisorType.XenServer + "," + HypervisorType.VMware + "," + HypervisorType.BareMetal + "," + HypervisorType.Ovm + "," + HypervisorType.LXC, "The list of hypervisors that this deployment will use.", "hypervisorList"), - ManagementHostIPAdr("Advanced", ManagementServer.class, String.class, "host", "localhost", "The ip address of management server", null), ManagementNetwork("Advanced", ManagementServer.class, String.class, "management.network.cidr", null, "The cidr of management server network", null), EventPurgeDelay("Advanced", ManagementServer.class, Integer.class, "event.purge.delay", "15", "Events older than specified number days will be purged. Set this value to 0 to never delete events", null), SecStorageVmMTUSize("Advanced", AgentManager.class, Integer.class, "secstorage.vm.mtu.size", String.valueOf(SecondaryStorageVmManager.DEFAULT_SS_VM_MTUSIZE), "MTU size (in Byte) of storage network in secondary storage vms", null), diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index c8475885d6a..90273f7588d 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -165,7 +165,6 @@ VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { private int _consoleProxyPort = ConsoleProxyManager.DEFAULT_PROXY_VNC_PORT; - private String _mgmt_host; private int _mgmt_port = 8250; @Inject @@ -1267,10 +1266,6 @@ VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { prepareDefaultCertificate(); Map agentMgrConfigs = _configDao.getConfiguration("AgentManager", params); - _mgmt_host = agentMgrConfigs.get("host"); - if (_mgmt_host == null) { - s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't be able to do console access"); - } value = agentMgrConfigs.get("port"); _mgmt_port = NumbersUtil.parseInt(value, 8250); @@ -1342,7 +1337,7 @@ VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { StringBuilder buf = profile.getBootArgsBuilder(); buf.append(" template=domP type=consoleproxy"); - buf.append(" host=").append(_mgmt_host); + buf.append(" host=").append(ClusterManager.ManagementHostIPAdr.value()); buf.append(" port=").append(_mgmt_port); buf.append(" name=").append(profile.getVirtualMachine().getHostName()); if (_sslEnabled) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index bd7aa383103..7c026a4cb80 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -96,6 +96,7 @@ import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.StaticNatRuleTO; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; +import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ManagementServerHostVO; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.configuration.Config; @@ -373,7 +374,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V int _routerCpuMHz; int _retry = 2; String _instance; - String _mgmt_host; String _mgmt_cidr; int _routerStatsInterval = 300; @@ -649,7 +649,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V final Map configs = _configDao.getConfiguration("AgentManager", params); - _mgmt_host = configs.get("host"); _routerRamSize = NumbersUtil.parseInt(configs.get("router.ram.size"), DEFAULT_ROUTER_VM_RAMSIZE); _routerCpuMHz = NumbersUtil.parseInt(configs.get("router.cpu.mhz"), DEFAULT_ROUTER_CPU_MHZ); @@ -2060,11 +2059,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V controlNic = nic; // DOMR control command is sent over management server in VMware if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: " - + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() - + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmt_host); - } + s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: " + dest.getPod().getCidrAddress() + "/" + + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + ClusterManager.ManagementHostIPAdr.value()); if (s_logger.isInfoEnabled()) { s_logger.info("Add management server explicit route to DomR."); diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index d1b029da36c..69cbd5bb0d2 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -159,7 +159,7 @@ import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; @Component -@Local({ ResourceManager.class, ResourceService.class }) +@Local({ResourceManager.class, ResourceService.class}) public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService, Manager { private static final Logger s_logger = Logger.getLogger(ResourceManagerImpl.class); @@ -212,7 +212,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject PlannerHostReservationDao _plannerHostReserveDao; @Inject - protected DedicatedResourceDao _dedicatedDao; + protected DedicatedResourceDao _dedicatedDao; protected List _discoverers; @@ -229,7 +229,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject protected StoragePoolHostDao _storagePoolHostDao; - @Inject protected VMTemplateDao _templateDao; @Inject @@ -297,7 +296,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, synchronized (_lifeCycleListeners) { Iterator it = _lifeCycleListeners.entrySet().iterator(); while (it.hasNext()) { - Map.Entry> items = (Map.Entry>) it.next(); + Map.Entry> items = (Map.Entry>)it.next(); List lst = items.getValue(); lst.remove(listener); } @@ -313,29 +312,28 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, String eventName; for (ResourceListener l : lst) { if (event == ResourceListener.EVENT_DISCOVER_BEFORE) { - l.processDiscoverEventBefore((Long) params[0], (Long) params[1], (Long) params[2], (URI) params[3], (String) params[4], - (String) params[5], (List) params[6]); + l.processDiscoverEventBefore((Long)params[0], (Long)params[1], (Long)params[2], (URI)params[3], (String)params[4], (String)params[5], (List)params[6]); eventName = "EVENT_DISCOVER_BEFORE"; } else if (event == ResourceListener.EVENT_DISCOVER_AFTER) { - l.processDiscoverEventAfter((Map>) params[0]); + l.processDiscoverEventAfter((Map>)params[0]); eventName = "EVENT_DISCOVER_AFTER"; } else if (event == ResourceListener.EVENT_DELETE_HOST_BEFORE) { - l.processDeleteHostEventBefore((HostVO) params[0]); + l.processDeleteHostEventBefore((HostVO)params[0]); eventName = "EVENT_DELETE_HOST_BEFORE"; } else if (event == ResourceListener.EVENT_DELETE_HOST_AFTER) { - l.processDeletHostEventAfter((HostVO) params[0]); + l.processDeletHostEventAfter((HostVO)params[0]); eventName = "EVENT_DELETE_HOST_AFTER"; } else if (event == ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE) { - l.processCancelMaintenaceEventBefore((Long) params[0]); + l.processCancelMaintenaceEventBefore((Long)params[0]); eventName = "EVENT_CANCEL_MAINTENANCE_BEFORE"; } else if (event == ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER) { - l.processCancelMaintenaceEventAfter((Long) params[0]); + l.processCancelMaintenaceEventAfter((Long)params[0]); eventName = "EVENT_CANCEL_MAINTENANCE_AFTER"; } else if (event == ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE) { - l.processPrepareMaintenaceEventBefore((Long) params[0]); + l.processPrepareMaintenaceEventBefore((Long)params[0]); eventName = "EVENT_PREPARE_MAINTENANCE_BEFORE"; } else if (event == ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER) { - l.processPrepareMaintenaceEventAfter((Long) params[0]); + l.processPrepareMaintenaceEventAfter((Long)params[0]); eventName = "EVENT_PREPARE_MAINTENANCE_AFTER"; } else { throw new CloudRuntimeException("Unknown resource event:" + event); @@ -364,16 +362,14 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // Check if the zone exists in the system DataCenterVO zone = _dcDao.findById(dcId); if (zone == null) { - InvalidParameterValueException ex = new InvalidParameterValueException( - "Can't find zone by the id specified"); + InvalidParameterValueException ex = new InvalidParameterValueException("Can't find zone by the id specified"); ex.addProxyObject(String.valueOf(dcId), "dcId"); throw ex; } Account account = CallContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - PermissionDeniedException ex = new PermissionDeniedException( - "Cannot perform this operation, Zone with specified id is currently disabled"); + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; } @@ -389,8 +385,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } // check if pod belongs to the zone if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) { - InvalidParameterValueException ex = new InvalidParameterValueException( - "Pod with specified id doesn't belong to the zone " + dcId); + InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified id doesn't belong to the zone " + dcId); ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; @@ -412,8 +407,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } if (zone.isSecurityGroupEnabled() && zone.getNetworkType().equals(NetworkType.Advanced)) { - if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.XenServer - && hypervisorType != HypervisorType.Simulator) { + if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.XenServer && hypervisorType != HypervisorType.Simulator) { throw new InvalidParameterValueException("Don't support hypervisor type " + hypervisorType + " in advanced security enabled zone"); } } @@ -460,8 +454,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, cluster = _clusterDao.persist(cluster); } catch (Exception e) { // no longer tolerate exception during the cluster creation phase - CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName - + " in pod and data center with specified ids", e); + CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod and data center with specified ids", e); // Get the pod VO object's table name. ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); @@ -509,7 +502,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, for (Map.Entry> entry : resources.entrySet()) { ServerResource resource = entry.getKey(); - HostVO host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, null, false); + HostVO host = (HostVO)createHostAndAgent(resource, entry.getValue(), true, null, false); if (host != null) { hosts.add(host); } @@ -561,8 +554,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (clusterId != null) { ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null) { - InvalidParameterValueException ex = new InvalidParameterValueException( - "can not find cluster for specified clusterId"); + InvalidParameterValueException ex = new InvalidParameterValueException("can not find cluster for specified clusterId"); ex.addProxyObject(clusterId.toString(), "clusterId"); throw ex; } else { @@ -570,7 +562,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, List hosts = listAllHostsInCluster(clusterId); if (!hosts.isEmpty()) { CloudRuntimeException ex = new CloudRuntimeException( - "Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up"); + "Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up"); ex.addProxyObject(cluster.getUuid(), "clusterId"); throw ex; } @@ -578,21 +570,18 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } } - return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, cmd.getHypervisor(), hostTags, cmd.getFullUrlParams(), - true); + return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, cmd.getHypervisor(), hostTags, cmd.getFullUrlParams(), true); } @Override - public List discoverHosts(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, - InvalidParameterValueException { + public List discoverHosts(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { Long dcId = cmd.getZoneId(); String url = cmd.getUrl(); return discoverHostsFull(dcId, null, null, null, url, null, null, "SecondaryStorage", null, null, false); } - private List discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, - String hypervisorType, List hostTags, Map params, boolean deferAgentCreation) throws IllegalArgumentException, - DiscoveryException, InvalidParameterValueException { + private List discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, + List hostTags, Map params, boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { URI uri = null; // Check if the zone exists in the system @@ -603,8 +592,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Account account = CallContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - PermissionDeniedException ex = new PermissionDeniedException( - "Cannot perform this operation, Zone with specified id is currently disabled"); + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; } @@ -617,11 +605,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } // check if pod belongs to the zone if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) { - InvalidParameterValueException ex = new InvalidParameterValueException( - "Pod with specified podId" - + podId - + " doesn't belong to the zone with specified zoneId" - + dcId); + InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified podId" + podId + " doesn't belong to the zone with specified zoneId" + + dcId); ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; @@ -680,11 +665,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } catch (Exception e) { cluster = _clusterDao.findBy(clusterName, podId); if (cluster == null) { - CloudRuntimeException ex = new CloudRuntimeException( - "Unable to create cluster " - + clusterName - + " in pod with specified podId and data center with specified dcID", - e); + CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + + " in pod with specified podId and data center with specified dcID", e); ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; @@ -733,8 +715,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } catch (DiscoveryException e) { throw e; } catch (Exception e) { - s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName() - + ", skip to another discoverer if there is any"); + s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName() + ", skip to another discoverer if there is any"); } processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, resources); @@ -766,9 +747,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, HostVO host = null; if (deferAgentCreation) { - host = (HostVO) createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false); + host = (HostVO)createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false); } else { - host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, hostTags, false); + host = (HostVO)createHostAndAgent(resource, entry.getValue(), true, hostTags, false); } if (host != null) { hosts.add(host); @@ -805,19 +786,20 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId()); if (!isForced && host.getResourceState() != ResourceState.Maintenance) { - 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."); + 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."); } // Get storage pool host mappings here because they can be removed as a // part of handleDisconnect later // TODO: find out the bad boy, what's a buggy logic! List pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId); - ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters( - ResourceStateAdapter.Event.DELETE_HOST, false, host, new Boolean(isForced), new Boolean(isForceDeleteStorage)); + ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, + new Boolean(isForced), new Boolean(isForceDeleteStorage)); if (answer == null) { - throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId - + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType()); + throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId + ", hypervisorType is " + + host.getHypervisorType() + ", host type is " + host.getType()); } if (answer.getIsException()) { @@ -885,7 +867,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } // delete the op_host_capacity entry - Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY }; + Object[] capacityTypes = {Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY}; SearchCriteria hostCapacitySC = _capacityDao.createSearchCriteria(); hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId); hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes); @@ -980,7 +962,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @DB public Cluster updateCluster(Cluster clusterToUpdate, String clusterType, String hypervisor, String allocationState, String managedstate) { - ClusterVO cluster = (ClusterVO) clusterToUpdate; + ClusterVO cluster = (ClusterVO)clusterToUpdate; // Verify cluster information and update the cluster if needed boolean doUpdate = false; @@ -1067,9 +1049,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, txn.commit(); List hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); for (HostVO host : hosts) { - if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) - && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up) - && !host.getStatus().equals(Status.Alert)) { + if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && + !host.getStatus().equals(Status.Up) && !host.getStatus().equals(Status.Alert)) { String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status"; throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg); } @@ -1090,8 +1071,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); for (HostVO host : hosts) { - if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) - && !host.getStatus().equals(Status.Alert)) { + if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Alert)) { lsuccess = false; break; } @@ -1102,8 +1082,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } } if (success == false) { - throw new CloudRuntimeException( - "PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later "); + throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later "); } } finally { txn.start(); @@ -1177,7 +1156,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, private boolean doMaintain(final long hostId) { HostVO host = _hostDao.findById(hostId); - MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand()); + MaintainAnswer answer = (MaintainAnswer)_agentMgr.easySend(hostId, new MaintainCommand()); if (answer == null || !answer.getResult()) { s_logger.warn("Unable to send MaintainCommand to host: " + hostId); } @@ -1235,13 +1214,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) { - throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " - + host.getClusterId()); + throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + host.getClusterId()); } if (_storageMgr.isLocalStorageActiveOnHost(host.getId())) { - throw new InvalidParameterValueException( - "There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage."); + throw new InvalidParameterValueException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage."); } try { @@ -1437,27 +1414,26 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Iterator> it = _resourceStateAdapters.entrySet().iterator(); Object result = null; while (it.hasNext()) { - Map.Entry item = it - .next(); + Map.Entry item = it.next(); ResourceStateAdapter adapter = item.getValue(); 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]); + 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) args[3], (List) args[4]); + result = adapter.createHostVOForDirectConnectAgent((HostVO)args[0], (StartupCommand[])args[1], (ServerResource)args[2], (Map)args[3], + (List)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]); + result = adapter.deleteHost((HostVO)args[0], (Boolean)args[1], (Boolean)args[2]); if (result != null) { break; } @@ -1488,10 +1464,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSize); String serverSubnet = NetUtils.getSubNet(serverPrivateIP, serverPrivateNetmask); if (!cidrSubnet.equals(serverSubnet)) { - s_logger.warn("The private ip address of the server (" + serverPrivateIP + ") is not compatible with the CIDR of pod: " + pod.getName() - + " and zone: " + dc.getName()); - throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP - + ") is not compatible with the CIDR of pod: " + pod.getName() + " and zone: " + dc.getName()); + s_logger.warn("The private ip address of the server (" + serverPrivateIP + ") is not compatible with the CIDR of pod: " + pod.getName() + " and zone: " + dc.getName()); + throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is not compatible with the CIDR of pod: " + pod.getName() + + " and zone: " + dc.getName()); } // If the server's private netmask is less inclusive than the pod's CIDR @@ -1500,8 +1475,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, long cidrNetmaskNumeric = NetUtils.ip2Long(cidrNetmask); long serverNetmaskNumeric = NetUtils.ip2Long(serverPrivateNetmask); if (serverNetmaskNumeric > cidrNetmaskNumeric) { - throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP - + ") is not compatible with the CIDR of pod: " + pod.getName() + " and zone: " + dc.getName()); + throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is not compatible with the CIDR of pod: " + pod.getName() + + " and zone: " + dc.getName()); } } @@ -1533,8 +1508,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return true; } - protected HostVO createHostVO(StartupCommand[] cmds, ServerResource resource, Map details, List hostTags, - ResourceStateAdapter.Event stateEvent) { + protected HostVO createHostVO(StartupCommand[] cmds, ServerResource resource, Map details, List hostTags, ResourceStateAdapter.Event stateEvent) { StartupCommand startup = cmds[0]; HostVO host = findHostByGuid(startup.getGuid()); boolean isNew = false; @@ -1633,7 +1607,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, 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); if (host == null) { throw new CloudRuntimeException("No resource state adapter response"); } @@ -1702,6 +1676,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, HostVO host = null; StartupCommand[] cmds = null; boolean hostExists = false; + boolean created = false; try { cmds = resource.initialize(); @@ -1729,20 +1704,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (host == null) { host = findHostByGuid(firstCmd.getGuidWithoutResource()); } - if (host != null && host.getRemoved() == null) { // host already - // added, no - // need to add - // again + if (host != null && host.getRemoved() == null) { // host already added, no need to add again s_logger.debug("Found the host " + host.getId() + " by guid: " + firstCmd.getGuid() + ", old host reconnected as new"); - hostExists = true; // ensures that host status is left - // unchanged in case of adding same one - // again + hostExists = true; // ensures that host status is left unchanged in case of adding same one again return null; } } host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT); if (host != null) { + created = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance); /* reload myself from database */ host = _hostDao.findById(host.getId()); } @@ -1753,18 +1724,25 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (cmds != null) { resource.disconnected(); } + } else { + if (!created) { + if (cmds != null) { + resource.disconnected(); + } + markHostAsDisconnected(host, cmds); + } } } return host; } - private Host createHostAndAgentDeferred(ServerResource resource, Map details, boolean old, List hostTags, - boolean forRebalance) { + private Host createHostAndAgentDeferred(ServerResource resource, Map details, boolean old, List hostTags, boolean forRebalance) { HostVO host = null; StartupCommand[] cmds = null; boolean hostExists = false; boolean deferAgentCreation = true; + boolean created = false; try { cmds = resource.initialize(); @@ -1825,6 +1803,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (host != null) { if (!deferAgentCreation) { // if first host in cluster then + created = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance); host = _hostDao.findById(host.getId()); // reload } else { host = _hostDao.findById(host.getId()); // reload @@ -1846,7 +1825,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, resource.disconnected(); } } else { - if (!deferAgentCreation) { + if (!deferAgentCreation && !created) { if (cmds != null) { resource.disconnected(); } @@ -1859,8 +1838,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } @Override - public Host createHostAndAgent(Long hostId, ServerResource resource, Map details, boolean old, List hostTags, - boolean forRebalance) { + public Host createHostAndAgent(Long hostId, ServerResource resource, Map details, boolean old, List hostTags, boolean forRebalance) { Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance); return host; } @@ -1889,8 +1867,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return createHostVO(cmds, null, null, null, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED); } - private void checkIPConflicts(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask, String serverPublicIP, - String serverPublicNetmask) { + private void checkIPConflicts(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask, String serverPublicIP, String serverPublicNetmask) { // If the server's private IP is the same as is public IP, this host has // a host-only private network. Don't check for conflicts with the // private IP address table. @@ -1898,19 +1875,18 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (!_privateIPAddressDao.mark(dc.getId(), pod.getId(), serverPrivateIP)) { // If the server's private IP address is already in the // database, return false - List existingPrivateIPs = _privateIPAddressDao.listByPodIdDcIdIpAddress(pod.getId(), dc.getId(), - serverPrivateIP); + List existingPrivateIPs = _privateIPAddressDao.listByPodIdDcIdIpAddress(pod.getId(), dc.getId(), serverPrivateIP); assert existingPrivateIPs.size() <= 1 : " How can we get more than one ip address with " + serverPrivateIP; if (existingPrivateIPs.size() > 1) { - throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " - + pod.getName() + " and zone: " + dc.getName()); + throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + pod.getName() + " and zone: " + + dc.getName()); } if (existingPrivateIPs.size() == 1) { DataCenterIpAddressVO vo = existingPrivateIPs.get(0); if (vo.getInstanceId() != null) { - throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP - + ") is already in use in pod: " + pod.getName() + " and zone: " + dc.getName()); + throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + pod.getName() + + " and zone: " + dc.getName()); } } } @@ -1921,15 +1897,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // return false List existingPublicIPs = _publicIPAddressDao.listByDcIdIpAddress(dc.getId(), serverPublicIP); if (existingPublicIPs.size() > 0) { - throw new IllegalArgumentException("The public ip address of the server (" + serverPublicIP + ") is already in use in zone: " - + dc.getName()); + throw new IllegalArgumentException("The public ip address of the server (" + serverPublicIP + ") is already in use in zone: " + dc.getName()); } } } @Override - public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, HypervisorType hyType, Map details, - List hostTags) { + public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, HypervisorType hyType, Map details, List hostTags) { if (host.getPodId() == null) { s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null"); throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null"); @@ -1937,8 +1911,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); if (clusterVO.getHypervisorType() != hyType) { - throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() - + " whose hypervisor type is: " + clusterVO.getHypervisorType()); + throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + + clusterVO.getHypervisorType()); } final Map hostDetails = ssCmd.getHostDetails(); @@ -2027,8 +2001,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } } } else { - throw new UnableDeleteHostException("Unable to delete the host as there are vms in " + vms.get(0).getState() - + " state using this host and isForced=false specified"); + throw new UnableDeleteHostException("Unable to delete the host as there are vms in " + vms.get(0).getState() + + " state using this host and isForced=false specified"); } } } @@ -2046,10 +2020,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, * TODO: think twice about returning true or throwing out exception, I * really prefer to exception that always exposes bugs */ - if (host.getResourceState() != ResourceState.PrepareForMaintenance && host.getResourceState() != ResourceState.Maintenance - && host.getResourceState() != ResourceState.ErrorInMaintenance) { - throw new CloudRuntimeException("Cannot perform cancelMaintenance when resource state is " + host.getResourceState() + ", hostId = " - + hostId); + if (host.getResourceState() != ResourceState.PrepareForMaintenance && host.getResourceState() != ResourceState.Maintenance && + host.getResourceState() != ResourceState.ErrorInMaintenance) { + throw new CloudRuntimeException("Cannot perform cancelMaintenance when resource state is " + host.getResourceState() + ", hostId = " + hostId); } /* TODO: move to listener */ @@ -2142,7 +2115,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } if (host.getHypervisorType() == HypervisorType.KVM) { - MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand()); + MaintainAnswer answer = (MaintainAnswer)_agentMgr.easySend(hostId, new MaintainCommand()); } _agentMgr.disconnectWithoutInvestigation(hostId, Event.ShutdownRequested); @@ -2265,8 +2238,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, try { return resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId); } catch (NoTransitionException e) { - s_logger.debug("No next resource state for host " + host.getId() + " while current state is " + host.getResourceState() - + " with event " + ResourceState.Event.UnableToMigrate, e); + s_logger.debug("No next resource state for host " + host.getId() + " while current state is " + host.getResourceState() + " with event " + + ResourceState.Event.UnableToMigrate, e); return false; } } @@ -2345,8 +2318,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId); } sc.addAnd(sc.getEntity().getType(), Op.EQ, type); - sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, - ResourceState.PrepareForMaintenance, ResourceState.Error); + sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance, ResourceState.Error); return sc.list(); } @@ -2402,18 +2374,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return sc.find(); } - @Override - public List listHostsByNameLike(String name) { - SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); - sc.addAnd(sc.getEntity().getName(), Op.LIKE, "%" + name + "%"); - return sc.list(); - } - - @Override public HostStats getHostStatistics(long hostId) { - Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), - hostId)); + Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), hostId)); if (answer != null && (answer instanceof UnsupportedAnswer)) { return null; @@ -2427,7 +2390,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // now construct the result object if (answer instanceof GetHostStatsAnswer) { - return ((GetHostStatsAnswer) answer).getHostStats(); + return ((GetHostStatsAnswer)answer).getHostStats(); } } return null; @@ -2510,8 +2473,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return true; } if (s_logger.isDebugEnabled()) { - s_logger.debug("Host reservation for host: " + hostId - + " does not even exist. Release reservartion call is ignored."); + s_logger.debug("Host reservation for host: " + hostId + " does not even exist. Release reservartion call is ignored."); } return false; } catch (CloudRuntimeException e) { diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index dc56fc678c9..4c5c8a1c1cf 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -51,6 +51,7 @@ import org.apache.cloudstack.framework.config.ConfigDepotAdmin; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; +import com.cloud.cluster.ClusterManager; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource; @@ -224,14 +225,14 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio if (hostIpAdr != null) { Boolean devel = Boolean.valueOf(_configDao.getValue("developer")); if (devel) { - String value = _configDao.getValue(Config.ManagementHostIPAdr.key()); + String value = _configDao.getValue(ClusterManager.ManagementHostIPAdr.key()); if (value != null && !value.equals("localhost")) { needUpdateHostIp = false; } } if (needUpdateHostIp) { - _configDao.update(Config.ManagementHostIPAdr.key(), Config.ManagementHostIPAdr.getCategory(), hostIpAdr); + _configDao.update(ClusterManager.ManagementHostIPAdr.key(), ClusterManager.ManagementHostIPAdr.category(), hostIpAdr); s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host."); } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 7052599dab6..d4463d91414 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -167,7 +167,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar private static final int STARTUP_DELAY = 60000; // 60 seconds - private String _mgmt_host; private int _mgmt_port = 8250; @Inject @@ -824,10 +823,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } Map agentMgrConfigs = _configDao.getConfiguration("AgentManager", params); - _mgmt_host = agentMgrConfigs.get("host"); - if (_mgmt_host == null) { - s_logger.warn("Critical warning! Please configure your management server host address right after you have started your management server and then restart it, otherwise you won't have access to secondary storage"); - } value = agentMgrConfigs.get("port"); _mgmt_port = NumbersUtil.parseInt(value, 8250); @@ -1020,7 +1015,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar StringBuilder buf = profile.getBootArgsBuilder(); buf.append(" template=domP type=secstorage"); - buf.append(" host=").append(_mgmt_host); + buf.append(" host=").append(ClusterManager.ManagementHostIPAdr.value()); buf.append(" port=").append(_mgmt_port); buf.append(" name=").append(profile.getVirtualMachine().getHostName()); diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index 3f6fb194f89..c5a3c214121 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -415,15 +415,6 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana return null; } - /* (non-Javadoc) - * @see com.cloud.resource.ResourceManager#listHostsByNameLike(java.lang.String) - */ - @Override - public List listHostsByNameLike(String name) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.resource.ResourceManager#getHostStatistics(long) */