mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	S3-backed Secondary Storage
This commit is contained in:
		
							parent
							
								
									3d2fefabdd
								
							
						
					
					
						commit
						e4583ced2e
					
				| @ -18,15 +18,11 @@ | |||||||
|  */ |  */ | ||||||
| package com.cloud.api.commands; | 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.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import com.cloud.api.BaseListCmd; | import com.cloud.api.BaseListCmd; | ||||||
| import com.cloud.api.Implementation; | import com.cloud.api.Implementation; | ||||||
| import com.cloud.api.Parameter; |  | ||||||
| import com.cloud.api.ServerApiException; | import com.cloud.api.ServerApiException; | ||||||
| import com.cloud.api.response.ListResponse; | import com.cloud.api.response.ListResponse; | ||||||
| import com.cloud.api.response.S3Response; | import com.cloud.api.response.S3Response; | ||||||
| @ -42,9 +38,6 @@ public final class ListS3sCmd extends BaseListCmd { | |||||||
| 
 | 
 | ||||||
|     private static final String COMMAND_NAME = "lists3sresponse"; |     private static final String COMMAND_NAME = "lists3sresponse"; | ||||||
| 
 | 
 | ||||||
|     @Parameter(name = ID, type = LONG, required = true, description = "The ID of the S3") |  | ||||||
|     private Long id; |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public void execute() throws ResourceUnavailableException, InsufficientCapacityException, |     public void execute() throws ResourceUnavailableException, InsufficientCapacityException, | ||||||
|             ServerApiException, ConcurrentOperationException, ResourceAllocationException, |             ServerApiException, ConcurrentOperationException, ResourceAllocationException, | ||||||
| @ -74,39 +67,9 @@ 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 |     @Override | ||||||
|     public String getCommandName() { |     public String getCommandName() { | ||||||
|         return COMMAND_NAME; |         return COMMAND_NAME; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Long getId() { |  | ||||||
|         return this.id; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -217,6 +217,10 @@ | |||||||
|         <include name="discovery-*.jar" /> |         <include name="discovery-*.jar" /> | ||||||
|         <include name="wsdl4j-*.jar" /> |         <include name="wsdl4j-*.jar" /> | ||||||
|         <include name="ejb-api-3.0.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> | ||||||
|       <zipfileset dir="${jar.dir}"> |       <zipfileset dir="${jar.dir}"> | ||||||
|         <include name="${agent.jar}" /> |         <include name="${agent.jar}" /> | ||||||
|  | |||||||
| @ -16,35 +16,110 @@ | |||||||
| // under the License. | // under the License. | ||||||
| package com.cloud.configuration; | 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.acl.SecurityChecker; | ||||||
| import com.cloud.alert.AlertManager; | import com.cloud.alert.AlertManager; | ||||||
| import com.cloud.api.ApiConstants.LDAPParams; | import com.cloud.api.ApiConstants.LDAPParams; | ||||||
| import com.cloud.api.ApiDBUtils; | 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.capacity.dao.CapacityDao; | ||||||
| import com.cloud.configuration.Resource.ResourceType; | import com.cloud.configuration.Resource.ResourceType; | ||||||
| import com.cloud.configuration.dao.ConfigurationDao; | 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.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.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.deploy.DataCenterDeployment; | ||||||
| import com.cloud.domain.Domain; | import com.cloud.domain.Domain; | ||||||
| import com.cloud.domain.DomainVO; | import com.cloud.domain.DomainVO; | ||||||
| import com.cloud.domain.dao.DomainDao; | import com.cloud.domain.dao.DomainDao; | ||||||
| import com.cloud.event.ActionEvent; | import com.cloud.event.ActionEvent; | ||||||
| import com.cloud.event.EventTypes; | 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.host.HostVO; | ||||||
| import com.cloud.hypervisor.Hypervisor.HypervisorType; | 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.Capability; | ||||||
| import com.cloud.network.Network.GuestType; | import com.cloud.network.Network.GuestType; | ||||||
| import com.cloud.network.Network.Provider; | import com.cloud.network.Network.Provider; | ||||||
| import com.cloud.network.Network.Service; | 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.BroadcastDomainType; | ||||||
| import com.cloud.network.Networks.TrafficType; | 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.network.vpc.VpcManager; | ||||||
| import com.cloud.offering.DiskOffering; | import com.cloud.offering.DiskOffering; | ||||||
| import com.cloud.offering.NetworkOffering; | 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.secondary.SecondaryStorageVmManager; | ||||||
| import com.cloud.storage.swift.SwiftManager; | import com.cloud.storage.swift.SwiftManager; | ||||||
| import com.cloud.test.IPRangeConfig; | 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.user.dao.AccountDao; | ||||||
| import com.cloud.utils.NumbersUtil; | import com.cloud.utils.NumbersUtil; | ||||||
| import com.cloud.utils.StringUtils; | import com.cloud.utils.StringUtils; | ||||||
| @ -85,20 +165,8 @@ import com.cloud.utils.exception.CloudRuntimeException; | |||||||
| import com.cloud.utils.net.NetUtils; | import com.cloud.utils.net.NetUtils; | ||||||
| import com.cloud.vm.VirtualMachine; | import com.cloud.vm.VirtualMachine; | ||||||
| import com.cloud.vm.dao.NicDao; | import com.cloud.vm.dao.NicDao; | ||||||
| import edu.emory.mathcs.backport.java.util.Arrays; |  | ||||||
| import org.apache.log4j.Logger; |  | ||||||
| 
 | 
 | ||||||
| import javax.ejb.Local; | import edu.emory.mathcs.backport.java.util.Arrays; | ||||||
| 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.*; |  | ||||||
| 
 | 
 | ||||||
| @Local(value = { ConfigurationManager.class, ConfigurationService.class }) | @Local(value = { ConfigurationManager.class, ConfigurationService.class }) | ||||||
| public class ConfigurationManagerImpl implements ConfigurationManager, ConfigurationService { | public class ConfigurationManagerImpl implements ConfigurationManager, ConfigurationService { | ||||||
|  | |||||||
| @ -203,6 +203,7 @@ import com.cloud.storage.dao.StoragePoolDao; | |||||||
| import com.cloud.storage.dao.UploadDao; | import com.cloud.storage.dao.UploadDao; | ||||||
| import com.cloud.storage.dao.VMTemplateDao; | import com.cloud.storage.dao.VMTemplateDao; | ||||||
| import com.cloud.storage.dao.VolumeDao; | import com.cloud.storage.dao.VolumeDao; | ||||||
|  | import com.cloud.storage.s3.S3Manager; | ||||||
| import com.cloud.storage.secondary.SecondaryStorageVmManager; | import com.cloud.storage.secondary.SecondaryStorageVmManager; | ||||||
| import com.cloud.storage.snapshot.SnapshotManager; | import com.cloud.storage.snapshot.SnapshotManager; | ||||||
| import com.cloud.storage.swift.SwiftManager; | import com.cloud.storage.swift.SwiftManager; | ||||||
| @ -292,6 +293,7 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|     private final ConsoleProxyManager _consoleProxyMgr; |     private final ConsoleProxyManager _consoleProxyMgr; | ||||||
|     private final SecondaryStorageVmManager _secStorageVmMgr; |     private final SecondaryStorageVmManager _secStorageVmMgr; | ||||||
|     private final SwiftManager _swiftMgr; |     private final SwiftManager _swiftMgr; | ||||||
|  |     private final S3Manager _s3Mgr; | ||||||
|     private final ServiceOfferingDao _offeringsDao; |     private final ServiceOfferingDao _offeringsDao; | ||||||
|     private final DiskOfferingDao _diskOfferingDao; |     private final DiskOfferingDao _diskOfferingDao; | ||||||
|     private final VMTemplateDao _templateDao; |     private final VMTemplateDao _templateDao; | ||||||
| @ -370,6 +372,7 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|         _consoleProxyMgr = locator.getManager(ConsoleProxyManager.class); |         _consoleProxyMgr = locator.getManager(ConsoleProxyManager.class); | ||||||
|         _secStorageVmMgr = locator.getManager(SecondaryStorageVmManager.class); |         _secStorageVmMgr = locator.getManager(SecondaryStorageVmManager.class); | ||||||
|         _swiftMgr = locator.getManager(SwiftManager.class); |         _swiftMgr = locator.getManager(SwiftManager.class); | ||||||
|  |         _s3Mgr = locator.getManager(S3Manager.class); | ||||||
|         _storageMgr = locator.getManager(StorageManager.class); |         _storageMgr = locator.getManager(StorageManager.class); | ||||||
|         _publicIpAddressDao = locator.getDao(IPAddressDao.class); |         _publicIpAddressDao = locator.getDao(IPAddressDao.class); | ||||||
|         _consoleProxyDao = locator.getDao(ConsoleProxyDao.class); |         _consoleProxyDao = locator.getDao(ConsoleProxyDao.class); | ||||||
| @ -1399,6 +1402,29 @@ public class ManagementServerImpl implements ManagementServer { | |||||||
|                 } |                 } | ||||||
|                 templateZonePairSet.add(new Pair<Long, Long>(template.getId(), zoneId)); |                 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 { |         } else { | ||||||
|             if (template == null) { |             if (template == null) { | ||||||
|                 templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers,  |                 templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, hypers,  | ||||||
|  | |||||||
| @ -58,6 +58,10 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> { | |||||||
|             boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, |             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); |             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 long addTemplateToZone(VMTemplateVO tmplt, long zoneId); | ||||||
| 	public List<VMTemplateVO> listAllInZone(long dataCenterId);	 | 	public List<VMTemplateVO> listAllInZone(long dataCenterId);	 | ||||||
| 	 | 	 | ||||||
|  | |||||||
| @ -16,6 +16,9 @@ | |||||||
| // under the License. | // under the License. | ||||||
| package com.cloud.storage.dao; | 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.PreparedStatement; | ||||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||||
| import java.sql.SQLException; | 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, " |     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"; |             + "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, " + |     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.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 " + |         "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[] {}); |         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; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -27,7 +27,6 @@ import static com.cloud.utils.S3Utils.checkClientOptions; | |||||||
| import static com.cloud.utils.S3Utils.doesBucketExist; | import static com.cloud.utils.S3Utils.doesBucketExist; | ||||||
| import static com.cloud.utils.StringUtils.join; | import static com.cloud.utils.StringUtils.join; | ||||||
| import static com.cloud.utils.db.GlobalLock.executeWithNoWaitLock; | 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.Boolean.TRUE; | ||||||
| import static java.lang.String.format; | import static java.lang.String.format; | ||||||
| import static java.util.Arrays.asList; | import static java.util.Arrays.asList; | ||||||
| @ -433,10 +432,6 @@ public class S3ManagerImpl implements S3Manager { | |||||||
|                 cmd.getStartIndex(), cmd.getPageSizeVal()); |                 cmd.getStartIndex(), cmd.getPageSizeVal()); | ||||||
|         final SearchCriteria<S3VO> criteria = this.s3Dao.createSearchCriteria(); |         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); |         return this.s3Dao.search(criteria, filter); | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -46,7 +46,6 @@ class cloudConnection(object): | |||||||
|             self.auth = False |             self.auth = False | ||||||
|         else: |         else: | ||||||
|             self.auth = True |             self.auth = True | ||||||
|              |  | ||||||
|         self.retries = 5 |         self.retries = 5 | ||||||
|         self.asyncTimeout = asyncTimeout |         self.asyncTimeout = asyncTimeout | ||||||
|      |      | ||||||
|  | |||||||
| @ -180,6 +180,17 @@ class secondaryStorage(): | |||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.url = None |         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(): | class netscaler(): | ||||||
|     def __init__(self, hostname=None, username='nsroot', password='nsroot'): |     def __init__(self, hostname=None, username='nsroot', password='nsroot'): | ||||||
|         self.hostname = hostname |         self.hostname = hostname | ||||||
|  | |||||||
| @ -399,9 +399,11 @@ class deployDataCenters(): | |||||||
|                                              logging=self.testClientLogger) |                                              logging=self.testClientLogger) | ||||||
| 
 | 
 | ||||||
|         """config database""" |         """config database""" | ||||||
|         #dbSvr = self.config.dbSvr |         dbSvr = self.config.dbSvr | ||||||
|         #self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \ |         if dbSvr is not None: | ||||||
|         #                            dbSvr.passwd, dbSvr.db) |           self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \ | ||||||
|  |                                       dbSvr.passwd, dbSvr.db) | ||||||
|  | 
 | ||||||
|         self.apiClient = self.testClient.getApiClient() |         self.apiClient = self.testClient.getApiClient() | ||||||
| 
 | 
 | ||||||
|     def updateConfiguration(self, globalCfg): |     def updateConfiguration(self, globalCfg): | ||||||
|  | |||||||
| @ -23,6 +23,7 @@ import java.sql.Connection; | |||||||
| import java.sql.PreparedStatement; | import java.sql.PreparedStatement; | ||||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||||
| import java.sql.SQLException; | import java.sql.SQLException; | ||||||
|  | import java.sql.Statement; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| @ -280,4 +281,62 @@ public class DbUtil { | |||||||
|         } |         } | ||||||
|         return false; |         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); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user