Skip to content

Commit 366b253

Browse files
sb-abhish3kshwstppr
authored andcommitted
server: create, update VPC offering for domain(s) & zone(s)
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent de79fbd commit 366b253

18 files changed

Lines changed: 904 additions & 57 deletions

File tree

‎api/src/main/java/com/cloud/network/vpc/VpcOffering.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.network.vpc;
1818

19+
import java.util.Date;
20+
1921
import org.apache.cloudstack.api.Identity;
2022
import org.apache.cloudstack.api.InternalIdentity;
2123

@@ -59,13 +61,16 @@ public enum State {
5961
/**
6062
* @return true if the offering provides a distributed router capable of one-hop forwarding
6163
*/
62-
boolean supportsDistributedRouter();
64+
boolean isSupportsDistributedRouter();
6365

6466
/**
6567
* @return true if VPC created with the offering can span multiple zones in the region
6668
*/
67-
boolean offersRegionLevelVPC();
69+
boolean isOffersRegionLevelVPC();
70+
71+
boolean isRedundantRouter();
6872

69-
boolean getRedundantRouter();
73+
Date getRemoved();
7074

75+
Date getCreated();
7176
}

‎api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import org.apache.cloudstack.api.command.admin.vpc.CreateVPCOfferingCmd;
24+
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
25+
2326
import com.cloud.utils.Pair;
2427

2528
public interface VpcProvisioningService {
2629

27-
public VpcOffering getVpcOffering(long vpcOfferingId);
30+
VpcOffering getVpcOffering(long vpcOfferingId);
31+
32+
VpcOffering createVpcOffering(CreateVPCOfferingCmd cmd);
2833

29-
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices,
30-
Map<String, List<String>> serviceProviders,
31-
Map serviceCapabilitystList,
32-
Long serviceOfferingId);
34+
VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices,
35+
Map<String, List<String>> serviceProviders,
36+
Map serviceCapabilitystList,
37+
Long serviceOfferingId, List<Long> domainIds, List<Long> zoneIds);
3338

3439
Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword,
3540
String state, Long startIndex, Long pageSizeVal);
@@ -41,12 +46,9 @@ Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(Long id, String name,
4146
public boolean deleteVpcOffering(long offId);
4247

4348
/**
44-
* @param vpcOffId
45-
* @param vpcOfferingName
46-
* @param displayText
47-
* @param state
49+
* @param cmd
4850
* @return
4951
*/
50-
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
52+
public VpcOffering updateVpcOffering(UpdateVPCOfferingCmd cmd);
5153

5254
}

‎api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
import java.util.Collection;
2121
import java.util.HashMap;
2222
import java.util.Iterator;
23+
import java.util.LinkedHashSet;
2324
import java.util.List;
2425
import java.util.Map;
26+
import java.util.Set;
2527

28+
import org.apache.cloudstack.api.response.DomainResponse;
29+
import org.apache.cloudstack.api.response.ZoneResponse;
30+
import org.apache.commons.collections.CollectionUtils;
2631
import org.apache.log4j.Logger;
2732

2833
import org.apache.cloudstack.api.APICommand;
@@ -75,6 +80,21 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
7580
description = "the ID of the service offering for the VPC router appliance")
7681
private Long serviceOfferingId;
7782

83+
@Parameter(name = ApiConstants.DOMAIN_ID,
84+
type = CommandType.LIST,
85+
collectionType = CommandType.UUID,
86+
entityType = DomainResponse.class,
87+
description = "the ID of the containing domain(s), null for public offerings")
88+
private List<Long> domainIds;
89+
90+
@Parameter(name = ApiConstants.ZONE_ID,
91+
type = CommandType.LIST,
92+
collectionType = CommandType.UUID,
93+
entityType = ZoneResponse.class,
94+
description = "the ID of the containing zone(s), null for public offerings",
95+
since = "4.13")
96+
private List<Long> zoneIds;
97+
7898
/////////////////////////////////////////////////////
7999
/////////////////// Accessors ///////////////////////
80100
/////////////////////////////////////////////////////
@@ -127,10 +147,27 @@ public Long getServiceOfferingId() {
127147
return serviceOfferingId;
128148
}
129149

