NaaS: Configure commands for DhcpElement, VirtualRouterElement and RedundantVirtualRouterElement

Add configure command for these virtual router based elements. The commands
should be different for different elements.

The context of configuration would be added later.
This commit is contained in:
Sheng Yang 2011-10-20 13:48:21 -07:00
parent 51828421f3
commit 04f106a595
15 changed files with 337 additions and 54 deletions

View File

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved. * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
* *
* This software is licensed under the GNU General Public License v3 or later. * This software is licensed under the GNU General Public License v3 or later.
* *
@ -16,8 +16,8 @@
* *
*/ */
package com.cloud.api.commands; package com.cloud.api.commands;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants; import com.cloud.api.ApiConstants;
@ -27,32 +27,29 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter; import com.cloud.api.Parameter;
import com.cloud.api.PlugService; import com.cloud.api.PlugService;
import com.cloud.api.ServerApiException; import com.cloud.api.ServerApiException;
import com.cloud.api.response.DomainRouterResponse; import com.cloud.api.response.SuccessResponse;
import com.cloud.async.AsyncJob; import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.network.element.DhcpElementService;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.VirtualNetworkApplianceService;
import com.cloud.network.router.VirtualRouter;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.user.UserContext; import com.cloud.user.UserContext;
@Implementation(responseObject=SuccessResponse.class, description="Configures a dhcp element.")
public class ConfigureDhcpElementCmd extends BaseAsyncCmd {
@Implementation(responseObject=DomainRouterResponse.class, description="Configures a router.") public static final Logger s_logger = Logger.getLogger(ConfigureDhcpElementCmd.class.getName());
public class ConfigureRouterCmd extends BaseAsyncCmd { private static final String s_name = "configuredhcpelementresponse";
public static final Logger s_logger = Logger.getLogger(ConfigureRouterCmd.class.getName());
private static final String s_name = "configurerouterresponse";
@PlugService @PlugService
private static VirtualNetworkApplianceService _myrouterService; private DhcpElementService _service;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
//////////////// API parameters ///////////////////// //////////////// API parameters /////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the router") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the dhcp element")
private Long id; private Long id;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -68,36 +65,31 @@ public class ConfigureRouterCmd extends BaseAsyncCmd {
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@Override @Override
public String getCommandName() { public String getCommandName() {
return s_name; return s_name;
} }
public static String getResultObjectName() { public static String getResultObjectName() {
return "router"; return "boolean";
} }
@Override @Override
public long getEntityOwnerId() { public long getEntityOwnerId() {
VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId()); return Account.ACCOUNT_ID_SYSTEM;
if (router != null) {
return router.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
} }
@Override @Override
public String getEventType() { public String getEventType() {
return EventTypes.EVENT_ROUTER_START; return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
} }
@Override @Override
public String getEventDescription() { public String getEventDescription() {
return "configuring router: " + getId(); return "configuring dhcp element: " + getId();
} }
public AsyncJob.Type getInstanceType() { public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.DomainRouter; return AsyncJob.Type.None;
} }
public Long getInstanceId() { public Long getInstanceId() {
@ -106,15 +98,15 @@ public class ConfigureRouterCmd extends BaseAsyncCmd {
@Override @Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Router Id: "+getId()); UserContext.current().setEventDetails("Dhcp element Id: " + getId());
//This should call the configure API. Calling startRouter for now. Boolean result = _service.configure();
VirtualRouter result = _myrouterService.startRouter(id); if (result){
if (result != null){ SuccessResponse response = new SuccessResponse();
DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result); response.setResponseName(getCommandName());
routerResponse.setResponseName(getCommandName()); response.setSuccess(result);
this.setResponseObject(routerResponse); this.setResponseObject(response);
} else { } else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start router"); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the dhcp element");
} }
} }
} }

View File

@ -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.BaseAsyncCmd;
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.element.RedundantVirtualRouterElementService;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(responseObject=SuccessResponse.class, description="Configures a redundant virtual router element.")
public class ConfigureRedundantVirtualRouterElementCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ConfigureRedundantVirtualRouterElementCmd.class.getName());
private static final String s_name = "configureredundantvirtualrouterelementresponse";
@PlugService
private RedundantVirtualRouterElementService _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the redundant virtual router element")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "boolean";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
}
@Override
public String getEventDescription() {
return "configuring redundant virtual router element: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.None;
}
public Long getInstanceId() {
return getId();
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Redundant virtual router element Id: " + getId());
Boolean result = _service.configure();
if (result){
SuccessResponse response = new SuccessResponse();
response.setResponseName(getCommandName());
response.setSuccess(result);
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the redundant virtual router element");
}
}
}

