From ffeca8bbd29ffa0821d04795bfaf2753143ee5ae Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 31 Jul 2014 15:27:28 -0700 Subject: [PATCH] CLOUDSTACK-7209: handle the case when network fails to implement NoTransitionException, and null is returned to the caller stack. All caller methods should verify if the return value is null before processing it further. --- .../orchestration/NetworkOrchestrator.java | 5 ++++- framework/db/test/resources/db.properties | 18 ++++++++++++++++++ .../cloud/network/IpAddressManagerImpl.java | 2 +- .../com/cloud/network/NetworkServiceImpl.java | 2 +- server/src/com/cloud/vm/UserVmManagerImpl.java | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 framework/db/test/resources/db.properties diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 3b7e92a5c06..cdca839fc30 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -2424,7 +2424,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // implement the network s_logger.debug("Starting network " + network + "..."); Pair implementedNetwork = implementNetwork(networkId, dest, context); - if (implementedNetwork.first() == null) { + if (implementedNetwork== null || implementedNetwork.first() == null) { s_logger.warn("Failed to start the network " + network); return false; } else { @@ -3083,6 +3083,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //2) prepare nic if (prepare) { Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); + if (implemented == null) { + throw new CloudRuntimeException("Failed to prepare the nic as a part of creating nic " + nic + " for vm "+ vm + " due to network " + network + " implement failure"); + } nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second()); s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); } diff --git a/framework/db/test/resources/db.properties b/framework/db/test/resources/db.properties new file mode 100644 index 00000000000..cc1215ff35c --- /dev/null +++ b/framework/db/test/resources/db.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Just here to make the unit test not blow up \ No newline at end of file diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java b/server/src/com/cloud/network/IpAddressManagerImpl.java index c45496879f5..2cd544de83d 100644 --- a/server/src/com/cloud/network/IpAddressManagerImpl.java +++ b/server/src/com/cloud/network/IpAddressManagerImpl.java @@ -1597,7 +1597,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage s_logger.debug("Implementing network " + guestNetwork + " as a part of network provision for persistent network"); try { Pair implementedNetwork = _networkMgr.implementNetwork(guestNetwork.getId(), dest, context); - if (implementedNetwork.first() == null) { + if (implementedNetwork == null || implementedNetwork.first() == null) { s_logger.warn("Failed to implement the network " + guestNetwork); } guestNetwork = implementedNetwork.second(); diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index 130d05176db..5e231e9ddcc 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -1309,7 +1309,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller); s_logger.debug("Implementing network " + network + " as a part of network provision for persistent network"); Pair implementedNetwork = _networkMgr.implementNetwork(network.getId(), dest, context); - if (implementedNetwork.first() == null) { + if (implementedNetwork == null || implementedNetwork.first() == null) { s_logger.warn("Failed to provision the network " + network); } network = implementedNetwork.second(); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index dd3083b3001..0fa5085c0e7 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -4559,7 +4559,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir s_logger.debug("Implementing the network for account" + newNetwork + " as a part of" + " network provision for persistent networks"); try { Pair implementedNetwork = _networkMgr.implementNetwork(newNetwork.getId(), dest, context); - if (implementedNetwork.first() == null) { + if (implementedNetwork == null || implementedNetwork.first() == null) { s_logger.warn("Failed to implement the network " + newNetwork); } newNetwork = implementedNetwork.second();