Skip to content

Commit ff77308

Browse files
committed
server: compute offerings for specified domain(s) and zone(s)
Service or compute offerings will be allowed to link with specified domain(s) and zone(s). Compute offering linked with multiple domains and zones can be created both with UI and API. Refactored createServiceOffering API to allow passing list of domain and zone IDs with domainids and zoneids parameter respectively. UI has been refactored to allow selecting multiple domains and zones while creating compute offering using multi-select elements. When list of passed domains contain both parent and child domain, offering will be created for parent domain. Compute offering details will now show list of linked domains and zones as a comma-separated list of names. Linked domains and zones will be stored in the cloud.service_offering_details table in database as comma-separated list of IDs with key domainids and zoneids respectively. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent beb0422 commit ff77308

27 files changed

Lines changed: 476 additions & 136 deletions

File tree

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;
@@ -96,7 +97,7 @@ UserAccount createUserAccount(String userName, String password, String firstName
9697

9798
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;
9899

99-
void checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
100+
void checkAccess(Account account, ServiceOffering so, DataCenter zone) throws PermissionDeniedException;
100101

101102
void checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException;
102103

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

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

137137
boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException;
138138

139-
public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
139+
public boolean checkAccess(Account account, ServiceOffering so, DataCenter zone) throws PermissionDeniedException;
140140

141141
boolean checkAccess(Account account, DiskOffering dof) 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
@@ -111,6 +111,8 @@ public class ApiConstants {
111111
public static final String IP6_DNS2 = "ip6dns2";
112112
public static final String DOMAIN = "domain";
113113
public static final String DOMAIN_ID = "domainid";
114+
public static final String DOMAIN_ID_LIST = "domainids";
115+
public static final String DOMAIN_NAME_LIST = "domainnames";
114116
public static final String DOMAIN__ID = "domainId";
115117
public static final String DURATION = "duration";
116118
public static final String ELIGIBLE = "eligible";
@@ -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/CreateServiceOfferingCmd.java

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

19+
import java.util.ArrayList;
1920
import java.util.Collection;
2021
import java.util.HashMap;
2122
import java.util.Iterator;
23+
import java.util.List;
2224
import java.util.Map;
2325

24-
import com.cloud.storage.Storage;
2526
import org.apache.cloudstack.api.APICommand;
2627
import org.apache.cloudstack.api.ApiConstants;
2728
import org.apache.cloudstack.api.ApiErrorCode;
@@ -30,9 +31,11 @@
3031
import org.apache.cloudstack.api.ServerApiException;
3132
import org.apache.cloudstack.api.response.DomainResponse;
3233
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
34+
import org.apache.cloudstack.api.response.ZoneResponse;
3335
import org.apache.log4j.Logger;
3436

3537
import com.cloud.offering.ServiceOffering;
38+
import com.cloud.storage.Storage;
3639
import com.cloud.user.Account;
3740

3841
@APICommand(name = "createServiceOffering", description = "Creates a service offering.", responseObject = ServiceOfferingResponse.class,
@@ -86,6 +89,24 @@ public class CreateServiceOfferingCmd extends BaseCmd {
8689
description = "the ID of the containing domain, null for public offerings")
8790
private Long domainId;
8891

92+
@Parameter(name = ApiConstants.DOMAIN_ID_LIST,
93+
type = CommandType.LIST,
94+
collectionType = CommandType.UUID,
95+
entityType = DomainResponse.class,
96+
required = false,
97+
description = "the ID of the domains offering is associated with, null for all domain offerings",
98+
since = "4.13")
99+
private List<Long> domainIds;
100+
101+
@Parameter(name = ApiConstants.ZONE_ID_LIST,
102+
type = CommandType.LIST,
103+
collectionType = CommandType.UUID,
104+
entityType = ZoneResponse.class,
105+
required = false,
106+
description = "the ID of the zones offering is associated with, null for all zone offerings",
107+
since = "4.13")
108+
private List<Long> zoneIds;
109+
89110
@Parameter(name = ApiConstants.HOST_TAGS, type = CommandType.STRING, description = "the host tag for this service offering.")
90111
private String hostTag;
91112

@@ -214,6 +235,20 @@ public Long getDomainId() {
214235
return domainId;
215236
}
216237

238+
public List<Long> getDomainIds() {
239+
if (domainId != null) {
240+
if (domainIds == null) {
241+
domainIds = new ArrayList<>();
242+
}
243+
domainIds.add(domainId);
244+
}
245+
return domainIds;
246+
}
247+
248+
public List<Long> getZoneIds() {
249+
return zoneIds;
250+
}
251+
217252
public String getHostTag() {
218253
return hostTag;
219254
}

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.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.ServiceOfferingResponse;
26+
import org.apache.log4j.Logger;
2827

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

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.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.BaseListDomainResourcesCmd;
2422
import org.apache.cloudstack.api.Parameter;
2523
import org.apache.cloudstack.api.response.ListResponse;
2624
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
2725
import org.apache.cloudstack.api.response.UserVmResponse;
26+
import org.apache.cloudstack.api.response.ZoneResponse;
27+
import org.apache.log4j.Logger;
2828

2929
@APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class,
3030
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -57,6 +57,13 @@ public class ListServiceOfferingsCmd extends BaseListDomainResourcesCmd {
5757
description = "the system VM type. Possible types are \"consoleproxy\", \"secondarystoragevm\" or \"domainrouter\".")
5858
private String systemVmType;
5959

60+
@Parameter(name = ApiConstants.ZONE_ID,
61+
type = CommandType.UUID,
62+
entityType = ZoneResponse.class,
63+
description = "id of zone disk offering is associated with",
64+
since = "4.13")
65+
private Long zoneId;
66+
6067
/////////////////////////////////////////////////////
6168
/////////////////// Accessors ///////////////////////
6269
/////////////////////////////////////////////////////
@@ -81,6 +88,8 @@ public String getSystemVmType() {
8188
return systemVmType;
8289
}
8390

91+
public Long getZoneId() { return zoneId; }
92+
8493
/////////////////////////////////////////////////////
8594
/////////////// API Implementation///////////////////
8695
/////////////////////////////////////////////////////

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
import java.util.Date;
2020
import java.util.Map;
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.offering.ServiceOffering;
2927
import com.cloud.serializer.Param;
28+
import com.google.gson.annotations.SerializedName;
3029

3130
@EntityReference(value = ServiceOffering.class)
3231
public class ServiceOfferingResponse extends BaseResponse {
@@ -416,6 +415,10 @@ public void setIopsWriteRate(Long iopsWriteRate) {
416415

417416
public void setIopsWriteRateMaxLength(Long iopsWriteRateMaxLength) { this.iopsWriteRateMaxLength = iopsWriteRateMaxLength; }
418417

418+
public Map<String, String> getDetails() {
419+
return details;
420+
}
421+
419422
public void setDetails(Map<String, String> details) {
420423
this.details = details;
421424
}

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
}

engine/schema/src/main/java/com/cloud/domain/dao/DomainDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ public interface DomainDao extends GenericDao<DomainVO, Long> {
4040
Set<Long> getDomainParentIds(long domainId);
4141

4242
List<Long> getDomainChildrenIds(String path);
43+
44+
List<DomainVO> list(Object[] ids);
4345
}

0 commit comments

Comments
 (0)