Fix NPE when node is null

This commit is contained in:
Sergey Tselovalnikov 2016-05-17 14:39:44 +03:00 committed by Ignasi Barrera
parent cd50ad905d
commit 0e41b45af5
1 changed files with 6 additions and 5 deletions

View File

@ -144,21 +144,22 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
@Override
public NodeMetadata rebootNode(String id) {
NodeMetadata node = getNode(checkNotNull(id, "id"));
checkStateAvailable(node);
checkStateAvailable(id, node);
client.rebootNode(id);
// invalidate state of node
return getNode(checkNotNull(id, "id"));
}
private void checkStateAvailable(NodeMetadata node) {
checkState(node != null && node.getStatus() != Status.TERMINATED,
private void checkStateAvailable(String id, NodeMetadata node) {
checkState(node != null, "node with id %s terminated or unavailable!", id);
checkState(node.getStatus() != Status.TERMINATED,
"node %s terminated or unavailable! current status: %s", node, formatStatus(node));
}
@Override
public NodeMetadata resumeNode(String id) {
NodeMetadata node = getNode(checkNotNull(id, "id"));
checkStateAvailable(node);
checkStateAvailable(id, node);
client.resumeNode(id);
// invalidate state of node
return getNode(checkNotNull(id, "id"));
@ -167,7 +168,7 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
@Override
public NodeMetadata suspendNode(String id) {
NodeMetadata node = getNode(checkNotNull(id, "id"));
checkStateAvailable(node);
checkStateAvailable(id, node);
client.suspendNode(id);
// invalidate state of node
return getNode(checkNotNull(id, "id"));