// TODO: add test for method @Override public final HostVO createHostVOForDirectConnectAgent( final HostVO host, final StartupCommand[] startup, final ServerResource resource, final Map<String, String> details, final List<String> hostTags) { StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd); if (ssCmd.getHypervisorType() != HypervisorType.Hyperv) { return null; } s_logger.info( "Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); _resourceMgr.checkCIDR(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPrivateNetmask()); return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Hyperv, details, hostTags); }
@DB private void updateClusterNativeHAState(Host host, StartupCommand cmd) { ClusterVO cluster = _clusterDao.findById(host.getClusterId()); if (cluster.getClusterType() == ClusterType.ExternalManaged) { if (cmd instanceof StartupRoutingCommand) { StartupRoutingCommand hostStartupCmd = (StartupRoutingCommand) cmd; Map<String, String> details = hostStartupCmd.getHostDetails(); if (details.get("NativeHA") != null && details.get("NativeHA").equalsIgnoreCase("true")) { _clusterDetailsDao.persist(host.getClusterId(), "NativeHA", "true"); } else { _clusterDetailsDao.persist(host.getClusterId(), "NativeHA", "false"); } } } }
@Override public HostVO createHostVOForDirectConnectAgent( HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) { StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd); if (ssCmd.getHypervisorType() != HypervisorType.VMware) { return null; } return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.VMware, details, hostTags); }
@Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { StartupCommand firstCmd = cmd[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd); if (ssCmd.getHypervisorType() != HypervisorType.KVM) { return null; } /* KVM requires host are the same in cluster */ ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId()); if (!hostsInCluster.isEmpty()) { HostVO oneHost = hostsInCluster.get(0); _hostDao.loadDetails(oneHost); String hostOsInCluster = oneHost.getDetail("Host.OS"); String hostOs = ssCmd.getHostDetails().get("Host.OS"); if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { throw new IllegalArgumentException( "Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + "in which there are " + hostOsInCluster + " hosts added"); } } _hostDao.loadDetails(host); return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null); }
@Override public final void processConnect( final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException { // Limit the commands we can process if (!(cmd instanceof StartupRoutingCommand)) { return; } StartupRoutingCommand startup = (StartupRoutingCommand) cmd; // assert if (startup.getHypervisorType() != HypervisorType.Hyperv) { s_logger.debug("Not Hyper-V hypervisor, so moving on."); return; } long agentId = agent.getId(); HostVO host = _hostDao.findById(agentId); // Our Hyper-V machines are not participating in pools, and the pool id // we provide them is not persisted. // This means the pool id can vary. ClusterVO cluster = _clusterDao.findById(host.getClusterId()); if (cluster.getGuid() == null) { cluster.setGuid(startup.getPool()); _clusterDao.update(cluster.getId(), cluster); } if (s_logger.isDebugEnabled()) { s_logger.debug("Setting up host " + agentId); } HostEnvironment env = new HostEnvironment(); SetupCommand setup = new SetupCommand(env); if (!host.isSetup()) { setup.setNeedSetup(true); } try { SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup); if (answer != null && answer.getResult()) { host.setSetup(true); // TODO: clean up magic numbers below host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60); _hostDao.update(host.getId(), host); if (answer.needReconnect()) { throw new ConnectionException(false, "Reinitialize agent after setup."); } return; } else { String reason = answer.getDetails(); if (reason == null) { reason = " details were null"; } s_logger.warn("Unable to setup agent " + agentId + " due to " + reason); } // Error handling borrowed from XcpServerDiscoverer, may need to be // updated. } catch (AgentUnavailableException e) { s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); } catch (OperationTimedoutException e) { s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e); } throw new ConnectionException(true, "Reinitialize agent after setup."); }