Skip to content

Commit b74f21b

Browse files
Merge branch '4.20' into 4.22
2 parents 5caf6cd + 744c8af commit b74f21b

File tree

13 files changed

+168
-221
lines changed

13 files changed

+168
-221
lines changed

.github/workflows/merge-conflict-checker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
name: "PR Merge Conflict Check"
1919
on:
2020
push:
21-
pull_request_target:
22-
types: [synchronize]
21+
pull_request:
22+
types: [opened, synchronize, reopened]
2323

2424
permissions: # added using https://github.com/step-security/secure-workflows
2525
contents: read

core/src/main/java/com/cloud/agent/api/ModifyStoragePoolAnswer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes,
4646
templateInfo = tInfo;
4747
}
4848

49+
public ModifyStoragePoolAnswer(final Command command, final boolean success, final String details) {
50+
super(command, success, details);
51+
}
52+
4953
public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, boolean success, String details) {
5054
super(cmd, success, details);
5155
}

engine/schema/src/main/java/com/cloud/user/UserVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public UserVO() {
123123
}
124124

125125
public UserVO(long id) {
126+
this();
126127
this.id = id;
127-
this.uuid = UUID.randomUUID().toString();
128128
}
129129

130130
public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, String uuid, Source source) {

engine/schema/src/main/java/com/cloud/user/dao/AccountDao.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121

2222
import com.cloud.user.Account;
2323
import com.cloud.user.AccountVO;
24-
import com.cloud.user.User;
2524
import com.cloud.utils.Pair;
2625
import com.cloud.utils.db.Filter;
2726
import com.cloud.utils.db.GenericDao;
2827

2928
public interface AccountDao extends GenericDao<AccountVO, Long> {
30-
Pair<User, Account> findUserAccountByApiKey(String apiKey);
3129

3230
List<AccountVO> findAccountsLike(String accountName);
3331

engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java

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

19-
import java.sql.PreparedStatement;
20-
import java.sql.ResultSet;
2119
import java.util.Date;
2220
import java.util.List;
2321

@@ -27,24 +25,17 @@
2725
import com.cloud.user.Account;
2826
import com.cloud.user.Account.State;
2927
import com.cloud.user.AccountVO;
30-
import com.cloud.user.User;
31-
import com.cloud.user.UserVO;
3228
import com.cloud.utils.Pair;
33-
import com.cloud.utils.crypt.DBEncryptionUtil;
3429
import com.cloud.utils.db.Filter;
3530
import com.cloud.utils.db.GenericDaoBase;
3631
import com.cloud.utils.db.GenericSearchBuilder;
3732
import com.cloud.utils.db.SearchBuilder;
3833
import com.cloud.utils.db.SearchCriteria;
3934
import com.cloud.utils.db.SearchCriteria.Func;
4035
import com.cloud.utils.db.SearchCriteria.Op;
41-
import com.cloud.utils.db.TransactionLegacy;
4236

4337
@Component
4438
public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements AccountDao {
45-
private static final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.username, u.account_id, u.secret_key, u.state, u.api_key_access, "
46-
+ "a.id, a.account_name, a.type, a.role_id, a.domain_id, a.state, a.api_key_access " + "FROM `cloud`.`user` u, `cloud`.`account` a "
47-
+ "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL";
4839

4940
protected final SearchBuilder<AccountVO> AllFieldsSearch;
5041
protected final SearchBuilder<AccountVO> AccountTypeSearch;
@@ -132,51 +123,6 @@ public List<AccountVO> findCleanupsForDisabledAccounts() {
132123
return listBy(sc);
133124
}
134125

135-
@Override
136-
public Pair<User, Account> findUserAccountByApiKey(String apiKey) {
137-
TransactionLegacy txn = TransactionLegacy.currentTxn();
138-
PreparedStatement pstmt = null;
139-
Pair<User, Account> userAcctPair = null;
140-
try {
141-
String sql = FIND_USER_ACCOUNT_BY_API_KEY;
142-
pstmt = txn.prepareAutoCloseStatement(sql);
143-
pstmt.setString(1, apiKey);
144-
ResultSet rs = pstmt.executeQuery();
145-
// TODO: make sure we don't have more than 1 result? ApiKey had better be unique
146-
if (rs.next()) {
147-
User u = new UserVO(rs.getLong(1));
148-
u.setUsername(rs.getString(2));
149-
u.setAccountId(rs.getLong(3));
150-
u.setSecretKey(DBEncryptionUtil.decrypt(rs.getString(4)));
151-
u.setState(State.getValueOf(rs.getString(5)));
152-
boolean apiKeyAccess = rs.getBoolean(6);
153-
if (rs.wasNull()) {
154-
u.setApiKeyAccess(null);
155-
} else {
156-
u.setApiKeyAccess(apiKeyAccess);
157-
}
158-
159-
AccountVO a = new AccountVO(rs.getLong(7));
160-
a.setAccountName(rs.getString(8));
161-
a.setType(Account.Type.getFromValue(rs.getInt(9)));
162-
a.setRoleId(rs.getLong(10));
163-
a.setDomainId(rs.getLong(11));
164-
a.setState(State.getValueOf(rs.getString(12)));
165-
apiKeyAccess = rs.getBoolean(13);
166-
if (rs.wasNull()) {
167-
a.setApiKeyAccess(null);
168-
} else {
169-
a.setApiKeyAccess(apiKeyAccess);
170-
}
171-
172-
userAcctPair = new Pair<User, Account>(u, a);
173-
}
174-
} catch (Exception e) {
175-
logger.warn("Exception finding user/acct by api key: " + apiKey, e);
176-
}
177-
return userAcctPair;
178-
}
179-
180126
@Override
181127
public List<AccountVO> findAccountsLike(String accountName) {
182128
return findAccountsLike(accountName, null).first();
@@ -341,11 +287,9 @@ public long getDomainIdForGivenAccountId(long id) {
341287
domain_id = account_vo.getDomainId();
342288
}
343289
catch (Exception e) {
344-
logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage());
345-
}
346-
finally {
347-
return domain_id;
290+
logger.warn("Can not get DomainId for the given AccountId; exception message : {}", e.getMessage());
348291
}
292+
return domain_id;
349293
}
350294

351295
@Override

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixModifyStoragePoolCommandWrapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour
5959
if (capacity == -1) {
6060
final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath();
6161
logger.warn(msg);
62-
return new Answer(command, false, msg);
62+
return new ModifyStoragePoolAnswer(command, false, msg);
6363
}
6464
final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
6565
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, capacity, available, tInfo);
@@ -68,12 +68,12 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour
6868
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost()
6969
+ pool.getPath();
7070
logger.warn(msg, e);
71-
return new Answer(command, false, msg);
71+
return new ModifyStoragePoolAnswer(command, false, msg);
7272
} catch (final Exception e) {
7373
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: "
7474
+ pool.getHost() + pool.getPath();
7575
logger.warn(msg, e);
76-
return new Answer(command, false, msg);
76+
return new ModifyStoragePoolAnswer(command, false, msg);
7777
}
7878
} else {
7979
try {
@@ -85,17 +85,17 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour
8585
if (result == null || !result.split("#")[1].equals("0")) {
8686
throw new CloudRuntimeException("Unable to remove heartbeat file entry for SR " + srUuid + " due to " + result);
8787
}
88-
return new Answer(command, true, "success");
88+
return new ModifyStoragePoolAnswer(command, true, "success");
8989
} catch (final XenAPIException e) {
9090
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: "
9191
+ pool.getHost() + pool.getPath();
9292
logger.warn(msg, e);
93-
return new Answer(command, false, msg);
93+
return new ModifyStoragePoolAnswer(command, false, msg);
9494
} catch (final Exception e) {
9595
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: "
9696
+ pool.getHost() + pool.getPath();
9797
logger.warn(msg, e);
98-
return new Answer(command, false, msg);
98+
return new ModifyStoragePoolAnswer(command, false, msg);
9999
}
100100
}
101101
}

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.inject.Inject;
4444
import javax.naming.ConfigurationException;
4545

