Skip to content

Commit 90c485e

Browse files
author
Alena Prokharchyk
committed
Fixed some problems reported by FindBugs
1 parent 67ab321 commit 90c485e

8 files changed

Lines changed: 29 additions & 137 deletions

File tree

api/src/org/apache/cloudstack/api/BaseListCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public abstract class BaseListCmd extends BaseCmd {
2525

2626
private static Long s_maxPageSize = null;
27-
public static Long s_pageSizeUnlimited = -1L;
27+
public static final Long s_pageSizeUnlimited = -1L;
2828

2929
// ///////////////////////////////////////////////////
3030
// ///////// BaseList API parameters /////////////////

engine/schema/src/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@Component
4040
@Local(value = {VmRulesetLogDao.class})
4141
public class VmRulesetLogDaoImpl extends GenericDaoBase<VmRulesetLogVO, Long> implements VmRulesetLogDao {
42-
protected static Logger s_logger = Logger.getLogger(VmRulesetLogDaoImpl.class);
42+
protected static final Logger s_logger = Logger.getLogger(VmRulesetLogDaoImpl.class);
4343
private SearchBuilder<VmRulesetLogVO> VmIdSearch;
4444
private String InsertOrUpdateSQl = "INSERT INTO op_vm_ruleset_log (instance_id, created, logsequence) "
4545
+ " VALUES(?, now(), 1) ON DUPLICATE KEY UPDATE logsequence=logsequence+1";

engine/schema/src/com/cloud/projects/ProjectVO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.cloudstack.api.Identity;
3232
import org.apache.cloudstack.api.InternalIdentity;
3333

34+
import com.cloud.utils.NumbersUtil;
3435
import com.cloud.utils.db.GenericDao;
3536

3637
@Entity
@@ -161,4 +162,8 @@ public void setUuid(String uuid) {
161162
this.uuid = uuid;
162163
}
163164

165+
@Override
166+
public int hashCode() {
167+
return NumbersUtil.hash(id);
168+
}
164169
}

framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.codec.binary.Base64;
3030
import org.apache.log4j.Logger;
3131

32+
import com.cloud.utils.exception.CloudRuntimeException;
3233
import com.google.gson.Gson;
3334
import com.google.gson.GsonBuilder;
3435
import com.google.gson.JsonDeserializationContext;
@@ -40,14 +41,12 @@
4041
import com.google.gson.JsonSerializationContext;
4142
import com.google.gson.JsonSerializer;
4243

43-
import com.cloud.utils.exception.CloudRuntimeException;
44-
4544
/**
4645
* Note: toPairList and appendPairList only support simple POJO objects currently
4746
*/
4847
public class JobSerializerHelper {
4948
private static final Logger s_logger = Logger.getLogger(JobSerializerHelper.class);
50-
public static String token = "/";
49+
public static final String token = "/";
5150

5251
private static Gson s_gson;
5352
static {

plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@
3030
import javax.ejb.Local;
3131
import javax.naming.ConfigurationException;
3232

33+
import org.apache.cloudstack.framework.events.Event;
34+
import org.apache.cloudstack.framework.events.EventBus;
35+
import org.apache.cloudstack.framework.events.EventBusException;
36+
import org.apache.cloudstack.framework.events.EventSubscriber;
37+
import org.apache.cloudstack.framework.events.EventTopic;
38+
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
3339
import org.apache.log4j.Logger;
3440

41+
import com.cloud.utils.Ternary;
42+
import com.cloud.utils.component.ManagerBase;
3543
import com.rabbitmq.client.AMQP;
3644
import com.rabbitmq.client.AlreadyClosedException;
3745
import com.rabbitmq.client.Channel;
@@ -43,16 +51,6 @@
4351
import com.rabbitmq.client.ShutdownListener;
4452
import com.rabbitmq.client.ShutdownSignalException;
4553

46-
import org.apache.cloudstack.framework.events.Event;
47-
import org.apache.cloudstack.framework.events.EventBus;
48-
import org.apache.cloudstack.framework.events.EventBusException;
49-
import org.apache.cloudstack.framework.events.EventSubscriber;
50-
import org.apache.cloudstack.framework.events.EventTopic;
51-
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
52-
53-
import com.cloud.utils.Ternary;
54-
import com.cloud.utils.component.ManagerBase;
55-
5654
@Local(value = EventBus.class)
5755
public class RabbitMQEventBus extends ManagerBase implements EventBus {
5856

server/src/com/cloud/dc/DedicatedResourceVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.persistence.Id;
2626
import javax.persistence.Table;
2727

28+
import com.cloud.utils.NumbersUtil;
29+
2830
@Entity
2931
@Table(name = "dedicated_resources")
3032
public class DedicatedResourceVO implements DedicatedResources {
@@ -163,4 +165,9 @@ public boolean equals(Object obj) {
163165
return false;
164166
}
165167
}
168+
169+
@Override
170+
public int hashCode() {
171+
return NumbersUtil.hash(id);
172+
}
166173
}

server/src/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ public IPAddressVO disassociatePortableIPToGuestNetwork(long ipId, long networkI
13461346
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipToAssoc, _vlanDao.findById(ipToAssoc.getVlanId()));
13471347
ipList.add(publicIp);
13481348
Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
1349-
if (ipToServices != null & !ipToServices.isEmpty()) {
1349+
if (!ipToServices.isEmpty()) {
13501350
Set<Service> services = ipToServices.get(publicIp);
13511351
if (services != null && !services.isEmpty()) {
13521352
throw new InvalidParameterValueException("IP " + ipToAssoc + " has services and rules associated in the network " + networkId);
@@ -1387,7 +1387,7 @@ public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId
13871387
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
13881388
ipList.add(publicIp);
13891389
Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
1390-
if (ipToServices != null & !ipToServices.isEmpty()) {
1390+
if (!ipToServices.isEmpty()) {
13911391
Set<Service> ipServices = ipToServices.get(publicIp);
13921392
if (ipServices != null && !ipServices.isEmpty()) {
13931393
return false;

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 3 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,10 @@
4040
import javax.inject.Inject;
4141
import javax.naming.ConfigurationException;
4242

43-
import org.apache.commons.codec.binary.Base64;
44-
import org.apache.log4j.Logger;
45-
4643
import org.apache.cloudstack.acl.ControlledEntity;
47-
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
4844
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
4945
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
5046
import org.apache.cloudstack.api.ApiConstants;
51-
import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
5247
import org.apache.cloudstack.api.command.admin.account.CreateAccountCmd;
5348
import org.apache.cloudstack.api.command.admin.account.DeleteAccountCmd;
5449
import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd;
@@ -465,6 +460,8 @@
465460
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
466461
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
467462
import org.apache.cloudstack.utils.identity.ManagementServerNode;
463+
import org.apache.commons.codec.binary.Base64;
464+
import org.apache.log4j.Logger;
468465

469466
import com.cloud.agent.AgentManager;
470467
import com.cloud.agent.api.GetVncPortAnswer;
@@ -556,34 +553,28 @@
556553
import com.cloud.storage.GuestOSHypervisorVO;
557554
import com.cloud.storage.GuestOSVO;
558555
import com.cloud.storage.GuestOsCategory;
559-
import com.cloud.storage.Storage.ImageFormat;
560-
import com.cloud.storage.Storage.TemplateType;
561556
import com.cloud.storage.StorageManager;
562557
import com.cloud.storage.StoragePool;
563-
import com.cloud.storage.VMTemplateVO;
564558
import com.cloud.storage.Volume;
565559
import com.cloud.storage.VolumeVO;
566560
import com.cloud.storage.dao.DiskOfferingDao;
567561
import com.cloud.storage.dao.GuestOSCategoryDao;
568562
import com.cloud.storage.dao.GuestOSDao;
569563
import com.cloud.storage.dao.GuestOSHypervisorDao;
570-
import com.cloud.storage.dao.VMTemplateDao;
571564
import com.cloud.storage.dao.VolumeDao;
572565
import com.cloud.storage.secondary.SecondaryStorageVmManager;
573566
import com.cloud.tags.ResourceTagVO;
574567
import com.cloud.tags.dao.ResourceTagDao;
575568
import com.cloud.template.TemplateManager;
576569
import com.cloud.user.Account;
577570
import com.cloud.user.AccountManager;
578-
import com.cloud.user.AccountService;
579571
import com.cloud.user.SSHKeyPair;
580572
import com.cloud.user.SSHKeyPairVO;
581573
import com.cloud.user.User;
582574
import com.cloud.user.UserVO;
583575
import com.cloud.user.dao.AccountDao;
584576
import com.cloud.user.dao.SSHKeyPairDao;
585577
import com.cloud.user.dao.UserDao;
586-
import com.cloud.utils.EnumUtils;
587578
import com.cloud.utils.NumbersUtil;
588579
import com.cloud.utils.Pair;
589580
import com.cloud.utils.PasswordGenerator;
@@ -668,8 +659,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
668659
@Inject
669660
private DiskOfferingDao _diskOfferingDao;
670661
@Inject
671-
private VMTemplateDao _templateDao;
672-
@Inject
673662
private DomainDao _domainDao;
674663
@Inject
675664
private AccountDao _accountDao;
@@ -734,15 +723,11 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
734723
@Inject
735724
private UserVmManager _userVmMgr;
736725
@Inject
737-
private AccountService _accountService;
738-
@Inject
739726
private ServiceOfferingDao _offeringDao;
740-
741727
@Inject
742728
private DeploymentPlanningManager _dpMgr;
743729

744730
private LockMasterListener _lockMasterListener;
745-
746731
private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker"));
747732
private final ScheduledExecutorService _alertExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AlertChecker"));
748733
@Inject
@@ -1809,108 +1794,6 @@ private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String
18091794
}
18101795
*/
18111796

1812-
private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
1813-
Long id = cmd.getId();
1814-
String name = cmd.getTemplateName();
1815-
String displayText = cmd.getDisplayText();
1816-
String format = cmd.getFormat();
1817-
Long guestOSId = cmd.getOsTypeId();
1818-
Boolean passwordEnabled = cmd.isPasswordEnabled();
1819-
Boolean bootable = cmd.isBootable();
1820-
Integer sortKey = cmd.getSortKey();
1821-
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
1822-
Boolean isRoutingTemplate = cmd.isRoutingType();
1823-
Account account = CallContext.current().getCallingAccount();
1824-
1825-
// verify that template exists
1826-
VMTemplateVO template = _templateDao.findById(id);
1827-
if (template == null || template.getRemoved() != null) {
1828-
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find template/iso with specified id");
1829-
ex.addProxyObject(id.toString(), "templateId");
1830-
throw ex;
1831-
}
1832-
1833-
// Don't allow to modify system template
1834-
if (id.equals(Long.valueOf(1))) {
1835-
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
1836-
ex.addProxyObject(template.getUuid(), "templateId");
1837-
throw ex;
1838-
}
1839-
1840-
// do a permission check
1841-
_accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
1842-
1843-
if (cmd.isRoutingType() != null) {
1844-
if (!_accountService.isRootAdmin(account.getType())) {
1845-
throw new PermissionDeniedException("Parameter isrouting can only be specified by a Root Admin, permission denied");
1846-
}
1847-
}
1848-
boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null && sortKey == null
1849-
&& isDynamicallyScalable == null && isRoutingTemplate == null);
1850-
if (!updateNeeded) {
1851-
return template;
1852-
}
1853-
1854-
template = _templateDao.createForUpdate(id);
1855-
1856-
if (name != null) {
1857-
template.setName(name);
1858-
}
1859-
1860-
if (displayText != null) {
1861-
template.setDisplayText(displayText);
1862-
}
1863-
1864-
if (sortKey != null) {
1865-
template.setSortKey(sortKey);
1866-
}
1867-
1868-
ImageFormat imageFormat = null;
1869-
if (format != null) {
1870-
try {
1871-
imageFormat = ImageFormat.valueOf(format.toUpperCase());
1872-
} catch (IllegalArgumentException e) {
1873-
throw new InvalidParameterValueException("Image format: " + format + " is incorrect. Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
1874-
}
1875-
1876-
template.setFormat(imageFormat);
1877-
}
1878-
1879-
if (guestOSId != null) {
1880-
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
1881-
1882-
if (guestOS == null) {
1883-
throw new InvalidParameterValueException("Please specify a valid guest OS ID.");
1884-
} else {
1885-
template.setGuestOSId(guestOSId);
1886-
}
1887-
}
1888-
1889-
if (passwordEnabled != null) {
1890-
template.setEnablePassword(passwordEnabled);
1891-
}
1892-
1893-
if (bootable != null) {
1894-
template.setBootable(bootable);
1895-
}
1896-
1897-
if (isDynamicallyScalable != null) {
1898-
template.setDynamicallyScalable(isDynamicallyScalable);
1899-
}
1900-
1901-
if (isRoutingTemplate != null) {
1902-
if (isRoutingTemplate) {
1903-
template.setTemplateType(TemplateType.ROUTING);
1904-
} else {
1905-
template.setTemplateType(TemplateType.USER);
1906-
}
1907-
}
1908-
1909-
_templateDao.update(id, template);
1910-
1911-
return _templateDao.findById(id);
1912-
}
1913-
19141797
@Override
19151798
public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(ListPublicIpAddressesCmd cmd) {
19161799
Object keyword = cmd.getKeyword();
@@ -3462,7 +3345,7 @@ public Map<String, Object> listCapabilities(ListCapabilitiesCmd cmd) {
34623345
}
34633346
}
34643347

3465-
long diskOffMaxSize = _volumeMgr.CustomDiskOfferingMaxSize.value();
3348+
long diskOffMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
34663349
KVMSnapshotEnabled = Boolean.parseBoolean(_configDao.getValue("KVM.snapshot.enabled"));
34673350

34683351
boolean userPublicTemplateEnabled = TemplateManager.AllowPublicUserTemplates.valueIn(caller.getId());

0 commit comments

Comments
 (0)