cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject [03/57] [abbrv] [partial] merge master
Date Mon, 13 May 2013 12:25:33 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VMTemplateStoragePoolVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VMTemplateStoragePoolVO.java b/engine/schema/src/com/cloud/storage/VMTemplateStoragePoolVO.java
new file mode 100644
index 0000000..9b76176
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VMTemplateStoragePoolVO.java
@@ -0,0 +1,275 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
+
+import com.cloud.utils.db.GenericDaoBase;
+
+/**
+ * Join table for storage pools and templates
+ *
+ */
+@Entity
+@Table(name="template_spool_ref")
+public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc, DataObjectInStore {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	long id;
+	
+	@Column(name="pool_id")
+	private long poolId;
+	
+	@Column(name="template_id") long templateId;
+	
+	@Column(name=GenericDaoBase.CREATED_COLUMN) Date created = null;
+	
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP) Date lastUpdated = null;
+	
+	@Column (name="download_pct") int downloadPercent;
+	
+	@Column (name="download_state")
+	@Enumerated(EnumType.STRING) Status downloadState;
+	
+	@Column (name="local_path") String localDownloadPath;
+	
+	@Column (name="error_str") String errorString;
+	
+	@Column (name="job_id") String jobId;
+	
+	@Column (name="install_path") String installPath;
+	
+	@Column (name="template_size") long templateSize;
+	
+	@Column (name="marked_for_gc") boolean markedForGC;
+
+	@Column(name="update_count", updatable = true, nullable=false)
+	protected long updatedCount;
+
+	@Column(name = "updated")
+	@Temporal(value = TemporalType.TIMESTAMP)
+	Date updated;
+
+	@Column(name = "state")
+	@Enumerated(EnumType.STRING)
+	ObjectInDataStoreStateMachine.State state;
+
+	@Override
+    public String getInstallPath() {
+		return installPath;
+	}
+	
+	@Override
+    public long getTemplateSize() {
+		return templateSize;
+	}
+
+	public long getPoolId() {
+		return poolId;
+	}
+
+	public void setpoolId(long poolId) {
+		this.poolId = poolId;
+	}
+
+	@Override
+    public long getTemplateId() {
+		return templateId;
+	}
+
+	@Override
+    public void setTemplateId(long templateId) {
+		this.templateId = templateId;
+	}
+
+	@Override
+    public int getDownloadPercent() {
+		return downloadPercent;
+	}
+
+	@Override
+    public void setDownloadPercent(int downloadPercent) {
+		this.downloadPercent = downloadPercent;
+	}
+
+	@Override
+    public void setDownloadState(Status downloadState) {
+		this.downloadState = downloadState;
+	}
+
+	@Override
+    public long getId() {
+		return id;
+	}
+
+	@Override
+    public Date getCreated() {
+		return created;
+	}
+
+	@Override
+    public Date getLastUpdated() {
+		return lastUpdated;
+	}
+	
+	@Override
+    public void setLastUpdated(Date date) {
+	    lastUpdated = date;
+	}
+	
+	@Override
+    public void setInstallPath(String installPath) {
+	    this.installPath = installPath;
+	}
+
+	@Override
+    public Status getDownloadState() {
+		return downloadState;
+	}
+
+	public VMTemplateStoragePoolVO(long poolId, long templateId) {
+		super();
+		this.poolId = poolId;
+		this.templateId = templateId;
+		this.downloadState = Status.NOT_DOWNLOADED;
+		this.state = ObjectInDataStoreStateMachine.State.Allocated;
+		this.markedForGC = false;
+	}
+
+	public VMTemplateStoragePoolVO(long poolId, long templateId, Date lastUpdated,
+			int downloadPercent, Status downloadState,
+			String localDownloadPath, String errorString, String jobId,
+			String installPath, long templateSize) {
+		super();
+		this.poolId = poolId;
+		this.templateId = templateId;
+		this.lastUpdated = lastUpdated;
+		this.downloadPercent = downloadPercent;
+		this.downloadState = downloadState;
+		this.localDownloadPath = localDownloadPath;
+		this.errorString = errorString;
+		this.jobId = jobId;
+		this.installPath = installPath;
+		this.templateSize = templateSize;
+	}
+
+	protected VMTemplateStoragePoolVO() {
+		
+	}
+
+	@Override
+    public void setLocalDownloadPath(String localPath) {
+		this.localDownloadPath = localPath;
+	}
+
+	@Override
+    public String getLocalDownloadPath() {
+		return localDownloadPath;
+	}
+
+	@Override
+    public void setErrorString(String errorString) {
+		this.errorString = errorString;
+	}
+
+	@Override
+    public String getErrorString() {
+		return errorString;
+	}
+
+	@Override
+    public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+
+	@Override
+    public String getJobId() {
+		return jobId;
+	}
+	
+	public void setTemplateSize(long templateSize) {
+		this.templateSize = templateSize;
+	}
+	
+	public boolean getMarkedForGC() {
+		return markedForGC;
+	}
+	
+	public void setMarkedForGC(boolean markedForGC) {
+		this.markedForGC = markedForGC;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (obj instanceof VMTemplateStoragePoolVO) {
+		   VMTemplateStoragePoolVO other = (VMTemplateStoragePoolVO)obj;
+		   return (this.templateId==other.getTemplateId() && this.poolId==other.getPoolId());
+		}
+		return false;
+	}
+
+	@Override
+	public int hashCode() {
+		Long tid = new Long(templateId);
+		Long hid = new Long(poolId);
+		return tid.hashCode()+hid.hashCode();
+	}
+	
+	@Override
+    public String toString() {
+	    return new StringBuilder("TmplPool[").append(id).append("-").append(templateId).append("-").append("poolId").append("-").append(installPath).append("]").toString();
+	}
+
+    @Override
+    public State getState() {
+        return this.state;
+    }
+    
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+    
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+    
+    public Date getUpdated() {
+        return updated;
+    }
+    
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VMTemplateSwiftVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VMTemplateSwiftVO.java b/engine/schema/src/com/cloud/storage/VMTemplateSwiftVO.java
new file mode 100755
index 0000000..6c7a73d
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VMTemplateSwiftVO.java
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDaoBase;
+import org.apache.cloudstack.api.InternalIdentity;
+
+/**
+ * Join table for swift and templates
+ * 
+ * 
+ */
+@Entity
+@Table(name = "template_swift_ref")
+public class VMTemplateSwiftVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    Long id;
+
+    @Column(name = "swift_id")
+    private long swiftId;
+
+    @Column(name = "template_id")
+    private long templateId;
+
+    @Column(name = GenericDaoBase.CREATED_COLUMN)
+    private Date created = null;
+
+    @Column(name = "path")
+    private String path;
+
+    @Column(name = "size")
+    private long size;
+
+    @Column(name = "physical_size")
+    private long physicalSize;
+
+    public VMTemplateSwiftVO(long swiftId, long templateId, Date created, String path, long size, long physicalSize) {
+        this.swiftId = swiftId;
+        this.templateId = templateId;
+        this.created = created;
+        this.path = path;
+        this.size = size;
+        this.physicalSize = physicalSize;
+    }
+
+    protected VMTemplateSwiftVO() {
+
+    }
+
+    public long getTemplateId() {
+        return templateId;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public long getSwiftId() {
+        return swiftId;
+    }
+
+    public long getSize() {
+        return size;
+    }
+
+    public long getPhysicalSize() {
+        return physicalSize;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("TmplSwift[").append(id).append("-").append(templateId).append("-").append(swiftId).append("]").toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VMTemplateVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/com/cloud/storage/VMTemplateVO.java
new file mode 100755
index 0000000..e643d75
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VMTemplateVO.java
@@ -0,0 +1,534 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.Storage.TemplateType;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateObject;
+
+@Entity
+@Table(name="vm_template")
+public class VMTemplateVO implements VirtualMachineTemplate, StateObject<TemplateState> {
+    @Id
+    @TableGenerator(name="vm_template_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_template_seq", allocationSize=1)
+    @Column(name="id", nullable = false)
+    private long id;
+
+    @Column(name="format")
+    private Storage.ImageFormat format;
+
+    @Column(name="unique_name")
+    private String uniqueName;
+
+    @Column(name="name")
+    private String name = null;
+
+    @Column(name="public")
+    private boolean publicTemplate = true;
+
+    @Column(name="featured")
+    private boolean featured;
+
+    @Column(name="type")
+    private Storage.TemplateType templateType;
+
+    @Column(name="url")
+    private String url = null;
+
+    @Column(name="hvm")
+    private boolean requiresHvm;
+
+    @Column(name="bits")
+    private int bits;
+
+    @Temporal(value=TemporalType.TIMESTAMP)
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created = null;
+
+    @Column(name=GenericDao.REMOVED)
+    @Temporal(TemporalType.TIMESTAMP)
+    private Date removed;
+
+    @Column(name="account_id")
+    private long accountId;
+
+    @Column(name="checksum")
+    private String checksum;
+
+    @Column(name="display_text", length=4096)
+    private String displayText;
+
+    @Column(name="enable_password")
+    private boolean enablePassword;
+
+    @Column(name="guest_os_id")
+    private long guestOSId;
+
+    @Column(name="bootable")
+    private boolean bootable = true;
+
+    @Column(name="prepopulate")
+    private boolean prepopulate = false;
+
+    @Column(name="cross_zones")
+    private boolean crossZones = false;
+
+    @Column(name="hypervisor_type")
+    @Enumerated(value=EnumType.STRING)
+    private HypervisorType hypervisorType;
+
+    @Column(name="extractable")
+    private boolean extractable = true;
+
+    @Column(name="source_template_id")
+    private Long sourceTemplateId;
+
+    @Column(name="template_tag")
+    private String templateTag;
+
+    @Column(name="uuid")
+    private String uuid;
+
+    @Column(name="sort_key")
+    private int sortKey;
+
+    @Column(name="enable_sshkey")
+    private boolean enableSshKey;
+    
+    @Column(name = "image_data_store_id")
+    private long imageDataStoreId;
+    
+    @Column(name = "size")
+    private Long size;
+    
+    @Column(name = "state")
+    private TemplateState state;
+    
+    @Column(name="update_count", updatable = true)
+    protected long updatedCount;
+    
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+
+    @Transient
+    Map details;
+
+    @Override
+    public String getUniqueName() {
+        return uniqueName;
+    }
+
+    public void setUniqueName(String uniqueName) {
+        this.uniqueName = uniqueName;
+    }
+
+    public VMTemplateVO() {
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = TemplateState.Allocated;
+    }
+
+    /**
+     * Proper constructor for a new vm template.
+     */
+    public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, Map details) {
+        this(id, generateUniqueName(id, accountId, name), name, format, isPublic, featured, isExtractable, type, url, null, requiresHvm, bits, accountId, cksum, displayText, enablePassword, guestOSId, bootable, hyperType, details);
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = TemplateState.Allocated;
+    }
+
+    public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, String templateTag, Map details, boolean sshKeyEnabled) {
+        this(id, name, format, isPublic, featured, isExtractable, type, url, requiresHvm, bits, accountId, cksum, displayText, enablePassword, guestOSId, bootable, hyperType, details);
+        this.templateTag = templateTag;
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = TemplateState.Allocated;
+    	this.enableSshKey = sshKeyEnabled;
+    }
+
+    public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType) {
+        this.id = id;
+        this.name = name;
+        this.publicTemplate = isPublic;
+        this.featured = featured;
+        this.templateType = type;
+        this.url = url;
+        this.requiresHvm = requiresHvm;
+        this.bits = bits;
+        this.accountId = accountId;
+        this.checksum = cksum;
+        this.uniqueName = uniqueName;
+        this.displayText = displayText;
+        this.enablePassword = enablePassword;
+        this.format = format;
+        this.created = created;
+        this.guestOSId = guestOSId;
+        this.bootable = bootable;
+        this.hypervisorType = hyperType;
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = TemplateState.Allocated;
+    }
+
+    // Has an extra attribute - isExtractable
+    public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, Map details) {
+        this(id, uniqueName, name, format, isPublic, featured, type, url, created, requiresHvm, bits, accountId, cksum,  displayText, enablePassword, guestOSId, bootable, hyperType);
+        this.extractable = isExtractable;
+    	this.uuid = UUID.randomUUID().toString();
+    	this.details = details;
+    }
+
+    public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, String templateTag, Map details) {
+        this(id, uniqueName, name, format, isPublic, featured, isExtractable, type, url, created, requiresHvm, bits, accountId, cksum,  displayText, enablePassword, guestOSId, bootable, hyperType, details);
+        this.templateTag = templateTag;
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    @Override
+    public boolean getEnablePassword() {
+        return enablePassword;
+    }
+
+    @Override
+    public Storage.ImageFormat getFormat() {
+        return format;
+    }
+
+    public void setEnablePassword(boolean enablePassword) {
+        this.enablePassword = enablePassword;
+    }
+
+    public void setFormat(ImageFormat format) {
+        this.format = format;
+    }
+
+    private static String generateUniqueName(long id, long userId, String displayName) {
+        StringBuilder name = new StringBuilder();
+        name.append(id);
+        name.append("-");
+        name.append(userId);
+        name.append("-");
+        name.append(UUID.nameUUIDFromBytes((displayName + System.currentTimeMillis()).getBytes()).toString());
+        return name.toString();
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public TemplateType getTemplateType() {
+        return templateType;
+    }
+
+    public void setTemplateType(TemplateType type) {
+        this.templateType = type;
+    }
+
+    public boolean requiresHvm() {
+        return requiresHvm;
+    }
+
+    @Override
+    public int getBits() {
+        return bits;
+    }
+
+    public void setBits(int bits) {
+        this.bits = bits;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    @Override
+    public boolean isPublicTemplate() {
+        return publicTemplate;
+    }
+
+    public void setPublicTemplate(boolean publicTemplate) {
+        this.publicTemplate = publicTemplate;
+    }
+
+    @Override
+    public boolean isFeatured() {
+        return featured;
+    }
+
+    public void setFeatured(boolean featured) {
+        this.featured = featured;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    @Override
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    @Override
+    public boolean isRequiresHvm() {
+        return requiresHvm;
+    }
+
+    public void setRequiresHvm(boolean value) {
+        requiresHvm = value;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    @Override
+    public String getChecksum() {
+        return checksum;
+    }
+
+    public void setChecksum(String checksum) {
+        this.checksum = checksum;
+    }
+
+    @Override
+    public String getDisplayText() {
+        return displayText;
+    }
+
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    @Override
+    public long getGuestOSId() {
+        return guestOSId;
+    }
+
+    public void setGuestOSId(long guestOSId) {
+        this.guestOSId = guestOSId;
+    }
+
+    @Override
+    public boolean isBootable() {
+        return bootable;
+    }
+
+    public void setBootable(boolean bootable) {
+        this.bootable = bootable;
+    }
+
+    public void setPrepopulate(boolean prepopulate) {
+        this.prepopulate = prepopulate;
+    }
+
+    public boolean isPrepopulate() {
+        return prepopulate;
+    }
+
+    public void setCrossZones(boolean crossZones) {
+        this.crossZones = crossZones;
+    }
+
+    @Override
+    public boolean isCrossZones() {
+        return crossZones;
+    }
+
+    @Override
+    public HypervisorType getHypervisorType() {
+        return hypervisorType;
+    }
+
+    public void setHypervisorType(HypervisorType hyperType) {
+        hypervisorType = hyperType;
+    }
+
+    @Override
+    public boolean isExtractable() {
+        return extractable;
+    }
+
+    public void setExtractable(boolean extractable) {
+        this.extractable = extractable;
+    }
+
+    @Override
+    public Long getSourceTemplateId() {
+        return sourceTemplateId;
+    }
+
+    public void setSourceTemplateId(Long sourceTemplateId) {
+        this.sourceTemplateId = sourceTemplateId;
+    }
+
+    @Override
+    public String getTemplateTag() {
+        return templateTag;
+    }
+
+    public void setTemplateTag(String templateTag) {
+        this.templateTag = templateTag;
+    }
+
+    @Override
+    public long getDomainId() {
+        return -1;
+    }
+
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+    public Map getDetails() {
+    	return this.details;
+    }
+
+    public void setDetails(Map details) {
+    	this.details = details;
+    }
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that ) {
+            return true;
+        }
+        if (!(that instanceof VMTemplateVO)){
+            return false;
+        }
+        VMTemplateVO other = (VMTemplateVO)that;
+
+        return ((this.getUniqueName().equals(other.getUniqueName())));
+    }
+
+    @Override
+    public int hashCode() {
+        return uniqueName.hashCode();
+    }
+
+    @Transient
+    String toString;
+    @Override
+    public String toString() {
+        if (toString == null) {
+            toString = new StringBuilder("Tmpl[").append(id).append("-").append(format).append("-").append(uniqueName).toString();
+        }
+        return toString;
+    }
+
+    public void setRemoved(Date removed) {
+        this.removed = removed;
+    }
+
+    public void setSortKey(int key) {
+    	sortKey = key;
+    }
+
+    public int getSortKey() {
+    	return sortKey;
+    }
+
+	@Override
+	public boolean getEnableSshKey() {
+		return enableSshKey;
+	}
+
+	public void setEnableSshKey(boolean enable) {
+		enableSshKey = enable;
+	}
+	
+	 public Long getImageDataStoreId() {
+	        return this.imageDataStoreId;
+	    }
+
+	    public void setImageDataStoreId(long dataStoreId) {
+	        this.imageDataStoreId = dataStoreId;
+	    }
+	    
+	    public void setSize(Long size) {
+	        this.size = size;
+	    }
+	    
+	    public Long getSize() {
+	        return this.size;
+	    }
+	    
+	    public TemplateState getState() {
+	        return this.state;
+	    }
+	    
+	    public long getUpdatedCount() {
+	        return this.updatedCount;
+	    }
+	    
+	    public void incrUpdatedCount() {
+	        this.updatedCount++;
+	    }
+
+	    public void decrUpdatedCount() {
+	        this.updatedCount--;
+	    }
+	    
+	    public Date getUpdated() {
+	        return updated;
+	    }
+	    
+	    public void setUpdated(Date updated) {
+	        this.updated = updated;
+	    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VMTemplateZoneVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VMTemplateZoneVO.java b/engine/schema/src/com/cloud/storage/VMTemplateZoneVO.java
new file mode 100644
index 0000000..93a67b5
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VMTemplateZoneVO.java
@@ -0,0 +1,116 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.GenericDaoBase;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="template_zone_ref")
+public class VMTemplateZoneVO implements InternalIdentity {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	Long id;
+	
+	@Column(name="zone_id")
+	private long zoneId;
+	
+	@Column(name="template_id")
+	private long templateId;
+	
+	@Column(name=GenericDaoBase.CREATED_COLUMN)
+	private Date created = null;
+	
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date lastUpdated = null;
+    
+    @Temporal(value=TemporalType.TIMESTAMP)
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+    
+    protected VMTemplateZoneVO() {
+    	
+    }
+
+	public VMTemplateZoneVO(long zoneId, long templateId, Date lastUpdated) {
+		this.zoneId = zoneId;
+		this.templateId = templateId;
+		this.lastUpdated = lastUpdated;
+	}
+
+	public long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+
+	public void setZoneId(long zoneId) {
+		this.zoneId = zoneId;
+	}
+
+	public long getTemplateId() {
+		return templateId;
+	}
+
+	public void setTemplateId(long templateId) {
+		this.templateId = templateId;
+	}
+
+	public Date getCreated() {
+		return created;
+	}
+
+	public void setCreated(Date created) {
+		this.created = created;
+	}
+
+	public Date getLastUpdated() {
+		return lastUpdated;
+	}
+
+	public void setLastUpdated(Date lastUpdated) {
+		this.lastUpdated = lastUpdated;
+	}
+
+	public void setRemoved(Date removed) {
+		this.removed = removed;
+	}
+
+	public Date getRemoved() {
+		return removed;
+	}
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VolumeHostVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VolumeHostVO.java b/engine/schema/src/com/cloud/storage/VolumeHostVO.java
new file mode 100755
index 0000000..40bae49
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VolumeHostVO.java
@@ -0,0 +1,347 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.utils.db.GenericDaoBase;
+
+/**
+ * Join table for storage hosts and volumes
+ *
+ */
+@Entity
+@Table(name="volume_host_ref")
+public class VolumeHostVO implements InternalIdentity, DataObjectInStore {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	Long id;
+	
+	@Column(name="host_id")
+	private long hostId;
+	
+	@Column(name="volume_id")
+	private long volumeId;
+	
+	@Column(name="zone_id")
+	private long zoneId;
+	
+	@Column(name=GenericDaoBase.CREATED_COLUMN)
+	private Date created = null;
+	
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date lastUpdated = null;
+	
+	@Column (name="download_pct")
+	private int downloadPercent;
+	
+	@Column (name="size")
+	private long size;
+	
+	@Column (name="physical_size")
+	private long physicalSize;
+	
+	@Column (name="download_state")
+	@Enumerated(EnumType.STRING)
+	private Status downloadState;
+	
+    @Column(name="checksum")
+    private String checksum;
+	
+	@Column (name="local_path")
+	private String localDownloadPath;
+	
+	@Column (name="error_str")
+	private String errorString;
+	
+	@Column (name="job_id")
+	private String jobId;	
+	
+	@Column (name="install_path")
+    private String installPath;
+	
+	@Column (name="url")
+	private String downloadUrl;
+	
+	@Column(name="format")
+    private Storage.ImageFormat format;
+    
+    @Column(name="destroyed")
+    boolean destroyed = false;
+    
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updatedCount;
+    
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+    
+    @Column(name = "state")
+    @Enumerated(EnumType.STRING)
+    ObjectInDataStoreStateMachine.State state;
+	
+    public String getInstallPath() {
+		return installPath;
+	}
+
+	public long getHostId() {
+		return hostId;
+	}
+
+	public void setHostId(long hostId) {
+		this.hostId = hostId;
+	}
+
+	
+    public long getVolumeId() {
+		return volumeId;
+	}
+
+	
+    public void setVolumeId(long volumeId) {
+		this.volumeId = volumeId;
+	}
+
+	
+    public long getZoneId() {
+		return zoneId;
+	}
+
+	public void setZoneId(long zoneId) {
+		this.zoneId = zoneId;
+	}
+
+	public int getDownloadPercent() {
+		return downloadPercent;
+	}
+
+	
+    public void setDownloadPercent(int downloadPercent) {
+		this.downloadPercent = downloadPercent;
+	}
+
+	
+    public void setDownloadState(Status downloadState) {
+		this.downloadState = downloadState;
+	}
+
+	
+    public long getId() {
+		return id;
+	}
+
+	
+    public Date getCreated() {
+		return created;
+	}
+
+	
+    public Date getLastUpdated() {
+		return lastUpdated;
+	}
+	
+	
+    public void setLastUpdated(Date date) {
+	    lastUpdated = date;
+	}
+	
+	
+    public void setInstallPath(String installPath) {
+	    this.installPath = installPath;
+	}
+
+	
+    public Status getDownloadState() {
+		return downloadState;
+	}
+
+	public String getChecksum() {
+		return checksum;
+	}
+
+	public void setChecksum(String checksum) {
+		this.checksum = checksum;
+	}
+
+	public VolumeHostVO(long hostId, long volumeId) {
+		super();
+		this.hostId = hostId;
+		this.volumeId = volumeId;
+		this.state = ObjectInDataStoreStateMachine.State.Allocated;
+	}
+
+	public VolumeHostVO(long hostId, long volumeId, long zoneId, Date lastUpdated,
+			int downloadPercent, Status downloadState,
+			String localDownloadPath, String errorString, String jobId,
+			String installPath, String downloadUrl, String checksum, ImageFormat format) {
+		//super();
+		this.hostId = hostId;
+		this.volumeId = volumeId;
+		this.zoneId = zoneId;
+		this.lastUpdated = lastUpdated;
+		this.downloadPercent = downloadPercent;
+		this.downloadState = downloadState;
+		this.localDownloadPath = localDownloadPath;
+		this.errorString = errorString;
+		this.jobId = jobId;
+		this.installPath = installPath;
+		this.setDownloadUrl(downloadUrl);
+		this.checksum = checksum;
+		this.format = format;
+	}
+
+	protected VolumeHostVO() {
+		
+	}
+
+	
+    public void setLocalDownloadPath(String localPath) {
+		this.localDownloadPath = localPath;
+	}
+
+	
+    public String getLocalDownloadPath() {
+		return localDownloadPath;
+	}
+
+	
+    public void setErrorString(String errorString) {
+		this.errorString = errorString;
+	}
+
+	
+    public String getErrorString() {
+		return errorString;
+	}
+
+	
+    public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+
+	
+    public String getJobId() {
+		return jobId;
+	}
+
+	
+	public boolean equals(Object obj) {
+		if (obj instanceof VolumeHostVO) {
+			VolumeHostVO other = (VolumeHostVO)obj;
+			return (this.volumeId==other.getVolumeId() && this.hostId==other.getHostId());		   
+		}
+		return false;
+	}
+
+	
+	public int hashCode() {
+		Long tid = new Long(volumeId);
+		Long hid = new Long(hostId);
+		return tid.hashCode()+hid.hashCode();
+	}
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public long getSize() {
+        return size;
+    }
+	
+    
+    public void setPhysicalSize(long physicalSize) {
+        this.physicalSize = physicalSize;
+    }
+
+    public long getPhysicalSize() {
+        return physicalSize;
+    }
+
+    public void setDestroyed(boolean destroyed) {
+    	this.destroyed = destroyed;
+    }
+
+    public boolean getDestroyed() {
+    	return destroyed;
+    }
+
+	public void setDownloadUrl(String downloadUrl) {
+		this.downloadUrl = downloadUrl;
+	}
+
+	public String getDownloadUrl() {
+		return downloadUrl;
+	}	
+	
+    public Storage.ImageFormat getFormat() {
+		return format;
+	}
+
+	public void setFormat(Storage.ImageFormat format) {
+		this.format = format;
+	}
+
+	public long getVolumeSize() {
+	    return -1;
+	}
+	
+	
+    public String toString() {
+	    return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(hostId).append(installPath).append("]").toString();
+	}
+    
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+    
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+    
+    public Date getUpdated() {
+        return updated;
+    }
+
+    @Override
+    public ObjectInDataStoreStateMachine.State getState() {
+        // TODO Auto-generated method stub
+        return this.state;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/VolumeVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VolumeVO.java b/engine/schema/src/com/cloud/storage/VolumeVO.java
new file mode 100755
index 0000000..1699afd
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/VolumeVO.java
@@ -0,0 +1,466 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = "volumes")
+public class VolumeVO implements Volume {
+    @Id
+    @TableGenerator(name = "volume_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "volume_seq", allocationSize = 1)
+    @GeneratedValue(strategy = GenerationType.TABLE)
+    @Column(name = "id")
+    long id;
+
+    @Column(name = "name")
+    String name;
+
+    @Column(name = "pool_id")
+    Long poolId;
+    
+    @Column(name = "last_pool_id")
+    Long lastPoolId;
+    
+    @Column(name = "account_id")
+    long accountId;
+
+    @Column(name = "domain_id")
+    long domainId;
+
+    @Column(name = "instance_id")
+    Long instanceId = null;
+
+    @Column(name = "device_id")
+    Long deviceId = null;
+
+    @Column(name = "size")
+    Long size;
+
+    @Column(name = "folder")
+    String folder;
+
+    @Column(name = "path")
+    String path;
+
+    @Column(name = "pod_id")
+    Long podId;
+
+    @Column(name = "created")
+    Date created;
+
+    @Column(name = "attached")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date attached;
+
+    @Column(name = "data_center_id")
+    long dataCenterId;
+
+    @Column(name = "host_ip")
+    String hostip;
+
+    @Column(name = "disk_offering_id")
+    long diskOfferingId;
+
+    @Column(name = "template_id")
+    Long templateId;
+
+    @Column(name = "first_snapshot_backup_uuid")
+    String firstSnapshotBackupUuid;
+
+    @Column(name = "volume_type")
+    @Enumerated(EnumType.STRING)
+    Type volumeType = Volume.Type.UNKNOWN;
+
+    @Column(name = "pool_type")
+    @Enumerated(EnumType.STRING)
+    StoragePoolType poolType;
+
+    @Column(name = GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+    
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updatedCount;	// This field should be updated everytime the state is updated.  There's no set method in the vo object because it is done with in the dao code.
+
+    @Column(name = "recreatable")
+    boolean recreatable;
+
+    @Column(name = "state")
+    @Enumerated(value = EnumType.STRING)
+    private State state;
+
+    @Column(name = "chain_info")
+    String chainInfo;
+
+    @Column(name = "uuid")
+    String uuid;
+
+    @Column(name="display_volume", updatable=true, nullable=false)
+    protected boolean displayVolume;
+
+    @Transient
+    // @Column(name="reservation")
+    String reservationId;
+    
+    // Real Constructor
+    public VolumeVO(Type type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) {
+        this.volumeType = type;
+        this.name = name;
+        this.dataCenterId = dcId;
+        this.accountId = accountId;
+        this.domainId = domainId;
+        this.size = size;
+        this.diskOfferingId = diskOfferingId;
+        this.state = State.Allocated;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.Type vType) {
+        this.name = name;
+        this.accountId = accountId;
+        this.domainId = domainId;
+        this.instanceId = instanceId;
+        this.folder = folder;
+        this.path = path;
+        this.size = size;
+        this.podId = podId;
+        this.dataCenterId = dcId;
+        this.volumeType = vType;
+        this.state = Volume.State.Allocated;
+        this.recreatable = false;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    // Copy Constructor
+    public VolumeVO(Volume that) {
+        this(that.getName(), that.getDataCenterId(), that.getPodId(), that.getAccountId(), that.getDomainId(), that.getInstanceId(), that.getFolder(), that.getPath(), that.getSize(), that
+                .getVolumeType());
+        this.recreatable = that.isRecreatable();
+        this.state = that.getState();
+        this.size = that.getSize();
+        this.diskOfferingId = that.getDiskOfferingId();
+        this.poolId = that.getPoolId();
+        this.attached = that.getAttached();
+        this.chainInfo = that.getChainInfo();
+        this.templateId = that.getTemplateId();
+        this.deviceId = that.getDeviceId();
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    @Override
+    public long getUpdatedCount() {
+    	return this.updatedCount;
+    }
+    
+    @Override
+    public void incrUpdatedCount() {
+    	this.updatedCount++;
+    }
+    
+    public void decrUpdatedCount() {
+    	this.updatedCount--;
+    }
+    
+    @Override
+    public boolean isRecreatable() {
+        return recreatable;
+    }
+
+    public void setRecreatable(boolean recreatable) {
+        this.recreatable = recreatable;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public Long getPodId() {
+        return podId;
+    }
+
+    @Override
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    public void setPoolType(StoragePoolType poolType) {
+        this.poolType = poolType;
+    }
+
+    public StoragePoolType getPoolType() {
+        return poolType;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+    @Override
+    public String getFolder() {
+        return folder;
+    }
+
+    @Override
+    public String getPath() {
+        return path;
+    }
+
+    protected VolumeVO() {
+    }
+
+    @Override
+    public Long getSize() {
+        return size;
+    }
+
+    public void setSize(Long size) {
+        this.size = size;
+    }
+
+    @Override
+    public Long getInstanceId() {
+        return instanceId;
+    }
+
+    @Override
+    public Long getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(Long deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    @Override
+    public Type getVolumeType() {
+        return volumeType;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setFolder(String folder) {
+        this.folder = folder;
+    }
+
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
+    }
+
+    public void setDomainId(long domainId) {
+        this.domainId = domainId;
+    }
+
+    public void setInstanceId(Long instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getHostIp() {
+        return hostip;
+    }
+
+    public void setHostIp(String hostip) {
+        this.hostip = hostip;
+    }
+
+    public void setPodId(Long podId) {
+        this.podId = podId;
+    }
+
+    public void setDataCenterId(long dataCenterId) {
+        this.dataCenterId = dataCenterId;
+    }
+
+    public void setVolumeType(Type type) {
+        volumeType = type;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setRemoved(Date removed) {
+        this.removed = removed;
+    }
+
+    @Override
+    public long getDiskOfferingId() {
+        return diskOfferingId;
+    }
+
+    public void setDiskOfferingId(long diskOfferingId) {
+        this.diskOfferingId = diskOfferingId;
+    }
+
+    @Override
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public String getFirstSnapshotBackupUuid() {
+        return firstSnapshotBackupUuid;
+    }
+
+    public void setFirstSnapshotBackupUuid(String firstSnapshotBackupUuid) {
+        this.firstSnapshotBackupUuid = firstSnapshotBackupUuid;
+    }
+
+    @Override
+    public Long getPoolId() {
+        return poolId;
+    }
+
+    public void setPoolId(Long poolId) {
+        this.poolId = poolId;
+    }
+
+    @Override
+    public Date getUpdated() {
+        return updated;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    public void setUpdated(Date updated) {
+        this.updated = updated;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
+    }
+
+    @Override
+    public Date getAttached() {
+        return this.attached;
+    }
+
+    public void setAttached(Date attached) {
+        this.attached = attached;
+    }
+
+    @Override
+    public String getChainInfo() {
+        return this.chainInfo;
+    }
+
+    public void setChainInfo(String chainInfo) {
+        this.chainInfo = chainInfo;
+    }
+    
+    public Long getLastPoolId() {
+    	return this.lastPoolId;
+    }
+    
+    public void setLastPoolId(Long poolId) {
+    	this.lastPoolId = poolId;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof VolumeVO) {
+            return id == ((VolumeVO) obj).id;
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public String getReservationId() {
+    	return this.reservationId;
+    }
+    
+    @Override
+    public void setReservationId(String reserv) {
+    	this.reservationId = reserv;
+    }
+    
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+    
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+
+    public boolean isDisplayVolume() {
+        return displayVolume;
+    }
+
+    public void setDisplayVolume(boolean displayVolume) {
+        this.displayVolume = displayVolume;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/DiskOfferingDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/DiskOfferingDao.java b/engine/schema/src/com/cloud/storage/dao/DiskOfferingDao.java
new file mode 100644
index 0000000..c17e319
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/DiskOfferingDao.java
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import java.util.List;
+
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface DiskOfferingDao extends GenericDao<DiskOfferingVO, Long> {
+    List<DiskOfferingVO> listByDomainId(long domainId);
+    List<DiskOfferingVO> findPrivateDiskOffering();
+	List<DiskOfferingVO> findPublicDiskOfferings();
+    DiskOfferingVO findByUniqueName(String uniqueName);
+    DiskOfferingVO persistDeafultDiskOffering(DiskOfferingVO offering);
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
new file mode 100644
index 0000000..1f68c50
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/DiskOfferingDaoImpl.java
@@ -0,0 +1,152 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.persistence.EntityExistsException;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.DiskOfferingVO.Type;
+import com.cloud.utils.db.Attribute;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value={DiskOfferingDao.class})
+public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> implements DiskOfferingDao {
+    private static final Logger s_logger = Logger.getLogger(DiskOfferingDaoImpl.class);
+
+    private final SearchBuilder<DiskOfferingVO> DomainIdSearch;
+    private final SearchBuilder<DiskOfferingVO> PrivateDiskOfferingSearch;
+    private final SearchBuilder<DiskOfferingVO> PublicDiskOfferingSearch;
+    protected final SearchBuilder<DiskOfferingVO> UniqueNameSearch;
+    private final Attribute _typeAttr;
+
+    protected DiskOfferingDaoImpl() {
+        DomainIdSearch  = createSearchBuilder();
+        DomainIdSearch.and("domainId", DomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        DomainIdSearch.and("removed", DomainIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        DomainIdSearch.done();
+        
+        PrivateDiskOfferingSearch  = createSearchBuilder();
+        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().getSystemUse(), SearchCriteria.Op.EQ);
+        PublicDiskOfferingSearch.and("removed", PublicDiskOfferingSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+        PublicDiskOfferingSearch.done();
+        
+        UniqueNameSearch = createSearchBuilder();
+        UniqueNameSearch.and("name", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
+        UniqueNameSearch.done();
+        
+        _typeAttr = _allAttributes.get("type");
+    }
+
+    @Override
+    public List<DiskOfferingVO> listByDomainId(long domainId) {
+        SearchCriteria<DiskOfferingVO> sc = DomainIdSearch.create();
+        sc.setParameters("domainId", domainId);
+        // FIXME:  this should not be exact match, but instead should find all available disk offerings from parent domains
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<DiskOfferingVO> findPrivateDiskOffering() {
+        SearchCriteria<DiskOfferingVO> sc = PrivateDiskOfferingSearch.create();
+        sc.setParameters("diskSize", 0);
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<DiskOfferingVO> searchIncludingRemoved(SearchCriteria<DiskOfferingVO> sc, final Filter filter, final Boolean lock, final boolean cache) {
+        sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
+        return super.searchIncludingRemoved(sc, filter, lock, cache);
+    }
+    
+    @Override
+    public <K> List<K> customSearchIncludingRemoved(SearchCriteria<K> sc, final Filter filter) {
+        sc.addAnd(_typeAttr, Op.EQ, Type.Disk);
+        return super.customSearchIncludingRemoved(sc, filter);
+    }
+    
+    @Override
+    protected List<DiskOfferingVO> executeList(final String sql, final Object... params) {
+        StringBuilder builder = new StringBuilder(sql);
+        int index = builder.indexOf("WHERE");
+        if (index == -1) {
+            builder.append(" WHERE type=?");
+        } else {
+            builder.insert(index + 6, "type=? ");
+        }
+        
+        return super.executeList(sql, Type.Disk, params);
+    }
+    
+    @Override
+    public List<DiskOfferingVO> findPublicDiskOfferings(){
+    	SearchCriteria<DiskOfferingVO> sc = PublicDiskOfferingSearch.create();
+    	sc.setParameters("system", false);
+        return listBy(sc);    	
+    }
+    
+    @Override
+    public DiskOfferingVO findByUniqueName(String uniqueName) {
+        SearchCriteria<DiskOfferingVO> sc = UniqueNameSearch.create();
+        sc.setParameters("name", uniqueName);
+        List<DiskOfferingVO> vos = search(sc, null, null, false);
+        if (vos.size() == 0) {
+            return null;
+        }
+        
+        return vos.get(0);
+    }
+    
+    @Override
+    public DiskOfferingVO persistDeafultDiskOffering(DiskOfferingVO offering) {
+        assert offering.getUniqueName() != null : "unique name shouldn't be null for the disk offering";
+        DiskOfferingVO vo = findByUniqueName(offering.getUniqueName());
+        if (vo != null) {
+            return vo;
+        }
+        try {
+            return persist(offering);
+        } catch (EntityExistsException e) {
+            // Assume it's conflict on unique name
+            return findByUniqueName(offering.getUniqueName());
+        }
+    }
+    
+    @Override
+    public boolean remove(Long id) {
+        DiskOfferingVO diskOffering = createForUpdate();
+        diskOffering.setRemoved(new Date());
+
+        return update(id, diskOffering);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDao.java b/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDao.java
new file mode 100644
index 0000000..0f7ea32
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDao.java
@@ -0,0 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import com.cloud.storage.GuestOSCategoryVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface GuestOSCategoryDao extends GenericDao<GuestOSCategoryVO, Long> {
+   
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDaoImpl.java
new file mode 100644
index 0000000..d017b99
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSCategoryDaoImpl.java
@@ -0,0 +1,34 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.storage.GuestOSCategoryVO;
+import com.cloud.utils.db.GenericDaoBase;
+
+@Component
+@Local (value={GuestOSCategoryDao.class})
+public class GuestOSCategoryDaoImpl extends GenericDaoBase<GuestOSCategoryVO, Long> implements GuestOSCategoryDao {
+    
+	protected GuestOSCategoryDaoImpl() {
+
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/GuestOSDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSDao.java b/engine/schema/src/com/cloud/storage/dao/GuestOSDao.java
new file mode 100755
index 0000000..19e423b
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSDao.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import com.cloud.storage.GuestOSVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface GuestOSDao extends GenericDao<GuestOSVO, Long> {
+
+    GuestOSVO listByDisplayName(String displayName);
+   
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/GuestOSDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/GuestOSDaoImpl.java
new file mode 100755
index 0000000..c39fae8
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSDaoImpl.java
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.storage.GuestOSVO;
+import com.cloud.storage.VMTemplateHostVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local (value={GuestOSDao.class})
+public class GuestOSDaoImpl extends GenericDaoBase<GuestOSVO, Long> implements GuestOSDao {
+    
+    
+    protected final SearchBuilder<GuestOSVO> Search;
+    
+	protected GuestOSDaoImpl() {
+        Search = createSearchBuilder();
+        Search.and("display_name", Search.entity().getDisplayName(), SearchCriteria.Op.EQ);
+        Search.done();
+	}
+	
+   @Override
+    public GuestOSVO listByDisplayName(String displayName) {
+        SearchCriteria<GuestOSVO> sc = Search.create();
+        sc.setParameters("display_name", displayName);
+        return findOneBy(sc);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDao.java b/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDao.java
new file mode 100644
index 0000000..0ad60b5
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDao.java
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import java.util.List;
+
+
+import com.cloud.storage.LaunchPermissionVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface LaunchPermissionDao extends GenericDao<LaunchPermissionVO, Long> {
+    /**
+     * remove the ability to launch vms from the given template for the given account names which are valid in the given domain
+     * @param templateId id of the template to modify launch permissions
+     * @param accountIds list of account ids
+     */
+    void removePermissions(long templateId, List<Long> accountIds);
+
+    /**
+     * remove all launch permissions associated with a template
+     * @param templateId
+     */
+    void removeAllPermissions(long templateId);
+
+    /**
+     * Find a launch permission by templateId, accountName, and domainId
+     * @param templateId the id of the template to search for
+     * @param accountId the id of the account for which permission is being searched
+     * @return launch permission if found, null otherwise
+     */
+    LaunchPermissionVO findByTemplateAndAccount(long templateId, long accountId);
+
+    /**
+     * List all launch permissions for the given template
+     * @param templateId id of the template for which launch permissions will be queried
+     * @return list of launch permissions
+     */
+    List<LaunchPermissionVO> findByTemplate(long templateId);
+
+    /**
+     * List all templates for which permission to launch instances has been granted to the given account
+     * @param accountId
+     * @return
+     */
+    List<VMTemplateVO> listPermittedTemplates(long accountId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java
new file mode 100644
index 0000000..286b1d9
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/LaunchPermissionDaoImpl.java
@@ -0,0 +1,158 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.storage.LaunchPermissionVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value={LaunchPermissionDao.class})
+public class LaunchPermissionDaoImpl extends GenericDaoBase<LaunchPermissionVO, Long> implements LaunchPermissionDao {
+    private static final Logger s_logger = Logger.getLogger(LaunchPermissionDaoImpl.class);
+    private static final String REMOVE_LAUNCH_PERMISSION = "DELETE FROM `cloud`.`launch_permission`" +
+                                                           "  WHERE template_id = ? AND account_id = ?";
+
+    private static final String LIST_PERMITTED_TEMPLATES = "SELECT t.id, t.unique_name, t.name, t.public, t.format, t.type, t.hvm, t.bits, t.url, t.created, t.account_id, t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.featured" +
+                                                           "  FROM `cloud`.`vm_template` t INNER JOIN (SELECT lp.template_id as lptid" +
+                                                                                                      " FROM `cloud`.`launch_permission` lp" +
+                                                                                                      " WHERE lp.account_id = ?) joinlp" +
+                                                           "  WHERE t.id = joinlp.lptid" +
+                                                           "  ORDER BY t.created DESC";
+
+    private final SearchBuilder<LaunchPermissionVO> TemplateAndAccountSearch;
+    private final SearchBuilder<LaunchPermissionVO> TemplateIdSearch;
+
+    protected LaunchPermissionDaoImpl() {
+        TemplateAndAccountSearch = createSearchBuilder();
+        TemplateAndAccountSearch.and("templateId", TemplateAndAccountSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateAndAccountSearch.and("accountId", TemplateAndAccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        TemplateAndAccountSearch.done();
+
+        TemplateIdSearch = createSearchBuilder();
+        TemplateIdSearch.and("templateId", TemplateIdSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateIdSearch.done();
+    }
+
+    @Override
+    public void removePermissions(long templateId, List<Long> accountIds) {
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+        try {
+            txn.start();
+            String sql = REMOVE_LAUNCH_PERMISSION;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            for (Long accountId : accountIds) {
+                pstmt.setLong(1, templateId);
+                pstmt.setLong(2, accountId.longValue());
+                pstmt.addBatch();
+            }
+            pstmt.executeBatch();
+            txn.commit();
+        } catch (Exception e) {
+            txn.rollback();
+            s_logger.warn("Error removing launch permissions", e);
+            throw new CloudRuntimeException("Error removing launch permissions", e);
+        }
+    }
+
+    @Override
+    public void removeAllPermissions(long templateId) {
+        SearchCriteria<LaunchPermissionVO> sc = TemplateIdSearch.create();
+        sc.setParameters("templateId", templateId);
+        expunge(sc);
+    }
+
+    @Override
+    public LaunchPermissionVO findByTemplateAndAccount(long templateId, long accountId) {
+        SearchCriteria<LaunchPermissionVO> sc = TemplateAndAccountSearch.create();
+        sc.setParameters("templateId", templateId);
+        sc.setParameters("accountId", accountId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateVO> listPermittedTemplates(long accountId) {
+        Transaction txn = Transaction.currentTxn();
+        List<VMTemplateVO> permittedTemplates = new ArrayList<VMTemplateVO>();
+        PreparedStatement pstmt = null;
+        try {
+            String sql = LIST_PERMITTED_TEMPLATES;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, accountId);
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                String uniqueName = rs.getString(2);
+                String name = rs.getString(3);
+                boolean isPublic = rs.getBoolean(4);
+                String value = rs.getString(5);
+                ImageFormat format = ImageFormat.valueOf(value);
+                String tmpltType = rs.getString(6);
+                boolean requiresHVM = rs.getBoolean(7);
+                int bits = rs.getInt(8);
+                String url = rs.getString(9);
+                String createdTS = rs.getString(10);
+                long templateAccountId = rs.getLong(11);
+                String checksum = rs.getString(12);
+                String displayText = rs.getString(13);
+                boolean enablePassword = rs.getBoolean(14);
+                long guestOSId = rs.getLong(15);
+                boolean featured = rs.getBoolean(16);
+                Date createdDate = null;
+
+                if (createdTS != null) {
+                    createdDate = DateUtil.parseDateString(s_gmtTimeZone, createdTS);
+                }
+
+                if (isPublic) {
+                    continue; // if it's public already, skip adding it to permitted templates as this for private templates only
+                }
+                VMTemplateVO template = new VMTemplateVO(id, uniqueName, name, format, isPublic, featured, TemplateType.valueOf(tmpltType), url, createdDate, requiresHVM, bits, templateAccountId, checksum, displayText, enablePassword, guestOSId, true, null);
+                permittedTemplates.add(template);
+            }
+        } catch (Exception e) {
+            s_logger.warn("Error listing permitted templates", e);
+        }
+        return permittedTemplates;
+    }
+
+    @Override
+    public List<LaunchPermissionVO> findByTemplate(long templateId) {
+        SearchCriteria<LaunchPermissionVO> sc = TemplateIdSearch.create();
+        sc.setParameters("templateId", templateId);
+        return listBy(sc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/S3Dao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/S3Dao.java b/engine/schema/src/com/cloud/storage/dao/S3Dao.java
new file mode 100644
index 0000000..ebea353
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/S3Dao.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.storage.dao;
+
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.storage.S3VO;
+import com.cloud.utils.db.GenericDao;
+
+public interface S3Dao extends GenericDao<S3VO, Long> {
+
+    S3TO getS3TO(final Long id);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/S3DaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/S3DaoImpl.java b/engine/schema/src/com/cloud/storage/dao/S3DaoImpl.java
new file mode 100644
index 0000000..f0dd078
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/S3DaoImpl.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.storage.dao;
+
+import com.cloud.agent.api.to.S3TO;
+import com.cloud.storage.S3VO;
+import com.cloud.utils.db.GenericDaoBase;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+@Component
+@Local(S3Dao.class)
+public class S3DaoImpl extends GenericDaoBase<S3VO, Long> implements S3Dao {
+
+    @Override
+    public S3TO getS3TO(final Long id) {
+
+        if (id != null) {
+
+            final S3VO s3VO = findById(id);
+            if (s3VO != null) {
+                return s3VO.toS3TO();
+            }
+
+        }
+
+        // NOTE: Excluded listAll / shuffle operation implemented in SwiftDaoImpl ...
+
+        return null;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
new file mode 100644
index 0000000..3ac9e77
--- /dev/null
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage.dao;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Snapshot.Type;
+import com.cloud.storage.SnapshotVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+import java.util.List;
+
+public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snapshot.State, Snapshot.Event, SnapshotVO> {
+	List<SnapshotVO> listByVolumeId(long volumeId);
+	List<SnapshotVO> listByVolumeId(Filter filter, long volumeId);
+	SnapshotVO findNextSnapshot(long parentSnapId);
+	long getLastSnapshot(long volumeId, long snapId);
+    List<SnapshotVO> listByVolumeIdType(long volumeId, Type type);
+    List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId);
+    List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid);
+    long updateSnapshotVersion(long volumeId, String from, String to);
+    List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
+    Long getSecHostId(long volumeId);
+    long updateSnapshotSecHost(long dcId, long secHostId);
+    List<SnapshotVO> listByHostId(Filter filter, long hostId);
+    List<SnapshotVO> listByHostId(long hostId);
+    public Long countSnapshotsForAccount(long accountId);
+    List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status);
+    List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status);
+    List<SnapshotVO> listAllByStatus(Snapshot.State... status);
+    /**
+     * Gets the Total Secondary Storage space (in bytes) used by snapshots allocated for an account
+     *
+     * @param account
+     * @return total Secondary Storage space allocated
+     */
+    long secondaryStorageUsedForAccount(long accountId);
+
+}


Mime
View raw message