mirror of https://github.com/apache/cloudstack.git
Fix coverity issues 569415, 569416, 569417
This commit is contained in:
parent
1760de47e5
commit
4683de5a92
|
|
@ -127,9 +127,9 @@ import com.cloud.vm.dao.NicDao;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Local(value = {NetworkElement.class, ConnectivityProvider.class, SourceNatServiceProvider.class, StaticNatServiceProvider.class, PortForwardingServiceProvider.class,
|
@Local(value = {NetworkElement.class, ConnectivityProvider.class, SourceNatServiceProvider.class, StaticNatServiceProvider.class, PortForwardingServiceProvider.class,
|
||||||
IpDeployer.class})
|
IpDeployer.class})
|
||||||
public class NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
|
public class NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
|
||||||
NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
|
NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
|
||||||
|
|
||||||
private static final int MAX_PORT = 65535;
|
private static final int MAX_PORT = 65535;
|
||||||
private static final int MIN_PORT = 0;
|
private static final int MIN_PORT = 0;
|
||||||
|
|
@ -211,7 +211,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||||
ResourceUnavailableException, InsufficientCapacityException {
|
ResourceUnavailableException, InsufficientCapacityException {
|
||||||
s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
|
s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
|
||||||
|
|
||||||
if (!canHandle(network, Service.Connectivity)) {
|
if (!canHandle(network, Service.Connectivity)) {
|
||||||
|
|
@ -262,9 +262,9 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
|
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
|
||||||
|
|
||||||
CreateLogicalRouterCommand cmd =
|
CreateLogicalRouterCommand cmd =
|
||||||
new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()),
|
new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()),
|
||||||
"router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" +
|
"router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" +
|
||||||
context.getAccount().getAccountName());
|
context.getAccount().getAccountName());
|
||||||
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||||
if (answer.getResult() == false) {
|
if (answer.getResult() == false) {
|
||||||
s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
|
s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
|
||||||
|
|
@ -281,7 +281,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
|
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
|
||||||
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||||
|
|
||||||
if (!canHandle(network, Service.Connectivity)) {
|
if (!canHandle(network, Service.Connectivity)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -310,8 +310,8 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
if (answer.getResult()) {
|
if (answer.getResult()) {
|
||||||
s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
|
s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
|
||||||
UpdateLogicalSwitchPortCommand cmd =
|
UpdateLogicalSwitchPortCommand cmd =
|
||||||
new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()),
|
new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()),
|
||||||
nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
|
nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
|
||||||
agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -321,8 +321,8 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateLogicalSwitchPortCommand cmd =
|
CreateLogicalSwitchPortCommand cmd =
|
||||||
new CreateLogicalSwitchPortCommand(BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" +
|
new CreateLogicalSwitchPortCommand(BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" +
|
||||||
context.getAccount().getAccountName(), nic.getName());
|
context.getAccount().getAccountName(), nic.getName());
|
||||||
CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||||
|
|
||||||
if (answer == null || !answer.getResult()) {
|
if (answer == null || !answer.getResult()) {
|
||||||
|
|
@ -331,7 +331,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
NiciraNvpNicMappingVO nicMap =
|
NiciraNvpNicMappingVO nicMap =
|
||||||
new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
|
new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
|
||||||
niciraNvpNicMappingDao.persist(nicMap);
|
niciraNvpNicMappingDao.persist(nicMap);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -339,7 +339,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
|
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
|
||||||
ResourceUnavailableException {
|
ResourceUnavailableException {
|
||||||
|
|
||||||
if (!canHandle(network, Service.Connectivity)) {
|
if (!canHandle(network, Service.Connectivity)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -434,7 +434,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
|
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
|
||||||
ResourceUnavailableException {
|
ResourceUnavailableException {
|
||||||
// Nothing to do here.
|
// Nothing to do here.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -499,6 +499,9 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
ServerResource resource = new NiciraNvpResource();
|
ServerResource resource = new NiciraNvpResource();
|
||||||
final String deviceName = Network.Provider.NiciraNvp.getName();
|
final String deviceName = Network.Provider.NiciraNvp.getName();
|
||||||
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
|
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
|
||||||
|
if (networkDevice == null) {
|
||||||
|
throw new CloudRuntimeException("No network device found for " + deviceName);
|
||||||
|
}
|
||||||
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
|
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
|
||||||
PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
|
PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
|
||||||
if (physicalNetwork == null) {
|
if (physicalNetwork == null) {
|
||||||
|
|
@ -507,13 +510,13 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
long zoneId = physicalNetwork.getDataCenterId();
|
long zoneId = physicalNetwork.getDataCenterId();
|
||||||
|
|
||||||
final PhysicalNetworkServiceProviderVO ntwkSvcProvider =
|
final PhysicalNetworkServiceProviderVO ntwkSvcProvider =
|
||||||
physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
|
physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
|
||||||
if (ntwkSvcProvider == null) {
|
if (ntwkSvcProvider == null) {
|
||||||
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " +
|
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " +
|
||||||
physicalNetworkId + "to add this device");
|
physicalNetworkId + "to add this device");
|
||||||
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
|
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
|
||||||
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " +
|
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " +
|
||||||
physicalNetworkId + "to add this device");
|
physicalNetworkId + "to add this device");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
|
if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
|
||||||
|
|
@ -598,12 +601,13 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
// Lets see if there are networks that use us
|
// Lets see if there are networks that use us
|
||||||
// Find the nicira networks on this physical network
|
// Find the nicira networks on this physical network
|
||||||
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
|
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
|
||||||
|
if (networkList != null) {
|
||||||
// Networks with broadcast type lswitch are ours
|
// Networks with broadcast type lswitch are ours
|
||||||
for (NetworkVO network : networkList) {
|
for (NetworkVO network : networkList) {
|
||||||
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
|
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
|
||||||
if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
|
if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
|
||||||
throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
|
throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -665,6 +669,9 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
|
|
||||||
// Find the nicira networks on this physical network
|
// Find the nicira networks on this physical network
|
||||||
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
|
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
|
||||||
|
if (networkList == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
// Networks with broadcast type lswitch are ours
|
// Networks with broadcast type lswitch are ours
|
||||||
List<NetworkVO> responseList = new ArrayList<NetworkVO>();
|
List<NetworkVO> responseList = new ArrayList<NetworkVO>();
|
||||||
|
|
@ -747,7 +754,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
|
cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
|
||||||
}
|
}
|
||||||
ConfigurePublicIpsOnLogicalRouterCommand cmd =
|
ConfigurePublicIpsOnLogicalRouterCommand cmd =
|
||||||
new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
|
new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
|
||||||
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||||
//FIXME answer can be null if the host is down
|
//FIXME answer can be null if the host is down
|
||||||
return answer.getResult();
|
return answer.getResult();
|
||||||
|
|
@ -788,7 +795,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
// we only need the source and destination ip. Unfortunately no mention if a rule
|
// we only need the source and destination ip. Unfortunately no mention if a rule
|
||||||
// is new.
|
// is new.
|
||||||
StaticNatRuleTO ruleTO =
|
StaticNatRuleTO ruleTO =
|
||||||
new StaticNatRuleTO(1, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT, rule.getDestIpAddress(), MIN_PORT, MAX_PORT, "any", rule.isForRevoke(), false);
|
new StaticNatRuleTO(1, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT, rule.getDestIpAddress(), MIN_PORT, MAX_PORT, "any", rule.isForRevoke(), false);
|
||||||
staticNatRules.add(ruleTO);
|
staticNatRules.add(ruleTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -830,7 +837,7 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
|
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
|
||||||
new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
|
new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
|
||||||
ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||||
|
|
||||||
return answer.getResult();
|
return answer.getResult();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue