mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	add guid in cluster table
This commit is contained in:
		
							parent
							
								
									8a002527de
								
							
						
					
					
						commit
						6419e49977
					
				| @ -247,7 +247,7 @@ public class XenServerConnectionPool { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public Connection slaveConnect(String ip, String username, String password) { |     static public Connection slaveConnect(String ip, String username, String password) { | ||||||
|         Connection conn = null; |         Connection conn = null; | ||||||
|         try{  |         try{  | ||||||
|             conn = new Connection(getURL(ip), 100); |             conn = new Connection(getURL(ip), 100); | ||||||
| @ -579,7 +579,7 @@ public class XenServerConnectionPool { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static private Pool.Record getPoolRecord(Connection conn) |     static public Pool.Record getPoolRecord(Connection conn) | ||||||
|             throws XmlRpcException, XenAPIException { |             throws XmlRpcException, XenAPIException { | ||||||
|         Map<Pool, Pool.Record> pools = Pool.getAllRecords(conn); |         Map<Pool, Pool.Record> pools = Pool.getAllRecords(conn); | ||||||
|         assert pools.size() == 1 : "Pool size is not one....hmmm....wth? " |         assert pools.size() == 1 : "Pool size is not one....hmmm....wth? " | ||||||
|  | |||||||
| @ -42,6 +42,9 @@ public class ClusterVO implements Cluster { | |||||||
|     @Column(name="name") |     @Column(name="name") | ||||||
|     String name; |     String name; | ||||||
|      |      | ||||||
|  |     @Column(name="guid") | ||||||
|  |     String guid; | ||||||
|  |      | ||||||
|     @Column(name="data_center_id") |     @Column(name="data_center_id") | ||||||
|     long dataCenterId; |     long dataCenterId; | ||||||
|      |      | ||||||
| @ -112,7 +115,16 @@ public class ClusterVO implements Cluster { | |||||||
|     	return HypervisorType.getType(hypervisorType); |     	return HypervisorType.getType(hypervisorType); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setHypervisorType(String hy) { | 	public void setHypervisorType(String hy) { | ||||||
|     	hypervisorType = hy; |     	hypervisorType = hy; | ||||||
|     } |     } | ||||||
|  | 	 | ||||||
|  |     public String getGuid() { | ||||||
|  |         return guid; | ||||||
|  |     } | ||||||
|  | 	 | ||||||
|  |     public void setGuid(String guid) { | ||||||
|  |         this.guid = guid; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -25,4 +25,5 @@ import com.cloud.utils.db.GenericDao; | |||||||
| public interface ClusterDao extends GenericDao<ClusterVO, Long> { | public interface ClusterDao extends GenericDao<ClusterVO, Long> { | ||||||
|     List<ClusterVO> listByPodId(long podId); |     List<ClusterVO> listByPodId(long podId); | ||||||
|     ClusterVO findBy(String name, long podId); |     ClusterVO findBy(String name, long podId); | ||||||
|  |     List<ClusterVO> listByHyTypeWithoutGuid(String hyType); | ||||||
| } | } | ||||||
|  | |||||||
| @ -30,10 +30,15 @@ import com.cloud.utils.db.SearchCriteria; | |||||||
| public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao { | public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao { | ||||||
| 
 | 
 | ||||||
|     protected final SearchBuilder<ClusterVO> PodSearch; |     protected final SearchBuilder<ClusterVO> PodSearch; | ||||||
|      |     protected final SearchBuilder<ClusterVO> HyTypeWithoutGuidSearch; | ||||||
|     protected ClusterDaoImpl() { |     protected ClusterDaoImpl() { | ||||||
|         super(); |         super(); | ||||||
|          |          | ||||||
|  |         HyTypeWithoutGuidSearch = createSearchBuilder(); | ||||||
|  |         HyTypeWithoutGuidSearch.and("hypervisorType", HyTypeWithoutGuidSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); | ||||||
|  |         HyTypeWithoutGuidSearch.and("guid", HyTypeWithoutGuidSearch.entity().getGuid(), SearchCriteria.Op.NULL); | ||||||
|  |         HyTypeWithoutGuidSearch.done(); | ||||||
|  |          | ||||||
|         PodSearch = createSearchBuilder(); |         PodSearch = createSearchBuilder(); | ||||||
|         PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); |         PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); | ||||||
|         PodSearch.and("name", PodSearch.entity().getName(), SearchCriteria.Op.EQ); |         PodSearch.and("name", PodSearch.entity().getName(), SearchCriteria.Op.EQ); | ||||||
| @ -56,4 +61,12 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C | |||||||
|          |          | ||||||
|         return findOneBy(sc); |         return findOneBy(sc); | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public List<ClusterVO> listByHyTypeWithoutGuid(String hyType) { | ||||||
|  |         SearchCriteria<ClusterVO> sc = HyTypeWithoutGuidSearch.create(); | ||||||
|  |         sc.setParameters("hypervisorType", hyType); | ||||||
|  |          | ||||||
|  |         return listBy(sc); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -156,6 +156,17 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
|             Pool.Record pr = pool.getRecord(conn); |             Pool.Record pr = pool.getRecord(conn); | ||||||
|             poolUuid = pr.uuid; |             poolUuid = pr.uuid; | ||||||
|             Host master = pr.master; |             Host master = pr.master; | ||||||
|  | 
 | ||||||
|  |             /*set cluster hypervisor type to xenserver*/ | ||||||
|  |             ClusterVO clu = _clusterDao.findById(clusterId); | ||||||
|  |             if ( HypervisorType.None == clu.getHypervisorType() ) { | ||||||
|  |             	clu.setHypervisorType(HypervisorType.XenServer.toString()); | ||||||
|  |             } | ||||||
|  |             if ( clu.getClusterType() == null ) { | ||||||
|  |             	clu.setGuid(poolUuid); | ||||||
|  |             } | ||||||
|  |             _clusterDao.update(clusterId, clu); | ||||||
|  |              | ||||||
|             LinkedHashMap<Host, Host.Record> hosts = new LinkedHashMap<Host, Host.Record>(20); |             LinkedHashMap<Host, Host.Record> hosts = new LinkedHashMap<Host, Host.Record>(20); | ||||||
|             hosts.put(master, master.getRecord(conn)); |             hosts.put(master, master.getRecord(conn)); | ||||||
|             Map<Host, Host.Record> thosts = Host.getAllRecords(conn); |             Map<Host, Host.Record> thosts = Host.getAllRecords(conn); | ||||||
| @ -164,7 +175,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
|                     hosts.put(entry.getKey(), entry.getValue()); |                     hosts.put(entry.getKey(), entry.getValue()); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|                         |                                     | ||||||
|             if (_checkHvm) { |             if (_checkHvm) { | ||||||
|                 for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) { |                 for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) { | ||||||
|                     Host.Record record = entry.getValue(); |                     Host.Record record = entry.getValue(); | ||||||
| @ -269,12 +280,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
|             if (!addHostsToPool(url, conn, dcId, podId, clusterId, resources)) { |             if (!addHostsToPool(url, conn, dcId, podId, clusterId, resources)) { | ||||||
|                 return null; |                 return null; | ||||||
|             } |             } | ||||||
|              |                          | ||||||
|             /*set cluster hypervisor type to xenserver*/ |  | ||||||
|             ClusterVO clu = _clusterDao.findById(clusterId); |  | ||||||
|             clu.setHypervisorType(HypervisorType.XenServer.toString()); |  | ||||||
|             _clusterDao.update(clusterId, clu); |  | ||||||
|              |  | ||||||
|         } catch (SessionAuthenticationFailed e) { |         } catch (SessionAuthenticationFailed e) { | ||||||
|             s_logger.warn("Authentication error", e);            |             s_logger.warn("Authentication error", e);            | ||||||
|             return null; |             return null; | ||||||
| @ -511,7 +517,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L | |||||||
|     public boolean processCommands(long agentId, long seq, Command[] commands) { |     public boolean processCommands(long agentId, long seq, Command[] commands) { | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|      |    | ||||||
|     private void createXsToolsISO() { |     private void createXsToolsISO() { | ||||||
|         String isoName = "xs-tools.iso"; |         String isoName = "xs-tools.iso"; | ||||||
|         VMTemplateVO tmplt = _tmpltDao.findByTemplateName(isoName); |         VMTemplateVO tmplt = _tmpltDao.findByTemplateName(isoName); | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package com.cloud.migration; | package com.cloud.migration; | ||||||
| 
 | 
 | ||||||
| import java.io.File; | import java.io.File; | ||||||
|  | import java.net.InetAddress; | ||||||
| import java.sql.PreparedStatement; | import java.sql.PreparedStatement; | ||||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @ -12,11 +13,17 @@ import com.cloud.configuration.ConfigurationVO; | |||||||
| import com.cloud.configuration.ResourceCountVO; | import com.cloud.configuration.ResourceCountVO; | ||||||
| import com.cloud.configuration.dao.ConfigurationDao; | import com.cloud.configuration.dao.ConfigurationDao; | ||||||
| import com.cloud.configuration.dao.ResourceCountDao; | import com.cloud.configuration.dao.ResourceCountDao; | ||||||
|  | import com.cloud.dc.ClusterVO; | ||||||
| import com.cloud.dc.DataCenterVO; | import com.cloud.dc.DataCenterVO; | ||||||
| import com.cloud.dc.DataCenter.NetworkType; | import com.cloud.dc.DataCenter.NetworkType; | ||||||
|  | import com.cloud.dc.dao.ClusterDao; | ||||||
| import com.cloud.dc.dao.DataCenterDao; | import com.cloud.dc.dao.DataCenterDao; | ||||||
| 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.host.HostVO; | ||||||
|  | import com.cloud.host.dao.HostDao; | ||||||
|  | import com.cloud.hypervisor.Hypervisor.HypervisorType; | ||||||
|  | import com.cloud.hypervisor.xen.resource.XenServerConnectionPool; | ||||||
| import com.cloud.user.Account; | import com.cloud.user.Account; | ||||||
| import com.cloud.user.dao.AccountDao; | import com.cloud.user.dao.AccountDao; | ||||||
| import com.cloud.utils.PropertiesUtil; | import com.cloud.utils.PropertiesUtil; | ||||||
| @ -29,8 +36,13 @@ import com.cloud.vm.InstanceGroupVMMapVO; | |||||||
| import com.cloud.vm.InstanceGroupVO; | import com.cloud.vm.InstanceGroupVO; | ||||||
| import com.cloud.vm.dao.InstanceGroupDao; | import com.cloud.vm.dao.InstanceGroupDao; | ||||||
| import com.cloud.vm.dao.InstanceGroupVMMapDao; | import com.cloud.vm.dao.InstanceGroupVMMapDao; | ||||||
|  | import com.xensource.xenapi.Connection; | ||||||
|  | import com.xensource.xenapi.Pool; | ||||||
|  | import com.xensource.xenapi.Session; | ||||||
| 
 | 
 | ||||||
| public class Db21to22MigrationUtil { | public class Db21to22MigrationUtil { | ||||||
|  |     private ClusterDao _clusterDao; | ||||||
|  |     private HostDao _hostDao; | ||||||
|     private AccountDao _accountDao; |     private AccountDao _accountDao; | ||||||
|     private DomainDao _domainDao; |     private DomainDao _domainDao; | ||||||
|     private ResourceCountDao _resourceCountDao; |     private ResourceCountDao _resourceCountDao; | ||||||
| @ -48,9 +60,45 @@ public class Db21to22MigrationUtil { | |||||||
| 
 | 
 | ||||||
|         migrateZones(); |         migrateZones(); | ||||||
|          |          | ||||||
|  |         setupClusterGuid(); | ||||||
|  |          | ||||||
|         System.out.println("Migration done"); |         System.out.println("Migration done"); | ||||||
|     } |     } | ||||||
| 
 |      | ||||||
|  |     /* add guid in cluster table */ | ||||||
|  |     private void setupClusterGuid() { | ||||||
|  |         List<ClusterVO> clusters = _clusterDao.listByHyTypeWithoutGuid(HypervisorType.XenServer.toString()); | ||||||
|  |         for (ClusterVO cluster : clusters) { | ||||||
|  |             List<HostVO> hosts = _hostDao.listByCluster(cluster.getId()); | ||||||
|  |             for (HostVO host : hosts) { | ||||||
|  |                 String ip = host.getPrivateIpAddress(); | ||||||
|  |                 String username = host.getDetail("username"); | ||||||
|  |                 String password = host.getDetail("password"); | ||||||
|  |                 if (ip == null || ip.isEmpty() || username == null || username.isEmpty() || password == null | ||||||
|  |                         || password.isEmpty()) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |                 Connection conn = XenServerConnectionPool.slaveConnect(ip, username, password); | ||||||
|  |                 if (conn == null) | ||||||
|  |                     continue; | ||||||
|  |                 Pool.Record pr = null; | ||||||
|  |                 try { | ||||||
|  |                     pr = XenServerConnectionPool.getPoolRecord(conn); | ||||||
|  |                 } catch (Exception e) { | ||||||
|  |                     continue; | ||||||
|  |                 } finally { | ||||||
|  |                     try { | ||||||
|  |                         Session.localLogout(conn); | ||||||
|  |                     } catch (Exception e) { | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 cluster.setGuid(pr.uuid); | ||||||
|  |                 _clusterDao.update(cluster.getId(), cluster); | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     }       | ||||||
|  |      | ||||||
|     /** |     /** | ||||||
|      * This method migrates the zones based on bug: 7204 |      * This method migrates the zones based on bug: 7204 | ||||||
|      * based on the param direct.attach.untagged.vlan.enabled, we update zone to basic or advanced for 2.2 |      * based on the param direct.attach.untagged.vlan.enabled, we update zone to basic or advanced for 2.2 | ||||||
|  | |||||||
| @ -217,6 +217,7 @@ CREATE TABLE `cloud`.`network_offerings` ( | |||||||
| CREATE TABLE `cloud`.`cluster` ( | CREATE TABLE `cloud`.`cluster` ( | ||||||
|   `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', |   `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', | ||||||
|   `name` varchar(255) NOT NULL COMMENT 'name for the cluster', |   `name` varchar(255) NOT NULL COMMENT 'name for the cluster', | ||||||
|  |   `guid` varchar(255) UNIQUE DEFAULT NULL COMMENT 'guid for the cluster', | ||||||
|   `pod_id` bigint unsigned NOT NULL COMMENT 'pod id', |   `pod_id` bigint unsigned NOT NULL COMMENT 'pod id', | ||||||
|   `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id', |   `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id', | ||||||
|   `hypervisor_type` varchar(255), |   `hypervisor_type` varchar(255), | ||||||
|  | |||||||
| @ -5,7 +5,8 @@ SET foreign_key_checks = 0; | |||||||
| -- | -- | ||||||
| ALTER TABLE `cloud`.`template_host_ref` ADD COLUMN `physical_size` bigint unsigned NOT NULL DEFAULT 0 | ALTER TABLE `cloud`.`template_host_ref` ADD COLUMN `physical_size` bigint unsigned NOT NULL DEFAULT 0 | ||||||
| ALTER TABLE `cloud`.`snapshots` MODIFY COLUMN `id` bigint unsigned UNIQUE NOT NULL | ALTER TABLE `cloud`.`snapshots` MODIFY COLUMN `id` bigint unsigned UNIQUE NOT NULL | ||||||
| ALTER TABLE `vm_instance` DROP COLUMN `group` | ALTER TABLE `cloud`.`vm_instance` DROP COLUMN `group` | ||||||
|  | ALTER TABLE `cloud`.`cluster` ADD COLUMN `guid` varchar(255) UNIQUE DEFAULT NULL | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| -- NOTE for tables below | -- NOTE for tables below | ||||||
| @ -16,4 +17,3 @@ ALTER TABLE `vm_instance` DROP COLUMN `group` | |||||||
| -- network_group_vm_map table --> security_group_vm_map table | -- network_group_vm_map table --> security_group_vm_map table | ||||||
| DROP TABLE `cloud`.`security_group`; | DROP TABLE `cloud`.`security_group`; | ||||||
| DROP TABLE `cloud`.`security_group_vm_map`; | DROP TABLE `cloud`.`security_group_vm_map`; | ||||||
| --END NOTE |  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user