diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 419d577358a..29bae6b7234 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -360,7 +360,7 @@ public class ApiConstants { public static final String VPC_OFF_ID = "vpcofferingid"; public static final String NETWORK = "network"; public static final String VPC_ID = "vpcid"; - public static final String GATEWAY_ID = "gatewaycid"; + public static final String GATEWAY_ID = "gatewayid"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/BaseAsyncCmd.java b/api/src/com/cloud/api/BaseAsyncCmd.java index 62cc9a0ad8d..2960e4878e9 100644 --- a/api/src/com/cloud/api/BaseAsyncCmd.java +++ b/api/src/com/cloud/api/BaseAsyncCmd.java @@ -27,6 +27,8 @@ import com.cloud.user.UserContext; public abstract class BaseAsyncCmd extends BaseCmd { public static final String ipAddressSyncObject = "ipaddress"; public static final String networkSyncObject = "network"; + public static final String vpcSyncObject = "vpc"; + private AsyncJob job; diff --git a/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java b/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java index 4f0fe038e7e..0299c9ec20f 100644 --- a/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java @@ -15,6 +15,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseAsyncCreateCmd; import com.cloud.api.BaseCmd; import com.cloud.api.IdentityMapper; @@ -22,12 +23,15 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.PrivateGatewayResponse; +import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.PrivateGateway; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; /** @@ -148,11 +152,30 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { @Override public String getEventDescription() { return "creating private gateway"; - } @Override public String getEntityTable() { return "vpc_gateways"; } + + + @Override + public String getSyncObjType() { + return BaseAsyncCmd.vpcSyncObject; + } + + @Override + public Long getSyncObjId() { + Vpc vpc = _vpcService.getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Invalid id is specified for the vpc"); + } + return vpc.getId(); + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.PrivateGateway; + } } diff --git a/api/src/com/cloud/api/commands/CreateStaticRouteCmd.java b/api/src/com/cloud/api/commands/CreateStaticRouteCmd.java new file mode 100644 index 00000000000..805013eaad9 --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateStaticRouteCmd.java @@ -0,0 +1,149 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCmd; +import com.cloud.api.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.StaticRouteResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.vpc.PrivateGateway; +import com.cloud.network.vpc.StaticRoute; +import com.cloud.user.UserContext; + +/** + * @author Alena Prokharchyk + */ + +@Implementation(description="Creates a static route", responseObject=StaticRouteResponse.class) +public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ + private static final String s_name = "createstaticrouteresponse"; + public static final Logger s_logger = Logger.getLogger(CreateStaticRouteCmd.class.getName()); + + @IdentityMapper(entityTableName="vpc_gateways") + @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.LONG, required=true, + description="the gateway id we are creating static route for") + private Long gatewayId; + + @Parameter(name = ApiConstants.CIDR, required = true, type = CommandType.STRING, description = "static route cidr") + private String cidr; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public long getGatewayId() { + return gatewayId; + } + + public String getCidr() { + return cidr; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void create() throws ResourceAllocationException { + try { + StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr()); + setEntityId(result.getId()); + } catch (NetworkRuleConflictException ex) { + s_logger.info("Network rule conflict: " + ex.getMessage()); + s_logger.trace("Network rule conflict: ", ex); + throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); + } + } + + @Override + public String getEntityTable() { + return "static_routes"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_STATIC_ROUTE_CREATE; + } + + @Override + public String getEventDescription() { + return "creating static route"; + } + + @Override + public void execute() { + boolean success = false; + StaticRoute route = _entityMgr.findById(StaticRoute.class, getEntityId()); + try { + UserContext.current().setEventDetails("Static route Id: " + getEntityId()); + success = _vpcService.applyStaticRoutes(route.getVpcId()); + + // State is different after the route is applied, so get new object here + route = _entityMgr.findById(StaticRoute.class, getEntityId()); + StaticRouteResponse routeResponse = new StaticRouteResponse(); + if (route != null) { + routeResponse = _responseGenerator.createStaticRouteResponse(route); + setResponseObject(routeResponse); + } + routeResponse.setResponseName(getCommandName()); + } finally { + if (!success || route == null) { + _vpcService.revokeStaticRoute(getEntityId()); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create static route"); + } + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + PrivateGateway gateway = _vpcService.getVpcPrivateGateway(gatewayId); + if (gateway == null) { + throw new InvalidParameterValueException("Invalid gateway id is specified"); + } + return _vpcService.getVpc(gateway.getVpcId()).getAccountId(); + } + + @Override + public String getSyncObjType() { + return BaseAsyncCmd.vpcSyncObject; + } + + @Override + public Long getSyncObjId() { + PrivateGateway privateGateway = _vpcService.getVpcPrivateGateway(gatewayId); + if (privateGateway == null) { + throw new InvalidParameterValueException("Invalid id is specified for the gateway"); + } + return privateGateway.getVpcId(); + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.StaticRoute; + } +} diff --git a/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java b/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java index 2d3a3e21510..89b941daa02 100644 --- a/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java +++ b/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java @@ -107,7 +107,7 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd { @Override public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.Vpc; + return AsyncJob.Type.PrivateGateway; } } \ No newline at end of file diff --git a/api/src/com/cloud/api/commands/DeleteStaticRouteCmd.java b/api/src/com/cloud/api/commands/DeleteStaticRouteCmd.java new file mode 100644 index 00000000000..a6fc85b798b --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteStaticRouteCmd.java @@ -0,0 +1,124 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +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.IdentityMapper; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.StaticRoute; +import com.cloud.user.UserContext; + +/** + * @author Alena Prokharchyk + */ + +@Implementation(description="Deletes a static route", responseObject=SuccessResponse.class) +public class DeleteStaticRouteCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteStaticRouteCmd.class.getName()); + private static final String s_name = "deletestaticrouteresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="static_routes") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the static route") + private Long id; + + // unexposed parameter needed for events logging + @IdentityMapper(entityTableName="account") + @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false) + private Long ownerId; + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return s_name; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_STATIC_ROUTE_DELETE; + } + + @Override + public String getEventDescription() { + return ("Deleting static route id=" + id); + } + + @Override + public long getEntityOwnerId() { + if (ownerId == null) { + StaticRoute route = _entityMgr.findById(StaticRoute.class, id); + if (route == null) { + throw new InvalidParameterValueException("Unable to find static route by id=" + id); + } else { + ownerId = route.getAccountId(); + } + } + return ownerId; + } + + @Override + public void execute() throws ResourceUnavailableException { + UserContext.current().setEventDetails("Route Id: " + id); + boolean result = _vpcService.revokeStaticRoute(id); + + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete static route"); + } + } + + + @Override + public String getSyncObjType() { + return BaseAsyncCmd.vpcSyncObject; + } + + @Override + public Long getSyncObjId() { + StaticRoute route = _vpcService.getStaticRoute(id); + if (route == null) { + throw new InvalidParameterValueException("Invalid id is specified for the static route"); + } + return route.getVpcId(); + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.StaticRoute; + } +} diff --git a/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java b/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java index 2827f0b2fb8..b43afd52632 100644 --- a/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java +++ b/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java @@ -33,7 +33,6 @@ import com.cloud.network.rules.FirewallRule; @Implementation(description="Lists all firewall rules for an IP address.", responseObject=FirewallResponse.class) public class ListFirewallRulesCmd extends BaseListProjectAndAccountResourcesCmd { public static final Logger s_logger = Logger.getLogger(ListFirewallRulesCmd.class.getName()); - private static final String s_name = "listfirewallrulesresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListStaticRoutesCmd.java b/api/src/com/cloud/api/commands/ListStaticRoutesCmd.java new file mode 100644 index 00000000000..f3e0021bc94 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListStaticRoutesCmd.java @@ -0,0 +1,86 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.api.commands; + +import java.util.ArrayList; +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseListProjectAndAccountResourcesCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.StaticRouteResponse; +import com.cloud.network.vpc.StaticRoute; + +/** + * @author Alena Prokharchyk + */ + +@Implementation(description="Lists all static routes", responseObject=StaticRouteResponse.class) +public class ListStaticRoutesCmd extends BaseListProjectAndAccountResourcesCmd { + private static final String s_name = "liststaticroutesresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="static_routes") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list static route by id") + private Long id; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list static routes by vpc id") + private Long vpcId; + + @IdentityMapper(entityTableName="vpc_gateways") + @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.LONG, description="list static routes by gateway id") + private Long gatewayId; + + public Long getId() { + return id; + } + + public Long getVpcId() { + return vpcId; + } + + public Long getGatewayId() { + return gatewayId; + } + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute(){ + List result = _vpcService.listStaticRoutes(this); + ListResponse response = new ListResponse(); + List routeResponses = new ArrayList(); + + for (StaticRoute route : result) { + StaticRouteResponse ruleData = _responseGenerator.createStaticRouteResponse(route); + routeResponses.add(ruleData); + } + response.setResponses(routeResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + + +} diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java index 12cf2a5c6ba..10279c5219e 100644 --- a/api/src/com/cloud/async/AsyncJob.java +++ b/api/src/com/cloud/async/AsyncJob.java @@ -41,7 +41,8 @@ public interface AsyncJob extends Identity { FirewallRule, Account, User, - Vpc + PrivateGateway, + StaticRoute } Long getId(); diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index f478e4c1c23..5fbb4bfa617 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -274,4 +274,8 @@ public class EventTypes { // Private gateway public static final String EVENT_PRIVATE_GATEWAY_CREATE = "PRIVATE.GATEWAY.CREATE"; public static final String EVENT_PRIVATE_GATEWAY_DELETE = "PRIVATE.GATEWAY.DELETE"; + + // Static routes + public static final String EVENT_STATIC_ROUTE_CREATE = "STATIC.ROUTE.CREATE"; + public static final String EVENT_STATIC_ROUTE_DELETE = "STATIC.ROUTE.DELETE"; } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 4188fb6101d..34bdb511cb8 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -12,12 +12,15 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.element; +import java.util.List; + import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.PrivateGateway; +import com.cloud.network.vpc.StaticRoute; import com.cloud.network.vpc.Vpc; import com.cloud.vm.ReservationContext; @@ -44,5 +47,6 @@ public interface VpcProvider extends NetworkElement{ boolean createPrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException; boolean deletePrivateGateway(PrivateGateway privateGateway) throws ConcurrentOperationException, ResourceUnavailableException; - + + boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/StaticRoute.java b/api/src/com/cloud/network/vpc/StaticRoute.java index fee47ab71de..eb4d7670527 100644 --- a/api/src/com/cloud/network/vpc/StaticRoute.java +++ b/api/src/com/cloud/network/vpc/StaticRoute.java @@ -12,11 +12,13 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.vpc; +import com.cloud.acl.ControlledEntity; + /** * @author Alena Prokharchyk */ -public interface StaticRoute { +public interface StaticRoute extends ControlledEntity{ enum State { Staged, // route been created but has never got through network rule conflict detection. Routes in this state can not be sent to VPC virtual router. Add, // Add means the route has been created and has gone through network rule conflict detection. diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 926ad0f8055..d1faf237ddd 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -17,8 +17,10 @@ import java.util.Map; import java.util.Set; import com.cloud.api.commands.ListPrivateGatewaysCmd; +import com.cloud.api.commands.ListStaticRoutesCmd; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; @@ -178,4 +180,35 @@ public interface VpcService { */ public List listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd); + /** + * @param routeId + * @return + */ + StaticRoute getStaticRoute(long routeId); + + /** + * @param vpcId + * @return + */ + public boolean applyStaticRoutes(long vpcId); + + /** + * @param routeId + * @return TODO + */ + public boolean revokeStaticRoute(long routeId); + + /** + * @param gatewayId + * @param cidr + * @return + */ + public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException; + + /** + * @param listStaticRoutesCmd + * @return + */ + public List listStaticRoutes(ListStaticRoutesCmd cmd); + } diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 64f9415b475..fef9f52b418 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -362,6 +362,6 @@ deleteNetworkACL=com.cloud.api.commands.DeleteNetworkACLCmd;15 listNetworkACLs=com.cloud.api.commands.ListNetworkACLsCmd;15 #### Static route commands -#createStaticRoute=com.cloud.api.commands.CreateStaticRouteCmd;15 -#deleteStaticRoute=com.cloud.api.commands.DeleteStaticRouteCmd;15 -#listStaticRoutes=com.cloud.api.commands.ListStaticRoutesCmd;15 +createStaticRoute=com.cloud.api.commands.CreateStaticRouteCmd;15 +deleteStaticRoute=com.cloud.api.commands.DeleteStaticRouteCmd;15 +listStaticRoutes=com.cloud.api.commands.ListStaticRoutesCmd;15 diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index a4012b735dd..b6a8541df88 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -126,6 +126,7 @@ import com.cloud.network.security.dao.VmRulesetLogDaoImpl; import com.cloud.network.vpc.NetworkACLManagerImpl; import com.cloud.network.vpc.VpcManagerImpl; import com.cloud.network.vpc.Dao.PrivateIpDaoImpl; +import com.cloud.network.vpc.Dao.StaticRouteDaoImpl; import com.cloud.network.vpc.Dao.VpcDaoImpl; import com.cloud.network.vpc.Dao.VpcGatewayDaoImpl; import com.cloud.network.vpc.Dao.VpcOfferingDaoImpl; @@ -342,6 +343,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class); addDao("PrivateIpDao", PrivateIpDaoImpl.class); addDao("VpcGatewayDao", VpcGatewayDaoImpl.class); + addDao("StaticRouteDao", StaticRouteDaoImpl.class); } @Override diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index dcd121865a3..e9a2cf5ac10 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -40,6 +40,7 @@ import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.NetworkACL; +import com.cloud.network.vpc.StaticRoute; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcGateway; import com.cloud.network.vpc.VpcManager; @@ -401,4 +402,13 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc protected VirtualRouterProviderType getVirtualRouterProvider() { return VirtualRouterProviderType.VPCVirtualRouter; } + + /* (non-Javadoc) + * @see com.cloud.network.element.VpcProvider#applyStaticRoutes(com.cloud.network.vpc.Vpc, java.util.List) + */ + @Override + public boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } } diff --git a/server/src/com/cloud/network/vpc/Dao/StaticRouteDao.java b/server/src/com/cloud/network/vpc/Dao/StaticRouteDao.java new file mode 100644 index 00000000000..f4bc80ab39e --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/StaticRouteDao.java @@ -0,0 +1,23 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import com.cloud.network.vpc.StaticRouteVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface StaticRouteDao extends GenericDao{ + +} diff --git a/server/src/com/cloud/network/vpc/Dao/StaticRouteDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/StaticRouteDaoImpl.java new file mode 100644 index 00000000000..b25b9316a12 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/StaticRouteDaoImpl.java @@ -0,0 +1,29 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.vpc.Dao; + +import javax.ejb.Local; + +import com.cloud.network.vpc.StaticRouteVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = StaticRouteDao.class) +@DB(txn = false) +public class StaticRouteDaoImpl extends GenericDaoBase implements StaticRouteDao{ + +} diff --git a/server/src/com/cloud/network/vpc/StaticRouteVO.java b/server/src/com/cloud/network/vpc/StaticRouteVO.java index 3b58c358202..f8b59a0beeb 100644 --- a/server/src/com/cloud/network/vpc/StaticRouteVO.java +++ b/server/src/com/cloud/network/vpc/StaticRouteVO.java @@ -55,8 +55,18 @@ public class StaticRouteVO implements Identity, StaticRoute{ @Column(name="vpc_id") private Long vpcId; + @Column(name = "account_id") + long accountId; + + @Column(name = "domain_id") + long domainId; + @Column(name=GenericDao.CREATED_COLUMN) - Date created; + Date created; + + protected StaticRouteVO(){ + this.uuid = UUID.randomUUID().toString(); + } /** * @param vpcGatewayId @@ -101,4 +111,14 @@ public class StaticRouteVO implements Identity, StaticRoute{ public long getId() { return id; } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public long getDomainId() { + return domainId; + } } \ No newline at end of file diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index d3605a16258..f21ca703a62 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -25,6 +25,7 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import com.cloud.api.commands.ListPrivateGatewaysCmd; +import com.cloud.api.commands.ListStaticRoutesCmd; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenter; @@ -34,6 +35,7 @@ import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; @@ -53,6 +55,7 @@ import com.cloud.network.dao.NetworkDao; import com.cloud.network.element.VpcProvider; import com.cloud.network.vpc.VpcOffering.State; import com.cloud.network.vpc.Dao.PrivateIpDao; +import com.cloud.network.vpc.Dao.StaticRouteDao; import com.cloud.network.vpc.Dao.VpcDao; import com.cloud.network.vpc.Dao.VpcGatewayDao; import com.cloud.network.vpc.Dao.VpcOfferingDao; @@ -111,6 +114,8 @@ public class VpcManagerImpl implements VpcManager, Manager{ VpcGatewayDao _vpcGatewayDao; @Inject PrivateIpDao _privateIpDao; + @Inject + StaticRouteDao _staticRouteDao; private VpcProvider vpcElement = null; @@ -1098,4 +1103,33 @@ public class VpcManagerImpl implements VpcManager, Manager{ return privateGtws; } + + @Override + public StaticRoute getStaticRoute(long routeId) { + return _staticRouteDao.findById(routeId); + } + + @Override + public boolean applyStaticRoutes(long vpcId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean revokeStaticRoute(long routeId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException { + // TODO Auto-generated method stub + return null; + } + + @Override + public List listStaticRoutes(ListStaticRoutesCmd cmd) { + // TODO Auto-generated method stub + return null; + } } diff --git a/setup/apidoc/gen_toc.py b/setup/apidoc/gen_toc.py index 184153a2289..c544e9fadb8 100644 --- a/setup/apidoc/gen_toc.py +++ b/setup/apidoc/gen_toc.py @@ -118,6 +118,7 @@ known_categories = { 'Pool': 'Pool', 'VPC': 'VPC', 'PrivateGateway': 'VPC', + 'StaticRoute': 'VPC', } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index c7f2cefd11f..b03b24bd728 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2242,10 +2242,14 @@ CREATE TABLE `cloud`.`static_routes` ( `cidr` varchar(18) COMMENT 'cidr for the static route', `state` char(32) NOT NULL COMMENT 'current state of this rule', `vpc_id` bigint unsigned COMMENT 'vpc the firewall rule is associated with', + `account_id` bigint unsigned NOT NULL COMMENT 'owner id', + `domain_id` bigint unsigned NOT NULL COMMENT 'domain id', `created` datetime COMMENT 'Date created', PRIMARY KEY (`id`), CONSTRAINT `fk_static_routes__vpc_gateway_id` FOREIGN KEY(`vpc_gateway_id`) REFERENCES `vpc_gateways`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_static_routes__vpc_id` FOREIGN KEY (`vpc_id`) REFERENCES `vpc`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_static_routes__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_static_routes__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, CONSTRAINT `uc_static_routes__uuid` UNIQUE (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;