Skip to content

Commit edb62b4

Browse files
author
Daan Hoogland
committed
Merge branch '4.20' into 4.22
2 parents 315cd52 + bbc23a7 commit edb62b4

File tree

28 files changed

+138
-51
lines changed

28 files changed

+138
-51
lines changed

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface QueryService {
120120

121121
ConfigKey<String> UserVMReadOnlyDetails = new ConfigKey<>(String.class,
122122
"user.vm.readonly.details", "Advanced", "dataDiskController, rootDiskController",
123-
"List of read-only VM settings/details as comma separated string", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
123+
"List of read-only VM settings/details as comma separated string", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null, "");
124124

125125
ConfigKey<Boolean> SortKeyAscending = new ConfigKey<>("Advanced", Boolean.class, "sortkey.algorithm", "true",
126126
"Sort algorithm - ascending or descending - to use. For entities that use sort key(template, disk offering, service offering, " +

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
4848

4949
List<VolumeVO> findIncludingRemovedByInstanceAndType(long id, Volume.Type vType);
5050

51-
List<VolumeVO> findByInstanceIdAndPoolId(long instanceId, long poolId);
51+
List<VolumeVO> findNonDestroyedVolumesByInstanceIdAndPoolId(long instanceId, long poolId);
5252

5353
List<VolumeVO> findByInstanceIdDestroyed(long vmId);
5454

@@ -70,11 +70,11 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
7070

7171
List<VolumeVO> findCreatedByInstance(long id);
7272

73-
List<VolumeVO> findByPoolId(long poolId);
73+
List<VolumeVO> findNonDestroyedVolumesByPoolId(long poolId);
7474

7575
VolumeVO findByPoolIdName(long poolId, String name);
7676

77-
List<VolumeVO> findByPoolId(long poolId, Volume.Type volumeType);
77+
List<VolumeVO> findNonDestroyedVolumesByPoolId(long poolId, Volume.Type volumeType);
7878

7979
List<VolumeVO> findByPoolIdAndState(long poolid, Volume.State state);
8080

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId)
136136
}
137137

138138
@Override
139-
public List<VolumeVO> findByPoolId(long poolId) {
139+
public List<VolumeVO> findNonDestroyedVolumesByPoolId(long poolId) {
140140
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
141141
sc.setParameters("poolId", poolId);
142142
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);
@@ -145,7 +145,7 @@ public List<VolumeVO> findByPoolId(long poolId) {
145145
}
146146

147147
@Override
148-
public List<VolumeVO> findByInstanceIdAndPoolId(long instanceId, long poolId) {
148+
public List<VolumeVO> findNonDestroyedVolumesByInstanceIdAndPoolId(long instanceId, long poolId) {
149149
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
150150
sc.setParameters("instanceId", instanceId);
151151
sc.setParameters("poolId", poolId);
@@ -162,7 +162,7 @@ public VolumeVO findByPoolIdName(long poolId, String name) {
162162
}
163163

164164
@Override
165-
public List<VolumeVO> findByPoolId(long poolId, Volume.Type volumeType) {
165+
public List<VolumeVO> findNonDestroyedVolumesByPoolId(long poolId, Volume.Type volumeType) {
166166
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
167167
sc.setParameters("poolId", poolId);
168168
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);

engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ static String getProgramToGenerateIso() throws IOException {
231231
throw new CloudRuntimeException("Cannot create ISO for config drive using any know tool. Known paths [/usr/bin/genisoimage, /usr/bin/mkisofs, /usr/local/bin/mkisofs]");
232232
}
233233
if (!isoCreator.canExecute()) {
234-
throw new CloudRuntimeException("Cannot create ISO for config drive using: " + isoCreator.getCanonicalPath());
234+
throw new CloudRuntimeException("Cannot create ISO for config drive using: " + isoCreator.getAbsolutePath());
235235
}
236-
return isoCreator.getCanonicalPath();
236+
return isoCreator.getAbsolutePath();
237237
}
238238

239239
/**

engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public void getProgramToGenerateIsoTestGenIsoExistsAndIsExecutable() throws Exce
435435

436436
Mockito.verify(genIsoFileMock, Mockito.times(2)).exists();
437437
Mockito.verify(genIsoFileMock).canExecute();
438-
Mockito.verify(genIsoFileMock).getCanonicalPath();
438+
Mockito.verify(genIsoFileMock).getAbsolutePath();
439439
}
440440
}
441441

@@ -475,11 +475,11 @@ public void getProgramToGenerateIsoTestNotGenIsoMkIsoInLinux() throws Exception
475475

476476
Mockito.verify(genIsoFileMock, Mockito.times(1)).exists();
477477
Mockito.verify(genIsoFileMock, Mockito.times(0)).canExecute();
478-
Mockito.verify(genIsoFileMock, Mockito.times(0)).getCanonicalPath();
478+
Mockito.verify(genIsoFileMock, Mockito.times(0)).getAbsolutePath();
479479

480480
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(2)).exists();
481481
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).canExecute();
482-
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).getCanonicalPath();
482+
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).getAbsolutePath();
483483
}
484484
}
485485

@@ -509,15 +509,15 @@ public void getProgramToGenerateIsoTestMkIsoMac() throws Exception {
509509

510510
Mockito.verify(genIsoFileMock, Mockito.times(1)).exists();
511511
Mockito.verify(genIsoFileMock, Mockito.times(0)).canExecute();
512-
Mockito.verify(genIsoFileMock, Mockito.times(0)).getCanonicalPath();
512+
Mockito.verify(genIsoFileMock, Mockito.times(0)).getAbsolutePath();
513513

514514
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).exists();
515515
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(0)).canExecute();
516-
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(0)).getCanonicalPath();
516+
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(0)).getAbsolutePath();
517517

518518
Mockito.verify(mkIsoProgramInMacOsFileMock, Mockito.times(1)).exists();
519519
Mockito.verify(mkIsoProgramInMacOsFileMock, Mockito.times(1)).canExecute();
520-
Mockito.verify(mkIsoProgramInMacOsFileMock, Mockito.times(1)).getCanonicalPath();
520+
Mockito.verify(mkIsoProgramInMacOsFileMock, Mockito.times(1)).getAbsolutePath();
521521
}
522522
}
523523

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected Void migrateDataCallBack(AsyncCallbackDispatcher<SecondaryStorageServi
280280
private void updateDataObject(DataObject srcData, DataObject destData) {
281281
if (destData instanceof SnapshotInfo) {
282282
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySourceSnapshot(srcData.getId(), DataStoreRole.Image);
283-
SnapshotDataStoreVO destSnapshotStore = snapshotStoreDao.findByStoreSnapshot(DataStoreRole.Image, srcData.getDataStore().getId(), srcData.getId());
283+
SnapshotDataStoreVO destSnapshotStore = snapshotStoreDao.findByStoreSnapshot(DataStoreRole.Image, destData.getDataStore().getId(), destData.getId());
284284
if (snapshotStore != null && destSnapshotStore != null) {
285285
destSnapshotStore.setPhysicalSize(snapshotStore.getPhysicalSize());
286286
destSnapshotStore.setCreated(snapshotStore.getCreated());

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ public TemplateInfo getReadyBypassedTemplateOnManagedStorage(long templateId, Te
296296
@Override
297297
public boolean isTemplateMarkedForDirectDownload(long templateId) {
298298
VMTemplateVO templateVO = imageDataDao.findById(templateId);
299+
if (templateVO == null) {
300+
throw new CloudRuntimeException(String.format("Template not found with ID: %s", templateId));
301+
}
299302
return templateVO.isDirectDownload();
300303
}
301304
}

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,10 @@ public void addSystemVMTemplatesToSecondary(DataStore store) {
13201320
if (_vmTemplateStoreDao.isTemplateMarkedForDirectDownload(tmplt.getId())) {
13211321
continue;
13221322
}
1323-
tmpltStore =
1324-
new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null,
1325-
TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + '/', tmplt.getUrl());
1323+
String templateDirectoryPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + File.separator + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR;
1324+
String installPath = templateDirectoryPath + tmplt.getAccountId() + File.separator + tmplt.getId() + File.separator;
1325+
tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED,
1326+
null, null, null, installPath, tmplt.getUrl());
13261327
tmpltStore.setSize(0L);
13271328
tmpltStore.setPhysicalSize(0); // no size information for
13281329
// pre-seeded system vm templates

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public VolumeInfo getVolume(long id) {
126126

127127
@Override
128128
public List<VolumeInfo> getVolumes() {
129-
List<VolumeVO> volumes = volumeDao.findByPoolId(getId());
129+
List<VolumeVO> volumes = volumeDao.findNonDestroyedVolumesByPoolId(getId());
130130
List<VolumeInfo> volumeInfos = new ArrayList<VolumeInfo>();
131131
for (VolumeVO volume : volumes) {
132132
volumeInfos.add(VolumeObject.getVolumeObject(this, volume));

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,18 @@ public String toString() {
267267

268268
static ConfigDepotImpl s_depot = null;
269269

270-
static public void init(ConfigDepotImpl depot) {
270+
private String _defaultValueIfEmpty = null;
271+
272+
public static void init(ConfigDepotImpl depot) {
271273
s_depot = depot;
272274
}
273275

276+
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,
277+
String displayText, String parent, Ternary<String, String, Long> group, Pair<String, Long> subGroup, Kind kind, String options, String defaultValueIfEmpty) {
278+
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, displayText, parent, group, subGroup, kind, options);
279+
this._defaultValueIfEmpty = defaultValueIfEmpty;
280+
}
281+
274282
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) {
275283
this(type, name, category, defaultValue, description, isDynamic, scope, null);
276284
}
@@ -380,7 +388,19 @@ public boolean isSameKeyAs(Object obj) {
380388
public T value() {
381389
if (_value == null || isDynamic()) {
382390
String value = s_depot != null ? s_depot.getConfigStringValue(_name, Scope.Global, null) : null;
383-
_value = valueOf((value == null) ? defaultValue() : value);
391+
392+
String effective;
393+
if (value != null) {
394+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
395+
effective = _defaultValueIfEmpty;
396+
} else {
397+
effective = value;
398+
}
399+
} else {
400+
effective = _defaultValueIfEmpty != null ? _defaultValueIfEmpty : defaultValue();
401+
}
402+
403+
_value = valueOf(effective);
384404
}
385405
return _value;
386406
}
@@ -409,6 +429,10 @@ public T valueInScope(Scope scope, Long id) {
409429
return valueInGlobalOrAvailableParentScope(scope, id);
410430
}
411431
logger.trace("Scope({}) value for config ({}): {}", scope, _name, _value);
432+
433+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
434+
return valueOf(_defaultValueIfEmpty);
435+
}
412436
return valueOf(value);
413437
}
414438

0 commit comments

Comments
 (0)