cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject [29/50] git commit: updated refs/heads/marvin to df58f51
Date Wed, 29 Jan 2014 08:54:04 GMT
Findbugs: different issues solved(cherry picked from commit
0b13f8e59db1e681e1dff0baa828bb0711842e9f)

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

Branch: refs/heads/marvin
Commit: fae05560218ef3bcb962bd424ae5dbf5cb8ede68
Parents: 0daca84
Author: Daan Hoogland <daan@onecht.net>
Authored: Tue Jan 28 16:30:04 2014 +0100
Committer: Daan Hoogland <dhoogland@schubergphilis.com>
Committed: Tue Jan 28 16:30:04 2014 +0100

----------------------------------------------------------------------
 .../com/cloud/api/query/vo/UserVmJoinVO.java    | 23 ++++----
 .../com/cloud/consoleproxy/AgentHookBase.java   |  5 +-
 .../src/com/cloud/dc/DedicatedResourceVO.java   | 15 +++--
 .../com/cloud/network/IpAddressManagerImpl.java | 60 +++++++++++---------
 .../src/com/cloud/network/NetworkModelImpl.java |  7 ++-
 .../cloud/network/guru/ControlNetworkGuru.java  |  4 +-
 .../com/cloud/network/vpc/VpcManagerImpl.java   |  4 +-
 .../com/cloud/template/TemplateManagerImpl.java |  4 +-
 8 files changed, 70 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
index 2df49ec..9e4fc21 100644
--- a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
@@ -35,6 +35,7 @@ import com.cloud.server.ResourceTag.ResourceObjectType;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.Volume;
 import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.State;
 
@@ -47,10 +48,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     private long id;
 
     @Column(name = "name", updatable = false, nullable = false, length = 255)
-    private String name = null;
+    private final String name = null;
 
     @Column(name = "display_name", updatable = false, nullable = false, length = 255)
-    private String displayName = null;
+    private final String displayName = null;
 
     @Column(name = "account_id")
     private long accountId;
@@ -59,7 +60,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     private String accountUuid;
 
     @Column(name = "account_name")
-    private String accountName = null;
+    private final String accountName = null;
 
     @Column(name = "account_type")
     private short accountType;
@@ -71,10 +72,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     private String domainUuid;
 
     @Column(name = "domain_name")
-    private String domainName = null;
+    private final String domainName = null;
 
     @Column(name = "domain_path")
-    private String domainPath = null;
+    private final String domainPath = null;
 
     @Column(name = "instance_group_id")
     private long instanceGroupId;
@@ -96,7 +97,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
      */
     @Enumerated(value = EnumType.STRING)
     @Column(name = "state", updatable = true, nullable = false, length = 32)
-    private State state = null;
+    private final State state = null;
 
     @Column(name = GenericDao.CREATED_COLUMN)
     private Date created;
@@ -148,7 +149,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     private String dataCenterUuid;
 
     @Column(name = "data_center_name")
-    private String dataCenterName = null;
+    private final String dataCenterName = null;
 
     @Column(name = "security_group_enabled")
     private boolean securityGroupEnabled;
@@ -233,7 +234,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     private String volumeUuid;
 
     @Column(name = "volume_device_id")
-    private Long volumeDeviceId = null;
+    private final Long volumeDeviceId = null;
 
     @Column(name = "volume_type")
     @Enumerated(EnumType.STRING)
