Skip to content

Commit 75859b6

Browse files
authored
Merge branch 'main' into instance-from-backup
2 parents 6b60a21 + 675ee2a commit 75859b6

File tree

15 files changed

+1163
-979
lines changed

15 files changed

+1163
-979
lines changed

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Install tools and dependencies used for development:
1818
# yum -y install git java-17-openjdk java-17-openjdk-devel \
1919
mysql mysql-server mkisofs git gcc python MySQL-python openssh-clients wget
2020

21-
Set up Maven (3.6.0):
21+
Set up Maven (3.9.9):
2222

2323
# wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
2424
# tar -zxvf apache-maven-3.9.9-bin.tar.gz -C /usr/local

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.cluster', 'storage_access_groups', '
7777
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host_pod_ref', 'storage_access_groups', 'varchar(255) DEFAULT NULL COMMENT "storage access groups for the hosts in the pod"');
7878
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.data_center', 'storage_access_groups', 'varchar(255) DEFAULT NULL COMMENT "storage access groups for the hosts in the zone"');
7979

80-
-- Add featured column for guest_os_category
80+
-- Add featured, sort_key, created, removed columns for guest_os_category
8181
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'featured', 'tinyint(1) NOT NULL DEFAULT 0 COMMENT "whether the category is featured or not" AFTER `uuid`');
8282
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'sort_key', 'int NOT NULL DEFAULT 0 COMMENT "sort key used for customising sort method" AFTER `featured`');
8383
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'created', 'datetime COMMENT "date on which the category was created" AFTER `sort_key`');
8484
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'removed', 'datetime COMMENT "date removed if not null" AFTER `created`');
85-
UPDATE `cloud`.`guest_os_category` SET `featured` = 1 WHERE `name` NOT IN ('Novel', 'None');
8685

8786
-- Begin: Changes for Guest OS category cleanup
8887
-- Add new OS categories if not present
@@ -98,7 +97,7 @@ BEGIN
9897

9998
CALL `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`('Fedora');
10099
CALL `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`('Rocky Linux');
101-
CALL `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`('Alma Linux');
100+
CALL `cloud`.`INSERT_CATEGORY_IF_NOT_EXIST`('AlmaLinux');
102101

