Skip to content

Commit 19edfdf

Browse files
author
Alex Huang
committed
migration code
1 parent 5810e80 commit 19edfdf

11 files changed

Lines changed: 748 additions & 643 deletions

api/src/com/cloud/deploy/DeployDestination.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ public boolean equals(Object obj) {
8181
}
8282
return this._host.getId() == that._host.getId();
8383
}
84+
85+
@Override
86+
public String toString() {
87+
return new StringBuilder("Dest[").append(_dc.getId()).append("-").append(_pod.getId()).append("-").append(_cluster.getId()).append("-").append(_host.getId()).append("]").toString();
88+
}
8489
}

server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.cloud.exception.AgentUnavailableException;
4444
import com.cloud.exception.ConcurrentOperationException;
4545
import com.cloud.exception.InsufficientCapacityException;
46-
import com.cloud.exception.OperationTimedoutException;
4746
import com.cloud.exception.StorageUnavailableException;
4847
import com.cloud.ha.HighAvailabilityManager;
4948
import com.cloud.host.HostVO;
@@ -283,11 +282,6 @@ public Command cleanup(ConsoleProxyVO vm, String vmName) {
283282
return new StopCommand(vm, vmName, null);
284283
}
285284

286-
@Override
287-
public boolean completeMigration(ConsoleProxyVO vm, HostVO host) throws AgentUnavailableException, OperationTimedoutException {
288-
return false;
289-
}
290-
291285
@Override
292286
public void completeStartCommand(ConsoleProxyVO vm) {
293287
}
@@ -304,21 +298,6 @@ public Long convertToId(String vmName) {
304298
return VirtualMachineName.getConsoleProxyId(vmName);
305299
}
306300

307-
@Override
308-
public ConsoleProxyVO get(long id) {
309-
return null;
310-
}
311-
312-
@Override
313-
public boolean migrate(ConsoleProxyVO vm, HostVO host) throws AgentUnavailableException, OperationTimedoutException {
314-
return false;
315-
}
316-
317-
@Override
318-
public HostVO prepareForMigration(ConsoleProxyVO vm) throws InsufficientCapacityException, StorageUnavailableException {
319-
return null;
320-
}
321-
322301
@Override
323302
public ConsoleProxyVO start(long vmId) throws InsufficientCapacityException, StorageUnavailableException,
324303
ConcurrentOperationException {

server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

Lines changed: 94 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Date;
2727
import java.util.Enumeration;
2828
import java.util.HashMap;
29-
import java.util.HashSet;
3029
import java.util.List;
3130
import java.util.Map;
3231
import java.util.concurrent.ExecutorService;
@@ -42,14 +41,10 @@
4241
import com.cloud.agent.AgentManager;
4342
import com.cloud.agent.api.AgentControlAnswer;
4443
import com.cloud.agent.api.Answer;
45-
import com.cloud.agent.api.CheckVirtualMachineAnswer;
46-
import com.cloud.agent.api.CheckVirtualMachineCommand;
4744
import com.cloud.agent.api.Command;
4845
import com.cloud.agent.api.ConsoleAccessAuthenticationAnswer;
4946
import com.cloud.agent.api.ConsoleAccessAuthenticationCommand;
5047
import com.cloud.agent.api.ConsoleProxyLoadReportCommand;
51-
import com.cloud.agent.api.MigrateCommand;
52-
import com.cloud.agent.api.PrepareForMigrationCommand;
5348
import com.cloud.agent.api.RebootCommand;
5449
import com.cloud.agent.api.StartupCommand;
5550
import com.cloud.agent.api.StartupProxyCommand;
@@ -91,7 +86,6 @@
9186
import com.cloud.exception.ResourceUnavailableException;
9287
import com.cloud.exception.StorageUnavailableException;
9388
import com.cloud.ha.HighAvailabilityManager;
94-
import com.cloud.host.Host;
9589
import com.cloud.host.Host.Type;
9690
import com.cloud.host.HostVO;
9791
import com.cloud.host.dao.HostDao;
@@ -115,7 +109,6 @@
115109
import com.cloud.service.dao.ServiceOfferingDao;
116110
import com.cloud.servlet.ConsoleProxyServlet;
117111
import com.cloud.storage.StorageManager;
118-
import com.cloud.storage.StoragePoolVO;
119112
import com.cloud.storage.VMTemplateHostVO;
120113
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
121114
import com.cloud.storage.VMTemplateVO;
@@ -1464,11 +1457,6 @@ protected void completeStopCommand(ConsoleProxyVO proxy, VirtualMachine.Event ev
14641457
}
14651458
}
14661459

