Skip to content

Commit 36fcfb5

Browse files
author
gitlab
committed
Merge branch 'fix/npe-batch-quality-issues@@2' into '5.5.12'
<fix>[multi]: batch guard NPE quality issues See merge request zstackio/zstack!9213
2 parents 6014606 + fd02d47 commit 36fcfb5

11 files changed

Lines changed: 42 additions & 11 deletions

File tree

compute/src/main/java/org/zstack/compute/allocator/HostAllocatorChain.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ private void runFlow(AbstractHostAllocatorFlow flow) {
146146
}
147147
} catch (Throwable t) {
148148
logger.warn("unhandled throwable", t);
149-
completion.fail(inerr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10019, t.toString()));
149+
String errMsg = t != null ? t.toString() : "unknown error";
150+
if (isDryRun) {
151+
if (dryRunCompletion != null) {
152+
dryRunCompletion.fail(inerr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10019, errMsg));
153+
}
154+
} else if (completion != null) {
155+
completion.fail(inerr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10019, errMsg));
156+
}
150157
}
151158
}
152159

compute/src/main/java/org/zstack/compute/host/HostBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ public String getName() {
14421442

14431443
@Override
14441444
protected String getDeduplicateString() {
1445-
return String.format("connect-host-%s", self.getUuid());
1445+
return String.format("connect-host-%s", self == null ? "unknown" : self.getUuid());
14461446
}
14471447
});
14481448
}

compute/src/main/java/org/zstack/compute/vm/VmCapabilitiesJudger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ private void checkPrimaryStorageCapabilities(VmCapabilities capabilities, VmInst
5353
q.add(PrimaryStorageVO_.uuid, SimpleQuery.Op.EQ, rootVolume.getPrimaryStorageUuid());
5454
String type = q.findValue();
5555

56+
if (type == null) {
57+
capabilities.setSupportLiveMigration(false);
58+
capabilities.setSupportVolumeMigration(false);
59+
return;
60+
}
61+
5662
PrimaryStorageType psType = PrimaryStorageType.valueOf(type);
5763

5864
if (vm.getState() != VmInstanceState.Running) {

core/src/main/java/org/zstack/core/db/UpdateQueryImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public UpdateQuery set(SingularAttribute attr, Object val) {
5454
@Override
5555
public UpdateQuery condAnd(SingularAttribute attr, Op op, Object val) {
5656
if ((op == Op.IN || op == Op.NOT_IN) && !(val instanceof Collection)) {
57-
throw new CloudRuntimeException(String.format("for operation IN or NOT IN, a Collection value is expected, but %s got", val.getClass()));
57+
throw new CloudRuntimeException(String.format("for operation IN or NOT IN, a Collection value is expected, but %s got",
58+
val == null ? "null" : val.getClass()));
5859
}
5960

6061
Cond cond = new Cond();

core/src/main/java/org/zstack/core/log/LogSafeGson.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ private static <T> JsonSerializer<T> getSerializer() {
208208
}
209209

210210
public static JsonElement toJsonElement(Object o) {
211+
if (o == null) {
212+
return JsonNull.INSTANCE;
213+
}
211214
return logSafeGson.toJsonTree(o, getGsonType(o.getClass()));
212215
}
213216

header/src/main/java/org/zstack/header/vm/VmAbnormalLifeCycleStruct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ boolean match(VmAbnormalLifeCycleStruct struct) {
7272
boolean match(VmAbnormalLifeCycleStruct struct) {
7373
return struct.getOriginalState() == VmInstanceState.Paused
7474
&& struct.getCurrentState() == VmInstanceState.Stopped
75-
&& struct.getCurrentHostUuid().equals(struct.getOriginalHostUuid());
75+
&& Objects.equals(struct.getCurrentHostUuid(), struct.getOriginalHostUuid());
7676
}
7777
},
7878
VmMigrateToAnotherHost {

identity/src/main/java/org/zstack/identity/AuthorizationManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionExcepti
116116
session = evaluateSession(msg);
117117
}
118118

119+
if (session == null) {
120+
throw new ApiMessageInterceptionException(err(ORG_ZSTACK_IDENTITY_10012, IdentityErrors.INVALID_SESSION,
121+
"evaluated session is null for message[%s]", msg.getMessageName()));
122+
}
123+
119124
logger.trace(String.format("authorizing message[%s] with user[accountUuid:%s, uuid:%s] session",
120125
msg.getMessageName(),
121126
session.getAccountUuid(),

plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,15 +3974,17 @@ public void done() {
39743974
mon.connect(new Completion(releaseLock) {
39753975
@Override
39763976
public void success() {
3977+
String monUuid = mon.getSelf() == null ? "unknown" : mon.getSelf().getUuid();
39773978
logger.debug(String.format("successfully reconnected the mon[uuid:%s] of the ceph primary" +
3978-
" storage[uuid:%s, name:%s]", mon.getSelf().getUuid(), self.getUuid(), self.getName()));
3979+
" storage[uuid:%s, name:%s]", monUuid, self.getUuid(), self.getName()));
39793980
releaseLock.done();
39803981
}
39813982

39823983
@Override
39833984
public void fail(ErrorCode errorCode) {
3985+
String monUuid = mon.getSelf() == null ? "unknown" : mon.getSelf().getUuid();
39843986
logger.warn(String.format("failed to reconnect the mon[uuid:%s] server of the ceph primary" +
3985-
" storage[uuid:%s, name:%s], %s", mon.getSelf().getUuid(), self.getUuid(), self.getName(), errorCode));
3987+
" storage[uuid:%s, name:%s], %s", monUuid, self.getUuid(), self.getName(), errorCode));
39863988
releaseLock.done();
39873989
}
39883990
});

plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageMonBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void fail(ErrorCode errorCode) {
141141

142142
@Override
143143
public String getName() {
144-
return String.format("connect-ceph-primary-storage-mon-%s", self.getUuid());
144+
return String.format("connect-ceph-primary-storage-mon-%s", self == null ? "unknown" : self.getUuid());
145145
}
146146
});
147147
}
@@ -420,7 +420,7 @@ public void fail(ErrorCode errorCode) {
420420

421421
@Override
422422
public String getName() {
423-
return String.format("ping-ceph-primary-storage-%s", self.getUuid());
423+
return String.format("ping-ceph-primary-storage-%s", self == null ? "unknown" : self.getUuid());
424424
}
425425
});
426426
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ private String getHostUuidFromAllocateMsg(AllocatePrimaryStorageSpaceMsg msg) {
385385
throw new OperationFailureException(
386386
argerr(ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10023, "invalid uri, correct example is file://$URL;hostUuid://$HOSTUUID or volume://$VOLUMEUUID "));
387387
}
388-
hostUuid = uriParsers.get(protocol).parseUri(msg.getRequiredInstallUri()).hostUuid;
388+
AbstractUriParser parser = uriParsers.get(protocol);
389+
if (parser == null) {
390+
throw new OperationFailureException(
391+
argerr(ORG_ZSTACK_STORAGE_PRIMARY_LOCAL_10023, "unsupported protocol[%s] in uri[%s]", protocol, msg.getRequiredInstallUri()));
392+
}
393+
hostUuid = parser.parseUri(msg.getRequiredInstallUri()).hostUuid;
389394
}
390395

391396
if (hostUuid != null) {

0 commit comments

Comments
 (0)