Skip to content

Commit 512ba72

Browse files
author
Zhang Wenhao
committed
<fix>[localstorage]: fix error message in LocalStorageMainAllocatorFlow
This patch is for zsv_4.10.28 Related: ZSV-10444 Change-Id: I68786e677666656666746868766d646c67616b69
1 parent 8d6e830 commit 512ba72

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

plugin/localstorage/src/main/java/org/zstack/storage/primary/local/LocalStorageMainAllocatorFlow.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public class LocalStorageMainAllocatorFlow extends NoRollbackFlow {
4343

4444
private class Result {
4545
List<PrimaryStorageVO> result;
46-
String errStr;
47-
List<ErrorCode> causes = new ArrayList<>();
46+
ErrorCode errorCode;
4847
}
4948

5049
@Transactional(readOnly = true)
@@ -77,7 +76,7 @@ private Result allocate(Map data) {
7776
query.setParameter("hstate", HostState.Enabled);
7877
query.setParameter("hstatus", HostStatus.Connected);
7978
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
80-
ret.errStr = i18n("the required host[uuid:%s] cannot satisfy conditions[state: %s, status: %s, size > %s bytes]," +
79+
ret.errorCode = operr("the required host[uuid:%s] cannot satisfy conditions[state: %s, status: %s, size > %s bytes]," +
8180
" or doesn't belong to a local primary storage satisfying conditions[state: %s, status: %s]," +
8281
" or its cluster doesn't attach to any local primary storage",
8382
spec.getRequiredHostUuid(),
@@ -105,7 +104,7 @@ private Result allocate(Map data) {
105104
query.setParameter("hstate", HostState.Enabled);
106105
query.setParameter("hstatus", HostStatus.Connected);
107106
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
108-
ret.errStr = i18n("no local primary storage in zone[uuid:%s] can satisfy conditions[state: %s, status: %s]" +
107+
ret.errorCode = operr("no local primary storage in zone[uuid:%s] can satisfy conditions[state: %s, status: %s]" +
109108
" or contain hosts satisfying conditions[state: %s, status: %s, size > %s bytes]",
110109
spec.getRequiredZoneUuid(),
111110
PrimaryStorageState.Enabled,
@@ -131,7 +130,7 @@ private Result allocate(Map data) {
131130
query.setParameter("hstatus", HostStatus.Connected);
132131
query.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE);
133132

134-
ret.errStr = i18n("no local primary storage can satisfy conditions[state: %s, status: %s]" +
133+
ret.errorCode = operr("no local primary storage can satisfy conditions[state: %s, status: %s]" +
135134
" or contain hosts satisfying conditions[state: %s, status: %s, size > %s bytes]",
136135
PrimaryStorageState.Enabled,
137136
PrimaryStorageStatus.Connected,
@@ -173,13 +172,13 @@ private Result allocate(Map data) {
173172
LocalStorageHostRefVO ref = it.next();
174173
if (!physicalCapacityMgr.checkCapacityByRatio(ref.getPrimaryStorageUuid(), ref.getTotalPhysicalCapacity(), ref.getAvailablePhysicalCapacity())
175174
|| !physicalCapacityMgr.checkRequiredCapacityByRatio(ref.getPrimaryStorageUuid(), ref.getTotalPhysicalCapacity(), spec.getTotalSize())) {
176-
ret.causes.add(operr("{the physical capacity usage of the host[uuid:%s] has exceeded the threshold[%s]}",
175+
errs.add(operr("{the physical capacity usage of the host[uuid:%s] has exceeded the threshold[%s]}",
177176
ref.getHostUuid(), physicalCapacityMgr.getRatio(ref.getPrimaryStorageUuid())));
178177
it.remove();
179178
}
180179
}
181180
if (candidateHosts.isEmpty()) {
182-
ret.errStr = i18n("failed allocate localstorage");
181+
ret.errorCode = operr("failed allocate localstorage").withCause(errs);
183182
}
184183
}
185184
Set<String> candidates = new HashSet<>();
@@ -289,7 +288,7 @@ public void run(FlowTrigger trigger, Map data) {
289288
return;
290289
}
291290

292-
ErrorCode err = ret.causes.isEmpty() ? operr(ret.errStr) : multiErr(ret.causes, ret.errStr);
291+
ErrorCode err = ret.errorCode;
293292
trigger.fail(err);
294293
}
295294
}

test/src/test/groovy/org/zstack/test/integration/kvm/vm/CreateVmWithDesignatedPSCase.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ class CreateVmWithDesignatedPSCase extends SubCase {
145145
return it["hostUuid"] == kvm1.uuid
146146
}
147147
assert candidates1.size() == 1
148-
assert it["hostName"] == "kvm1"
149-
assert it["reject"] == Platform.i18n("not accessible to the specific primary storage")
150-
assert it["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
148+
assert candidates1[0]["hostName"] == "kvm1"
149+
assert candidates1[0]["reject"] == Platform.i18n("not accessible to the specific primary storage")
150+
assert candidates1[0]["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
151151

152152
def kvm2 = env.inventoryByName("kvm2") as HostInventory
153153
def candidates2 = rejectedCandidates.findAll {
154154
return it["hostUuid"] == kvm2.uuid
155155
}
156156
assert candidates2.size() == 1
157-
assert it["hostName"] == "kvm2"
158-
assert it["reject"] == Platform.i18n("not accessible to the specific primary storage")
159-
assert it["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
157+
assert candidates2[0]["hostName"] == "kvm2"
158+
assert candidates2[0]["reject"] == Platform.i18n("not accessible to the specific primary storage")
159+
assert candidates2[0]["rejectBy"] == "HostPrimaryStorageAllocatorFlow"
160160
}
161161
}
162162

0 commit comments

Comments
 (0)