46+
import com.cloud.network.vpc.VpcVO;
4647
import org.apache.cloudstack.acl.ControlledEntity;
4748
import org.apache.cloudstack.acl.SecurityChecker;
4849
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -2649,12 +2650,21 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
26492650
}
26502651

26512652
if (associatedNetworkId != null) {
2652-
_accountMgr.checkAccess(caller, null, false, networkDao.findById(associatedNetworkId));
2653-
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
2653+
NetworkVO associatedNetwork = networkDao.findById(associatedNetworkId);
2654+
2655+
if (associatedNetwork != null) {
2656+
_accountMgr.checkAccess(caller, null, false, associatedNetwork);
2657+
sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
2658+
}
26542659
}
2660+
26552661
if (vpcId != null) {
2656-
_accountMgr.checkAccess(caller, null, false, _vpcDao.findById(vpcId));
2657-
sc.setParameters("vpcId", vpcId);
2662+
VpcVO vpc = _vpcDao.findById(vpcId);
2663+
2664+
if (vpc != null) {
2665+
_accountMgr.checkAccess(caller, null, false, vpc);
2666+
sc.setParameters("vpcId", vpcId);
2667+
}
26582668
}
26592669

26602670
addrs = _publicIpAddressDao.search(sc, searchFilter); // Allocated
@@ -2671,12 +2681,15 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
26712681
}
26722682
if (associatedNetworkId != null) {
26732683
NetworkVO guestNetwork = networkDao.findById(associatedNetworkId);
2674-
if (zoneId == null) {
2675-
zoneId = guestNetwork.getDataCenterId();
2676-
} else if (zoneId != guestNetwork.getDataCenterId()) {
2677-
throw new InvalidParameterValueException("Please specify a valid associated network id in the specified zone.");
2684+
2685+
if (guestNetwork != null) {
2686+
if (zoneId == null) {
2687+
zoneId = guestNetwork.getDataCenterId();
2688+
} else if (zoneId != guestNetwork.getDataCenterId()) {
2689+
throw new InvalidParameterValueException("Please specify a valid associated network id in the specified zone.");
2690+
}
2691+
owner = _accountDao.findById(guestNetwork.getAccountId());
26782692
}
2679-
owner = _accountDao.findById(guestNetwork.getAccountId());
26802693
}
26812694
List<DataCenterVO> dcList = new ArrayList<>();
26822695
if (zoneId == null){

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
import com.cloud.vm.VmDetailConstants;
222222
import com.cloud.vm.dao.UserVmDao;
223223
import com.cloud.vm.dao.VMInstanceDao;
224-
import com.google.common.base.Joiner;
225224
import com.google.gson.Gson;
226225
import com.google.gson.GsonBuilder;
227226

@@ -1395,9 +1394,16 @@ public boolean deleteTemplate(DeleteTemplateCmd cmd) {
13951394
else {
13961395
vmInstanceVOList = _vmInstanceDao.listNonExpungedByTemplate(templateId);
13971396
}
1398-
if(!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
1399-
final String message = String.format("Unable to delete Template: %s because Instance: [%s] are using it.", template, Joiner.on(",").join(vmInstanceVOList));
1400-
logger.warn(message);
1397+
if (!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
1398+
String message = String.format("Unable to delete template [%s] because there are [%d] VM instances using it.", template, vmInstanceVOList.size());
1399+
String instancesListMessage = String.format(" Instances list: [%s].", StringUtils.join(vmInstanceVOList, ","));
1400+
1401+
logger.warn("{}{}", message, instancesListMessage);
1402+
1403+
if (_accountMgr.isRootAdmin(caller.getAccountId())) {
1404+
message += instancesListMessage;
1405+
}
1406+
14011407
throw new InvalidParameterValueException(message);
14021408
}
14031409

0 commit comments

Comments
 (0)