From 9a6eaaf21fe2a74c4dcd5872093f03153f38497b Mon Sep 17 00:00:00 2001
From: abhishek
Date: Tue, 30 Nov 2010 12:26:50 -0800
Subject: [PATCH 01/32] this is a good point to commit the code; have the basic
domain specific service offering working
---
.../commands/CreateServiceOfferingCmd.java | 10 +-
.../api/commands/ListServiceOfferingsCmd.java | 7 +
.../api/response/ServiceOfferingResponse.java | 12 ++
.../com/cloud/offering/ServiceOffering.java | 2 +
.../src/com/cloud/storage/DiskOfferingVO.java | 15 ++
.../src/com/cloud/api/ApiResponseHelper.java | 1 +
.../configuration/ConfigurationManager.java | 3 +-
.../ConfigurationManagerImpl.java | 6 +-
.../cloud/server/ManagementServerImpl.java | 133 +++++++++++++++++-
.../com/cloud/service/ServiceOfferingVO.java | 14 +-
.../cloud/service/dao/ServiceOfferingDao.java | 6 +-
.../service/dao/ServiceOfferingDaoImpl.java | 35 ++++-
12 files changed, 232 insertions(+), 12 deletions(-)
diff --git a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java
index 0ab12647b60..99bd1955d1b 100644
--- a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java
+++ b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java
@@ -25,6 +25,7 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ServiceOfferingResponse;
import com.cloud.offering.ServiceOffering;
@@ -64,6 +65,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.USE_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="if true, the VM created will use default virtual networking. If false, the VM created will use a direct attached networking model. The default value is true.")
private Boolean useVirtualNetwork;
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
+ private Long domainId;
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -100,7 +104,11 @@ public class CreateServiceOfferingCmd extends BaseCmd {
return tags;
}
- public Boolean getUseVirtualNetwork() {
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public Boolean getUseVirtualNetwork() {
return useVirtualNetwork;
}
diff --git a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java
index 37aa4b01276..1c81a02c9f2 100644
--- a/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java
+++ b/api/src/com/cloud/api/commands/ListServiceOfferingsCmd.java
@@ -26,6 +26,7 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
+import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ServiceOfferingResponse;
import com.cloud.offering.ServiceOffering;
@@ -48,6 +49,9 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="the ID of the virtual machine. Pass this in if you want to see the available service offering that a virtual machine can be changed to.")
private Long virtualMachineId;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain associated with the service offering")
+ private Long domainId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@@ -65,6 +69,9 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
return virtualMachineId;
}
+ public Long getDomainId(){
+ return domainId;
+ }
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
diff --git a/api/src/com/cloud/api/response/ServiceOfferingResponse.java b/api/src/com/cloud/api/response/ServiceOfferingResponse.java
index 16cd432f1a9..3b4e45c66e9 100644
--- a/api/src/com/cloud/api/response/ServiceOfferingResponse.java
+++ b/api/src/com/cloud/api/response/ServiceOfferingResponse.java
@@ -56,6 +56,9 @@ public class ServiceOfferingResponse extends BaseResponse {
@SerializedName("tags") @Param(description="the tags for the service offering")
private String tags;
+ @SerializedName("domainId") @Param(description="the domain id of the service offering")
+ private Long domainId;
+
public Long getId() {
return id;
}
@@ -143,4 +146,13 @@ public class ServiceOfferingResponse extends BaseResponse {
public void setTags(String tags) {
this.tags = tags;
}
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public void setDomainId(Long domainId) {
+ this.domainId = domainId;
+ }
+
}
diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java
index 357715f59cc..aa9c97c1b8c 100755
--- a/api/src/com/cloud/offering/ServiceOffering.java
+++ b/api/src/com/cloud/offering/ServiceOffering.java
@@ -77,4 +77,6 @@ public interface ServiceOffering {
*/
boolean getUseLocalStorage();
+ Long getDomainId();
+
}
diff --git a/core/src/com/cloud/storage/DiskOfferingVO.java b/core/src/com/cloud/storage/DiskOfferingVO.java
index 591f609fd67..4c52e1bc9d3 100644
--- a/core/src/com/cloud/storage/DiskOfferingVO.java
+++ b/core/src/com/cloud/storage/DiskOfferingVO.java
@@ -120,6 +120,21 @@ public class DiskOfferingVO implements DiskOffering {
this.systemUse = systemUse;
this.customized = customized;
}
+
+ //domain specific offerings constructor (null domainId implies public offering)
+ public DiskOfferingVO(String name, String displayText, boolean mirrored, String tags, boolean recreatable, boolean useLocalStorage, boolean systemUse, boolean customized, Long domainId) {
+ this.domainId = null;
+ this.type = Type.Service;
+ this.name = name;
+ this.displayText = displayText;
+ this.mirrored = mirrored;
+ this.tags = tags;
+ this.recreatable = recreatable;
+ this.useLocalStorage = useLocalStorage;
+ this.systemUse = systemUse;
+ this.customized = customized;
+ this.domainId = domainId;
+ }
@Override
public long getId() {
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 4c8252be2d9..32e49738370 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -345,6 +345,7 @@ public class ApiResponseHelper implements ResponseGenerator {
offeringResponse.setOfferHa(offering.getOfferHA());
offeringResponse.setUseVirtualNetwork(offering.getGuestIpType().equals(GuestIpType.Virtualized));
offeringResponse.setTags(offering.getTags());
+ offeringResponse.setDomainId(offering.getDomainId());
offeringResponse.setObjectName("serviceoffering");
return offeringResponse;
diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java
index cad2d478858..75df0ec0b95 100644
--- a/server/src/com/cloud/configuration/ConfigurationManager.java
+++ b/server/src/com/cloud/configuration/ConfigurationManager.java
@@ -56,9 +56,10 @@ public interface ConfigurationManager extends Manager {
* @param localStorageRequired
* @param offerHA
* @param useVirtualNetwork
+ * @param domainId
* @return ID
*/
- ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags);
+ ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, Long domainId);
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 35949b11b41..4fefb4683ba 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1138,18 +1138,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
return createServiceOffering(userId, cmd.getServiceOfferingName(), cpuNumber.intValue(), memory.intValue(), cpuSpeed.intValue(), cmd.getDisplayText(),
- localStorageRequired, offerHA, useVirtualNetwork, cmd.getTags());
+ localStorageRequired, offerHA, useVirtualNetwork, cmd.getTags(),cmd.getDomainId());
}
@Override
- public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags) {
+ public ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean useVirtualNetwork, String tags, Long domainId) {
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
NetworkOffering.GuestIpType guestIpType = useVirtualNetwork ? NetworkOffering.GuestIpType.Virtualized : NetworkOffering.GuestIpType.DirectSingle;
tags = cleanupTags(tags);
- ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false);
+ ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, multicastRate, offerHA, displayText, guestIpType, localStorageRequired, false, tags, false,domainId);
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_CREATE, "Successfully created new service offering with name: " + name + ".", "soId=" + offering.getId(), "name=" + name, "numCPUs=" + cpu, "ram=" + ramSize, "cpuSpeed=" + speed,
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 31df6ab1c93..5167de6d50a 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -1592,17 +1592,70 @@ public class ManagementServerImpl implements ManagementServer {
return _userAccountDao.search(sc, searchFilter);
}
+
+ private boolean isPermissible(Long accountDomainId, Long serviceOfferingDomainId){
+
+ if(accountDomainId == serviceOfferingDomainId)
+ return true; // account and service offering in same domain
+
+ DomainVO domainRecord = _domainDao.findById(accountDomainId);
+
+ if(domainRecord != null){
+ while(true){
+ if(domainRecord.getId() == serviceOfferingDomainId)
+ return true;
+
+ //try and move on to the next domain
+ if(domainRecord.getParent() != null)
+ domainRecord = _domainDao.findById(domainRecord.getParent());
+ else
+ break;
+ }
+ }
+
+ return false;
+ }
@Override
public List searchForServiceOfferings(ListServiceOfferingsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
- Filter searchFilter = new Filter(ServiceOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
+
+ //Note
+ //The list method for offerings is being modified in accordance with discussion with Will/Kevin
+ //For now, we will be listing the following based on the usertype
+ //1. For root, we will list all offerings
+ //2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till root
+ Filter searchFilter = new Filter(ServiceOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchCriteria sc = _offeringsDao.createSearchCriteria();
+ Account account = UserContext.current().getAccount();
Object name = cmd.getServiceOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long vmId = cmd.getVirtualMachineId();
-
+ Long domainId = cmd.getDomainId();
+
+ //Keeping this logic consistent with domain specific zones
+ //if a domainId is provided, we just return the so associated with this domain
+ if(domainId != null){
+ if(account.getType() == Account.ACCOUNT_TYPE_ADMIN){
+ return _offeringsDao.findServiceOfferingByDomainId(domainId);//no perm check
+ }else{
+ //check if the user's domain == so's domain || user's domain is a child of so's domain
+ if(isPermissible(account.getDomainId(), domainId)){
+ //perm check succeeded
+ return _offeringsDao.findServiceOfferingByDomainId(domainId);
+ }else{
+ throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account:"+account.getAccountName()+" does not fall in the same domain hierarchy as the service offering");
+ }
+ }
+ }
+
+ //For non-root users
+ if((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)){
+ return searchOfferingsInternal(account, name, id, vmId, keyword, searchFilter);
+ }
+
+ //for root users, the existing flow
if (keyword != null) {
SearchCriteria ssc = _offeringsDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@ -1610,8 +1663,6 @@ public class ManagementServerImpl implements ManagementServer {
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
} else if (vmId != null) {
- Account account = UserContext.current().getAccount();
-
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
@@ -1642,6 +1693,80 @@ public class ManagementServerImpl implements ManagementServer {
return _offeringsDao.search(sc, searchFilter);
}
+ private List searchOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter){
+
+ //it was decided to return all offerings for the user's domain, and everything above till root (for normal user or domain admin)
+ //list all offerings belonging to this domain, and all of its parents
+ //check the parent, if not null, add offerings for that parent to list
+ List sol = new ArrayList();
+ DomainVO domainRecord = _domainDao.findById(account.getDomainId());
+ boolean includePublicOfferings = true;
+ if(domainRecord != null)
+ {
+ while(true){
+ SearchCriteria sc = _offeringsDao.createSearchCriteria();
+
+ if (keyword != null) {
+ includePublicOfferings = false;
+ SearchCriteria ssc = _offeringsDao.createSearchCriteria();
+ ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ } else if (vmId != null) {
+ includePublicOfferings = false;
+ UserVmVO vmInstance = _userVmDao.findById(vmId);
+ if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
+ throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
+ }
+ if ((account != null) && !isAdmin(account.getType())) {
+ if (account.getId() != vmInstance.getAccountId()) {
+ throw new PermissionDeniedException("unable to find a virtual machine with id " + vmId + " for this account");
+ }
+ }
+
+ ServiceOfferingVO offering = _offeringsDao.findById(vmInstance.getServiceOfferingId());
+ sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId());
+
+ // Only return offerings with the same Guest IP type and storage pool preference
+ sc.addAnd("guestIpType", SearchCriteria.Op.EQ, offering.getGuestIpType());
+ sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage());
+ }
+
+ if (id != null) {
+ includePublicOfferings = false;
+ sc.addAnd("id", SearchCriteria.Op.EQ, id);
+ }
+
+ if (name != null) {
+ includePublicOfferings = false;
+ sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
+ }
+ sc.addAnd("systemUse", SearchCriteria.Op.EQ, false);
+
+ //for this domain
+ sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
+
+ //search and add for this domain
+ sol.addAll(_offeringsDao.search(sc, searchFilter));
+
+ //try and move on to the next domain
+ if(domainRecord.getParent() != null)
+ domainRecord = _domainDao.findById(domainRecord.getParent());
+ else
+ break;//now we got all the offerings for this user/dom adm
+ }
+ }else{
+ s_logger.error("Could not find the domainId for account:"+account.getAccountName());
+ throw new CloudAuthenticationException("Could not find the domainId for account:"+account.getAccountName());
+ }
+
+ //add all the public offerings to the sol list before returning
+ if(includePublicOfferings)
+ sol.addAll(_offeringsDao.findPublicServiceOfferings());
+
+ return sol;
+ }
@Override
public List searchForClusters(ListClustersCmd cmd) {
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
diff --git a/server/src/com/cloud/service/ServiceOfferingVO.java b/server/src/com/cloud/service/ServiceOfferingVO.java
index d4e48cfbe51..9591f6c8b57 100644
--- a/server/src/com/cloud/service/ServiceOfferingVO.java
+++ b/server/src/com/cloud/service/ServiceOfferingVO.java
@@ -72,6 +72,17 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.offerHA = offerHA;
this.guestIpType = guestIpType;
}
+
+ public ServiceOfferingVO(String name, int cpu, int ramSize, int speed, int rateMbps, int multicastRateMbps, boolean offerHA, String displayText, NetworkOffering.GuestIpType guestIpType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, Long domainId) {
+ super(name, displayText, false, tags, recreatable, useLocalStorage, systemUse,false,domainId);
+ this.cpu = cpu;
+ this.ramSize = ramSize;
+ this.speed = speed;
+ this.rateMbps = rateMbps;
+ this.multicastRateMbps = multicastRateMbps;
+ this.offerHA = offerHA;
+ this.guestIpType = guestIpType;
+ }
@Override
public boolean getOfferHA() {
@@ -145,5 +156,6 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Override
public NetworkOffering.GuestIpType getGuestIpType() {
return guestIpType;
- }
+ }
+
}
diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDao.java b/server/src/com/cloud/service/dao/ServiceOfferingDao.java
index 3eee286fadb..9e823c2a01c 100644
--- a/server/src/com/cloud/service/dao/ServiceOfferingDao.java
+++ b/server/src/com/cloud/service/dao/ServiceOfferingDao.java
@@ -18,6 +18,8 @@
package com.cloud.service.dao;
+import java.util.List;
+
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.GenericDao;
@@ -26,5 +28,7 @@ import com.cloud.utils.db.GenericDao;
*/
public interface ServiceOfferingDao extends GenericDao {
ServiceOfferingVO findByName(String name);
- ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
+ ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
+ List findPublicServiceOfferings();
+ List findServiceOfferingByDomainId(Long domainId);
}
diff --git a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
index 7d73f09161c..710c2c18520 100644
--- a/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
+++ b/server/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
@@ -25,6 +25,7 @@ import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger;
+import com.cloud.dc.DataCenterVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@@ -35,7 +36,11 @@ import com.cloud.utils.db.SearchCriteria;
public class ServiceOfferingDaoImpl extends GenericDaoBase implements ServiceOfferingDao {
protected static final Logger s_logger = Logger.getLogger(ServiceOfferingDaoImpl.class);
- protected final SearchBuilder UniqueNameSearch;
+ protected final SearchBuilder UniqueNameSearch;
+ protected final SearchBuilder ServiceOfferingsByDomainIdSearch;
+ protected final SearchBuilder ServiceOfferingsByKeywordSearch;
+ protected final SearchBuilder PublicServiceOfferingSearch;
+
protected ServiceOfferingDaoImpl() {
super();
@@ -43,6 +48,20 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase findServiceOfferingByDomainId(Long domainId){
+ SearchCriteria sc = ServiceOfferingsByDomainIdSearch.create();
+ sc.setParameters("domainId", domainId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List findPublicServiceOfferings(){
+ SearchCriteria sc = PublicServiceOfferingSearch.create();
+ sc.setParameters("system", false);
+ return listBy(sc);
}
}
From 1dfdcf51cb3495e3585081a53f41a4c75af3161c Mon Sep 17 00:00:00 2001
From: abhishek
Date: Tue, 30 Nov 2010 12:59:04 -0800
Subject: [PATCH 02/32] another good point for checkin, added the domain
checker for checks against service offerings, whilst deploying virtual
machines
---
api/src/com/cloud/acl/SecurityChecker.java | 3 ++
server/src/com/cloud/acl/DomainChecker.java | 49 +++++++++++++++++++
.../configuration/ConfigurationManager.java | 5 +-
.../ConfigurationManagerImpl.java | 19 ++++++-
.../cloud/server/ManagementServerImpl.java | 10 ++++
5 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/api/src/com/cloud/acl/SecurityChecker.java b/api/src/com/cloud/acl/SecurityChecker.java
index e835d9d2241..e745607dab4 100644
--- a/api/src/com/cloud/acl/SecurityChecker.java
+++ b/api/src/com/cloud/acl/SecurityChecker.java
@@ -6,6 +6,7 @@ package com.cloud.acl;
import com.cloud.dc.DataCenter;
import com.cloud.domain.Domain;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.component.Adapter;
@@ -57,6 +58,8 @@ public interface SecurityChecker extends Adapter {
boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException;
+ public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
+
// We should be able to use this method to check against commands. For example, we can
// annotate the command with access annotations and this method can use it to extract
// OwnedBy and PartOf interfaces on the object and use it to verify against a user.
diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java
index 95dca17171b..ae434f1509a 100644
--- a/server/src/com/cloud/acl/DomainChecker.java
+++ b/server/src/com/cloud/acl/DomainChecker.java
@@ -25,6 +25,7 @@ import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.ServiceOffering;
import com.cloud.storage.LaunchPermissionVO;
import com.cloud.storage.dao.LaunchPermissionDao;
import com.cloud.template.VirtualMachineTemplate;
@@ -100,6 +101,54 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
return checkAccess(account, entity);
}
+
+ @Override
+ public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException
+ {
+ if(account == null || so.getDomainId() == null)
+ {//public offering
+ return true;
+ }
+ else
+ {
+ //admin has all permissions
+ if(account.getType() == Account.ACCOUNT_TYPE_ADMIN)
+ {
+ return true;
+ }
+ //if account is normal user
+ //check if account's domain is a child of zone's domain
+ else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
+ {
+ if(account.getDomainId() == so.getDomainId())
+ {
+ return true; //service offering and account at exact node
+ }
+ else
+ {
+ DomainVO domainRecord = _domainDao.findById(account.getDomainId());
+ if(domainRecord != null)
+ {
+ while(true)
+ {
+ if(domainRecord.getId() == so.getDomainId())
+ {
+ //found as a child
+ return true;
+ }
+ if(domainRecord.getParent() != null)
+ domainRecord = _domainDao.findById(domainRecord.getParent());
+ else
+ break;
+ }
+ }
+ }
+ }
+ }
+ //not found
+ return false;
+ }
+
@Override
public boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException {
if(account == null || zone.getDomainId() == null){//public zone
diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java
index 75df0ec0b95..a1cee1a56b8 100644
--- a/server/src/com/cloud/configuration/ConfigurationManager.java
+++ b/server/src/com/cloud/configuration/ConfigurationManager.java
@@ -26,6 +26,7 @@ import com.cloud.dc.HostPodVO;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.user.Account;
@@ -153,5 +154,7 @@ public interface ConfigurationManager extends Manager {
void checkAccess(Account caller, DataCenter zone)
throws PermissionDeniedException;
-
+
+ void checkAccess(Account caller, ServiceOffering so)
+ throws PermissionDeniedException;
}
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 4fefb4683ba..98feff6fa85 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2311,7 +2311,24 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return deleteVlanAndPublicIpRange(userId, vlanDbId);
}
-
+
+ @Override
+ public void checkAccess(Account caller, ServiceOffering so) throws PermissionDeniedException {
+ for (SecurityChecker checker : _secChecker) {
+ if (checker.checkAccess(caller, so)) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Access granted to " + caller + " to service offering:" + so.getId() + " by " + checker.getName());
+ }
+ return;
+ }else{
+ throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName());
+ }
+ }
+
+ assert false : "How can all of the security checkers pass on checking this caller?";
+ throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to service offering:" + so.getId());
+ }
+
@Override
public void checkAccess(Account caller, DataCenter zone) throws PermissionDeniedException {
for (SecurityChecker checker : _secChecker) {
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 5167de6d50a..69e6702909b 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -1196,6 +1196,16 @@ public class ManagementServerImpl implements ManagementServer {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
+ if(offering.getDomainId() == null){
+ //do nothing as offering is public
+ }else{
+ if(userAccount != null){
+ _configMgr.checkAccess(userAccount, offering);//user deploying his own vm
+ }else{
+ _configMgr.checkAccess(ctxAccount, offering);
+ }
+ }
+
VMTemplateVO template = _templateDao.findById(templateId);
// Make sure a valid template ID was specified
if (template == null) {
From 402baae9fabb73ca0a1774f0831ffc4222d5a348 Mon Sep 17 00:00:00 2001
From: abhishek
Date: Tue, 30 Nov 2010 14:09:07 -0800
Subject: [PATCH 03/32] adding comments for the domain checker, so that the
design decision is better understood down the road
---
server/src/com/cloud/acl/DomainChecker.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java
index ae434f1509a..a9aacddc5bb 100644
--- a/server/src/com/cloud/acl/DomainChecker.java
+++ b/server/src/com/cloud/acl/DomainChecker.java
@@ -116,8 +116,8 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
{
return true;
}
- //if account is normal user
- //check if account's domain is a child of zone's domain
+ //if account is normal user or domain admin
+ //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for service offering)
else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
{
if(account.getDomainId() == so.getDomainId())
From 4387e2ca0abde794714149a65f66dbdffd8aa6a2 Mon Sep 17 00:00:00 2001
From: abhishek
Date: Tue, 30 Nov 2010 16:16:45 -0800
Subject: [PATCH 04/32] another good point to commit; the basic domain specific
disk offering functionality is now in place
---
.../api/commands/ListDiskOfferingsCmd.java | 2 +-
.../commands/UpdateServiceOfferingCmd.java | 2 +
.../ConfigurationManagerImpl.java | 7 ++
.../cloud/server/ManagementServerImpl.java | 103 +++++++++++++++++-
.../cloud/storage/dao/DiskOfferingDao.java | 1 +
.../storage/dao/DiskOfferingDaoImpl.java | 14 +++
6 files changed, 122 insertions(+), 7 deletions(-)
diff --git a/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java b/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java
index 61645d06597..46cc202d0ee 100644
--- a/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java
+++ b/api/src/com/cloud/api/commands/ListDiskOfferingsCmd.java
@@ -40,7 +40,7 @@ public class ListDiskOfferingsCmd extends BaseListCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain of the disk offering. This information is not currently applicable, and should not be used as a parameter.")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain of the disk offering.")
private Long domainId;
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="ID of the disk offering")
diff --git a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
index cd765e6276f..0175f2bd9ed 100644
--- a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
+++ b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
@@ -93,6 +93,8 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
@Override
public void execute(){
+ //Note
+ //Once an offering is created, we cannot update the domainId field (keeping consistent with zones logic)
ServiceOffering result = _configService.updateServiceOffering(this);
if (result != null){
ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result);
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 98feff6fa85..170ae7f55ca 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1115,6 +1115,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to create service offering " + name + ": specify the memory value between 1 and 2147483647");
}
+ //check if valid domain
+ if(cmd.getDomainId() != null){
+ DomainVO domain = _domainDao.findById(cmd.getDomainId());
+ if(domain == null)
+ throw new InvalidParameterValueException("Please specify a valid domain id");
+ }
+
boolean localStorageRequired = false;
String storageType = cmd.getStorageType();
if (storageType == null) {
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 69e6702909b..a9dedba7524 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -1603,16 +1603,17 @@ public class ManagementServerImpl implements ManagementServer {
return _userAccountDao.search(sc, searchFilter);
}
- private boolean isPermissible(Long accountDomainId, Long serviceOfferingDomainId){
+ //This method is used for permissions check for both disk and service offerings
+ private boolean isPermissible(Long accountDomainId, Long offeringDomainId){
- if(accountDomainId == serviceOfferingDomainId)
+ if(accountDomainId == offeringDomainId)
return true; // account and service offering in same domain
DomainVO domainRecord = _domainDao.findById(accountDomainId);
if(domainRecord != null){
while(true){
- if(domainRecord.getId() == serviceOfferingDomainId)
+ if(domainRecord.getId() == offeringDomainId)
return true;
//try and move on to the next domain
@@ -1662,7 +1663,7 @@ public class ManagementServerImpl implements ManagementServer {
//For non-root users
if((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)){
- return searchOfferingsInternal(account, name, id, vmId, keyword, searchFilter);
+ return searchServiceOfferingsInternal(account, name, id, vmId, keyword, searchFilter);
}
//for root users, the existing flow
@@ -1703,7 +1704,7 @@ public class ManagementServerImpl implements ManagementServer {
return _offeringsDao.search(sc, searchFilter);
}
- private List searchOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter){
+ private List searchServiceOfferingsInternal(Account account, Object name, Object id, Long vmId, Object keyword, Filter searchFilter){
//it was decided to return all offerings for the user's domain, and everything above till root (for normal user or domain admin)
//list all offerings belonging to this domain, and all of its parents
@@ -4337,17 +4338,107 @@ public class ManagementServerImpl implements ManagementServer {
return accountNames;
}
+ private List searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter){
+ //it was decided to return all offerings for the user's domain, and everything above till root (for normal user or domain admin)
+ //list all offerings belonging to this domain, and all of its parents
+ //check the parent, if not null, add offerings for that parent to list
+ List dol = new ArrayList();
+ DomainVO domainRecord = _domainDao.findById(account.getDomainId());
+ boolean includePublicOfferings = true;
+ if(domainRecord != null)
+ {
+ while(true){
+ SearchBuilder sb = _diskOfferingDao.createSearchBuilder();
+
+ sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
+ sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+
+ SearchCriteria sc = sb.create();
+ if (keyword != null) {
+ includePublicOfferings = false;
+ SearchCriteria ssc = _diskOfferingDao.createSearchCriteria();
+ ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ }
+
+ if (name != null) {
+ includePublicOfferings = false;
+ sc.setParameters("name", "%" + name + "%");
+ }
+
+ if (id != null) {
+ includePublicOfferings = false;
+ sc.setParameters("id", id);
+ }
+
+ //for this domain
+ sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
+
+ //search and add for this domain
+ dol.addAll(_diskOfferingDao.search(sc, searchFilter));
+
+ //try and move on to the next domain
+ if(domainRecord.getParent() != null)
+ domainRecord = _domainDao.findById(domainRecord.getParent());
+ else
+ break;//now we got all the offerings for this user/dom adm
+ }
+ }else{
+ s_logger.error("Could not find the domainId for account:"+account.getAccountName());
+ throw new CloudAuthenticationException("Could not find the domainId for account:"+account.getAccountName());
+ }
+
+ //add all the public offerings to the sol list before returning
+ if(includePublicOfferings)
+ dol.addAll(_diskOfferingDao.findPublicDiskOfferings());
+
+ return dol;
+
+ }
+
@Override
public List searchForDiskOfferings(ListDiskOfferingsCmd cmd) {
+ //Note
+ //The list method for offerings is being modified in accordance with discussion with Will/Kevin
+ //For now, we will be listing the following based on the usertype
+ //1. For root, we will list all offerings
+ //2. For domainAdmin and regular users, we will list everything in their domains+parent domains ... all the way till root
+
Filter searchFilter = new Filter(DiskOfferingVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder sb = _diskOfferingDao.createSearchBuilder();
// SearchBuilder and SearchCriteria are now flexible so that the search builder can be built with all possible
// search terms and only those with criteria can be set. The proper SQL should be generated as a result.
+ Account account = UserContext.current().getAccount();
Object name = cmd.getDiskOfferingName();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
-
+ Long domainId = cmd.getDomainId();
+
+ //Keeping this logic consistent with domain specific zones
+ //if a domainId is provided, we just return the disk offering associated with this domain
+ if(domainId != null){
+ if(account.getType() == Account.ACCOUNT_TYPE_ADMIN){
+ return _diskOfferingDao.listByDomainId(domainId);//no perm check
+ }else{
+ //check if the user's domain == do's domain || user's domain is a child of so's domain
+ if(isPermissible(account.getDomainId(), domainId)){
+ //perm check succeeded
+ return _diskOfferingDao.listByDomainId(domainId);
+ }else{
+ throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account:"+account.getAccountName()+" does not fall in the same domain hierarchy as the disk offering");
+ }
+ }
+ }
+
+ //For non-root users
+ if((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)){
+ return searchDiskOfferingsInternal(account, name, id, keyword, searchFilter);
+ }
+
+ //For root users, preserving existing flow
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
diff --git a/server/src/com/cloud/storage/dao/DiskOfferingDao.java b/server/src/com/cloud/storage/dao/DiskOfferingDao.java
index 0cfe20e3aea..70646ec7337 100644
--- a/server/src/com/cloud/storage/dao/DiskOfferingDao.java
+++ b/server/src/com/cloud/storage/dao/DiskOfferingDao.java
@@ -26,5 +26,6 @@ import com.cloud.utils.db.GenericDao;
public interface DiskOfferingDao extends GenericDao {
List listByDomainId(long domainId);
List findPrivateDiskOffering();
+ List findPublicDiskOfferings();
}
diff --git a/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
index ae6f587d5fa..2e9c4591413 100644
--- a/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
@@ -24,6 +24,7 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
+import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.DiskOfferingVO.Type;
import com.cloud.utils.db.Attribute;
@@ -39,6 +40,7 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im
private final SearchBuilder DomainIdSearch;
private final SearchBuilder PrivateDiskOfferingSearch;
+ private final SearchBuilder PublicDiskOfferingSearch;
private final Attribute _typeAttr;
protected DiskOfferingDaoImpl() {
@@ -50,6 +52,11 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im
PrivateDiskOfferingSearch.and("diskSize", PrivateDiskOfferingSearch.entity().getDiskSize(), SearchCriteria.Op.EQ);
PrivateDiskOfferingSearch.done();
+ PublicDiskOfferingSearch = createSearchBuilder();
+ PublicDiskOfferingSearch.and("domainId", PublicDiskOfferingSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
+ PublicDiskOfferingSearch.and("system", PublicDiskOfferingSearch.entity().isSystemUse(), SearchCriteria.Op.EQ);
+ PublicDiskOfferingSearch.done();
+
_typeAttr = _allAttributes.get("type");
}
@@ -91,5 +98,12 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im
}
return super.executeList(sql, Type.Disk, params);
+ }
+
+ @Override
+ public List findPublicDiskOfferings(){
+ SearchCriteria sc = PublicDiskOfferingSearch.create();
+ sc.setParameters("system", false);
+ return listBy(sc);
}
}
From b51a7fec505f817d45bb681310d712e7add620cb Mon Sep 17 00:00:00 2001
From: abhishek
Date: Tue, 30 Nov 2010 17:46:31 -0800
Subject: [PATCH 05/32] adding a security checker whilst creating a volume from
a disk offering
---
api/src/com/cloud/acl/SecurityChecker.java | 3 ++
server/src/com/cloud/acl/DomainChecker.java | 47 +++++++++++++++++++
.../configuration/ConfigurationManager.java | 6 ++-
.../ConfigurationManagerImpl.java | 19 +++++++-
.../cloud/server/ManagementServerImpl.java | 17 +++++--
.../com/cloud/storage/StorageManagerImpl.java | 6 +++
6 files changed, 93 insertions(+), 5 deletions(-)
diff --git a/api/src/com/cloud/acl/SecurityChecker.java b/api/src/com/cloud/acl/SecurityChecker.java
index e745607dab4..53b8438b8f0 100644
--- a/api/src/com/cloud/acl/SecurityChecker.java
+++ b/api/src/com/cloud/acl/SecurityChecker.java
@@ -6,6 +6,7 @@ package com.cloud.acl;
import com.cloud.dc.DataCenter;
import com.cloud.domain.Domain;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
import com.cloud.user.User;
@@ -59,6 +60,8 @@ public interface SecurityChecker extends Adapter {
boolean checkAccess(Account account, DataCenter zone) throws PermissionDeniedException;
public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException;
+
+ boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException;
// We should be able to use this method to check against commands. For example, we can
// annotate the command with access annotations and this method can use it to extract
diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java
index a9aacddc5bb..7af3f8b42d8 100644
--- a/server/src/com/cloud/acl/DomainChecker.java
+++ b/server/src/com/cloud/acl/DomainChecker.java
@@ -25,6 +25,7 @@ import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.LaunchPermissionVO;
import com.cloud.storage.dao.LaunchPermissionDao;
@@ -101,6 +102,52 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
return checkAccess(account, entity);
}
+ @Override
+ public boolean checkAccess(Account account, DiskOffering dof) throws PermissionDeniedException
+ {
+ if(account == null || dof.getDomainId() == null)
+ {//public offering
+ return true;
+ }
+ else
+ {
+ //admin has all permissions
+ if(account.getType() == Account.ACCOUNT_TYPE_ADMIN)
+ {
+ return true;
+ }
+ //if account is normal user or domain admin
+ //check if account's domain is a child of zone's domain (Note: This is made consistent with the list command for disk offering)
+ else if(account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)
+ {
+ if(account.getDomainId() == dof.getDomainId())
+ {
+ return true; //disk offering and account at exact node
+ }
+ else
+ {
+ DomainVO domainRecord = _domainDao.findById(account.getDomainId());
+ if(domainRecord != null)
+ {
+ while(true)
+ {
+ if(domainRecord.getId() == dof.getDomainId())
+ {
+ //found as a child
+ return true;
+ }
+ if(domainRecord.getParent() != null)
+ domainRecord = _domainDao.findById(domainRecord.getParent());
+ else
+ break;
+ }
+ }
+ }
+ }
+ }
+ //not found
+ return false;
+ }
@Override
public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException
diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java
index a1cee1a56b8..f05e478226a 100644
--- a/server/src/com/cloud/configuration/ConfigurationManager.java
+++ b/server/src/com/cloud/configuration/ConfigurationManager.java
@@ -26,6 +26,7 @@ import com.cloud.dc.HostPodVO;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.PermissionDeniedException;
+import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
@@ -155,6 +156,9 @@ public interface ConfigurationManager extends Manager {
void checkAccess(Account caller, DataCenter zone)
throws PermissionDeniedException;
- void checkAccess(Account caller, ServiceOffering so)
+ void checkServiceOfferingAccess(Account caller, ServiceOffering so)
throws PermissionDeniedException;
+
+ void checkDiskOfferingAccess(Account caller, DiskOffering dof)
+ throws PermissionDeniedException;
}
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 170ae7f55ca..9f3e82439bd 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2320,7 +2320,24 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
@Override
- public void checkAccess(Account caller, ServiceOffering so) throws PermissionDeniedException {
+ public void checkDiskOfferingAccess(Account caller, DiskOffering dof) throws PermissionDeniedException {
+ for (SecurityChecker checker : _secChecker) {
+ if (checker.checkAccess(caller, dof)) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Access granted to " + caller + " to disk offering:" + dof.getId() + " by " + checker.getName());
+ }
+ return;
+ }else{
+ throw new PermissionDeniedException("Access denied to "+caller+" by "+checker.getName());
+ }
+ }
+
+ assert false : "How can all of the security checkers pass on checking this caller?";
+ throw new PermissionDeniedException("There's no way to confirm " + caller + " has access to disk offering:" + dof.getId());
+ }
+
+ @Override
+ public void checkServiceOfferingAccess(Account caller, ServiceOffering so) throws PermissionDeniedException {
for (SecurityChecker checker : _secChecker) {
if (checker.checkAccess(caller, so)) {
if (s_logger.isDebugEnabled()) {
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index a9dedba7524..d9a4b9c5b86 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -1200,9 +1200,9 @@ public class ManagementServerImpl implements ManagementServer {
//do nothing as offering is public
}else{
if(userAccount != null){
- _configMgr.checkAccess(userAccount, offering);//user deploying his own vm
+ _configMgr.checkServiceOfferingAccess(userAccount, offering);//user deploying his own vm
}else{
- _configMgr.checkAccess(ctxAccount, offering);
+ _configMgr.checkServiceOfferingAccess(ctxAccount, offering);
}
}
@@ -1230,6 +1230,18 @@ public class ManagementServerImpl implements ManagementServer {
throw new InvalidParameterValueException("Please specify a valid disk offering ID.");
}
+ if(diskOffering != null){
+ if(diskOffering.getDomainId() == null){
+ //do nothing as offering is public
+ }else{
+ if(userAccount != null){
+ _configMgr.checkDiskOfferingAccess(userAccount, diskOffering);//user deploying his own vm
+ }else{
+ _configMgr.checkDiskOfferingAccess(ctxAccount, diskOffering);
+ }
+ }
+ }
+
if (isIso) {
/*iso template doesn;t have hypervisor type, temporarily set it's type as user specified, pass it to storage allocator */
template.setHypervisorType(HypervisorType.getType(cmd.getHypervisor()));
@@ -4416,7 +4428,6 @@ public class ManagementServerImpl implements ManagementServer {
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long domainId = cmd.getDomainId();
-
//Keeping this logic consistent with domain specific zones
//if a domainId is provided, we just return the disk offering associated with this domain
if(domainId != null){
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 767327d85c6..5a840d2b551 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1742,6 +1742,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
throw new InvalidParameterValueException("Please specify a valid disk offering.");
}
+ if(diskOffering.getDomainId() == null){
+ //do nothing as offering is public
+ }else{
+ _configMgr.checkDiskOfferingAccess(account, diskOffering);
+ }
+
if(!validateVolumeSizeRange(diskOffering.getDiskSize()/1024)){//convert size from mb to gb for validation
throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size+" ,max volume size is:"+_maxVolumeSizeInGb);
}
From a477d6c33c9e3689a5c8e488af9a974750a9a309 Mon Sep 17 00:00:00 2001
From: abhishek
Date: Wed, 1 Dec 2010 10:40:08 -0800
Subject: [PATCH 06/32] adding support for updating service and disk offerings,
also adding domain and domainid back in the responses to the CRUD methods for
both service and disk offerings
---
.../api/commands/UpdateDiskOfferingCmd.java | 8 +++++++
.../commands/UpdateServiceOfferingCmd.java | 14 +++++++++++--
.../api/response/ServiceOfferingResponse.java | 14 +++++++++++++
.../src/com/cloud/api/ApiResponseHelper.java | 5 ++++-
.../ConfigurationManagerImpl.java | 21 +++++++++++++------
5 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java
index 211b6082e7f..41a3c67d481 100644
--- a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java
+++ b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.DiskOfferingResponse;
import com.cloud.offering.DiskOffering;
@@ -48,6 +49,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
// @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="update tags of the disk offering with this value")
// private String tags;
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
+ private Long domainId;
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -67,6 +71,10 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
// public String getTags() {
// return tags;
// }
+
+ public Long getDomainId() {
+ return domainId;
+ }
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
diff --git a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
index 0175f2bd9ed..96db774da5e 100644
--- a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
+++ b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ServiceOfferingResponse;
import com.cloud.offering.ServiceOffering;
@@ -53,6 +54,9 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.USE_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="if true, the VM created from the offering will use default virtual networking. If false, the VM created will use a direct attached networking model. The default value is true.")
private Boolean useVirtualNetwork;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
+ private Long domainId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@@ -82,11 +86,17 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
return useVirtualNetwork;
}
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
-
- @Override
+
+
+ @Override
public String getName() {
return s_name;
}
diff --git a/api/src/com/cloud/api/response/ServiceOfferingResponse.java b/api/src/com/cloud/api/response/ServiceOfferingResponse.java
index 3b4e45c66e9..5eb505f6708 100644
--- a/api/src/com/cloud/api/response/ServiceOfferingResponse.java
+++ b/api/src/com/cloud/api/response/ServiceOfferingResponse.java
@@ -19,6 +19,7 @@ package com.cloud.api.response;
import java.util.Date;
+import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@@ -58,6 +59,9 @@ public class ServiceOfferingResponse extends BaseResponse {
@SerializedName("domainId") @Param(description="the domain id of the service offering")
private Long domainId;
+
+ @SerializedName(ApiConstants.DOMAIN) @Param(description="Domain name for the offering")
+ private String domain;
public Long getId() {
return id;
@@ -155,4 +159,14 @@ public class ServiceOfferingResponse extends BaseResponse {
this.domainId = domainId;
}
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+
+
}
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 32e49738370..a7ed96541c6 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -345,7 +345,10 @@ public class ApiResponseHelper implements ResponseGenerator {
offeringResponse.setOfferHa(offering.getOfferHA());
offeringResponse.setUseVirtualNetwork(offering.getGuestIpType().equals(GuestIpType.Virtualized));
offeringResponse.setTags(offering.getTags());
- offeringResponse.setDomainId(offering.getDomainId());
+ if(offering.getDomainId() != null){
+ offeringResponse.setDomain(ApiDBUtils.findDomainById(offering.getDomainId()).getName());
+ offeringResponse.setDomainId(offering.getDomainId());
+ }
offeringResponse.setObjectName("serviceoffering");
return offeringResponse;
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 9f3e82439bd..20f418602df 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1166,7 +1166,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return null;
}
}
-
+
@Override
public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) {
String displayText = cmd.getDisplayText();
@@ -1176,7 +1176,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
// String tags = cmd.getTags();
Boolean useVirtualNetwork = cmd.getUseVirtualNetwork();
Long userId = UserContext.current().getUserId();
-
+ Long domainId = cmd.getDomainId();
+
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
}
@@ -1186,8 +1187,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (offeringHandle == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + id);
}
-
- boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null);
+
+ boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null || domainId != null);
if (!updateNeeded) {
return _serviceOfferingDao.findById(id);
}
@@ -1211,6 +1212,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
offering.setGuestIpType(guestIpType);
}
+ if (domainId != null){
+ offering.setDomainId(domainId);
+ }
// if (tags != null)
// {
// if (tags.trim().isEmpty() && offeringHandle.getTags() == null)
@@ -1236,7 +1240,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (_serviceOfferingDao.update(id, offering)) {
offering = _serviceOfferingDao.findById(id);
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(),
- "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags());
+ "displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags(), "domainId=" + offering.getDomainId());
return offering;
} else {
return null;
@@ -1287,6 +1291,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String name = cmd.getDiskOfferingName();
String displayText = cmd.getDisplayText();
// String tags = cmd.getTags();
+ Long domainId = cmd.getDomainId();
//Check if diskOffering exists
DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId);
@@ -1310,6 +1315,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
diskOffering.setDisplayText(displayText);
}
+ if (domainId != null){
+ diskOffering.setDomainId(domainId);
+ }
+
// if (tags != null)
// {
// if (tags.trim().isEmpty() && diskOfferingHandle.getTags() == null)
@@ -1334,7 +1343,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (_diskOfferingDao.update(diskOfferingId, diskOffering)) {
saveConfigurationEvent(UserContext.current().getUserId(), null, EventTypes.EVENT_DISK_OFFERING_EDIT, "Successfully updated disk offering with name: " + diskOffering.getName() + ".", "doId=" + diskOffering.getId(), "name=" + diskOffering.getName(),
- "displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags());
+ "displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags(),"domainId="+cmd.getDomainId());
return _diskOfferingDao.findById(diskOfferingId);
} else {
return null;
From cad49264e0dcab5765c43f25e3d64dab946eac76 Mon Sep 17 00:00:00 2001
From: Jessica Wang
Date: Wed, 1 Dec 2010 10:50:29 -0800
Subject: [PATCH 07/32] replace encodeURIComponent() with todb().
---
ui/scripts/cloud.core.diskoffering.js | 4 +-
ui/scripts/cloud.core.iso.js | 2 +-
ui/scripts/cloud.core.pod.js | 28 +++++++-------
ui/scripts/cloud.core.primarystorage.js | 2 +-
ui/scripts/cloud.core.resource.js | 48 ++++++++++++------------
ui/scripts/cloud.core.serviceoffering.js | 4 +-
ui/scripts/cloud.core.template.js | 2 +-
ui/scripts/cloud.core.volume.js | 2 +-
ui/scripts/cloud.core.zone.js | 32 ++++++++--------
9 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/ui/scripts/cloud.core.diskoffering.js b/ui/scripts/cloud.core.diskoffering.js
index 588336c7adb..10294b3e107 100644
--- a/ui/scripts/cloud.core.diskoffering.js
+++ b/ui/scripts/cloud.core.diskoffering.js
@@ -84,7 +84,7 @@ function initAddDiskOfferingButton($midmenuAddLink1) {
var tags = trim(thisDialog.find("#add_disk_tags").val());
if(tags != null && tags.length > 0)
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
$.ajax({
data: createURL("command=createDiskOffering&isMirrored=false" + array1.join("")),
@@ -149,7 +149,7 @@ function doEditDiskOffering2($actionLink, $detailsTab, $midmenuItem1, $readonlyF
array1.push("&displayText="+todb(displaytext));
var tags = $detailsTab.find("#tags_edit").val();
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
$.ajax({
data: createURL("command=updateDiskOffering&id="+id+array1.join("")),
diff --git a/ui/scripts/cloud.core.iso.js b/ui/scripts/cloud.core.iso.js
index 37c9cb5e5ca..67d21892c8d 100644
--- a/ui/scripts/cloud.core.iso.js
+++ b/ui/scripts/cloud.core.iso.js
@@ -52,7 +52,7 @@ function afterLoadIsoJSP() {
array1.push("&displayText="+todb(desc));
var url = trim(thisDialog.find("#add_iso_url").val());
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
var zoneId = thisDialog.find("#add_iso_zone").val();
array1.push("&zoneId="+zoneId);
diff --git a/ui/scripts/cloud.core.pod.js b/ui/scripts/cloud.core.pod.js
index 02b08e41960..b10efe9d564 100644
--- a/ui/scripts/cloud.core.pod.js
+++ b/ui/scripts/cloud.core.pod.js
@@ -328,10 +328,10 @@ function initAddHostButton($button, currentPageInRightPanel, $leftmenuItem1) {
array1.push("&podId="+podId);
var username = trim($thisDialog.find("#host_username").val());
- array1.push("&username="+encodeURIComponent(username));
+ array1.push("&username="+todb(username));
var password = trim($thisDialog.find("#host_password").val());
- array1.push("&password="+encodeURIComponent(password));
+ array1.push("&password="+todb(password));
var newClusterName, existingClusterId;
if(clusterRadio == "new_cluster_radio") {
@@ -352,7 +352,7 @@ function initAddHostButton($button, currentPageInRightPanel, $leftmenuItem1) {
url = "http://" + todb(hostname);
else
url = hostname;
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
//var $midmenuItem1 = beforeAddingMidMenuItem() ;
@@ -521,11 +521,11 @@ function initAddPrimaryStorageButton($button, currentPageInRightPanel, $leftmenu
var lun = trim($thisDialog.find("#add_pool_lun").val());
url = iscsiURL(server, iqn, lun);
}
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
var tags = trim($thisDialog.find("#add_pool_tags").val());
if(tags != null && tags.length > 0)
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
$.ajax({
data: createURL("command=createStoragePool" + array1.join("")),
@@ -615,11 +615,11 @@ function initAddPodVLANButton($button, $leftmenuItem1) {
array1.push("&zoneid=" + zoneId);
array1.push("&podId=" + podId);
array1.push("&forVirtualNetwork=false"); //direct VLAN
- array1.push("&gateway="+encodeURIComponent(guestgateway));
- array1.push("&netmask="+encodeURIComponent(netmask));
- array1.push("&startip="+encodeURIComponent(startip));
+ array1.push("&gateway="+todb(guestgateway));
+ array1.push("&netmask="+todb(netmask));
+ array1.push("&startip="+todb(startip));
if(endip != null && endip.length > 0)
- array1.push("&endip="+encodeURIComponent(endip));
+ array1.push("&endip="+todb(endip));
$.ajax({
data: createURL("command=createVlanIpRange" + array1.join("")),
@@ -751,17 +751,17 @@ function doEditPod2($actionLink, $detailsTab, $midmenuItem1, $readonlyFields, $e
if(newName != oldName)
array1.push("&name="+todb(newName));
if(newCidr != oldCidr)
- array1.push("&cidr="+encodeURIComponent(newCidr));
+ array1.push("&cidr="+todb(newCidr));
if(newStartip != oldStartip)
- array1.push("&startIp="+encodeURIComponent(newStartip));
+ array1.push("&startIp="+todb(newStartip));
if(newEndip != oldEndip && newEndip != null && newEndip.length > 0) {
if(newStartip == oldStartip) {
- array1.push("&startIp="+encodeURIComponent(newStartip)); //startIp needs to be passed to updatePod API when endIp is passed to updatePod API.
+ array1.push("&startIp="+todb(newStartip)); //startIp needs to be passed to updatePod API when endIp is passed to updatePod API.
}
- array1.push("&endIp="+encodeURIComponent(newEndip));
+ array1.push("&endIp="+todb(newEndip));
}
if(newGateway != oldGateway && newGateway != null && newGateway.length > 0)
- array1.push("&gateway="+encodeURIComponent(newGateway));
+ array1.push("&gateway="+todb(newGateway));
if(array1.length > 0) {
$.ajax({
diff --git a/ui/scripts/cloud.core.primarystorage.js b/ui/scripts/cloud.core.primarystorage.js
index 2a2001e9056..e4cf04dd2f2 100644
--- a/ui/scripts/cloud.core.primarystorage.js
+++ b/ui/scripts/cloud.core.primarystorage.js
@@ -240,7 +240,7 @@ function doEditPrimaryStorage2($actionLink, $detailsTab, $midmenuItem1, $readonl
var array1 = [];
var tags = $detailsTab.find("#tags_edit").val();
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
if(array1.length == 0)
return;
diff --git a/ui/scripts/cloud.core.resource.js b/ui/scripts/cloud.core.resource.js
index 7430f799eb3..367a332ee29 100644
--- a/ui/scripts/cloud.core.resource.js
+++ b/ui/scripts/cloud.core.resource.js
@@ -320,11 +320,11 @@ function initAddPodShortcut() {
var array1 = [];
array1.push("&zoneId="+zoneId);
array1.push("&name="+todb(name));
- array1.push("&cidr="+encodeURIComponent(cidr));
- array1.push("&startIp="+encodeURIComponent(startip));
+ array1.push("&cidr="+todb(cidr));
+ array1.push("&startIp="+todb(startip));
if (endip != null && endip.length > 0)
- array1.push("&endIp="+encodeURIComponent(endip));
- array1.push("&gateway="+encodeURIComponent(gateway));
+ array1.push("&endIp="+todb(endip));
+ array1.push("&gateway="+todb(gateway));
$.ajax({
data: createURL("command=createPod"+array1.join("")),
@@ -458,10 +458,10 @@ function initAddHostShortcut() {
array1.push("&podid="+podId);
var username = trim($thisDialog.find("#host_username").val());
- array1.push("&username="+encodeURIComponent(username));
+ array1.push("&username="+todb(username));
var password = trim($thisDialog.find("#host_password").val());
- array1.push("&password="+encodeURIComponent(password));
+ array1.push("&password="+todb(password));
var newClusterName, existingClusterId;
if(clusterRadio == "new_cluster_radio") {
@@ -482,7 +482,7 @@ function initAddHostShortcut() {
url = "http://" + todb(hostname);
else
url = hostname;
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
//var $midmenuItem1 = beforeAddingMidMenuItem() ;
@@ -751,32 +751,32 @@ function addZoneWizardSubmit($thisWizard) {
moreCriteria.push("&name="+todb(name));
var dns1 = trim($thisWizard.find("#add_zone_dns1").val());
- moreCriteria.push("&dns1="+encodeURIComponent(dns1));
+ moreCriteria.push("&dns1="+todb(dns1));
var dns2 = trim($thisWizard.find("#add_zone_dns2").val());
if (dns2 != null && dns2.length > 0)
- moreCriteria.push("&dns2="+encodeURIComponent(dns2));
+ moreCriteria.push("&dns2="+todb(dns2));
var internaldns1 = trim($thisWizard.find("#add_zone_internaldns1").val());
- moreCriteria.push("&internaldns1="+encodeURIComponent(internaldns1));
+ moreCriteria.push("&internaldns1="+todb(internaldns1));
var internaldns2 = trim($thisWizard.find("#add_zone_internaldns2").val());
if (internaldns2 != null && internaldns2.length > 0)
- moreCriteria.push("&internaldns2="+encodeURIComponent(internaldns2));
+ moreCriteria.push("&internaldns2="+todb(internaldns2));
if($thisWizard.find("#step2").find("#add_zone_vlan_container").css("display") != "none") {
var vlanStart = $thisWizard.find("#add_zone_startvlan").val();
if(vlanStart != null && vlanStart.length > 0) {
var vlanEnd = $thisWizard.find("#add_zone_endvlan").val();
if (vlanEnd != null && vlanEnd.length > 0)
- moreCriteria.push("&vlan=" + encodeURIComponent(vlanStart + "-" + vlanEnd));
+ moreCriteria.push("&vlan=" + todb(vlanStart + "-" + vlanEnd));
else
- moreCriteria.push("&vlan=" + encodeURIComponent(vlanStart));
+ moreCriteria.push("&vlan=" + todb(vlanStart));
}
}
var guestcidraddress = trim($thisWizard.find("#add_zone_guestcidraddress").val());
- moreCriteria.push("&guestcidraddress="+encodeURIComponent(guestcidraddress));
+ moreCriteria.push("&guestcidraddress="+todb(guestcidraddress));
if($thisWizard.find("#domain_dropdown_container").css("display") != "none") {
var domainId = trim($thisWizard.find("#domain_dropdown").val());
@@ -825,11 +825,11 @@ function addZoneWizardSubmit($thisWizard) {
var array1 = [];
array1.push("&zoneId="+zoneId);
array1.push("&name="+todb(name));
- array1.push("&cidr="+encodeURIComponent(cidr));
- array1.push("&startIp="+encodeURIComponent(startip));
+ array1.push("&cidr="+todb(cidr));
+ array1.push("&startIp="+todb(startip));
if (endip != null && endip.length > 0)
- array1.push("&endIp="+encodeURIComponent(endip));
- array1.push("&gateway="+encodeURIComponent(gateway));
+ array1.push("&endIp="+todb(endip));
+ array1.push("&gateway="+todb(gateway));
$.ajax({
data: createURL("command=createPod"+array1.join("")),
@@ -885,11 +885,11 @@ function addZoneWizardSubmit($thisWizard) {
array1.push("&zoneid=" + zoneId);
array1.push("&podId=" + podId);
array1.push("&forVirtualNetwork=false"); //direct VLAN
- array1.push("&gateway="+encodeURIComponent(guestgateway));
- array1.push("&netmask="+encodeURIComponent(netmask));
- array1.push("&startip="+encodeURIComponent(startip));
+ array1.push("&gateway="+todb(guestgateway));
+ array1.push("&netmask="+todb(netmask));
+ array1.push("&startip="+todb(startip));
if(endip != null && endip.length > 0)
- array1.push("&endip="+encodeURIComponent(endip));
+ array1.push("&endip="+todb(endip));
$.ajax({
data: createURL("command=createVlanIpRange" + array1.join("")),
@@ -936,7 +936,7 @@ function initUpdateConsoleCertButton($midMenuAddLink2) {
var cert = trim($thisDialog.find("#update_cert").val());
$.ajax({
- data: createURL("command=uploadCustomCertificate&certificate="+encodeURIComponent(cert)),
+ data: createURL("command=uploadCustomCertificate&certificate="+todb(cert)),
dataType: "json",
success: function(json) {
var jobId = json.uploadcustomcertificateresponse.jobid;
@@ -1123,7 +1123,7 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel
var lun = trim($thisDialog.find("#add_pool_lun").val());
url = iscsiURL(server, iqn, lun);
}
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
var tags = trim($thisDialog.find("#add_pool_tags").val());
if(tags != null && tags.length > 0)
diff --git a/ui/scripts/cloud.core.serviceoffering.js b/ui/scripts/cloud.core.serviceoffering.js
index a7a8f72bd5e..fff2181ba9f 100644
--- a/ui/scripts/cloud.core.serviceoffering.js
+++ b/ui/scripts/cloud.core.serviceoffering.js
@@ -84,7 +84,7 @@ function afterLoadServiceOfferingJSP() {
var tags = trim(thisDialog.find("#add_service_tags").val());
if(tags != null && tags.length > 0)
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
$.ajax({
data: createURL("command=createServiceOffering"+array1.join("")+"&response=json"),
@@ -159,7 +159,7 @@ function doEditServiceOffering2($actionLink, $detailsTab, $midmenuItem1, $readon
*/
var tags = $detailsTab.find("#tags_edit").val();
- array1.push("&tags="+encodeURIComponent(tags));
+ array1.push("&tags="+todb(tags));
$.ajax({
data: createURL("command=updateServiceOffering&id="+id+array1.join("")),
diff --git a/ui/scripts/cloud.core.template.js b/ui/scripts/cloud.core.template.js
index 10c3287d983..0a6e45de3c9 100644
--- a/ui/scripts/cloud.core.template.js
+++ b/ui/scripts/cloud.core.template.js
@@ -84,7 +84,7 @@ function afterLoadTemplateJSP() {
var $midmenuItem1 = beforeAddingMidMenuItem() ;
$.ajax({
- data: createURL("command=registerTemplate&name="+todb(name)+"&displayText="+todb(desc)+"&url="+encodeURIComponent(url)+"&zoneid="+zoneId+"&ispublic="+isPublic+moreCriteria.join("")+"&format="+format+"&passwordEnabled="+password+"&osTypeId="+osType+"&hypervisor="+hypervisor+"&response=json"),
+ data: createURL("command=registerTemplate&name="+todb(name)+"&displayText="+todb(desc)+"&url="+todb(url)+"&zoneid="+zoneId+"&ispublic="+isPublic+moreCriteria.join("")+"&format="+format+"&passwordEnabled="+password+"&osTypeId="+osType+"&hypervisor="+hypervisor+"&response=json"),
dataType: "json",
success: function(json) {
var items = json.registertemplateresponse.template;
diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js
index 437b27ac8f6..3e687a10940 100644
--- a/ui/scripts/cloud.core.volume.js
+++ b/ui/scripts/cloud.core.volume.js
@@ -732,7 +732,7 @@ function doRecurringSnapshot($actionLink, $detailsTab, $midmenuItem1) {
}
var thisLink;
$.ajax({
- data: createURL("command=createSnapshotPolicy&intervaltype="+intervalType+"&schedule="+schedule+"&volumeid="+volumeId+"&maxsnaps="+max+"&timezone="+encodeURIComponent(timezone)),
+ data: createURL("command=createSnapshotPolicy&intervaltype="+intervalType+"&schedule="+schedule+"&volumeid="+volumeId+"&maxsnaps="+max+"&timezone="+todb(timezone)),
dataType: "json",
success: function(json) {
thisDialog.dialog("close");
diff --git a/ui/scripts/cloud.core.zone.js b/ui/scripts/cloud.core.zone.js
index 70f9bcb4ceb..8fa3e974649 100644
--- a/ui/scripts/cloud.core.zone.js
+++ b/ui/scripts/cloud.core.zone.js
@@ -479,7 +479,7 @@ function initAddVLANButton($button, $leftmenuItem1) {
var endip = trim($thisDialog.find("#add_publicip_vlan_endip").val());
$.ajax({
- data: createURL("command=createVlanIpRange&forVirtualNetwork="+type+"&zoneId="+zoneObj.id+vlan+scopeParams+"&gateway="+encodeURIComponent(gateway)+"&netmask="+encodeURIComponent(netmask)+"&startip="+encodeURIComponent(startip)+"&endip="+encodeURIComponent(endip)),
+ data: createURL("command=createVlanIpRange&forVirtualNetwork="+type+"&zoneId="+zoneObj.id+vlan+scopeParams+"&gateway="+todb(gateway)+"&netmask="+todb(netmask)+"&startip="+todb(startip)+"&endip="+todb(endip)),
dataType: "json",
success: function(json) {
$thisDialog.find("#spinning_wheel").hide();
@@ -543,7 +543,7 @@ function initAddSecondaryStorageButton($button, $leftmenuItem1) {
var url = nfsURL(nfs_server, path);
$.ajax({
- data: createURL("command=addSecondaryStorage&zoneId="+zoneId+"&url="+encodeURIComponent(url)),
+ data: createURL("command=addSecondaryStorage&zoneId="+zoneId+"&url="+todb(url)),
dataType: "json",
success: function(json) {
$thisDialog.find("#spinning_wheel").hide();
@@ -604,11 +604,11 @@ function initAddPodButton($button, $leftmenuItem1) {
var array1 = [];
array1.push("&zoneId="+zoneObj.id);
array1.push("&name="+todb(name));
- array1.push("&cidr="+encodeURIComponent(cidr));
- array1.push("&startIp="+encodeURIComponent(startip));
+ array1.push("&cidr="+todb(cidr));
+ array1.push("&startIp="+todb(startip));
if (endip != null && endip.length > 0)
- array1.push("&endIp="+encodeURIComponent(endip));
- array1.push("&gateway="+encodeURIComponent(gateway));
+ array1.push("&endIp="+todb(endip));
+ array1.push("&gateway="+todb(gateway));
$.ajax({
data: createURL("command=createPod"+array1.join("")),
@@ -855,19 +855,19 @@ function doEditZone2($actionLink, $detailsTab, $leftmenuItem1, $readonlyFields,
var dns1 = $detailsTab.find("#dns1_edit").val();
if(dns1 != jsonObj.dns1)
- moreCriteria.push("&dns1="+encodeURIComponent(dns1));
+ moreCriteria.push("&dns1="+todb(dns1));
var dns2 = $detailsTab.find("#dns2_edit").val();
if (dns2 != null && dns2.length > 0 && dns2 != jsonObj.dns2)
- moreCriteria.push("&dns2="+encodeURIComponent(dns2));
+ moreCriteria.push("&dns2="+todb(dns2));
var internaldns1 = $detailsTab.find("#internaldns1_edit").val();
if(internaldns1 != jsonObj.internaldns1)
- moreCriteria.push("&internaldns1="+encodeURIComponent(internaldns1));
+ moreCriteria.push("&internaldns1="+todb(internaldns1));
var internaldns2 = $detailsTab.find("#internaldns2_edit").val();
if (internaldns2 != null && internaldns2.length > 0 && internaldns2 != jsonObj.internaldns2)
- moreCriteria.push("&internaldns2="+encodeURIComponent(internaldns2));
+ moreCriteria.push("&internaldns2="+todb(internaldns2));
var vlan;
if ($("#tab_content_details #vlan_container").css("display") != "none") {
@@ -880,13 +880,13 @@ function doEditZone2($actionLink, $detailsTab, $leftmenuItem1, $readonlyFields,
vlan = vlanStart;
if(vlan != jsonObj.vlan)
- moreCriteria.push("&vlan=" + encodeURIComponent(vlan));
+ moreCriteria.push("&vlan=" + todb(vlan));
}
}
var guestcidraddress = $detailsTab.find("#guestcidraddress_edit").val();
if(guestcidraddress != jsonObj.guestcidraddress)
- moreCriteria.push("&guestcidraddress="+encodeURIComponent(guestcidraddress));
+ moreCriteria.push("&guestcidraddress="+todb(guestcidraddress));
if(moreCriteria.length > 0) {
$.ajax({
@@ -986,10 +986,10 @@ function initAddHostButtonOnZonePage($button, zoneId, zoneName) {
array1.push("&podid="+podId);
var username = trim($thisDialog.find("#host_username").val());
- array1.push("&username="+encodeURIComponent(username));
+ array1.push("&username="+todb(username));
var password = trim($thisDialog.find("#host_password").val());
- array1.push("&password="+encodeURIComponent(password));
+ array1.push("&password="+todb(password));
var newClusterName, existingClusterId;
if(clusterRadio == "new_cluster_radio") {
@@ -1010,7 +1010,7 @@ function initAddHostButtonOnZonePage($button, zoneId, zoneName) {
url = "http://" + todb(hostname);
else
url = hostname;
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
//var $midmenuItem1 = beforeAddingMidMenuItem() ;
@@ -1176,7 +1176,7 @@ function initAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) {
var lun = trim($thisDialog.find("#add_pool_lun").val());
url = iscsiURL(server, iqn, lun);
}
- array1.push("&url="+encodeURIComponent(url));
+ array1.push("&url="+todb(url));
var tags = trim($thisDialog.find("#add_pool_tags").val());
if(tags != null && tags.length > 0)
From 34f660b403e71817af6081d8898c1bc73e16ff83 Mon Sep 17 00:00:00 2001
From: Jessica Wang
Date: Wed, 1 Dec 2010 11:06:52 -0800
Subject: [PATCH 08/32] replace noNull() with fromdb().
---
ui/scripts/cloud.core.account.js | 8 ++---
ui/scripts/cloud.core.diskoffering.js | 2 +-
ui/scripts/cloud.core.domain.js | 10 +++---
ui/scripts/cloud.core.event.js | 2 +-
ui/scripts/cloud.core.host.js | 2 +-
ui/scripts/cloud.core.instance.js | 10 +++---
ui/scripts/cloud.core.ipaddress.js | 40 ++++++++++++------------
ui/scripts/cloud.core.iso.js | 4 +--
ui/scripts/cloud.core.pod.js | 18 +++++------
ui/scripts/cloud.core.primarystorage.js | 4 +--
ui/scripts/cloud.core.serviceoffering.js | 2 +-
ui/scripts/cloud.core.snapshot.js | 2 +-
ui/scripts/cloud.core.systemvm.js | 2 +-
ui/scripts/cloud.core.template.js | 2 +-
ui/scripts/cloud.core.volume.js | 8 ++---
ui/scripts/cloud.core.zone.js | 2 +-
16 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/ui/scripts/cloud.core.account.js b/ui/scripts/cloud.core.account.js
index da84d45740f..52c60b4e32a 100644
--- a/ui/scripts/cloud.core.account.js
+++ b/ui/scripts/cloud.core.account.js
@@ -60,15 +60,15 @@ function accountJsonToDetailsTab() {
var $detailsTab = $("#right_panel_content").find("#tab_content_details");
$detailsTab.find("#grid_header_title").text(fromdb(jsonObj.name));
- $detailsTab.find("#id").text(noNull(jsonObj.id));
+ $detailsTab.find("#id").text(fromdb(jsonObj.id));
$detailsTab.find("#role").text(toRole(jsonObj.accounttype));
$detailsTab.find("#account").text(fromdb(jsonObj.name));
$detailsTab.find("#domain").text(fromdb(jsonObj.domain));
- $detailsTab.find("#vm_total").text(noNull(jsonObj.vmtotal));
- $detailsTab.find("#ip_total").text(noNull(jsonObj.iptotal));
+ $detailsTab.find("#vm_total").text(fromdb(jsonObj.vmtotal));
+ $detailsTab.find("#ip_total").text(fromdb(jsonObj.iptotal));
$detailsTab.find("#bytes_received").text(convertBytes(jsonObj.receivedbytes));
$detailsTab.find("#bytes_sent").text(convertBytes(jsonObj.sentbytes));
- $detailsTab.find("#state").text(noNull(jsonObj.state));
+ $detailsTab.find("#state").text(fromdb(jsonObj.state));
//actions ***
var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu");
diff --git a/ui/scripts/cloud.core.diskoffering.js b/ui/scripts/cloud.core.diskoffering.js
index 10294b3e107..7821233318b 100644
--- a/ui/scripts/cloud.core.diskoffering.js
+++ b/ui/scripts/cloud.core.diskoffering.js
@@ -212,7 +212,7 @@ function diskOfferingJsonToDetailsTab() {
}
});
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
diff --git a/ui/scripts/cloud.core.domain.js b/ui/scripts/cloud.core.domain.js
index 3378bb8fe59..e87906a0eca 100644
--- a/ui/scripts/cloud.core.domain.js
+++ b/ui/scripts/cloud.core.domain.js
@@ -60,12 +60,12 @@ function drawNode(json, level, container) {
var $treeNode = $("#domain_tree_node_template").clone(true);
$treeNode.find("#domain_indent").css("marginLeft", (30*(level+1)));
- $treeNode.attr("id", "domain_"+noNull(json.id));
+ $treeNode.attr("id", "domain_"+fromdb(json.id));
$treeNode.data("jsonObj", json).data("domainLevel", level);
- $treeNode.find("#domain_title_container").attr("id", "domain_title_container_"+noNull(json.id));
- $treeNode.find("#domain_expand_icon").attr("id", "domain_expand_icon_"+noNull(json.id));
- $treeNode.find("#domain_name").attr("id", "domain_name_"+noNull(json.id)).text(fromdb(json.name));
- $treeNode.find("#domain_children_container").attr("id", "domain_children_container_"+noNull(json.id));
+ $treeNode.find("#domain_title_container").attr("id", "domain_title_container_"+fromdb(json.id));
+ $treeNode.find("#domain_expand_icon").attr("id", "domain_expand_icon_"+fromdb(json.id));
+ $treeNode.find("#domain_name").attr("id", "domain_name_"+fromdb(json.id)).text(fromdb(json.name));
+ $treeNode.find("#domain_children_container").attr("id", "domain_children_container_"+fromdb(json.id));
container.append($treeNode.show());
return $treeNode;
}
diff --git a/ui/scripts/cloud.core.event.js b/ui/scripts/cloud.core.event.js
index 1522d25d050..dcf4dff4710 100644
--- a/ui/scripts/cloud.core.event.js
+++ b/ui/scripts/cloud.core.event.js
@@ -55,7 +55,7 @@ function eventJsonToDetailsTab() {
$thisTab.find("#tab_container").hide();
$thisTab.find("#tab_spinning_wheel").show();
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#username").text(fromdb(jsonObj.username));
$thisTab.find("#account").text(fromdb(jsonObj.account));
$thisTab.find("#type").text(fromdb(jsonObj.type));
diff --git a/ui/scripts/cloud.core.host.js b/ui/scripts/cloud.core.host.js
index 4a8a8aef46c..56d93db2104 100644
--- a/ui/scripts/cloud.core.host.js
+++ b/ui/scripts/cloud.core.host.js
@@ -86,7 +86,7 @@ function hostJsonToDetailsTab() {
$thisTab.find("#tab_container").hide();
$thisTab.find("#tab_spinning_wheel").show();
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
diff --git a/ui/scripts/cloud.core.instance.js b/ui/scripts/cloud.core.instance.js
index c418aa4ad93..fb67af77724 100644
--- a/ui/scripts/cloud.core.instance.js
+++ b/ui/scripts/cloud.core.instance.js
@@ -1327,9 +1327,9 @@ function vmJsonToDetailsTab(){
resetViewConsoleAction(jsonObj, $thisTab);
setVmStateInRightPanel(jsonObj.state, $thisTab.find("#state"));
- $thisTab.find("#ipAddress").text(noNull(jsonObj.ipaddress));
+ $thisTab.find("#ipAddress").text(fromdb(jsonObj.ipaddress));
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#zoneName").text(fromdb(jsonObj.zonename));
var vmName = getVmName(jsonObj.name, jsonObj.displayname);
@@ -1549,10 +1549,10 @@ var vmVolumeActionMap = {
}
function vmVolumeJSONToTemplate(json, $template) {
- $template.attr("id","vm_volume_"+noNull(json.id));
+ $template.attr("id","vm_volume_"+fromdb(json.id));
$template.data("jsonObj", json);
$template.find("#title").text(fromdb(json.name));
- $template.find("#id").text(noNull(json.id));
+ $template.find("#id").text(fromdb(json.id));
$template.find("#name").text(fromdb(json.name));
if (json.storagetype == "shared")
$template.find("#type").text(fromdb(json.type) + " (shared storage)");
@@ -1608,7 +1608,7 @@ function vmRouterJSONToTemplate(jsonObj, $template) {
resetViewConsoleAction(jsonObj, $template);
setVmStateInRightPanel(fromdb(jsonObj.state), $template.find("#state"));
- $template.find("#ipAddress").text(noNull(jsonObj.publicip));
+ $template.find("#ipAddress").text(fromdb(jsonObj.publicip));
$template.find("#zonename").text(fromdb(jsonObj.zonename));
$template.find("#name").text(fromdb(jsonObj.name));
diff --git a/ui/scripts/cloud.core.ipaddress.js b/ui/scripts/cloud.core.ipaddress.js
index 77d88766ac5..db17bfd9600 100644
--- a/ui/scripts/cloud.core.ipaddress.js
+++ b/ui/scripts/cloud.core.ipaddress.js
@@ -755,8 +755,8 @@ function ipJsonToDetailsTab() {
}
});
- $thisTab.find("#grid_header_title").text(noNull(ipObj.ipaddress));
- $thisTab.find("#ipaddress").text(noNull(ipObj.ipaddress));
+ $thisTab.find("#grid_header_title").text(fromdb(ipObj.ipaddress));
+ $thisTab.find("#ipaddress").text(fromdb(ipObj.ipaddress));
$thisTab.find("#zonename").text(fromdb(ipObj.zonename));
$thisTab.find("#vlanname").text(fromdb(ipObj.vlanname));
setBooleanReadField(ipObj.issourcenat, $thisTab.find("#source_nat"));
@@ -991,20 +991,20 @@ function ipClearPortForwardingTab() {
}
function portForwardingJsonToTemplate(jsonObj, $template) {
- $template.attr("id", "portForwarding_" + noNull(jsonObj.id)).data("portForwardingId", noNull(jsonObj.id));
+ $template.attr("id", "portForwarding_" + fromdb(jsonObj.id)).data("portForwardingId", fromdb(jsonObj.id));
- $template.find("#row_container #public_port").text(noNull(jsonObj.publicport));
- $template.find("#row_container_edit #public_port").text(noNull(jsonObj.publicport));
+ $template.find("#row_container #public_port").text(fromdb(jsonObj.publicport));
+ $template.find("#row_container_edit #public_port").text(fromdb(jsonObj.publicport));
- $template.find("#row_container #private_port").text(noNull(jsonObj.privateport));
- $template.find("#row_container_edit #private_port").val(noNull(jsonObj.privateport));
+ $template.find("#row_container #private_port").text(fromdb(jsonObj.privateport));
+ $template.find("#row_container_edit #private_port").val(fromdb(jsonObj.privateport));
$template.find("#row_container #protocol").text(fromdb(jsonObj.protocol));
$template.find("#row_container_edit #protocol").text(fromdb(jsonObj.protocol));
var vmName = getVmName(jsonObj.virtualmachinename, jsonObj.virtualmachinedisplayname);
$template.find("#row_container #vm_name").text(vmName);
- var virtualMachineId = noNull(jsonObj.virtualmachineid);
+ var virtualMachineId = fromdb(jsonObj.virtualmachineid);
var $midmenuItem1 = $("#right_panel_content").data("$midmenuItem1");
if($midmenuItem1 == null)
@@ -1012,8 +1012,8 @@ function portForwardingJsonToTemplate(jsonObj, $template) {
var ipObj = $midmenuItem1.data("jsonObj");
if(ipObj == null)
return;
- var ipAddress = noNull(ipObj.ipaddress);
- var IpDomainid = noNull(ipObj.domainid);
+ var ipAddress = fromdb(ipObj.ipaddress);
+ var IpDomainid = fromdb(ipObj.domainid);
var IpAccount = fromdb(ipObj.account);
var $vmSelect = $template.find("#row_container_edit #vm").empty();
@@ -1028,7 +1028,7 @@ function portForwardingJsonToTemplate(jsonObj, $template) {
$spinningWheel.find("#description").text("Deleting....");
$spinningWheel.show();
$.ajax({
- data: createURL("command=deletePortForwardingRule&id="+noNull(jsonObj.id)),
+ data: createURL("command=deletePortForwardingRule&id="+fromdb(jsonObj.id)),
dataType: "json",
success: function(json) {
$template.slideUp("slow", function(){
@@ -1148,7 +1148,7 @@ function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) {
var instances = json.listvirtualmachinesresponse.virtualmachine;
if (instances != null && instances.length > 0) {
for (var i = 0; i < instances.length; i++) {
- var html = $("");
+ var html = $("");
$vmSelect.append(html);
}
}
@@ -1163,7 +1163,7 @@ function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) {
var instances = json.listvirtualmachinesresponse.virtualmachine;
if (instances != null && instances.length > 0) {
for (var i = 0; i < instances.length; i++) {
- var html = $("");
+ var html = $("");
$vmSelect.append(html);
}
}
@@ -1180,17 +1180,17 @@ function ipClearLoadBalancerTab() {
}
function loadBalancerJsonToTemplate(jsonObj, $template) {
- var loadBalancerId = noNull(jsonObj.id);
+ var loadBalancerId = fromdb(jsonObj.id);
$template.attr("id", "loadBalancer_" + loadBalancerId).data("loadBalancerId", loadBalancerId);
$template.find("#row_container #name").text(fromdb(jsonObj.name));
$template.find("#row_container_edit #name").val(fromdb(jsonObj.name));
- $template.find("#row_container #public_port").text(noNull(jsonObj.publicport));
- $template.find("#row_container_edit #public_port").text(noNull(jsonObj.publicport));
+ $template.find("#row_container #public_port").text(fromdb(jsonObj.publicport));
+ $template.find("#row_container_edit #public_port").text(fromdb(jsonObj.publicport));
- $template.find("#row_container #private_port").text(noNull(jsonObj.privateport));
- $template.find("#row_container_edit #private_port").val(noNull(jsonObj.privateport));
+ $template.find("#row_container #private_port").text(fromdb(jsonObj.privateport));
+ $template.find("#row_container_edit #private_port").val(fromdb(jsonObj.privateport));
$template.find("#row_container #algorithm").text(fromdb(jsonObj.algorithm));
$template.find("#row_container_edit #algorithm").val(fromdb(jsonObj.algorithm));
@@ -1440,13 +1440,13 @@ function refreshCreateLoadBalancerRow() {
function lbVmObjToTemplate(obj, $template) {
$template.find("#vm_name").text(obj.vmName);
- $template.find("#vm_private_ip").text(noNull(obj.vmPrivateIp));
+ $template.find("#vm_private_ip").text(fromdb(obj.vmPrivateIp));
$template.find("#remove_link").bind("click", function(event){
var $spinningWheel = $template.find("#spinning_wheel");
$spinningWheel.show();
$.ajax({
- data: createURL("command=removeFromLoadBalancerRule&id="+noNull(obj.loadBalancerId)+"&virtualmachineid="+noNull(obj.vmId)),
+ data: createURL("command=removeFromLoadBalancerRule&id="+fromdb(obj.loadBalancerId)+"&virtualmachineid="+fromdb(obj.vmId)),
dataType: "json",
success: function(json) {
var lbJSON = json.removefromloadbalancerruleresponse;
diff --git a/ui/scripts/cloud.core.iso.js b/ui/scripts/cloud.core.iso.js
index 67d21892c8d..b167c0657e3 100644
--- a/ui/scripts/cloud.core.iso.js
+++ b/ui/scripts/cloud.core.iso.js
@@ -225,7 +225,7 @@ function isoJsonToDetailsTab() {
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#zonename").text(fromdb(jsonObj.zonename));
$thisTab.find("#name").text(fromdb(jsonObj.name));
@@ -234,7 +234,7 @@ function isoJsonToDetailsTab() {
$thisTab.find("#displaytext").text(fromdb(jsonObj.displaytext));
$thisTab.find("#displaytext_edit").val(fromdb(jsonObj.displaytext));
$thisTab.find("#ostypename").text(fromdb(jsonObj.ostypename));
- $thisTab.find("#ostypename_edit").val(noNull(jsonObj.ostypeid));
+ $thisTab.find("#ostypename_edit").val(fromdb(jsonObj.ostypeid));
$thisTab.find("#account").text(fromdb(jsonObj.account));
$thisTab.find("#domain").text(fromdb(jsonObj.domain));
diff --git a/ui/scripts/cloud.core.pod.js b/ui/scripts/cloud.core.pod.js
index b10efe9d564..424e7fa39a0 100644
--- a/ui/scripts/cloud.core.pod.js
+++ b/ui/scripts/cloud.core.pod.js
@@ -70,7 +70,7 @@ function podJsonToDetailsTab() {
$thisTab.find("#tab_container").hide();
$thisTab.find("#tab_spinning_wheel").show();
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
@@ -90,7 +90,7 @@ function podJsonToDetailsTab() {
// hide network tab upon zone vlan
var networkType;
$.ajax({
- data: createURL("command=listZones&id="+noNull(jsonObj.zoneid)),
+ data: createURL("command=listZones&id="+fromdb(jsonObj.zoneid)),
dataType: "json",
async: false,
success: function(json) {
@@ -143,7 +143,7 @@ function podJsonToNetworkTab() {
$thisTab.find("#tab_spinning_wheel").show();
$.ajax({
- data: createURL("command=listVlanIpRanges&zoneid="+noNull(jsonObj.zoneid)+"&podid="+noNull(jsonObj.id)),
+ data: createURL("command=listVlanIpRanges&zoneid="+fromdb(jsonObj.zoneid)+"&podid="+fromdb(jsonObj.id)),
dataType: "json",
success: function(json) {
var items = json.listvlaniprangesresponse.vlaniprange;
@@ -164,12 +164,12 @@ function podJsonToNetworkTab() {
function podNetworkJsonToTemplate(jsonObj, template) {
template.data("jsonObj", jsonObj);
- template.attr("id", "pod_VLAN_"+noNull(jsonObj.id)).data("podVLANId", noNull(jsonObj.id));
+ template.attr("id", "pod_VLAN_"+fromdb(jsonObj.id)).data("podVLANId", fromdb(jsonObj.id));
template.find("#grid_header_title").text(fromdb(jsonObj.description));
- template.find("#id").text(noNull(jsonObj.id));
+ template.find("#id").text(fromdb(jsonObj.id));
template.find("#iprange").text(fromdb(jsonObj.description));
- template.find("#netmask").text(noNull(jsonObj.netmask));
- template.find("#gateway").text(noNull(jsonObj.gateway));
+ template.find("#netmask").text(fromdb(jsonObj.netmask));
+ template.find("#gateway").text(fromdb(jsonObj.gateway));
template.find("#podname").text(fromdb(jsonObj.podname));
var $actionLink = template.find("#network_action_link");
@@ -247,9 +247,9 @@ function refreshClsuterFieldInAddHostDialog(dialogAddHost, podId, clusterId) {
if(items != null && items.length > 0) {
for(var i=0; i" + fromdb(items[i].name) + "");
+ clusterSelect.append("");
else
- clusterSelect.append("");
+ clusterSelect.append("");
}
dialogAddHost.find("input[value=existing_cluster_radio]").attr("checked", true);
}
diff --git a/ui/scripts/cloud.core.primarystorage.js b/ui/scripts/cloud.core.primarystorage.js
index e4cf04dd2f2..a3b1dcee3aa 100644
--- a/ui/scripts/cloud.core.primarystorage.js
+++ b/ui/scripts/cloud.core.primarystorage.js
@@ -77,7 +77,7 @@ function primarystorageJsonToDetailsTab() {
$thisTab.find("#tab_container").hide();
$thisTab.find("#tab_spinning_wheel").show();
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
@@ -90,7 +90,7 @@ function primarystorageJsonToDetailsTab() {
if (jsonObj.type == 'NetworkFilesystem')
storageType = "NFS Share";
$thisTab.find("#type").text(fromdb(storageType));
- $thisTab.find("#ipaddress").text(noNull(jsonObj.ipaddress));
+ $thisTab.find("#ipaddress").text(fromdb(jsonObj.ipaddress));
$thisTab.find("#path").text(fromdb(jsonObj.path));
$thisTab.find("#disksizetotal").text(convertBytes(jsonObj.disksizetotal));
$thisTab.find("#disksizeallocated").text(convertBytes(jsonObj.disksizeallocated));
diff --git a/ui/scripts/cloud.core.serviceoffering.js b/ui/scripts/cloud.core.serviceoffering.js
index fff2181ba9f..3ca96cec9fd 100644
--- a/ui/scripts/cloud.core.serviceoffering.js
+++ b/ui/scripts/cloud.core.serviceoffering.js
@@ -221,7 +221,7 @@ function serviceOfferingJsonToDetailsTab() {
}
});
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
diff --git a/ui/scripts/cloud.core.snapshot.js b/ui/scripts/cloud.core.snapshot.js
index 67112a0bc61..154bc448674 100644
--- a/ui/scripts/cloud.core.snapshot.js
+++ b/ui/scripts/cloud.core.snapshot.js
@@ -85,7 +85,7 @@ function snapshotJsonToDetailsTab() {
}
});
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#name").text(fromdb(jsonObj.name));
$thisTab.find("#volume_name").text(fromdb(jsonObj.volumename));
$thisTab.find("#interval_type").text(fromdb(jsonObj.intervaltype));
diff --git a/ui/scripts/cloud.core.systemvm.js b/ui/scripts/cloud.core.systemvm.js
index 4f26778298f..ed72781c636 100644
--- a/ui/scripts/cloud.core.systemvm.js
+++ b/ui/scripts/cloud.core.systemvm.js
@@ -61,7 +61,7 @@ function systemvmJsonToDetailsTab() {
resetViewConsoleAction(jsonObj, $thisTab);
setVmStateInRightPanel(fromdb(jsonObj.state), $thisTab.find("#state"));
- $thisTab.find("#ipAddress").text(noNull(jsonObj.publicip));
+ $thisTab.find("#ipAddress").text(fromdb(jsonObj.publicip));
$thisTab.find("#state").text(fromdb(jsonObj.state));
$thisTab.find("#systemvmtype").text(toSystemVMTypeText(jsonObj.systemvmtype));
diff --git a/ui/scripts/cloud.core.template.js b/ui/scripts/cloud.core.template.js
index 0a6e45de3c9..733612e6992 100644
--- a/ui/scripts/cloud.core.template.js
+++ b/ui/scripts/cloud.core.template.js
@@ -242,7 +242,7 @@ function templateJsonToDetailsTab() {
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#zonename").text(fromdb(jsonObj.zonename));
$thisTab.find("#name").text(fromdb(jsonObj.name));
diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js
index 3e687a10940..2219529c402 100644
--- a/ui/scripts/cloud.core.volume.js
+++ b/ui/scripts/cloud.core.volume.js
@@ -329,7 +329,7 @@ function volumeJsonToDetailsTab(){
}
});
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#name").text(fromdb(jsonObj.name));
$thisTab.find("#zonename").text(fromdb(jsonObj.zonename));
$thisTab.find("#device_id").text(fromdb(jsonObj.deviceid));
@@ -394,7 +394,7 @@ function volumeJsonToSnapshotTab() {
$.ajax({
cache: false,
- data: createURL("command=listSnapshots&volumeid="+noNull(jsonObj.id)),
+ data: createURL("command=listSnapshots&volumeid="+fromdb(jsonObj.id)),
dataType: "json",
success: function(json) {
var items = json.listsnapshotsresponse.snapshot;
@@ -415,9 +415,9 @@ function volumeJsonToSnapshotTab() {
function volumeSnapshotJSONToTemplate(jsonObj, template) {
template.data("jsonObj", jsonObj);
- template.attr("id", "volume_snapshot_"+noNull(jsonObj.id)).data("volumeSnapshotId", noNull(jsonObj.id));
+ template.attr("id", "volume_snapshot_"+fromdb(jsonObj.id)).data("volumeSnapshotId", fromdb(jsonObj.id));
template.find("#grid_header_title").text(fromdb(jsonObj.name));
- template.find("#id").text(noNull(jsonObj.id));
+ template.find("#id").text(fromdb(jsonObj.id));
template.find("#name").text(fromdb(jsonObj.name));
template.find("#volumename").text(fromdb(jsonObj.volumename));
template.find("#intervaltype").text(fromdb(jsonObj.intervaltype));
diff --git a/ui/scripts/cloud.core.zone.js b/ui/scripts/cloud.core.zone.js
index 8fa3e974649..8e3016000e0 100644
--- a/ui/scripts/cloud.core.zone.js
+++ b/ui/scripts/cloud.core.zone.js
@@ -96,7 +96,7 @@ function zoneJsonToDetailsTab() {
$thisTab.find("#tab_container").hide();
$thisTab.find("#tab_spinning_wheel").show();
- $thisTab.find("#id").text(noNull(jsonObj.id));
+ $thisTab.find("#id").text(fromdb(jsonObj.id));
$thisTab.find("#grid_header_title").text(fromdb(jsonObj.name));
$thisTab.find("#name").text(fromdb(jsonObj.name));
From 833c1708cee3184f3ed409cae77bc203a231f409 Mon Sep 17 00:00:00 2001
From: Jessica Wang
Date: Wed, 1 Dec 2010 13:43:54 -0800
Subject: [PATCH 09/32] instance page - fix a bug that instance groups didn't
show when login as a user.
---
ui/scripts/cloud.core.instance.js | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/ui/scripts/cloud.core.instance.js b/ui/scripts/cloud.core.instance.js
index fb67af77724..96a41058a03 100644
--- a/ui/scripts/cloud.core.instance.js
+++ b/ui/scripts/cloud.core.instance.js
@@ -16,7 +16,6 @@
*
*/
-var $instanceSubMenuContainer;
function instanceBuildSubMenu() {
if (isAdmin() || isDomainAdmin()) {
$("#leftmenu_instance_expandedbox").find("#leftmenu_instances_my_instances_container, #leftmenu_instances_all_instances_container, #leftmenu_instances_running_instances_container, #leftmenu_instances_stopped_instances_container, #leftmenu_instances_destroyed_instances_container ").show();
@@ -43,7 +42,7 @@ function instanceBuildSubMenu2(label, commandString) {
var $newSubMenu = $("#leftmenu_secondindent_template").clone();
$newSubMenu.find("#label").text(label);
bindAndListMidMenuItems($newSubMenu, commandString, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- $instanceSubMenuContainer.append($newSubMenu.show());
+ $("#leftmenu_instance_expandedbox").append($newSubMenu.show());
}
var $doTemplateNo, $doTemplateCustom,$doTemplateExisting;
From 59667ebe14b6de82cba4f240de208fd25d2ca109 Mon Sep 17 00:00:00 2001
From: Jessica Wang
Date: Wed, 1 Dec 2010 14:41:36 -0800
Subject: [PATCH 10/32] Search - add getSearchParamsFn() on all pages.
---
ui/scripts/cloud.core.account.js | 4 +++
ui/scripts/cloud.core.alert.js | 4 +++
ui/scripts/cloud.core.diskoffering.js | 4 +++
ui/scripts/cloud.core.event.js | 4 +++
ui/scripts/cloud.core.init.js | 46 ++++++++++++------------
ui/scripts/cloud.core.instance.js | 6 +++-
ui/scripts/cloud.core.ipaddress.js | 4 +++
ui/scripts/cloud.core.iso.js | 4 +++
ui/scripts/cloud.core.js | 13 +++----
ui/scripts/cloud.core.router.js | 4 +++
ui/scripts/cloud.core.serviceoffering.js | 4 +++
ui/scripts/cloud.core.snapshot.js | 4 +++
ui/scripts/cloud.core.systemvm.js | 4 +++
ui/scripts/cloud.core.template.js | 4 +++
ui/scripts/cloud.core.volume.js | 4 +++
15 files changed, 83 insertions(+), 30 deletions(-)
diff --git a/ui/scripts/cloud.core.account.js b/ui/scripts/cloud.core.account.js
index 52c60b4e32a..7c46cf50a69 100644
--- a/ui/scripts/cloud.core.account.js
+++ b/ui/scripts/cloud.core.account.js
@@ -19,6 +19,10 @@
var systemAccountId = 1;
var adminAccountId = 2;
+function accountGetSearchParams() {
+ return "";
+}
+
function afterLoadAccountJSP() {
initDialog("dialog_resource_limits");
initDialog("dialog_disable_account");
diff --git a/ui/scripts/cloud.core.alert.js b/ui/scripts/cloud.core.alert.js
index 2355e7a5b86..4fc02e17f77 100644
--- a/ui/scripts/cloud.core.alert.js
+++ b/ui/scripts/cloud.core.alert.js
@@ -16,6 +16,10 @@
*
*/
+function alertGetSearchParams() {
+ return "";
+}
+
function afterLoadAlertJSP() {
}
diff --git a/ui/scripts/cloud.core.diskoffering.js b/ui/scripts/cloud.core.diskoffering.js
index 7821233318b..2e736973b19 100644
--- a/ui/scripts/cloud.core.diskoffering.js
+++ b/ui/scripts/cloud.core.diskoffering.js
@@ -16,6 +16,10 @@
*
*/
+function diskOfferingGetSearchParams() {
+ return "";
+}
+
function afterLoadDiskOfferingJSP() {
var $detailsTab = $("#right_panel_content #tab_content_details");
initAddDiskOfferingButton($("#midmenu_add_link"));
diff --git a/ui/scripts/cloud.core.event.js b/ui/scripts/cloud.core.event.js
index dcf4dff4710..a13428a78ee 100644
--- a/ui/scripts/cloud.core.event.js
+++ b/ui/scripts/cloud.core.event.js
@@ -16,6 +16,10 @@
*
*/
+function eventGetSearchParams() {
+ return "";
+}
+
function afterLoadEventJSP() {
}
diff --git a/ui/scripts/cloud.core.init.js b/ui/scripts/cloud.core.init.js
index 0afa5e57d8f..ea4fad7d9ee 100644
--- a/ui/scripts/cloud.core.init.js
+++ b/ui/scripts/cloud.core.init.js
@@ -60,7 +60,7 @@ $(document).ready(function() {
});
$("#leftmenu_account").bind("click", function(event) {
selectLeftMenu($(this), false);
- listMidMenuItems("listAccounts", "listaccountsresponse", "account", "jsp/account.jsp", afterLoadAccountJSP, accountToMidmenu, accountToRightPanel, getMidmenuId, false, "leftmenu_account");
+ listMidMenuItems("listAccounts", accountGetSearchParams, "listaccountsresponse", "account", "jsp/account.jsp", afterLoadAccountJSP, accountToMidmenu, accountToRightPanel, getMidmenuId, false, "leftmenu_account");
return false;
});
@@ -109,31 +109,31 @@ $(document).ready(function() {
function buildSecondLevelNavigation() {
// Instance sub menus
- bindAndListMidMenuItems($("#leftmenu_instances_my_instances"), "listVirtualMachines&domainid="+g_domainid+"&account="+g_account, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- bindAndListMidMenuItems($("#leftmenu_instances_all_instances"), "listVirtualMachines", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- bindAndListMidMenuItems($("#leftmenu_instances_running_instances"), "listVirtualMachines&state=Running", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- bindAndListMidMenuItems($("#leftmenu_instances_stopped_instances"), "listVirtualMachines&state=Stopped", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- bindAndListMidMenuItems($("#leftmenu_instances_destroyed_instances"), "listVirtualMachines&state=Destroyed", "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($("#leftmenu_instances_my_instances"), "listVirtualMachines&domainid="+g_domainid+"&account="+g_account, vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($("#leftmenu_instances_all_instances"), "listVirtualMachines", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($("#leftmenu_instances_running_instances"), "listVirtualMachines&state=Running", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($("#leftmenu_instances_stopped_instances"), "listVirtualMachines&state=Stopped", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($("#leftmenu_instances_destroyed_instances"), "listVirtualMachines&state=Destroyed", vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
- bindAndListMidMenuItems($("#leftmenu_event"), "listEvents", "listeventsresponse", "event", "jsp/event.jsp", afterLoadEventJSP, eventToMidmenu, eventToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_alert"), "listAlerts", "listalertsresponse", "alert", "jsp/alert.jsp", afterLoadAlertJSP, alertToMidmenu, alertToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_volume"), "listVolumes", "listvolumesresponse", "volume", "jsp/volume.jsp", afterLoadVolumeJSP, volumeToMidmenu, volumeToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_snapshot"), "listSnapshots", "listsnapshotsresponse", "snapshot", "jsp/snapshot.jsp", afterLoadSnapshotJSP, snapshotToMidmenu, snapshotToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_ip"), "listPublicIpAddresses", "listpublicipaddressesresponse", "publicipaddress", "jsp/ipaddress.jsp", afterLoadIpJSP, ipToMidmenu, ipToRightPanel, ipGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_event"), "listEvents", eventGetSearchParams, "listeventsresponse", "event", "jsp/event.jsp", afterLoadEventJSP, eventToMidmenu, eventToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_alert"), "listAlerts", alertGetSearchParams, "listalertsresponse", "alert", "jsp/alert.jsp", afterLoadAlertJSP, alertToMidmenu, alertToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_volume"), "listVolumes", volumeGetSearchParams, "listvolumesresponse", "volume", "jsp/volume.jsp", afterLoadVolumeJSP, volumeToMidmenu, volumeToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_snapshot"), "listSnapshots", snapshotGetSearchParams, "listsnapshotsresponse", "snapshot", "jsp/snapshot.jsp", afterLoadSnapshotJSP, snapshotToMidmenu, snapshotToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_ip"), "listPublicIpAddresses", ipGetSearchParams, "listpublicipaddressesresponse", "publicipaddress", "jsp/ipaddress.jsp", afterLoadIpJSP, ipToMidmenu, ipToRightPanel, ipGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_my_template"), "listTemplates&templatefilter=self", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_featured_template"), "listTemplates&templatefilter=featured", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_community_template"), "listTemplates&templatefilter=community", "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_my_template"), "listTemplates&templatefilter=self", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_featured_template"), "listTemplates&templatefilter=featured", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_community_template"), "listTemplates&templatefilter=community", templateGetSearchParams, "listtemplatesresponse", "template", "jsp/template.jsp", afterLoadTemplateJSP, templateToMidmenu, templateToRightPanel, templateGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_my_iso"), "listIsos&isofilter=self", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_featured_iso"), "listIsos&isofilter=featured", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_community_iso"), "listIsos&isofilter=community", "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_my_iso"), "listIsos&isofilter=self", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_featured_iso"), "listIsos&isofilter=featured", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_community_iso"), "listIsos&isofilter=community", isoGetSearchParams, "listisosresponse", "iso", "jsp/iso.jsp", afterLoadIsoJSP, isoToMidmenu, isoToRightPanel, isoGetMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_service_offering"), "listServiceOfferings", "listserviceofferingsresponse", "serviceoffering", "jsp/serviceoffering.jsp", afterLoadServiceOfferingJSP, serviceOfferingToMidmenu, serviceOfferingToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_disk_offering"), "listDiskOfferings", "listdiskofferingsresponse", "diskoffering", "jsp/diskoffering.jsp", afterLoadDiskOfferingJSP, diskOfferingToMidmenu, diskOfferingToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_service_offering"), "listServiceOfferings", serviceOfferingGetSearchParams, "listserviceofferingsresponse", "serviceoffering", "jsp/serviceoffering.jsp", afterLoadServiceOfferingJSP, serviceOfferingToMidmenu, serviceOfferingToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_disk_offering"), "listDiskOfferings", diskOfferingGetSearchParams, "listdiskofferingsresponse", "diskoffering", "jsp/diskoffering.jsp", afterLoadDiskOfferingJSP, diskOfferingToMidmenu, diskOfferingToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_virtual_router"), "listRouters", "listroutersresponse", "router", "jsp/router.jsp", afterLoadRouterJSP, routerToMidmenu, routerToRightPanel, getMidmenuId, false);
- bindAndListMidMenuItems($("#leftmenu_submenu_systemvm"), "listSystemVms", "listsystemvmsresponse", "systemvm", "jsp/systemvm.jsp", afterLoadSystemVmJSP, systemvmToMidmenu, systemvmToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_virtual_router"), "listRouters", routerGetSearchParams, "listroutersresponse", "router", "jsp/router.jsp", afterLoadRouterJSP, routerToMidmenu, routerToRightPanel, getMidmenuId, false);
+ bindAndListMidMenuItems($("#leftmenu_submenu_systemvm"), "listSystemVms", systemVmGetSearchParams, "listsystemvmsresponse", "systemvm", "jsp/systemvm.jsp", afterLoadSystemVmJSP, systemvmToMidmenu, systemvmToRightPanel, getMidmenuId, false);
$("#leftmenu_global_setting").bind("click", function(event) {
selectLeftSubMenu($(this));
@@ -220,10 +220,10 @@ $(document).ready(function() {
var targetId = $target.attr("id");
if(targetId == "midmenu_prevbutton") {
- listMidMenuItems2(params.commandString, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page-1));
+ listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page-1));
}
else if(targetId == "midmenu_nextbutton") {
- listMidMenuItems2(params.commandString, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page+1));
+ listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, (params.page+1));
}
return false;
diff --git a/ui/scripts/cloud.core.instance.js b/ui/scripts/cloud.core.instance.js
index 96a41058a03..e5862b72047 100644
--- a/ui/scripts/cloud.core.instance.js
+++ b/ui/scripts/cloud.core.instance.js
@@ -16,6 +16,10 @@
*
*/
+function vmGetSearchParams() {
+ return "";
+}
+
function instanceBuildSubMenu() {
if (isAdmin() || isDomainAdmin()) {
$("#leftmenu_instance_expandedbox").find("#leftmenu_instances_my_instances_container, #leftmenu_instances_all_instances_container, #leftmenu_instances_running_instances_container, #leftmenu_instances_stopped_instances_container, #leftmenu_instances_destroyed_instances_container ").show();
@@ -41,7 +45,7 @@ function instanceBuildSubMenu() {
function instanceBuildSubMenu2(label, commandString) {
var $newSubMenu = $("#leftmenu_secondindent_template").clone();
$newSubMenu.find("#label").text(label);
- bindAndListMidMenuItems($newSubMenu, commandString, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
+ bindAndListMidMenuItems($newSubMenu, commandString, vmGetSearchParams, "listvirtualmachinesresponse", "virtualmachine", "jsp/instance.jsp", afterLoadInstanceJSP, vmToMidmenu, vmToRightPanel, getMidmenuId, true);
$("#leftmenu_instance_expandedbox").append($newSubMenu.show());
}
diff --git a/ui/scripts/cloud.core.ipaddress.js b/ui/scripts/cloud.core.ipaddress.js
index db17bfd9600..a68008d246c 100644
--- a/ui/scripts/cloud.core.ipaddress.js
+++ b/ui/scripts/cloud.core.ipaddress.js
@@ -16,6 +16,10 @@
*
*/
+function ipGetSearchParams() {
+ return "";
+}
+
function afterLoadIpJSP() {
//***** switch between different tabs (begin) ********************************************************************
var tabArray = [$("#tab_details"), $("#tab_port_forwarding"), $("#tab_load_balancer"), $("#tab_vpn")];
diff --git a/ui/scripts/cloud.core.iso.js b/ui/scripts/cloud.core.iso.js
index b167c0657e3..de4bdc96b08 100644
--- a/ui/scripts/cloud.core.iso.js
+++ b/ui/scripts/cloud.core.iso.js
@@ -21,6 +21,10 @@ var xsToolsIsoId = 200;
var g_zoneIds = [];
var g_zoneNames = [];
+function isoGetSearchParams() {
+ return "";
+}
+
function afterLoadIsoJSP() {
var $detailsTab = $("#right_panel_content #tab_content_details");
diff --git a/ui/scripts/cloud.core.js b/ui/scripts/cloud.core.js
index d5f3ab8f158..233354e5c30 100644
--- a/ui/scripts/cloud.core.js
+++ b/ui/scripts/cloud.core.js
@@ -926,9 +926,10 @@ function getMidmenuId(jsonObj) {
return "midmenuItem_" + jsonObj.id;
}
-function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, page) {
+function listMidMenuItems2(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, page) {
var params = {
"commandString": commandString,
+ "getSearchParamsFn": getSearchParamsFn,
"jsonResponse1": jsonResponse1,
"jsonResponse2": jsonResponse2,
"toMidmenuFn": toMidmenuFn,
@@ -949,7 +950,7 @@ function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmen
var count = 0;
$.ajax({
cache: false,
- data: createURL("command="+commandString+"&pagesize="+midmenuItemCount+"&page="+page),
+ data: createURL("command="+commandString+getSearchParamsFn()+"&pagesize="+midmenuItemCount+"&page="+page),
dataType: "json",
async: false,
success: function(json) {
@@ -986,7 +987,7 @@ function listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmen
return count;
}
-function listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, leftmenuId) {
+function listMidMenuItems(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, leftmenuId) {
clearMiddleMenu();
showMiddleMenu();
$("#midmenu_container").hide();
@@ -1008,15 +1009,15 @@ function listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPane
});
removeDialogs();
afterLoadRightPanelJSPFn();
- listMidMenuItems2(commandString, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, 1);
+ listMidMenuItems2(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, 1);
});
return false;
}
-function bindAndListMidMenuItems($leftmenu, commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu) {
+function bindAndListMidMenuItems($leftmenu, commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu) {
$leftmenu.bind("click", function(event) {
selectLeftSubMenu($(this));
- listMidMenuItems(commandString, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, $(this).attr("id"));
+ listMidMenuItems(commandString, getSearchParamsFn, jsonResponse1, jsonResponse2, rightPanelJSP, afterLoadRightPanelJSPFn, toMidmenuFn, toRightPanelFn, getMidmenuIdFn, isMultipleSelectionInMidMenu, $(this).attr("id"));
return false;
});
}
diff --git a/ui/scripts/cloud.core.router.js b/ui/scripts/cloud.core.router.js
index 346710e2db8..02024663f64 100644
--- a/ui/scripts/cloud.core.router.js
+++ b/ui/scripts/cloud.core.router.js
@@ -16,6 +16,10 @@
*
*/
+function routerGetSearchParams() {
+ return "";
+}
+
function afterLoadRouterJSP() {
}
diff --git a/ui/scripts/cloud.core.serviceoffering.js b/ui/scripts/cloud.core.serviceoffering.js
index 3ca96cec9fd..3ff69220fc7 100644
--- a/ui/scripts/cloud.core.serviceoffering.js
+++ b/ui/scripts/cloud.core.serviceoffering.js
@@ -16,6 +16,10 @@
*
*/
+function serviceOfferingGetSearchParams() {
+ return "";
+}
+
function afterLoadServiceOfferingJSP() {
var $detailsTab = $("#right_panel_content #tab_content_details");
diff --git a/ui/scripts/cloud.core.snapshot.js b/ui/scripts/cloud.core.snapshot.js
index 154bc448674..1d214c11bdc 100644
--- a/ui/scripts/cloud.core.snapshot.js
+++ b/ui/scripts/cloud.core.snapshot.js
@@ -16,6 +16,10 @@
*
*/
+function snapshotGetSearchParams() {
+ return "";
+}
+
function afterLoadSnapshotJSP() {
//initialize dialog
initDialog("dialog_add_volume_from_snapshot");
diff --git a/ui/scripts/cloud.core.systemvm.js b/ui/scripts/cloud.core.systemvm.js
index ed72781c636..298687e9118 100644
--- a/ui/scripts/cloud.core.systemvm.js
+++ b/ui/scripts/cloud.core.systemvm.js
@@ -16,6 +16,10 @@
*
*/
+ function systemVmGetSearchParams() {
+ return "";
+ }
+
function afterLoadSystemVmJSP($midmenuItem1) {
//hideMiddleMenu();
//systemvmToRightPanel($midmenuItem1);
diff --git a/ui/scripts/cloud.core.template.js b/ui/scripts/cloud.core.template.js
index 733612e6992..5de25803486 100644
--- a/ui/scripts/cloud.core.template.js
+++ b/ui/scripts/cloud.core.template.js
@@ -21,6 +21,10 @@
var g_zoneIds = [];
var g_zoneNames = [];
+function templateGetSearchParams() {
+ return "";
+}
+
function afterLoadTemplateJSP() {
var $detailsTab = $("#right_panel_content #tab_content_details");
diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js
index 2219529c402..96c458fd744 100644
--- a/ui/scripts/cloud.core.volume.js
+++ b/ui/scripts/cloud.core.volume.js
@@ -16,6 +16,10 @@
*
*/
+function volumeGetSearchParams() {
+ return "";
+}
+
function afterLoadVolumeJSP() {
initDialog("dialog_create_template", 400);
initDialog("dialog_create_snapshot");
From 9d33c2a63e7c5c5de25b2a00eb9e1468350d5f04 Mon Sep 17 00:00:00 2001
From: Jessica Wang
Date: Wed, 1 Dec 2010 15:39:25 -0800
Subject: [PATCH 11/32] instance page - implement basic search
---
ui/index.jsp | 4 ++--
ui/scripts/cloud.core.init.js | 12 +++++++++++
ui/scripts/cloud.core.instance.js | 35 +++++++++++++++++++++++++++++--
3 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/ui/index.jsp b/ui/index.jsp
index de626da15e2..2b9da0ab4f1 100644
--- a/ui/index.jsp
+++ b/ui/index.jsp
@@ -138,8 +138,8 @@
+
+
+
International
+
+
+
+ - English
+ - 汉语
+ - Français
+
+
+
+
From 0b76c26ce971cb1196c520d76ea4c785c6cd915c Mon Sep 17 00:00:00 2001
From: kishan
Date: Thu, 2 Dec 2010 14:11:02 +0530
Subject: [PATCH 31/32] bug 7216: show capacity alerts at pod level instead of
zone status 7216: resolved fixed
---
.../src/com/cloud/alert/AlertManagerImpl.java | 28 +++++++++++++------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java
index 71767e63c32..c15c9f457c2 100644
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@ -382,9 +382,16 @@ public class AlertManagerImpl implements AlertManager {
Map> capacityDcTypeMap = new HashMap>();
for (CapacityVO capacity : capacityList) {
- long dataCenterId = capacity.getDataCenterId();
+ long dataCenterId = capacity.getDataCenterId();
+ long podId = capacity.getPodId();
short type = capacity.getCapacityType();
- String key = "dc" + dataCenterId + "t" + type;
+ String key = null;
+ if((type == CapacityVO.CAPACITY_TYPE_PUBLIC_IP) || (type == CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE)){
+ key = "dc" + dataCenterId + "t" + type;
+ } else {
+ key = "pod" + podId + "t" + type;
+ }
+
List list = capacityDcTypeMap.get(key);
if (list == null) {
list = new ArrayList();
@@ -399,7 +406,8 @@ public class AlertManagerImpl implements AlertManager {
double usedCapacity = 0d;
CapacityVO cap = capacities.get(0);
short capacityType = cap.getCapacityType();
- long dataCenterId = cap.getDataCenterId();
+ long dataCenterId = cap.getDataCenterId();
+ long podId = cap.getPodId();
for (CapacityVO capacity : capacities) {
totalCapacity += capacity.getTotalCapacity();
@@ -409,7 +417,9 @@ public class AlertManagerImpl implements AlertManager {
double capacityPct = (usedCapacity / totalCapacity);
double thresholdLimit = 1.0;
DataCenterVO dcVO = _dcDao.findById(dataCenterId);
- String dcName = ((dcVO == null) ? "unknown" : dcVO.getName());
+ String dcName = ((dcVO == null) ? "unknown" : dcVO.getName());
+ HostPodVO pod = _podDao.findById(podId);
+ String podName = ((pod == null) ? "unknown" : pod.getName());
String msgSubject = "";
String msgContent = "";
String totalStr = "";
@@ -420,28 +430,28 @@ public class AlertManagerImpl implements AlertManager {
switch (capacityType) {
case CapacityVO.CAPACITY_TYPE_MEMORY:
thresholdLimit = _memoryCapacityThreshold;
- msgSubject = "System Alert: Low Available Memory in availablity zone " + dcName;
+ msgSubject = "System Alert: Low Available Memory in pod "+podName+" of availablity zone " + dcName;
totalStr = formatBytesToMegabytes(totalCapacity);
usedStr = formatBytesToMegabytes(usedCapacity);
msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
break;
case CapacityVO.CAPACITY_TYPE_CPU:
thresholdLimit = _cpuCapacityThreshold;
- msgSubject = "System Alert: Low Unallocated CPU in availablity zone " + dcName;
+ msgSubject = "System Alert: Low Unallocated CPU in pod "+podName+" of availablity zone " + dcName;
totalStr = _dfWhole.format(totalCapacity);
usedStr = _dfWhole.format(usedCapacity);
msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)";
break;
case CapacityVO.CAPACITY_TYPE_STORAGE:
thresholdLimit = _storageCapacityThreshold;
- msgSubject = "System Alert: Low Available Storage in availablity zone " + dcName;
+ msgSubject = "System Alert: Low Available Storage in pod "+podName+" of availablity zone " + dcName;
totalStr = formatBytesToMegabytes(totalCapacity);
usedStr = formatBytesToMegabytes(usedCapacity);
msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
break;
case CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED:
thresholdLimit = _storageAllocCapacityThreshold;
- msgSubject = "System Alert: Remaining unallocated Storage is low in availablity zone " + dcName;
+ msgSubject = "System Alert: Remaining unallocated Storage is low in pod "+podName+" of availablity zone " + dcName;
totalStr = formatBytesToMegabytes(totalCapacity);
usedStr = formatBytesToMegabytes(usedCapacity);
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
@@ -455,7 +465,7 @@ public class AlertManagerImpl implements AlertManager {
break;
case CapacityVO.CAPACITY_TYPE_PRIVATE_IP:
thresholdLimit = _privateIPCapacityThreshold;
- msgSubject = "System Alert: Number of unallocated private IPs is low in availablity zone " + dcName;
+ msgSubject = "System Alert: Number of unallocated private IPs is low in pod "+podName+" of availablity zone " + dcName;
totalStr = Double.toString(totalCapacity);
usedStr = Double.toString(usedCapacity);
msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
From 794c83f0113f7e9ac717bf3663cd312cc5dac917 Mon Sep 17 00:00:00 2001
From: kishan
Date: Thu, 2 Dec 2010 15:20:05 +0530
Subject: [PATCH 32/32] bug 7216: show capacity alerts at pod level instead of
zone status 7216: resolved fixed
---
server/src/com/cloud/alert/AlertManagerImpl.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java
index c15c9f457c2..0261d12a9a9 100644
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@ -383,7 +383,7 @@ public class AlertManagerImpl implements AlertManager {
for (CapacityVO capacity : capacityList) {
long dataCenterId = capacity.getDataCenterId();
- long podId = capacity.getPodId();
+ Long podId = capacity.getPodId();
short type = capacity.getCapacityType();
String key = null;
if((type == CapacityVO.CAPACITY_TYPE_PUBLIC_IP) || (type == CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE)){
@@ -407,7 +407,7 @@ public class AlertManagerImpl implements AlertManager {
CapacityVO cap = capacities.get(0);
short capacityType = cap.getCapacityType();
long dataCenterId = cap.getDataCenterId();
- long podId = cap.getPodId();
+ Long podId = cap.getPodId();
for (CapacityVO capacity : capacities) {
totalCapacity += capacity.getTotalCapacity();
@@ -418,8 +418,11 @@ public class AlertManagerImpl implements AlertManager {
double thresholdLimit = 1.0;
DataCenterVO dcVO = _dcDao.findById(dataCenterId);
String dcName = ((dcVO == null) ? "unknown" : dcVO.getName());
- HostPodVO pod = _podDao.findById(podId);
- String podName = ((pod == null) ? "unknown" : pod.getName());
+ String podName = "";
+ if( podId != null){
+ HostPodVO pod = _podDao.findById(podId);
+ podName = ((pod == null) ? "unknown" : pod.getName());
+ }
String msgSubject = "";
String msgContent = "";
String totalStr = "";