150+
public List<Long> getDomainIds() {
151+
if (CollectionUtils.isNotEmpty(domainIds)) {
152+
Set<Long> set = new LinkedHashSet<>(domainIds);
153+
domainIds.clear();
154+
domainIds.addAll(set);
155+
}
156+
return domainIds;
157+
}
158+
159+
public List<Long> getZoneIds() {
160+
if (CollectionUtils.isNotEmpty(zoneIds)) {
161+
Set<Long> set = new LinkedHashSet<>(zoneIds);
162+
zoneIds.clear();
163+
zoneIds.addAll(set);
164+
}
165+
return zoneIds;
166+
}
167+
130168
@Override
131169
public void create() throws ResourceAllocationException {
132-
VpcOffering vpcOff = _vpcProvSvc.createVpcOffering(getVpcOfferingName(), getDisplayText(),
133-
getSupportedServices(), getServiceProviders(), getServiceCapabilitystList(), getServiceOfferingId());
170+
VpcOffering vpcOff = _vpcProvSvc.createVpcOffering(this);
134171
if (vpcOff != null) {
135172
setEntityId(vpcOff.getId());
136173
setEntityUuid(vpcOff.getUuid());

‎api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.vpc;
1818

19+
import java.util.LinkedHashSet;
20+
import java.util.List;
21+
import java.util.Set;
22+
23+
import org.apache.cloudstack.api.response.DomainResponse;
24+
import org.apache.cloudstack.api.response.ZoneResponse;
25+
import org.apache.commons.collections.CollectionUtils;
1926
import org.apache.log4j.Logger;
2027

2128
import org.apache.cloudstack.api.APICommand;
@@ -52,6 +59,21 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
5259
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "update state for the VPC offering; " + "supported states - Enabled/Disabled")
5360
private String state;
5461

62+
@Parameter(name = ApiConstants.DOMAIN_ID,
63+
type = CommandType.LIST,
64+
collectionType = CommandType.UUID,
65+
entityType = DomainResponse.class,
66+
description = "the ID of the containing domain(s), null for public offerings")
67+
private List<Long> domainIds;
68+
69+
@Parameter(name = ApiConstants.ZONE_ID,
70+
type = CommandType.LIST,
71+
collectionType = CommandType.UUID,
72+
entityType = ZoneResponse.class,
73+
description = "the ID of the containing zone(s), null for public offerings",
74+
since = "4.13")
75+
private List<Long> zoneIds;
76+
5577
/////////////////////////////////////////////////////
5678
/////////////////// Accessors ///////////////////////
5779
/////////////////////////////////////////////////////
@@ -72,6 +94,24 @@ public String getState() {
7294
return state;
7395
}
7496

97+
public List<Long> getDomainIds() {
98+
if (CollectionUtils.isNotEmpty(domainIds)) {
99+
Set<Long> set = new LinkedHashSet<>(domainIds);
100+
domainIds.clear();
101+
domainIds.addAll(set);
102+
}
103+
return domainIds;
104+
}
105+
106+
public List<Long> getZoneIds() {
107+
if (CollectionUtils.isNotEmpty(zoneIds)) {
108+
Set<Long> set = new LinkedHashSet<>(zoneIds);
109+
zoneIds.clear();
110+
zoneIds.addAll(set);
111+
}
112+
return zoneIds;
113+
}
114+
75115
/////////////////////////////////////////////////////
76116
/////////////// API Implementation///////////////////
77117
/////////////////////////////////////////////////////
@@ -87,7 +127,7 @@ public long getEntityOwnerId() {
87127

88128
@Override
89129
public void execute() {
90-
VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
130+
VpcOffering result = _vpcProvSvc.updateVpcOffering(this);
91131
if (result != null) {
92132
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
93133
response.setResponseName(getCommandName());

‎api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
import java.util.Date;
2020
import java.util.List;
2121

22-
import com.google.gson.annotations.SerializedName;
23-
2422
import org.apache.cloudstack.api.ApiConstants;
2523
import org.apache.cloudstack.api.BaseResponse;
2624
import org.apache.cloudstack.api.EntityReference;
2725

2826
import com.cloud.network.vpc.VpcOffering;
2927
import com.cloud.serializer.Param;
28+
import com.google.gson.annotations.SerializedName;
3029

3130
@EntityReference(value = VpcOffering.class)
3231
@SuppressWarnings("unused")
@@ -67,6 +66,22 @@ public class VpcOfferingResponse extends BaseResponse {
6766
@Param(description = " indicated if the offering can support region level vpc", since = "4.4")
6867
private Boolean supportsRegionLevelVpc;
6968

69+
@SerializedName(ApiConstants.DOMAIN_ID)
70+
@Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.")
71+
private String domainId;
72+
73+
@SerializedName(ApiConstants.DOMAIN)
74+
@Param(description = "the domain name(s) this disk offering belongs to. Ignore this information as it is not currently applicable.")
75+
private String domain;
76+
77+
@SerializedName(ApiConstants.ZONE_ID)
78+
@Param(description = "the zone ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.", since = "4.13.0")
79+
private String zoneId;
80+
81+
@SerializedName(ApiConstants.ZONE)
82+
@Param(description = "the zone name(s) this disk offering belongs to. Ignore this information as it is not currently applicable.", since = "4.13.0")
83+
private String zone;
84+
7085
public void setId(String id) {
7186
this.id = id;
7287
}
@@ -102,4 +117,36 @@ public void setSupportsDistributedRouter(Boolean supportsDistributedRouter) {
102117
public void setSupportsRegionLevelVpc(Boolean supports) {
103118
this.supportsRegionLevelVpc = supports;
104119
}
120+
121+
public String getDomainId() {
122+
return domainId;
123+
}
124+
125+
public void setDomainId(String domainId) {
126+
this.domainId = domainId;
127+
}
128+
129+
public String getDomain() {
130+
return domain;
131+
}
132+
133+
public void setDomain(String domain) {
134+
this.domain = domain;
135+
}
136+
137+
public String getZoneId() {
138+
return zoneId;
139+
}
140+
141+
public void setZoneId(String zoneId) {
142+
this.zoneId = zoneId;
143+
}
144+
145+
public String getZone() {
146+
return zone;
147+
}
148+
149+
public void setZone(String zone) {
150+
this.zone = zone;
151+
}
105152
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.network.vpc;
19+
20+
import javax.persistence.Column;
21+
import javax.persistence.Entity;
22+
import javax.persistence.GeneratedValue;
23+
import javax.persistence.GenerationType;
24+
import javax.persistence.Id;
25+
import javax.persistence.Table;
26+
27+
import org.apache.cloudstack.api.ResourceDetail;
28+
29+
@Entity
30+
@Table(name = "vpc_offering_details")
31+
public class VpcOfferingDetailsVO implements ResourceDetail {
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "id")
35+
private long id;
36+
37+
@Column(name = "offering_id")
38+
private long resourceId;
39+
40+
@Column(name = "name")
41+
private String name;
42+
43+
@Column(name = "value")
44+
private String value;
45+
46+
@Column(name = "display")
47+
private boolean display = true;
48+
49+
protected VpcOfferingDetailsVO() {
50+
}
51+
52+
public VpcOfferingDetailsVO(long vpcOfferingId, String name, String value, boolean display) {
53+
this.resourceId = vpcOfferingId;
54+
this.name = name;
55+
this.value = value;
56+
this.display = display;
57+
}
58+
59+
@Override
60+
public long getResourceId() {
61+
return resourceId;
62+
}
63+
64+
public void setResourceId(long vpcOfferingId) {
65+
this.resourceId = vpcOfferingId;
66+
}
67+
68+
@Override
69+
public String getName() {
70+
return name;
71+
}
72+
73+
@Override
74+
public String getValue() {
75+
return value;
76+
}
77+
78+
@Override
79+
public long getId() {
80+
return id;
81+
}
82+
83+
@Override
84+
public boolean isDisplay() {
85+
return display;
86+
}
87+
}

0 commit comments

Comments
 (0)