diff --git a/api/src/com/cloud/api/commands/ConfigureRouterCmd.java b/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java similarity index 64% rename from api/src/com/cloud/api/commands/ConfigureRouterCmd.java rename to api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java index 235f4622690..5fd11f733e0 100644 --- a/api/src/com/cloud/api/commands/ConfigureRouterCmd.java +++ b/api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java @@ -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. * @@ -16,8 +16,8 @@ * */ -package com.cloud.api.commands; - +package com.cloud.api.commands; + import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; @@ -27,32 +27,29 @@ 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.DomainRouterResponse; +import com.cloud.api.response.SuccessResponse; import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; +import com.cloud.network.element.DhcpElementService; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; 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.UserContext; - - -@Implementation(responseObject=DomainRouterResponse.class, description="Configures a router.") -public class ConfigureRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureRouterCmd.class.getName()); - private static final String s_name = "configurerouterresponse"; +@Implementation(responseObject=SuccessResponse.class, description="Configures a dhcp element.") +public class ConfigureDhcpElementCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(ConfigureDhcpElementCmd.class.getName()); + private static final String s_name = "configuredhcpelementresponse"; - @PlugService - private static VirtualNetworkApplianceService _myrouterService; - + @PlugService + private DhcpElementService _service; + ///////////////////////////////////////////////////// //////////////// 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; ///////////////////////////////////////////////////// @@ -68,36 +65,31 @@ public class ConfigureRouterCmd extends BaseAsyncCmd { ///////////////////////////////////////////////////// @Override - public String getCommandName() { - return s_name; - } - - public static String getResultObjectName() { - return "router"; + public String getCommandName() { + return s_name; + } + + public static String getResultObjectName() { + return "boolean"; } @Override public long getEntityOwnerId() { - VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId()); - 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 + return Account.ACCOUNT_ID_SYSTEM; } @Override public String getEventType() { - return EventTypes.EVENT_ROUTER_START; + return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE; } @Override public String getEventDescription() { - return "configuring router: " + getId(); + return "configuring dhcp element: " + getId(); } public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.DomainRouter; + return AsyncJob.Type.None; } public Long getInstanceId() { @@ -106,15 +98,15 @@ public class ConfigureRouterCmd extends BaseAsyncCmd { @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{ - UserContext.current().setEventDetails("Router Id: "+getId()); - //This should call the configure API. Calling startRouter for now. - VirtualRouter result = _myrouterService.startRouter(id); - if (result != null){ - DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(result); - routerResponse.setResponseName(getCommandName()); - this.setResponseObject(routerResponse); + UserContext.current().setEventDetails("Dhcp 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 start router"); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the dhcp element"); } - } -} + } +} diff --git a/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java new file mode 100644 index 00000000000..e31acd8705b --- /dev/null +++ b/api/src/com/cloud/api/commands/ConfigureRedundantVirtualRouterElementCmd.java @@ -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 . + * + */ + +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"); + } + } +} diff --git a/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java new file mode 100644 index 00000000000..487a15421ca --- /dev/null +++ b/api/src/com/cloud/api/commands/ConfigureVirtualRouterElementCmd.java @@ -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 . + * + */ + +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"); + } + } +} diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 25319a7b362..d928806c946 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -211,4 +211,7 @@ public class EventTypes { 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_REMOVE = "PROJECT.ACCOUNT.REMOVE"; + + //Network as a Service + public static final String EVENT_NETWORK_ELEMENT_CONFIGURE = "NETWORK.ELEMENT.CONFIGURE"; } diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index 03935fcc0e0..84259da2a21 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -24,7 +24,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.router.VirtualRouter; import com.cloud.utils.component.PluggableService; -public interface VirtualNetworkApplianceService extends PluggableService{ +public interface VirtualNetworkApplianceService { /** * Starts domain router * @param cmd the command specifying router's id diff --git a/api/src/com/cloud/network/element/DhcpElementService.java b/api/src/com/cloud/network/element/DhcpElementService.java new file mode 100644 index 00000000000..848c79841b5 --- /dev/null +++ b/api/src/com/cloud/network/element/DhcpElementService.java @@ -0,0 +1,7 @@ +package com.cloud.network.element; + +import com.cloud.utils.component.PluggableService; + +public interface DhcpElementService extends PluggableService{ + boolean configure(); +} diff --git a/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java b/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java new file mode 100644 index 00000000000..ec54099fd35 --- /dev/null +++ b/api/src/com/cloud/network/element/RedundantVirtualRouterElementService.java @@ -0,0 +1,7 @@ +package com.cloud.network.element; + +import com.cloud.utils.component.PluggableService; + +public interface RedundantVirtualRouterElementService extends PluggableService{ + boolean configure(); +} diff --git a/api/src/com/cloud/network/element/VirtualRouterElementService.java b/api/src/com/cloud/network/element/VirtualRouterElementService.java new file mode 100644 index 00000000000..705fc8b168c --- /dev/null +++ b/api/src/com/cloud/network/element/VirtualRouterElementService.java @@ -0,0 +1,7 @@ +package com.cloud.network.element; + +import com.cloud.utils.component.PluggableService; + +public interface VirtualRouterElementService extends PluggableService{ + boolean configure(); +} diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 8999e9651e4..b7288f8b5bf 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -107,7 +107,9 @@ - + + + diff --git a/client/tomcatconf/virtualrouter_commands.properties.in b/client/tomcatconf/virtualrouter_commands.properties.in index 55ecb396567..7fc0cdcd809 100644 --- a/client/tomcatconf/virtualrouter_commands.properties.in +++ b/client/tomcatconf/virtualrouter_commands.properties.in @@ -2,4 +2,6 @@ ### Please standardize naming conventions to camel-case (even for acronyms). #### router commands -configureRouter=com.cloud.api.commands.ConfigureRouterCmd;7 \ No newline at end of file +configureDhcpElement=com.cloud.api.commands.ConfigureDhcpElementCmd;7 +configureVirtualRouterElement=com.cloud.api.commands.ConfigureVirtualRouterElementCmd;7 +configureRedundantVirtualRouterElement=com.cloud.api.commands.ConfigureRedundantVirtualRouterElementCmd;7 diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 1806dfebd5d..efc6ba312f1 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -84,6 +84,12 @@ import com.cloud.network.dao.PhysicalNetworkDaoImpl; import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl; import com.cloud.network.dao.RemoteAccessVpnDaoImpl; 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.lb.ElasticLoadBalancerManagerImpl; import com.cloud.network.lb.LoadBalancingRulesManagerImpl; @@ -373,7 +379,9 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com } 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 diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index c1d23b29ba6..c147a839246 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -46,6 +46,7 @@ import com.cloud.network.dao.NetworkDao; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.network.element.DhcpElementService; import com.cloud.offering.NetworkOffering; import com.cloud.org.Cluster; import com.cloud.user.AccountManager; @@ -64,7 +65,7 @@ import com.cloud.vm.dao.UserVmDao; @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 Map> capabilities = setCapabilities(); @@ -246,4 +247,16 @@ public class DhcpElement extends AdapterBase implements PasswordServiceProvider 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"; + } + } diff --git a/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java b/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java index 6f63bd1e627..eb8a5011d48 100644 --- a/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/RedundantVirtualRouterElement.java @@ -19,6 +19,7 @@ import com.cloud.network.Network.Service; import com.cloud.network.Network.Type; import com.cloud.network.NetworkManager; import com.cloud.network.router.VirtualRouter; +import com.cloud.network.element.RedundantVirtualRouterElementService; import com.cloud.offering.NetworkOffering; import com.cloud.uservm.UserVm; import com.cloud.utils.component.Inject; @@ -29,7 +30,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @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); @Inject NetworkManager _networkMgr; @@ -77,4 +78,15 @@ public class RedundantVirtualRouterElement extends VirtualRouterElement { return false; } } + + @Override + public String getPropertiesFile() { + return "virtualrouter_commands.properties"; + } + + @Override + public boolean configure() { + // TODO Auto-generated method stub + return false; + } } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 201ca58f20e..421086c7521 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -51,6 +51,7 @@ import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.StaticNat; +import com.cloud.network.element.VirtualRouterElementService; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.org.Cluster; @@ -69,7 +70,7 @@ import com.cloud.vm.dao.UserVmDao; @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 Map> capabilities = setCapabilities(); @@ -373,4 +374,15 @@ public class VirtualRouterElement extends DhcpElement implements SourceNATServic 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; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index d56ad569fe5..8ed21ce4e43 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2742,10 +2742,4 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian public boolean processTimeout(long agentId, long seq) { return false; } - - @Override - public String getPropertiesFile() { - return "virtualrouter_commands.properties"; - } - }