cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject git commit: S3-backed Secondary Storage
Date Wed, 02 Jan 2013 18:34:16 GMT
Updated Branches:
  refs/heads/master 3d2fefabd -> e4583ced2


S3-backed Secondary Storage


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/e4583ced
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/e4583ced
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/e4583ced

Branch: refs/heads/master
Commit: e4583ced2e1bc9b4abf7b8f9dbf53edd2baa1704
Parents: 3d2fefa
Author: John Burwell <jburwell@basho.com>
Authored: Thu Dec 20 20:35:56 2012 -0500
Committer: Edison Su <sudison@gmail.com>
Committed: Wed Jan 2 10:28:47 2013 -0800

----------------------------------------------------------------------
 api/src/com/cloud/api/commands/ListS3sCmd.java     |   37 ----
 build/package.xml                                  |    4 +
 .../configuration/ConfigurationManagerImpl.java    |  108 +++++++++--
 .../src/com/cloud/server/ManagementServerImpl.java |   26 +++
 .../src/com/cloud/storage/dao/VMTemplateDao.java   |    4 +
 .../com/cloud/storage/dao/VMTemplateDaoImpl.java   |  140 +++++++++++++++
 server/src/com/cloud/storage/s3/S3ManagerImpl.java |    5 -
 tools/marvin/marvin/cloudstackConnection.py        |    1 -
 tools/marvin/marvin/configGenerator.py             |   11 ++
 tools/marvin/marvin/deployDataCenter.py            |    8 +-
 utils/src/com/cloud/utils/db/DbUtil.java           |   59 ++++++
 11 files changed, 337 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/api/src/com/cloud/api/commands/ListS3sCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListS3sCmd.java b/api/src/com/cloud/api/commands/ListS3sCmd.java
index 507053d..d536cfc 100644
--- a/api/src/com/cloud/api/commands/ListS3sCmd.java
+++ b/api/src/com/cloud/api/commands/ListS3sCmd.java
@@ -18,15 +18,11 @@
  */
 package com.cloud.api.commands;
 
-import static com.cloud.api.ApiConstants.ID;
-import static com.cloud.api.BaseCmd.CommandType.LONG;
-
 import java.util.ArrayList;
 import java.util.List;
 
 import com.cloud.api.BaseListCmd;
 import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
 import com.cloud.api.response.ListResponse;
 import com.cloud.api.response.S3Response;