103102
-- Move existing guest OS to new categories
104103
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`;
@@ -117,7 +116,7 @@ BEGIN
117116
WHERE `display_name` LIKE CONCAT('%', os_name, '%')
118117
; END;
119118
CALL `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`('Rocky Linux', 'Rocky Linux');
120-
CALL `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`('Alma Linux', 'Alma Linux');
119+
CALL `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`('AlmaLinux', 'AlmaLinux');
121120
CALL `cloud`.`UPDATE_CATEGORY_FOR_GUEST_OSES`('Fedora', 'Fedora');
122121

123122
-- Move existing guest OS whose category will be deleted to Other category
@@ -143,11 +142,8 @@ CALL `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`('Other', 'None');
143142
CALL `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`('Other', 'Unix');
144143
CALL `cloud`.`UPDATE_NEW_AND_DELETE_OLD_CATEGORY_FOR_GUEST_OS`('Other', 'Mac');
145144

146-
-- Add featured column for cloud.guest_os_category
147-
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'featured', 'tinyint(1) NOT NULL DEFAULT 0 COMMENT "whether the category is featured or not" AFTER `uuid`');
145+
-- Update featured for existing guest OS categories
148146
UPDATE `cloud`.`guest_os_category` SET featured = 1;
149-
-- Add sort_key column for cloud.guest_os_category
150-
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.guest_os_category', 'sort_key', 'int NOT NULL DEFAULT 0 COMMENT "sort key used for customising sort method" AFTER `featured`');
151147

152148
-- Update sort order for all guest OS categories
153149
UPDATE `cloud`.`guest_os_category`
@@ -157,7 +153,7 @@ SET `sort_key` = CASE
157153
WHEN `name` = 'Fedora' THEN 3
158154
WHEN `name` = 'CentOS' THEN 4
159155
WHEN `name` = 'Rocky Linux' THEN 5
160-
WHEN `name` = 'Alma Linux' THEN 6
156+
WHEN `name` = 'AlmaLinux' THEN 6
161157
WHEN `name` = 'Oracle' THEN 7
162158
WHEN `name` = 'RedHat' THEN 8
163159
WHEN `name` = 'SUSE' THEN 9

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ public void revokeAccess(DataObject data, Host host, DataStore dataStore) {
222222
StorPoolUtil.volumeRemoveTags(StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true), conn);
223223
}
224224
}
225-
226225
}
227226

228227
private void updateStoragePool(final long poolId, final long deltaUsedBytes) {
@@ -327,19 +326,14 @@ private SpApiResponse createStorPoolVolume(String template, String tier, VolumeI
327326
Long vmId, SpConnectionDesc conn) {
328327
SpApiResponse resp = new SpApiResponse();
329328
Map<String, String> tags = StorPoolHelper.addStorPoolTags(name, getVMInstanceUUID(vmId), "volume", getVcPolicyTag(vmId), tier);
330-
if (tier != null || template != null) {
331-
StorPoolUtil.spLog(
332-
"Creating volume [%s] with template [%s] or tier tags [%s] described in disk/service offerings details",
333-
vinfo.getUuid(), template, tier);
334-
resp = StorPoolUtil.volumeCreate(size, null, template, tags, conn);
335-
} else {
336-
StorPoolUtil.spLog(
337-
"StorpoolPrimaryDataStoreDriver.createAsync volume: name=%s, uuid=%s, isAttached=%s vm=%s, payload=%s, template: %s",
338-
vinfo.getName(), vinfo.getUuid(), vinfo.isAttachedVM(), vinfo.getAttachedVmName(),
339-
vinfo.getpayload(), conn.getTemplateName());
340-
resp = StorPoolUtil.volumeCreate(name, null, size, getVMInstanceUUID(vinfo.getInstanceId()), null,
341-
"volume", vinfo.getMaxIops(), conn);
329+
if (vinfo.getDeviceId() != null) {
330+
tags.put("disk", vinfo.getDeviceId().toString());
331+
}
332+
if (template == null) {
333+
template = conn.getTemplateName();
342334
}
335+
StorPoolVolumeDef volume = new StorPoolVolumeDef(null, size, tags, null, vinfo.getMaxIops(), template, null, null, null);
336+
resp = StorPoolUtil.volumeCreate(volume, conn);
343337
return resp;
344338
}
345339

@@ -827,20 +821,24 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
827821
if (tier == null) {
828822
template = getTemplateFromOfferingDetail(vinfo.getDiskOfferingId());
829823
}
830-
}
831-
832-
if (tier != null || template != null) {
833-
Map<String, String> tags = StorPoolHelper.addStorPoolTags(name, getVMInstanceUUID(vmId), "volume", getVcPolicyTag(vmId), tier);
834-
835824
StorPoolUtil.spLog(
836825
"Creating volume [%s] with template [%s] or tier tags [%s] described in disk/service offerings details",
837826
vinfo.getUuid(), template, tier);
838-
resp = StorPoolUtil.volumeCreate(size, parentName, template, tags, conn);
839-
} else {
840-
resp = StorPoolUtil.volumeCreate(name, parentName, size, getVMInstanceUUID(vmId),
841-
getVcPolicyTag(vmId), "volume", vinfo.getMaxIops(), conn);
842827
}
843828

829+
Map<String, String> tags = StorPoolHelper.addStorPoolTags(name, getVMInstanceUUID(vmId), "volume", getVcPolicyTag(vmId), tier);
830+
831+
if (vinfo.getDeviceId() != null) {
832+
tags.put("disk", vinfo.getDeviceId().toString());
833+
}
834+
835+
if (template == null) {
836+
template = conn.getTemplateName();
837+
}
838+
839+
StorPoolVolumeDef volumeDef = new StorPoolVolumeDef(null, size, tags, parentName, null, template, null, null, null);
840+
resp = StorPoolUtil.volumeCreate(volumeDef, conn);
841+
844842
if (resp.getError() == null) {
845843
updateStoragePool(dstData.getDataStore().getId(), vinfo.getSize());
846844
updateVolumePoolType(vinfo);
@@ -1309,7 +1307,13 @@ public void provideVmInfo(long vmId, long volumeId) {
13091307
SpConnectionDesc conn = StorPoolUtil.getSpConnection(poolVO.getUuid(), poolVO.getId(), storagePoolDetailsDao, primaryStoreDao);
13101308
String volName = StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true);
13111309
VMInstanceVO userVM = vmInstanceDao.findById(vmId);
1312-
SpApiResponse resp = StorPoolUtil.volumeUpdateIopsAndTags(volName, volume.getInstanceId() != null ? userVM.getUuid() : "", null, conn, getVcPolicyTag(vmId));
1310+
Map<String, String> tags = StorPoolHelper.addStorPoolTags(null, userVM.getUuid(), null, getVcPolicyTag(vmId), null);
1311+
if (volume.getDeviceId() != null) {
1312+
tags.put("disk", volume.getDeviceId().toString());
1313+
}
1314+
StorPoolVolumeDef spVolume = new StorPoolVolumeDef(volName, null, tags, null, null, null, null, null, null);
1315+
1316+
SpApiResponse resp = StorPoolUtil.volumeUpdate(spVolume, conn);
13131317
if (resp.getError() != null) {
13141318
logger.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid()));
13151319
}

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ public static SpApiResponse volumeCreate(Long size, String parentName, String te
520520
return POST("MultiCluster/VolumeCreate", json, conn);
521521
}
522522

523+
public static SpApiResponse volumeCreate(StorPoolVolumeDef volume, SpConnectionDesc conn) {
524+
return POST("MultiCluster/VolumeCreate", volume, conn);
525+
}
526+
523527
public static SpApiResponse volumeCreate(SpConnectionDesc conn) {
524528
Map<String, Object> json = new LinkedHashMap<>();
525529
json.put("name", "");
@@ -568,6 +572,7 @@ public static SpApiResponse volumeUpdate(final String name, final Long newSize,
568572
public static SpApiResponse volumeRemoveTags(String name, SpConnectionDesc conn) {
569573
Map<String, Object> json = new HashMap<>();
570574
Map<String, String> tags = StorPoolHelper.addStorPoolTags(null, "", null, "", null);
575+
tags.put("disk", "");
571576
json.put("tags", tags);
572577
return POST("MultiCluster/VolumeUpdate/" + name, json, conn);
573578
}

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,16 +1579,20 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
15791579
public void verifyCallerPrivilegeForUserOrAccountOperations(Account userAccount) {
15801580
logger.debug(String.format("Verifying whether the caller has the correct privileges based on the user's role type and API permissions: %s", userAccount));
15811581

1582-
checkCallerRoleTypeAllowedForUserOrAccountOperations(userAccount, null);
1583-
checkCallerApiPermissionsForUserOrAccountOperations(userAccount);
1582+
if (!Account.Type.PROJECT.equals(userAccount.getType())) {
1583+
checkCallerRoleTypeAllowedForUserOrAccountOperations(userAccount, null);
1584+
checkCallerApiPermissionsForUserOrAccountOperations(userAccount);
1585+
}
15841586
}
15851587

15861588
protected void verifyCallerPrivilegeForUserOrAccountOperations(User user) {
15871589
logger.debug(String.format("Verifying whether the caller has the correct privileges based on the user's role type and API permissions: %s", user));
15881590

15891591
Account userAccount = getAccount(user.getAccountId());
1590-
checkCallerRoleTypeAllowedForUserOrAccountOperations(userAccount, user);
1591-
checkCallerApiPermissionsForUserOrAccountOperations(userAccount);
1592+
if (!Account.Type.PROJECT.equals(userAccount.getType())) {
1593+
checkCallerRoleTypeAllowedForUserOrAccountOperations(userAccount, user);
1594+
checkCallerApiPermissionsForUserOrAccountOperations(userAccount);
1595+
}
15921596
}
15931597

15941598
protected void checkCallerRoleTypeAllowedForUserOrAccountOperations(Account userAccount, User user) {
@@ -1597,7 +1601,7 @@ protected void checkCallerRoleTypeAllowedForUserOrAccountOperations(Account user
15971601
RoleType userAccountRoleType = getRoleType(userAccount);
15981602

15991603
if (RoleType.Unknown == callerRoleType || RoleType.Unknown == userAccountRoleType) {
1600-
String errMsg = String.format("The role type of account [%s, %s] or [%s, %s] is unknown",
1604+
String errMsg = String.format("The role type of caller account [%s, %s] or target account [%s, %s] is unknown",
16011605
callingAccount.getName(), callingAccount.getUuid(), userAccount.getName(), userAccount.getUuid());
16021606
throw new PermissionDeniedException(errMsg);
16031607
}
@@ -2707,10 +2711,8 @@ public AccountVO createAccount(final String accountName, final Account.Type acco
27072711
}
27082712
}
27092713

2710-
if (!Account.Type.PROJECT.equals(accountType)) {
2711-
AccountVO newAccount = new AccountVO(accountName, domainId, networkDomain, accountType, roleId, uuid);
2712-
verifyCallerPrivilegeForUserOrAccountOperations(newAccount);
2713-
}
2714+
AccountVO newAccount = new AccountVO(accountName, domainId, networkDomain, accountType, roleId, uuid);
2715+
verifyCallerPrivilegeForUserOrAccountOperations(newAccount);
27142716

27152717
// Create the account
27162718
return Transaction.execute(new TransactionCallback<>() {

setup/bindir/cloud-setup-databases.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class DBDeployer(object):
7272
magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate'
7373
tmpMysqlFile = os.path.join(os.path.expanduser('~/'), 'cloudstackmysql.tmp.sql')
7474
mysqlBinPath = None
75+
skipUsersAutoCreation = False
7576

7677
def preRun(self):
7778
def backUpDbDotProperties():
@@ -219,6 +220,19 @@ for full help
219220
""),
220221
)
221222

223+
queriesToSkip = (
224+
("CREATE USER cloud@`localhost` identified by 'cloud';", ""),
225+
("CREATE USER cloud@`%` identified by 'cloud';", ""),
226+
("GRANT ALL ON cloud.* to cloud@`localhost`;", ""),
227+
("GRANT ALL ON cloud.* to cloud@`%`;", ""),
228+
("GRANT ALL ON cloud_usage.* to cloud@`localhost`;", ""),
229+
("GRANT ALL ON cloud_usage.* to cloud@`%`;", ""),
230+
("GRANT process ON *.* TO cloud@`localhost`;", ""),
231+
("GRANT process ON *.* TO cloud@`%`;", ""),
232+
("DROP USER 'cloud'@'localhost' ;", "DO NULL;"),
233+
("DROP USER 'cloud'@'%' ;", "DO NULL;")
234+
)
235+
222236
scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"]
223237
if self.options.schemaonly:
224238
scriptsToRun = ["create-schema", "create-schema-premium"]
@@ -227,6 +241,8 @@ for full help
227241
p = os.path.join(self.dbFilesPath,"%s.sql"%f)
228242
if not os.path.exists(p): continue
229243
text = open(p).read()
244+
if self.options.skipUsersAutoCreation:
245+
for t, r in queriesToSkip: text = text.replace(t,r)
230246
for t, r in replacements: text = text.replace(t,r)
231247
self.info("Applying %s"%p)
232248
self.runMysql(text, p, self.rootuser != None)
@@ -472,6 +488,8 @@ for example:
472488
self.encryptionJarPath = self.options.encryptionJarPath
473489
if self.options.mysqlbinpath:
474490
self.mysqlBinPath = self.options.mysqlbinpath
491+
if self.options.skipUsersAutoCreation:
492+
self.skipUsersAutoCreation = self.options.skipUsersAutoCreation
475493

476494
if self.options.encryptorVersion:
477495
self.encryptorVersion = "--encryptorversion %s" % self.options.encryptorVersion
@@ -612,6 +630,9 @@ for example:
612630
self.parser.add_option("-g", "--encryptor-version", action="store", dest="encryptorVersion", default="V2",
613631
help="The encryptor version to be used to encrypt the values in db.properties")
614632
self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path")
633+
self.parser.add_option("-u", "--skip-users-auto-creation", action="store_true", dest="skipUsersAutoCreation",
634+
help="Indicates whether to skip the auto-creation of users in the database. Use this flag when your database users " \
635+
"are already configured and you only want to populate the db.properties file.")
615636
(self.options, self.args) = self.parser.parse_args()
616637
parseCasualCredit()
617638
parseOtherOptions()

0 commit comments

Comments
 (0)