@@ -745,9 +746,11 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity
{
     }
 
     public String getDetail(String name) {
-        assert (details != null) : "Did you forget to load the details?";
+        if (details == null) {
+            throw new CloudRuntimeException("No details to get. Did you forget to load the
details?");
+        }
 
-        return details != null ? details.get(name) : null;
+        return details.get(name);
     }
 
     public String getUserData() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/consoleproxy/AgentHookBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/AgentHookBase.java b/server/src/com/cloud/consoleproxy/AgentHookBase.java
index 9dfffd4..2e0bada 100644
--- a/server/src/com/cloud/consoleproxy/AgentHookBase.java
+++ b/server/src/com/cloud/consoleproxy/AgentHookBase.java
@@ -49,6 +49,7 @@ import com.cloud.host.dao.HostDao;
 import com.cloud.servlet.ConsoleProxyPasswordBasedEncryptor;
 import com.cloud.servlet.ConsoleProxyServlet;
 import com.cloud.utils.Ternary;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.VMInstanceDao;
 
@@ -192,7 +193,9 @@ public abstract class AgentHookBase implements AgentHook {
 
         assert (ksBits != null);
         if (ksBits == null) {
-            s_logger.error("Could not find and construct a valid SSL certificate");
+            String msg = "Could not find and construct a valid SSL certificate";
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg);
         }
         cmd = new StartConsoleProxyAgentHttpHandlerCommand(ksBits, storePassword);
         cmd.setEncryptorPassword(getEncryptorPassword());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/dc/DedicatedResourceVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/dc/DedicatedResourceVO.java b/server/src/com/cloud/dc/DedicatedResourceVO.java
index 9948f50..41bdfec 100644
--- a/server/src/com/cloud/dc/DedicatedResourceVO.java
+++ b/server/src/com/cloud/dc/DedicatedResourceVO.java
@@ -29,6 +29,11 @@ import javax.persistence.Table;
 @Table(name = "dedicated_resources")
 public class DedicatedResourceVO implements DedicatedResources {
 
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -6659510127145101917L;
+
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
@@ -59,7 +64,7 @@ public class DedicatedResourceVO implements DedicatedResources {
     private long affinityGroupId;
 
     public DedicatedResourceVO() {
-        this.uuid = UUID.randomUUID().toString();
+        uuid = UUID.randomUUID().toString();
     }
 
     public DedicatedResourceVO(Long dataCenterId, Long podId, Long clusterId, Long hostId,
Long domainId, Long accountId, long affinityGroupId) {
@@ -69,7 +74,7 @@ public class DedicatedResourceVO implements DedicatedResources {
         this.hostId = hostId;
         this.domainId = domainId;
         this.accountId = accountId;
-        this.uuid = UUID.randomUUID().toString();
+        uuid = UUID.randomUUID().toString();
         this.affinityGroupId = affinityGroupId;
     }
 
@@ -115,7 +120,7 @@ public class DedicatedResourceVO implements DedicatedResources {
     }
 
     public DedicatedResourceVO(long dedicatedResourceId) {
-        this.id = dedicatedResourceId;
+        id = dedicatedResourceId;
     }
 
     @Override
@@ -138,7 +143,7 @@ public class DedicatedResourceVO implements DedicatedResources {
 
     @Override
     public String getUuid() {
-        return this.uuid;
+        return uuid;
     }
 
     public void setUuid(String uuid) {
@@ -153,7 +158,7 @@ public class DedicatedResourceVO implements DedicatedResources {
     @Override
     public boolean equals(Object obj) {
         if (obj instanceof DedicatedResourceVO) {
-            return ((DedicatedResourceVO)obj).getId() == this.getId();
+            return ((DedicatedResourceVO)obj).getId() == getId();
         } else {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/network/IpAddressManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java b/server/src/com/cloud/network/IpAddressManagerImpl.java
index 6596074..09f73a4 100644
--- a/server/src/com/cloud/network/IpAddressManagerImpl.java
+++ b/server/src/com/cloud/network/IpAddressManagerImpl.java
@@ -17,6 +17,7 @@
 package com.cloud.network;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -28,6 +29,8 @@ import java.util.UUID;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.context.CallContext;
@@ -39,7 +42,6 @@ import org.apache.cloudstack.region.PortableIp;
 import org.apache.cloudstack.region.PortableIpDao;
 import org.apache.cloudstack.region.PortableIpVO;
 import org.apache.cloudstack.region.Region;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.alert.AlertManager;
@@ -570,8 +572,9 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
 
         IPAddressVO ip = markIpAsUnavailable(addrId);
 
-        assert (ip != null) : "Unable to mark the ip address id=" + addrId + " as unavailable.";
         if (ip == null) {
+            String msg = "Unable to mark the ip address id=" + addrId + " as unavailable.";
+            s_logger.error(msg);
             return true;
         }
 
@@ -684,10 +687,10 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
                 if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty())
{
                     fetchFromDedicatedRange = true;
                     sc.setParameters("vlanId", dedicatedVlanDbIds.toArray());
-                    errorMessage.append(", vlanId id=" + dedicatedVlanDbIds.toArray());
+                    errorMessage.append(", vlanId id=" + Arrays.toString(dedicatedVlanDbIds.toArray()));
                 } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty())
{
                     sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
-                    errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
+                    errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
                 } else {
                     if (podId != null) {
                         InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient
address capacity", Pod.class, podId);
@@ -727,7 +730,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
                     if (useSystemIps && nonDedicatedVlanDbIds != null &&
!nonDedicatedVlanDbIds.isEmpty()) {
                         fetchFromDedicatedRange = false;
                         sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
-                        errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray());
+                        errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
                         addrs = _ipAddressDao.lockRows(sc, filter, true);
                     }
                 }
@@ -852,6 +855,11 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
     public PublicIp assignDedicateIpAddress(Account owner, final Long guestNtwkId, final
Long vpcId, final long dcId, final boolean isSourceNat)
             throws ConcurrentOperationException, InsufficientAddressCapacityException {
 
+        if (owner == null) {
+            s_logger.error("No account to assign an ip to.");
+            return null;
+        }
+
         final long ownerId = owner.getId();
 
         PublicIp ip = null;
@@ -883,13 +891,11 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
 
             return ip;
         } finally {
-            if (owner != null) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Releasing lock account " + ownerId);
-                }
-
-                _accountDao.releaseFromLockTable(ownerId);
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Releasing lock account " + ownerId);
             }
+            _accountDao.releaseFromLockTable(ownerId);
+
             if (ip == null) {
                 s_logger.error("Unable to get source nat ip address for account " + ownerId);
             }
@@ -1218,7 +1224,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
 
         s_logger.debug("Associating ip " + ipToAssoc + " to network " + network);
 
-        IPAddressVO ip = _ipAddressDao.findById(ipId);
+        IPAddressVO ip = ipToAssoc; //_ipAddressDao.findById(ipId);
         //update ip address with networkId
         ip.setAssociatedWithNetworkId(networkId);
         ip.setSourceNat(isSourceNat);
@@ -1235,18 +1241,16 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
             return ip;
         } finally {
             if (!success && releaseOnFailure) {
-                if (ip != null) {
-                    try {
-                        s_logger.warn("Failed to associate ip address, so releasing ip from
the database " + ip);
-                        _ipAddressDao.markAsUnavailable(ip.getId());
-                        if (!applyIpAssociations(network, true)) {
-                            // if fail to apply ip assciations again, unassign ip address
without updating resource
-                            // count and generating usage event as there is no need to keep
it in the db
-                            _ipAddressDao.unassignIpAddress(ip.getId());
-                        }
-                    } catch (Exception e) {
-                        s_logger.warn("Unable to disassociate ip address for recovery", e);
+                try {
+                    s_logger.warn("Failed to associate ip address, so releasing ip from the
database " + ip);
+                    _ipAddressDao.markAsUnavailable(ip.getId());
+                    if (!applyIpAssociations(network, true)) {
+                        // if fail to apply ip assciations again, unassign ip address without
updating resource
+                        // count and generating usage event as there is no need to keep it
in the db
+                        _ipAddressDao.unassignIpAddress(ip.getId());
                     }
+                } catch (Exception e) {
+                    s_logger.warn("Unable to disassociate ip address for recovery", e);
                 }
             }
         }
@@ -1327,7 +1331,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
         PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipToAssoc, _vlanDao.findById(ipToAssoc.getVlanId()));
         ipList.add(publicIp);
         Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList,
false, true);
-        if (ipToServices != null & !ipToServices.isEmpty()) {
+        if (ipToServices != null && !ipToServices.isEmpty()) {
             Set<Service> services = ipToServices.get(publicIp);
             if (services != null && !services.isEmpty()) {
                 throw new InvalidParameterValueException("IP " + ipToAssoc + " has services
and rules associated in the network " + networkId);
@@ -1368,7 +1372,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
         PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
         ipList.add(publicIp);
         Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList,
false, true);
-        if (ipToServices != null & !ipToServices.isEmpty()) {
+        if (ipToServices != null && !ipToServices.isEmpty()) {
             Set<Service> ipServices = ipToServices.get(publicIp);
             if (ipServices != null && !ipServices.isEmpty()) {
                 return false;
@@ -1671,14 +1675,14 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
 
     @Override
     public boolean applyStaticNats(List<? extends StaticNat> staticNats, boolean continueOnError,
boolean forRevoke) throws ResourceUnavailableException {
-        Network network = _networksDao.findById(staticNats.get(0).getNetworkId());
-        boolean success = true;
-
         if (staticNats == null || staticNats.size() == 0) {
             s_logger.debug("There are no static nat rules for the network elements");
             return true;
         }
 
+        Network network = _networksDao.findById(staticNats.get(0).getNetworkId());
+        boolean success = true;
+
         // get the list of public ip's owned by the network
         List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(),
null);
         List<PublicIp> publicIps = new ArrayList<PublicIp>();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index 52a08e1..68807d3 100755
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -1017,14 +1017,14 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
         List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
 
         for (NetworkOfferingServiceMapVO instance : map) {
-            String service = instance.getService();
+            Service service = Network.Service.getService(instance.getService());
             Set<Provider> providers;
             providers = serviceProviderMap.get(service);
             if (providers == null) {
                 providers = new HashSet<Provider>();
             }
             providers.add(Provider.getProvider(instance.getProvider()));
-            serviceProviderMap.put(Service.getService(service), providers);
+            serviceProviderMap.put(service, providers);
         }
 
         return serviceProviderMap;
@@ -1533,6 +1533,9 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
 
     @Override
     public void checkNetworkPermissions(Account owner, Network network) {
+        if (network == null) {
+            throw new CloudRuntimeException("no network to check permissions for.");
+        }
         // Perform account permission check
         if (network.getGuestType() != Network.GuestType.Shared || (network.getGuestType()
== Network.GuestType.Shared && network.getAclType() == ACLType.Account)) {
             AccountVO networkOwner = _accountDao.findById(network.getAccountId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/network/guru/ControlNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java
index a6e2180..13ff385 100755
--- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java
@@ -224,12 +224,12 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements
NetworkGu
 
         Map<String, String> dbParams = _configDao.getConfiguration(params);
 
-        _cidr = dbParams.get(Config.ControlCidr);
+        _cidr = dbParams.get(Config.ControlCidr.toString());
         if (_cidr == null) {
             _cidr = "169.254.0.0/16";
         }
 
-        _gateway = dbParams.get(Config.ControlGateway);
+        _gateway = dbParams.get(Config.ControlGateway.toString());
         if (_gateway == null) {
             _gateway = NetUtils.getLinkLocalGateway();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 2face90..51e476f 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -424,14 +424,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager,
VpcProvis
         List<VpcOfferingServiceMapVO> map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId);
 
         for (VpcOfferingServiceMapVO instance : map) {
-            String service = instance.getService();
+            Service service = Service.getService(instance.getService());
             Set<Provider> providers;
             providers = serviceProviderMap.get(service);
             if (providers == null) {
                 providers = new HashSet<Provider>();
             }
             providers.add(Provider.getProvider(instance.getProvider()));
-            serviceProviderMap.put(Service.getService(service), providers);
+            serviceProviderMap.put(service, providers);
         }
 
         return serviceProviderMap;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fae05560/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 ac641a2..56232d2 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -425,7 +425,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         if (isISO) {
             desc = Upload.Type.ISO.toString();
         }
-        eventId = eventId == null ? 0 : eventId;
+        eventId = (eventId == null ? 0 : eventId);
 
         if (!_accountMgr.isRootAdmin(caller.getType()) && _disableExtraction) {
             throw new PermissionDeniedException("Extraction has been disabled by admin");
@@ -1785,7 +1785,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         }
 
         // Don't allow to modify system template
-        if (id == Long.valueOf(1)) {
+        if (Long.valueOf(1).equals(id)) {
             InvalidParameterValueException ex = new InvalidParameterValueException("Unable
to update template/iso of specified id");
             ex.addProxyObject(String.valueOf(id), "templateId");
             throw ex;


Mime
View raw message