@@ -42,9 +38,6 @@ public final class ListS3sCmd extends BaseListCmd {
 
     private static final String COMMAND_NAME = "lists3sresponse";
 
-    @Parameter(name = ID, type = LONG, required = true, description = "The ID of the S3")
-    private Long id;
-
     @Override
     public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
             ServerApiException, ConcurrentOperationException, ResourceAllocationException,
@@ -75,38 +68,8 @@ public final class ListS3sCmd extends BaseListCmd {
     }
 
     @Override
-    public boolean equals(final Object thatObject) {
-
-        if (this == thatObject) {
-            return true;
-        }
-
-        if (thatObject == null || getClass() != thatObject.getClass()) {
-            return false;
-        }
-
-        final ListS3sCmd thatListS3sCmd = (ListS3sCmd) thatObject;
-
-        if (this.id != null ? !this.id.equals(thatListS3sCmd.id) : thatListS3sCmd.id != null)
{
-            return false;
-        }
-
-        return true;
-
-    }
-
-    @Override
-    public int hashCode() {
-        return this.id != null ? this.id.hashCode() : 0;
-    }
-
-    @Override
     public String getCommandName() {
         return COMMAND_NAME;
     }
 
-    public Long getId() {
-        return this.id;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/build/package.xml
----------------------------------------------------------------------
diff --git a/build/package.xml b/build/package.xml
index 09ed939..3efdd7d 100755
--- a/build/package.xml
+++ b/build/package.xml
@@ -217,6 +217,10 @@
         <include name="discovery-*.jar" />
         <include name="wsdl4j-*.jar" />
         <include name="ejb-api-3.0.jar" />
+        <include name="aws-java-sdk-1.3.21.1.jar" />
+        <include name="httpclient-4.1.jar" />
+        <include name="httpcore-4.1.jar" />
+        <include name="commons-lang-2.1.jar" />
       </zipfileset>
       <zipfileset dir="${jar.dir}">
         <include name="${agent.jar}" />

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 2d7dfe2..c7a5d64 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -16,35 +16,110 @@
 // under the License.
 package com.cloud.configuration;
 
+import java.net.URI;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+
+import org.apache.log4j.Logger;
+
 import com.cloud.acl.SecurityChecker;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiConstants.LDAPParams;
 import com.cloud.api.ApiDBUtils;
-import com.cloud.api.commands.*;
+import com.cloud.api.commands.CreateDiskOfferingCmd;
+import com.cloud.api.commands.CreateNetworkOfferingCmd;
+import com.cloud.api.commands.CreateServiceOfferingCmd;
+import com.cloud.api.commands.CreateVlanIpRangeCmd;
+import com.cloud.api.commands.CreateZoneCmd;
+import com.cloud.api.commands.DeleteDiskOfferingCmd;
+import com.cloud.api.commands.DeleteNetworkOfferingCmd;
+import com.cloud.api.commands.DeletePodCmd;
+import com.cloud.api.commands.DeleteServiceOfferingCmd;
+import com.cloud.api.commands.DeleteVlanIpRangeCmd;
+import com.cloud.api.commands.DeleteZoneCmd;
+import com.cloud.api.commands.LDAPConfigCmd;
+import com.cloud.api.commands.LDAPRemoveCmd;
+import com.cloud.api.commands.ListNetworkOfferingsCmd;
+import com.cloud.api.commands.UpdateCfgCmd;
+import com.cloud.api.commands.UpdateDiskOfferingCmd;
+import com.cloud.api.commands.UpdateNetworkOfferingCmd;
+import com.cloud.api.commands.UpdatePodCmd;
+import com.cloud.api.commands.UpdateServiceOfferingCmd;
+import com.cloud.api.commands.UpdateZoneCmd;
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.*;
+import com.cloud.dc.AccountVlanMapVO;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.DataCenterIpAddressVO;
+import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.dc.Pod;
+import com.cloud.dc.PodVlanMapVO;
+import com.cloud.dc.Vlan;
 import com.cloud.dc.Vlan.VlanType;
-import com.cloud.dc.dao.*;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.AccountVlanMapDao;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.DataCenterIpAddressDao;
+import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.dc.dao.PodVlanMapDao;
+import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DataCenterDeployment;
 import com.cloud.domain.Domain;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
-import com.cloud.exception.*;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.host.HostVO;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.*;
+import com.cloud.network.IPAddressVO;
+import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkVO;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.dao.*;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.PhysicalNetworkVO;
+import com.cloud.network.dao.FirewallRulesDao;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.PhysicalNetworkDao;
+import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
+import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.offering.DiskOffering;
 import com.cloud.offering.NetworkOffering;
@@ -69,7 +144,12 @@ import com.cloud.storage.s3.S3Manager;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.swift.SwiftManager;
 import com.cloud.test.IPRangeConfig;
-import com.cloud.user.*;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.StringUtils;
@@ -85,20 +165,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.NicDao;
-import edu.emory.mathcs.backport.java.util.Arrays;
-import org.apache.log4j.Logger;
 
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.net.URI;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
+import edu.emory.mathcs.backport.java.util.Arrays;
 
 @Local(value = { ConfigurationManager.class, ConfigurationService.class })
 public class ConfigurationManagerImpl implements ConfigurationManager, ConfigurationService
{

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 117be57..500c067 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -203,6 +203,7 @@ import com.cloud.storage.dao.StoragePoolDao;
 import com.cloud.storage.dao.UploadDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
+import com.cloud.storage.s3.S3Manager;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.storage.swift.SwiftManager;
@@ -292,6 +293,7 @@ public class ManagementServerImpl implements ManagementServer {
     private final ConsoleProxyManager _consoleProxyMgr;
     private final SecondaryStorageVmManager _secStorageVmMgr;
     private final SwiftManager _swiftMgr;
+    private final S3Manager _s3Mgr;
     private final ServiceOfferingDao _offeringsDao;
     private final DiskOfferingDao _diskOfferingDao;
     private final VMTemplateDao _templateDao;
@@ -370,6 +372,7 @@ public class ManagementServerImpl implements ManagementServer {
         _consoleProxyMgr = locator.getManager(ConsoleProxyManager.class);
         _secStorageVmMgr = locator.getManager(SecondaryStorageVmManager.class);
         _swiftMgr = locator.getManager(SwiftManager.class);
+        _s3Mgr = locator.getManager(S3Manager.class);
         _storageMgr = locator.getManager(StorageManager.class);
         _publicIpAddressDao = locator.getDao(IPAddressDao.class);
         _consoleProxyDao = locator.getDao(ConsoleProxyDao.class);
@@ -1399,6 +1402,29 @@ public class ManagementServerImpl implements ManagementServer {
                 }
                 templateZonePairSet.add(new Pair<Long, Long>(template.getId(), zoneId));
             }
+        } else if (_s3Mgr.isS3Enabled()) {
+            if (template == null) {
+                templateZonePairSet = _templateDao.searchSwiftTemplates(name, keyword, templateFilter,
isIso, 
+                        hypers, bootable, domain, pageSize, startIndex, zoneId, hyperType,
onlyReady, showDomr,
+                        permittedAccounts, caller, tags);
+                Set<Pair<Long, Long>> templateZonePairSet2 = new HashSet<Pair<Long,
Long>>();
+                templateZonePairSet2 = _templateDao.searchTemplates(name, keyword, templateFilter,
isIso, hypers, 
+                        bootable, domain, pageSize, startIndex, zoneId, hyperType, onlyReady,
showDomr,
+                        permittedAccounts, caller, listProjectResourcesCriteria, tags);
+                
+                for (Pair<Long, Long> tmpltPair : templateZonePairSet2) {
+                    if (!templateZonePairSet.contains(new Pair<Long, Long>(tmpltPair.first(),
-1L))) {
+                        templateZonePairSet.add(tmpltPair);
+                    }
+                }
+            } else {
+                // if template is not public, perform permission check here
+                if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN)
{
+                    Account owner = _accountMgr.getAccount(template.getAccountId());
+                    _accountMgr.checkAccess(caller, null, true, owner);
+                }
+                templateZonePairSet.add(new Pair<Long, Long>(template.getId(), zoneId));
+            }
         } else {
             if (template == null) {
                 templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter,
isIso, hypers, 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/server/src/com/cloud/storage/dao/VMTemplateDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/VMTemplateDao.java b/server/src/com/cloud/storage/dao/VMTemplateDao.java
index 1284ba1..a043a2c 100755
--- a/server/src/com/cloud/storage/dao/VMTemplateDao.java
+++ b/server/src/com/cloud/storage/dao/VMTemplateDao.java
@@ -58,6 +58,10 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>
{
             boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO
domain, Long pageSize, Long startIndex,
             Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account>
permittedAccounts, Account caller, Map<String, String> tags);
 
+    public Set<Pair<Long, Long>> searchS3Templates(String name, String keyword,
TemplateFilter templateFilter,
+            boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO
domain, Long pageSize, Long startIndex,
+            Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account>
permittedAccounts, Account caller, Map<String, String> tags);
+
 	public long addTemplateToZone(VMTemplateVO tmplt, long zoneId);
 	public List<VMTemplateVO> listAllInZone(long dataCenterId);	
 	

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
index 5c71f1b..7ef9c9f 100755
--- a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -16,6 +16,9 @@
 // under the License.
 package com.cloud.storage.dao;
 
+import static com.cloud.utils.StringUtils.*;
+import static com.cloud.utils.db.DbUtil.*;
+
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -93,6 +96,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long>
implem
     private final String SELECT_TEMPLATE_SWIFT_REF = "SELECT t.id, t.unique_name, t.name,
t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
             + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable,
t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
 
+    private final String SELECT_TEMPLATE_S3_REF = "SELECT t.id, t.unique_name, t.name, t.public,
t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
+            + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable,
t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
+
     private static final String SELECT_S3_CANDIDATE_TEMPLATES = "SELECT t.id, t.unique_name,
t.name, t.public, t.featured, " +
         "t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, t.checksum, t.display_text,
" +
         "t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type
" +
@@ -931,4 +937,138 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         return executeList(SELECT_S3_CANDIDATE_TEMPLATES, new Object[] {});
     }
 
+    @Override
+    public Set<Pair<Long, Long>> searchS3Templates(final String name,
+            final String keyword, final TemplateFilter templateFilter,
+            final boolean isIso, final List<HypervisorType> hypers,
+            final Boolean bootable, final DomainVO domain, final Long pageSize,
+            final Long startIndex, final Long zoneId,
+            final HypervisorType hyperType, final boolean onlyReady,
+            final boolean showDomr, final List<Account> permittedAccounts,
+            final Account caller, final Map<String, String> tags) {
+
+        final String permittedAccountsStr = join(",", permittedAccounts);
+
+        final Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        Set<Pair<Long, Long>> templateZonePairList = new HashSet<Pair<Long,
Long>>();
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        try {
+
+            final StringBuilder joinClause = new StringBuilder();
+            final StringBuilder whereClause = new StringBuilder(" WHERE t.removed IS NULL");
+
+            if (isIso) {
+                whereClause.append(" AND t.format = 'ISO'");
+                if (!hyperType.equals(HypervisorType.None)) {
+                    joinClause.append(" INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id)
INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) ");
+                    whereClause.append(" AND goh.hypervisor_type = '");
+                    whereClause.append(hyperType);
+                    whereClause.append("'");
+                }
+            } else {
+                whereClause.append(" AND t.format <> 'ISO'");
+                if (hypers.isEmpty()) {
+                    return templateZonePairList;
+                } else {
+                    final StringBuilder relatedHypers = new StringBuilder();
+                    for (HypervisorType hyper : hypers) {
+                        relatedHypers.append("'");
+                        relatedHypers.append(hyper.toString());
+                        relatedHypers.append("'");
+                        relatedHypers.append(",");
+                    }
+                    relatedHypers.setLength(relatedHypers.length() - 1);
+                    whereClause.append(" AND t.hypervisor_type IN (");
+                    whereClause.append(relatedHypers);
+                    whereClause.append(")");
+                }
+            }
+
+            joinClause.append(" INNER JOIN  template_s3_ref tsr on (t.id = tsr.template_id)");
+
+            whereClause.append("AND t.name LIKE \"%");
+            whereClause.append(keyword == null ? keyword : name);
+            whereClause.append("%\"");
+
+            if (bootable != null) {
+                whereClause.append(" AND t.bootable = ");
+                whereClause.append(bootable);
+            }
+
+            if (!showDomr) {
+                whereClause.append(" AND t.type != '");
+                whereClause.append(Storage.TemplateType.SYSTEM);
+                whereClause.append("'");
+            }
+
+            if (templateFilter == TemplateFilter.featured) {
+                whereClause.append(" AND t.public = 1 AND t.featured = 1");
+            } else if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
+                    && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+                if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN
+                        || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)
{
+                    joinClause.append(" INNER JOIN account a on (t.account_id = a.id) INNER
JOIN domain d on (a.domain_id = d.id)");
+                    whereClause.append("  AND d.path LIKE '");
+                    whereClause.append(domain.getPath());
+                    whereClause.append("%'");
+                } else {
+                    whereClause.append(" AND t.account_id IN (");
+                    whereClause.append(permittedAccountsStr);
+                    whereClause.append(")");
+                }
+            } else if (templateFilter == TemplateFilter.sharedexecutable
+                    && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+                if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
+                    joinClause.append(" LEFT JOIN launch_permission lp ON t.id = lp.template_id
WHERE (t.account_id IN (");
+                    joinClause.append(permittedAccountsStr);
+                    joinClause.append(") OR lp.account_id IN (");
+                    joinClause.append(permittedAccountsStr); 
+                    joinClause.append("))");
+                } else {
+                    joinClause.append(" INNER JOIN account a on (t.account_id = a.id) ");
+                }
+            } else if (templateFilter == TemplateFilter.executable
+                    && !permittedAccounts.isEmpty()) {
+                whereClause.append(" AND (t.public = 1 OR t.account_id IN (");
+                whereClause.append(permittedAccountsStr);
+                whereClause.append("))");
+            } else if (templateFilter == TemplateFilter.community) {
+                whereClause.append(" AND t.public = 1 AND t.featured = 0");
+            } else if (templateFilter == TemplateFilter.all
+                    && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
+            } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+                return templateZonePairList;
+            }
+
+            final StringBuilder sql = new StringBuilder(SELECT_TEMPLATE_S3_REF);
+            sql.append(joinClause);
+            sql.append(whereClause);
+            sql.append(getOrderByLimit(pageSize, startIndex));
+
+            pstmt = txn.prepareStatement(sql.toString());
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                final Pair<Long, Long> templateZonePair = new Pair<Long, Long>(
+                        rs.getLong(1), -1L);
+                templateZonePairList.add(templateZonePair);
+            }
+            txn.commit();
+        } catch (Exception e) {
+            s_logger.warn("Error listing S3 templates", e);
+            if (txn != null) {
+                txn.rollback();
+            }
+        } finally {
+            closeResources(pstmt, rs);
+            if (txn != null) {
+                txn.close();
+            }
+        }
+
+        return templateZonePairList;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/server/src/com/cloud/storage/s3/S3ManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
index 6b07254..0da11ff 100644
--- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java
+++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
@@ -27,7 +27,6 @@ import static com.cloud.utils.S3Utils.checkClientOptions;
 import static com.cloud.utils.S3Utils.doesBucketExist;
 import static com.cloud.utils.StringUtils.join;
 import static com.cloud.utils.db.GlobalLock.executeWithNoWaitLock;
-import static com.cloud.utils.db.SearchCriteria.Op.EQ;
 import static java.lang.Boolean.TRUE;
 import static java.lang.String.format;
 import static java.util.Arrays.asList;
@@ -433,10 +432,6 @@ public class S3ManagerImpl implements S3Manager {
                 cmd.getStartIndex(), cmd.getPageSizeVal());
         final SearchCriteria<S3VO> criteria = this.s3Dao.createSearchCriteria();
 
-        if (cmd.getId() != null) {
-            criteria.addAnd(ID_COLUMN_NAME, EQ, cmd.getId());
-        }
-
         return this.s3Dao.search(criteria, filter);
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/tools/marvin/marvin/cloudstackConnection.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py
index 8c4e325..e8b861e 100644
--- a/tools/marvin/marvin/cloudstackConnection.py
+++ b/tools/marvin/marvin/cloudstackConnection.py
@@ -46,7 +46,6 @@ class cloudConnection(object):
             self.auth = False
         else:
             self.auth = True
-            
         self.retries = 5
         self.asyncTimeout = asyncTimeout
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/tools/marvin/marvin/configGenerator.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py
index 11fbce9..d494beb 100644
--- a/tools/marvin/marvin/configGenerator.py
+++ b/tools/marvin/marvin/configGenerator.py
@@ -180,6 +180,17 @@ class secondaryStorage():
     def __init__(self):
         self.url = None
 
+class s3():
+    def __init__(self):
+        self.accesskey = None
+        self.secretkey = None
+        self.bucket = None
+        self.endpoint = None
+        self.sockettimeout = None
+        self.connectiontimeout = None
+        self.maxerrorrety = None
+        self.usehttps = None
+
 class netscaler():
     def __init__(self, hostname=None, username='nsroot', password='nsroot'):
         self.hostname = hostname

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/tools/marvin/marvin/deployDataCenter.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py
index ba124cb..0d5f3bd 100644
--- a/tools/marvin/marvin/deployDataCenter.py
+++ b/tools/marvin/marvin/deployDataCenter.py
@@ -399,9 +399,11 @@ class deployDataCenters():
                                              logging=self.testClientLogger)
 
         """config database"""
-        #dbSvr = self.config.dbSvr
-        #self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
-        #                            dbSvr.passwd, dbSvr.db)
+        dbSvr = self.config.dbSvr
+        if dbSvr is not None:
+          self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
+                                      dbSvr.passwd, dbSvr.db)
+
         self.apiClient = self.testClient.getApiClient()
 
     def updateConfiguration(self, globalCfg):

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e4583ced/utils/src/com/cloud/utils/db/DbUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/DbUtil.java b/utils/src/com/cloud/utils/db/DbUtil.java
index feef7b3..da0efbb 100755
--- a/utils/src/com/cloud/utils/db/DbUtil.java
+++ b/utils/src/com/cloud/utils/db/DbUtil.java
@@ -23,6 +23,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -280,4 +281,62 @@ public class DbUtil {
         }
         return false;
     }
+
+    public static void closeResources(final Connection connection,
+            final Statement statement, final ResultSet resultSet) {
+
+        closeResultSet(resultSet);
+        closeStatement(statement);
+        closeConnection(connection);
+
+    }
+
+    public static void closeResources(final Statement statement, final ResultSet resultSet)
{
+
+        closeResources(null, statement, resultSet);
+
+    }
+    
+    public static void closeResultSet(final ResultSet resultSet) {
+
+        try {
+            
+            if (resultSet != null) {
+                resultSet.close();
+            }
+
+        } catch (Exception e) {
+            s_logger.warn("Ignored exception while closing result set.",e);
+        }
+
+    }
+
+    public static void closeStatement(final Statement statement) {
+
+        try {
+
+            if (statement != null) {
+                statement.close();
+            }
+
+        } catch (Exception e) {
+            s_logger.warn("Ignored exception while closing statement.",e);
+        }
+
+    }
+
+    public static void closeConnection(final Connection connection) {
+
+        try {
+
+            if (connection != null) {
+                connection.close();
+            }
+
+        } catch (Exception e) {
+            s_logger.warn("Ignored exception while close connection.",e);
+        }
+
+    }
+
 }


Mime
View raw message