Repository: cloudstack
Updated Branches:
  refs/heads/master 80846ba98 -> 1aef5cba6


Fixed Coverity Issues


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1aef5cba
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1aef5cba
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1aef5cba

Branch: refs/heads/master
Commit: 1aef5cba666510a23f50bd24c4233fc5dd1d35d2
Parents: 80846ba
Author: Santhosh Edukulla <santhosh.eduku...@gmail.com>
Authored: Mon Nov 3 16:34:26 2014 +0530
Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com>
Committed: Mon Nov 3 16:45:30 2014 +0530

----------------------------------------------------------------------
 .../resource/TrafficSentinelResource.java       |  3 ---
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  6 -----
 .../snapshot/StorageSystemSnapshotStrategy.java | 12 +++++-----
 .../kvm/storage/KVMStorageProcessor.java        |  4 +++-
 .../kvm/storage/LibvirtStorageAdaptor.java      |  6 ++---
 .../kvm/storage/ManagedNfsStorageAdaptor.java   | 13 ++++-------
 .../network/element/CiscoNexusVSMElement.java   |  2 +-
 .../storage/snapshot/SnapshotManagerImpl.java   | 10 +++++---
 .../com/cloud/template/TemplateManagerImpl.java |  5 ----
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 24 ++++++++------------
 .../cloudstack/region/RegionsApiUtil.java       |  5 ----
 .../SecondaryStorageManagerImpl.java            |  9 ++++----
 12 files changed, 38 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/core/src/com/cloud/network/resource/TrafficSentinelResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/network/resource/TrafficSentinelResource.java 
