From 60b52f90dd008e33374fb2eb97b261bf41dbbedb Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 16 May 2012 12:52:32 -0700 Subject: [PATCH] Initial checkin for VPC feature: 1) Added API frameworks for the feature. New commands: * CreateVPCCmd * ListVPCsCmd * DeleteVPCCmd * UpdateVPCCmd * CreateVPCOfferingCmd * UpdateVPCOfferingCmd * DeleteVPCOfferingCmd * ListVPCOfferingsCmd 2) New db tables: * `cloud`.`vpc` * `cloud`.`vpc_offerings` * `cloud`.`vpc_offering_service_map` and corresponding VO/Dao objects. Added vpc_id field to `cloud.`networks` table - not null when network belongs to VPC 3) New Manager and Service interfaces- VpcManager/VpcService 4) Automatically create new VpcOffering (if doesn't exist) on system start 5) New Action events: * VPC.CREATE * VPC.UPDATE * VPC.DELETE * VPC.OFFERING.CREATE * VPC.OFFERING.UPDATE * VPC.OFFERING.DELETE Conflicts: api/src/com/cloud/api/ApiConstants.java client/tomcatconf/commands.properties.in server/src/com/cloud/api/ApiDBUtils.java server/src/com/cloud/network/NetworkManagerImpl.java setup/db/create-schema.sql --- api/src/com/cloud/api/ApiConstants.java | 2 + api/src/com/cloud/api/BaseCmd.java | 3 + api/src/com/cloud/api/ResponseGenerator.java | 16 + .../com/cloud/api/commands/CreateVPCCmd.java | 155 +++++ .../api/commands/CreateVPCOfferingCmd.java | 116 ++++ .../com/cloud/api/commands/DeleteVPCCmd.java | 93 +++ .../api/commands/DeleteVPCOfferingCmd.java | 89 +++ .../api/commands/ListVPCOfferingsCmd.java | 113 ++++ .../com/cloud/api/commands/ListVPCsCmd.java | 148 +++++ .../com/cloud/api/commands/UpdateVPCCmd.java | 106 +++ .../api/commands/UpdateVPCOfferingCmd.java | 107 +++ .../api/response/VpcOfferingResponse.java | 77 +++ .../com/cloud/api/response/VpcResponse.java | 143 ++++ api/src/com/cloud/event/EventTypes.java | 10 + api/src/com/cloud/network/Network.java | 5 + api/src/com/cloud/network/NetworkProfile.java | 7 + api/src/com/cloud/network/NetworkService.java | 2 + .../VirtualNetworkApplianceService.java | 6 +- api/src/com/cloud/network/vpc/Vpc.java | 51 ++ .../com/cloud/network/vpc/VpcOffering.java | 41 ++ api/src/com/cloud/network/vpc/VpcService.java | 105 +++ api/src/com/cloud/storage/StorageService.java | 9 +- client/tomcatconf/commands.properties.in | 19 + server/src/com/cloud/api/ApiDBUtils.java | 16 +- .../src/com/cloud/api/ApiResponseHelper.java | 87 +++ server/src/com/cloud/api/ApiServer.java | 3 +- .../configuration/ConfigurationManager.java | 22 +- .../ConfigurationManagerImpl.java | 34 +- .../DefaultComponentLibrary.java | 18 +- server/src/com/cloud/network/IPAddressVO.java | 1 + .../com/cloud/network/NetworkManagerImpl.java | 27 +- server/src/com/cloud/network/NetworkVO.java | 8 + .../src/com/cloud/network/dao/NetworkDao.java | 6 +- .../com/cloud/network/dao/NetworkDaoImpl.java | 34 +- .../VirtualNetworkApplianceManager.java | 44 +- .../VirtualNetworkApplianceManagerImpl.java | 71 +- .../src/com/cloud/network/vpc/Dao/VpcDao.java | 29 + .../com/cloud/network/vpc/Dao/VpcDaoImpl.java | 56 ++ .../cloud/network/vpc/Dao/VpcOfferingDao.java | 30 + .../network/vpc/Dao/VpcOfferingDaoImpl.java | 68 ++ .../vpc/Dao/VpcOfferingServiceMapDao.java | 34 + .../vpc/Dao/VpcOfferingServiceMapDaoImpl.java | 90 +++ .../src/com/cloud/network/vpc/VpcManager.java | 61 ++ .../com/cloud/network/vpc/VpcManagerImpl.java | 608 ++++++++++++++++++ .../network/vpc/VpcOfferingServiceMapVO.java | 87 +++ .../com/cloud/network/vpc/VpcOfferingVO.java | 143 ++++ server/src/com/cloud/network/vpc/VpcVO.java | 164 +++++ .../dao/NetworkOfferingServiceMapDao.java | 5 + .../dao/NetworkOfferingServiceMapDaoImpl.java | 5 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 2 +- setup/db/create-schema.sql | 53 ++ wscript | 2 +- 52 files changed, 3083 insertions(+), 148 deletions(-) create mode 100644 api/src/com/cloud/api/commands/CreateVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/commands/DeleteVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java create mode 100644 api/src/com/cloud/api/commands/ListVPCsCmd.java create mode 100644 api/src/com/cloud/api/commands/UpdateVPCCmd.java create mode 100644 api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java create mode 100644 api/src/com/cloud/api/response/VpcOfferingResponse.java create mode 100644 api/src/com/cloud/api/response/VpcResponse.java create mode 100644 api/src/com/cloud/network/vpc/Vpc.java create mode 100644 api/src/com/cloud/network/vpc/VpcOffering.java create mode 100644 api/src/com/cloud/network/vpc/VpcService.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java create mode 100644 server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java create mode 100644 server/src/com/cloud/network/vpc/VpcManager.java create mode 100644 server/src/com/cloud/network/vpc/VpcManagerImpl.java create mode 100644 server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java create mode 100644 server/src/com/cloud/network/vpc/VpcOfferingVO.java create mode 100644 server/src/com/cloud/network/vpc/VpcVO.java diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index f7acd5168be..600ea6702d6 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -357,6 +357,8 @@ public class ApiConstants { public static final String VSM_CONFIG_STATE = "vsmconfigstate"; public static final String VSM_DEVICE_STATE = "vsmdevicestate"; public static final String ADD_VSM_FLAG = "addvsmflag"; + public static final String VPC_OFF_ID = "vpcofferingid"; + public static final String NETWORK = "network"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/BaseCmd.java b/api/src/com/cloud/api/BaseCmd.java index a9b6f6074b8..623cdec4939 100755 --- a/api/src/com/cloud/api/BaseCmd.java +++ b/api/src/com/cloud/api/BaseCmd.java @@ -44,6 +44,7 @@ import com.cloud.network.firewall.FirewallService; import com.cloud.network.lb.LoadBalancingRulesService; import com.cloud.network.rules.RulesService; import com.cloud.network.security.SecurityGroupService; +import com.cloud.network.vpc.VpcService; import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.projects.Project; import com.cloud.projects.ProjectService; @@ -128,6 +129,7 @@ public abstract class BaseCmd { public static ResourceLimitService _resourceLimitService; public static IdentityService _identityService; public static StorageNetworkService _storageNetworkService; + public static VpcService _vpcService; static void setComponents(ResponseGenerator generator) { ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); @@ -155,6 +157,7 @@ public abstract class BaseCmd { _resourceLimitService = locator.getManager(ResourceLimitService.class); _identityService = locator.getManager(IdentityService.class); _storageNetworkService = locator.getManager(StorageNetworkService.class); + _vpcService = locator.getManager(VpcService.class); } public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 5f55705981c..5886021eead 100755 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -74,6 +74,8 @@ import com.cloud.api.response.UserVmResponse; import com.cloud.api.response.VirtualRouterProviderResponse; import com.cloud.api.response.VlanIpRangeResponse; import com.cloud.api.response.VolumeResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.api.response.VpcResponse; import com.cloud.api.response.VpnUsersResponse; import com.cloud.api.response.ZoneResponse; import com.cloud.async.AsyncJob; @@ -107,6 +109,8 @@ import com.cloud.network.rules.StickinessPolicy; import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupRules; import com.cloud.network.security.SecurityRule; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcOffering; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; @@ -280,4 +284,16 @@ public interface ResponseGenerator { * @return */ Long getIdentiyId(String tableName, String token); + + /** + * @param offering + * @return + */ + VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering); + + /** + * @param vpc + * @return + */ + VpcResponse createVpcResponse(Vpc vpc); } diff --git a/api/src/com/cloud/api/commands/CreateVPCCmd.java b/api/src/com/cloud/api/commands/CreateVPCCmd.java new file mode 100644 index 00000000000..59efff6cbcd --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateVPCCmd.java @@ -0,0 +1,155 @@ +// 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.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.UserContext; + +/** + * @author Alena Prokharchyk + */ +public class CreateVPCCmd extends BaseAsyncCreateCmd{ + public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName()); + private static final String s_name = "createvpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the VPC. " + + "Must be used with the domainId parameter.") + private String accountName; + + @IdentityMapper(entityTableName="domain") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the VPC. " + + "If used with the account parameter returns the VPC associated with the account for the specified domain.") + private Long domainId; + + @IdentityMapper(entityTableName="data_center") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone") + private Long zoneId; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " + + "the VPC") + private String displayText; + + @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, required=true, description="the cidr of the VPC. All VPC " + + "guest networks' cidrs should be within this CIDR") + private String cidr; + + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") + private Long vpcOffering; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Long getZoneId() { + return zoneId; + } + + public String getVpcName() { + return vpcName; + } + + public String getCidr() { + return cidr; + } + + public String getDisplayText() { + return displayText; + } + + public Long getVpcOffering() { + return vpcOffering; + } + + @Override + public void create() throws ResourceAllocationException { + Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr()); + if (vpc != null) { + this.setEntityId(vpc.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC"); + } + } + + @Override + public void execute() { + //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc) + Vpc vpc = _vpcService.getVpc(this.getEntityId()); + if (vpc != null) { + VpcResponse response = _responseGenerator.createVpcResponse(vpc); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC"); + } + } + + @Override + public String getEntityTable() { + return "vpc"; + } + + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_CREATE; + } + + + @Override + public String getEventDescription() { + return "creating VPC. Id: " + getEntityId(); + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Long accountId = finalyzeAccountId(accountName, domainId, null, true); + if (accountId == null) { + return UserContext.current().getCaller().getId(); + } + + return accountId; + } +} diff --git a/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java b/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java new file mode 100644 index 00000000000..b8411810f6d --- /dev/null +++ b/api/src/com/cloud/api/commands/CreateVPCOfferingCmd.java @@ -0,0 +1,116 @@ +// 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.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseAsyncCreateCmd; +import com.cloud.api.BaseCmd; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{ + public static final Logger s_logger = Logger.getLogger(CreateVPCOfferingCmd.class.getName()); + private static final String _name = "createvpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the vpc offering") + private String vpcOfferingName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " + + "the vpc offering") + private String displayText; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, required=true, collectionType=CommandType.STRING, + description="services supported by the vpc offering") + private List supportedServices; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcOfferingName() { + return vpcOfferingName; + } + + public String getDisplayText() { + return displayText; + } + + public List getSupportedServices() { + return supportedServices; + } + + + @Override + public void create() throws ResourceAllocationException { + VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices()); + if (vpcOff != null) { + this.setEntityId(vpcOff.getId()); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC offering"); + } + } + + @Override + public void execute() { + VpcOffering vpc = _vpcService.getVpcOffering(this.getEntityId()); + if (vpc != null) { + VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC offering"); + } + } + + @Override + public String getEntityTable() { + return "vpc_offerings"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_OFFERING_CREATE; + } + + @Override + public String getEventDescription() { + return "creating VPC offering. Id: " + getEntityId(); + } + + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} diff --git a/api/src/com/cloud/api/commands/DeleteVPCCmd.java b/api/src/com/cloud/api/commands/DeleteVPCCmd.java new file mode 100644 index 00000000000..d4ad1ae3208 --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteVPCCmd.java @@ -0,0 +1,93 @@ +// 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.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class DeleteVPCCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteVPCCmd.class.getName()); + private static final String s_name = "deletevpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the VPC") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting VPC id=" + getId(); + } + + @Override + public void execute() { + boolean result = _vpcService.deleteVpc(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Vpc vpc = _entityMgr.findById(Vpc.class, getId()); + if (vpc != null) { + return vpc.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + +} diff --git a/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java new file mode 100644 index 00000000000..b32b17ba3ab --- /dev/null +++ b/api/src/com/cloud/api/commands/DeleteVPCOfferingCmd.java @@ -0,0 +1,89 @@ +// 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.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class DeleteVPCOfferingCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(DeleteVPCOfferingCmd.class.getName()); + private static final String s_name = "deletevpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") + private Long id; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + boolean result = _vpcService.deleteVpcOffering(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC offering"); + } + } + + @Override + public String getEventType(){ + return EventTypes.EVENT_VPC_OFFERING_DELETE; + } + + + @Override + public String getEventDescription() { + return "Deleting VPC offering id=" + getId(); + } + + +} diff --git a/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java b/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java new file mode 100644 index 00000000000..adb96354105 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListVPCOfferingsCmd.java @@ -0,0 +1,113 @@ +// 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 org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseListCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.network.vpc.VpcOffering; + +/** + * @author Alena Prokharchyk + */ +public class ListVPCOfferingsCmd extends BaseListCmd{ + public static final Logger s_logger = Logger.getLogger(ListVPCOfferingsCmd.class.getName()); + private static final String _name = "listvpcofferingsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC offerings by id") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list VPC offerings by name") + private String vpcOffName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="list VPC offerings by display text") + private String displayText; + + @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if need to list only default " + + "VPC offerings. Default value is false") + private Boolean isDefault; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, + description="list VPC offerings supporting certain services") + private List supportedServices; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPC offerings by state") + private String state; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public String getVpcOffName() { + return vpcOffName; + } + + public String getDisplayText() { + return displayText; + } + + public Boolean getIsDefault() { + return isDefault; + } + + public List getSupportedServices() { + return supportedServices; + } + + public String getState() { + return state; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute(){ + List offerings = _vpcService.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(), + getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal()); + ListResponse response = new ListResponse(); + List offeringResponses = new ArrayList(); + for (VpcOffering offering : offerings) { + VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering); + offeringResponses.add(offeringResponse); + } + + response.setResponses(offeringResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + + + @Override + public String getCommandName() { + return _name; + } + +} diff --git a/api/src/com/cloud/api/commands/ListVPCsCmd.java b/api/src/com/cloud/api/commands/ListVPCsCmd.java new file mode 100644 index 00000000000..bda292ac603 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListVPCsCmd.java @@ -0,0 +1,148 @@ +// 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 org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseListAccountResourcesCmd; +import com.cloud.api.IdentityMapper; +import com.cloud.api.Parameter; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.VpcResponse; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.Vpc; + +/** + * @author Alena Prokharchyk + */ +public class ListVPCsCmd extends BaseListAccountResourcesCmd{ + public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName()); + private static final String s_name = "listvpcsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC by id") + private Long id; + + @IdentityMapper(entityTableName="data_center") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list by zone") + private Long zoneId; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list by name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="List by display text of " + + "the VPC") + private String displayText; + + @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, description="list by cidr of the VPC. All VPC " + + "guest networks' cidrs should be within this CIDR") + private String cidr; + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, description="list by ID of the VPC offering") + private Long VpcOffId; + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " + + "Must be used with the domainId parameter.") + private String accountName; + + @IdentityMapper(entityTableName="domain") + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="list by domain ID associated with the VPC. " + + "If used with the account parameter returns the VPC associated with the account for the specified domain.") + private Long domainId; + + @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, + description="list VPC supporting certain services") + private List supportedServices; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPCs by state") + private String state; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Long getZoneId() { + return zoneId; + } + + public String getVpcName() { + return vpcName; + } + + public String getCidr() { + return cidr; + } + + public String getDisplayText() { + return displayText; + } + + public Long getVpcOffId() { + return VpcOffId; + } + + public Long getId() { + return id; + } + + public List getSupportedServices() { + return supportedServices; + } + + public String getState() { + return state; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + List vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), + getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(), + this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(), this.listAll()); + ListResponse response = new ListResponse(); + List offeringResponses = new ArrayList(); + for (Vpc vpc : vpcs) { + VpcResponse offeringResponse = _responseGenerator.createVpcResponse(vpc); + offeringResponses.add(offeringResponse); + } + + response.setResponses(offeringResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + + @Override + public String getCommandName() { + return s_name; + } + +} diff --git a/api/src/com/cloud/api/commands/UpdateVPCCmd.java b/api/src/com/cloud/api/commands/UpdateVPCCmd.java new file mode 100644 index 00000000000..80babfc1a4d --- /dev/null +++ b/api/src/com/cloud/api/commands/UpdateVPCCmd.java @@ -0,0 +1,106 @@ +// 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.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class UpdateVPCCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName()); + private static final String _name = "updatevpcresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC") + private String vpcName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC") + private String displayText; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcName() { + return vpcName; + } + + public String getDisplayText() { + return displayText; + } + + public Long getId() { + return id; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + Vpc vpc = _entityMgr.findById(Vpc.class, getId()); + if (vpc != null) { + return vpc.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText()); + if (result != null) { + VpcResponse response = _responseGenerator.createVpcResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC"); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating VPC id=" + getId(); + } +} diff --git a/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java new file mode 100644 index 00000000000..a31a8acb29b --- /dev/null +++ b/api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java @@ -0,0 +1,107 @@ +// 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.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.event.EventTypes; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.user.Account; + +/** + * @author Alena Prokharchyk + */ +public class UpdateVPCOfferingCmd extends BaseAsyncCmd{ + public static final Logger s_logger = Logger.getLogger(UpdateVPCOfferingCmd.class.getName()); + private static final String _name = "updatevpcofferingresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc_offerings") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC offering") + private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC offering") + private String vpcOffName; + + @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC offering") + private String displayText; + + @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering") + private String state; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getVpcOfferingName() { + return vpcOffName; + } + + public String getDisplayText() { + return displayText; + } + + public Long getId() { + return id; + } + + public String getState() { + return state; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return _name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + VpcOffering result = _vpcService.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState()); + if (result != null) { + VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC offering"); + } + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_OFFERING_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating VPC offering id=" + getId(); + } +} diff --git a/api/src/com/cloud/api/response/VpcOfferingResponse.java b/api/src/com/cloud/api/response/VpcOfferingResponse.java new file mode 100644 index 00000000000..8fe536181a1 --- /dev/null +++ b/api/src/com/cloud/api/response/VpcOfferingResponse.java @@ -0,0 +1,77 @@ +// 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.response; + +import java.util.Date; +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.cloud.utils.IdentityProxy; +import com.google.gson.annotations.SerializedName; + +/** + * @author Alena Prokharchyk + */ +@SuppressWarnings("unused") +public class VpcOfferingResponse extends BaseResponse{ + @SerializedName("id") @Param(description="the id of the vpc offering") + private final IdentityProxy id = new IdentityProxy("vpc_offerings"); + + @SerializedName(ApiConstants.NAME) @Param(description="the name of the vpc offering") + private String name; + + @SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description="an alternate display text of the vpc offering.") + private String displayText; + + @SerializedName(ApiConstants.CREATED) @Param(description="the date this vpc offering was created") + private Date created; + + @SerializedName(ApiConstants.IS_DEFAULT) @Param(description="true if vpc offering is default, false otherwise") + private Boolean isDefault; + + @SerializedName(ApiConstants.STATE) @Param(description="state of the vpc offering. Can be Disabled/Enabled") + private String state; + + @SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class) + private List services; + + + public void setId(Long id) { + this.id.setValue(id); + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + public void setServices(List services) { + this.services = services; + } + + public void setState(String state) { + this.state = state; + } +} diff --git a/api/src/com/cloud/api/response/VpcResponse.java b/api/src/com/cloud/api/response/VpcResponse.java new file mode 100644 index 00000000000..3ba92808422 --- /dev/null +++ b/api/src/com/cloud/api/response/VpcResponse.java @@ -0,0 +1,143 @@ +// 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.response; + +import java.util.Date; +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.cloud.utils.IdentityProxy; +import com.google.gson.annotations.SerializedName; + +/** + * @author Alena Prokharchyk + */ + +@SuppressWarnings("unused") +public class VpcResponse extends BaseResponse implements ControlledEntityResponse{ + @SerializedName("id") @Param(description="the id of the VPC") + private final IdentityProxy id = new IdentityProxy("vpc"); + + @SerializedName(ApiConstants.NAME) @Param(description="the name of the VPC") + private String name; + + @SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description="an alternate display text of the VPC.") + private String displayText; + + @SerializedName(ApiConstants.STATE) @Param(description="state of the VPC. Can be Disabled/Enabled") + private String state; + + @SerializedName(ApiConstants.ZONE_ID) @Param(description="zone id of the vpc") + private IdentityProxy zoneId = new IdentityProxy("data_center"); + + @SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class) + private List services; + + @SerializedName(ApiConstants.CIDR) @Param(description="the cidr the VPC") + private String cidr; + + @SerializedName(ApiConstants.VPC_OFF_ID) @Param(description="vpc offering id the VPC is created from") + private IdentityProxy vpcOfferingId = new IdentityProxy("vpc_offerings"); + + @SerializedName(ApiConstants.CREATED) @Param(description="the date this VPC was created") + private Date created; + + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner of the VPC") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the VPC") + private IdentityProxy projectId = new IdentityProxy("projects"); + + @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the VPC") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the VPC owner") + private IdentityProxy domainId = new IdentityProxy("domain"); + + @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the owner") + private String domain; + + @SerializedName(ApiConstants.NETWORK) @Param(description="the list of networks belongign to the VPC", responseObject = NetworkResponse.class) + private List networks; + + + public void setId(Long id) { + this.id.setValue(id); + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setServices(List services) { + this.services = services; + } + + public void setState(String state) { + this.state = state; + } + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(Long projectId) { + this.projectId.setValue(projectId); + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(Long domainId) { + this.domainId.setValue(domainId); + } + + @Override + public void setDomainName(String domainName) { + this.domain = domainName; + } + + public void setZoneId(Long zoneId) { + this.zoneId.setValue(zoneId); + } + + public void setCidr(String cidr) { + this.cidr = cidr; + } + + public void setVpcOfferingId(Long vpcOfferingId) { + this.vpcOfferingId.setValue(vpcOfferingId); + } + + public List getNetworks() { + return networks; + } + + public void setNetworks(List networks) { + this.networks = networks; + } +} diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 424ddc90a23..edfaccdb5a4 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -259,4 +259,14 @@ public class EventTypes { public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_ADD = "PHYSICAL.FIREWALL.ADD"; public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_DELETE = "PHYSICAL.FIREWALL.DELETE"; public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_CONFIGURE = "PHYSICAL.FIREWALL.CONFIGURE"; + + // VPC + public static final String EVENT_VPC_CREATE = "VPC.CREATE"; + public static final String EVENT_VPC_UPDATE = "VPC.UPDATE"; + public static final String EVENT_VPC_DELETE = "VPC.DELETE"; + + + public static final String EVENT_VPC_OFFERING_CREATE = "VPC.OFFERING.CREATE"; + public static final String EVENT_VPC_OFFERING_UPDATE = "VPC.OFFERING.UPDATE"; + public static final String EVENT_VPC_OFFERING_DELETE = "VPC.OFFERING.DELETE"; } diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 0443a0f41cc..42e52258759 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -283,4 +283,9 @@ public interface Network extends ControlledEntity { boolean isRestartRequired(); boolean getSpecifyIpRanges(); + + /** + * @return + */ + long getVpcId(); } diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index 4c8708812e5..0c18150bb7e 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -47,6 +47,7 @@ public class NetworkProfile implements Network { private ACLType aclType; private boolean restartRequired; private boolean specifyIpRanges; + private Long vpcId; public NetworkProfile(Network network) { this.id = network.getId(); @@ -71,6 +72,7 @@ public class NetworkProfile implements Network { this.aclType = network.getAclType(); this.restartRequired = network.isRestartRequired(); this.specifyIpRanges = network.getSpecifyIpRanges(); + this.vpcId = network.getVpcId(); } public String getDns1() { @@ -210,4 +212,9 @@ public class NetworkProfile implements Network { return false; } + @Override + public long getVpcId() { + return vpcId; + } + } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 99f8014e6a6..15b71064b40 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -133,5 +133,7 @@ public interface NetworkService { List> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd); List getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner); + + List listNetworksByVpc(long vpcId); } diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index e2cfc6d62b9..4d141bbdc77 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -30,7 +30,8 @@ public interface VirtualNetworkApplianceService { * the command specifying router's id * @return DomainRouter object */ - VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; /** * Reboots domain router @@ -39,7 +40,8 @@ public interface VirtualNetworkApplianceService { * the command specifying router's id * @return router if successful */ - VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException; VirtualRouter upgradeRouter(UpgradeRouterCmd cmd); diff --git a/api/src/com/cloud/network/vpc/Vpc.java b/api/src/com/cloud/network/vpc/Vpc.java new file mode 100644 index 00000000000..88fee8c76b5 --- /dev/null +++ b/api/src/com/cloud/network/vpc/Vpc.java @@ -0,0 +1,51 @@ +// 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; + +import java.util.List; + +import com.cloud.acl.ControlledEntity; +import com.cloud.network.Network; +import com.cloud.network.Network.Service; + + +/** + * @author Alena Prokharchyk + */ +public interface Vpc extends ControlledEntity{ + public enum State { + Enabled, + Disabled + } + + public static final String _supportedProviders = Network.Provider.VirtualRouter.getName(); + + boolean readyToUse(); + + long getId(); + + String getUuid(); + + String getName(); + + long getZoneId(); + + String getCidr(); + + State getState(); + + long getVpcOfferingId(); + + String getDisplayText(); + +} diff --git a/api/src/com/cloud/network/vpc/VpcOffering.java b/api/src/com/cloud/network/vpc/VpcOffering.java new file mode 100644 index 00000000000..5531f55a998 --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcOffering.java @@ -0,0 +1,41 @@ +// 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; + + +/** + * @author Alena Prokharchyk + */ +public interface VpcOffering { + public enum State { + Disabled, + Enabled + } + + public static final String defaultVPCOfferingName = "Default VPC offering"; + + long getId(); + + String getUuid(); + + String getName(); + + String getUniqueName(); + + String getDisplayText(); + + State getState(); + + boolean isDefault(); + +} diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java new file mode 100644 index 00000000000..faf2845006c --- /dev/null +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -0,0 +1,105 @@ +// 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; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.cloud.network.Network; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; + +/** + * @author Alena Prokharchyk + */ +public interface VpcService { + + public VpcOffering getVpcOffering(long vpcOfferingId); + + public VpcOffering createVpcOffering(String name, String displayText, List supportedServices); + + public Vpc getVpc(long vpcId); + + public Vpc createVpc(long zoneId, String name, String cidr, long ownerId); + + public List getVpcNetworks(long vpcId); + + Map> getVpcOffSvcProvidersMap(long vpcOffId); + + List listVpcOfferings(Long id, String name, String displayText, List supportedServicesStr, + Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal); + + /** + * @param offId + * @return + */ + public boolean deleteVpcOffering(long offId); + + /** + * @param vpcOffId + * @param vpcOfferingName + * @param displayText + * @param state + * @return + */ + public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state); + + /** + * @param zoneId + * @param vpcOffId + * @param vpcOwnerId + * @param vpcName + * @param displayText + * @param cidr + * @return + */ + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr); + + /** + * @param vpcId + * @return + */ + public boolean deleteVpc(long vpcId); + + /** + * @param vpcId + * @param vpcName + * @param displayText + * @return + */ + public Vpc updateVpc(long vpcId, String vpcName, String displayText); + + /** + * @param id + * @param vpcName + * @param displayText + * @param supportedServicesStr + * @param cidr + * @param state TODO + * @param accountName + * @param domainId + * @param keyword + * @param startIndex + * @param pageSizeVal + * @param zoneId TODO + * @param isRecursive TODO + * @param listAll TODO + * @param vpc + * @return + */ + public List listVpcs(Long id, String vpcName, String displayText, + List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, + String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll); + +} diff --git a/api/src/com/cloud/storage/StorageService.java b/api/src/com/cloud/storage/StorageService.java index e8809a3633d..4fb3b55f057 100644 --- a/api/src/com/cloud/storage/StorageService.java +++ b/api/src/com/cloud/storage/StorageService.java @@ -47,7 +47,8 @@ public interface StorageService{ * @throws ResourceUnavailableException * TODO */ - StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException; + StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, + UnknownHostException, ResourceUnavailableException; /** * Creates the database object for a volume based on the given criteria @@ -92,7 +93,8 @@ public interface StorageService{ * @throws InsufficientCapacityException * TODO */ - public StoragePool preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException, InsufficientCapacityException; + public StoragePool preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException, + InsufficientCapacityException; /** * Complete maintenance for primary storage @@ -103,7 +105,8 @@ public interface StorageService{ * @throws ResourceUnavailableException * TODO */ - public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException; + public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) + throws ResourceUnavailableException; public StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException; diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index a939eb7751a..5a1ffcd440c 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -332,3 +332,22 @@ updateStorageNetworkIpRange=com.cloud.api.commands.UpdateStorageNetworkIpRangeCm addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1 listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1 deleteNetworkDevice=com.cloud.api.commands.DeleteNetworkDeviceCmd;1 + +### Network Devices commands +addNetworkDevice=com.cloud.api.commands.AddNetworkDeviceCmd;1 +listNetworkDevice=com.cloud.api.commands.ListNetworkDeviceCmd;1 +deleteNetworkDevice=com.cloud.api.commands.DeleteNetworkDeviceCmd;1 + + +### VPC commands +createVPC=com.cloud.api.commands.CreateVPCCmd;15 +listVPCs=com.cloud.api.commands.ListVPCsCmd;15 +deleteVPC=com.cloud.api.commands.DeleteVPCCmd;15 +updateVPC=com.cloud.api.commands.UpdateVPCCmd;15 + + +#### VPC offering commands +createVPCOffering=com.cloud.api.commands.CreateVPCOfferingCmd;1 +updateVPCOffering=com.cloud.api.commands.UpdateVPCOfferingCmd;1 +deleteVPCOffering=com.cloud.api.commands.DeleteVPCOfferingCmd;1 +listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15 diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index f4948860183..855bd74f06f 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -49,6 +49,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; import com.cloud.network.LoadBalancerVO; +import com.cloud.network.Network; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -68,6 +69,7 @@ import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.SecurityGroupVO; import com.cloud.network.security.dao.SecurityGroupDao; +import com.cloud.network.vpc.VpcManager; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -84,6 +86,7 @@ import com.cloud.storage.GuestOS; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; +import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.StorageStats; @@ -91,9 +94,8 @@ import com.cloud.storage.UploadVO; import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateSwiftVO; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.VolumeHostVO; -import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Volume.Type; +import com.cloud.storage.VolumeHostVO; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSCategoryDao; @@ -188,6 +190,7 @@ public class ApiDBUtils { private static AccountDetailsDao _accountDetailsDao; private static NetworkDomainDao _networkDomainDao; private static HighAvailabilityManager _haMgr; + private static VpcManager _vpcMgr; static { _ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name); @@ -241,6 +244,7 @@ public class ApiDBUtils { _accountDetailsDao = locator.getDao(AccountDetailsDao.class); _networkDomainDao = locator.getDao(NetworkDomainDao.class); _haMgr = locator.getManager(HighAvailabilityManager.class); + _vpcMgr = locator.getManager(VpcManager.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -748,4 +752,12 @@ public class ApiDBUtils { public static String getHaTag() { return _haMgr.getHaTag(); } + + public static Map> listVpcOffServices(long vpcOffId) { + return _vpcMgr.getVpcOffSvcProvidersMap(vpcOffId); + } + + public static List listVpcNetworks(long vpcId) { + return _networkMgr.listNetworksByVpc(vpcId); + } } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index eb64d98512c..869370d54b7 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -91,6 +91,8 @@ import com.cloud.api.response.UserVmResponse; import com.cloud.api.response.VirtualRouterProviderResponse; import com.cloud.api.response.VlanIpRangeResponse; import com.cloud.api.response.VolumeResponse; +import com.cloud.api.response.VpcOfferingResponse; +import com.cloud.api.response.VpcResponse; import com.cloud.api.response.VpnUsersResponse; import com.cloud.api.response.ZoneResponse; import com.cloud.async.AsyncJob; @@ -143,6 +145,8 @@ import com.cloud.network.security.SecurityGroupRules; import com.cloud.network.security.SecurityGroupVO; import com.cloud.network.security.SecurityRule; import com.cloud.network.security.SecurityRule.SecurityRuleType; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcOffering; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; @@ -3398,5 +3402,88 @@ public class ApiResponseHelper implements ResponseGenerator { public Long getIdentiyId(String tableName, String token) { return ApiDispatcher.getIdentiyId(tableName, token); } + + + @Override + public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) { + VpcOfferingResponse response = new VpcOfferingResponse(); + response.setId(offering.getId()); + response.setName(offering.getName()); + response.setDisplayText(offering.getDisplayText()); + response.setIsDefault(offering.isDefault()); + response.setState(offering.getState().name()); + + Map> serviceProviderMap = ApiDBUtils.listVpcOffServices(offering.getId()); + List serviceResponses = new ArrayList(); + for (Service service : serviceProviderMap.keySet()) { + ServiceResponse svcRsp = new ServiceResponse(); + // skip gateway service + if (service == Service.Gateway) { + continue; + } + svcRsp.setName(service.getName()); + List providers = new ArrayList(); + for (Provider provider : serviceProviderMap.get(service)) { + if (provider != null) { + ProviderResponse providerRsp = new ProviderResponse(); + providerRsp.setName(provider.getName()); + providers.add(providerRsp); + } + } + svcRsp.setProviders(providers); + + serviceResponses.add(svcRsp); + } + response.setServices(serviceResponses); + response.setObjectName("vpcoffering"); + return response; + } + + + @Override + public VpcResponse createVpcResponse(Vpc vpc) { + VpcResponse response = new VpcResponse(); + response.setId(vpc.getId()); + response.setName(vpc.getName()); + response.setDisplayText(vpc.getDisplayText()); + response.setState(vpc.getState().name()); + response.setVpcOfferingId(vpc.getVpcOfferingId()); + response.setCidr(vpc.getCidr()); + response.setZoneId(vpc.getZoneId()); + + Map> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId()); + List serviceResponses = new ArrayList(); + for (Service service : serviceProviderMap.keySet()) { + ServiceResponse svcRsp = new ServiceResponse(); + // skip gateway service + if (service == Service.Gateway) { + continue; + } + svcRsp.setName(service.getName()); + List providers = new ArrayList(); + for (Provider provider : serviceProviderMap.get(service)) { + if (provider != null) { + ProviderResponse providerRsp = new ProviderResponse(); + providerRsp.setName(provider.getName()); + providers.add(providerRsp); + } + } + svcRsp.setProviders(providers); + + serviceResponses.add(svcRsp); + } + + List networkResponses = new ArrayList(); + List networks = ApiDBUtils.listVpcNetworks(vpc.getId()); + for (Network network : networks) { + NetworkResponse ntwkRsp = createNetworkResponse(network); + networkResponses.add(ntwkRsp); + } + + response.setNetworks(networkResponses); + response.setServices(serviceResponses); + response.setObjectName("vpcoffering"); + return response; + } } diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 83133e4952f..48e2bdd13d7 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -499,7 +499,8 @@ public class ApiServer implements HttpRequestHandler { asyncCmd.setStartEventId(startEventId); // save the scheduled event - Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), + Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, + asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), startEventId); if (startEventId == 0) { // There was no create event before, set current event id as start eventId diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 85cdf34cf24..29de7bf4ba2 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -164,11 +164,12 @@ public interface ConfigurationManager extends ConfigurationService, Manager { /** * Creates a new network offering - * * @param name * @param displayText * @param trafficType * @param tags + * @param specifyVlan + * ; * @param networkRate * TODO * @param serviceProviderMap @@ -180,19 +181,18 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @param systemOnly * TODO * @param serviceOfferingId + * @param conserveMode + * ; * @param specifyIpRanges * TODO * @param id - * @param specifyVlan - * ; - * @param conserveMode - * ; + * * @return network offering object */ - NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, - Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, - Map> serviceCapabilityMap, boolean specifyIpRanges); + NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map> serviceProviderMap, + boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map> serviceCapabilityMap, + boolean specifyIpRanges); Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; @@ -226,4 +226,10 @@ public interface ConfigurationManager extends ConfigurationService, Manager { AllocationState findClusterAllocationState(ClusterVO cluster); + /** + * @param tags + * @return + */ + String cleanupTags(String tags); + } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index d4891086ffe..8c241a6cbda 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -138,8 +138,8 @@ import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.swift.SwiftManager; import com.cloud.test.IPRangeConfig; import com.cloud.user.Account; -import com.cloud.user.AccountVO; import com.cloud.user.AccountManager; +import com.cloud.user.AccountVO; import com.cloud.user.ResourceLimitService; import com.cloud.user.User; import com.cloud.user.UserContext; @@ -2531,7 +2531,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return tags; } - private String cleanupTags(String tags) { + @Override + public String cleanupTags(String tags) { if (tags != null) { String[] tokens = tags.split(","); StringBuilder t = new StringBuilder(); @@ -2863,7 +2864,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering") public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) { - Long userId = UserContext.current().getCallerUserId(); String name = cmd.getNetworkOfferingName(); String displayText = cmd.getDisplayText(); String tags = cmd.getTags(); @@ -2970,7 +2970,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Set providers = new HashSet(); // in Acton, don't allow to specify more than 1 provider per service if (svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) { - throw new InvalidParameterValueException("In the current release only one provider can be specified for the service"); + throw new InvalidParameterValueException("In the current release only one provider can be " + + "specified for the service"); } for (String prvNameStr : svcPrv.get(serviceStr)) { // check if provider is supported @@ -3001,7 +3002,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } serviceProviderMap.put(service, providers); } else { - throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network offering, can't add a provider to it"); + throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + + "offering, can't add a provider to it"); } } } @@ -3035,8 +3037,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap); serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap); - // if Firewall service is missing, and Juniper is a provider for any other service or VR is StaticNat/PF provider, add Firewall - // service/provider combination + // if Firewall service is missing, add Firewall service/provider combination if (firewallProvider != null) { s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName()); Set firewallProviderSet = new HashSet(); @@ -3044,8 +3045,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura serviceProviderMap.put(Service.Firewall, firewallProviderSet); } - return createNetworkOffering(userId, name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, - false, serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges); + return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, + serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges); } void validateLoadBalancerServiceCapabilities(Map lbServiceCapabilityMap) { @@ -3125,9 +3126,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override @DB - public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, - Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, - Long serviceOfferingId, boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges) { + public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, + Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, + boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges) { String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); @@ -3189,13 +3190,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if ((sourceNatServiceCapabilityMap != null) && (!sourceNatServiceCapabilityMap.isEmpty())) { String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes); if (sourceNatType != null) { - _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType); + _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + Capability.SupportedSourceNatTypes, sourceNatType); sharedSourceNat = sourceNatType.contains("perzone"); } String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter); if (param != null) { - _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param); + _networkMgr.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, + Capability.RedundantRouter, param); redundantRouter = param.contains("true"); } } @@ -3209,7 +3212,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, + NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, + networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges); if (serviceOfferingId != null) { diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 150d7af89b6..9bbcb6ea3ce 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -45,6 +45,7 @@ import com.cloud.dao.EntityManagerImpl; import com.cloud.dc.ClusterDetailsDaoImpl; import com.cloud.dc.dao.AccountVlanMapDaoImpl; import com.cloud.dc.dao.ClusterDaoImpl; +import com.cloud.dc.dao.ClusterVSMMapDaoImpl; import com.cloud.dc.dao.DataCenterDaoImpl; import com.cloud.dc.dao.DataCenterIpAddressDaoImpl; import com.cloud.dc.dao.DcDetailsDaoImpl; @@ -70,11 +71,9 @@ import com.cloud.maint.dao.AgentUpgradeDaoImpl; import com.cloud.network.ExternalLoadBalancerUsageManagerImpl; import com.cloud.network.NetworkManagerImpl; import com.cloud.network.StorageNetworkManagerImpl; +import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; import com.cloud.network.dao.ExternalFirewallDeviceDaoImpl; import com.cloud.network.dao.ExternalLoadBalancerDeviceDaoImpl; -import com.cloud.network.dao.CiscoNexusVSMDeviceDaoImpl; -import com.cloud.dc.dao.ClusterVSMMapDaoImpl; -import com.cloud.network.dao.PortProfileDaoImpl; import com.cloud.network.dao.FirewallRulesCidrsDaoImpl; import com.cloud.network.dao.FirewallRulesDaoImpl; import com.cloud.network.dao.IPAddressDaoImpl; @@ -92,16 +91,17 @@ import com.cloud.network.dao.NetworkServiceMapDaoImpl; import com.cloud.network.dao.PhysicalNetworkDaoImpl; import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl; import com.cloud.network.dao.PhysicalNetworkTrafficTypeDaoImpl; +import com.cloud.network.dao.PortProfileDaoImpl; import com.cloud.network.dao.RemoteAccessVpnDaoImpl; import com.cloud.network.dao.VirtualRouterProviderDaoImpl; import com.cloud.network.dao.VpnUserDaoImpl; +import com.cloud.network.element.CiscoNexusVSMElement; +import com.cloud.network.element.CiscoNexusVSMElementService; import com.cloud.network.element.F5ExternalLoadBalancerElement; import com.cloud.network.element.F5ExternalLoadBalancerElementService; import com.cloud.network.element.JuniperSRXExternalFirewallElement; import com.cloud.network.element.JuniperSRXFirewallElementService; import com.cloud.network.element.NetscalerElement; -import com.cloud.network.element.CiscoNexusVSMElement; -import com.cloud.network.element.CiscoNexusVSMElementService; import com.cloud.network.element.NetscalerLoadBalancerElementService; import com.cloud.network.element.VirtualRouterElement; import com.cloud.network.element.VirtualRouterElementService; @@ -122,6 +122,10 @@ import com.cloud.network.security.dao.SecurityGroupRulesDaoImpl; import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl; import com.cloud.network.security.dao.SecurityGroupWorkDaoImpl; import com.cloud.network.security.dao.VmRulesetLogDaoImpl; +import com.cloud.network.vpc.VpcManagerImpl; +import com.cloud.network.vpc.Dao.VpcDaoImpl; +import com.cloud.network.vpc.Dao.VpcOfferingDaoImpl; +import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDaoImpl; import com.cloud.network.vpn.RemoteAccessVpnManagerImpl; import com.cloud.offerings.dao.NetworkOfferingDaoImpl; import com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl; @@ -329,6 +333,9 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("NetworkServiceMapDao", NetworkServiceMapDaoImpl.class); addDao("StorageNetworkIpAddressDao", StorageNetworkIpAddressDaoImpl.class); addDao("StorageNetworkIpRangeDao", StorageNetworkIpRangeDaoImpl.class); + addDao("VpcDao", VpcDaoImpl.class); + addDao("VpcOfferingDao", VpcOfferingDaoImpl.class); + addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class); } @Override @@ -385,6 +392,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addManager("StorageNetworkManager", StorageNetworkManagerImpl.class); addManager("ExternalLoadBalancerUsageManager", ExternalLoadBalancerUsageManagerImpl.class); addManager("HA Manager", HighAvailabilityManagerImpl.class); + addManager("VPC Manager", VpcManagerImpl.class); } @Override diff --git a/server/src/com/cloud/network/IPAddressVO.java b/server/src/com/cloud/network/IPAddressVO.java index 4f9114254d2..fb05d2bc612 100644 --- a/server/src/com/cloud/network/IPAddressVO.java +++ b/server/src/com/cloud/network/IPAddressVO.java @@ -28,6 +28,7 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import com.cloud.api.Identity; +import com.cloud.network.IpAddress; import com.cloud.utils.net.Ip; /** diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 60c98b86d96..7eae799203e 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1251,29 +1251,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO offering = null; if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, - null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, + true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, - null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, + defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", - TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, + null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, - true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, + Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -1301,8 +1301,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag serviceCapabilityMap.put(Service.StaticNat, eip); if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(Account.ACCOUNT_ID_SYSTEM, NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, - true, Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, + Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true); offering.setState(NetworkOffering.State.Enabled); offering.setDedicatedLB(false); _networkOfferingDao.update(offering.getId(), offering); @@ -1929,7 +1929,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); } - + for (NetworkElement element : _networkElements) { if (s_logger.isDebugEnabled()) { s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); @@ -6574,4 +6574,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networkList.get(0); } + + @Override + public List listNetworksByVpc(long vpcId) { + return _networksDao.listByVpc(vpcId); + } } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 4dae61a7871..f4121322825 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -75,6 +75,9 @@ public class NetworkVO implements Network, Identity { @Column(name="network_offering_id") long networkOfferingId; + + @Column(name="vpc_id") + long vpcId; @Column(name="physical_network_id") Long physicalNetworkId; @@ -473,4 +476,9 @@ public class NetworkVO implements Network, Identity { public boolean getSpecifyIpRanges() { return specifyIpRanges; } + + @Override + public long getVpcId() { + return vpcId; + } } diff --git a/server/src/com/cloud/network/dao/NetworkDao.java b/server/src/com/cloud/network/dao/NetworkDao.java index df74f238409..299f5ee8a26 100644 --- a/server/src/com/cloud/network/dao/NetworkDao.java +++ b/server/src/com/cloud/network/dao/NetworkDao.java @@ -70,8 +70,6 @@ public interface NetworkDao extends GenericDao { void addDomainToNetwork(long networkId, long domainId, Boolean subdomainAccess); - Long getNetworkCountByOfferingId(long offeringId); - List listByPhysicalNetwork(long physicalNetworkId); List listSecurityGroupEnabledNetworks(); @@ -95,5 +93,9 @@ public interface NetworkDao extends GenericDao { long countNetworksUserCanCreate(long ownerId); List listSourceNATEnabledNetworks(long accountId, long dataCenterId, GuestType type); + + int getNetworkCountByVpcId(long vpcId); + + List listByVpc(long vpcId); } diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java index f907ce8116b..8fa107c8710 100644 --- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -56,7 +56,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N final SearchBuilder AccountNetworkSearch; final SearchBuilder ZoneBroadcastUriSearch; final SearchBuilder ZoneSecurityGroupSearch; - final GenericSearchBuilder CountByOfferingId; + final GenericSearchBuilder CountBy; final SearchBuilder PhysicalNetworkSearch; final SearchBuilder SecurityGroupSearch; final GenericSearchBuilder NetworksRegularUserCanCreateSearch; @@ -88,6 +88,7 @@ public class NetworkDaoImpl extends GenericDaoBase implements N AllFieldsSearch.and("related", AllFieldsSearch.entity().getRelated(), Op.EQ); AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), Op.EQ); AllFieldsSearch.and("physicalNetwork", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); + AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.done(); AccountSearch = createSearchBuilder(); @@ -126,11 +127,12 @@ public class NetworkDaoImpl extends GenericDaoBase implements N ZoneSecurityGroupSearch.join("services", join1, ZoneSecurityGroupSearch.entity().getId(), join1.entity().getNetworkId(), JoinBuilder.JoinType.INNER); ZoneSecurityGroupSearch.done(); - CountByOfferingId = createSearchBuilder(Long.class); - CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId()); - CountByOfferingId.and("offeringId", CountByOfferingId.entity().getNetworkOfferingId(), Op.EQ); - CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL); - CountByOfferingId.done(); + CountBy = createSearchBuilder(Integer.class); + CountBy.select(null, Func.COUNT, CountBy.entity().getId()); + CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ); + CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ); + CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); + CountBy.done(); PhysicalNetworkSearch = createSearchBuilder(); PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ); @@ -363,14 +365,16 @@ public class NetworkDaoImpl extends GenericDaoBase implements N NetworkDomainVO domain = new NetworkDomainVO(networkId, domainId, subdomainAccess); _domainsDao.persist(domain); } - + + @Override - public Long getNetworkCountByOfferingId(long offeringId) { - SearchCriteria sc = CountByOfferingId.create(); - sc.setParameters("offeringId", offeringId); - List results = customSearch(sc, null); + public int getNetworkCountByVpcId(long vpcId) { + SearchCriteria sc = CountBy.create(); + sc.setParameters("vpcId", vpcId); + List results = customSearch(sc, null); return results.get(0); } + @Override public List listSecurityGroupEnabledNetworks() { @@ -458,5 +462,13 @@ public class NetworkDaoImpl extends GenericDaoBase implements N sc.setJoinParameters("services", "service", Service.SourceNat.getName()); return listBy(sc); } + + @Override + public List listByVpc(long vpcId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcId", vpcId); + + return listBy(sc, null); + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 052cd0f7389..5c40161ee32 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -24,7 +24,6 @@ import com.cloud.network.PublicIpAddress; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VirtualNetworkApplianceService; import com.cloud.network.VpnUser; -import com.cloud.network.Network.Provider; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; import com.cloud.user.Account; @@ -33,7 +32,6 @@ import com.cloud.uservm.UserVm; import com.cloud.utils.component.Manager; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; -import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile; /** @@ -58,35 +56,41 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA * @param routers TODO * */ - boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; - - boolean getRouterStatistics(long vmId, Map netStats, Map diskStats); - - List getRouters(long accountId, long zoneId); + boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + List routers) throws ResourceUnavailableException; + + List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + Map params, boolean isRedundant) throws InsufficientCapacityException, + ResourceUnavailableException, ConcurrentOperationException; - List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException; + boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException; - boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; - - boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; + boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + throws ResourceUnavailableException; - boolean associateIP (Network network, final List ipAddress, List routers) throws ResourceUnavailableException; + boolean associateIP (Network network, final List ipAddress, + List routers) throws ResourceUnavailableException; - boolean applyFirewallRules(Network network, final List rules, List routers) throws ResourceUnavailableException; + boolean applyFirewallRules(Network network, final List rules, + List routers) throws ResourceUnavailableException; List getRoutersForNetwork(long networkId); - String[] applyVpnUsers(Network network, List users, List routers) throws ResourceUnavailableException; + String[] applyVpnUsers(Network network, List users, List routers) + throws ResourceUnavailableException; - VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException; + VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) + throws ConcurrentOperationException, ResourceUnavailableException; String getDnsBasicZoneUpdate(); - boolean applyStaticNats(Network network, final List rules, List routers) throws ResourceUnavailableException; + boolean applyStaticNats(Network network, final List rules, List routers) + throws ResourceUnavailableException; - boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; + boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + List routers) throws ResourceUnavailableException; - boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; - - long getDefaultVirtualRouterServiceOfferingId(); + boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + List routers) throws ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index d044d4f3525..a35e1775e88 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -95,7 +95,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; -import com.cloud.event.dao.EventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConnectionException; @@ -132,7 +131,6 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.VpnUser; import com.cloud.network.VpnUserVO; import com.cloud.network.addr.PublicIp; -import com.cloud.network.dao.FirewallRulesCidrsDao; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; @@ -163,13 +161,11 @@ import com.cloud.resource.ResourceManager; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.GuestOSVO; -import com.cloud.storage.StorageManager; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume.Type; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VMTemplateDao; -import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -214,13 +210,13 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; -import com.cloud.vm.dao.VMInstanceDao; /** * VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances available in the Cloud Stack. */ @Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class }) -public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, VirtualMachineGuru, Listener { +public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, + VirtualMachineGuru, Listener { private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class); String _name; @@ -245,24 +241,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject UserStatisticsDao _userStatsDao = null; @Inject - VolumeDao _volsDao = null; - @Inject HostDao _hostDao = null; @Inject - EventDao _eventDao = null; - @Inject ConfigurationDao _configDao; @Inject HostPodDao _podDao = null; @Inject - VMTemplateHostDao _vmTemplateHostDao = null; - @Inject UserStatsLogDao _userStatsLogDao = null; @Inject AgentManager _agentMgr; @Inject - StorageManager _storageMgr; - @Inject AlertManager _alertMgr; @Inject AccountManager _accountMgr; @@ -273,8 +261,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject UserVmDao _userVmDao; @Inject - FirewallRulesDao _firewallRulesDao; - @Inject UserStatisticsDao _statsDao = null; @Inject NetworkOfferingDao _networkOfferingDao = null; @@ -299,14 +285,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Inject RemoteAccessVpnDao _vpnDao; @Inject - VMInstanceDao _instanceDao; - @Inject NicDao _nicDao; @Inject VolumeDao _volumeDao = null; @Inject - FirewallRulesCidrsDao _firewallCidrsDao; - @Inject UserVmDetailsDao _vmDetailsDao; @Inject ClusterDao _clusterDao; @@ -343,12 +325,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian ScheduledExecutorService _networkStatsUpdateExecutor; Account _systemAcct; - - @Override - public List getRouters(long accountId, long dataCenterId) { - return _routerDao.findBy(accountId, dataCenterId); - } - + @Override public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) { ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey); @@ -542,26 +519,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - @Override - public boolean getRouterStatistics(final long vmId, final Map netStats, final Map diskStats) { - final DomainRouterVO router = _routerDao.findById(vmId); - - if (router == null || router.getState() != State.Running || router.getHostId() == null) { - return true; - } - - /* - * final GetVmStatsCommand cmd = new GetVmStatsCommand(router, router.getInstanceName()); final Answer answer = - * _agentMgr.easySend(router.getHostId(), cmd); if (answer == null) { return false; } - * - * final GetVmStatsAnswer stats = (GetVmStatsAnswer)answer; - * - * netStats.putAll(stats.getNetworkStats()); diskStats.putAll(stats.getDiskStats()); - */ - - return true; - } - @Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true) public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Account caller = UserContext.current().getCaller(); @@ -908,10 +865,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Exception while trying to acquire network stats lock", e); } finally { scanLock.releaseRef(); - } - + } } - } @@ -1110,9 +1065,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - public static boolean isAdmin(short accountType) { - return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)); - } + private final int DEFAULT_PRIORITY = 100; private final int DEFAULT_DELTA = 2; @@ -1477,7 +1430,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, + public List deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, + Map params, boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); @@ -1489,7 +1443,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || + guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork; assert guestNetwork.getTrafficType() == TrafficType.Guest; @@ -2942,14 +2897,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - @Override - public long getDefaultVirtualRouterServiceOfferingId() { - if (_offering != null) { - return _offering.getId(); - } - return 0; - } - private String getRouterControlIp(long routerId) { String routerControlIpAddress = null; List nics = _nicDao.listByVmId(routerId); diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDao.java b/server/src/com/cloud/network/vpc/Dao/VpcDao.java new file mode 100644 index 00000000000..e95b6674de1 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcDao.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 com.cloud.network.vpc.VpcVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcDao extends GenericDao{ + + /** + * @param offId + * @return + */ + int getVpcCountByOfferingId(long offId); + +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java new file mode 100644 index 00000000000..4e32541e39f --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcDaoImpl.java @@ -0,0 +1,56 @@ +// 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 java.util.List; + +import javax.ejb.Local; + +import com.cloud.network.vpc.VpcVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = VpcDao.class) +@DB(txn = false) +public class VpcDaoImpl extends GenericDaoBase implements VpcDao{ + final GenericSearchBuilder CountByOfferingId; + + + protected VpcDaoImpl() { + super(); + + CountByOfferingId = createSearchBuilder(Integer.class); + CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId()); + CountByOfferingId.and("offeringId", CountByOfferingId.entity().getVpcOfferingId(), Op.EQ); + CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL); + CountByOfferingId.done(); + } + + + @Override + public int getVpcCountByOfferingId(long offId) { + SearchCriteria sc = CountByOfferingId.create(); + sc.setParameters("offeringId", offId); + List results = customSearch(sc, null); + return results.get(0); + } +} + diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java new file mode 100644 index 00000000000..b5c8b47933d --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDao.java @@ -0,0 +1,30 @@ +// 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.VpcOfferingVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcOfferingDao extends GenericDao{ + /** + * Returns the VPC offering that matches the unique name. + * + * @param uniqueName + * name + * @return VpcOfferingVO + */ + VpcOfferingVO findByUniqueName(String uniqueName); +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java new file mode 100644 index 00000000000..0a152344c69 --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingDaoImpl.java @@ -0,0 +1,68 @@ +// 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.VpcOfferingVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; + +/** + * @author Alena Prokharchyk + */ +@Local(value = VpcOfferingDao.class) +@DB(txn = false) +public class VpcOfferingDaoImpl extends GenericDaoBase implements VpcOfferingDao{ + final SearchBuilder AllFieldsSearch; + + + protected VpcOfferingDaoImpl() { + super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ); + AllFieldsSearch.and("uName", AllFieldsSearch.entity().getUniqueName(), Op.EQ); + AllFieldsSearch.and("displayText", AllFieldsSearch.entity().getDisplayText(), Op.EQ); + AllFieldsSearch.done(); + + } + + @Override + @DB + public boolean remove(Long vpcOffId) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + VpcOfferingVO offering = findById(vpcOffId); + offering.setUniqueName(null); + update(vpcOffId, offering); + boolean result = super.remove(vpcOffId); + txn.commit(); + return result; + } + + + @Override + public VpcOfferingVO findByUniqueName(String uniqueName) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("uName", uniqueName); + + return findOneBy(sc); + } +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java new file mode 100644 index 00000000000..74246aef67e --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDao.java @@ -0,0 +1,34 @@ +// 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 java.util.List; + +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOfferingServiceMapVO; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ +public interface VpcOfferingServiceMapDao extends GenericDao{ + + List listByVpcOffId(long vpcOffId); + + /** + * @param networkOfferingId + * @param services + * @return + */ + boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service[] services); +} diff --git a/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java new file mode 100644 index 00000000000..cbbf1d5e43e --- /dev/null +++ b/server/src/com/cloud/network/vpc/Dao/VpcOfferingServiceMapDaoImpl.java @@ -0,0 +1,90 @@ +// 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 java.util.List; + +import javax.ejb.Local; + +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOfferingServiceMapVO; +import com.cloud.offerings.NetworkOfferingServiceMapVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +/** + * @author Alena Prokharchyk + */ +@Local(value = VpcOfferingServiceMapDao.class) +@DB(txn = false) +public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase implements VpcOfferingServiceMapDao{ + final SearchBuilder AllFieldsSearch; + final SearchBuilder MultipleServicesSearch; + + + protected VpcOfferingServiceMapDaoImpl() { + super(); + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("vpcOffId", AllFieldsSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ); + AllFieldsSearch.done(); + + + MultipleServicesSearch = createSearchBuilder(); + MultipleServicesSearch.and("vpcOffId", MultipleServicesSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN); + MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ); + MultipleServicesSearch.done(); + } + + @Override + public List listByVpcOffId(long vpcOffId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("vpcOffId", vpcOffId); + return listBy(sc); + } + + + @Override + public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) { + SearchCriteria sc = MultipleServicesSearch.create(); + sc.setParameters("vpcOffId", networkOfferingId); + + if (services != null) { + String[] servicesStr = new String[services.length]; + + int i = 0; + for (Service service : services) { + servicesStr[i] = service.getName(); + i++; + } + + sc.setParameters("service", (Object[])servicesStr); + } + + List offeringServices = listBy(sc); + + if (services != null) { + if (offeringServices.size() == services.length) { + return true; + } + } else if (!offeringServices.isEmpty()) { + return true; + } + + return false; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java new file mode 100644 index 00000000000..a7adf9c6895 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -0,0 +1,61 @@ +// 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; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.vpc.VpcOffering.State; +import com.cloud.user.Account; + + +/** + * @author Alena Prokharchyk + */ +public interface VpcManager extends VpcService{ + + /** + * @param name + * @param displayText + * @param svcProviderMap + * @param isDefault + * @param state TODO + * @return + */ + VpcOffering createVpcOffering(String name, String displayText, Map> svcProviderMap, + boolean isDefault, State state); + + /** + * @param vpcOffId + * @param services + * @return + */ + boolean areServicesSupportedByVpcOffering(long vpcOffId, Service[] services); + + /** + * @param zoneId + * @param vpcOffId + * @param vpcOwner + * @param vpcName + * @param displayText + * @param cidr + * @return + */ + Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr); + + List getSupportedServices(); + +} diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java new file mode 100644 index 00000000000..108b4871531 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -0,0 +1,608 @@ +// 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; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ejb.Local; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.configuration.ConfigurationManager; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenter; +import com.cloud.event.ActionEvent; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.UnsupportedServiceException; +import com.cloud.network.Network; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.vpc.VpcOffering.State; +import com.cloud.network.vpc.Dao.VpcDao; +import com.cloud.network.vpc.Dao.VpcOfferingDao; +import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao; +import com.cloud.org.Grouping; +import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.user.UserContext; +import com.cloud.utils.Ternary; +import com.cloud.utils.component.Inject; +import com.cloud.utils.component.Manager; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.net.NetUtils; + +/** + * @author Alena Prokharchyk + */ + +@Local(value = { VpcManager.class, VpcService.class }) +public class VpcManagerImpl implements VpcManager, Manager{ + private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class); + @Inject + VpcOfferingDao _vpcOffDao; + @Inject + VpcOfferingServiceMapDao _vpcOffSvcMapDao; + @Inject + VpcDao _vpcDao; + @Inject + ConfigurationDao _configDao; + @Inject + ConfigurationManager _configMgr; + @Inject + AccountManager _accountMgr; + @Inject + NetworkDao _ntwkDao; + + String _name; + + @Override + @DB + public boolean configure(String name, Map params) throws ConfigurationException { + _name = name; + + //configure default vpc offering + Transaction txn = Transaction.currentTxn(); + txn.start(); + + if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) { + s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName); + + Map> svcProviderMap = new HashMap>(); + Set provider = new HashSet(); + provider.add(Provider.VirtualRouter); + for (Service svc : getSupportedServices()) { + svcProviderMap.put(svc, provider); + } + createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, + true, State.Enabled); + } + + txn.commit(); + + return true; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } + + @Override + public String getName() { + return _name; + } + + @Override + public Vpc createVpc(long zoneId, String name, String cidr, long ownerId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getVpcNetworks(long vpcId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public VpcOffering getVpcOffering(long vpcOffId) { + return _vpcOffDao.findById(vpcOffId); + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering") + public VpcOffering createVpcOffering(String name, String displayText, List supportedServices) { + Map> svcProviderMap = new HashMap>(); + Set defaultProviders = new HashSet(); + defaultProviders.add(Provider.VirtualRouter); + + boolean sourceNatSvc = false; + boolean firewallSvs = false; + // populate the services first + for (String serviceName : supportedServices) { + // validate if the service is supported + Service service = Network.Service.getService(serviceName); + if (service == null || service == Service.Gateway) { + throw new InvalidParameterValueException("Invalid service " + serviceName); + } + + //don't allow security group service for vpc + if (service == Service.SecurityGroup) { + throw new UnsupportedServiceException("Service " + Service.SecurityGroup.getName() + " is not supported by VPC"); + } + svcProviderMap.put(service, defaultProviders); + } + + if (!sourceNatSvc) { + s_logger.debug("Automatically adding source nat service to the list of VPC services"); + svcProviderMap.put(Service.SourceNat, defaultProviders); + } + + if (!firewallSvs) { + s_logger.debug("Automatically adding firewall service to the list of VPC services"); + svcProviderMap.put(Service.Firewall, defaultProviders); + } + + svcProviderMap.put(Service.Gateway, defaultProviders); + + return createVpcOffering(name, displayText, svcProviderMap, false, null); + } + + + @Override + @DB + public VpcOffering createVpcOffering(String name, String displayText, Map> svcProviderMap, boolean isDefault, State state) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + // create vpc offering object + VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault); + + if (state != null) { + offering.setState(state); + } + s_logger.debug("Adding vpc offering " + offering); + offering = _vpcOffDao.persist(offering); + // populate services and providers + if (svcProviderMap != null) { + for (Network.Service service : svcProviderMap.keySet()) { + Set providers = svcProviderMap.get(service); + if (providers != null && !providers.isEmpty()) { + for (Network.Provider provider : providers) { + VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider); + _vpcOffSvcMapDao.persist(offService); + s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName()); + } + } else { + throw new InvalidParameterValueException("Provider is missing for the VPC offering service " + service.getName()); + } + } + } + + + + txn.commit(); + + UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name); + return offering; + } + + + + @Override + public Vpc getVpc(long vpcId) { + return _vpcDao.findById(vpcId); + } + + @Override + public Map> getVpcOffSvcProvidersMap(long vpcOffId) { + Map> serviceProviderMap = new HashMap>(); + List map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId); + + for (VpcOfferingServiceMapVO instance : map) { + String service = instance.getService(); + Set providers; + providers = serviceProviderMap.get(service); + if (providers == null) { + providers = new HashSet(); + } + providers.add(Provider.getProvider(instance.getProvider())); + serviceProviderMap.put(Service.getService(service), providers); + } + + return serviceProviderMap; + } + + + @Override + public List listVpcOfferings(Long id, String name, String displayText, List supportedServicesStr, + Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal) { + Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, startIndex, pageSizeVal); + SearchCriteria sc = _vpcOffDao.createSearchCriteria(); + + if (keyword != null) { + SearchCriteria ssc = _vpcOffDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + + if (displayText != null) { + sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); + } + + if (isDefault != null) { + sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault); + } + + if (state != null) { + sc.addAnd("state", SearchCriteria.Op.EQ, state); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + + List offerings = _vpcOffDao.search(sc, searchFilter); + + // filter by supported services + boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); + + if (listBySupportedServices) { + List supportedOfferings = new ArrayList(); + Service[] supportedServices = null; + + if (listBySupportedServices) { + supportedServices = new Service[supportedServicesStr.size()]; + int i = 0; + for (String supportedServiceStr : supportedServicesStr) { + Service service = Service.getService(supportedServiceStr); + if (service == null) { + throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); + } else { + supportedServices[i] = service; + } + i++; + } + } + + for (VpcOfferingVO offering : offerings) { + if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) { + supportedOfferings.add(offering); + } + } + + return supportedOfferings; + } else { + return offerings; + } + } + + @Override + public boolean areServicesSupportedByVpcOffering(long vpcOffId, Service... services) { + return (_vpcOffSvcMapDao.areServicesSupportedByNetworkOffering(vpcOffId, services)); + } + + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_DELETE, eventDescription = "deleting vpc offering") + public boolean deleteVpcOffering(long offId) { + UserContext.current().setEventDetails(" Id: " + offId); + + // Verify vpc offering id + VpcOfferingVO offering = _vpcOffDao.findById(offId); + if (offering == null) { + throw new InvalidParameterValueException("unable to find vpc offering " + offId); + } + + // Don't allow to delete default vpc offerings + if (offering.isDefault() == true) { + throw new InvalidParameterValueException("Default network offering can't be deleted"); + } + + // don't allow to delete vpc offering if it's in use by existing vpcs (the offering can be disabled though) + int vpcCount = _vpcDao.getVpcCountByOfferingId(offId); + if (vpcCount > 0) { + throw new InvalidParameterValueException("Can't delete vpc offering " + offId + " as its used by " + vpcCount + " vpcs. " + + "To make the network offering unavaiable, disable it"); + } + + if (_vpcOffDao.remove(offId)) { + return true; + } else { + return false; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering") + public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) { + UserContext.current().setEventDetails(" Id: " + vpcOffId); + + // Verify input parameters + VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId); + if (offeringToUpdate == null) { + throw new InvalidParameterValueException("Unable to find vpc offering " + vpcOffId); + } + + VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId); + + if (vpcOfferingName != null) { + offering.setName(vpcOfferingName); + } + + if (displayText != null) { + offering.setDisplayText(displayText); + } + + + if (state != null) { + boolean validState = false; + for (VpcOffering.State st : VpcOffering.State.values()) { + if (st.name().equalsIgnoreCase(state)) { + validState = true; + offering.setState(st); + } + } + if (!validState) { + throw new InvalidParameterValueException("Incorrect state value: " + state); + } + } + + if (_vpcOffDao.update(vpcOffId, offering)) { + s_logger.debug("Updated VPC offeirng id=" + vpcOffId); + return _vpcOffDao.findById(vpcOffId); + } else { + return null; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc") + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr) { + Account caller = UserContext.current().getCaller(); + Account owner = _accountMgr.getAccount(vpcOwnerId); + + //Verify that caller can perform actions in behalf of vpc owner + _accountMgr.checkAccess(caller, null, true, owner); + + // Validate vpc offering + VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); + if (vpcOff == null) { + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find vpc offering by specified id"); + ex.addProxyObject("vpc_offerings", vpcOffId, "vpcOfferingId"); + throw ex; + } + + //Validate zone + DataCenter zone = _configMgr.getZone(zoneId); + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { + // See DataCenterVO.java + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); + ex.addProxyObject("data_center", zone.getId(), "zoneId"); + throw ex; + } + + //validate cidr + return createVpc(zoneId, vpcOffId, owner, vpcName, displayText, cidr); + } + + @Override + public Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr) { + if (!NetUtils.isValidCIDR(cidr)) { + throw new InvalidParameterValueException("Invalid CIDR specified " + cidr); + } + + VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr); + vpc = _vpcDao.persist(vpc); + + if (vpc != null) { + s_logger.debug("Created VPC " + vpc); + } else { + s_logger.debug("Failed to create VPC"); + } + return vpc; + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") + public boolean deleteVpc(long vpcId) { + UserContext.current().setEventDetails(" Id: " + vpcId); + + // Verify vpc id + VpcVO vpc = _vpcDao.findById(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); + } + + // don't allow to delete vpc if it's in use by existing networks + int networksCount = _ntwkDao.getNetworkCountByVpcId(vpcId); + if (networksCount > 0) { + throw new InvalidParameterValueException("Can't delete VPC " + vpcId + " as its used by " + networksCount + " networks"); + } + + if (_vpcDao.remove(vpcId)) { + return true; + } else { + return false; + } + } + + @Override + @ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc") + public Vpc updateVpc(long vpcId, String vpcName, String displayText) { + UserContext.current().setEventDetails(" Id: " + vpcId); + + // Verify input parameters + VpcVO vpcToUpdate = _vpcDao.findById(vpcId); + if (vpcToUpdate == null) { + throw new InvalidParameterValueException("Unable to find vpc offering " + vpcId); + } + + VpcVO vpc = _vpcDao.createForUpdate(vpcId); + + if (vpcName != null) { + vpc.setName(vpcName); + } + + if (displayText != null) { + vpc.setDisplayText(displayText); + } + + if (_vpcDao.update(vpcId, vpc)) { + s_logger.debug("Updated VPC id=" + vpcId); + return _vpcDao.findById(vpcId); + } else { + return null; + } + } + + + @Override + public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, + String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, + Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll) { + Account caller = UserContext.current().getCaller(); + List permittedAccounts = new ArrayList(); + + Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); + _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, + listAll, false); + domainId = domainIdRecursiveListProject.first(); + isRecursive = domainIdRecursiveListProject.second(); + ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + Filter searchFilter = new Filter(VpcVO.class, "created", false, startIndex, pageSizeVal); + + SearchBuilder sb = _vpcDao.createSearchBuilder(); + _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + + sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("displayText", sb.entity().getDisplayText(), SearchCriteria.Op.LIKE); + sb.and("vpcOfferingId", sb.entity().getVpcOfferingId(), SearchCriteria.Op.EQ); + sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); + + + // now set the SC criteria... + SearchCriteria sc = sb.create(); + _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + + if (keyword != null) { + SearchCriteria ssc = _vpcDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (vpcName != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + vpcName + "%"); + } + + if (displayText != null) { + sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%"); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (vpcOffId != null) { + sc.addAnd("vpcOfferingId", SearchCriteria.Op.EQ, vpcOffId); + } + + if (zoneId != null) { + sc.addAnd("zoneId", SearchCriteria.Op.EQ, zoneId); + } + + if (state != null) { + sc.addAnd("state", SearchCriteria.Op.EQ, state); + } + + List vpcs = _vpcDao.search(sc, searchFilter); + + // filter by supported services + boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !vpcs.isEmpty()); + + if (listBySupportedServices) { + List supportedVpcs = new ArrayList(); + Service[] supportedServices = null; + + if (listBySupportedServices) { + supportedServices = new Service[supportedServicesStr.size()]; + int i = 0; + for (String supportedServiceStr : supportedServicesStr) { + Service service = Service.getService(supportedServiceStr); + if (service == null) { + throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); + } else { + supportedServices[i] = service; + } + i++; + } + } + + for (VpcVO vpc : vpcs) { + if (areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), supportedServices)) { + supportedVpcs.add(vpc); + } + } + + return supportedVpcs; + } else { + return vpcs; + } + } + + @Override + public List getSupportedServices() { + List services = new ArrayList(); + services.add(Network.Service.Dhcp); + services.add(Network.Service.Dns); + services.add(Network.Service.UserData); + services.add(Network.Service.Firewall); + services.add(Network.Service.PortForwarding); + services.add(Network.Service.Lb); + services.add(Network.Service.SourceNat); + services.add(Network.Service.StaticNat); + services.add(Network.Service.Gateway); + services.add(Network.Service.Vpn); + return services; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java b/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java new file mode 100644 index 00000000000..ffe8533cdf9 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java @@ -0,0 +1,87 @@ +// 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; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc_offering_service_map") +public class VpcOfferingServiceMapVO { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + long id; + + @Column(name="vpc_offering_id") + long vpcOfferingId; + + @Column(name="service") + String service; + + @Column(name="provider") + String provider; + + @Column(name=GenericDao.CREATED_COLUMN) + Date created; + + public long getId() { + return id; + } + + public long getVpcOfferingId() { + return vpcOfferingId; + } + + public String getService() { + return service; + } + + public String getProvider() { + return provider; + } + + public Date getCreated() { + return created; + } + + public VpcOfferingServiceMapVO() { + } + + public VpcOfferingServiceMapVO(long vpcOfferingId, Service service, Provider provider) { + this.vpcOfferingId = vpcOfferingId; + this.service = service.getName(); + if (provider != null) { + this.provider = provider.getName(); + } + } + + public String toString() { + StringBuilder buf = new StringBuilder("[VPC Offering Service["); + return buf.append(vpcOfferingId).append("-").append(service).append("-").append(provider).append("]").toString(); + } +} diff --git a/server/src/com/cloud/network/vpc/VpcOfferingVO.java b/server/src/com/cloud/network/vpc/VpcOfferingVO.java new file mode 100644 index 00000000000..86b698e6b05 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcOfferingVO.java @@ -0,0 +1,143 @@ +// 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; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc_offerings") +public class VpcOfferingVO implements VpcOffering{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name="uuid") + private String uuid; + + @Column(name = "name") + String name; + + @Column(name = "unique_name") + String uniqueName; + + @Column(name = "display_text") + String displayText; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + State state = State.Disabled; + + @Column(name = "default") + boolean isDefault = false; + + @Column(name = GenericDao.REMOVED_COLUMN) + Date removed; + + @Column(name = GenericDao.CREATED_COLUMN) + Date created; + + public VpcOfferingVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public VpcOfferingVO(String name, String displayText) { + this.name = name; + this.displayText = displayText; + this.uniqueName = name; + this.uuid = UUID.randomUUID().toString(); + this.state = State.Disabled; + } + + public VpcOfferingVO(String name, String displayText, boolean isDefault) { + this(name, displayText); + this.isDefault = isDefault; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getUniqueName() { + return uniqueName; + } + + @Override + public String getDisplayText() { + return displayText; + } + + @Override + public State getState() { + return state; + } + + @Override + public boolean isDefault() { + return isDefault; + } + + public void setUniqueName(String uniqueName) { + this.uniqueName = uniqueName; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder("[VPC Offering ["); + return buf.append(id).append("-").append(name).append("]").toString(); + } + + + public void setName(String name) { + this.name = name; + } + + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + + public void setState(State state) { + this.state = state; + } +} diff --git a/server/src/com/cloud/network/vpc/VpcVO.java b/server/src/com/cloud/network/vpc/VpcVO.java new file mode 100644 index 00000000000..65ad5c64727 --- /dev/null +++ b/server/src/com/cloud/network/vpc/VpcVO.java @@ -0,0 +1,164 @@ +// 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; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.api.Identity; +import com.cloud.network.Network; +import com.cloud.network.Network.Service; +import com.cloud.utils.db.GenericDao; + +/** + * @author Alena Prokharchyk + */ + +@Entity +@Table(name="vpc") +public class VpcVO implements Vpc, Identity { + @Id + @Column(name="id") + long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name = "display_text") + String displayText; + + @Column(name="zone_id") + long zoneId; + + @Column(name="cidr") + private String cidr = null; + + @Column(name="domain_id") + Long domainId = null; + + @Column(name="account_id") + Long accountId = null; + + @Column(name="state") + @Enumerated(value=EnumType.STRING) + State state; + + @Column(name="vpc_offering_id") + long vpcOfferingId; + + @Column(name=GenericDao.REMOVED_COLUMN) + Date removed; + + @Column(name=GenericDao.CREATED_COLUMN) + Date created; + + public VpcVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr) { + this.zoneId = zoneId; + this.name = name; + this.displayText = displayText; + this.accountId = accountId; + this.domainId = domainId; + this.cidr = cidr; + this.uuid = UUID.randomUUID().toString(); + this.state = State.Enabled; + this.vpcOfferingId = vpcOffId; + } + + @Override + public boolean readyToUse() { + return state == State.Enabled; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + @Override + public long getZoneId() { + return zoneId; + } + + @Override + public String getCidr() { + return cidr; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public long getVpcOfferingId() { + return vpcOfferingId; + } + + public Date getRemoved() { + return removed; + } + + @Override + public String getDisplayText() { + return displayText; + } + + public void setName(String name) { + this.name = name; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + +} diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java index 2ab4507d765..8ef8922f799 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java @@ -26,10 +26,15 @@ import com.cloud.utils.db.GenericDao; */ public interface NetworkOfferingServiceMapDao extends GenericDao { boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services); + List listByNetworkOfferingId(long networkOfferingId); + void deleteByOfferingId(long networkOfferingId); + List listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service); + boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider); + List listServicesForNetworkOffering(long networkOfferingId); } diff --git a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java index 28eed904e43..f47112c3cde 100644 --- a/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java +++ b/server/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java @@ -17,12 +17,9 @@ import java.util.List; import javax.ejb.Local; -import com.cloud.exception.UnsupportedServiceException; -import com.cloud.network.NetworkServiceMapVO; -import com.cloud.network.Network.Service; import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.offerings.NetworkOfferingServiceMapVO; -import com.cloud.offerings.NetworkOfferingVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index ba76d220799..cfab9bbd320 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -152,7 +152,6 @@ import com.cloud.storage.GuestOSVO; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; import com.cloud.storage.Storage; -import com.cloud.storage.VolumeHostVO; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.TemplateType; @@ -166,6 +165,7 @@ import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateZoneVO; import com.cloud.storage.Volume; import com.cloud.storage.Volume.Type; +import com.cloud.storage.VolumeHostVO; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSDao; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 488fb06e9cd..046b8b3b12b 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -208,12 +208,14 @@ CREATE TABLE `cloud`.`networks` ( `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', `specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if the network provides an ability to define ip ranges', + `vpc_id` bigint unsigned COMMENT 'vpc this network belongs to', PRIMARY KEY (`id`), CONSTRAINT `fk_networks__network_offering_id` FOREIGN KEY (`network_offering_id`) REFERENCES `network_offerings`(`id`), CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`), CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), + CONSTRAINT `fk_networks__vpc_id` FOREIGN KEY(`vpc_id`) REFERENCES `vpc`(`id`), CONSTRAINT `uc_networks__uuid` UNIQUE (`uuid`), INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2132,4 +2134,55 @@ CREATE TABLE `cloud`.`netscaler_pod_ref` ( CONSTRAINT `fk_ns_pod_ref__device_id` FOREIGN KEY (`external_load_balancer_device_id`) REFERENCES `external_load_balancer_devices`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`vpc` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) NOT NULL, + `name` varchar(255) COMMENT 'vpc name', + `display_text` varchar(255) COMMENT 'vpc display text', + `cidr` varchar(18) COMMENT 'vpc cidr', + `vpc_offering_id` bigint unsigned NOT NULL COMMENT 'vpc offering id that this vpc is created from', + `zone_id` bigint unsigned NOT NULL COMMENT 'the id of the zone this Vpc belongs to', + `state` varchar(32) NOT NULL COMMENT 'state of the VP (can be Enabled and Disabled)', + `domain_id` bigint unsigned NOT NULL COMMENT 'domain the vpc belongs to', + `account_id` bigint unsigned NOT NULL COMMENT 'owner of this vpc', + `removed` datetime COMMENT 'date removed if not null', + `created` datetime NOT NULL COMMENT 'date created', + PRIMARY KEY (`id`), + INDEX `i_vpc__removed`(`removed`), + CONSTRAINT `fk_vpc__zone_id` FOREIGN KEY `fk_vpc__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), + CONSTRAINT `fk_vpc__account_id` FOREIGN KEY `fk_vpc__account_id` (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_vpc__domain_id` FOREIGN KEY `fk_vpc__domain_id` (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`vpc_offerings` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) NOT NULL, + `unique_name` varchar(64) UNIQUE COMMENT 'unique name of the vpc offering', + `name` varchar(255) COMMENT 'vpc name', + `display_text` varchar(255) COMMENT 'display text', + `state` char(32) COMMENT 'state of the vpc offering that has Disabled value by default', + `default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if vpc offering is default', + `removed` datetime COMMENT 'date removed if not null', + `created` datetime NOT NULL COMMENT 'date created', + PRIMARY KEY (`id`), + INDEX `i_vpc__removed`(`removed`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`vpc_offering_service_map` ( + `id` bigint unsigned NOT NULL auto_increment, + `vpc_offering_id` bigint unsigned NOT NULL COMMENT 'vpc_offering_id', + `service` varchar(255) NOT NULL COMMENT 'service', + `provider` varchar(255) COMMENT 'service provider', + `created` datetime COMMENT 'date created', + PRIMARY KEY (`id`), + CONSTRAINT `fk_vpc_offering_service_map__vpc_offering_id` FOREIGN KEY(`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`) ON DELETE CASCADE, + UNIQUE (`vpc_offering_id`, `service`, `provider`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + SET foreign_key_checks = 1; + diff --git a/wscript b/wscript index 1ead7af8061..1b64c6ba6d2 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-15T19:32:03Z' +VERSION = '3.0.3.2012-05-18T01:05:37Z' APPNAME = 'cloud' import shutil,os