Skip to content

Commit 7afb82f

Browse files
authored
Merge branch '4.22' into create-vol-on-stroage
2 parents b420f90 + b1bc538 commit 7afb82f

File tree

25 files changed

+431
-109
lines changed

25 files changed

+431
-109
lines changed

api/src/main/java/org/apache/cloudstack/storage/volume/VolumeImportUnmanageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface VolumeImportUnmanageService extends PluggableService, Configura
3737
Arrays.asList(Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.VMware);
3838

3939
List<Storage.StoragePoolType> SUPPORTED_STORAGE_POOL_TYPES_FOR_KVM = Arrays.asList(Storage.StoragePoolType.NetworkFilesystem,
40-
Storage.StoragePoolType.Filesystem, Storage.StoragePoolType.RBD);
40+
Storage.StoragePoolType.Filesystem, Storage.StoragePoolType.RBD, Storage.StoragePoolType.SharedMountPoint);
4141

4242
ConfigKey<Boolean> AllowImportVolumeWithBackingFile = new ConfigKey<>(Boolean.class,
4343
"allow.import.volume.with.backing.file",

core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class RestoreBackupCommand extends Command {
3434
private List<String> backupVolumesUUIDs;
3535
private List<PrimaryDataStoreTO> restoreVolumePools;
3636
private List<String> restoreVolumePaths;
37+
private List<Long> restoreVolumeSizes;
3738
private List<String> backupFiles;
3839
private String diskType;
3940
private Boolean vmExists;
@@ -92,6 +93,14 @@ public void setRestoreVolumePaths(List<String> restoreVolumePaths) {
9293
this.restoreVolumePaths = restoreVolumePaths;
9394
}
9495

96+
public List<Long> getRestoreVolumeSizes() {
97+
return restoreVolumeSizes;
98+
}
99+
100+
public void setRestoreVolumeSizes(List<Long> restoreVolumeSizes) {
101+
this.restoreVolumeSizes = restoreVolumeSizes;
102+
}
103+
95104
public List<String> getBackupFiles() {
96105
return backupFiles;
97106
}

engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public interface HostTagsDao extends GenericDao<HostTagVO, Long> {
4545
HostTagResponse newHostTagResponse(HostTagVO hostTag);
4646

4747
List<HostTagVO> searchByIds(Long... hostTagIds);
48+
49+
/**
50+
* List all host tags defined on hosts within a cluster
51+
*/
52+
List<String> listByClusterId(Long clusterId);
4853
}

engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.framework.config.ConfigKey;
2424
import org.apache.cloudstack.framework.config.Configurable;
2525
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
26+
import org.apache.commons.collections4.CollectionUtils;
2627
import org.apache.commons.lang3.StringUtils;
2728
import org.springframework.stereotype.Component;
2829

@@ -43,9 +44,12 @@ public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements
4344
private final SearchBuilder<HostTagVO> stSearch;
4445
private final SearchBuilder<HostTagVO> tagIdsearch;
4546
private final SearchBuilder<HostTagVO> ImplicitTagsSearch;
47+
private final GenericSearchBuilder<HostTagVO, String> tagSearch;
4648

4749
@Inject
4850
private ConfigurationDao _configDao;
51+
@Inject
52+
private HostDao hostDao;
4953

5054
public HostTagsDaoImpl() {
5155
HostSearch = createSearchBuilder();
@@ -72,6 +76,11 @@ public HostTagsDaoImpl() {
7276
ImplicitTagsSearch.and("hostId", ImplicitTagsSearch.entity().getHostId(), SearchCriteria.Op.EQ);
7377
ImplicitTagsSearch.and("isImplicit", ImplicitTagsSearch.entity().getIsImplicit(), SearchCriteria.Op.EQ);
7478
ImplicitTagsSearch.done();
79+
80+
tagSearch = createSearchBuilder(String.class);
81+
tagSearch.selectFields(tagSearch.entity().getTag());
82+
tagSearch.and("hostIdIN", tagSearch.entity().getHostId(), SearchCriteria.Op.IN);
83+
tagSearch.done();
7584
}
7685

7786
@Override
@@ -235,4 +244,15 @@ public List<HostTagVO> searchByIds(Long... tagIds) {
235244

236245
return tagList;
237246
}
247+
248+
@Override
249+
public List<String> listByClusterId(Long clusterId) {
250+
List<Long> hostIds = hostDao.listIdsByClusterId(clusterId);
251+
if (CollectionUtils.isEmpty(hostIds)) {
252+
return new ArrayList<>();
253+
}
254+
SearchCriteria<String> sc = tagSearch.create();
255+
sc.setParameters("hostIdIN", hostIds.toArray());
256+
return customSearch(sc, null);
257+
}
238258
}

engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ protected void init() {
193193
PersistentNetworkSearch.and("id", PersistentNetworkSearch.entity().getId(), Op.NEQ);
194194
PersistentNetworkSearch.and("guestType", PersistentNetworkSearch.entity().getGuestType(), Op.IN);
195195
PersistentNetworkSearch.and("broadcastUri", PersistentNetworkSearch.entity().getBroadcastUri(), Op.EQ);
196+
PersistentNetworkSearch.and("dc", PersistentNetworkSearch.entity().getDataCenterId(), Op.EQ);
196197
PersistentNetworkSearch.and("removed", PersistentNetworkSearch.entity().getRemoved(), Op.NULL);
197198
final SearchBuilder<NetworkOfferingVO> persistentNtwkOffJoin = _ntwkOffDao.createSearchBuilder();
198199
persistentNtwkOffJoin.and("persistent", persistentNtwkOffJoin.entity().isPersistent(), Op.EQ);

engine/schema/src/main/resources/META-INF/db/schema-42200to42210-cleanup.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@
1818
--;
1919
-- Schema upgrade cleanup from 4.22.0.0 to 4.22.1.0
2020
--;
21-
22-
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;

engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ UPDATE `cloud`.`alert` SET type = 34 WHERE name = 'ALERT.VR.PRIVATE.IFACE.MTU';
3535
UPDATE `cloud`.`configuration` SET description = 'True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations', is_dynamic = 1 WHERE name = 'kvm.ssh.to.agent';
3636

3737
UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
38+
39+
-- Update existing vm_template records with NULL type to "USER"
40+
UPDATE `cloud`.`vm_template` SET `type` = 'USER' WHERE `type` IS NULL;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- cloud.account_netstats_view source
19+
20+
21+
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;
22+
23+
CREATE VIEW `cloud`.`account_netstats_view` AS
24+
select
25+
`user_statistics`.`account_id` AS `account_id`,
26+
(sum(`user_statistics`.`net_bytes_received`) + sum(`user_statistics`.`current_bytes_received`)) AS `bytesReceived`,
27+
(sum(`user_statistics`.`net_bytes_sent`) + sum(`user_statistics`.`current_bytes_sent`)) AS `bytesSent`
28+
from
29+
`user_statistics`
30+
group by
31+
`user_statistics`.`account_id`;

engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ select
3939
`data_center`.`id` AS `data_center_id`,
4040
`data_center`.`uuid` AS `data_center_uuid`,
4141
`data_center`.`name` AS `data_center_name`,
42-
`account_netstats`.`bytesReceived` AS `bytesReceived`,
43-
`account_netstats`.`bytesSent` AS `bytesSent`,
42+
`account_netstats_view`.`bytesReceived` AS `bytesReceived`,
43+
`account_netstats_view`.`bytesSent` AS `bytesSent`,
4444
`vmlimit`.`max` AS `vmLimit`,
4545
`vmcount`.`count` AS `vmTotal`,
4646
`runningvm`.`vmcount` AS `runningVms`,
@@ -89,15 +89,8 @@ from
8989
`cloud`.`domain` ON account.domain_id = domain.id
9090
left join
9191
`cloud`.`data_center` ON account.default_zone_id = data_center.id
92-
left join lateral (
93-
select
94-
coalesce(sum(`user_statistics`.`net_bytes_received` + `user_statistics`.`current_bytes_received`), 0) AS `bytesReceived`,
95-
coalesce(sum(`user_statistics`.`net_bytes_sent` + `user_statistics`.`current_bytes_sent`), 0) AS `bytesSent`
96-
from
97-
`cloud`.`user_statistics`
98-
where
99-
`user_statistics`.`account_id` = `account`.`id`
100-
) AS `account_netstats` ON TRUE
92+
left join
93+
`cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id
10194
left join
10295
`cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id
10396
and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ private Pair<List<PrimaryDataStoreTO>, List<String>> getVolumePoolsAndPaths(List
351351
volumePools.add(dataStore != null ? (PrimaryDataStoreTO)dataStore.getTO() : null);
352352

353353
String volumePathPrefix = getVolumePathPrefix(storagePool);
354-
volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
354+
String volumePathSuffix = getVolumePathSuffix(storagePool);
355+
volumePaths.add(String.format("%s%s%s", volumePathPrefix, volume.getPath(), volumePathSuffix));
355356
}
356357
return new Pair<>(volumePools, volumePaths);
357358
}
@@ -361,14 +362,24 @@ private String getVolumePathPrefix(StoragePoolVO storagePool) {
361362
if (ScopeType.HOST.equals(storagePool.getScope()) ||
362363
Storage.StoragePoolType.SharedMountPoint.equals(storagePool.getPoolType()) ||
363364
Storage.StoragePoolType.RBD.equals(storagePool.getPoolType())) {
364-
volumePathPrefix = storagePool.getPath();
365+
volumePathPrefix = storagePool.getPath() + "/";
366+
} else if (Storage.StoragePoolType.Linstor.equals(storagePool.getPoolType())) {
367+
volumePathPrefix = "/dev/drbd/by-res/cs-";
365368
} else {
366369
// Should be Storage.StoragePoolType.NetworkFilesystem
367-
volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid());
370+
volumePathPrefix = String.format("/mnt/%s/", storagePool.getUuid());
368371
}
369372
return volumePathPrefix;
370373
}
371374

375+
private String getVolumePathSuffix(StoragePoolVO storagePool) {
376+
if (Storage.StoragePoolType.Linstor.equals(storagePool.getPoolType())) {
377+
return "/0";
378+
} else {
379+
return "";
380+
}
381+
}
382+
372383
@Override
373384
public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, Backup.VolumeInfo backupVolumeInfo, String hostIp, String dataStoreUuid, Pair<String, VirtualMachine.State> vmNameAndState) {
374385
final VolumeVO volume = volumeDao.findByUuid(backupVolumeInfo.getUuid());
@@ -413,7 +424,9 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, Backup.VolumeI
413424
restoreCommand.setBackupRepoType(backupRepository.getType());
414425
restoreCommand.setBackupRepoAddress(backupRepository.getAddress());
415426
restoreCommand.setVmName(vmNameAndState.first());
416-
restoreCommand.setRestoreVolumePaths(Collections.singletonList(String.format("%s/%s", getVolumePathPrefix(pool), volumeUUID)));
427+
String restoreVolumePath = String.format("%s%s%s", getVolumePathPrefix(pool), volumeUUID, getVolumePathSuffix(pool));
428+
restoreCommand.setRestoreVolumePaths(Collections.singletonList(restoreVolumePath));
429+
restoreCommand.setRestoreVolumeSizes(Collections.singletonList(backedUpVolumeSize));
417430
DataStore dataStore = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
418431
restoreCommand.setRestoreVolumePools(Collections.singletonList(dataStore != null ? (PrimaryDataStoreTO)dataStore.getTO() : null));
419432
restoreCommand.setDiskType(backupVolumeInfo.getType().name().toLowerCase(Locale.ROOT));

0 commit comments

Comments
 (0)