diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index ca255d96f7a..eebd526857e 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -129,6 +129,7 @@ listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstanc startRouter=com.cloud.api.commands.StartRouterCmd;3 rebootRouter=com.cloud.api.commands.RebootRouterCmd;3 stopRouter=com.cloud.api.commands.StopRouterCmd;3 +changeServiceForRouter=com.cloud.api.commands.UpgradeRouterCmd;3 listRouters=com.cloud.api.commands.ListRoutersCmd;7 #### system vm commands diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 410ff5ff3ce..35d82fac733 100755 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -2261,5 +2261,6 @@ public interface ManagementServer { */ String getVersion(); boolean uploadCertificate(String certificatePath); + boolean upgradeRouter(long routerId, long serviceOfferingId) throws InvalidParameterValueException; } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 12f4cafb1cb..d03ecea83ff 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -320,4 +320,8 @@ public class DomainRouterVO extends VMInstanceVO implements DomainRouter { public String getGuestZoneMacAddress() { return guestZoneMacAddress; } + + public void setServiceOfferingId(long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 37a3fc977cc..6e04cda5326 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -234,4 +234,5 @@ public interface NetworkManager extends Manager { void create(K vm); List getNics(K vm); + boolean upgradeRouter(long routerId, long serviceOfferingId); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c89c388d045..8f147797f31 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -778,6 +778,15 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager return true; } + + @Override + @DB + public boolean upgradeRouter(long routerId, long serviceOfferingId) { + DomainRouterVO router = _routerDao.acquire(routerId); + + router.setServiceOfferingId(serviceOfferingId); + return _routerDao.update(routerId, router); + } private String rot13(final String password) { final StringBuffer newPassword = new StringBuffer(""); @@ -888,10 +897,11 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager final HashSet avoid = new HashSet(); final VMTemplateVO template = _templateDao.findById(router.getTemplateId()); final DataCenterVO dc = _dcDao.findById(router.getDataCenterId()); + ServiceOfferingVO offering = _serviceOfferingDao.findById(router.getServiceOfferingId()); List sps = _storageMgr.getStoragePoolsForVm(router.getId()); StoragePoolVO sp = sps.get(0); // FIXME - HostVO routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _offering, template, router, null, avoid); + HostVO routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, template, router, null, avoid); if (routingHost == null) { s_logger.error("Unable to find a host to start " + router.toString()); @@ -1053,7 +1063,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager _dcDao.releaseLinkLocalPrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId()); _storageMgr.unshare(router, vols, routingHost); - } while (--retry > 0 && (routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _offering, template, router, null, avoid)) != null); + } while (--retry > 0 && (routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, template, router, null, avoid)) != null); if (routingHost == null || retry <= 0) { @@ -2134,6 +2144,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager final boolean mirroredVols = router.isMirroredVols(); final DataCenterVO dc = _dcDao.findById(router.getDataCenterId()); final HostPodVO pod = _podDao.findById(router.getPodId()); + final ServiceOfferingVO offering = _serviceOfferingDao.findById(router.getServiceOfferingId()); List sps = _storageMgr.getStoragePoolsForVm(router.getId()); StoragePoolVO sp = sps.get(0); // FIXME @@ -2158,7 +2169,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager } avoid.add(fromHost); - while ((routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, _offering, _template, router, fromHost, avoid)) != null) { + while ((routingHost = (HostVO)_agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, _template, router, fromHost, avoid)) != null) { avoid.add(routingHost); if (s_logger.isDebugEnabled()) { s_logger.debug("Trying to migrate router to host " + routingHost.getName()); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index c47f53355ae..16b28d8ed8a 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2903,6 +2903,37 @@ public class ManagementServerImpl implements ManagementServer { public boolean destroyRouter(long routerId) { return _networkMgr.destroyRouter(routerId); } + + @Override + public boolean upgradeRouter(long routerId, long serviceOfferingId) throws InvalidParameterValueException { + DomainRouterVO router = _routerDao.findById(routerId); + if (router == null) { + throw new InvalidParameterValueException("Unable to find router with id " + routerId); + } + + if (router.getServiceOfferingId() == serviceOfferingId) { + s_logger.debug("Router: " + routerId + "already has service offering: " + serviceOfferingId); + return true; + } + + ServiceOfferingVO newServiceOffering = _offeringsDao.findById(serviceOfferingId); + if (newServiceOffering == null) { + throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId); + } + + ServiceOfferingVO currentServiceOffering = _offeringsDao.findById(router.getServiceOfferingId()); + + if (!currentServiceOffering.getGuestIpType().equals(newServiceOffering.getGuestIpType())) { + throw new InvalidParameterValueException("Can't upgrade, due to new newtowrk type: " + newServiceOffering.getGuestIpType() + " is different from " + + "curruent network type: " + currentServiceOffering.getGuestIpType()); + } + if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) { + throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newServiceOffering.getGuestIpType() + " is different from " + + "curruent local storage status: " + currentServiceOffering.getUseLocalStorage()); + } + + return _networkMgr.upgradeRouter(routerId, serviceOfferingId); + } @Override public DomainRouterVO findDomainRouterBy(long accountId, long dataCenterId) {