From 0ea1f370b8336b78db27c1661395097eabfa7c9f Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 7 Sep 2010 11:08:38 -0700 Subject: [PATCH 1/8] bug 5147: Adding the check to block create and destroy of system resources whilst the storage pool is in maintenance mode. This is based on checking if the pool is in UP state --- .../storage/allocator/AbstractStoragePoolAllocator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java index e0ae7a9e756..d29e51d11cf 100644 --- a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java +++ b/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java @@ -142,7 +142,12 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement return false; } - + //if pool is NOT in up state, return false + if(!pool.getStatus().equals(com.cloud.host.Status.Up))//this is the pool status + { + return false; + } + // Check that the pool type is correct if (!poolIsCorrectType(dskCh, pool, vm, offering)) { return false; From 1a824bd19594676094ef6900fc6fb9ed6f1a5a63 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 7 Sep 2010 11:25:06 -0700 Subject: [PATCH 2/8] 1) Use transactions instead of global lock in AlertManagerImpl, StatsCollector. 2) Removed GlobalLock on read available capacity from UserConcentratedAllocator --- .../impl/UserConcentratedAllocator.java | 35 ++++---------- .../src/com/cloud/alert/AlertManagerImpl.java | 41 ++++++++--------- .../src/com/cloud/server/StatsCollector.java | 46 ++++++++----------- 3 files changed, 47 insertions(+), 75 deletions(-) diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index cab971738e1..ba612b71fc2 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -37,7 +37,6 @@ import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.dao.HostPodDao; import com.cloud.offering.NetworkOffering; -import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; @@ -50,7 +49,6 @@ import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.Inject; -import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.SearchCriteria; import com.cloud.vm.State; import com.cloud.vm.UserVmVO; @@ -76,7 +74,6 @@ public class UserConcentratedAllocator implements PodAllocator { @Inject VMInstanceDao _vmInstanceDao; Random _rand = new Random(System.currentTimeMillis()); - private final GlobalLock m_capacityCheckLock = GlobalLock.getInternLock("capacity.check"); private int _hoursToSkipStoppedVMs = 24; private int _secStorageVmRamSize = 1024; @@ -156,30 +153,14 @@ public class UserConcentratedAllocator implements PodAllocator { private boolean dataCenterAndPodHasEnoughCapacity(long dataCenterId, long podId, long capacityNeeded, short capacityType, long[] hostCandidate) { List capacities = null; - if (m_capacityCheckLock.lock(120)) { // 2 minutes - try { - SearchCriteria sc = _capacityDao.createSearchCriteria(); - sc.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType); - sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId); - sc.addAnd("podId", SearchCriteria.Op.EQ, podId); - capacities = _capacityDao.search(sc, null); - } finally { - m_capacityCheckLock.unlock(); - } - } else { - s_logger.error("Unable to acquire synchronization lock for pod allocation"); - - // we now try to enforce reservation-style allocation, waiting time has been adjusted - // to 2 minutes - return false; - -/* - // If we can't lock the table, just return that there is enough capacity and allow instance creation to fail on the agent - // if there is not enough capacity. All that does is skip the optimization of checking for capacity before sending the - // command to the agent. - return true; -*/ - } + + SearchCriteria sc = _capacityDao.createSearchCriteria(); + sc.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType); + sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId); + sc.addAnd("podId", SearchCriteria.Op.EQ, podId); + s_logger.trace("Executing search"); + capacities = _capacityDao.search(sc, null); + s_logger.trace("Done with a search"); boolean enoughCapacity = false; if (capacities != null) { diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 033b1ba3282..9250bb86557 100644 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -65,8 +65,9 @@ import com.cloud.storage.dao.VolumeDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.db.GlobalLock; +import com.cloud.utils.db.DB; import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.SecondaryStorageVmVO; @@ -118,8 +119,6 @@ public class AlertManagerImpl implements AlertManager { private double _publicIPCapacityThreshold = 0.75; private double _privateIPCapacityThreshold = 0.75; - private final GlobalLock m_capacityCheckLock = GlobalLock.getInternLock("capacity.check"); - @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; @@ -319,7 +318,7 @@ public class AlertManagerImpl implements AlertManager { } } - @Override + @Override @DB public void recalculateCapacity() { // FIXME: the right way to do this is to register a listener (see RouterStatsListener, VMSyncListener) // for the vm sync state. The listener model has connects/disconnects to keep things in sync much better @@ -435,25 +434,23 @@ public class AlertManagerImpl implements AlertManager { newCapacities.add(newPrivateIPCapacity); } - if (m_capacityCheckLock.lock(5)) { // 5 second timeout - try { - // delete the old records - _capacityDao.clearNonStorageCapacities(); + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + // delete the old records + _capacityDao.clearNonStorageCapacities(); - for (CapacityVO newCapacity : newCapacities) { - _capacityDao.persist(newCapacity); - } - } finally { - m_capacityCheckLock.unlock(); - } - - if (s_logger.isTraceEnabled()) { - s_logger.trace("done recalculating system capacity"); - } - } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Skipping capacity check, unable to lock the capacity table for recalculation."); - } + for (CapacityVO newCapacity : newCapacities) { + s_logger.trace("Executing capacity update"); + _capacityDao.persist(newCapacity); + s_logger.trace("Done with capacity update"); + } + txn.commit(); + } catch (Exception ex) { + txn.rollback(); + s_logger.error("Unable to start transaction for capacity update"); + }finally { + txn.close(); } } diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java index 58cfe27cdf8..668d4674171 100644 --- a/server/src/com/cloud/server/StatsCollector.java +++ b/server/src/com/cloud/server/StatsCollector.java @@ -61,6 +61,7 @@ import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; import com.cloud.vm.UserVmManager; import com.cloud.vm.UserVmVO; import com.cloud.vm.VmStats; @@ -99,7 +100,7 @@ public class StatsCollector { long storageStatsInterval = -1L; long volumeStatsInterval = -1L; - private final GlobalLock m_capacityCheckLock = GlobalLock.getInternLock("capacity.check"); + //private final GlobalLock m_capacityCheckLock = GlobalLock.getInternLock("capacity.check"); public static StatsCollector getInstance() { return s_instance; @@ -335,32 +336,25 @@ public class StatsCollector { // _capacityDao.persist(capacity); } - if (m_capacityCheckLock.lock(5)) { // 5 second timeout - if (s_logger.isTraceEnabled()) { - s_logger.trace("recalculating system storage capacity"); - } - try { - // now update the capacity table with the new stats - // FIXME: the right way to do this is to register a listener (see RouterStatsListener) - // for the host stats, send the WatchCommand at a regular interval - // to collect the stats from an agent and update the database as needed. The - // listener model has connects/disconnects to keep things in sync much better - // than this model right now - _capacityDao.clearStorageCapacities(); + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + if (s_logger.isTraceEnabled()) { + s_logger.trace("recalculating system storage capacity"); + } + txn.start(); + _capacityDao.clearStorageCapacities(); - for (CapacityVO newCapacity : newCapacities) { - _capacityDao.persist(newCapacity); - } - } finally { - m_capacityCheckLock.unlock(); - } - if (s_logger.isTraceEnabled()) { - s_logger.trace("done recalculating system storage capacity"); - } - } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("not recalculating system storage capacity, unable to lock capacity table"); - } + for (CapacityVO newCapacity : newCapacities) { + s_logger.trace("Executing capacity update"); + _capacityDao.persist(newCapacity); + s_logger.trace("Done with capacity update"); + } + txn.commit(); + } catch (Exception ex) { + txn.rollback(); + s_logger.error("Unable to start transaction for storage capacity update"); + }finally { + txn.close(); } } catch (Throwable t) { s_logger.error("Error trying to retrieve storage stats", t); From 5aa70deae776d0b71ff026bfdc509a98638d0374 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Sep 2010 11:24:46 -0700 Subject: [PATCH 3/8] new UI - add a shared function fromdb() --- ui/new/scripts/cloud.core.account.js | 4 ++-- ui/new/scripts/cloud.core.event.js | 6 +++--- ui/new/scripts/cloud.core.instance.js | 16 ++++++++-------- ui/new/scripts/cloud.core.js | 14 +++++++++++--- ui/new/scripts/cloud.core.snapshot.js | 8 ++++---- ui/new/scripts/cloud.core.volume.js | 10 +++++----- 6 files changed, 33 insertions(+), 25 deletions(-) diff --git a/ui/new/scripts/cloud.core.account.js b/ui/new/scripts/cloud.core.account.js index ed4475d3af1..6438c247731 100644 --- a/ui/new/scripts/cloud.core.account.js +++ b/ui/new/scripts/cloud.core.account.js @@ -2,8 +2,8 @@ function loadAccountToRigntPanelFn($rightPanelContent) { var jsonObj = $rightPanelContent.data("jsonObj"); var $rightPanelContent = $("#right_panel_content"); $rightPanelContent.find("#role").text(toRole(jsonObj.accounttype)); - $rightPanelContent.find("#account").text(jsonObj.name); - $rightPanelContent.find("#domain").text(jsonObj.domain); + $rightPanelContent.find("#account").text(fromdb(jsonObj.name)); + $rightPanelContent.find("#domain").text(fromdb(jsonObj.domain)); $rightPanelContent.find("#vm_total").text(jsonObj.vmtotal); $rightPanelContent.find("#ip_total").text(jsonObj.iptotal); $rightPanelContent.find("#bytes_received").text(jsonObj.receivedbytes); diff --git a/ui/new/scripts/cloud.core.event.js b/ui/new/scripts/cloud.core.event.js index ca70c3b3096..72c54960e9c 100644 --- a/ui/new/scripts/cloud.core.event.js +++ b/ui/new/scripts/cloud.core.event.js @@ -1,11 +1,11 @@ function loadEventToRigntPanelFn($rightPanelContent) { var jsonObj = $rightPanelContent.data("jsonObj"); var $rightPanelContent = $("#right_panel_content"); - $rightPanelContent.find("#username").text(jsonObj.username); - $rightPanelContent.find("#account").text(jsonObj.account); + $rightPanelContent.find("#username").text(fromdb(jsonObj.username)); + $rightPanelContent.find("#account").text(fromdb(jsonObj.account)); $rightPanelContent.find("#type").text(jsonObj.type); $rightPanelContent.find("#level").text(jsonObj.level); - $rightPanelContent.find("#description").text(jsonObj.description); + $rightPanelContent.find("#description").text(fromdb(jsonObj.description)); $rightPanelContent.find("#state").text(jsonObj.state); setDateField(jsonObj.created, $rightPanelContent.find("#created")); } \ No newline at end of file diff --git a/ui/new/scripts/cloud.core.instance.js b/ui/new/scripts/cloud.core.instance.js index 78ce2d97683..d44eb6bf51d 100755 --- a/ui/new/scripts/cloud.core.instance.js +++ b/ui/new/scripts/cloud.core.instance.js @@ -384,21 +384,21 @@ function clickInstanceGroupHeader($arrowIcon) { var jsonObj = $t.data("jsonObj"); var vmName = getVmName(jsonObj.name, jsonObj.displayname); - $rightPanelHeader.find("#vm_name").text(vmName); + $rightPanelHeader.find("#vm_name").text(fromdb(vmName)); updateVirtualMachineStateInRightPanel(jsonObj.state); $rightPanelContent.find("#ipAddress").text(jsonObj.ipaddress); - $rightPanelContent.find("#zoneName").text(jsonObj.zonename); - $rightPanelContent.find("#templateName").text(jsonObj.templatename); - $rightPanelContent.find("#serviceOfferingName").text(jsonObj.serviceofferingname); + $rightPanelContent.find("#zoneName").text(fromdb(jsonObj.zonename)); + $rightPanelContent.find("#templateName").text(fromdb(jsonObj.templatename)); + $rightPanelContent.find("#serviceOfferingName").text(fromdb(jsonObj.serviceofferingname)); if(jsonObj.haenable == "true") $rightPanelContent.find("#ha").removeClass("cross_icon").addClass("tick_icon").show(); else $rightPanelContent.find("#ha").removeClass("tick_icon").addClass("cross_icon").show(); $rightPanelContent.find("#created").text(jsonObj.created); - $rightPanelContent.find("#account").text(jsonObj.account); - $rightPanelContent.find("#domain").text(jsonObj.domain); - $rightPanelContent.find("#hostName").text(jsonObj.hostname); - $rightPanelContent.find("#group").text(jsonObj.group); + $rightPanelContent.find("#account").text(fromdb(jsonObj.account)); + $rightPanelContent.find("#domain").text(fromdb(jsonObj.domain)); + $rightPanelContent.find("#hostName").text(fromdb(jsonObj.hostname)); + $rightPanelContent.find("#group").text(fromdb(jsonObj.group)); if(jsonObj.isoid != null && jsonObj.isoid.length > 0) $rightPanelContent.find("#iso").removeClass("cross_icon").addClass("tick_icon").show(); else diff --git a/ui/new/scripts/cloud.core.js b/ui/new/scripts/cloud.core.js index d65d01b054a..c563805529c 100755 --- a/ui/new/scripts/cloud.core.js +++ b/ui/new/scripts/cloud.core.js @@ -165,6 +165,14 @@ function createURL(url) { return url +"&response=json&sessionkey=" + g_sessionKey; } +function fromdb(val) { + return sanitizeXSS(unescape(noNull(val))); +} + +function todb(val) { + return encodeURIComponent(escape(display)); +} + @@ -790,16 +798,16 @@ function sanitizeXSS(val) { function getVmName(p_vmName, p_vmDisplayname) { if(p_vmDisplayname == null) - return sanitizeXSS(p_vmName); + return sanitizeXSS(unescape(p_vmName)); var vmName = null; if (isAdmin()) { if (p_vmDisplayname != p_vmName) { - vmName = p_vmName + "(" + sanitizeXSS(p_vmDisplayname) + ")"; + vmName = p_vmName + "(" + sanitizeXSS(unescape(p_vmDisplayname)) + ")"; } else { vmName = p_vmName; } } else { - vmName = sanitizeXSS(p_vmDisplayname); + vmName = sanitizeXSS(unescape(p_vmDisplayname)); } return vmName; } diff --git a/ui/new/scripts/cloud.core.snapshot.js b/ui/new/scripts/cloud.core.snapshot.js index 279d38b0d95..c54a63d3b53 100644 --- a/ui/new/scripts/cloud.core.snapshot.js +++ b/ui/new/scripts/cloud.core.snapshot.js @@ -4,11 +4,11 @@ function loadSnapshotToRigntPanelFn($rightPanelContent) { var $rightPanelContent = $("#right_panel_content"); $rightPanelContent.find("#id").text(jsonObj.id); - $rightPanelContent.find("#name").text(jsonObj.name); - $rightPanelContent.find("#volume_name").text(jsonObj.volumename); + $rightPanelContent.find("#name").text(fromdb(jsonObj.name)); + $rightPanelContent.find("#volume_name").text(fromdb(jsonObj.volumename)); $rightPanelContent.find("#interval_type").text(jsonObj.intervaltype); - $rightPanelContent.find("#account").text(jsonObj.account); - $rightPanelContent.find("#domain").text(jsonObj.domain); + $rightPanelContent.find("#account").text(fromdb(jsonObj.account)); + $rightPanelContent.find("#domain").text(fromdb(jsonObj.domain)); setDateField(jsonObj.created, $rightPanelContent.find("#created")); } \ No newline at end of file diff --git a/ui/new/scripts/cloud.core.volume.js b/ui/new/scripts/cloud.core.volume.js index 1a5493427af..7324d6d3d04 100644 --- a/ui/new/scripts/cloud.core.volume.js +++ b/ui/new/scripts/cloud.core.volume.js @@ -4,14 +4,14 @@ function loadVolumeToRigntPanelFn($rightPanelContent) { var $rightPanelContent = $("#right_panel_content"); $rightPanelContent.find("#id").text(jsonObj.id); - $rightPanelContent.find("#name").text(jsonObj.name); - $rightPanelContent.find("#zonename").text(jsonObj.zonename); + $rightPanelContent.find("#name").text(fromdb(jsonObj.name)); + $rightPanelContent.find("#zonename").text(fromdb(jsonObj.zonename)); $rightPanelContent.find("#device_id").text(jsonObj.deviceid); $rightPanelContent.find("#state").text(jsonObj.state); - $rightPanelContent.find("#storage").text(jsonObj.storage); - $rightPanelContent.find("#account").text(jsonObj.account); + $rightPanelContent.find("#storage").text(fromdb(jsonObj.storage)); + $rightPanelContent.find("#account").text(fromdb(jsonObj.account)); - $rightPanelContent.find("#type").text(noNull(jsonObj.type) + " (" + noNull(jsonObj.storagetype) + " storage)"); + $rightPanelContent.find("#type").text(jsonObj.type + " (" + jsonObj.storagetype + " storage)"); $rightPanelContent.find("#size").text((jsonObj.size == "0") ? "" : convertBytes(jsonObj.size)); if (jsonObj.virtualmachineid == null) From 2b590dbc5d3c6437107b4ade0a98361bdeb06b0d Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 7 Sep 2010 11:30:16 -0700 Subject: [PATCH 4/8] bug 5147: Now, we restart the system vms immediately on another pool after a successful stop on the current pool, if such a reserve pool exists --- .../com/cloud/storage/StorageManagerImpl.java | 60 ++++++++----------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index f6d9aa72de0..de19c3ba8f6 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1963,8 +1963,6 @@ public class StorageManagerImpl implements StorageManager { { boolean destroyVolumes = false; long count = 1; - long consoleProxyId = 0; - long ssvmId = 0; try { //1. Get the primary storage record @@ -2023,9 +2021,20 @@ public class StorageManagerImpl implements StorageManager { { if(destroyVolumes) { - //proxy vm is stopped, and we have another ps available - //get the id for restart - consoleProxyId = vmInstance.getId(); + //create a dummy event + long eventId1 = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting console proxy with Id: "+vmInstance.getId()); + + //Restore config val for consoleproxy.restart to true + _configMgr.updateConfiguration(userId, "consoleproxy.restart", "true"); + + if(_consoleProxyMgr.startProxy(vmInstance.getId(), eventId1)==null) + { + s_logger.warn("There was an error starting the console proxy id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance"); + primaryStorage.setStatus(Status.ErrorInMaintenance); + _storagePoolDao.persist(primaryStorage); + return false; + } + } } } @@ -2064,9 +2073,15 @@ public class StorageManagerImpl implements StorageManager { { if(destroyVolumes) { - //ss vm is stopped, and we have another ps available - //get the id for restart - ssvmId = vmInstance.getId(); + //create a dummy event and restart the ssvm immediately + long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "starting ssvm with Id: "+vmInstance.getId()); + if(_secStorageMgr.startSecStorageVm(vmInstance.getId(), eventId)==null) + { + s_logger.warn("There was an error starting the ssvm id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance"); + primaryStorage.setStatus(Status.ErrorInMaintenance); + _storagePoolDao.persist(primaryStorage); + return false; + } } } @@ -2100,34 +2115,7 @@ public class StorageManagerImpl implements StorageManager { _volsDao.remove(vol.getId()); } - //5. Restart all the system vms conditionally - if(destroyVolumes) //this means we have another ps. Ok to restart - { - //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "starting ssvm with Id: "+ssvmId); - if(_secStorageMgr.startSecStorageVm(ssvmId, eventId)==null) - { - s_logger.warn("There was an error starting the ssvm id: "+ssvmId+" on another storage pool, cannot enable primary storage maintenance"); - primaryStorage.setStatus(Status.ErrorInMaintenance); - _storagePoolDao.persist(primaryStorage); - return false; - } - - //create a dummy event - long eventId1 = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting console proxy with Id: "+consoleProxyId); - - //Restore config val for consoleproxy.restart to true - _configMgr.updateConfiguration(userId, "consoleproxy.restart", "true"); - - if(_consoleProxyMgr.startProxy(consoleProxyId, eventId1)==null) - { - s_logger.warn("There was an error starting the console proxy id: "+consoleProxyId+" on another storage pool, cannot enable primary storage maintenance"); - primaryStorage.setStatus(Status.ErrorInMaintenance); - _storagePoolDao.persist(primaryStorage); - return false; } - } - - //6. Update the status + //5. Update the status primaryStorage.setStatus(Status.Maintenance); _storagePoolDao.persist(primaryStorage); From afc181dd82317ea86c9e399b4e7b0fc6e89d5e77 Mon Sep 17 00:00:00 2001 From: abhishek Date: Tue, 7 Sep 2010 11:50:04 -0700 Subject: [PATCH 5/8] some code cleanup --- server/src/com/cloud/storage/StorageManagerImpl.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index de19c3ba8f6..552e13c1d44 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -19,11 +19,7 @@ package com.cloud.storage; import java.net.URI; import java.net.UnknownHostException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.Enumeration; @@ -33,7 +29,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -94,9 +89,9 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; -import com.cloud.host.Host.Type; import com.cloud.host.HostVO; import com.cloud.host.Status; +import com.cloud.host.Host.Type; import com.cloud.host.dao.DetailsDao; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor; @@ -127,12 +122,9 @@ import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.AccountVO; import com.cloud.user.User; -import com.cloud.user.UserContext; -import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.uservm.UserVm; -import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapters; From 673ed9821390cd99681f5dd87dbbefbf6ad247a8 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Sep 2010 11:46:15 -0700 Subject: [PATCH 6/8] new UI - use new shared function todb() to escape and encode parameters in API command. --- ui/new/scripts/cloud.core.instance.js | 38 +++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ui/new/scripts/cloud.core.instance.js b/ui/new/scripts/cloud.core.instance.js index d44eb6bf51d..11ecdce7749 100755 --- a/ui/new/scripts/cloud.core.instance.js +++ b/ui/new/scripts/cloud.core.instance.js @@ -108,7 +108,7 @@ function clickInstanceGroupHeader($arrowIcon) { if (isos != null && isos.length > 0) { isoSelect.empty(); for (var i = 0; i < isos.length; i++) { - isoSelect.append("");; + isoSelect.append("");; } } } @@ -196,7 +196,7 @@ function clickInstanceGroupHeader($arrowIcon) { var name = trim(thisDialog.find("#change_instance_name").val()); for(var id in selectedItemIds) { - var apiCommand = "command=updateVirtualMachine&id="+id+"&displayName="+encodeURIComponent(escape(name)); + var apiCommand = "command=updateVirtualMachine&id="+id+"&displayName="+todb(name); doAction(id, $t, apiCommand, listAPIMap); } }, @@ -217,7 +217,7 @@ function clickInstanceGroupHeader($arrowIcon) { if (offerings != null && offerings.length > 0) { for (var i = 0; i < offerings.length; i++) { - var option = $("").data("name", sanitizeXSS(unescape(offerings[i].name))); + var option = $("").data("name", fromdb(offerings[i].name)); offeringSelect.append(option); } } @@ -264,7 +264,7 @@ function clickInstanceGroupHeader($arrowIcon) { var $midMenuItem = selectedItemIds[id]; var jsonObj = $midMenuItem.data("jsonObj"); var group = trim(thisDialog.find("#change_group_name").val()); - var apiCommand = "command=updateVirtualMachine&id="+id+"&group="+encodeURIComponent(group); + var apiCommand = "command=updateVirtualMachine&id="+id+"&group="+todb(group); doAction(id, $t, apiCommand, listAPIMap); } }, @@ -558,7 +558,7 @@ function clickInstanceGroupHeader($arrowIcon) { var $zoneSelect = $vmPopup.find("#wizard_zone").empty(); if (zones != null && zones.length > 0) { for (var i = 0; i < zones.length; i++) { - $zoneSelect.append(""); + $zoneSelect.append(""); } } listTemplatesInVmPopup(); @@ -582,15 +582,15 @@ function clickInstanceGroupHeader($arrowIcon) { var $t = $serviceOfferingTemplate.clone(); $t.find("input:radio[name=service_offering_radio]").val(offerings[i].id); - $t.find("#name").text(sanitizeXSS(unescape(offerings[i].name))); - $t.find("#description").text(sanitizeXSS(unescape(offerings[i].displaytext))); + $t.find("#name").text(fromdb(offerings[i].name)); + $t.find("#description").text(fromdb(offerings[i].displaytext)); if (i > 0) $t.find("input:radio[name=service_offering_radio]").removeAttr("checked"); //if(i == 0) // $t.find("input:radio[name=service_offering_radio]").attr("checked", true); - //var listItem = $("
  • "); + //var listItem = $("
  • "); $container.append($t.show()); } //Safari and Chrome are not smart enough to make checkbox checked if html markup is appended by JQuery.append(). So, the following 2 lines are added. @@ -628,8 +628,8 @@ function clickInstanceGroupHeader($arrowIcon) { for (var i = 0; i < offerings.length; i++) { var $t = $existingDiskOfferingTemplate.clone(); $t.find("input:radio").attr("name","data_disk_offering_radio").val(offerings[i].id).removeAttr("checked"); - $t.find("#name").text(sanitizeXSS(unescape(noNull(offerings[i].name)))); - $t.find("#description").text(sanitizeXSS(noNull(unescape(offerings[i].displaytext)))); + $t.find("#name").text(fromdb(noNull(offerings[i].name))); + $t.find("#description").text(fromdb(offerings[i].displaytext)); $dataDiskOfferingContainer.append($t.show()); } } @@ -655,8 +655,8 @@ function clickInstanceGroupHeader($arrowIcon) { $t.find("input:radio").attr("name","root_disk_offering_radio").val(offerings[i].id); if(i > 0) //default is the 1st existing disk offering. If there is no existing disk offering, default to "custom" radio button $t.find("input:radio").removeAttr("checked"); - $t.find("#name").text(sanitizeXSS(unescape(noNull(offerings[i].name)))); - $t.find("#description").text(sanitizeXSS(noNull(unescape(offerings[i].displaytext)))); + $t.find("#name").text(fromdb(offerings[i].name)); + $t.find("#description").text(fromdb(offerings[i].displaytext)); $rootDiskOfferingContainer.append($t.show()); } } @@ -684,14 +684,14 @@ function clickInstanceGroupHeader($arrowIcon) { var html = "
  • " +"" - +"" + +"" +"
  • "; $("#wizard_root_disk_offering").append(html); var html2 = "
  • " +"" - +"" + +"" +"
  • "; $("#wizard_data_disk_offering").append(html2); } @@ -843,8 +843,8 @@ function clickInstanceGroupHeader($arrowIcon) { var html = '
    ' +'
    ' - +'
    '+sanitizeXSS(items[i].displaytext)+'
    ' - +'
    '+sanitizeXSS(items[i].account)+'
    ' + +'
    '+fromdb(items[i].displaytext)+'
    ' + +'
    '+fromdb(items[i].account)+'
    ' +'
    '; container.append(html); } @@ -1067,11 +1067,11 @@ function clickInstanceGroupHeader($arrowIcon) { var name = trim($thisPopup.find("#wizard_vm_name").val()); if (name != null && name.length > 0) - moreCriteria.push("&displayname="+encodeURIComponent(name)); + moreCriteria.push("&displayname="+todb(name)); var group = trim($thisPopup.find("#wizard_vm_group").val()); if (group != null && group.length > 0) - moreCriteria.push("&group="+encodeURIComponent(group)); + moreCriteria.push("&group="+todb(group)); vmWizardClose(); @@ -1131,7 +1131,7 @@ function clickInstanceGroupHeader($arrowIcon) { // Failed $t.find("#vm_name").text("Adding failed"); $t.find("#info_icon").addClass("error").show(); - $t.data("afterActionInfo", ("Adding failed. Reason: " + sanitizeXSS(result.jobresult))); + $t.data("afterActionInfo", ("Adding failed. Reason: " + fromdb(result.jobresult))); $t.bind("click", function(event) { $rightPanelContent.find("#after_action_info").text($(this).data("afterActionInfo")); $rightPanelContent.find("#after_action_info_container").addClass("errorbox"); From 3bf19dcccbdc12f8886ddbe5417c98d934b86308 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Sep 2010 12:02:53 -0700 Subject: [PATCH 7/8] new UI - apply detail header text. --- ui/new/jsp/tab_account.jsp | 8 ++++++++ ui/new/jsp/tab_alert.jsp | 8 ++++++++ ui/new/jsp/tab_event.jsp | 8 ++++++++ ui/new/jsp/tab_instance.jsp | 2 +- ui/new/jsp/tab_snapshot.jsp | 8 ++++++++ ui/new/jsp/tab_volume.jsp | 8 ++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ui/new/jsp/tab_account.jsp b/ui/new/jsp/tab_account.jsp index a4b8c117648..c64d2ae9301 100644 --- a/ui/new/jsp/tab_account.jsp +++ b/ui/new/jsp/tab_account.jsp @@ -12,6 +12,14 @@ %> +
    + +

    Account +

    +