mirror of https://github.com/apache/cloudstack.git
NaaS: Create AddVirtualRouterElementCmd
As DhcpElement/VirtualRouterElement/RedundantVirtualRouterElement is decided to be the service provider of the physical network, this API should be called to add a new element, with correlated network service provider ID. Then e.g. ConfigureVirtualRouterElementCmd should be called to configure and enable the element.
This commit is contained in:
parent
00bb63ac67
commit
cd3fbf0548
|
|
@ -287,5 +287,6 @@ public class ApiConstants {
|
|||
public static final String XEN_NETWORK_LABEL = "xennetworklabel";
|
||||
public static final String KVM_NETWORK_LABEL = "kvmnetworklabel";
|
||||
public static final String VMWARE_NETWORK_LABEL = "vmwarenetworklabel";
|
||||
public static final String NETWORK_SERVICE_PROVIDER_ID = "nspid";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.PlugService;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.element.DhcpElementService;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(responseObject=SuccessResponse.class, description="Create a dhcp element.")
|
||||
public class CreateDhcpElementCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateDhcpElementCmd.class.getName());
|
||||
private static final String s_name = "createdhcpelementresponse";
|
||||
|
||||
@PlugService
|
||||
private DhcpElementService _service;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.LONG, required=true, description="the network service provider ID of the dhcp element")
|
||||
private Long nspId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public void setNspId(Long nspId) {
|
||||
this.nspId = nspId;
|
||||
}
|
||||
|
||||
public Long getNspId() {
|
||||
return nspId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("DHCP element Id: "+getEntityId());
|
||||
VirtualRouterElements result = _service.getCreatedElement(getEntityId());
|
||||
if (result != null) {
|
||||
SuccessResponse response = new SuccessResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
response.setSuccess(true);
|
||||
this.setResponseObject(response);
|
||||
}else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
VirtualRouterElements result = _service.addElement(getNspId());
|
||||
if (result != null) {
|
||||
setEntityId(result.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_SERVICE_PROVIDER_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Adding physical network ServiceProvider Dhcp server: " + getEntityId();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.PlugService;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.element.RedundantVirtualRouterElementService;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(responseObject=SuccessResponse.class, description="Create a redundant virtual router element.")
|
||||
public class CreateRedundantVirtualRouterElementCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateVirtualRouterElementCmd.class.getName());
|
||||
private static final String s_name = "createredundantvirtualrouterelementresponse";
|
||||
|
||||
@PlugService
|
||||
private RedundantVirtualRouterElementService _service;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.LONG, required=true, description="the network service provider ID of the redundant virtual router element")
|
||||
private Long nspId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public void setNspId(Long nspId) {
|
||||
this.nspId = nspId;
|
||||
}
|
||||
|
||||
public Long getNspId() {
|
||||
return nspId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Redundant Virtual Router Element Id: "+getEntityId());
|
||||
VirtualRouterElements result = _service.getCreatedElement(getEntityId());
|
||||
if (result != null) {
|
||||
SuccessResponse response = new SuccessResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
response.setSuccess(true);
|
||||
this.setResponseObject(response);
|
||||
}else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
VirtualRouterElements result = _service.addElement(getNspId());
|
||||
if (result != null) {
|
||||
setEntityId(result.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_SERVICE_PROVIDER_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Adding physical network ServiceProvider redundant virtual router: " + getEntityId();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.PlugService;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.element.VirtualRouterElementService;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(responseObject=SuccessResponse.class, description="Create a virtual router element.")
|
||||
public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateVirtualRouterElementCmd.class.getName());
|
||||
private static final String s_name = "createvirtualrouterelementresponse";
|
||||
|
||||
@PlugService
|
||||
private VirtualRouterElementService _service;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.LONG, required=true, description="the network service provider ID of the virtual router element")
|
||||
private Long nspId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public void setNspId(Long nspId) {
|
||||
this.nspId = nspId;
|
||||
}
|
||||
|
||||
public Long getNspId() {
|
||||
return nspId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
|
||||
VirtualRouterElements result = _service.getCreatedElement(getEntityId());
|
||||
if (result != null) {
|
||||
SuccessResponse response = new SuccessResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
response.setSuccess(true);
|
||||
this.setResponseObject(response);
|
||||
}else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
VirtualRouterElements result = _service.addElement(getNspId());
|
||||
if (result != null) {
|
||||
setEntityId(result.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_SERVICE_PROVIDER_CREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "Adding physical network ServiceProvider Virtual Router: " + getEntityId();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package com.cloud.network.element;
|
||||
package com.cloud.network;
|
||||
|
||||
public interface VirtualRouterElements {
|
||||
public enum VirtualRouterElementsType {
|
||||
|
|
@ -25,4 +25,7 @@ public interface VirtualRouterElements {
|
|||
RedundantVirtualRouterElement,
|
||||
}
|
||||
public VirtualRouterElementsType getType();
|
||||
public long getId();
|
||||
public boolean isEnabled();
|
||||
public long getNspId();
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
package com.cloud.network.element;
|
||||
|
||||
import com.cloud.api.commands.ConfigureDhcpElementCmd;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
|
||||
public interface DhcpElementService extends PluggableService{
|
||||
boolean configure(ConfigureDhcpElementCmd cmd);
|
||||
boolean addElement(Long nspId);
|
||||
VirtualRouterElements addElement(Long nspId);
|
||||
Long getIdByNspId(Long nspId);
|
||||
boolean isReady(long nspId);
|
||||
VirtualRouterElements getCreatedElement(long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
### Please standardize naming conventions to camel-case (even for acronyms).
|
||||
|
||||
#### router commands
|
||||
createVirtualRouterElement=com.cloud.api.commands.CreateVirtualRouterElementCmd;7
|
||||
createDhcpElement=com.cloud.api.commands.CreateDhcpElementCmd;7
|
||||
createRedundantVirtualRouterElement=com.cloud.api.commands.CreateRedundantVirtualRouterElementCmd;7
|
||||
configureDhcpElement=com.cloud.api.commands.ConfigureDhcpElementCmd;7
|
||||
configureVirtualRouterElement=com.cloud.api.commands.ConfigureVirtualRouterElementCmd;7
|
||||
configureRedundantVirtualRouterElement=com.cloud.api.commands.ConfigureRedundantVirtualRouterElementCmd;7
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
package com.cloud.network.dao;
|
||||
|
||||
import com.cloud.network.element.VirtualRouterElementsVO;
|
||||
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface VirtualRouterElementsDao extends GenericDao<VirtualRouterElementsVO, Long> {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package com.cloud.network.dao;
|
|||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.network.element.VirtualRouterElementsVO;
|
||||
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import com.cloud.exception.InsufficientCapacityException;
|
|||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Network.Provider;
|
||||
|
|
@ -45,7 +46,7 @@ import com.cloud.network.Networks.TrafficType;
|
|||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.VirtualRouterElementsDao;
|
||||
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
|
|
@ -218,7 +219,7 @@ public class DhcpElement extends AdapterBase implements DhcpElementService, User
|
|||
s_logger.trace("Can't find element with network service provider ID " + cmd.getNspId());
|
||||
return false;
|
||||
}
|
||||
element.setIsReady(cmd.getEnabled());
|
||||
element.setEnabled(cmd.getEnabled());
|
||||
|
||||
_vrElementsDao.persist(element);
|
||||
|
||||
|
|
@ -226,14 +227,19 @@ public class DhcpElement extends AdapterBase implements DhcpElementService, User
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addElement(Long nspId) {
|
||||
public VirtualRouterElements addElement(Long nspId) {
|
||||
long serviceOfferingId = _routerMgr.getDefaultVirtualRouterServiceOfferingId();
|
||||
if (serviceOfferingId == 0) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
VirtualRouterElementsVO element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.DhcpElement);
|
||||
VirtualRouterElementsVO element = _vrElementsDao.findByNspIdAndType(nspId, VirtualRouterElementsType.DhcpElement);
|
||||
if (element != null) {
|
||||
s_logger.trace("There is already a dhcp element with service provider id " + nspId);
|
||||
return null;
|
||||
}
|
||||
element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.DhcpElement);
|
||||
_vrElementsDao.persist(element);
|
||||
return true;
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -248,7 +254,12 @@ public class DhcpElement extends AdapterBase implements DhcpElementService, User
|
|||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
return element.getIsReady();
|
||||
return element.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualRouterElements getCreatedElement(long id) {
|
||||
return _vrElementsDao.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.dao.VirtualRouterElementsDao;
|
||||
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
|
@ -88,16 +88,37 @@ public class RedundantVirtualRouterElement extends VirtualRouterElement implemen
|
|||
s_logger.trace("Can't find element with UUID " + cmd.getNspId());
|
||||
return false;
|
||||
}
|
||||
element.setIsReady(cmd.getEnabled());
|
||||
element.setEnabled(cmd.getEnabled());
|
||||
_vrElementsDao.persist(element);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElement(Long nspId) {
|
||||
VirtualRouterElementsVO element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.RedundantVirtualRouterElement);
|
||||
public VirtualRouterElements addElement(Long nspId) {
|
||||
VirtualRouterElementsVO element = _vrElementsDao.findByNspIdAndType(nspId, VirtualRouterElementsType.RedundantVirtualRouterElement);
|
||||
if (element != null) {
|
||||
s_logger.trace("There is already a redundant virtual router element with service provider id " + nspId);
|
||||
return null;
|
||||
}
|
||||
element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.RedundantVirtualRouterElement);
|
||||
_vrElementsDao.persist(element);
|
||||
return true;
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady(long nspId) {
|
||||
VirtualRouterElementsVO element = _vrElementsDao.findByNspIdAndType(nspId, VirtualRouterElementsType.RedundantVirtualRouterElement);
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
return element.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIdByNspId(Long nspId) {
|
||||
VirtualRouterElementsVO vr = _vrElementsDao.findByNspIdAndType(nspId, VirtualRouterElementsType.RedundantVirtualRouterElement);
|
||||
return vr.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,11 +43,12 @@ import com.cloud.network.NetworkManager;
|
|||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.VirtualRouterElementsDao;
|
||||
import com.cloud.network.element.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.VirtualRouterElements.VirtualRouterElementsType;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
|
|
@ -408,17 +409,22 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
|
|||
return false;
|
||||
}
|
||||
|
||||
element.setIsReady(cmd.getEnabled());
|
||||
element.setEnabled(cmd.getEnabled());
|
||||
_vrElementsDao.persist(element);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElement(Long nspId) {
|
||||
VirtualRouterElementsVO element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.VirtualRouterElement);
|
||||
public VirtualRouterElements addElement(Long nspId) {
|
||||
VirtualRouterElementsVO element = _vrElementsDao.findByNspIdAndType(nspId, VirtualRouterElementsType.VirtualRouterElement);
|
||||
if (element != null) {
|
||||
s_logger.trace("There is already a virtual router element with service provider id " + nspId);
|
||||
return null;
|
||||
}
|
||||
element = new VirtualRouterElementsVO(nspId, null, VirtualRouterElementsType.VirtualRouterElement);
|
||||
_vrElementsDao.persist(element);
|
||||
return true;
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -446,7 +452,7 @@ public class VirtualRouterElement extends DhcpElement implements VirtualRouterEl
|
|||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
return element.getIsReady();
|
||||
return element.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import javax.persistence.GenerationType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.network.VirtualRouterElements;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
|
|
@ -42,8 +43,8 @@ public class VirtualRouterElementsVO implements VirtualRouterElements {
|
|||
@Enumerated(EnumType.STRING)
|
||||
private VirtualRouterElementsType type;
|
||||
|
||||
@Column(name="ready")
|
||||
private boolean isReady;
|
||||
@Column(name="enabled")
|
||||
private boolean enabled;
|
||||
|
||||
@Column(name="nsp_id")
|
||||
private long nspId;
|
||||
|
|
@ -63,6 +64,7 @@ public class VirtualRouterElementsVO implements VirtualRouterElements {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNspId() {
|
||||
return nspId;
|
||||
}
|
||||
|
|
@ -71,6 +73,7 @@ public class VirtualRouterElementsVO implements VirtualRouterElements {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -88,12 +91,13 @@ public class VirtualRouterElementsVO implements VirtualRouterElements {
|
|||
this.removed = removed;
|
||||
}
|
||||
|
||||
public void setIsReady(boolean isReady) {
|
||||
this.isReady = isReady;
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean getIsReady() {
|
||||
return isReady;
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
|
|
|
|||
|
|
@ -1805,11 +1805,11 @@ CREATE TABLE `cloud`.`physical_network_external_devices` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`virtual_router_elements` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`nsp_id` bigint unsigned NOT NULL,
|
||||
`id` bigint unsigned NOT NULL auto_increment COMMENT 'id',
|
||||
`nsp_id` bigint unsigned NOT NULL COMMENT 'Network Service Provider ID',
|
||||
`uuid` varchar(255) UNIQUE,
|
||||
`type` varchar(255) NOT NULL,
|
||||
`ready` int(1) NOT NULL,
|
||||
`type` varchar(255) NOT NULL COMMENT 'DHCP element, or Virtual router, or redundant virtual router',
|
||||
`enabled` int(1) NOT NULL COMMENT 'Enabled or disabled',
|
||||
`removed` datetime COMMENT 'date removed if not null',
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_virtual_router_elements__nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) ON DELETE CASCADE
|
||||
|
|
|
|||
Loading…
Reference in New Issue