1467-
@Override
1468-
public ConsoleProxyVO get(long id) {
1469-
return _consoleProxyDao.findById(id);
1470-
}
1471-
14721460
@Override
14731461
public Long convertToId(String vmName) {
14741462
if (!VirtualMachineName.isValidConsoleProxyName(vmName, _instance)) {
@@ -1649,100 +1637,100 @@ public boolean stop(ConsoleProxyVO proxy) throws AgentUnavailableException {
16491637
}
16501638
}
16511639

1652-
@Override
1653-
public boolean migrate(ConsoleProxyVO proxy, HostVO host) {
1654-
HostVO fromHost = _hostDao.findById(proxy.getId());
1655-
1656-
if (! _itMgr.stateTransitTo(proxy, VirtualMachine.Event.MigrationRequested, proxy.getHostId())) {
1657-
s_logger.debug("State for " + proxy.toString() + " has changed so migration can not take place.");
1658-
return false;
1659-
}
1660-
1661-
MigrateCommand cmd = new MigrateCommand(proxy.getInstanceName(), host.getPrivateIpAddress(), false);
1662-
Answer answer = _agentMgr.easySend(fromHost.getId(), cmd);
1663-
if (answer == null || !answer.getResult()) {
1664-
return false;
1665-
}
1666-
1667-
_storageMgr.unshare(proxy, fromHost);
1668-
1669-
return true;
1670-
}
1671-
1672-
@Override
1673-
public boolean completeMigration(ConsoleProxyVO proxy, HostVO host) throws AgentUnavailableException, OperationTimedoutException {
1674-
1675-
CheckVirtualMachineCommand cvm = new CheckVirtualMachineCommand(proxy.getInstanceName());
1676-
CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(host.getId(), cvm);
1677-
if (!answer.getResult()) {
1678-
s_logger.debug("Unable to complete migration for " + proxy.getId());
1679-
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.AgentReportStopped, null);
1680-
return false;
1681-
}
1682-
1683-
State state = answer.getState();
1684-
if (state == State.Stopped) {
1685-
s_logger.warn("Unable to complete migration as we can not detect it on " + host.getId());
1686-
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.AgentReportStopped, null);
1687-
return false;
1688-
}
1689-
1690-
_itMgr.stateTransitTo(proxy, VirtualMachine.Event.OperationSucceeded, host.getId());
1691-
return true;
1692-
}
1693-
1694-
@Override
1695-
public HostVO prepareForMigration(ConsoleProxyVO proxy) throws StorageUnavailableException {
1696-
1697-
VMTemplateVO template = _templateDao.findById(proxy.getTemplateId());
1698-
long routerId = proxy.getId();
1699-
boolean mirroredVols = proxy.isMirroredVols();
1700-
DataCenterVO dc = _dcDao.findById(proxy.getDataCenterId());
1701-
HostPodVO pod = _podDao.findById(proxy.getPodId());
1702-
StoragePoolVO sp = _storageMgr.getStoragePoolForVm(proxy.getId());
1703-
1704-
List<VolumeVO> vols = _volsDao.findCreatedByInstance(routerId);
1705-
1706-
String[] storageIps = new String[2];
1707-
VolumeVO vol = vols.get(0);
1708-
storageIps[0] = vol.getHostIp();
1709-
if (mirroredVols && (vols.size() == 2)) {
1710-
storageIps[1] = vols.get(1).getHostIp();
1711-
}
1712-
1713-
PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(proxy.getName(), null, storageIps, vols, mirroredVols);
1714-
1715-
HostVO routingHost = null;
1716-
HashSet<Host> avoid = new HashSet<Host>();
1717-
1718-
HostVO fromHost = _hostDao.findById(proxy.getHostId());
1719-
if (fromHost.getClusterId() == null) {
1720-
s_logger.debug("The host is not in a cluster");
1721-
return null;
1722-
}
1723-
avoid.add(fromHost);
1724-
1725-
while ((routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _serviceOffering, template, proxy, fromHost, avoid)) != null) {
1726-
avoid.add(routingHost);
1727-
1728-
if (s_logger.isDebugEnabled()) {
1729-
s_logger.debug("Trying to migrate router to host " + routingHost.getName());
1730-
}
1731-
1732-
if (!_storageMgr.share(proxy, vols, routingHost, false)) {
1733-
s_logger.warn("Can not share " + proxy.getName());
1734-
throw new StorageUnavailableException("Can not share " + proxy.getName(), vol.getPoolId());
1735-
}
1736-
1737-
Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
1738-
if (answer != null && answer.getResult()) {
1739-
return routingHost;
1740-
}
1741-
_storageMgr.unshare(proxy, vols, routingHost);
1742-
}
1743-
1744-
return null;
1745-
}
1640+
// @Override
1641+
// public boolean migrate(ConsoleProxyVO proxy, HostVO host) {
1642+
// HostVO fromHost = _hostDao.findById(proxy.getId());
1643+
//
1644+
// if (! _itMgr.stateTransitTo(proxy, VirtualMachine.Event.MigrationRequested, proxy.getHostId())) {
1645+
// s_logger.debug("State for " + proxy.toString() + " has changed so migration can not take place.");
1646+
// return false;
1647+
// }
1648+
//
1649+
// MigrateCommand cmd = new MigrateCommand(proxy.getInstanceName(), host.getPrivateIpAddress(), false);
1650+
// Answer answer = _agentMgr.easySend(fromHost.getId(), cmd);
1651+
// if (answer == null || !answer.getResult()) {
1652+
// return false;
1653+
// }
1654+
//
1655+
// _storageMgr.unshare(proxy, fromHost);
1656+
//
1657+
// return true;
1658+
// }
1659+
//
1660+
// @Override
1661+
// public boolean completeMigration(ConsoleProxyVO proxy, HostVO host) throws AgentUnavailableException, OperationTimedoutException {
1662+
//
1663+
// CheckVirtualMachineCommand cvm = new CheckVirtualMachineCommand(proxy.getInstanceName());
1664+
// CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(host.getId(), cvm);
1665+
// if (!answer.getResult()) {
1666+
// s_logger.debug("Unable to complete migration for " + proxy.getId());
1667+
// _itMgr.stateTransitTo(proxy, VirtualMachine.Event.AgentReportStopped, null);
1668+
// return false;
1669+
// }
1670+
//
1671+
// State state = answer.getState();
1672+
// if (state == State.Stopped) {
1673+
// s_logger.warn("Unable to complete migration as we can not detect it on " + host.getId());
1674+
// _itMgr.stateTransitTo(proxy, VirtualMachine.Event.AgentReportStopped, null);
1675+
// return false;
1676+
// }
1677+
//
1678+
// _itMgr.stateTransitTo(proxy, VirtualMachine.Event.OperationSucceeded, host.getId());
1679+
// return true;
1680+
// }
1681+
//
1682+
// @Override
1683+
// public HostVO prepareForMigration(ConsoleProxyVO proxy) throws StorageUnavailableException {
1684+
//
1685+
// VMTemplateVO template = _templateDao.findById(proxy.getTemplateId());
1686+
// long routerId = proxy.getId();
1687+
// boolean mirroredVols = proxy.isMirroredVols();
1688+
// DataCenterVO dc = _dcDao.findById(proxy.getDataCenterId());
1689+
// HostPodVO pod = _podDao.findById(proxy.getPodId());
1690+
// StoragePoolVO sp = _storageMgr.getStoragePoolForVm(proxy.getId());
1691+
//
1692+
// List<VolumeVO> vols = _volsDao.findCreatedByInstance(routerId);
1693+
//
1694+
// String[] storageIps = new String[2];
1695+
// VolumeVO vol = vols.get(0);
1696+
// storageIps[0] = vol.getHostIp();
1697+
// if (mirroredVols && (vols.size() == 2)) {
1698+
// storageIps[1] = vols.get(1).getHostIp();
1699+
// }
1700+
//
1701+
// PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(proxy.getName(), null, storageIps, vols, mirroredVols);
1702+
//
1703+
// HostVO routingHost = null;
1704+
// HashSet<Host> avoid = new HashSet<Host>();
1705+
//
1706+
// HostVO fromHost = _hostDao.findById(proxy.getHostId());
1707+
// if (fromHost.getClusterId() == null) {
1708+
// s_logger.debug("The host is not in a cluster");
1709+
// return null;
1710+
// }
1711+
// avoid.add(fromHost);
1712+
//
1713+
// while ((routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _serviceOffering, template, proxy, fromHost, avoid)) != null) {
1714+
// avoid.add(routingHost);
1715+
//
1716+
// if (s_logger.isDebugEnabled()) {
1717+
// s_logger.debug("Trying to migrate router to host " + routingHost.getName());
1718+
// }
1719+
//
1720+
// if (!_storageMgr.share(proxy, vols, routingHost, false)) {
1721+
// s_logger.warn("Can not share " + proxy.getName());
1722+
// throw new StorageUnavailableException("Can not share " + proxy.getName(), vol.getPoolId());
1723+
// }
1724+
//
1725+
// Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
1726+
// if (answer != null && answer.getResult()) {
1727+
// return routingHost;
1728+
// }
1729+
// _storageMgr.unshare(proxy, vols, routingHost);
1730+
// }
1731+
//
1732+
// return null;
1733+
// }
17461734

17471735
private String getCapacityScanLockName() {
17481736
// to improve security, it may be better to return a unique mashed

server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.cloud.info.ConsoleProxyInfo;
3030
import com.cloud.utils.component.ComponentLocator;
3131
import com.cloud.utils.component.Inject;
32-
import com.cloud.vm.ConsoleProxyVO;
3332
import com.cloud.vm.VMInstanceVO;
3433
import com.cloud.vm.dao.ConsoleProxyDao;
3534

@@ -67,9 +66,4 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
6766

6867
return true;
6968
}
70-
71-
@Override
72-
public ConsoleProxyVO get(long id) {
73-
return _proxyDao.findById(id);
74-
}
7569
}

0 commit comments

Comments
 (0)