Skip to content

Commit 46e1cc6

Browse files
shwstpprrohityadavcloud
authored andcommitted
server: ability to create disk offerings for domain(s) and zone(s)
Allows creating storage offerings associated with particular domain(s) and zone(s). In create disk/storage offfering form UI, a mult-select control has been addded to select desired zone(s) and domain select element has been made multi-select. createDiskOffering API has been modified to allow passing list of domain and zone IDs with keys domainids and zoneids respectively. These lists are stored in DB in cloud.disk_offering_details table with 'domainids' and 'zoneids' key as string of comma separated list of IDs. Response for create, update and list disk offering APIs will return domainids, domainnames, zoneids and zonenames in details object of offering. listDiskOfferings API has been modified to allow passing zoneid to return only offerings which are associated with the zone. Signed-off-by: Abhishek Kumar <[email protected]>
1 parent beb0422 commit 46e1cc6

File tree

30 files changed

+534
-127
lines changed

30 files changed

+534
-127
lines changed

api/src/main/java/com/cloud/user/AccountService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
2626
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
2727

28+
import com.cloud.dc.DataCenter;
2829
import com.cloud.domain.Domain;
2930
import com.cloud.exception.PermissionDeniedException;
3031
import com.cloud.offering.DiskOffering;
@@ -98,7 +99,7 @@ UserAccount createUserAccount(String userName, String password, String firstName
9899

99100
void checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
100101

101-
void checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException;
102+
void checkAccess(Account account, DiskOffering dof, DataCenter zone) throws PermissionDeniedException;
102103

103104
void checkAccess(User user, ControlledEntity entity);
104105

api/src/main/java/org/apache/cloudstack/acl/SecurityChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,5 @@ boolean checkAccess(Account caller, AccessType accessType, String action, Contro
138138

139139
public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
140140

141-
boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException;
141+
boolean checkAccess(Account account, DiskOffering dof, DataCenter zone) throws PermissionDeniedException;
142142
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public class ApiConstants {
112112
public static final String DOMAIN = "domain";
113113
public static final String DOMAIN_ID = "domainid";
114114
public static final String DOMAIN__ID = "domainId";
115+
public static final String DOMAIN_ID_LIST = "domainids";
116+
public static final String DOMAIN_NAME_LIST = "domainnames";
115117
public static final String DURATION = "duration";
116118
public static final String ELIGIBLE = "eligible";
117119
public static final String EMAIL = "email";
@@ -706,6 +708,7 @@ public class ApiConstants {
706708
public static final String NETSCALER_SERVICEPACKAGE_ID = "netscalerservicepackageid";
707709

708710
public static final String ZONE_ID_LIST = "zoneids";
711+
public static final String ZONE_NAME_LIST = "zonenames";
709712
public static final String DESTINATION_ZONE_ID_LIST = "destzoneids";
710713
public static final String ADMIN = "admin";
711714
public static final String CHECKSUM_PARAMETER_PREFIX_DESCRIPTION = "The parameter containing the checksum will be considered a MD5sum if it is not prefixed\n"

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.offering;
1818

19-
import org.apache.log4j.Logger;
19+
import java.util.ArrayList;
20+
import java.util.List;
2021

2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.ApiConstants;
@@ -26,10 +27,12 @@
2627
import org.apache.cloudstack.api.ServerApiException;
2728
import org.apache.cloudstack.api.response.DiskOfferingResponse;
2829
import org.apache.cloudstack.api.response.DomainResponse;
30+
import org.apache.cloudstack.api.response.ZoneResponse;
31+
import org.apache.log4j.Logger;
2932

30-
import com.cloud.storage.Storage.ProvisioningType;
3133
import com.cloud.offering.DiskOffering;
3234
import com.cloud.offering.ServiceOffering;
35+
import com.cloud.storage.Storage.ProvisioningType;
3336
import com.cloud.user.Account;
3437

3538
@APICommand(name = "createDiskOffering", description = "Creates a disk offering.", responseObject = DiskOfferingResponse.class,
@@ -64,6 +67,24 @@ public class CreateDiskOfferingCmd extends BaseCmd {
6467
description = "the ID of the containing domain, null for public offerings")
6568
private Long domainId;
6669

70+
@Parameter(name = ApiConstants.DOMAIN_ID_LIST,
71+
type = CommandType.LIST,
72+
collectionType = CommandType.UUID,
73+
entityType = DomainResponse.class,
74+
required = false,
75+
description = "the ID of the domains offering is associated with, null for all domain offerings",
76+
since = "4.13")
77+
private List<Long> domainIds;
78+
79+
@Parameter(name = ApiConstants.ZONE_ID_LIST,
80+
type = CommandType.LIST,
81+
collectionType = CommandType.UUID,
82+
entityType = ZoneResponse.class,
83+
required = false,
84+
description = "the ID of the zones offering is associated with, null for all zone offerings",
85+
since = "4.13")
86+
private List<Long> zoneIds;
87+
6788
@Parameter(name = ApiConstants.STORAGE_TYPE, type = CommandType.STRING, description = "the storage type of the disk offering. Values are local and shared.")
6889
private String storageType = ServiceOffering.StorageType.shared.toString();
6990

@@ -170,6 +191,20 @@ public Long getDomainId() {
170191
return domainId;
171192
}
172193

194+
public List<Long> getDomainIds() {
195+
if (domainId != null) {
196+
if (domainIds == null) {
197+
domainIds = new ArrayList<>();
198+
}
199+
domainIds.add(domainId);
200+
}
201+
return domainIds;
202+
}
203+
204+
public List<Long> getZoneIds() {
205+
return zoneIds;
206+
}
207+
173208
public Long getBytesReadRate() {
174209
return bytesReadRate;
175210
}

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.offering;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.ApiErrorCode;
2422
import org.apache.cloudstack.api.BaseCmd;
2523
import org.apache.cloudstack.api.Parameter;
2624
import org.apache.cloudstack.api.ServerApiException;
2725
import org.apache.cloudstack.api.response.DiskOfferingResponse;
26+
import org.apache.log4j.Logger;
2827

2928
import com.cloud.offering.DiskOffering;
3029
import com.cloud.user.Account;

api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.offering;
1818

19+
import org.apache.cloudstack.api.response.ZoneResponse;
1920
import org.apache.log4j.Logger;
2021

2122
import org.apache.cloudstack.api.APICommand;
@@ -42,6 +43,13 @@ public class ListDiskOfferingsCmd extends BaseListDomainResourcesCmd {
4243
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "name of the disk offering")
4344
private String diskOfferingName;
4445

46+
@Parameter(name = ApiConstants.ZONE_ID,
47+
type = CommandType.UUID,
48+
entityType = ZoneResponse.class,
49+
description = "id of zone disk offering is associated with",
50+
since = "4.13")
51+
private Long zoneId;
52+
4553
/////////////////////////////////////////////////////
4654
/////////////////// Accessors ///////////////////////
4755
/////////////////////////////////////////////////////
@@ -54,6 +62,10 @@ public String getDiskOfferingName() {
5462
return diskOfferingName;
5563
}
5664

65+
public Long getZoneId() {
66+
return zoneId;
67+
}
68+
5769
/////////////////////////////////////////////////////
5870
/////////////// API Implementation///////////////////
5971
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
package org.apache.cloudstack.api.response;
1818

1919
import java.util.Date;
20-
21-
import com.google.gson.annotations.SerializedName;
20+
import java.util.Map;
2221

2322
import org.apache.cloudstack.api.ApiConstants;
2423
import org.apache.cloudstack.api.BaseResponse;
2524
import org.apache.cloudstack.api.EntityReference;
2625

2726
import com.cloud.offering.DiskOffering;
2827
import com.cloud.serializer.Param;
28+
import com.google.gson.annotations.SerializedName;
2929

3030
@EntityReference(value = DiskOffering.class)
3131
public class DiskOfferingResponse extends BaseResponse {
@@ -144,6 +144,10 @@ public class DiskOfferingResponse extends BaseResponse {
144144
@Param(description = "whether to display the offering to the end user or not.")
145145
private Boolean displayOffering;
146146

147+
@SerializedName(ApiConstants.DETAILS)
148+
@Param(description = "the details of the disk offering", since = "4.13.0")
149+
private Map<String, String> details;
150+
147151
public Boolean getDisplayOffering() {
148152
return displayOffering;
149153
}
@@ -328,4 +332,12 @@ public void setIopsWriteRateMax(Long iopsWriteRateMax) {
328332
public void setIopsWriteRateMaxLength(Long iopsWriteRateMaxLength) {
329333
this.iopsWriteRateMaxLength = iopsWriteRateMaxLength;
330334
}
335+
336+
public Map<String, String> getDetails() {
337+
return details;
338+
}
339+
340+
public void setDetails(Map<String, String> details) {
341+
this.details = details;
342+
}
331343
}

engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
177177

178178
void checkZoneAccess(Account caller, DataCenter zone);
179179

180-
void checkDiskOfferingAccess(Account caller, DiskOffering dof);
180+
void checkDiskOfferingAccess(Account caller, DiskOffering dof, DataCenter zone);
181181

182182
/**
183183
* Creates a new network offering

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,6 @@ public Integer getVlan() {
121121
List<DataCenterVO> findByKeyword(String keyword);
122122

123123
List<DataCenterVO> listAllZones();
124+
125+
List<DataCenterVO> list(Object[] ids);
124126
}

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,12 @@ public List<DataCenterVO> listAllZones() {
437437

438438
return dcs;
439439
}
440+
441+
@Override
442+
public List<DataCenterVO> list(Object[] ids) {
443+
SearchBuilder<DataCenterVO> sb = createSearchBuilder();
444+
SearchCriteria<DataCenterVO> sc = sb.create();
445+
sc.addAnd("id", SearchCriteria.Op.IN, ids);
446+
return listBy(sc);
447+
}
440448
}

0 commit comments

Comments
 (0)