diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 4e44d10fa04..5acf93097a1 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -146,11 +146,11 @@ import com.google.gson.GsonBuilder; public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProxyService, Manager, AgentHook, VirtualMachineGuru, SystemVmLoadScanHandler { private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class); - private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds - private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC = 180; // 3 minutes + private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds + private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC = 180; // 3 minutes - private static final int API_WAIT_TIMEOUT = 5000; // 5 seconds (in milliseconds) - private static final int STARTUP_DELAY = 60000; // 60 seconds + private static final int API_WAIT_TIMEOUT = 5000; // 5 seconds (in milliseconds) + private static final int STARTUP_DELAY = 60000; // 60 seconds private int _consoleProxyPort = ConsoleProxyManager.DEFAULT_PROXY_VNC_PORT; @@ -160,32 +160,48 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx private String _name; private Adapters _consoleProxyAllocators; - @Inject private ConsoleProxyDao _consoleProxyDao; - @Inject private DataCenterDao _dcDao; - @Inject private VMTemplateDao _templateDao; - @Inject private HostPodDao _podDao; - @Inject private HostDao _hostDao; - @Inject private ConfigurationDao _configDao; - @Inject private CertificateDao _certDao; - @Inject private VMInstanceDao _instanceDao; - @Inject private VMTemplateHostDao _vmTemplateHostDao; - @Inject private AgentManager _agentMgr; - @Inject private StorageManager _storageMgr; - @Inject NetworkManager _networkMgr; - @Inject AccountManager _accountMgr; - @Inject ServiceOfferingDao _offeringDao; - @Inject NetworkOfferingDao _networkOfferingDao; - + @Inject + private ConsoleProxyDao _consoleProxyDao; + @Inject + private DataCenterDao _dcDao; + @Inject + private VMTemplateDao _templateDao; + @Inject + private HostPodDao _podDao; + @Inject + private HostDao _hostDao; + @Inject + private ConfigurationDao _configDao; + @Inject + private CertificateDao _certDao; + @Inject + private VMInstanceDao _instanceDao; + @Inject + private VMTemplateHostDao _vmTemplateHostDao; + @Inject + private AgentManager _agentMgr; + @Inject + private StorageManager _storageMgr; + @Inject + NetworkManager _networkMgr; + @Inject + AccountManager _accountMgr; + @Inject + ServiceOfferingDao _offeringDao; + @Inject + NetworkOfferingDao _networkOfferingDao; + private ConsoleProxyListener _listener; private ServiceOfferingVO _serviceOffering; - + NetworkOfferingVO _publicNetworkOffering; NetworkOfferingVO _managementNetworkOffering; NetworkOfferingVO _linkLocalNetworkOffering; - @Inject private VirtualMachineManager _itMgr; - + @Inject + private VirtualMachineManager _itMgr; + private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new NamedThreadFactory("Request-handler")); private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL; @@ -198,16 +214,16 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx private boolean _use_storage_vm; private boolean _disable_rp_filter = false; private String _instance; - + private int _proxySessionTimeoutValue = DEFAULT_PROXY_SESSION_TIMEOUT; private boolean _sslEnabled = false; // global load picture at zone basis private SystemVmLoadScanner _loadScanner; - private Map _zoneHostInfoMap; // map - private Map _zoneProxyCountMap; // map - private Map _zoneVmCountMap; // map - + private Map _zoneHostInfoMap; // map + private Map _zoneProxyCountMap; // map + private Map _zoneVmCountMap; // map + private final GlobalLock _allocProxyLock = GlobalLock.getInternLock(getAllocProxyLockName()); @Override @@ -241,17 +257,17 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.info("Waiting for console proxy assignment is interrupted"); } } - + ConsoleProxyVO proxy = result.second(); if (proxy == null) { return null; } - - if(proxy.getPublicIpAddress() == null) { - s_logger.warn("Assigned console proxy does not have a valid public IP address"); - return null; + + if (proxy.getPublicIpAddress() == null) { + s_logger.warn("Assigned console proxy does not have a valid public IP address"); + return null; } - + return new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), _consoleProxyPort, proxy.getPort(), _configDao.getValue("consoleproxy.url.domain")); } @@ -271,8 +287,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _allocProxyLock.unlock(); } } else { - s_logger.error("Unable to acquire synchronization lock to get/allocate proxy resource for vm :" + vmId - + ". Previous console proxy allocation is taking too long"); + s_logger.error("Unable to acquire synchronization lock to get/allocate proxy resource for vm :" + vmId + ". Previous console proxy allocation is taking too long"); } if (proxy == null) { @@ -302,7 +317,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } else { proxy.setPort(80); } - + return proxy; } } @@ -431,7 +446,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return false; } } - + @Override public ConsoleProxyVO startProxy(long proxyVmId) { try { @@ -441,18 +456,19 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (proxy.getState() == VirtualMachine.State.Running) { return proxy; } - + String restart = _configDao.getValue(Config.ConsoleProxyRestart.key()); - if(restart != null && restart.equalsIgnoreCase("false")) { + if (restart != null && restart.equalsIgnoreCase("false")) { return null; } - - if(proxy.getState() == VirtualMachine.State.Stopped) { + + if (proxy.getState() == VirtualMachine.State.Stopped) { return _itMgr.start(proxy, null, systemUser, systemAcct); } - + // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null - // as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited to Stopped to allow + // as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited to + // Stopped to allow // Starting of it return null; } catch (StorageUnavailableException e) { @@ -464,7 +480,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } catch (ResourceUnavailableException e) { s_logger.warn("Exception while trying to start console proxy", e); return null; - } catch(CloudRuntimeException e) { + } catch (CloudRuntimeException e) { s_logger.warn("Runtime Exception while trying to start console proxy", e); return null; } @@ -508,8 +524,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } public ConsoleProxyVO assignProxyFromStoppedPool(long dataCenterId) { - - // practically treat all console proxy VM that is not in Running state but can be entering into Running state as candidates + + // practically treat all console proxy VM that is not in Running state but can be entering into Running state as + // candidates // this is to prevent launching unneccessary console proxy VMs because of temporarily unavailable state List l = _consoleProxyDao.getProxyListInStates(dataCenterId, State.Starting, State.Stopped, State.Migrating, State.Stopping); if (l != null && l.size() > 0) { @@ -524,13 +541,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isDebugEnabled()) { s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId); } - - if(!allowToLaunchNew(dataCenterId)) { + + if (!allowToLaunchNew(dataCenterId)) { s_logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit"); return null; } HypervisorType currentHyp = currentHypervisorType(dataCenterId); - + Map context = createProxyInstance(dataCenterId, currentHyp); long proxyVmId = (Long) context.get("proxyVmId"); @@ -541,7 +558,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return null; } - ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); + ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); if (proxy != null) { SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATED, dataCenterId, proxy.getId(), proxy, null)); @@ -551,11 +568,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.debug("Unable to allocate console proxy storage, remove the console proxy record from DB, proxy id: " + proxyVmId); } - SubscriptionMgr.getInstance().notifySubscribers( - ConsoleProxyManager.ALERT_SUBJECT, - this, - new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, proxyVmId, null, - "Unable to allocate storage")); + SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, + new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, proxyVmId, null, "Unable to allocate storage")); } return null; } @@ -566,14 +580,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx String name = VirtualMachineName.getConsoleProxyName(id, _instance); DataCenterVO dc = _dcDao.findById(dataCenterId); Account systemAcct = _accountMgr.getSystemAccount(); - + DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); List defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork); if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemGuestNetwork); } - + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork); List> networks = new ArrayList>(offerings.size() + 1); NicProfile defaultNic = new NicProfile(); @@ -583,21 +597,22 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx for (NetworkOfferingVO offering : offerings) { networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null)); } - + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId, desiredHyp); if (template == null) { s_logger.debug("Can't find a template to start"); throw new CloudRuntimeException("Insufficient capacity exception"); } - - ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0); + + ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), + systemAcct.getId(), 0); try { proxy = _itMgr.allocate(proxy, template, _serviceOffering, networks, plan, null, systemAcct); } catch (InsufficientCapacityException e) { s_logger.warn("InsufficientCapacity", e); throw new CloudRuntimeException("Insufficient capacity exception", e); } - + Map context = new HashMap(); context.put("dc", dc); HostPodVO pod = _podDao.findById(proxy.getPodId()); @@ -606,7 +621,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return context; } - + private ConsoleProxyAllocator getCurrentAllocator() { // for now, only one adapter is supported Enumeration it = _consoleProxyAllocators.enumeration(); @@ -692,37 +707,37 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticationCommand cmd) { long vmId = 0; - - String ticketInUrl = cmd.getTicket(); - if(ticketInUrl == null) { - s_logger.error("Access ticket could not be found, you could be running an old version of console proxy. vmId: " + cmd.getVmId()); - return new ConsoleAccessAuthenticationAnswer(cmd, false); - } - - if(s_logger.isDebugEnabled()) { + + String ticketInUrl = cmd.getTicket(); + if (ticketInUrl == null) { + s_logger.error("Access ticket could not be found, you could be running an old version of console proxy. vmId: " + cmd.getVmId()); + return new ConsoleAccessAuthenticationAnswer(cmd, false); + } + + if (s_logger.isDebugEnabled()) { s_logger.debug("Console authentication. Ticket in url for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticketInUrl); } String ticket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId()); - if(s_logger.isDebugEnabled()) { + if (s_logger.isDebugEnabled()) { s_logger.debug("Console authentication. Ticket in 1 minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticket); } - - if(!ticket.equals(ticketInUrl)) { - Date now = new Date(); - // considering of minute round-up - String minuteEarlyTicket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(), - new Date(now.getTime() - 60*1000)); - if(s_logger.isDebugEnabled()) { + if (!ticket.equals(ticketInUrl)) { + Date now = new Date(); + // considering of minute round-up + String minuteEarlyTicket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(), new Date(now.getTime() - 60 * 1000)); + + if (s_logger.isDebugEnabled()) { s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket); } - - if(!minuteEarlyTicket.equals(ticketInUrl)) { - s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId() + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + "," + minuteEarlyTicket); - return new ConsoleAccessAuthenticationAnswer(cmd, false); - } - } + + if (!minuteEarlyTicket.equals(ticketInUrl)) { + s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId() + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + "," + + minuteEarlyTicket); + return new ConsoleAccessAuthenticationAnswer(cmd, false); + } + } if (cmd.getVmId() != null && cmd.getVmId().isEmpty()) { if (s_logger.isDebugEnabled()) { @@ -769,32 +784,32 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public void onAgentConnect(HostVO host, StartupCommand cmd) { -// if (host.getType() == Type.ConsoleProxy) { -// // TODO we can use this event to mark the proxy is up and -// // functioning instead of -// // pinging the console proxy VM command port -// // -// // for now, just log a message -// if (s_logger.isInfoEnabled()) { -// s_logger.info("Console proxy agent is connected. proxy: " + host.getName()); -// } -// -// /* update public/private ip address */ -// if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) { -// try { -// ConsoleProxyVO console = findConsoleProxyByHost(host); -// if (console == null) { -// s_logger.debug("Can't find console proxy "); -// return; -// } -// console.setPrivateIpAddress(cmd.getPrivateIpAddress()); -// console.setPublicIpAddress(cmd.getPublicIpAddress()); -// console.setPublicNetmask(cmd.getPublicNetmask()); -// _consoleProxyDao.persist(console); -// } catch (NumberFormatException e) { -// } -// } -// } + // if (host.getType() == Type.ConsoleProxy) { + // // TODO we can use this event to mark the proxy is up and + // // functioning instead of + // // pinging the console proxy VM command port + // // + // // for now, just log a message + // if (s_logger.isInfoEnabled()) { + // s_logger.info("Console proxy agent is connected. proxy: " + host.getName()); + // } + // + // /* update public/private ip address */ + // if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) { + // try { + // ConsoleProxyVO console = findConsoleProxyByHost(host); + // if (console == null) { + // s_logger.debug("Can't find console proxy "); + // return; + // } + // console.setPrivateIpAddress(cmd.getPrivateIpAddress()); + // console.setPublicIpAddress(cmd.getPublicIpAddress()); + // console.setPublicNetmask(cmd.getPublicNetmask()); + // _consoleProxyDao.persist(console); + // } catch (NumberFormatException e) { + // } + // } + // } } @Override @@ -832,17 +847,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx // continue on forever /* - * _capacityScanScheduler.execute(new Runnable() { - * public void run() { if(s_logger.isInfoEnabled()) - * s_logger.info("Stop console proxy " + proxy.getName() - * + - * " VM because of that the agent running inside it has disconnected" - * ); stopProxy(proxy.getId()); } }); + * _capacityScanScheduler.execute(new Runnable() { public void run() { if(s_logger.isInfoEnabled()) + * s_logger.info("Stop console proxy " + proxy.getName() + + * " VM because of that the agent running inside it has disconnected" ); stopProxy(proxy.getId()); } }); */ } else { if (s_logger.isInfoEnabled()) { - s_logger.info("Console proxy agent disconnected but corresponding console proxy VM no longer exists in DB, proxy: " - + name); + s_logger.info("Console proxy agent disconnected but corresponding console proxy VM no longer exists in DB, proxy: " + name); } } } else { @@ -851,32 +862,30 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } } } - + private boolean reserveStandbyCapacity() { String value = _configDao.getValue(Config.SystemVMAutoReserveCapacity.key()); - if(value != null && value.equalsIgnoreCase("true")) { + if (value != null && value.equalsIgnoreCase("true")) { return true; } - + return false; } - + private boolean allowToLaunchNew(long dcId) { - List l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, - VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped, - VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown); - + List l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped, + VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown); + String value = _configDao.getValue(Config.ConsoleProxyLaunchMax.key()); int launchLimit = NumbersUtil.parseInt(value, 10); return l.size() < launchLimit; } - + private HypervisorType currentHypervisorType(long dcId) { - List l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, - VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped, - VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown); - - return l.size() > 0? l.get(0).getHypervisorType():HypervisorType.Any; + List l = _consoleProxyDao.getProxyListInStates(dcId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Stopped, + VirtualMachine.State.Migrating, VirtualMachine.State.Shutdowned, VirtualMachine.State.Unknown); + + return l.size() > 0 ? l.get(0).getHypervisorType() : HypervisorType.Any; } private boolean checkCapacity(ConsoleProxyLoadInfo proxyCountInfo, ConsoleProxyLoadInfo vmCountInfo) { @@ -901,10 +910,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isInfoEnabled()) { s_logger.info("No stopped console proxy is available, need to allocate a new console proxy"); } - + try { proxy = startNew(dataCenterId); - } catch (ConcurrentOperationException e) { + } catch (ConcurrentOperationException e) { s_logger.info("Concurrent Operation caught " + e); } } else { @@ -916,7 +925,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _allocProxyLock.unlock(); } } else { - if(s_logger.isInfoEnabled()) { + if (s_logger.isInfoEnabled()) { s_logger.info("Unable to acquire proxy allocation lock, skip for next time"); } } @@ -1007,7 +1016,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isInfoEnabled()) { s_logger.info("Stop console proxy manager"); } - + this._loadScanner.stop(); _allocProxyLock.releaseRef(); return true; @@ -1030,7 +1039,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return false; } - + try { return _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); } catch (ResourceUnavailableException e) { @@ -1056,11 +1065,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.debug("Successfully reboot console proxy " + proxy.getName()); } - SubscriptionMgr.getInstance().notifySubscribers( - ConsoleProxyManager.ALERT_SUBJECT, - this, - new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_REBOOTED, proxy.getDataCenterId(), proxy.getId(), - proxy, null)); + SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, + new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_REBOOTED, proxy.getDataCenterId(), proxy.getId(), proxy, null)); return true; } else { @@ -1089,7 +1095,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx private String getAllocProxyLockName() { return "consoleproxy.alloc"; } - + @Override public boolean configure(String name, Map params) throws ConfigurationException { if (s_logger.isInfoEnabled()) { @@ -1108,7 +1114,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _proxyRamSize = NumbersUtil.parseInt(configs.get(Config.ConsoleProxyRamSize.key()), DEFAULT_PROXY_VM_RAMSIZE); _proxyCpuMHz = NumbersUtil.parseInt(configs.get(Config.ConsoleProxyCpuMHz.key()), DEFAULT_PROXY_VM_CPUMHZ); - + String value = configs.get(Config.ConsoleProxyCmdPort.key()); value = configs.get("consoleproxy.sslEnabled"); if (value != null && value.equalsIgnoreCase("true")) { @@ -1126,9 +1132,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (value != null) { _consoleProxyPort = NumbersUtil.parseInt(value, ConsoleProxyManager.DEFAULT_PROXY_VNC_PORT); } - + value = configs.get(Config.ConsoleProxyDisableRpFilter.key()); - if(value != null && value.equalsIgnoreCase("true")) { + if (value != null && value.equalsIgnoreCase("true")) { _disable_rp_filter = true; } @@ -1141,7 +1147,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (value != null && value.equalsIgnoreCase("true")) { _use_storage_vm = true; } - + if (s_logger.isInfoEnabled()) { s_logger.info("Console proxy max session soft limit : " + _capacityPerProxy); s_logger.info("Console proxy standby capacity : " + _standbyCapacity); @@ -1178,7 +1184,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _loadScanner = new SystemVmLoadScanner(this); _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval); - + if (s_logger.isInfoEnabled()) { s_logger.info("Console Proxy Manager is configured."); } @@ -1186,15 +1192,15 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd) throws ServerApiException{ + public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd) throws ServerApiException { Long proxyId = cmd.getId(); - + // verify parameters ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyId); if (proxy == null) { throw new InvalidParameterValueException("unable to find a console proxy with id " + proxyId); } - + return destroyProxy(proxyId); } @@ -1203,7 +1209,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - StringBuilder buf = profile.getBootArgsBuilder(); + StringBuilder buf = profile.getBootArgsBuilder(); buf.append(" template=domP type=consoleproxy"); buf.append(" host=").append(_mgmt_host); buf.append(" port=").append(_mgmt_port); @@ -1215,26 +1221,26 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx buf.append(" pod=").append(dest.getPod().getId()); buf.append(" guid=Proxy.").append(profile.getId()); buf.append(" proxy_vm=").append(profile.getId()); - if(_disable_rp_filter) { + if (_disable_rp_filter) { buf.append(" disable_rp_filter=true"); } boolean externalDhcp = false; String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled"); - if(externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) { + if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) { externalDhcp = true; } - + for (NicProfile nic : profile.getNics()) { int deviceId = nic.getDeviceId(); - if(nic.getIp4Address() == null) { - buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0"); - buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0"); + if (nic.getIp4Address() == null) { + buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0"); + buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0"); } else { - buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address()); - buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); + buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address()); + buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask()); } - + if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getGateway()); buf.append(" dns1=").append(nic.getDns1()); @@ -1242,91 +1248,95 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx buf.append(" dns2=").append(nic.getDns2()); } } - + if (nic.getTrafficType() == TrafficType.Management) { - String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key()); - if (NetUtils.isValidCIDR(mgmt_cidr)) { - buf.append(" mgmtcidr=").append(mgmt_cidr); - } + String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key()); + if (NetUtils.isValidCIDR(mgmt_cidr)) { + buf.append(" mgmtcidr=").append(mgmt_cidr); + } buf.append(" localgw=").append(dest.getPod().getGateway()); - } + } } - /*External DHCP mode*/ - if(externalDhcp) { + /* External DHCP mode */ + if (externalDhcp) { buf.append(" bootproto=dhcp"); } - + String bootArgs = buf.toString(); if (s_logger.isDebugEnabled()) { s_logger.debug("Boot Args for " + profile + ": " + bootArgs); } - + return true; } @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - + finalizeCommandsOnStart(cmds, profile); - + ConsoleProxyVO proxy = profile.getVirtualMachine(); DataCenter dc = dest.getDataCenter(); List nics = profile.getNics(); for (NicProfile nic : nics) { - if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { - proxy.setPublicIpAddress(nic.getIp4Address()); - proxy.setPublicNetmask(nic.getNetmask()); - proxy.setPublicMacAddress(nic.getMacAddress()); - } else if (nic.getTrafficType() == TrafficType.Management) { - proxy.setPrivateIpAddress(nic.getIp4Address()); - proxy.setPrivateMacAddress(nic.getMacAddress()); - } + if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) + || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { + proxy.setPublicIpAddress(nic.getIp4Address()); + proxy.setPublicNetmask(nic.getNetmask()); + proxy.setPublicMacAddress(nic.getMacAddress()); + } else if (nic.getTrafficType() == TrafficType.Management) { + proxy.setPrivateIpAddress(nic.getIp4Address()); + proxy.setPrivateMacAddress(nic.getMacAddress()); + } } _consoleProxyDao.update(proxy.getId(), proxy); return true; } - + @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - + NicProfile managementNic = null; NicProfile controlNic = null; for (NicProfile nic : profile.getNics()) { - if (nic.getTrafficType() == TrafficType.Management) { - managementNic = nic; - } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { - controlNic = nic; - } + if (nic.getTrafficType() == TrafficType.Management) { + managementNic = nic; + } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { + controlNic = nic; + } } if (controlNic == null) { - assert (managementNic != null); - controlNic = managementNic; + if (managementNic == null) { + s_logger.error("Management network doesn't exist for the console proxy vm " + profile.getVirtualMachine()); + return false; + } + controlNic = managementNic; } CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); cmds.addCommand("checkSsh", check); - + return true; } - + @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { - CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh"); + CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh"); if (answer == null || !answer.getResult()) { - if(answer != null) { + if (answer != null) { s_logger.warn("Unable to ssh to the VM: " + answer.getDetails()); } else { s_logger.warn("Unable to ssh to the VM: null answer"); } return false; } - + return true; } - - @Override + + @Override public void finalizeExpunge(ConsoleProxyVO proxy) { proxy.setPublicIpAddress(null); proxy.setPublicMacAddress(null); @@ -1335,56 +1345,55 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx proxy.setPrivateIpAddress(null); _consoleProxyDao.update(proxy.getId(), proxy); } - + @Override - public boolean applyCustomCertToNewProxy(StartupProxyCommand cmd){ - //this is the case for updating cust cert on each new starting proxy, if such cert exists - //get cert from db - CertificateVO cert = _certDao.listAll().get(0); - - if(cert.getUpdated().equalsIgnoreCase("Y")){ - String certStr = cert.getCertificate(); - long proxyVmId = (cmd).getProxyVmId(); - ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(proxyVmId); - //find corresponding host - if(consoleProxy!=null){ - HostVO consoleProxyHost = _hostDao.findConsoleProxyHost(consoleProxy.getName(), Type.ConsoleProxy); - //now send a command to console proxy host - UpdateCertificateCommand certCmd = new UpdateCertificateCommand(certStr, true); - try { - Answer updateCertAns = _agentMgr.send(consoleProxyHost.getId(), certCmd); - if(updateCertAns.getResult() == true) - { - //we have the cert copied over on cpvm - rebootProxy(consoleProxy.getId()); - //when cp reboots, the context will be reinit with the new cert - s_logger.info("Successfully rebooted console proxy resource after custom certificate application for proxy:"+cmd.getProxyVmId()); - return true; - } - } catch (AgentUnavailableException e) { - s_logger.warn("Unable to send update certificate command to the console proxy resource for proxy:"+cmd.getProxyVmId(), e); - return false; - } catch (OperationTimedoutException e) { - s_logger.warn("Unable to send update certificate command to the console proxy resource for proxy:"+cmd.getProxyVmId(), e); - return false; - } - } - } else { - return false;//no cert entry in the db record - } - return false;//cert already applied in previous cycles + public boolean applyCustomCertToNewProxy(StartupProxyCommand cmd) { + // this is the case for updating cust cert on each new starting proxy, if such cert exists + // get cert from db + CertificateVO cert = _certDao.listAll().get(0); + + if (cert.getUpdated().equalsIgnoreCase("Y")) { + String certStr = cert.getCertificate(); + long proxyVmId = (cmd).getProxyVmId(); + ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(proxyVmId); + // find corresponding host + if (consoleProxy != null) { + HostVO consoleProxyHost = _hostDao.findConsoleProxyHost(consoleProxy.getName(), Type.ConsoleProxy); + // now send a command to console proxy host + UpdateCertificateCommand certCmd = new UpdateCertificateCommand(certStr, true); + try { + Answer updateCertAns = _agentMgr.send(consoleProxyHost.getId(), certCmd); + if (updateCertAns.getResult() == true) { + // we have the cert copied over on cpvm + rebootProxy(consoleProxy.getId()); + // when cp reboots, the context will be reinit with the new cert + s_logger.info("Successfully rebooted console proxy resource after custom certificate application for proxy:" + cmd.getProxyVmId()); + return true; + } + } catch (AgentUnavailableException e) { + s_logger.warn("Unable to send update certificate command to the console proxy resource for proxy:" + cmd.getProxyVmId(), e); + return false; + } catch (OperationTimedoutException e) { + s_logger.warn("Unable to send update certificate command to the console proxy resource for proxy:" + cmd.getProxyVmId(), e); + return false; + } + } + } else { + return false;// no cert entry in the db record + } + return false;// cert already applied in previous cycles } - + @Override public ConsoleProxyVO persist(ConsoleProxyVO proxy) { return _consoleProxyDao.persist(proxy); } - + @Override public ConsoleProxyVO findById(long id) { return _consoleProxyDao.findById(id); } - + @Override public ConsoleProxyVO findByName(String name) { if (!VirtualMachineName.isValidConsoleProxyName(name)) { @@ -1392,38 +1401,38 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return findById(VirtualMachineName.getConsoleProxyId(name)); } - + @Override public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { } @Override - public String getScanHandlerName() { - return "consoleproxy"; - } - + public String getScanHandlerName() { + return "consoleproxy"; + } + @Override - public void onScanStart() { + public void onScanStart() { // to reduce possible number of DB queries for capacity scan, we run following aggregated queries in preparation stage _zoneHostInfoMap = getZoneHostInfo(); - + _zoneProxyCountMap = new HashMap(); List listProxyCounts = _consoleProxyDao.getDatacenterProxyLoadMatrix(); for (ConsoleProxyLoadInfo info : listProxyCounts) { - _zoneProxyCountMap.put(info.getId(), info); + _zoneProxyCountMap.put(info.getId(), info); } _zoneVmCountMap = new HashMap(); List listVmCounts = _consoleProxyDao.getDatacenterSessionLoadMatrix(); for (ConsoleProxyLoadInfo info : listVmCounts) { - _zoneVmCountMap.put(info.getId(), info); + _zoneVmCountMap.put(info.getId(), info); } } - + @Override - public boolean canScan() { - if(!reserveStandbyCapacity()) { - if(s_logger.isDebugEnabled()) { + public boolean canScan() { + if (!reserveStandbyCapacity()) { + if (s_logger.isDebugEnabled()) { s_logger.debug("Reserving standby capacity is disable, skip capacity scan"); } return false; @@ -1435,71 +1444,72 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode"); return false; } - + return true; - } + } @Override - public Long[] getScannablePools() { - List zones = _dcDao.listEnabledZones(); + public Long[] getScannablePools() { + List zones = _dcDao.listEnabledZones(); - Long[] dcIdList = new Long[zones.size()]; - int i = 0; - for(DataCenterVO dc : zones) { - dcIdList[i++] = dc.getId(); - } - - return dcIdList; - } - - public boolean isPoolReadyForScan(Long pool) { - // pool is at zone basis - long dataCenterId = pool.longValue(); - - if(!isZoneReady(_zoneHostInfoMap, dataCenterId)) { - if(s_logger.isDebugEnabled()) - s_logger.debug("Zone " + dataCenterId + " is not ready to launch console proxy yet"); - return false; - } - - if(s_logger.isDebugEnabled()) - s_logger.debug("Zone " + dataCenterId + " is ready to launch console proxy"); - return true; - } - - @Override - public Pair scanPool(Long pool) { - long dataCenterId = pool.longValue(); - - ConsoleProxyLoadInfo proxyInfo = this._zoneProxyCountMap.get(dataCenterId); - if(proxyInfo == null) - return new Pair(AfterScanAction.nop, null); - - ConsoleProxyLoadInfo vmInfo = this._zoneVmCountMap.get(dataCenterId); - if(vmInfo == null) - vmInfo = new ConsoleProxyLoadInfo(); - - if (!checkCapacity(proxyInfo, vmInfo)) { - if(s_logger.isDebugEnabled()) - s_logger.debug("Expand console proxy standby capacity for zone " + proxyInfo.getName()); - - return new Pair(AfterScanAction.expand, null); + Long[] dcIdList = new Long[zones.size()]; + int i = 0; + for (DataCenterVO dc : zones) { + dcIdList[i++] = dc.getId(); } - - return new Pair(AfterScanAction.nop, null); - } - - @Override - public void expandPool(Long pool, Object actionArgs) { - long dataCenterId = pool.longValue(); - allocCapacity(dataCenterId); - } - - @Override - public void shrinkPool(Long pool, Object actionArgs) { - } - @Override - public void onScanEnd() { - } + return dcIdList; + } + + @Override + public boolean isPoolReadyForScan(Long pool) { + // pool is at zone basis + long dataCenterId = pool.longValue(); + + if (!isZoneReady(_zoneHostInfoMap, dataCenterId)) { + if (s_logger.isDebugEnabled()) + s_logger.debug("Zone " + dataCenterId + " is not ready to launch console proxy yet"); + return false; + } + + if (s_logger.isDebugEnabled()) + s_logger.debug("Zone " + dataCenterId + " is ready to launch console proxy"); + return true; + } + + @Override + public Pair scanPool(Long pool) { + long dataCenterId = pool.longValue(); + + ConsoleProxyLoadInfo proxyInfo = this._zoneProxyCountMap.get(dataCenterId); + if (proxyInfo == null) + return new Pair(AfterScanAction.nop, null); + + ConsoleProxyLoadInfo vmInfo = this._zoneVmCountMap.get(dataCenterId); + if (vmInfo == null) + vmInfo = new ConsoleProxyLoadInfo(); + + if (!checkCapacity(proxyInfo, vmInfo)) { + if (s_logger.isDebugEnabled()) + s_logger.debug("Expand console proxy standby capacity for zone " + proxyInfo.getName()); + + return new Pair(AfterScanAction.expand, null); + } + + return new Pair(AfterScanAction.nop, null); + } + + @Override + public void expandPool(Long pool, Object actionArgs) { + long dataCenterId = pool.longValue(); + allocCapacity(dataCenterId); + } + + @Override + public void shrinkPool(Long pool, Object actionArgs) { + } + + @Override + public void onScanEnd() { + } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 3b1e7607254..ed73a2db368 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -185,8 +185,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V private String _allowedInternalSites; private SystemVmLoadScanner _loadScanner; - private Map _zoneHostInfoMap; // map - + private Map _zoneHostInfoMap; // map + private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName()); @Override @@ -255,7 +255,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V String privateCidr = NetUtils.ipAndNetMaskToCidr(privateNic.getIp4Address(), privateNic.getNetmask()); String publicCidr = NetUtils.ipAndNetMaskToCidr(secStorageVm.getPublicIpAddress(), secStorageVm.getPublicNetmask()); if (NetUtils.isNetworkAWithinNetworkB(privateCidr, publicCidr) || NetUtils.isNetworkAWithinNetworkB(publicCidr, privateCidr)) { - s_logger.info("private and public interface overlaps, add a default route through private interface. privateCidr: " + privateCidr + ", publicCidr: " + publicCidr); + s_logger.info("private and public interface overlaps, add a default route through private interface. privateCidr: " + privateCidr + ", publicCidr: " + publicCidr); allowedCidrs.add("0.0.0.0/0"); } setupCmd.setAllowedInternalSites(allowedCidrs.toArray(new String[allowedCidrs.size()])); @@ -278,9 +278,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public Pair assignSecStorageVm(long zoneId, Command cmd) { - return null; - } + public Pair assignSecStorageVm(long zoneId, Command cmd) { + return null; + } private boolean generateFirewallConfigurationForZone(Long zoneId) { List zoneSsvms = _secStorageVmDao.listByZoneId(SecondaryStorageVm.Role.templateProcessor, zoneId); @@ -354,15 +354,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V return secStorageVm; } else { if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: " - + secStorageVmId); + s_logger.debug("Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: " + secStorageVmId); } - SubscriptionMgr.getInstance().notifySubscribers( - ALERT_SUBJECT, - this, - new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, - "Unable to allocate storage")); + SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, + new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage")); } return null; } @@ -383,37 +379,34 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V DataCenter dc = _dcDao.findById(plan.getDataCenterId()); List defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork); - + if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemGuestNetwork); } - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, - NetworkOfferingVO.SystemManagementNetwork); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork); List> networks = new ArrayList>(offerings.size() + 1); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); try { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false) - .get(0), defaultNic)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false).get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { - networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), - null)); + networks.add(new Pair(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null)); } } catch (ConcurrentOperationException e) { s_logger.info("Unable to setup due to concurrent operation. " + e); return new HashMap(); } - + VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); if (template == null) { s_logger.debug("Can't find a template to start"); throw new CloudRuntimeException("Insufficient capacity exception"); } - - SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), - template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), role); + + SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, + systemAcct.getDomainId(), systemAcct.getId(), role); try { secStorageVm = _itMgr.allocate(secStorageVm, template, _serviceOffering, networks, plan, null, systemAcct); } catch (InsufficientCapacityException e) { @@ -521,8 +514,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } } else { if (s_logger.isInfoEnabled()) { - s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " - + secStorageVm.getId()); + s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId()); } return; } @@ -532,8 +524,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V if (secStorageVm == null) { if (s_logger.isInfoEnabled()) { - s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId - + ", will recycle it and start a new one"); + s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId + ", will recycle it and start a new one"); } if (secStorageVmFromStoppedPool) { @@ -554,8 +545,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId); if (secHost == null) { if (s_logger.isDebugEnabled()) { - s_logger.debug("No secondary storage available in zone " + dataCenterId - + ", wait until it is ready to launch secondary storage vm"); + s_logger.debug("No secondary storage available in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm"); } return false; } @@ -616,7 +606,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V @Override public boolean stop() { - _loadScanner.stop(); + _loadScanner.stop(); _allocLock.releaseRef(); return true; } @@ -761,11 +751,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getName()); } - SubscriptionMgr.getInstance().notifySubscribers( - ALERT_SUBJECT, - this, - new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), - secStorageVm.getId(), secStorageVm, null)); + SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, + new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null)); return true; } else { @@ -825,8 +812,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, - ReservationContext context) { + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { HostVO secHost = _hostDao.findSecondaryStorageHost(dest.getDataCenter().getId()); assert (secHost != null); @@ -840,11 +826,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" zone=").append(dest.getDataCenter().getId()); buf.append(" pod=").append(dest.getPod().getId()); - if(profile.getVirtualMachine().getRole() == SecondaryStorageVm.Role.templateProcessor) - buf.append(" guid=").append(secHost.getGuid()); + if (profile.getVirtualMachine().getRole() == SecondaryStorageVm.Role.templateProcessor) + buf.append(" guid=").append(secHost.getGuid()); else - buf.append(" guid=").append(profile.getVirtualMachine().getName()); - + buf.append(" guid=").append(profile.getVirtualMachine().getName()); + String nfsMountPoint = null; try { nfsMountPoint = NfsUtils.url2Mount(secHost.getStorageUrl()); @@ -852,13 +838,13 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } buf.append(" mount.path=").append(nfsMountPoint); - if(_configDao.isPremium()) { + if (_configDao.isPremium()) { if (profile.getHypervisorType() == HypervisorType.Hyperv) { - buf.append(" resource=com.cloud.storage.resource.CifsSecondaryStorageResource"); + buf.append(" resource=com.cloud.storage.resource.CifsSecondaryStorageResource"); } else - buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource"); - } else - buf.append(" resource=com.cloud.storage.resource.NfsSecondaryStorageResource"); + buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource"); + } else + buf.append(" resource=com.cloud.storage.resource.NfsSecondaryStorageResource"); buf.append(" instance=SecStorage"); buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy)); buf.append(" role=").append(profile.getVirtualMachine().getRole().toString()); @@ -884,11 +870,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" gateway=").append(nic.getGateway()); } if (nic.getTrafficType() == TrafficType.Management) { - String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key()); - if (NetUtils.isValidCIDR(mgmt_cidr)) { - buf.append(" mgmtcidr=").append(mgmt_cidr); - } - + String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key()); + if (NetUtils.isValidCIDR(mgmt_cidr)) { + buf.append(" mgmtcidr=").append(mgmt_cidr); + } + buf.append(" localgw=").append(dest.getPod().getGateway()); buf.append(" private.network.device=").append("eth").append(deviceId); } else if (nic.getTrafficType() == TrafficType.Public) { @@ -916,9 +902,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, - ReservationContext context) { - + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + finalizeCommandsOnStart(cmds, profile); SecondaryStorageVmVO secVm = profile.getVirtualMachine(); @@ -926,7 +911,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V List nics = profile.getNics(); for (NicProfile nic : nics) { if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) - || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { + || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { secVm.setPublicIpAddress(nic.getIp4Address()); secVm.setPublicNetmask(nic.getNetmask()); secVm.setPublicMacAddress(nic.getMacAddress()); @@ -938,28 +923,31 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _secStorageVmDao.update(secVm.getId(), secVm); return true; } - + @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - + NicProfile managementNic = null; NicProfile controlNic = null; for (NicProfile nic : profile.getNics()) { - if (nic.getTrafficType() == TrafficType.Management) { - managementNic = nic; - } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { - controlNic = nic; - } + if (nic.getTrafficType() == TrafficType.Management) { + managementNic = nic; + } else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) { + controlNic = nic; + } } if (controlNic == null) { - assert (managementNic != null); - controlNic = managementNic; + if (managementNic == null) { + s_logger.error("Management network doesn't exist for the secondaryStorageVm " + profile.getVirtualMachine()); + return false; + } + controlNic = managementNic; } CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20); cmds.addCommand("checkSsh", check); - + return true; } @@ -977,88 +965,86 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V @Override public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { } - + @Override public void finalizeExpunge(SecondaryStorageVmVO vm) { } - - @Override - public String getScanHandlerName() { - return "secstorage"; - } - - @Override - public boolean canScan() { - return true; - } @Override - public void onScanStart() { + public String getScanHandlerName() { + return "secstorage"; + } + + @Override + public boolean canScan() { + return true; + } + + @Override + public void onScanStart() { _zoneHostInfoMap = getZoneHostInfo(); - } - - @Override - public Long[] getScannablePools() { - List zones = _dcDao.listEnabledZones(); + } - Long[] dcIdList = new Long[zones.size()]; - int i = 0; - for(DataCenterVO dc : zones) { - dcIdList[i++] = dc.getId(); - } - - return dcIdList; - } - @Override - public boolean isPoolReadyForScan(Long pool) { - // pool is at zone basis - long dataCenterId = pool.longValue(); - - if(!isZoneReady(_zoneHostInfoMap, dataCenterId)) { - if(s_logger.isDebugEnabled()) - s_logger.debug("Zone " + dataCenterId + " is not ready to launch secondary storage VM yet"); - return false; - } + public Long[] getScannablePools() { + List zones = _dcDao.listEnabledZones(); + + Long[] dcIdList = new Long[zones.size()]; + int i = 0; + for (DataCenterVO dc : zones) { + dcIdList[i++] = dc.getId(); + } + + return dcIdList; + } - if(s_logger.isDebugEnabled()) - s_logger.debug("Zone " + dataCenterId + " is ready to launch secondary storage VM"); - return true; - } - @Override - public Pair scanPool(Long pool) { - long dataCenterId = pool.longValue(); - - List alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, - State.Migrating, State.Starting); - List stopped = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, - State.Stopping); + public boolean isPoolReadyForScan(Long pool) { + // pool is at zone basis + long dataCenterId = pool.longValue(); + + if (!isZoneReady(_zoneHostInfoMap, dataCenterId)) { + if (s_logger.isDebugEnabled()) + s_logger.debug("Zone " + dataCenterId + " is not ready to launch secondary storage VM yet"); + return false; + } + + if (s_logger.isDebugEnabled()) + s_logger.debug("Zone " + dataCenterId + " is ready to launch secondary storage VM"); + return true; + } + + @Override + public Pair scanPool(Long pool) { + long dataCenterId = pool.longValue(); + + List alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, + State.Starting); + List stopped = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping); if (alreadyRunning.size() == 0) { if (stopped.size() == 0) { s_logger.info("No secondary storage vms found in datacenter id=" + dataCenterId + ", starting a new one"); - return new Pair(AfterScanAction.expand, SecondaryStorageVm.Role.templateProcessor); + return new Pair(AfterScanAction.expand, SecondaryStorageVm.Role.templateProcessor); } else { - s_logger.warn("Stopped secondary storage vms found in datacenter id=" + dataCenterId - + ", not restarting them automatically"); + s_logger.warn("Stopped secondary storage vms found in datacenter id=" + dataCenterId + ", not restarting them automatically"); } } - + return new Pair(AfterScanAction.nop, SecondaryStorageVm.Role.templateProcessor); - } - + } + @Override - public void expandPool(Long pool, Object actionArgs) { - long dataCenterId = pool.longValue(); - allocCapacity(dataCenterId, (SecondaryStorageVm.Role)actionArgs); - } - + public void expandPool(Long pool, Object actionArgs) { + long dataCenterId = pool.longValue(); + allocCapacity(dataCenterId, (SecondaryStorageVm.Role) actionArgs); + } + @Override - public void shrinkPool(Long pool, Object actionArgs) { - } - + public void shrinkPool(Long pool, Object actionArgs) { + } + @Override - public void onScanEnd() { - } - + public void onScanEnd() { + } + } diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 3a0b07aacb4..d120d87555d 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -96,6 +96,7 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; import com.cloud.hypervisor.HypervisorGuruManager; +import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.org.Cluster; @@ -1480,6 +1481,12 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene vm = vmGuru.findById(vm.getId()); VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + List nics = _nicsDao.listByVmId(profile.getId()); + for (NicVO nic : nics) { + Network network = _networkMgr.getNetwork(nic.getNetworkId()); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null); + profile.addNic(nicProfile); + } Commands cmds = new Commands(OnError.Revert); s_logger.debug("Finalizing commands that need to be send to complete Start process for the vm " + vm);