Skip to content

Commit d72a05a

Browse files
authored
Add special Icon to Shared FileSystem Instances (#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 d5f6b7c commit d72a05a

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
@@ -140,13 +140,18 @@ private String getStorageVmConfig(final String fileSystem, final String hypervis
140140
return fsVmConfig;
141141
}
142142

143-
private String getStorageVmName(String fileShareName) {
143+
private String getStorageVmPrefix(String fileShareName) {
144144
String prefix = String.format("%s-%s", SharedFSVmNamePrefix, fileShareName);
145-
String suffix = Long.toHexString(System.currentTimeMillis());
146-
147145
if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
148146
prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
149147
}
148+
return prefix;
149+
}
150+
151+
private String getStorageVmName(String fileShareName) {
152+
String prefix = getStorageVmPrefix(fileShareName);
153+
String suffix = Long.toHexString(System.currentTimeMillis());
154+
150155
int nameLength = prefix.length() + suffix.length() + SharedFSVmNamePrefix.length();
151156
if (nameLength > 63) {
152157
int prefixLength = prefix.length() - (nameLength - 63);
@@ -236,8 +241,18 @@ public Pair<Long, Long> deploySharedFS(SharedFS sharedFS, Long networkId, Long d
236241
Account owner = accountMgr.getActiveAccountById(sharedFS.getAccountId());
237242
UserVm vm = deploySharedFSVM(sharedFS.getDataCenterId(), owner, List.of(networkId), sharedFS.getName(), sharedFS.getServiceOfferingId(), diskOfferingId, sharedFS.getFsType(), size, minIops, maxIops);
238243

239-
List<VolumeVO> volumes = volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.DATADISK);
240-
return new Pair<>(volumes.get(0).getId(), vm.getId());
244+
List<VolumeVO> volumes = volumeDao.findByInstance(vm.getId());
245+
VolumeVO dataVol = null;
246+
for (VolumeVO vol : volumes) {
247+
String volumeName = vol.getName();
248+
String updatedVolumeName = SharedFSVmNamePrefix + "-" + volumeName;
249+
vol.setName(updatedVolumeName);
250+
volumeDao.update(vol.getId(), vol);
251+
if (vol.getVolumeType() == Volume.Type.DATADISK) {
252+
dataVol = vol;
253+
}
254+
}
255+
return new Pair<>(dataVol.getId(), vm.getId());
241256
}
242257

243258
@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
@@ -260,9 +260,14 @@ public void testDeploySharedFS() throws ResourceUnavailableException, Insufficie
260260
anyMap(), isNull(), isNull(), isNull(), isNull(),
261261
anyBoolean(), anyString(), isNull())).thenReturn(vm);
262262

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

267272
Pair<Long, Long> result = lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops);
268273
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="(resource.icon && resource.icon.base64image || images.template || images.iso || resourceIcon) && !['router', 'systemvm', 'volume'].includes($route.path.split('/')[1])">
3535
<resource-icon :image="getImage(resource.icon && resource.icon.base64image || images.template || images.iso || 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.name" size="3x" @update-osname="setResourceOsType"/>
3942
<render-icon v-else-if="typeof $route.meta.icon ==='string'" style="font-size: 36px" :icon="$route.meta.icon" />
@@ -876,6 +879,7 @@ import UploadResourceIcon from '@/components/view/UploadResourceIcon'
876879
import eventBus from '@/config/eventBus'
877880
import ResourceIcon from '@/components/view/ResourceIcon'
878881
import ResourceLabel from '@/components/widgets/ResourceLabel'
882+
import { FileTextOutlined } from '@ant-design/icons-vue'
879883
880884
export default {
881885
name: 'InfoCard',
@@ -887,7 +891,8 @@ export default {
887891
TooltipButton,
888892
UploadResourceIcon,
889893
ResourceIcon,
890-
ResourceLabel
894+
ResourceLabel,
895+
FileTextOutlined
891896
},
892897
props: {
893898
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" >
@@ -591,6 +594,7 @@ import { createPathBasedOnVmType } from '@/utils/plugins'
591594
import { validateLinks } from '@/utils/links'
592595
import cronstrue from 'cronstrue/i18n'
593596
import moment from 'moment-timezone'
597+
import { FileTextOutlined } from '@ant-design/icons-vue'
594598
595599
export default {
596600
name: 'ListView',
@@ -601,7 +605,8 @@ export default {
601605
CopyLabel,
602606
TooltipButton,
603607
ResourceIcon,
604-
ResourceLabel
608+
ResourceLabel,
609+
FileTextOutlined
605610
},
606611
props: {
607612
columns: {

0 commit comments

Comments
 (0)