diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index f43f5a5be74..64c868412e3 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -17,6 +17,8 @@ */ package com.cloud.storage; +import java.util.Date; + import com.cloud.domain.PartOf; import com.cloud.template.BasedOn; import com.cloud.user.OwnedBy; @@ -86,4 +88,8 @@ public interface Volume extends PartOf, OwnedBy, BasedOn { void setSourceId(Long sourceId); Long getSourceId(); + + Date getAttached(); + + void setAttached(Date attached); } diff --git a/core/src/com/cloud/agent/api/storage/CreateCommand.java b/core/src/com/cloud/agent/api/storage/CreateCommand.java index ab370027c8d..48e53748f1e 100644 --- a/core/src/com/cloud/agent/api/storage/CreateCommand.java +++ b/core/src/com/cloud/agent/api/storage/CreateCommand.java @@ -64,7 +64,7 @@ public class CreateCommand extends Command { this.pool = new StoragePoolTO(pool); this.templateUrl = null; this.size = size; - this.instanceName = vm.getInstanceName(); + //this.instanceName = vm.getInstanceName(); } @Override diff --git a/core/src/com/cloud/storage/VolumeVO.java b/core/src/com/cloud/storage/VolumeVO.java index 48ccc908c99..6e342aaa185 100755 --- a/core/src/com/cloud/storage/VolumeVO.java +++ b/core/src/com/cloud/storage/VolumeVO.java @@ -90,6 +90,10 @@ public class VolumeVO implements Volume { @Column(name="created") Date created; + @Column(name="attached") + @Temporal(value=TemporalType.TIMESTAMP) + Date attached; + @Column(name="data_center_id") long dataCenterId; @@ -535,4 +539,15 @@ public class VolumeVO implements Volume { public Long getSourceId(){ return this.sourceId; } + + @Override + public Date getAttached(){ + return this.attached; + } + + @Override + public void setAttached(Date attached){ + this.attached = attached; + } + } diff --git a/core/src/com/cloud/storage/dao/VolumeDaoImpl.java b/core/src/com/cloud/storage/dao/VolumeDaoImpl.java index 976c6445483..b9040983db2 100755 --- a/core/src/com/cloud/storage/dao/VolumeDaoImpl.java +++ b/core/src/com/cloud/storage/dao/VolumeDaoImpl.java @@ -234,6 +234,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol volume.setInstanceId(vmId); volume.setDeviceId(deviceId); volume.setUpdated(new Date()); + volume.setAttached(new Date()); update(volumeId, volume); } @@ -243,6 +244,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol volume.setInstanceId(null); volume.setDeviceId(null); volume.setUpdated(new Date()); + volume.setAttached(null); update(volumeId, volume); } diff --git a/server/src/com/cloud/api/BaseCmd.java b/server/src/com/cloud/api/BaseCmd.java index 4c630bd734c..90c2397f43a 100644 --- a/server/src/com/cloud/api/BaseCmd.java +++ b/server/src/com/cloud/api/BaseCmd.java @@ -153,6 +153,7 @@ public abstract class BaseCmd { CPU_ALLOCATED("cpuallocated", BaseCmd.TYPE_LONG, "cpuallocated"), CPU_USED("cpuused", BaseCmd.TYPE_LONG, "cpuused"), CREATED("created", BaseCmd.TYPE_DATE, "created"), + ATTACHED("attached", BaseCmd.TYPE_DATE, "attached"), CROSS_ZONES("crossZones", BaseCmd.TYPE_BOOLEAN, "crosszones"), DAILY_MAX("dailymax", BaseCmd.TYPE_INT, "dailyMax"), DATA_DISK_OFFERING_ID("datadiskofferingid", BaseCmd.TYPE_LONG, "dataDiskOfferingId"), diff --git a/server/src/com/cloud/api/commands/ListVolumesCmd.java b/server/src/com/cloud/api/commands/ListVolumesCmd.java index 85d93f39223..435c4bdeeba 100755 --- a/server/src/com/cloud/api/commands/ListVolumesCmd.java +++ b/server/src/com/cloud/api/commands/ListVolumesCmd.java @@ -194,6 +194,7 @@ public class ListVolumesCmd extends BaseCmd{ volumeData.add(new Pair(BaseCmd.Properties.SIZE.getName(), virtualSizeInBytes)); volumeData.add(new Pair(BaseCmd.Properties.CREATED.getName(), getDateString(volume.getCreated()))); + volumeData.add(new Pair(BaseCmd.Properties.ATTACHED.getName(), getDateString(volume.getAttached()))); volumeData.add(new Pair(BaseCmd.Properties.STATE.getName(),volume.getStatus())); Account accountTemp = getManagementServer().findAccountById(volume.getAccountId()); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 9449b043602..f6d9aa72de0 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -19,7 +19,11 @@ 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; @@ -29,6 +33,7 @@ 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; @@ -122,8 +127,12 @@ 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; @@ -188,6 +197,7 @@ public class StorageManagerImpl implements StorageManager { @Inject protected VMTemplateDao _templateDao; @Inject protected VMTemplateHostDao _templateHostDao; @Inject protected ServiceOfferingDao _offeringDao; + @Inject protected UserDao _userDao; protected SearchBuilder HostTemplateStatesSearch; protected SearchBuilder PoolsUsedByVmSearch; @@ -921,6 +931,17 @@ public class StorageManagerImpl implements StorageManager { } for (VolumeVO v : volumes) { + + //when the user vm is created, the volume is attached upon creation + //set the attached datetime + try{ + v.setAttached(new Date()); + _volsDao.update(v.getId(), v); + }catch(Exception e) + { + s_logger.warn("Error updating the attached value for volume "+v.getId()+":"+e); + } + long volumeId = v.getId(); // Create an event long sizeMB = v.getSize() / (1024 * 1024); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index e9dd4fecdb7..188b6e345a9 100644 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -251,6 +251,7 @@ CREATE TABLE `cloud`.`volumes` ( `recreatable` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this volume recreatable?', `destroyed` tinyint(1) COMMENT 'indicates whether the volume was destroyed by the user or not', `created` datetime COMMENT 'Date Created', + `attached` datetime COMMENT 'Date Attached', `updated` datetime COMMENT 'Date updated for attach/detach', `removed` datetime COMMENT 'Date removed. not null if removed', `status` varchar(32) COMMENT 'Async API volume creation status', diff --git a/setup/db/schema-21to22.sql b/setup/db/schema-21to22.sql index dff1e91ae52..ae3b3db4446 100644 --- a/setup/db/schema-21to22.sql +++ b/setup/db/schema-21to22.sql @@ -9,3 +9,4 @@ ALTER TABLE `cloud`.`resource_count` MODIFY COLUMN `account_id` bigint unsigned; ALTER TABLE `cloud`.`storage_pool` add COLUMN STATUS varchar(32) not null; -- new status column for maintenance mode support for primary storage ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_id` bigint unsigned; -- id for the source ALTER TABLE `cloud`.`volumes` ADD COLUMN `source_type` varchar(32); --source from which the volume is created i.e. snapshot, diskoffering, template, blank +ALTER TABLE `cloud`.`volumes` ADD COLUMN 'attached' datetime; --date and time the volume was attached