b/core/src/com/cloud/network/resource/TrafficSentinelResource.java
index cac3ae3..610190a 100644
--- a/core/src/com/cloud/network/resource/TrafficSentinelResource.java
+++ b/core/src/com/cloud/network/resource/TrafficSentinelResource.java
@@ -222,9 +222,6 @@ public class TrafficSentinelResource implements 
ServerResource {
                         String publicIp = st.nextToken();
                         Long bytesSent = new Long(st.nextToken());
                         Long bytesRcvd = new Long(st.nextToken());
-                        if (bytesSent == null || bytesRcvd == null) {
-                            s_logger.debug("Incorrect bytes for IP: " + 
publicIp);
-                        }
                         long[] bytesSentAndReceived = new long[2];
                         bytesSentAndReceived[0] = bytesSent;
                         bytesSentAndReceived[1] = bytesRcvd;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index ebb030e..32bf54c 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -2675,12 +2675,6 @@ public class VirtualMachineManagerImpl extends 
ManagerBase implements VirtualMac
             s_logger.debug("Not processing listener " + this + " as connect 
happens on rebalance process");
             return;
         }
-
-        if (forRebalance) {
-            s_logger.debug("Not processing listener " + this + " as connect 
happens on rebalance process");
-            return;
-        }
-
         Long clusterId = agent.getClusterId();
         long agentId = agent.getId();
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
index 41019fb..7427f37 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
@@ -404,14 +404,14 @@ public class StorageSystemSnapshotStrategy extends 
SnapshotStrategyBase {
         DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, 
DataStoreRole.Primary);
 
         Map<String, String> mapCapabilities = 
dataStore.getDriver().getCapabilities();
+        if(mapCapabilities != null) {
+            String value = 
mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
+            Boolean supportsStorageSystemSnapshots = new Boolean(value);
 
-        String value = 
mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
-        Boolean supportsStorageSystemSnapshots = new Boolean(value);
-
-        if (supportsStorageSystemSnapshots) {
-            return StrategyPriority.HIGHEST;
+            if (supportsStorageSystemSnapshots) {
+                return StrategyPriority.HIGHEST;
+            }
         }
-
         return StrategyPriority.CANT_HANDLE;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index 21f5919..562cf5f 100644
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -1082,7 +1082,9 @@ public class KVMStorageProcessor implements 
StorageProcessor {
                                                  volume.getProvisioningType(), 
disksize);
 
             VolumeObjectTO newVol = new VolumeObjectTO();
-            newVol.setPath(vol.getName());
+            if(vol != null) {
+                newVol.setPath(vol.getName());
+            }
             newVol.setSize(volume.getSize());
             
newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index c882a78..8c9ea69 100644
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -915,6 +915,9 @@ public class LibvirtStorageAdaptor implements 
StorageAdaptor {
             try {
                 String newUuid = name;
                 disk = destPool.createPhysicalDisk(newUuid, format, 
provisioningType, template.getVirtualSize());
+                if (disk == null) {
+                    throw new CloudRuntimeException("Failed to create disk 
from template " + template.getName());
+                }
                 if (template.getFormat() == PhysicalDiskFormat.TAR) {
                     Script.runSimpleBashScript("tar -x -f " + 
template.getPath() + " -C " + disk.getPath(), timeout); // TO BE FIXED to aware 
provisioningType
                 } else if (template.getFormat() == PhysicalDiskFormat.DIR) {
@@ -960,9 +963,6 @@ public class LibvirtStorageAdaptor implements 
StorageAdaptor {
             }
         }
 
-        if (disk == null) {
-            throw new CloudRuntimeException("Failed to create disk from 
template " + template.getName());
-        }
 
         return disk;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java
index af2e6f6..c00e8cb 100644
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java
@@ -100,6 +100,9 @@ public class ManagedNfsStorageAdaptor implements 
StorageAdaptor {
         LibvirtStoragePoolDef spd = null;
         try {
             conn = LibvirtConnection.getConnection();
+            if (conn == null) {
+                throw new CloudRuntimeException("Failed to create Libvrt 
Connection");
+            }
 
             targetPath = "/mnt" + volumeUuid;
             spd = new LibvirtStoragePoolDef(poolType.NETFS, volumeUuid, 
details.get(DiskTO.UUID), pool.getSourceHost(), 
details.get(DiskTO.MOUNT_POINT), targetPath);
@@ -140,7 +143,7 @@ public class ManagedNfsStorageAdaptor implements 
StorageAdaptor {
                 if (result == null) {
                     s_logger.error("Succeeded in unmounting " + targetPath);
                     try {
-                        sp = conn.storagePoolCreateXML(spd.toString(), 0);
+                        conn.storagePoolCreateXML(spd.toString(), 0);
                         s_logger.error("Succeeded in redefining storage");
                         return true;
                     } catch (LibvirtException l) {
@@ -176,9 +179,6 @@ public class ManagedNfsStorageAdaptor implements 
StorageAdaptor {
         }
 
         LibvirtStorageVolumeDef.volFormat libvirtformat = null;
-        String volPath = null;
-        String volName = null;
-        long volAllocation = 0;
         long volCapacity = 0;
         // check whether the volume is present on the given pool
         StorageVol vol = getVolume(virtPool, volumeUuid);
@@ -194,13 +194,8 @@ public class ManagedNfsStorageAdaptor implements 
StorageAdaptor {
                 s_logger.debug(volDef.toString());
 
                 vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
-                volPath = vol.getPath();
-                volName = vol.getName();
-                volAllocation = vol.getInfo().allocation;
-                volCapacity = vol.getInfo().capacity;
 
             }
-
             KVMPhysicalDisk disk = new KVMPhysicalDisk(vol.getPath(), 
volumeUuid, pool);
             disk.setFormat(PhysicalDiskFormat.QCOW2);
             disk.setSize(vol.getInfo().allocation);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
 
b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
index 0e2a911..81e4f86 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
@@ -294,7 +294,7 @@ public class CiscoNexusVSMElement extends 
CiscoNexusVSMDeviceManagerImpl impleme
                     CiscoNexusVSMDeviceVO vsm = null;
                     if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
                         vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, 
vsmPassword);
-                        vsm = _vsmDao.persist(vsm);
+                        _vsmDao.persist(vsm);
                     }
                     // Create a mapping between the cluster and the vsm.
                     vsm = _vsmDao.getVSMbyIpaddress(vsmIp);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java 
b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index ac013c4..1625889 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -309,17 +309,21 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
             throw new InvalidParameterValueException("Volume is not in ready 
state");
         }
 
-        boolean backedUp = false;
+
         // does the caller have the authority to act on this volume
         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), 
null, true, volume);
 
         SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, 
DataStoreRole.Primary);
-
+        if(snapshot != null)
+        {
+            s_logger.debug("Failed to create snapshot");
+            throw new CloudRuntimeException("Failed to create snapshot");
+        }
         try {
             postCreateSnapshot(volumeId, snapshot.getId(), policyId);
             //Check if the snapshot was removed while backingUp. If yes, do 
not log snapshot create usage event
             SnapshotVO freshSnapshot = _snapshotDao.findById(snapshot.getId());
-            if ((freshSnapshot != null) && backedUp) {
+            if (freshSnapshot != null)  {
                 
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, 
snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, 
snapshot.getName(),
                     null, null, volume.getSize(), 
snapshot.getClass().getName(), snapshot.getUuid());
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java 
b/server/src/com/cloud/template/TemplateManagerImpl.java
index d3ad2db..d854579 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -156,7 +156,6 @@ import com.cloud.user.AccountManager;
 import com.cloud.user.AccountService;
 import com.cloud.user.AccountVO;
 import com.cloud.user.ResourceLimitService;
-import com.cloud.user.User;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.DateUtil;
@@ -1350,10 +1349,6 @@ public class TemplateManagerImpl extends ManagerBase 
implements TemplateManager,
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, 
eventDescription = "creating template", async = true)
     public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd 
command) throws CloudRuntimeException {
-        Long userId = CallContext.current().getCallingUserId();
-        if (userId == null) {
-            userId = User.UID_SYSTEM;
-        }
         final long templateId = command.getEntityId();
         Long volumeId = command.getVolumeId();
         Long snapshotId = command.getSnapshotId();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 609f781..abb5b7b 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -748,12 +748,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         } catch (CloudException e) {
             throw new CloudRuntimeException("Unable to contact the agent to 
stop the virtual machine " + vm, e);
         }
-
-        if (status) {
-            return status;
-        } else {
-            return status;
-        }
+        return status;
     }
 
     private UserVm rebootVirtualMachine(long userId, long vmId) throws 
InsufficientCapacityException, ResourceUnavailableException {
@@ -1328,16 +1323,15 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             if (vmSnapshots.size() > 0) {
                 throw new InvalidParameterValueException("Unable to scale VM, 
please remove VM snapshots before scaling VM");
             }
+            if (vmInstance.getState().equals(State.Stopped)) {
+                upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, 
customParameters);
+                return true;
+            }
+            if (vmInstance.getState().equals(State.Running)) {
+                return upgradeRunningVirtualMachine(vmId, 
newServiceOfferingId, customParameters);
+            }
         }
-
-        if (vmInstance.getState().equals(State.Stopped)) {
-            upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, 
customParameters);
-            return true;
-        }
-        if (vmInstance.getState().equals(State.Running)) {
-            return upgradeRunningVirtualMachine(vmId, newServiceOfferingId, 
customParameters);
-        }
-        return false;
+    return false;
     }
 
     private boolean upgradeRunningVirtualMachine(Long vmId, Long 
newServiceOfferingId, Map<String, String> customParameters) throws 
ResourceUnavailableException,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionsApiUtil.java 
b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
index 7894e37..92c5ed4 100644
--- a/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
+++ b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
@@ -237,11 +237,6 @@ public class RegionsApiUtil {
 
         String apiKey = "";
         String secretKey = "";
-
-        if (apiKey == null || secretKey == null) {
-            return region.getEndPoint() + "?" + apiParams;
-        }
-
         String encodedApiKey;
         try {
             encodedApiKey = URLEncoder.encode(apiKey, "UTF-8");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aef5cba/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
 
b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
index 86d94df..8069050 100755
--- 
a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
+++ 
b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
@@ -988,11 +988,12 @@ public class SecondaryStorageManagerImpl extends 
ManagerBase implements Secondar
             if (host != null) {
                 s_logger.debug("Removing host entry for ssvm id=" + vmId);
                 _hostDao.remove(host.getId());
+                //Expire the download urls in the entire zone for templates 
and volumes.
+                _tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
+                _volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
+                return true;
             }
-            //Expire the download urls in the entire zone for templates and 
volumes.
-            _tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
-            _volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
-            return true;
+            return false;
         } catch (ResourceUnavailableException e) {
             s_logger.warn("Unable to expunge " + ssvm, e);
             return false;

Reply via email to