Skip to content

Commit 3628e59

Browse files
abh1sardhslove
authored andcommitted
Add special Icon to Shared FileSystem Instances (apache#10857)
* Use special icon for sharedfs instance and prefix for sharedfs volumes * Give custom icon precedence over shared fs icon * Fix sharedfsvm icon size * Fix UT failure in StorageVmSharedFSLifeCycleTest
1 parent 1e9ae76 commit 3628e59

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,18 @@ private String getStorageVmConfig(final String fileSystem, final String hypervis
136136
return fsVmConfig;
137137
}
138138

139-
private String getStorageVmName(String fileShareName) {
139+
private String getStorageVmPrefix(String fileShareName) {
140140
String prefix = String.format("%s-%s", SharedFSVmNamePrefix, fileShareName);
141-
String suffix = Long.toHexString(System.currentTimeMillis());
142-
143141
if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
144142
prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
145143
}
144+
return prefix;
145+
}
146+
147+
private String getStorageVmName(String fileShareName) {
148+
String prefix = getStorageVmPrefix(fileShareName);
149+
String suffix = Long.toHexString(System.currentTimeMillis());
150+
146151
int nameLength = prefix.length() + suffix.length() + SharedFSVmNamePrefix.length();
147152
if (nameLength > 63) {
148153
int prefixLength = prefix.length() - (nameLength - 63);
@@ -232,8 +237,18 @@ public Pair<Long, Long> deploySharedFS(SharedFS sharedFS, Long networkId, Long d
232237
Account owner = accountMgr.getActiveAccountById(sharedFS.getAccountId());
233238
UserVm vm = deploySharedFSVM(sharedFS.getDataCenterId(), owner, List.of(networkId), sharedFS.getName(), sharedFS.getServiceOfferingId(), diskOfferingId, sharedFS.getFsType(), size, minIops, maxIops);
234239

235-
List<VolumeVO> volumes = volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.DATADISK);
236-
return new Pair<>(volumes.get(0).getId(), vm.getId());
240+
List<VolumeVO> volumes = volumeDao.findByInstance(vm.getId());
241+
VolumeVO dataVol = null;
242+
for (VolumeVO vol : volumes) {
243+
String volumeName = vol.getName();
244+
String updatedVolumeName = SharedFSVmNamePrefix + "-" + volumeName;
245+
vol.setName(updatedVolumeName);
246+
volumeDao.update(vol.getId(), vol);
247+
if (vol.getVolumeType() == Volume.Type.DATADISK) {
248+
dataVol = vol;
249+
}
250+
}
251+
return new Pair<>(dataVol.getId(), vm.getId());
237252
}
238253

239254
@Override

plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,14 @@ public void testDeploySharedFS() throws ResourceUnavailableException, Insufficie
259259
anyMap(), isNull(), isNull(), isNull(), isNull(),
260260
anyBoolean(), anyString(), isNull(), isNull(), isNull())).thenReturn(vm);
261261

262-
VolumeVO volume = mock(VolumeVO.class);
263-
when(volume.getId()).thenReturn(s_volumeId);
264-
when(volumeDao.findByInstanceAndType(s_vmId, Volume.Type.DATADISK)).thenReturn(List.of(volume));
262+
VolumeVO rootVol = mock(VolumeVO.class);
263+
when(rootVol.getVolumeType()).thenReturn(Volume.Type.ROOT);
264+
when(rootVol.getName()).thenReturn("ROOT-1");
265+
VolumeVO dataVol = mock(VolumeVO.class);
266+
when(dataVol.getId()).thenReturn(s_volumeId);
267+
when(dataVol.getName()).thenReturn("DATA-1");
268+
when(dataVol.getVolumeType()).thenReturn(Volume.Type.DATADISK);
269+
when(volumeDao.findByInstance(s_vmId)).thenReturn(List.of(rootVol, dataVol));
265270

266271
Pair<Long, Long> result = lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops);
267272
Assert.assertEquals(Optional.ofNullable(result.first()), Optional.ofNullable(s_volumeId));

ui/src/components/view/InfoCard.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<span v-if="resourceIcon && !['router', 'systemvm', 'volume'].includes($route.path.split('/')[1])">
3535
<resource-icon :image="resourceIcon" size="4x" style="margin-right: 5px"/>
3636
</span>
37+
<span v-else-if="resource.vmtype === 'sharedfsvm'">
38+
<file-text-outlined style="font-size: 36px;" />
39+
</span>
3740
<span v-else>
3841
<os-logo v-if="resource.ostypeid || resource.ostypename || ['guestoscategory'].includes($route.path.split('/')[1])" :osId="resource.ostypeid" :osName="resource.ostypename || resource.osdisplayname || resource.name" size="3x" />
3942
<render-icon v-else-if="typeof $route.meta.icon ==='string'" style="font-size: 36px" :icon="$route.meta.icon" />
@@ -1066,6 +1069,7 @@ import eventBus from '@/config/eventBus'
10661069
import ResourceIcon from '@/components/view/ResourceIcon'
10671070
import ResourceLabel from '@/components/widgets/ResourceLabel'
10681071
import ImageDeployInstanceButton from '@/components/view/ImageDeployInstanceButton'
1072+
import { FileTextOutlined } from '@ant-design/icons-vue'
10691073
10701074
export default {
10711075
name: 'InfoCard',
@@ -1078,7 +1082,8 @@ export default {
10781082
UploadResourceIcon,
10791083
ResourceIcon,
10801084
ResourceLabel,
1081-
ImageDeployInstanceButton
1085+
ImageDeployInstanceButton,
1086+
FileTextOutlined
10821087
},
10831088
props: {
10841089
resource: {

ui/src/components/view/ListView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<span v-if="record.icon && record.icon.base64image">
4545
<resource-icon :image="record.icon.base64image" size="2x"/>
4646
</span>
47+
<span v-else-if="record.vmtype === 'sharedfsvm'">
48+
<file-text-outlined style="font-size: 18px;" />
49+
</span>
4750
<os-logo v-else :osId="record.ostypeid" :osName="record.osdisplayname" size="xl" />
4851
</span>
4952
<span style="min-width: 120px" >
@@ -675,6 +678,7 @@ import { createPathBasedOnVmType } from '@/utils/plugins'
675678
import { validateLinks } from '@/utils/links'
676679
import cronstrue from 'cronstrue/i18n'
677680
import moment from 'moment-timezone'
681+
import { FileTextOutlined } from '@ant-design/icons-vue'
678682
679683
export default {
680684
name: 'ListView',
@@ -685,7 +689,8 @@ export default {
685689
CopyLabel,
686690
TooltipButton,
687691
ResourceIcon,
688-
ResourceLabel
692+
ResourceLabel,
693+
FileTextOutlined
689694
},
690695
props: {
691696
columns: {

0 commit comments

Comments
 (0)