Skip to content

Commit a31f211

Browse files
committed
Merge remote-tracking branch 'remote/4.18'
2 parents 60b399f + 956efb2 commit a31f211

File tree

7 files changed

+222
-70
lines changed

7 files changed

+222
-70
lines changed

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

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

19+
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
1920
import org.apache.cloudstack.api.response.StoragePoolResponse;
2021
import org.apache.cloudstack.api.response.VolumeResponse;
2122
import org.apache.cloudstack.api.response.ZoneResponse;
2223
import org.apache.log4j.Logger;
2324

2425
import org.apache.cloudstack.api.APICommand;
2526
import org.apache.cloudstack.api.ApiConstants;
26-
import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.BaseCmd.CommandType;
2929
import org.apache.cloudstack.api.response.DiskOfferingResponse;
3030
import org.apache.cloudstack.api.response.ListResponse;
3131

3232
@APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class,
3333
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
34-
public class ListDiskOfferingsCmd extends BaseListDomainResourcesCmd {
34+
public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
3535
public static final Logger s_logger = Logger.getLogger(ListDiskOfferingsCmd.class.getName());
3636

3737

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

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

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

2223
import org.apache.cloudstack.api.APICommand;
2324
import org.apache.cloudstack.api.ApiConstants;
24-
import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
2525
import org.apache.cloudstack.api.Parameter;
2626
import org.apache.cloudstack.api.BaseCmd.CommandType;
2727
import org.apache.cloudstack.api.response.ListResponse;
@@ -30,7 +30,7 @@
3030

3131
@APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class,
3232
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
33-
public class ListServiceOfferingsCmd extends BaseListDomainResourcesCmd {
33+
public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
3434
public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName());
3535

3636

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,8 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
31533153
Object keyword = cmd.getKeyword();
31543154
Long domainId = cmd.getDomainId();
31553155
Boolean isRootAdmin = accountMgr.isRootAdmin(account.getAccountId());
3156+
Long projectId = cmd.getProjectId();
3157+
String accountName = cmd.getAccountName();
31563158
Boolean isRecursive = cmd.isRecursive();
31573159
Long zoneId = cmd.getZoneId();
31583160
Long volumeId = cmd.getVolumeId();
@@ -3246,9 +3248,9 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
32463248

32473249
// Filter offerings that are not associated with caller's domain
32483250
// Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
3249-
Account caller = CallContext.current().getCallingAccount();
3250-
if (caller.getType() != Account.Type.ADMIN) {
3251-
Domain callerDomain = _domainDao.findById(caller.getDomainId());
3251+
account = accountMgr.finalizeOwner(account, accountName, domainId, projectId);
3252+
if (!Account.Type.ADMIN.equals(account.getType())) {
3253+
Domain callerDomain = _domainDao.findById(account.getDomainId());
32523254
List<Long> domainIds = findRelatedDomainIds(callerDomain, isRecursive);
32533255

32543256
List<Long> ids = _diskOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
@@ -3338,6 +3340,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33383340
searchFilter.addOrderBy(ServiceOfferingJoinVO.class, "id", true);
33393341

33403342
Account caller = CallContext.current().getCallingAccount();
3343+
Long projectId = cmd.getProjectId();
3344+
String accountName = cmd.getAccountName();
33413345
Object name = cmd.getServiceOfferingName();
33423346
Object id = cmd.getId();
33433347
Object keyword = cmd.getKeyword();
@@ -3354,6 +3358,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33543358
Boolean encryptRoot = cmd.getEncryptRoot();
33553359
String storageType = cmd.getStorageType();
33563360

3361+
final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
33573362
SearchCriteria<ServiceOfferingJoinVO> sc = _srvOfferingJoinDao.createSearchCriteria();
33583363
if (!accountMgr.isRootAdmin(caller.getId()) && isSystem) {
33593364
throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
@@ -3365,8 +3370,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33653370
if (domainId != null && !accountMgr.isRootAdmin(caller.getId())) {
33663371
// check if the user's domain == so's domain || user's domain is a
33673372
// child of so's domain
3368-
if (!isPermissible(caller.getDomainId(), domainId)) {
3369-
throw new PermissionDeniedException("The account:" + caller.getAccountName() + " does not fall in the same domain hierarchy as the service offering");
3373+
if (!isPermissible(owner.getDomainId(), domainId)) {
3374+
throw new PermissionDeniedException("The account:" + owner.getAccountName() + " does not fall in the same domain hierarchy as the service offering");
33703375
}
33713376
}
33723377

@@ -3432,16 +3437,16 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
34323437
throw new InvalidParameterValueException("Only root admins can access system's offering");
34333438
}
34343439
if (isRecursive) { // domain + all sub-domains
3435-
if (caller.getType() == Account.Type.NORMAL) {
3440+
if (owner.getType() == Account.Type.NORMAL) {
34363441
throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list service offerings with isrecursive=true");
34373442
}
34383443
}
34393444
} else {
34403445
// for root users
3441-
if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin
3442-
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering");
3446+
if (owner.getDomainId() != 1 && isSystem) { // NON ROOT admin
3447+
throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering.");
34433448
}
3444-
if (domainId != null) {
3449+
if (domainId != null && accountName == null) {
34453450
sc.addAnd("domainId", Op.FIND_IN_SET, String.valueOf(domainId));
34463451
}
34473452
}
@@ -3527,8 +3532,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
35273532

35283533
// Filter offerings that are not associated with caller's domain
35293534
// Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
3530-
if (caller.getType() != Account.Type.ADMIN) {
3531-
Domain callerDomain = _domainDao.findById(caller.getDomainId());
3535+
if (owner.getType() != Account.Type.ADMIN) {
3536+
Domain callerDomain = _domainDao.findById(owner.getDomainId());
35323537
List<Long> domainIds = findRelatedDomainIds(callerDomain, isRecursive);
35333538

35343539
List<Long> ids = _srvOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);

server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,16 @@ protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsFo
16861686
for (VolumeVO toBeCreated : volumesTobeCreated) {
16871687
s_logger.debug("Checking suitable pools for volume (Id, Type): (" + toBeCreated.getId() + "," + toBeCreated.getVolumeType().name() + ")");
16881688

1689+
if (toBeCreated.getState() == Volume.State.Allocated && toBeCreated.getPoolId() != null) {
1690+
toBeCreated.setPoolId(null);
1691+
if (!_volsDao.update(toBeCreated.getId(), toBeCreated)) {
1692+
throw new CloudRuntimeException(String.format("Error updating volume [%s] to clear pool Id.", toBeCreated.getId()));
1693+
}
1694+
if (s_logger.isDebugEnabled()) {
1695+
String msg = String.format("Setting pool_id to NULL for volume id=%s as it is in Allocated state", toBeCreated.getId());
1696+
s_logger.debug(msg);
1697+
}
1698+
}
16891699
// If the plan specifies a poolId, it means that this VM's ROOT
16901700
// volume is ready and the pool should be reused.
16911701
// In this case, also check if rest of the volumes are ready and can

0 commit comments

Comments
 (0)