Skip to content

Commit 49cd5ba

Browse files
authored
Fix link to removed volumes being shown in info card and list view (#8833)
* Framework for validating links in the front-end * Rename valid links map in the list view
1 parent 54c8b71 commit 49cd5ba

File tree

9 files changed

+77
-3
lines changed

9 files changed

+77
-3
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ public class ApiConstants {
576576
public static final String AGGREGATE_NAME = "aggregatename";
577577
public static final String POOL_NAME = "poolname";
578578
public static final String VOLUME_NAME = "volumename";
579+
public static final String VOLUME_STATE = "volumestate";
579580
public static final String SNAPSHOT_POLICY = "snapshotpolicy";
580581
public static final String SNAPSHOT_RESERVATION = "snapshotreservation";
581582
public static final String IP_NETWORK_LIST = "iptonetworklist";

api/src/main/java/org/apache/cloudstack/api/response/SnapshotResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public class SnapshotResponse extends BaseResponseWithTagInformation implements
7171
@Param(description = "type of the disk volume")
7272
private String volumeType;
7373

74+
@SerializedName(ApiConstants.VOLUME_STATE)
75+
@Param(description = "state of the disk volume")
76+
private String volumeState;
77+
7478
@SerializedName(ApiConstants.CREATED)
7579
@Param(description = " the date the snapshot was created")
7680
private Date created;
@@ -199,6 +203,10 @@ public void setVolumeType(String volumeType) {
199203
this.volumeType = volumeType;
200204
}
201205

206+
public void setVolumeState(String volumeState) {
207+
this.volumeState = volumeState;
208+
}
209+
202210
public void setCreated(Date created) {
203211
this.created = created;
204212
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SELECT
4848
`volumes`.`uuid` AS `volume_uuid`,
4949
`volumes`.`name` AS `volume_name`,
5050
`volumes`.`volume_type` AS `volume_type`,
51+
`volumes`.`state` AS `volume_state`,
5152
`volumes`.`size` AS `volume_size`,
5253
`data_center`.`id` AS `data_center_id`,
5354
`data_center`.`uuid` AS `data_center_uuid`,

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ public SnapshotResponse createSnapshotResponse(Snapshot snapshot) {
659659
snapshotResponse.setVolumeId(volume.getUuid());
660660
snapshotResponse.setVolumeName(volume.getName());
661661
snapshotResponse.setVolumeType(volume.getVolumeType().name());
662+
snapshotResponse.setVolumeState(volume.getState().name());
662663
snapshotResponse.setVirtualSize(volume.getSize());
663664
DataCenter zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
664665
if (zone != null) {

server/src/main/java/com/cloud/api/query/dao/SnapshotJoinDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public SnapshotResponse newSnapshotResponse(ResponseObject.ResponseView view, bo
128128
snapshotResponse.setVolumeId(snapshot.getVolumeUuid());
129129
snapshotResponse.setVolumeName(snapshot.getVolumeName());
130130
snapshotResponse.setVolumeType(snapshot.getVolumeType().name());
131+
snapshotResponse.setVolumeState(snapshot.getVolumeState().name());
131132
snapshotResponse.setVirtualSize(snapshot.getVolumeSize());
132133
VolumeVO volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId());
133134
if (volume != null && volume.getVolumeType() == Type.ROOT && volume.getInstanceId() != null) {

server/src/main/java/com/cloud/api/query/vo/SnapshotJoinVO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public class SnapshotJoinVO extends BaseViewWithTagInformationVO implements Cont
130130
@Enumerated(EnumType.STRING)
131131
Volume.Type volumeType = Volume.Type.UNKNOWN;
132132

133+
@Column(name = "volume_state")
134+
@Enumerated(EnumType.STRING)
135+
Volume.State volumeState;
136+
133137
@Column(name = "volume_size")
134138
Long volumeSize;
135139

@@ -297,6 +301,10 @@ public Volume.Type getVolumeType() {
297301
return volumeType;
298302
}
299303

304+
public Volume.State getVolumeState() {
305+
return volumeState;
306+
}
307+
300308
public Long getVolumeSize() {
301309
return volumeSize;
302310
}

ui/src/components/view/InfoCard.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@
442442
<div class="resource-detail-item__label">{{ $t('label.volume') }}</div>
443443
<div class="resource-detail-item__details">
444444
<hdd-outlined />
445-
<router-link :to="{ path: '/volume/' + resource.volumeid }">{{ resource.volumename || resource.volume || resource.volumeid }} </router-link>
445+
<router-link v-if="validLinks.volume" :to="{ path: '/volume/' + resource.volumeid }">{{ resource.volumename || resource.volume || resource.volumeid }} </router-link>
446+
<span v-else>{{ resource.volumename || resource.volume || resource.volumeid }}</span>
446447
</div>
447448
</div>
448449
<div class="resource-detail-item" v-if="resource.associatednetworkid">
@@ -783,6 +784,7 @@
783784
<script>
784785
import { api } from '@/api'
785786
import { createPathBasedOnVmType } from '@/utils/plugins'
787+
import { validateLinks } from '@/utils/links'
786788
import Console from '@/components/widgets/Console'
787789
import OsLogo from '@/components/widgets/OsLogo'
788790
import Status from '@/components/widgets/Status'
@@ -848,7 +850,8 @@ export default {
848850
vpc: '',
849851
network: ''
850852
},
851-
newResource: {}
853+
newResource: {},
854+
validLinks: {}
852855
}
853856
},
854857
watch: {
@@ -865,6 +868,7 @@ export default {
865868
this.newResource = newData
866869
this.showKeys = false
867870
this.setData()
871+
this.validLinks = validateLinks(this.$router, this.isStatic, this.resource)
868872
869873
if ('apikey' in this.resource) {
870874
this.getUserKeys()

ui/src/components/view/ListView.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@
167167
<router-link :to="{ path: getVmRouteUsingType(record) + record.virtualmachineid }">{{ text }}</router-link>
168168
</template>
169169
<template v-if="column.key === 'volumename'">
170-
<router-link :to="{ path: '/volume/' + record.volumeid }">{{ text }}</router-link>
170+
<router-link v-if="resourceIdToValidLinksMap[record.id]?.volume" :to="{ path: '/volume/' + record.volumeid }">{{ text }}</router-link>
171+
<span v-else>{{ text }}</span>
171172
</template>
172173
<template v-if="column.key === 'size'">
173174
<span v-if="text && $route.path === '/kubernetes'">
@@ -488,6 +489,7 @@ import TooltipButton from '@/components/widgets/TooltipButton'
488489
import ResourceIcon from '@/components/view/ResourceIcon'
489490
import ResourceLabel from '@/components/widgets/ResourceLabel'
490491
import { createPathBasedOnVmType } from '@/utils/plugins'
492+
import { validateLinks } from '@/utils/links'
491493
import cronstrue from 'cronstrue/i18n'
492494
import moment from 'moment-timezone'
493495
@@ -576,6 +578,18 @@ export default {
576578
notification: 'storageallocatedthreshold',
577579
disable: 'storageallocateddisablethreshold'
578580
}
581+
},
582+
resourceIdToValidLinksMap: {}
583+
}
584+
},
585+
watch: {
586+
items: {
587+
deep: true,
588+
handler (newData, oldData) {
589+
if (newData === oldData) return
590+
this.items.forEach(record => {
591+
this.resourceIdToValidLinksMap[record.id] = validateLinks(this.$router, false, record)
592+
})
579593
}
580594
}
581595
},

ui/src/utils/links.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
export function validateLinks (router, isStatic, resource) {
19+
const validLinks = {
20+
volume: false
21+
}
22+
23+
if (isStatic) {
24+
return validLinks
25+
}
26+
27+
if (resource.volumeid && router.resolve('/volume/' + resource.volumeid).matched[0].redirect !== '/exception/404') {
28+
if (resource.volumestate) {
29+
validLinks.volume = resource.volumestate !== 'Expunged'
30+
} else {
31+
validLinks.volume = true
32+
}
33+
}
34+
35+
return validLinks
36+
}

0 commit comments

Comments
 (0)