View File

@ -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.BaseAsyncCmd;
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.element.VirtualRouterElementService;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(responseObject=SuccessResponse.class, description="Configures a virtual router element.")
public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(ConfigureVirtualRouterElementCmd.class.getName());
private static final String s_name = "configurevirtualrouterelementresponse";
@PlugService
private VirtualRouterElementService _service;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the virtual router element")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "boolean";
}
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
}
@Override
public String getEventDescription() {
return "configuring virtual router element: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.None;
}
public Long getInstanceId() {
return getId();
}
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
UserContext.current().setEventDetails("Virtual router element Id: " + getId());
Boolean result = _service.configure();
if (result){
SuccessResponse response = new SuccessResponse();
response.setResponseName(getCommandName());
response.setSuccess(result);
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the virtual router element");
}
}
}

View File

@ -211,4 +211,7 @@ public class EventTypes {
public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND"; public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND";
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD"; public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE"; public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
//Network as a Service
public static final String EVENT_NETWORK_ELEMENT_CONFIGURE = "NETWORK.ELEMENT.CONFIGURE";
} }

View File

@ -24,7 +24,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter;
import com.cloud.utils.component.PluggableService; import com.cloud.utils.component.PluggableService;
public interface VirtualNetworkApplianceService extends PluggableService{ public interface VirtualNetworkApplianceService {
/** /**
* Starts domain router * Starts domain router
* @param cmd the command specifying router's id * @param cmd the command specifying router's id

View File

@ -0,0 +1,7 @@
package com.cloud.network.element;
import com.cloud.utils.component.PluggableService;
public interface DhcpElementService extends PluggableService{
boolean configure();
}

View File

@ -0,0 +1,7 @@
package com.cloud.network.element;
import com.cloud.utils.component.PluggableService;
public interface RedundantVirtualRouterElementService extends PluggableService{
boolean configure();
}

View File

@ -0,0 +1,7 @@
package com.cloud.network.element;
import com.cloud.utils.component.PluggableService;
public interface VirtualRouterElementService extends PluggableService{
boolean configure();
}

View File

@ -107,7 +107,9 @@
<adapter name="ClusterBasedAgentLbPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner"/> <adapter name="ClusterBasedAgentLbPlanner" class="com.cloud.cluster.agentlb.ClusterBasedAgentLoadBalancerPlanner"/>
</adapters> </adapters>
<!-- pluggableservice name="VirtualRouterService" key="com.cloud.network.VirtualNetworkApplianceService" class="com.cloud.network.router.VirtualNetworkApplianceManagerImpl"/ --> <pluggableservice name="DhcpElementService" key="com.cloud.network.element.DhcpElementService" class="com.cloud.network.element.DhcpElement"/>
<pluggableservice name="VirtualRouterElementService" key="com.cloud.network.element.VirtualRouterElementService" class="com.cloud.network.element.VirtualRouterElement"/>
<pluggableservice name="RedundantVirtualRouterElementService" key="com.cloud.network.element.RedundantVirtualRouterElementService" class="com.cloud.network.element.RedundantVirtualRouterElement"/>
</management-server> </management-server>
<configuration-server class="com.cloud.server.ConfigurationServerImpl"> <configuration-server class="com.cloud.server.ConfigurationServerImpl">

View File

@ -2,4 +2,6 @@
### Please standardize naming conventions to camel-case (even for acronyms). ### Please standardize naming conventions to camel-case (even for acronyms).
#### router commands #### router commands
configureRouter=com.cloud.api.commands.ConfigureRouterCmd;7 configureDhcpElement=com.cloud.api.commands.ConfigureDhcpElementCmd;7
configureVirtualRouterElement=com.cloud.api.commands.ConfigureVirtualRouterElementCmd;7
configureRedundantVirtualRouterElement=com.cloud.api.commands.ConfigureRedundantVirtualRouterElementCmd;7

View File

@ -84,6 +84,12 @@ import com.cloud.network.dao.PhysicalNetworkDaoImpl;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl; import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl;
import com.cloud.network.dao.RemoteAccessVpnDaoImpl; import com.cloud.network.dao.RemoteAccessVpnDaoImpl;
import com.cloud.network.dao.VpnUserDaoImpl; import com.cloud.network.dao.VpnUserDaoImpl;
import com.cloud.network.element.DhcpElement;
import com.cloud.network.element.RedundantVirtualRouterElement;
import com.cloud.network.element.VirtualRouterElement;
import com.cloud.network.element.DhcpElementService;
import com.cloud.network.element.RedundantVirtualRouterElementService;
import com.cloud.network.element.VirtualRouterElementService;
import com.cloud.network.firewall.FirewallManagerImpl; import com.cloud.network.firewall.FirewallManagerImpl;
import com.cloud.network.lb.ElasticLoadBalancerManagerImpl; import com.cloud.network.lb.ElasticLoadBalancerManagerImpl;
import com.cloud.network.lb.LoadBalancingRulesManagerImpl; import com.cloud.network.lb.LoadBalancingRulesManagerImpl;
@ -373,7 +379,9 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
} }
protected void populateServices() { protected void populateServices() {
addService("VirtualRouterService", VirtualNetworkApplianceService.class, VirtualNetworkApplianceManagerImpl.class); addService("DhcpElementService", DhcpElementService.class, DhcpElement.class);
addService("VirtualRouterElementService", VirtualRouterElementService.class, VirtualRouterElement.class);
addService("RedundantVirtualRouterElementService", RedundantVirtualRouterElementService.class, RedundantVirtualRouterElement.class);
} }
@Override @Override

View File

@ -46,6 +46,7 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.element.DhcpElementService;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.org.Cluster; import com.cloud.org.Cluster;
import com.cloud.user.AccountManager; import com.cloud.user.AccountManager;
@ -64,7 +65,7 @@ import com.cloud.vm.dao.UserVmDao;
@Local(value=NetworkElement.class) @Local(value=NetworkElement.class)
public class DhcpElement extends AdapterBase implements PasswordServiceProvider { public class DhcpElement extends AdapterBase implements DhcpElementService, PasswordServiceProvider {
private static final Logger s_logger = Logger.getLogger(DhcpElement.class); private static final Logger s_logger = Logger.getLogger(DhcpElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -246,4 +247,16 @@ public class DhcpElement extends AdapterBase implements PasswordServiceProvider
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers); return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
} }
@Override
public boolean configure() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getPropertiesFile() {
return "virtualrouter_commands.properties";
}
} }

View File

@ -19,6 +19,7 @@ import com.cloud.network.Network.Service;
import com.cloud.network.Network.Type; import com.cloud.network.Network.Type;
import com.cloud.network.NetworkManager; import com.cloud.network.NetworkManager;
import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter;
import com.cloud.network.element.RedundantVirtualRouterElementService;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.uservm.UserVm; import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
@ -29,7 +30,7 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
@Local(value=NetworkElement.class) @Local(value=NetworkElement.class)
public class RedundantVirtualRouterElement extends VirtualRouterElement { public class RedundantVirtualRouterElement extends VirtualRouterElement implements RedundantVirtualRouterElementService {
private static final Logger s_logger = Logger.getLogger(RedundantVirtualRouterElement.class); private static final Logger s_logger = Logger.getLogger(RedundantVirtualRouterElement.class);
@Inject NetworkManager _networkMgr; @Inject NetworkManager _networkMgr;
@ -77,4 +78,15 @@ public class RedundantVirtualRouterElement extends VirtualRouterElement {
return false; return false;
} }
} }
@Override
public String getPropertiesFile() {
return "virtualrouter_commands.properties";
}
@Override
public boolean configure() {
// TODO Auto-generated method stub
return false;
}
} }

View File

@ -51,6 +51,7 @@ import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNat; import com.cloud.network.rules.StaticNat;
import com.cloud.network.element.VirtualRouterElementService;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.org.Cluster; import com.cloud.org.Cluster;
@ -69,7 +70,7 @@ import com.cloud.vm.dao.UserVmDao;
@Local(value=NetworkElement.class) @Local(value=NetworkElement.class)
public class VirtualRouterElement extends DhcpElement implements SourceNATServiceProvider, FirewallServiceProvider, StaticNATServiceProvider, RemoteAccessVPNServiceProvider { public class VirtualRouterElement extends DhcpElement implements VirtualRouterElementService, SourceNATServiceProvider, FirewallServiceProvider, StaticNATServiceProvider, RemoteAccessVPNServiceProvider {
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class); private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -373,4 +374,15 @@ public class VirtualRouterElement extends DhcpElement implements SourceNATServic
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers); return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
} }
@Override
public String getPropertiesFile() {
return "virtualrouter_commands.properties";
}
@Override
public boolean configure() {
// TODO Auto-generated method stub
return false;
}
} }

View File

@ -2742,10 +2742,4 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
public boolean processTimeout(long agentId, long seq) { public boolean processTimeout(long agentId, long seq) {
return false; return false;
} }
@Override
public String getPropertiesFile() {
return "virtualrouter_commands.properties";
}
} }