Findbugs: different issues solved

This commit is contained in:
Daan Hoogland 2014-01-26 23:14:17 +01:00 committed by Daan Hoogland
parent 1fb32b58eb
commit dcda79e2c0
9 changed files with 97 additions and 75 deletions

View File

@ -35,6 +35,7 @@ import com.cloud.server.ResourceTag.ResourceObjectType;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
@ -47,10 +48,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
private long id; private long id;
@Column(name="name", updatable=false, nullable=false, length=255) @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) @Column(name="display_name", updatable=false, nullable=false, length=255)
private String displayName = null; private final String displayName = null;
@Column(name="account_id") @Column(name="account_id")
private long accountId; private long accountId;
@ -59,7 +60,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
private String accountUuid; private String accountUuid;
@Column(name="account_name") @Column(name="account_name")
private String accountName = null; private final String accountName = null;
@Column(name="account_type") @Column(name="account_type")
private short accountType; private short accountType;
@ -71,10 +72,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
private String domainUuid; private String domainUuid;
@Column(name="domain_name") @Column(name="domain_name")
private String domainName = null; private final String domainName = null;
@Column(name="domain_path") @Column(name="domain_path")
private String domainPath = null; private final String domainPath = null;
@Column(name="instance_group_id") @Column(name="instance_group_id")
private long instanceGroupId; private long instanceGroupId;
@ -96,7 +97,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
*/ */
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
@Column(name="state", updatable=true, nullable=false, length=32) @Column(name="state", updatable=true, nullable=false, length=32)
private State state = null; private final State state = null;
@Column(name=GenericDao.CREATED_COLUMN) @Column(name=GenericDao.CREATED_COLUMN)
private Date created; private Date created;
@ -149,7 +150,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
private String dataCenterUuid; private String dataCenterUuid;
@Column(name="data_center_name") @Column(name="data_center_name")
private String dataCenterName = null; private final String dataCenterName = null;
@Column(name="security_group_enabled") @Column(name="security_group_enabled")
private boolean securityGroupEnabled; private boolean securityGroupEnabled;
@ -225,7 +226,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
private String volume_uuid; private String volume_uuid;
@Column(name = "volume_device_id") @Column(name = "volume_device_id")
private Long volumeDeviceId = null; private final Long volumeDeviceId = null;
@Column(name = "volume_type") @Column(name = "volume_type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@ -726,9 +727,11 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
} }
public String getDetail(String name) { 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() { public String getUserData() {

View File

@ -22,6 +22,11 @@ import java.util.Random;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
import com.cloud.agent.api.AgentControlAnswer; import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
@ -44,14 +49,10 @@ import com.cloud.server.ManagementServer;
import com.cloud.servlet.ConsoleProxyPasswordBasedEncryptor; import com.cloud.servlet.ConsoleProxyPasswordBasedEncryptor;
import com.cloud.servlet.ConsoleProxyServlet; import com.cloud.servlet.ConsoleProxyServlet;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.VMInstanceDao; import com.cloud.vm.dao.VMInstanceDao;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
/** /**
* Utility class to manage interactions with agent-based console access * Utility class to manage interactions with agent-based console access
* Extracted from ConsoleProxyManagerImpl so that other console proxy managers * Extracted from ConsoleProxyManagerImpl so that other console proxy managers
@ -72,12 +73,12 @@ public abstract class AgentHookBase implements AgentHook {
public AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr, public AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr,
AgentManager agentMgr, ManagementServer ms) { AgentManager agentMgr, ManagementServer ms) {
this._instanceDao = instanceDao; _instanceDao = instanceDao;
this._hostDao = hostDao; _hostDao = hostDao;
this._agentMgr = agentMgr; _agentMgr = agentMgr;
this._configDao = cfgDao; _configDao = cfgDao;
this._ksMgr = ksMgr; _ksMgr = ksMgr;
this._ms = ms; _ms = ms;
} }
@Override @Override
@ -204,7 +205,9 @@ public abstract class AgentHookBase implements AgentHook {
assert (ksBits != null); assert (ksBits != null);
if (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 = new StartConsoleProxyAgentHttpHandlerCommand(ksBits, storePassword);
cmd.setEncryptorPassword(getEncryptorPassword()); cmd.setEncryptorPassword(getEncryptorPassword());

View File

@ -970,11 +970,7 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
} }
} else { } else {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
if (template == null) { s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
s_logger.debug("Zone host is ready, but console proxy template is null");
} else {
s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
}
} }
} }
} }

View File

@ -20,7 +20,6 @@ import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
@ -31,6 +30,11 @@ import javax.persistence.Table;
@Table(name="dedicated_resources") @Table(name="dedicated_resources")
public class DedicatedResourceVO implements DedicatedResources{ public class DedicatedResourceVO implements DedicatedResources{
/**
*
*/
private static final long serialVersionUID = -6659510127145101917L;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id") @Column(name="id")
@ -61,7 +65,7 @@ public class DedicatedResourceVO implements DedicatedResources{
private long affinityGroupId; private long affinityGroupId;
public DedicatedResourceVO() { public DedicatedResourceVO() {
this.uuid = UUID.randomUUID().toString(); uuid = UUID.randomUUID().toString();
} }
public DedicatedResourceVO(Long dataCenterId, Long podId, Long clusterId, Long hostId, Long domainId, public DedicatedResourceVO(Long dataCenterId, Long podId, Long clusterId, Long hostId, Long domainId,
@ -72,14 +76,16 @@ public class DedicatedResourceVO implements DedicatedResources{
this.hostId = hostId; this.hostId = hostId;
this.domainId = domainId; this.domainId = domainId;
this.accountId = accountId; this.accountId = accountId;
this.uuid = UUID.randomUUID().toString(); uuid = UUID.randomUUID().toString();
this.affinityGroupId = affinityGroupId; this.affinityGroupId = affinityGroupId;
} }
@Override
public long getId() { public long getId() {
return id; return id;
} }
@Override
public Long getDataCenterId() { public Long getDataCenterId() {
return dataCenterId; return dataCenterId;
} }
@ -88,6 +94,7 @@ public class DedicatedResourceVO implements DedicatedResources{
this.dataCenterId = dataCenterId; this.dataCenterId = dataCenterId;
} }
@Override
public Long getPodId() { public Long getPodId() {
return podId; return podId;
} }
@ -96,6 +103,7 @@ public class DedicatedResourceVO implements DedicatedResources{
this.podId = podId; this.podId = podId;
} }
@Override
public Long getClusterId() { public Long getClusterId() {
return clusterId; return clusterId;
} }
@ -104,6 +112,7 @@ public class DedicatedResourceVO implements DedicatedResources{
this.clusterId = clusterId; this.clusterId = clusterId;
} }
@Override
public Long getHostId() { public Long getHostId() {
return hostId; return hostId;
} }
@ -113,9 +122,10 @@ public class DedicatedResourceVO implements DedicatedResources{
} }
public DedicatedResourceVO(long dedicatedResourceId) { public DedicatedResourceVO(long dedicatedResourceId) {
this.id = dedicatedResourceId; id = dedicatedResourceId;
} }
@Override
public Long getDomainId() { public Long getDomainId() {
return domainId; return domainId;
} }
@ -124,6 +134,7 @@ public class DedicatedResourceVO implements DedicatedResources{
this.domainId = domainId; this.domainId = domainId;
} }
@Override
public Long getAccountId() { public Long getAccountId() {
return accountId; return accountId;
} }
@ -132,14 +143,16 @@ public class DedicatedResourceVO implements DedicatedResources{
this.accountId = accountId; this.accountId = accountId;
} }
@Override
public String getUuid() { public String getUuid() {
return this.uuid; return uuid;
} }
public void setUuid(String uuid) { public void setUuid(String uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
@Override
public long getAffinityGroupId() { public long getAffinityGroupId() {
return affinityGroupId; return affinityGroupId;
} }
@ -147,7 +160,7 @@ public class DedicatedResourceVO implements DedicatedResources{
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof DedicatedResourceVO) { if (obj instanceof DedicatedResourceVO) {
return ((DedicatedResourceVO) obj).getId() == this.getId(); return ((DedicatedResourceVO) obj).getId() == getId();
} else { } else {
return false; return false;
} }

View File

@ -17,6 +17,7 @@
package com.cloud.network; package com.cloud.network;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -29,6 +30,7 @@ import java.util.UUID;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
@ -138,14 +140,14 @@ import com.cloud.utils.db.DB;
import com.cloud.utils.db.EntityManager; import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.Filter; import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionCallbackWithException;
import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.JoinBuilder.JoinType;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionCallbackWithException;
import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn; import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn;
import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
@ -578,8 +580,9 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
IPAddressVO ip = markIpAsUnavailable(addrId); IPAddressVO ip = markIpAsUnavailable(addrId);
assert (ip != null) : "Unable to mark the ip address id=" + addrId + " as unavailable.";
if (ip == null) { if (ip == null) {
String msg = "Unable to mark the ip address id=" + addrId + " as unavailable.";
s_logger.error(msg);
return true; return true;
} }
@ -692,10 +695,10 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) { if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
fetchFromDedicatedRange = true; fetchFromDedicatedRange = true;
sc.setParameters("vlanId", dedicatedVlanDbIds.toArray()); 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()) { } else if (nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray()); sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray());
errorMessage.append(", vlanId id=" + nonDedicatedVlanDbIds.toArray()); errorMessage.append(", vlanId id=" + Arrays.toString(nonDedicatedVlanDbIds.toArray()));
} else { } else {
if (podId != null) { if (podId != null) {
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId); InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
@ -735,7 +738,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) { if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) {
fetchFromDedicatedRange = false; fetchFromDedicatedRange = false;
sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray()); 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); addrs = _ipAddressDao.lockRows(sc, filter, true);
} }
} }
@ -868,6 +871,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, public PublicIp assignDedicateIpAddress(Account owner, final Long guestNtwkId, final Long vpcId, final long dcId, final boolean isSourceNat) throws ConcurrentOperationException,
InsufficientAddressCapacityException { InsufficientAddressCapacityException {
if (owner == null) {
s_logger.error("No account to assign an ip to.");
return null;
}
final long ownerId = owner.getId(); final long ownerId = owner.getId();
PublicIp ip = null; PublicIp ip = null;
@ -899,13 +907,11 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
return ip; return ip;
} finally { } finally {
if (owner != null) { if (s_logger.isDebugEnabled()) {
if (s_logger.isDebugEnabled()) { s_logger.debug("Releasing lock account " + ownerId);
s_logger.debug("Releasing lock account " + ownerId);
}
_accountDao.releaseFromLockTable(ownerId);
} }
_accountDao.releaseFromLockTable(ownerId);
if (ip == null) { if (ip == null) {
s_logger.error("Unable to get source nat ip address for account " + ownerId); s_logger.error("Unable to get source nat ip address for account " + ownerId);
} }
@ -1253,7 +1259,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
s_logger.debug("Associating ip " + ipToAssoc + " to network " + network); 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 //update ip address with networkId
ip.setAssociatedWithNetworkId(networkId); ip.setAssociatedWithNetworkId(networkId);
ip.setSourceNat(isSourceNat); ip.setSourceNat(isSourceNat);
@ -1270,18 +1276,16 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
return ip; return ip;
} finally { } finally {
if (!success && releaseOnFailure) { if (!success && releaseOnFailure) {
if (ip != null) { try {
try { s_logger.warn("Failed to associate ip address, so releasing ip from the database " + ip);
s_logger.warn("Failed to associate ip address, so releasing ip from the database " + ip); _ipAddressDao.markAsUnavailable(ip.getId());
_ipAddressDao.markAsUnavailable(ip.getId()); if (!applyIpAssociations(network, true)) {
if (!applyIpAssociations(network, true)) { // if fail to apply ip assciations again, unassign ip address without updating resource
// 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
// count and generating usage event as there is no need to keep it in the db _ipAddressDao.unassignIpAddress(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
}
} catch (Exception e) {
s_logger.warn("Unable to disassociate ip address for recovery", e);
} }
} catch (Exception e) {
s_logger.warn("Unable to disassociate ip address for recovery", e);
} }
} }
} }
@ -1362,7 +1366,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipToAssoc, _vlanDao.findById(ipToAssoc.getVlanId())); PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipToAssoc, _vlanDao.findById(ipToAssoc.getVlanId()));
ipList.add(publicIp); ipList.add(publicIp);
Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true); 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); Set<Service> services = ipToServices.get(publicIp);
if (services != null && !services.isEmpty()) { if (services != null && !services.isEmpty()) {
throw new InvalidParameterValueException("IP " + ipToAssoc + " has services and rules associated in the network " + networkId); throw new InvalidParameterValueException("IP " + ipToAssoc + " has services and rules associated in the network " + networkId);
@ -1403,7 +1407,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId())); PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
ipList.add(publicIp); ipList.add(publicIp);
Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true); 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); Set<Service> ipServices = ipToServices.get(publicIp);
if (ipServices != null && !ipServices.isEmpty()) { if (ipServices != null && !ipServices.isEmpty()) {
return false; return false;
@ -1732,14 +1736,14 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
@Override @Override
public boolean applyStaticNats(List<? extends StaticNat> staticNats, boolean continueOnError, boolean forRevoke) throws ResourceUnavailableException { 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) { if (staticNats == null || staticNats.size() == 0) {
s_logger.debug("There are no static nat rules for the network elements"); s_logger.debug("There are no static nat rules for the network elements");
return true; return true;
} }
Network network = _networksDao.findById(staticNats.get(0).getNetworkId());
boolean success = true;
// get the list of public ip's owned by the network // get the list of public ip's owned by the network
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null); List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
List<PublicIp> publicIps = new ArrayList<PublicIp>(); List<PublicIp> publicIps = new ArrayList<PublicIp>();

View File

@ -1024,14 +1024,14 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId); List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
for (NetworkOfferingServiceMapVO instance : map) { for (NetworkOfferingServiceMapVO instance : map) {
String service = instance.getService(); Service service = Network.Service.getService(instance.getService());
Set<Provider> providers; Set<Provider> providers;
providers = serviceProviderMap.get(service); providers = serviceProviderMap.get(service);
if (providers == null) { if (providers == null) {
providers = new HashSet<Provider>(); providers = new HashSet<Provider>();
} }
providers.add(Provider.getProvider(instance.getProvider())); providers.add(Provider.getProvider(instance.getProvider()));
serviceProviderMap.put(Service.getService(service), providers); serviceProviderMap.put(service, providers);
} }
return serviceProviderMap; return serviceProviderMap;
@ -1526,12 +1526,15 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
@Override @Override
public void checkNetworkPermissions(Account owner, Network network) { public void checkNetworkPermissions(Account owner, Network network) {
if (network == null) {
throw new CloudRuntimeException("no network to check permissions for.");
}
// Perform account permission check // Perform account permission check
if (network.getGuestType() != Network.GuestType.Shared if (network.getGuestType() != Network.GuestType.Shared
|| (network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Account)) { || (network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Account)) {
AccountVO networkOwner = _accountDao.findById(network.getAccountId()); AccountVO networkOwner = _accountDao.findById(network.getAccountId());
if(networkOwner == null) if(networkOwner == null)
throw new PermissionDeniedException("Unable to use network with id= " + ((network != null)? ((NetworkVO)network).getUuid() : "") + ", network does not have an owner"); throw new PermissionDeniedException("Unable to use network with id= " + ((NetworkVO)network).getUuid() + ", network does not have an owner");
if(owner.getType() != Account.ACCOUNT_TYPE_PROJECT && networkOwner.getType() == Account.ACCOUNT_TYPE_PROJECT){ if(owner.getType() != Account.ACCOUNT_TYPE_PROJECT && networkOwner.getType() == Account.ACCOUNT_TYPE_PROJECT){
if(!_projectAccountDao.canAccessProjectAccount(owner.getAccountId(), network.getAccountId())){ if(!_projectAccountDao.canAccessProjectAccount(owner.getAccountId(), network.getAccountId())){
throw new PermissionDeniedException("Unable to use network with id= " + ((network != null)? ((NetworkVO)network).getUuid() : "") + ", permission denied"); throw new PermissionDeniedException("Unable to use network with id= " + ((network != null)? ((NetworkVO)network).getUuid() : "") + ", permission denied");
@ -1545,7 +1548,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
} else { } else {
if (!isNetworkAvailableInDomain(network.getId(), owner.getDomainId())) { if (!isNetworkAvailableInDomain(network.getId(), owner.getDomainId())) {
throw new PermissionDeniedException("Shared network id=" + ((network != null)? ((NetworkVO)network).getUuid() : "") + " is not available in domain id=" + owner.getDomainId()); throw new PermissionDeniedException("Shared network id=" + ((NetworkVO)network).getUuid() + " is not available in domain id=" + owner.getDomainId());
} }
} }
} }

View File

@ -134,7 +134,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
assert nic.getTrafficType() == TrafficType.Control; assert nic.getTrafficType() == TrafficType.Control;
// we have to get management/private ip for the control nic for vmware/hyperv due ssh issues. // we have to get management/private ip for the control nic for vmware/hyperv due ssh issues.
HypervisorType hType = dest.getHost().getHypervisorType(); HypervisorType hType = dest.getHost().getHypervisorType();
if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) { if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) {
if(dest.getDataCenter().getNetworkType() != NetworkType.Basic) { if(dest.getDataCenter().getNetworkType() != NetworkType.Basic) {
super.reserve(nic, config, vm, dest, context); super.reserve(nic, config, vm, dest, context);
@ -168,7 +168,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
@Override @Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
assert nic.getTrafficType() == TrafficType.Control; assert nic.getTrafficType() == TrafficType.Control;
HypervisorType hType = vm.getHypervisorType(); HypervisorType hType = vm.getHypervisorType();
if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) { if ( ( (hType == HypervisorType.VMware) || (hType == HypervisorType.Hyperv) )&& isRouterVm(vm)) {
long dcId = vm.getVirtualMachine().getDataCenterId(); long dcId = vm.getVirtualMachine().getDataCenterId();
DataCenterVO dcVo = _dcDao.findById(dcId); DataCenterVO dcVo = _dcDao.findById(dcId);
@ -218,12 +218,12 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
Map<String, String> dbParams = _configDao.getConfiguration(params); Map<String, String> dbParams = _configDao.getConfiguration(params);
_cidr = dbParams.get(Config.ControlCidr); _cidr = dbParams.get(Config.ControlCidr.toString());
if (_cidr == null) { if (_cidr == null) {
_cidr = "169.254.0.0/16"; _cidr = "169.254.0.0/16";
} }
_gateway = dbParams.get(Config.ControlGateway); _gateway = dbParams.get(Config.ControlGateway.toString());
if (_gateway == null) { if (_gateway == null) {
_gateway = NetUtils.getLinkLocalGateway(); _gateway = NetUtils.getLinkLocalGateway();
} }

View File

@ -432,14 +432,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
List<VpcOfferingServiceMapVO> map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId); List<VpcOfferingServiceMapVO> map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId);
for (VpcOfferingServiceMapVO instance : map) { for (VpcOfferingServiceMapVO instance : map) {
String service = instance.getService(); Service service = Service.getService(instance.getService());
Set<Provider> providers; Set<Provider> providers;
providers = serviceProviderMap.get(service); providers = serviceProviderMap.get(service);
if (providers == null) { if (providers == null) {
providers = new HashSet<Provider>(); providers = new HashSet<Provider>();
} }
providers.add(Provider.getProvider(instance.getProvider())); providers.add(Provider.getProvider(instance.getProvider()));
serviceProviderMap.put(Service.getService(service), providers); serviceProviderMap.put(service, providers);
} }
return serviceProviderMap; return serviceProviderMap;

View File

@ -425,7 +425,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (isISO) { if (isISO) {
desc = Upload.Type.ISO.toString(); desc = Upload.Type.ISO.toString();
} }
eventId = eventId == null ? 0 : eventId; eventId = (eventId == null ? 0 : eventId);
if (!_accountMgr.isRootAdmin(caller.getType()) && _disableExtraction) { if (!_accountMgr.isRootAdmin(caller.getType()) && _disableExtraction) {
throw new PermissionDeniedException("Extraction has been disabled by admin"); throw new PermissionDeniedException("Extraction has been disabled by admin");
@ -1801,7 +1801,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
} }
// Don't allow to modify system template // 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"); InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
ex.addProxyObject(String.valueOf(id), "templateId"); ex.addProxyObject(String.valueOf(id), "templateId");
throw ex; throw ex;