Skip to content

Commit 60b52f9

Browse files
author
Alena Prokharchyk
committed
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
1 parent f3e598a commit 60b52f9

52 files changed

Lines changed: 3083 additions & 148 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ public class ApiConstants {
357357
public static final String VSM_CONFIG_STATE = "vsmconfigstate";
358358
public static final String VSM_DEVICE_STATE = "vsmdevicestate";
359359
public static final String ADD_VSM_FLAG = "addvsmflag";
360+
public static final String VPC_OFF_ID = "vpcofferingid";
361+
public static final String NETWORK = "network";
360362

361363
public enum HostDetails {
362364
all, capacity, events, stats, min;

api/src/com/cloud/api/BaseCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.cloud.network.lb.LoadBalancingRulesService;
4545
import com.cloud.network.rules.RulesService;
4646
import com.cloud.network.security.SecurityGroupService;
47+
import com.cloud.network.vpc.VpcService;
4748
import com.cloud.network.vpn.RemoteAccessVpnService;
4849
import com.cloud.projects.Project;
4950
import com.cloud.projects.ProjectService;
@@ -128,6 +129,7 @@ public enum CommandType {
128129
public static ResourceLimitService _resourceLimitService;
129130
public static IdentityService _identityService;
130131
public static StorageNetworkService _storageNetworkService;
132+
public static VpcService _vpcService;
131133

132134
static void setComponents(ResponseGenerator generator) {
133135
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
@@ -155,6 +157,7 @@ static void setComponents(ResponseGenerator generator) {
155157
_resourceLimitService = locator.getManager(ResourceLimitService.class);
156158
_identityService = locator.getManager(IdentityService.class);
157159
_storageNetworkService = locator.getManager(StorageNetworkService.class);
160+
_vpcService = locator.getManager(VpcService.class);
158161
}
159162

160163
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;

api/src/com/cloud/api/ResponseGenerator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import com.cloud.api.response.VirtualRouterProviderResponse;
7575
import com.cloud.api.response.VlanIpRangeResponse;
7676
import com.cloud.api.response.VolumeResponse;
77+
import com.cloud.api.response.VpcOfferingResponse;
78+
import com.cloud.api.response.VpcResponse;
7779
import com.cloud.api.response.VpnUsersResponse;
7880
import com.cloud.api.response.ZoneResponse;
7981
import com.cloud.async.AsyncJob;
@@ -107,6 +109,8 @@
107109
import com.cloud.network.security.SecurityGroup;
108110
import com.cloud.network.security.SecurityGroupRules;
109111
import com.cloud.network.security.SecurityRule;
112+
import com.cloud.network.vpc.Vpc;
113+
import com.cloud.network.vpc.VpcOffering;
110114
import com.cloud.offering.DiskOffering;
111115
import com.cloud.offering.NetworkOffering;
112116
import com.cloud.offering.ServiceOffering;
@@ -280,4 +284,16 @@ public interface ResponseGenerator {
280284
* @return
281285
*/
282286
Long getIdentiyId(String tableName, String token);
287+
288+
/**
289+
* @param offering
290+
* @return
291+
*/
292+
VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering);
293+
294+
/**
295+
* @param vpc
296+
* @return
297+
*/
298+
VpcResponse createVpcResponse(Vpc vpc);
283299
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.api.commands;
14+
15+
import org.apache.log4j.Logger;
16+
17+
import com.cloud.api.ApiConstants;
18+
import com.cloud.api.BaseAsyncCreateCmd;
19+
import com.cloud.api.BaseCmd;
20+
import com.cloud.api.IdentityMapper;
21+
import com.cloud.api.Parameter;
22+
import com.cloud.api.ServerApiException;
23+
import com.cloud.api.response.VpcResponse;
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.exception.ResourceAllocationException;
26+
import com.cloud.network.vpc.Vpc;
27+
import com.cloud.user.UserContext;
28+
29+
/**
30+
* @author Alena Prokharchyk
31+
*/
32+
public class CreateVPCCmd extends BaseAsyncCreateCmd{
33+
public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName());
34+
private static final String s_name = "createvpcresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the VPC. " +
41+
"Must be used with the domainId parameter.")
42+
private String accountName;
43+
44+
@IdentityMapper(entityTableName="domain")
45+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the VPC. " +
46+
"If used with the account parameter returns the VPC associated with the account for the specified domain.")
47+
private Long domainId;
48+
49+
@IdentityMapper(entityTableName="data_center")
50+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone")
51+
private Long zoneId;
52+
53+
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the VPC")
54+
private String vpcName;
55+
56+
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " +
57+
"the VPC")
58+
private String displayText;
59+
60+
@Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, required=true, description="the cidr of the VPC. All VPC " +
61+
"guest networks' cidrs should be within this CIDR")
62+
private String cidr;
63+
64+
65+
@IdentityMapper(entityTableName="vpc_offerings")
66+
@Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering")
67+
private Long vpcOffering;
68+
69+
/////////////////////////////////////////////////////
70+
/////////////////// Accessors ///////////////////////
71+
/////////////////////////////////////////////////////
72+
73+
public String getAccountName() {
74+
return accountName;
75+
}
76+
77+
public Long getDomainId() {
78+
return domainId;
79+
}
80+
81+
public Long getZoneId() {
82+
return zoneId;
83+
}
84+
85+
public String getVpcName() {
86+
return vpcName;
87+
}
88+
89+
public String getCidr() {
90+
return cidr;
91+
}
92+
93+
public String getDisplayText() {
94+
return displayText;
95+
}
96+
97+
public Long getVpcOffering() {
98+
return vpcOffering;
99+
}
100+
101+
@Override
102+
public void create() throws ResourceAllocationException {
103+
Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr());
104+
if (vpc != null) {
105+
this.setEntityId(vpc.getId());
106+
} else {
107+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC");
108+
}
109+
}
110+
111+
@Override
112+
public void execute() {
113+
//TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc)
114+
Vpc vpc = _vpcService.getVpc(this.getEntityId());
115+
if (vpc != null) {
116+
VpcResponse response = _responseGenerator.createVpcResponse(vpc);
117+
response.setResponseName(getCommandName());
118+
this.setResponseObject(response);
119+
} else {
120+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC");
121+
}
122+
}
123+
124+
@Override
125+
public String getEntityTable() {
126+
return "vpc";
127+
}
128+
129+
130+
@Override
131+
public String getEventType() {
132+
return EventTypes.EVENT_VPC_CREATE;
133+
}
134+
135+
136+
@Override
137+
public String getEventDescription() {
138+
return "creating VPC. Id: " + getEntityId();
139+
}
140+
141+
@Override
142+
public String getCommandName() {
143+
return s_name;
144+
}
145+
146+
@Override
147+
public long getEntityOwnerId() {
148+
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
149+
if (accountId == null) {
150+
return UserContext.current().getCaller().getId();
151+
}
152+
153+
return accountId;
154+
}
155+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.api.commands;
14+
15+
import java.util.List;
16+
17+
import org.apache.log4j.Logger;
18+
19+
import com.cloud.api.ApiConstants;
20+
import com.cloud.api.BaseAsyncCreateCmd;
21+
import com.cloud.api.BaseCmd;
22+
import com.cloud.api.Parameter;
23+
import com.cloud.api.ServerApiException;
24+
import com.cloud.api.response.VpcOfferingResponse;
25+
import com.cloud.event.EventTypes;
26+
import com.cloud.exception.ResourceAllocationException;
27+
import com.cloud.network.vpc.VpcOffering;
28+
import com.cloud.user.Account;
29+
30+
/**
31+
* @author Alena Prokharchyk
32+
*/
33+
public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
34+
public static final Logger s_logger = Logger.getLogger(CreateVPCOfferingCmd.class.getName());
35+
private static final String _name = "createvpcofferingresponse";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
41+
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the vpc offering")
42+
private String vpcOfferingName;
43+
44+
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of " +
45+
"the vpc offering")
46+
private String displayText;
47+
48+
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, required=true, collectionType=CommandType.STRING,
49+
description="services supported by the vpc offering")
50+
private List<String> supportedServices;
51+
52+
/////////////////////////////////////////////////////
53+
/////////////////// Accessors ///////////////////////
54+
/////////////////////////////////////////////////////
55+
56+
public String getVpcOfferingName() {
57+
return vpcOfferingName;
58+
}
59+
60+
public String getDisplayText() {
61+
return displayText;
62+
}
63+
64+
public List<String> getSupportedServices() {
65+
return supportedServices;
66+
}
67+
68+
69+
@Override
70+
public void create() throws ResourceAllocationException {
71+
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices());
72+
if (vpcOff != null) {
73+
this.setEntityId(vpcOff.getId());
74+
} else {
75+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a VPC offering");
76+
}
77+
}
78+
79+
@Override
80+
public void execute() {
81+
VpcOffering vpc = _vpcService.getVpcOffering(this.getEntityId());
82+
if (vpc != null) {
83+
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc);
84+
response.setResponseName(getCommandName());
85+
this.setResponseObject(response);
86+
} else {
87+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPC offering");
88+
}
89+
}
90+
91+
@Override
92+
public String getEntityTable() {
93+
return "vpc_offerings";
94+
}
95+
96+
@Override
97+
public String getEventType() {
98+
return EventTypes.EVENT_VPC_OFFERING_CREATE;
99+
}
100+
101+
@Override
102+
public String getEventDescription() {
103+
return "creating VPC offering. Id: " + getEntityId();
104+
}
105+
106+
@Override
107+
public String getCommandName() {
108+
return _name;
109+
}
110+
111+
@Override
112+
public long getEntityOwnerId() {
113+
return Account.ACCOUNT_ID_SYSTEM;
114+
}
115+
116+
}

0 commit comments

Comments
 (0)