diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 2b85b625fae..0a6f1615fa2 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -24,6 +24,11 @@ import java.util.Date; * offered. */ public interface ServiceOffering { + public static final String consoleProxyDefaultOffUniqueName = "Cloud.com-ConsoleProxy"; + public static final String ssvmDefaultOffUniqueName = "Cloud.com-SecondaryStorage"; + public static final String routerDefaultOffUniqueName = "Cloud.Com-SoftwareRouter"; + public static final String elbVmDefaultOffUniqueName = "Cloud.Com-ElasticLBVm"; + public enum StorageType { local, shared diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 308d98a77bf..400259aa704 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -728,7 +728,7 @@ public class ApiDBUtils { } public static long findDefaultRouterServiceOffering() { - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName("Cloud.Com-SoftwareRouter"); + ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName); return serviceOffering.getId(); } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 337279d76c7..6290f872cb6 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -402,7 +402,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + ", need to update System VM offerings"); } boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key())); - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName("Cloud.com-ConsoleProxy"); + ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.consoleProxyDefaultOffUniqueName); if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { @@ -410,7 +410,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - serviceOffering = _serviceOfferingDao.findByName("Cloud.Com-SoftwareRouter"); + serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName); if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { @@ -418,7 +418,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } } - serviceOffering = _serviceOfferingDao.findByName("Cloud.com-SecondaryStorage"); + serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.ssvmDefaultOffUniqueName); if (serviceOffering != null) { serviceOffering.setUseLocalStorage(useLocalStorage); if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) { @@ -447,7 +447,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (value == null) { return _configDao.findByName(name); } - + if (value.trim().isEmpty() || value.equals("null")) { value = null; } @@ -463,7 +463,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } private String validateConfigurationValue(String name, String value) { - + Config c = Config.getConfig(name); if (c == null) { s_logger.error("Missing configuration variable " + name + " in configuration table"); @@ -471,7 +471,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } Class type = c.getType(); - + if (value == null) { if (type.equals(Boolean.class)) { return "Please enter either 'true' or 'false'."; @@ -479,7 +479,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura return null; } value = value.trim(); - + if (type.equals(Boolean.class)) { if (!(value.equals("true") || value.equals("false"))) { s_logger.error("Configuration variable " + name + " is expecting true or false in stead of " + value); @@ -1253,7 +1253,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura _configDao.expunge(LDAPParams.passwd.toString()); _configDao.expunge(LDAPParams.truststore.toString()); _configDao.expunge(LDAPParams.truststorepass.toString()); - return true; + return true; } @Override @@ -1274,7 +1274,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (bindDN != null && bindPasswd == null) { throw new InvalidParameterValueException("If you specify a bind name then you need to provide bind password too."); } - + // check if the info is correct Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); @@ -1282,15 +1282,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (new Boolean(useSSL)) { env.put(Context.SECURITY_PROTOCOL, "ssl"); protocol = "ldaps://"; - if (trustStore == null || trustStorePassword==null ){ - throw new InvalidParameterValueException("If you plan to use SSL then you need to configure the trust store."); + if (trustStore == null || trustStorePassword == null) { + throw new InvalidParameterValueException("If you plan to use SSL then you need to configure the trust store."); } System.setProperty("javax.net.ssl.trustStore", trustStore); System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); } env.put(Context.PROVIDER_URL, protocol + hostname + ":" + port); if (bindDN != null && bindPasswd != null) { - env.put(Context.SECURITY_AUTHENTICATION, "simple"); + env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, bindDN); env.put(Context.SECURITY_CREDENTIALS, bindPasswd); } @@ -1363,7 +1363,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } cvo.setValue(DBEncryptionUtil.encrypt(trustStorePassword)); _configDao.persist(cvo); - + s_logger.debug("The ldap server is configured: " + hostname); } catch (NamingException ne) { ne.printStackTrace(); @@ -1371,8 +1371,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } return true; } - - + @Override @DB @ActionEvent(eventType = EventTypes.EVENT_ZONE_EDIT, eventDescription = "editing zone", async = false) @@ -3138,7 +3137,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (provider == Provider.JuniperSRX) { isSrx = true; } - + providers.add(provider); Set serviceSet = null; @@ -3186,9 +3185,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap); serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap); serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap); - - //if Firewall service is missing, and Juniper is a provider for any other service, add Firewall service/provider combination - if (isSrx) { + + // if Firewall service is missing, and Juniper is a provider for any other service, add Firewall +// service/provider combination + if (isSrx) { s_logger.debug("Adding Firewall service with provider " + Provider.JuniperSRX.getName()); Set firewallProvider = new HashSet(); firewallProvider.add(Provider.JuniperSRX); @@ -3510,11 +3510,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (id != null) { sc.addAnd("id", SearchCriteria.Op.EQ, id); } - + if (tags != null) { sc.addAnd("tags", SearchCriteria.Op.EQ, tags); } - + if (isTagged != null) { if (isTagged) { sc.addAnd("tags", SearchCriteria.Op.NNULL); @@ -3531,7 +3531,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura List pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest); if (pNtwks.size() > 1) { checkForTags = true; - //go through tags + // go through tags for (PhysicalNetworkVO pNtwk : pNtwks) { List pNtwkTag = pNtwk.getTags(); if (pNtwkTag == null || pNtwkTag.isEmpty()) { @@ -3568,13 +3568,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura for (NetworkOfferingVO offering : offerings) { boolean addOffering = true; List checkForProviders = new ArrayList(); - + if (checkForTags) { if (!pNtwkTags.contains(offering.getTags())) { continue; } } - + if (listBySupportedServices) { addOffering = addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices); } @@ -3592,14 +3592,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (sourceNatSupported != null) { addOffering = addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported); } - - if (addOffering) { supportedOfferings.add(offering); } - - + } return supportedOfferings; @@ -3626,12 +3623,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (offering.isDefault() == true) { throw new InvalidParameterValueException("Default network offering can't be deleted"); } - - //don't allow to delete network offering if it's in use by existing networks (the offering can be disabled though) + + // don't allow to delete network offering if it's in use by existing networks (the offering can be disabled +// though) int networkCount = _networkDao.getNetworkCountByNetworkOffId(offeringId); if (networkCount > 0) { throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + networkCount + " networks. " + - "To make the network offering unavaiable, disable it"); + "To make the network offering unavaiable, disable it"); } if (_networkOfferingDao.remove(offeringId)) { diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 66eadd837a8..b2a8a76bfa8 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -88,6 +88,7 @@ import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.NetworkDao; +import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.resource.ResourceManager; @@ -209,7 +210,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Inject UserVmDetailsDao _vmDetailsDao; @Inject - ResourceManager _resourceMgr; + ResourceManager _resourceMgr; @Inject IdentityDao _identityDao; @Inject @@ -222,14 +223,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx NetworkOfferingVO _publicNetworkOffering; NetworkOfferingVO _managementNetworkOffering; NetworkOfferingVO _linkLocalNetworkOffering; - @Inject private VirtualMachineManager _itMgr; -/* - private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new NamedThreadFactory("Request-handler")); -*/ + /* + * private final ExecutorService _requestHandlerScheduler = Executors.newCachedThreadPool(new + * NamedThreadFactory("Request-handler")); + */ private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL; private int _capacityPerProxy = ConsoleProxyManager.DEFAULT_PROXY_CAPACITY; private int _standbyCapacity = ConsoleProxyManager.DEFAULT_STANDBY_CAPACITY; @@ -252,166 +253,186 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx private final GlobalLock _allocProxyLock = GlobalLock.getInternLock(getAllocProxyLockName()); -/* - private final String keyContent = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALV5vGlkiWwoZX4hTRplPXP8qtST\n" - + "hwZhko8noeY5vf8ECwmd+vrCTw/JvnOtkx/8oYNbg/SeUt1EfOsk6gqJdBblGFBZRMcUJlIpqE9z\n" + "uv68U9G8Gfi/qvRSY336hibw0J5bZ4vn1QqmyHDB+Czea9AjFUV7AEVG15+vED7why+/AgMBAAEC\n" - + "gYBmFBPnNKYYMKDmUdUNA+WNWJK/ADzzWe8WlzR6TACTcbLDthl289WFC/YVG42mcHRpbxDKiEQU\n" + "MnIR0rHTO34Qb/2HcuyweStU2gqR6omxBvMnFpJr90nD1HcOMJzeLHsphau0/EmKKey+gk4PyieD\n" - + "KqTM7LTjjHv8xPM4n+WAAQJBAOMNCeFKlJ4kMokWhU74B5/w/NGyT1BHUN0VmilHSiJC8JqS4BiI\n" + "ZpAeET3VmilO6QTGh2XVhEDGteu3uZR6ipUCQQDMnRzMgQ/50LFeIQo4IBtwlEouczMlPQF4c21R\n" - + "1d720moxILVPT0NJZTQUDDmmgbL+B7CgtcCR2NlP5sKPZVADAkEAh4Xq1cy8dMBKYcVNgNtPQcqI\n" + "PWpfKR3ISI5yXB0vRNAL6Vet5zbTcUZhKDVtNSbis3UEsGYH8NorEC2z2cpjGQJANhJi9Ow6c5Mh\n" - + "/DURBUn+1l5pyCKrZnDbvaALSLATLvjmFTuGjoHszy2OeKnOZmEqExWnKKE/VYuPyhy6V7i3TwJA\n" + "f8skDgtPK0OsBCa6IljPaHoWBjPc4kFkSTSS1d56hUcWSikTmiuKdLyBb85AADSZYsvHWrte4opN\n" + "dhNukMJuRA==\n"; + /* + * private final String keyContent = + * "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALV5vGlkiWwoZX4hTRplPXP8qtST\n" + * + "hwZhko8noeY5vf8ECwmd+vrCTw/JvnOtkx/8oYNbg/SeUt1EfOsk6gqJdBblGFBZRMcUJlIpqE9z\n" + + * "uv68U9G8Gfi/qvRSY336hibw0J5bZ4vn1QqmyHDB+Czea9AjFUV7AEVG15+vED7why+/AgMBAAEC\n" + * + "gYBmFBPnNKYYMKDmUdUNA+WNWJK/ADzzWe8WlzR6TACTcbLDthl289WFC/YVG42mcHRpbxDKiEQU\n" + + * "MnIR0rHTO34Qb/2HcuyweStU2gqR6omxBvMnFpJr90nD1HcOMJzeLHsphau0/EmKKey+gk4PyieD\n" + * + "KqTM7LTjjHv8xPM4n+WAAQJBAOMNCeFKlJ4kMokWhU74B5/w/NGyT1BHUN0VmilHSiJC8JqS4BiI\n" + + * "ZpAeET3VmilO6QTGh2XVhEDGteu3uZR6ipUCQQDMnRzMgQ/50LFeIQo4IBtwlEouczMlPQF4c21R\n" + * + "1d720moxILVPT0NJZTQUDDmmgbL+B7CgtcCR2NlP5sKPZVADAkEAh4Xq1cy8dMBKYcVNgNtPQcqI\n" + + * "PWpfKR3ISI5yXB0vRNAL6Vet5zbTcUZhKDVtNSbis3UEsGYH8NorEC2z2cpjGQJANhJi9Ow6c5Mh\n" + * + "/DURBUn+1l5pyCKrZnDbvaALSLATLvjmFTuGjoHszy2OeKnOZmEqExWnKKE/VYuPyhy6V7i3TwJA\n" + + * "f8skDgtPK0OsBCa6IljPaHoWBjPc4kFkSTSS1d56hUcWSikTmiuKdLyBb85AADSZYsvHWrte4opN\n" + "dhNukMJuRA==\n"; + * + * private final String certContent = "-----BEGIN CERTIFICATE-----\n" + + * "MIIE3jCCA8agAwIBAgIFAqv56tIwDQYJKoZ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eS8wgYAGCCsGAQUFBwEBBHQwcjAkBggrBgEFBQcwAYYYaHR0\n" + + * "cDovL29jc3AuZ29kYWRkeS5jb20vMEoGCCsGAQUFBzAChj5odHRwOi8vY2VydGlm\n" + * + "aWNhdGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkvZ2RfaW50ZXJtZWRpYXRlLmNy\n" + + * "dDAfBgNVHSMEGDAWgBT9rGEyk2xF1uLuhV+auud2mWjM5zArBgNVHREEJDAighAq\n" + * + "LnJlYWxob3N0aXAuY29tgg5yZWFsaG9zdGlwLmNvbTAdBgNVHQ4EFgQUHxwmdK5w\n" + + * "9/YVeZ/3fHyi6nQfzoYwDQYJKoZIhvcNAQEFBQADggEBABv/XinvId6oWXJtmku+\n" + * + "7m90JhSVH0ycoIGjgdaIkcExQGP08MCilbUsPcbhLheSFdgn/cR4e1MP083lacoj\n" + + * "OGauY7b8f/cuquGkT49Ns14awPlEzRjjycQEjjLxFEuL5CFWa2t2gKRE1dSfhDQ+\n" + * + "fJ6GBCs1XgZLuhkKS8fPf+YmG2ZjHzYDjYoSx7paDXgEm+kbYIZdCK51lA0BUAjP\n" + + * "9ZMGhsu/PpAbh5U/DtcIqxY0xeqD4TeGsBzXg6uLhv+jKHDtXg5fYPe+z0n5DCEL\n" + * + "k0fLF4+i/pt9hVCz0QrZ28RUhXf825+EOL0Gw+Uzt+7RV2cCaJrlu4cDrDom2FRy\n" + "E8I=\n" + + * "-----END CERTIFICATE-----\n"; + */ + public static final String keyContent = + "-----BEGIN PRIVATE KEY-----\n" + + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDT9AtEfs+s/I8QXp6rrCw0iNJ\n" + + "0+GgsybNHheU+JpL39LMTZykCrZhZnyDvwdxCoOfE38Sa32baHKNds+y2SHnMNsOkw8OcNucHEBX\n" + + "1FIpOBGph9D6xC+umx9od6xMWETUv7j6h2u+WC3OhBM8fHCBqIiAol31/IkcqDxxsHlQ8S/oCfTl\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tKhjshcv3XkIqFPo2XdVvOAgglPO7vajX91iiXXuH7h7RmJud6l0y/lwKBgE+bi90gLuPtpoEr\n" + + "VzIDKz40ED5bNYHT80NNy0rpT7J2GVN9nwStRYXPBBVeZq7xCpgqpgmO5LtDAWULeZBlbHlOdBwl\n" + + "NhNKKl5wzdEUKwW0yBL1WSS5PQgWPwgARYP25/ggW22sj+49WIo1neXsEKPGWObk8e050f1fTt92\n" + + "Vo1lAoGAb1gCoyBCzvi7sqFxm4V5oapnJeiQQJFjhoYWqGa26rQ+AvXXNuBcigIeDXNJPctSF0Uc\n" + + "p11KbbCgiruBbckvM1vGsk6Sx4leRk+IFHRpJktFUek4o0eUg0shOsyyvyet48Dfg0a8FvcxROs0\n" + + "gD+IYds5doiob/hcm1hnNB/3vk4=\n" + + "-----END PRIVATE KEY-----\n"; + + public static final String certContent = + "-----BEGIN CERTIFICATE-----\n" + + "MIIFZTCCBE2gAwIBAgIHKBCduBUoKDANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE\n" + + "BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY\n" + + "BgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlm\n" + + "aWNhdGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5\n" + + "IFNlY3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMIMDc5Njky\n" + + "ODcwHhcNMTIwMjAzMDMzMDQwWhcNMTcwMjA3MDUxMTIzWjBZMRkwFwYDVQQKDBAq\n" + + "LnJlYWxob3N0aXAuY29tMSEwHwYDVQQLDBhEb21haW4gQ29udHJvbCBWYWxpZGF0\n" + + "ZWQxGTAXBgNVBAMMECoucmVhbGhvc3RpcC5jb20wggEiMA0GCSqGSIb3DQEBAQUA\n" + + "A4IBDwAwggEKAoIBAQCDT9At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S92fmQkCLqm+qUWyN\n" + + "BfBVgf9/M5pcT8EiTZlS5nAtzAE/eRpBeR3ubLlaAogj4rdH7YYVJcDDLLoB2qM3\n" + + "qeCHu8LFoblkb93UuFDWqRaVPmMlJRnhsRkL1oa2gM2hwQTkBDkP7w5FG1BELCgl\n" + + "gZI2ij2yxjge6pOEwSyZCzzbCcg9pN+dNrYyGEtB4k+BBnPA3N4r14CWbk+uxjrQ\n" + + "6j2Ip+b7wOc5IuMEMl8xwTyjuX3lsLbAZyFI9RCyofwA9NqIZ1GeB6Zd196rubQp\n" + + "93cmBqGGjZUs3wMrGlm7xdjlX6GQ9UvmvkMub9+lL99A5W50QgCmFeI=\n" + + "-----END CERTIFICATE-----\n"; - private final String certContent = "-----BEGIN CERTIFICATE-----\n" + "MIIE3jCCA8agAwIBAgIFAqv56tIwDQYJKoZIhvcNAQEFBQAwgcoxCzAJBgNVBAYT\n" - + "AlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMRowGAYD\n" + "VQQKExFHb0RhZGR5LmNvbSwgSW5jLjEzMDEGA1UECxMqaHR0cDovL2NlcnRpZmlj\n" - + "YXRlcy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5MTAwLgYDVQQDEydHbyBEYWRkeSBT\n" + "ZWN1cmUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxETAPBgNVBAUTCDA3OTY5Mjg3\n" - + "MB4XDTA5MDIxMTA0NTc1NloXDTEyMDIwNzA1MTEyM1owWTEZMBcGA1UECgwQKi5y\n" + "ZWFsaG9zdGlwLmNvbTEhMB8GA1UECwwYRG9tYWluIENvbnRyb2wgVmFsaWRhdGVk\n" - + "MRkwFwYDVQQDDBAqLnJlYWxob3N0aXAuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GN\n" + "ADCBiQKBgQC1ebxpZIlsKGV+IU0aZT1z/KrUk4cGYZKPJ6HmOb3/BAsJnfr6wk8P\n" - + "yb5zrZMf/KGD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GsBzXg6uLhv+jKHDtXg5fYPe+z0n5DCEL\n" - + "k0fLF4+i/pt9hVCz0QrZ28RUhXf825+EOL0Gw+Uzt+7RV2cCaJrlu4cDrDom2FRy\n" + "E8I=\n" + "-----END CERTIFICATE-----\n"; -*/ - public static final String keyContent = - "-----BEGIN PRIVATE KEY-----\n" + - "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDT9AtEfs+s/I8QXp6rrCw0iNJ\n" + - "0+GgsybNHheU+JpL39LMTZykCrZhZnyDvwdxCoOfE38Sa32baHKNds+y2SHnMNsOkw8OcNucHEBX\n" + - "1FIpOBGph9D6xC+umx9od6xMWETUv7j6h2u+WC3OhBM8fHCBqIiAol31/IkcqDxxsHlQ8S/oCfTl\n" + - "XJUY6Yn628OA1XijKdRnadV0hZ829cv/PZKljjwQUTyrd0KHQeksBH+YAYSo2JUl8ekNLsOi8/cP\n" + - "tfojnltzRI1GXi0ZONs8VnDzJ0a2gqZY+uxlz+CGbLnGnlN4j9cBpE+MfUE+35Dq121sTpsSgF85\n" + - "Mz+pVhn2S633AgMBAAECggEAH/Szd9RxbVADenCA6wxKSa3KErRyq1YN8ksJeCKMAj0FIt0caruE\n" + - "qO11DebWW8cwQu1Otl/cYI6pmg24/BBldMrp9IELX/tNJo+lhPpRyGAxxC0eSXinFfoASb8d+jJd\n" + - "Bd1mmemM6fSxqRlxSP4LrzIhjhR1g2CiyYuTsiM9UtoVKGyHwe7KfFwirUOJo3Mr18zUVNm7YqY4\n" + - "IVhOSq59zkH3ULBlYq4bG50jpxa5mNSCZ7IpafPY/kE/CbR+FWNt30+rk69T+qb5abg6+XGm+OAm\n" + - "bnQ18yZEqX6nJLk7Ch0cfA5orGgrTMOrM71wK7tBBDQ308kOxDGebx6j0qD36QKBgQDTRDr8kuhA\n" + - "9sUyKr9vk2DQCMpNvEeiwI3JRMqmmxpNAtg01aJ3Ya57vX5Fc+zcuV87kP6FM1xgpHQvnw5LWo2J\n" + - "s7ANwQcP8ricEW5zkZhSjI4ssMeAubmsHOloGxmLFYZqwx0JI7CWViGTLMcUlqKblmHcjeQDeDfP\n" + - "P1TaCItFmwKBgQCfHZwVvIcaDs5vxVpZ4ftvflIrW8qq0uOVK6QIf9A/YTGhCXl2qxxTg2A6+0rg\n" + - "ZqI7zKzUDxIbVv0KlgCbpHDC9d5+sdtDB3wW2pimuJ3p1z4/RHb4n/lDwXCACZl1S5l24yXX2pFZ\n" + - "wdPCXmy5PYkHMssFLNhI24pprUIQs66M1QKBgQDQwjAjWisD3pRXESSfZRsaFkWJcM28hdbVFhPF\n" + - "c6gWhwQLmTp0CuL2RPXcPUPFi6sN2iWWi3zxxi9Eyz+9uBn6AsOpo56N5MME/LiOnETO9TKb+Ib6\n" + - "rQtKhjshcv3XkIqFPo2XdVvOAgglPO7vajX91iiXXuH7h7RmJud6l0y/lwKBgE+bi90gLuPtpoEr\n" + - "VzIDKz40ED5bNYHT80NNy0rpT7J2GVN9nwStRYXPBBVeZq7xCpgqpgmO5LtDAWULeZBlbHlOdBwl\n" + - "NhNKKl5wzdEUKwW0yBL1WSS5PQgWPwgARYP25/ggW22sj+49WIo1neXsEKPGWObk8e050f1fTt92\n" + - "Vo1lAoGAb1gCoyBCzvi7sqFxm4V5oapnJeiQQJFjhoYWqGa26rQ+AvXXNuBcigIeDXNJPctSF0Uc\n" + - "p11KbbCgiruBbckvM1vGsk6Sx4leRk+IFHRpJktFUek4o0eUg0shOsyyvyet48Dfg0a8FvcxROs0\n" + - "gD+IYds5doiob/hcm1hnNB/3vk4=\n" + - "-----END PRIVATE KEY-----\n" ; - - public static final String certContent = - "-----BEGIN CERTIFICATE-----\n" + - "MIIFZTCCBE2gAwIBAgIHKBCduBUoKDANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE\n" + - "BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY\n" + - "BgNVBAoTEUdvRGFkZHkuY29tLCBJbm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keS5jb20vcmVwb3Np\n" + - "dG9yeS8wgYAGCCsGAQUFBwEBBHQwcjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3Au\n" + - "Z29kYWRkeS5jb20vMEoGCCsGAQUFBzAChj5odHRwOi8vY2VydGlmaWNhdGVzLmdv\n" + - "ZGFkZHkuY29tL3JlcG9zaXRvcnkvZ2RfaW50ZXJtZWRpYXRlLmNydDAfBgNVHSME\n" + - "GDAWgBT9rGEyk2xF1uLuhV+auud2mWjM5zArBgNVHREEJDAighAqLnJlYWxob3N0\n" + - "aXAuY29tgg5yZWFsaG9zdGlwLmNvbTAdBgNVHQ4EFgQUZyJz9/QLy5TWIIscTXID\n" + - "E8Xk47YwDQYJKoZIhvcNAQEFBQADggEBAKiUV3KK16mP0NpS92fmQkCLqm+qUWyN\n" + - "BfBVgf9/M5pcT8EiTZlS5nAtzAE/eRpBeR3ubLlaAogj4rdH7YYVJcDDLLoB2qM3\n" + - "qeCHu8LFoblkb93UuFDWqRaVPmMlJRnhsRkL1oa2gM2hwQTkBDkP7w5FG1BELCgl\n" + - "gZI2ij2yxjge6pOEwSyZCzzbCcg9pN+dNrYyGEtB4k+BBnPA3N4r14CWbk+uxjrQ\n" + - "6j2Ip+b7wOc5IuMEMl8xwTyjuX3lsLbAZyFI9RCyofwA9NqIZ1GeB6Zd196rubQp\n" + - "93cmBqGGjZUs3wMrGlm7xdjlX6GQ9UvmvkMub9+lL99A5W50QgCmFeI=\n" + - "-----END CERTIFICATE-----\n"; - public static final String rootCa = - "-----BEGIN CERTIFICATE-----\n" + - "MIIE3jCCA8agAwIBAgICAwEwDQYJKoZIhvcNAQEFBQAwYzELMAkGA1UEBhMCVVMx\n" + - "ITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28g\n" + - "RGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExMTYw\n" + - "MTU0MzdaFw0yNjEx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wYDVR0gBEQwQjBABgRVHSAAMDgwNgYIKwYBBQUH\n" + - "AgEWKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5jb20vcmVwb3NpdG9yeTAO\n" + - "BgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEFBQADggEBANKGwOy9+aG2Z+5mC6IG\n" + - "OgRQjhVyrEp0lVPLN8tESe8HkGsz2ZbwlFalEzAFPIUyIXvJxwqoJKSQ3kbTJSMU\n" + - "A2fCENZvD117esyfxVgqwcSeIaha86ykRvOe5GPLL5CkKSkB2XIsKd83ASe8T+5o\n" + - "0yGPwLPk9Qnt0hCqU7S+8MxZC9Y7lhyVJEnfzuz9p0iRFEUOOjZv2kWzRaJBydTX\n" + - "RE4+uXR21aITVSzGh6O1mawGhId/dQb8vxRMDsxuxN89txJx9OjxUUAiKEngHUuH\n" + - "qDTMBqLdElrRhjZkAzVvb3du6/KFUJheqwNTrZEjYx8WnM25sgVjOuH0aBsXBTWV\n" + - "U+4=\n" + - "-----END CERTIFICATE-----\n" + - "-----BEGIN CERTIFICATE-----\n" + - "MIIE+zCCBGSgAwIBAgICAQ0wDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1Zh\n" + - "bGlDZXJ0IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIElu\n" + - "Yy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24g\n" + - "QXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAe\n" + - "BgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTA0MDYyOTE3MDYyMFoX\n" + - "DTI0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMxITAfBgNVBAoTGFRoZSBHbyBE\n" + - "YWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28gRGFkZHkgQ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DBCMEAGBFUd\n" + - "IAAwODA2BggrBgEFBQcCARYqaHR0cDovL2NlcnRpZmljYXRlcy5nb2RhZGR5LmNv\n" + - "bS9yZXBvc2l0b3J5MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQUFAAOBgQC1\n" + - "QPmnHfbq/qQaQlpE9xXUhUaJwL6e4+PrxeNYiY+Sn1eocSxI0YGyeR+sBjUZsE4O\n" + - "WBsUs5iB0QQeyAfJg594RAoYC5jcdnplDQ1tgMQLARzLrUc+cb53S8wGd9D0Vmsf\n" + - "SxOaFIqII6hR8INMqzW/Rn453HWkrugp++85j09VZw==\n" + - "-----END CERTIFICATE-----\n" + - "-----BEGIN CERTIFICATE-----\n" + - "MIIC5zCCAlACAQEwDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0\n" + - "IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAz\n" + - "BgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9y\n" + - "aXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkqhkiG\n" + - "9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNjAwMTk1NFoXDTE5MDYy\n" + - "NjAwMTk1NFowgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTmV0d29y\n" + - "azEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENs\n" + - "YXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRw\n" + - "Oi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNl\n" + - "cnQuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOOnHK5avIWZJV16vY\n" + - "dA757tn2VUdZZUcOBVXc65g2PFxTXdMwzzjsvUGJ7SVCCSRrCl6zfN1SLUzm1NZ9\n" + - "WlmpZdRJEy0kTRxQb7XBhVQ7/nHk01xC+YDgkRoKWzk2Z/M/VXwbP7RfZHM047QS\n" + - "v4dk+NoS/zcnwbNDu+97bi5p9wIDAQABMA0GCSqGSIb3DQEBBQUAA4GBADt/UG9v\n" + - "UJSZSWI4OB9L+KXIPqeCgfYrx+jFzug6EILLGACOTb2oWH+heQC1u+mNr0HZDzTu\n" + - "IYEZoDJJKPTEjlbVUjP9UNV+mWwD5MlM/Mtsq2azSiGM5bUMMj4QssxsodyamEwC\n" + - "W/POuZ6lcg5Ktz885hZo+L7tdEy8W9ViH0Pd\n" + - "-----END CERTIFICATE-----\n"; - + "-----BEGIN CERTIFICATE-----\n" + + "MIIE3jCCA8agAwIBAgICAwEwDQYJKoZIhvcNAQEFBQAwYzELMAkGA1UEBhMCVVMx\n" + + "ITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28g\n" + + "RGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExMTYw\n" + + "MTU0MzdaFw0yNjExMTYwMTU0MzdaMIHKMQswCQYDVQQGEwJVUzEQMA4GA1UECBMH\n" + + "QXJpem9uYTETMBEGA1UEBxMKU2NvdHRzZGFsZTEaMBgGA1UEChMRR29EYWRkeS5j\n" + + "b20sIEluYy4xMzAxBgNVBAsTKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5j\n" + + "b20vcmVwb3NpdG9yeTEwMC4GA1UEAxMnR28gRGFkZHkgU2VjdXJlIENlcnRpZmlj\n" + + "YXRpb24gQXV0aG9yaXR5MREwDwYDVQQFEwgwNzk2OTI4NzCCASIwDQYJKoZIhvcN\n" + + "AQEBBQADggEPADCCAQoCggEBAMQt1RWMnCZM7D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uz9p0iRFEUOOjZv2kWzRaJBydTX\n" + + "RE4+uXR21aITVSzGh6O1mawGhId/dQb8vxRMDsxuxN89txJx9OjxUUAiKEngHUuH\n" + + "qDTMBqLdElrRhjZkAzVvb3du6/KFUJheqwNTrZEjYx8WnM25sgVjOuH0aBsXBTWV\n" + + "U+4=\n" + + "-----END CERTIFICATE-----\n" + + "-----BEGIN CERTIFICATE-----\n" + + "MIIE+zCCBGSgAwIBAgICAQ0wDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1Zh\n" + + "bGlDZXJ0IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIElu\n" + + "Yy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24g\n" + + "QXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAe\n" + + "BgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTA0MDYyOTE3MDYyMFoX\n" + + "DTI0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMxITAfBgNVBAoTGFRoZSBHbyBE\n" + + "YWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28gRGFkZHkgQ2xhc3MgMiBDZXJ0\n" + + "aWZpY2F0aW9uIEF1dGhvcml0eTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgC\n" + + "ggEBAN6d1+pXGEmhW+vXX0iG6r7d/+TvZxz0ZWizV3GgXne77ZtJ6XCAPVYYYwhv\n" + + "2vLM0D9/AlQiVBDYsoHUwHU9S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux6wwdhFJ2+q\n" + + "N1j3hybX2C32qRe3H3I2TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLOtXiEqITLdiO\n" + + "r18SPaAIBQi2XKVlOARFmR6jYGB0xUGlcmIbYsUfb18aQr4CUWWoriMYavx4A6lN\n" +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C\n" + + "W/POuZ6lcg5Ktz885hZo+L7tdEy8W9ViH0Pd\n" + + "-----END CERTIFICATE-----\n"; + @Inject private KeystoreDao _ksDao; @Inject @@ -439,12 +460,12 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx public ConsoleProxyVO doAssignProxy(long dataCenterId, long vmId) { ConsoleProxyVO proxy = null; VMInstanceVO vm = _instanceDao.findById(vmId); - + if (vm == null) { s_logger.warn("VM " + vmId + " no longer exists, return a null proxy for vm:" + vmId); return null; } - + if (vm != null && vm.getState() != State.Running) { if (s_logger.isInfoEnabled()) { s_logger.info("Detected that vm : " + vmId + " is not currently at running state, we will fail the proxy assignment for it"); @@ -454,7 +475,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - if(vm.getProxyId() != null) { + if (vm.getProxyId() != null) { proxy = _consoleProxyDao.findById(vm.getProxyId()); if (proxy != null) { @@ -477,8 +498,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } } } - } - + } + if (proxy == null) { proxy = assignProxyFromRunningPool(dataCenterId); } @@ -493,7 +514,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.warn("Unable to find or allocate console proxy resource"); return null; } - + // if it is a new assignment or a changed assignment, update the record if (vm.getProxyId() == null || vm.getProxyId().longValue() != proxy.getId()) { _instanceDao.updateProxyId(vmId, proxy.getId(), DateUtil.currentGMTTime()); @@ -585,7 +606,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null - // as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited to + // as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited +// to // Stopped to allow // Starting of it s_logger.warn("Console proxy is not in correct state to be started: " + proxy.getState()); @@ -701,18 +723,18 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx Account systemAcct = _accountMgr.getSystemAccount(); DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); - + TrafficType defaultTrafficType = TrafficType.Public; if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { - defaultTrafficType = TrafficType.Guest; + defaultTrafficType = TrafficType.Guest; } - + List defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType); - + if (defaultNetworks.size() != 1) { - throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1"); - } - + throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1"); + } + NetworkVO defaultNetwork = defaultNetworks.get(0); List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork); @@ -874,9 +896,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return new ConsoleAccessAuthenticationAnswer(cmd, false); } - + vmId = _identityDao.getIdentityId("vm_instance", cmd.getVmId()); - if(vmId == null) { + if (vmId == null) { s_logger.error("Invalid vm id " + cmd.getVmId() + " sent from console access authentication"); return new ConsoleAccessAuthenticationAnswer(cmd, false); } @@ -975,9 +997,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx // continue on forever /* - * _capacityScanScheduler.execute(new Runnable() { public void run() { if(s_logger.isInfoEnabled()) + * _capacityScanScheduler.execute(new Runnable() { public void run() { + * if(s_logger.isInfoEnabled()) * s_logger.info("Stop console proxy " + proxy.getName() + - * " VM because of that the agent running inside it has disconnected" ); stopProxy(proxy.getId()); } }); + * " VM because of that the agent running inside it has disconnected" ); + * stopProxy(proxy.getId()); } }); */ } else { if (s_logger.isInfoEnabled()) { @@ -999,7 +1023,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return true; } - + private boolean isConsoleProxyVmRequired(long dcId) { DataCenterVO dc = _dcDao.findById(dcId); _dcDao.loadDetails(dc); @@ -1326,7 +1350,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx KeystoreVO ksVo = _ksDao.findByName(CERTIFICATE_NAME); if (ksVo == null) { _ksDao.save(CERTIFICATE_NAME, certContent, keyContent, "realhostip.com"); - KeystoreVO caRoot = new KeystoreVO(); + KeystoreVO caRoot = new KeystoreVO(); caRoot.setCertificate(rootCa); caRoot.setDomainSuffix("realhostip.com"); caRoot.setName("root"); @@ -1425,19 +1449,19 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); _serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, _proxyRamSize, _proxyCpuMHz, 0, 0, false, null, useLocalStorage, true, null, true, VirtualMachine.Type.ConsoleProxy, true); - _serviceOffering.setUniqueName("Cloud.com-ConsoleProxy"); + _serviceOffering.setUniqueName(ServiceOffering.consoleProxyDefaultOffUniqueName); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); - + // this can sometimes happen, if DB is manually or programmatically manipulated - if(_serviceOffering == null) { - String msg = "Data integrity problem : System Offering For Console Proxy has been removed?"; - s_logger.error(msg); + if (_serviceOffering == null) { + String msg = "Data integrity problem : System Offering For Console Proxy has been removed?"; + s_logger.error(msg); throw new ConfigurationException(msg); } _loadScanner = new SystemVmLoadScanner(this); _loadScanner.initScan(STARTUP_DELAY, _capacityScanInterval); - _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); + _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); if (s_logger.isInfoEnabled()) { s_logger.info("Console Proxy Manager is configured."); @@ -1463,11 +1487,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - - ConsoleProxyVO vm = profile.getVirtualMachine(); + + ConsoleProxyVO vm = profile.getVirtualMachine(); Map details = _vmDetailsDao.findDetails(vm.getId()); vm.setDetails(details); - + StringBuilder buf = profile.getBootArgsBuilder(); buf.append(" template=domP type=consoleproxy"); buf.append(" host=").append(_mgmt_host); @@ -1489,9 +1513,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) { externalDhcp = true; } - + if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { - buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); + buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password")); } for (NicProfile nic : profile.getNics()) { @@ -1530,7 +1554,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (dc.getDns2() != null) { buf.append(" dns2=").append(dc.getDns2()); } - + String bootArgs = buf.toString(); if (s_logger.isDebugEnabled()) { s_logger.debug("Boot Args for " + profile + ": " + bootArgs); @@ -1633,11 +1657,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx try { long proxyVmId = startupCmd.getProxyVmId(); ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(proxyVmId); - if(consoleProxy == null) { + if (consoleProxy == null) { s_logger.info("Proxy " + proxyVmId + " is no longer in DB, skip sending startup command"); return; } - + assert (consoleProxy != null); HostVO consoleProxyHost = findConsoleProxyHostByName(consoleProxy.getHostName()); @@ -1651,10 +1675,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.error("Unable to send http handling startup command to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e); } catch (OperationTimedoutException e) { s_logger.error("Unable to send http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e); - } catch(OutOfMemoryError e) { - s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched"); - System.exit(1); - } catch (Exception e) { + } catch (OutOfMemoryError e) { + s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched"); + System.exit(1); + } catch (Exception e) { s_logger.error("Unexpected exception when sending http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e); } } @@ -1688,7 +1712,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Override public void onScanStart() { - // to reduce possible number of DB queries for capacity scan, we run following aggregated queries in preparation stage + // to reduce possible number of DB queries for capacity scan, we run following aggregated queries in preparation +// stage _zoneHostInfoMap = getZoneHostInfo(); _zoneProxyCountMap = new HashMap(); @@ -1751,7 +1776,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } List upPools = _storagePoolDao.listByStatus(StoragePoolStatus.Up); - if (upPools == null || upPools.size() == 0 ) { + if (upPools == null || upPools.size() == 0) { s_logger.debug("Skip capacity scan due to there is no Primary Storage UPintenance mode"); return false; } @@ -1783,16 +1808,16 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return false; } - + List l = _consoleProxyDao.getProxyListInStates(VirtualMachine.State.Starting, VirtualMachine.State.Stopping); - if(l.size() > 0) { + if (l.size() > 0) { if (s_logger.isDebugEnabled()) { s_logger.debug("Zone " + dataCenterId + " has " + l.size() + " console proxy VM(s) in transition state"); } - + return false; } - + if (s_logger.isDebugEnabled()) { s_logger.debug("Zone " + dataCenterId + " is ready to launch console proxy"); } @@ -1812,7 +1837,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (vmInfo == null) { vmInfo = new ConsoleProxyLoadInfo(); } - + if (!checkCapacity(proxyInfo, vmInfo)) { if (s_logger.isDebugEnabled()) { s_logger.debug("Expand console proxy standby capacity for zone " + proxyInfo.getName()); @@ -1838,33 +1863,33 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx public void onScanEnd() { } - @Override + @Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { if (!(cmd[0] instanceof StartupProxyCommand)) { return null; } - + host.setType(com.cloud.host.Host.Type.ConsoleProxy); return host; } - @Override + @Override public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { - // TODO Auto-generated method stub - return null; + // TODO Auto-generated method stub + return null; } - @Override + @Override public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { - // TODO Auto-generated method stub - return null; + // TODO Auto-generated method stub + return null; } protected HostVO findConsoleProxyHostByName(String name) { - SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); - sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.ConsoleProxy); - sc.addAnd(sc.getEntity().getName(), Op.EQ, name); - return sc.find(); + SearchCriteriaService sc = SearchCriteria2.create(HostVO.class); + sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.ConsoleProxy); + sc.addAnd(sc.getEntity().getName(), Op.EQ, name); + return sc.find(); } } diff --git a/server/src/com/cloud/migration/Db20to21MigrationUtil.java b/server/src/com/cloud/migration/Db20to21MigrationUtil.java index 014f2a32c3d..1f594dc161b 100644 --- a/server/src/com/cloud/migration/Db20to21MigrationUtil.java +++ b/server/src/com/cloud/migration/Db20to21MigrationUtil.java @@ -16,932 +16,934 @@ * */ -package com.cloud.migration; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.security.NoSuchAlgorithmException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.Random; -import java.util.Scanner; - -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKey; - -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; - -import com.cloud.configuration.Config; -import com.cloud.configuration.ConfigurationVO; -import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.consoleproxy.ConsoleProxyManager; -import com.cloud.dc.ClusterVO; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.HostPodVO; -import com.cloud.dc.dao.ClusterDao; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.HostPodDao; -import com.cloud.domain.DomainVO; -import com.cloud.domain.dao.DomainDao; -import com.cloud.host.Host; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.migration.DiskOffering21VO.Type; -import com.cloud.storage.Storage.StoragePoolType; -import com.cloud.storage.StoragePoolVO; -import com.cloud.storage.Volume; -import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.StoragePoolDao; -import com.cloud.storage.dao.VolumeDao; -import com.cloud.storage.secondary.SecondaryStorageVmManager; -import com.cloud.utils.NumbersUtil; -import com.cloud.utils.PropertiesUtil; -import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.db.Filter; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Func; -import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.net.NetUtils; -import com.cloud.utils.script.Script; -import com.cloud.vm.ConsoleProxyVO; -import com.cloud.vm.DomainRouterVO; -import com.cloud.vm.SecondaryStorageVmVO; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachine.State; -import com.cloud.vm.dao.ConsoleProxyDao; -import com.cloud.vm.dao.DomainRouterDao; -import com.cloud.vm.dao.SecondaryStorageVmDao; -import com.cloud.vm.dao.UserVmDao; -import com.cloud.vm.dao.VMInstanceDao; - -public class Db20to21MigrationUtil { - private static final Logger s_logger = Logger.getLogger(Db20to21MigrationUtil.class); - - protected DataCenterDao _dcDao; - protected HostPodDao _podDao; - protected ConfigurationDao _configDao; - protected ClusterDao _clusterDao; - protected HostDao _hostDao; - protected StoragePoolDao _spDao; - protected DomainDao _domainDao; - protected ServiceOffering20Dao _serviceOffering20Dao; - protected DiskOffering20Dao _diskOffering20Dao; - protected ServiceOffering21Dao _serviceOffering21Dao; - protected DiskOffering21Dao _diskOffering21Dao; - protected ConsoleProxyDao _consoleProxyDao; - protected SecondaryStorageVmDao _secStorageVmDao; - protected VMInstanceDao _vmInstanceDao; - protected VolumeDao _volumeDao; - protected UserVmDao _userVmDao; - protected DomainRouterDao _routerDao; - protected StoragePoolDao _poolDao; - - protected long _consoleProxyServiceOfferingId; - protected long _secStorageServiceOfferingId; - protected long _domRServiceOfferingId; - protected boolean _isPremium = false; - - protected static class DcPod { - long id; - String name; - long count; - - public DcPod() { - } - } - - private void migrateZones() { - boolean createCluster = false; - String value = _configDao.getValue("xen.create.pools.in.pod"); - if(value == null || !value.equalsIgnoreCase("true")) { - s_logger.info("System is not configured to use Xen server pool, we will skip creating cluster for pods"); - } else { - createCluster = true; - } - - // Displaying summarize data center/pod configuration from old DB before we continue - GenericSearchBuilder sb = _dcDao.createSearchBuilder(DcPod.class); - sb.selectField(sb.entity().getId()); - sb.selectField(sb.entity().getName()); - sb.select("count", Func.COUNT, null); - sb.groupBy(sb.entity().getId(), sb.entity().getName()); - sb.done(); - - SearchCriteria sc = sb.create(); - List results = _dcDao.customSearchIncludingRemoved(sc, (Filter)null); - if(results.size() > 0) { - System.out.println("We've found following zones are deployed in your database"); - for(DcPod cols : results) { - System.out.println("\tid: " + cols.id + ",\tname: " + cols.name + ",\tpods in zone: " + cols.count); - } - System.out.println("From 2.0 to 2.1, pod is required to have gateway configuration"); - - for(DcPod cols : results) { - migrateZonePods(cols.id, cols.name, createCluster); - - s_logger.info("Set system VM guest MAC in zone" + cols.name); - migrateSystemVmGuestMacAndState(cols.id); - } - } else { - System.out.println("We couldn't find any zone being deployed. Skip Zone/Pod migration"); - } - } - - private void migrateZonePods(long zoneId, String zoneName, boolean createCluster) { - SearchBuilder sb = _podDao.createSearchBuilder(); - sb.and("zoneId", sb.entity().getDataCenterId(), Op.EQ); - sb.done(); - - SearchCriteria sc = sb.create(); - sc.setParameters("zoneId", zoneId); - - List pods = _podDao.searchIncludingRemoved(sc, null, false, false); - if(pods.size() > 0) { - for(HostPodVO pod : pods) { - System.out.println("Migrating pod " + pod.getName() + " in zone " + zoneName + "..."); - System.out.println("Current pod " + pod.getName() + " configuration as"); - System.out.println("\tCIDR: " + pod.getCidrAddress() + "/" + pod.getCidrSize()); - System.out.println("\tGateway: " + pod.getGateway()); - System.out.print("Please type your gateway address for the pod: "); - - String gateway = readInput(); - pod.setGateway(gateway); - _podDao.update(pod.getId(), pod); - if(createCluster) { - migrateHostsInPod(zoneId, pod.getId(), pod.getName()); - } - - System.out.println("Set last_host_id for VMs in pod " + pod.getName()); - migrateVmInstanceLastHostId(zoneId, pod.getId()); - - System.out.println("Setup link local addresses, it will take a while, please wait..."); - String ipNums = _configDao.getValue("linkLocalIp.nums"); - int nums = Integer.parseInt(ipNums); - if (nums > 16 || nums <= 0) { - nums = 10; - } - - /*local link ip address starts from 169.254.0.2 - 169.254.(nums)*/ - String[] ipRanges = NetUtils.getLinkLocalIPRange(nums); - _dcDao.addLinkLocalIpAddress(zoneId, pod.getId(), ipRanges[0], ipRanges[1]); - } - } - } - - private void migrateHostsInPod(long zoneId, long podId, String podName) { - System.out.println("Creating cluster for pod " + podName); - - ClusterVO cluster = null; - - SearchBuilder sb = _hostDao.createSearchBuilder(); - sb.and("dc", sb.entity().getDataCenterId(), Op.EQ); - sb.and("pod", sb.entity().getPodId(), Op.EQ); - sb.and("type", sb.entity().getType(), Op.EQ); - sb.done(); - - SearchCriteria sc = sb.create(); - sc.setParameters("dc", zoneId); - sc.setParameters("pod", podId); - sc.setParameters("type", Host.Type.Routing); - - // join cluster for hosts in pod - List hostsInPod = _hostDao.searchIncludingRemoved(sc, null, false, false); - if(hostsInPod.size() > 0) { - if(cluster == null) { - cluster = new ClusterVO(zoneId, podId, String.valueOf(podId)); - cluster = _clusterDao.persist(cluster); - } - - for(HostVO host : hostsInPod) { - host.setClusterId(cluster.getId()); - _hostDao.update(host.getId(), host); - - System.out.println("Join host " + host.getName() + " to auto-formed cluster"); - } - } - - SearchBuilder sbPool = _spDao.createSearchBuilder(); - sbPool.and("dc", sbPool.entity().getDataCenterId(), Op.EQ); - sbPool.and("pod", sbPool.entity().getPodId(), Op.EQ); - sbPool.and("poolType", sbPool.entity().getPoolType(), Op.IN); - sbPool.done(); - - SearchCriteria scPool = sbPool.create(); - scPool.setParameters("dc", zoneId); - scPool.setParameters("pod", podId); - scPool.setParameters("poolType", StoragePoolType.NetworkFilesystem.toString(), StoragePoolType.IscsiLUN.toString()); - - List sPoolsInPod = _spDao.searchIncludingRemoved(scPool, null, false, false); - if(sPoolsInPod.size() > 0) { - if(cluster == null) { - cluster = new ClusterVO(zoneId, podId, String.valueOf(podId)); - cluster = _clusterDao.persist(cluster); - } - - for(StoragePoolVO spool : sPoolsInPod) { - spool.setClusterId(cluster.getId()); - _spDao.update(spool.getId(), spool); - - System.out.println("Join host " + spool.getName() + " to auto-formed cluster"); - } - } - } - - private void composeDomainPath(DomainVO domain, StringBuilder sb) { - if(domain.getParent() == null) { - sb.append("/"); - } else { - DomainVO parent = _domainDao.findById(domain.getParent()); - composeDomainPath(parent, sb); - - if(domain.getName().contains("/")) { - System.out.println("Domain " + domain.getName() + " contains invalid domain character, replace it with -"); - sb.append(domain.getName().replace('/', '-')); - } else { - sb.append(domain.getName()); - } - sb.append("/"); - } - } - - private void migrateDomains() { - System.out.println("Migrating domains..."); - - // we shouldn't have too many domains in the system, use a very dumb way to setup domain path - List domains = _domainDao.listAllIncludingRemoved(); - for(DomainVO domain : domains) { - StringBuilder path = new StringBuilder(); - composeDomainPath(domain, path); - - System.out.println("Convert domain path, domin: " + domain.getId() + ", path:" + path.toString()); - - domain.setPath(path.toString()); - _domainDao.update(domain.getId(), domain); - } - - System.out.println("All domains have been migrated to 2.1 format"); - } - - private void migrateServiceOfferings() { - System.out.println("Migrating service offering..."); - - long seq = getServiceOfferingStartSequence(); - - List oldServiceOfferings = _serviceOffering20Dao.listAllIncludingRemoved(); - for(ServiceOffering20VO so20 : oldServiceOfferings) { - ServiceOffering21VO so21 = new ServiceOffering21VO(so20.getName(), so20.getCpu(), so20.getRamSize(), so20.getSpeed(), so20.getRateMbps(), - so20.getMulticastRateMbps(), so20.getOfferHA(), so20.getDisplayText(), so20.getUseLocalStorage(), - false, null); - so21.setId(seq++); - so21.setDiskSize(0); - so21 = _serviceOffering21Dao.persist(so21); - - if(so20.getId().longValue() != so21.getId()) { - // Update all foreign reference from old value to new value, need to be careful with foreign key constraints - updateServiceOfferingReferences(so20.getId().longValue(), so21.getId()); - } - } - - boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key())); - - // create service offering for system VMs and update references - int proxyRamSize = NumbersUtil.parseInt( - _configDao.getValue(Config.ConsoleProxyRamSize.key()), - ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); - ServiceOffering21VO soConsoleProxy = new ServiceOffering21VO("Fake Offering For DomP", 1, - proxyRamSize, 0, 0, 0, false, null, useLocalStorage, - true, null); - soConsoleProxy.setId(seq++); - soConsoleProxy.setUniqueName("Cloud.com-ConsoleProxy"); - soConsoleProxy = _serviceOffering21Dao.persist(soConsoleProxy); - _consoleProxyServiceOfferingId = soConsoleProxy.getId(); - - int secStorageVmRamSize = NumbersUtil.parseInt( - _configDao.getValue(Config.SecStorageVmRamSize.key()), - SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); - ServiceOffering21VO soSecondaryVm = new ServiceOffering21VO("Fake Offering For Secondary Storage VM", 1, - secStorageVmRamSize, 0, 0, 0, false, null, useLocalStorage, true, null); - soSecondaryVm.setId(seq++); - soSecondaryVm.setUniqueName("Cloud.com-SecondaryStorage"); - soSecondaryVm = _serviceOffering21Dao.persist(soSecondaryVm); - _secStorageServiceOfferingId = soSecondaryVm.getId(); - - int routerRamSize = NumbersUtil.parseInt(_configDao.getValue("router.ram.size"), 128); - ServiceOffering21VO soDomainRouter = new ServiceOffering21VO("Fake Offering For DomR", 1, - routerRamSize, 0, 0, 0, false, null, useLocalStorage, true, null); - soDomainRouter.setId(seq++); - soDomainRouter.setUniqueName("Cloud.Com-SoftwareRouter"); - soDomainRouter = _serviceOffering21Dao.persist(soDomainRouter); - _domRServiceOfferingId = soDomainRouter.getId(); - - System.out.println("Service offering has been migrated to 2.1 format"); - } - - private long getServiceOfferingStartSequence() { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - long seq = 0; - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement("SELECT max(id) FROM service_offering"); - ResultSet rs = pstmt.executeQuery(); - rs.next(); - seq = rs.getLong(1); - pstmt.close(); - - pstmt = txn.prepareAutoCloseStatement("SELECT max(id) FROM disk_offering"); - rs = pstmt.executeQuery(); - rs.next(); - seq += rs.getLong(1); - pstmt.close(); - - seq += 100; // add a gap - return seq; - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - - return 10000; - } - - private void updateConsoleProxyServiceOfferingReferences(long serviceOfferingId) { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement( - "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='ConsoleProxy')"); - pstmt.setLong(1, serviceOfferingId); - - int rows = pstmt.executeUpdate(); - s_logger.info("Update volumes for console proxy service offering change, affected rows: " + rows); - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - } - - private void updateSecondaryStorageServiceOfferingReferences(long serviceOfferingId) { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement( - "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='SecondaryStorageVm')"); - pstmt.setLong(1, serviceOfferingId); - - int rows = pstmt.executeUpdate(); - s_logger.info("Update volumes for secondary storage service offering change, affected rows: " + rows); - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - } - - private void updateDomainRouterServiceOfferingReferences(long serviceOfferingId) { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement( - "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='DomainRouter')"); - pstmt.setLong(1, serviceOfferingId); - - int rows = pstmt.executeUpdate(); - s_logger.info("Update volumes for secondary storage service offering change, affected rows: " + rows); - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - } - - private void updateServiceOfferingReferences(long oldServiceOfferingId, long newServiceOfferingId) { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement("UPDATE user_vm SET service_offering_id=? WHERE service_offering_id=?"); - - pstmt.setLong(1, newServiceOfferingId); - pstmt.setLong(2, oldServiceOfferingId); - - int rows = pstmt.executeUpdate(); - s_logger.info("Update user_vm for service offering change (" + oldServiceOfferingId + "->" + newServiceOfferingId + "), affected rows: " + rows); - - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - } - - private void migrateDiskOfferings() { - System.out.println("Migrating disk offering..."); - - List oldDiskOfferings = _diskOffering20Dao.listAllIncludingRemoved(); - long maxDiskOfferingId = _domRServiceOfferingId; - maxDiskOfferingId += 100; - - for(DiskOffering20VO do20 : oldDiskOfferings) { - DiskOffering21VO do21 = new DiskOffering21VO(do20.getDomainId(), do20.getName(), do20.getDisplayText(), do20.getDiskSize(), - do20.getMirrored(), null); - do21.setType(Type.Disk); - do21.setId(maxDiskOfferingId++); - - do21 = _diskOffering21Dao.persist(do21); - if(do20.getId().longValue() != do21.getId()) { - updateDiskOfferingReferences(do20.getId().longValue(), do21.getId()); - } - } - - FixupNullDiskOfferingInVolumes(); - - System.out.println("Disk offering has been migrated to 2.1 format"); - } - - private void FixupNullDiskOfferingInVolumes() { - System.out.println("Fixup NULL disk_offering_id references in volumes table ..."); - - SearchCriteria scDiskOffering = _diskOffering21Dao.createSearchCriteria(); - List offeringList = _diskOffering21Dao.searchIncludingRemoved(scDiskOffering, - new Filter(DiskOffering21VO.class, "diskSize", true, null, null), false, false); - - for(DiskOffering21VO offering : offeringList) { - s_logger.info("Disk offering name: " + offering.getName() + ", disk size: " + offering.getDiskSizeInBytes()); - } - - SearchBuilder sb = _volumeDao.createSearchBuilder(); - sb.and("diskOfferingId", sb.entity().getDiskOfferingId(), Op.NULL); - sb.done(); - - SearchCriteria sc = sb.create(); - List volumes = _volumeDao.searchIncludingRemoved(sc, null, false, false); - - if(volumes.size() > 0) { - for(VolumeVO vol : volumes) { - if(vol.getInstanceId() != null) { - VMInstanceVO vmInstance = _vmInstanceDao.findById(vol.getInstanceId()); - - if(vmInstance.getType() == VirtualMachine.Type.User) { - // if the volume is for user VM, we can retrieve the information from service_offering_id - UserVmVO userVm = _userVmDao.findById(vol.getInstanceId()); - if(userVm != null) { - // following operation requires that all service offerings should have been fixed up already - vol.setDiskOfferingId(userVm.getServiceOfferingId()); - } else { - System.out.println("Data integrity could not be fixed up for volume: " + vol.getId() + " because its owner user vm no longer exists"); - } - } else if(vmInstance.getType() == VirtualMachine.Type.ConsoleProxy) { - vol.setDiskOfferingId(this._consoleProxyServiceOfferingId); - } else if(vmInstance.getType() == VirtualMachine.Type.SecondaryStorageVm) { - vol.setDiskOfferingId(this._secStorageServiceOfferingId); - } else if(vmInstance.getType() == VirtualMachine.Type.DomainRouter) { - vol.setDiskOfferingId(this._domRServiceOfferingId); - } - } else { - System.out.println("volume: " + vol.getId() + " is standalone, fix disck_offering_id based on volume size"); - - // try to guess based on volume size and fill it in - boolean found = false; - for(DiskOffering21VO do21 : offeringList) { - if(do21.getType() == Type.Disk && vol.getSize() > do21.getDiskSizeInBytes()) { - found = true; - System.out.println("volume: " + vol.getId() + " disck_offering_id is fixed to " + do21.getId()); - vol.setDiskOfferingId(do21.getId()); - break; - } - } - - if(!found) { - System.out.println("volume: " + vol.getId() + " disck_offering_id is fixed to " + offeringList.get(offeringList.size() - 1).getId()); - vol.setDiskOfferingId(offeringList.get(offeringList.size() - 1).getId()); - } - } - - _volumeDao.update(vol.getId(), vol); - } - } - - System.out.println("Disk offering fixup is done"); - } - - private void updateDiskOfferingReferences(long oldDiskOfferingId, long newDiskOfferingId) { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - PreparedStatement pstmt = null; - pstmt = txn.prepareAutoCloseStatement("UPDATE vm_disk SET disk_offering_id=? WHERE disk_offering_id=?"); - - pstmt.setLong(1, newDiskOfferingId); - pstmt.setLong(2, oldDiskOfferingId); - - int rows = pstmt.executeUpdate(); - pstmt.close(); - - s_logger.info("Update vm_disk for disk offering change (" + oldDiskOfferingId + "->" + newDiskOfferingId + "), affected rows: " + rows); - - pstmt = txn.prepareAutoCloseStatement("UPDATE volumes SET disk_offering_id=? WHERE disk_offering_id=?"); - pstmt.setLong(1, newDiskOfferingId); - pstmt.setLong(2, oldDiskOfferingId); - rows = pstmt.executeUpdate(); - pstmt.close(); - s_logger.info("Update volumes for disk offering change (" + oldDiskOfferingId + "->" + newDiskOfferingId + "), affected rows: " + rows); - } catch (SQLException e) { - s_logger.error("Unhandled exception: ", e); - } finally { - txn.close(); - } - } - - private void migrateSystemVmGuestMacAndState(long zoneId) { - // for console proxy VMs - SearchBuilder sb = _consoleProxyDao.createSearchBuilder(); - sb.and("zoneId", sb.entity().getDataCenterIdToDeployIn(), Op.EQ); - sb.done(); - - SearchCriteria sc = sb.create(); - sc.setParameters("zoneId", zoneId); - - List proxies =_consoleProxyDao.searchIncludingRemoved(sc, null, false, false); - for(ConsoleProxyVO proxy : proxies) { - String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(zoneId, (1L << 31)); - String guestMacAddress = macAddresses[0]; - - if(proxy.getState() == State.Running || proxy.getState() == State.Starting) { - System.out.println("System VM " + proxy.getHostName() + " is in active state, mark it to Stopping state for migration"); - proxy.setState(State.Stopping); - } - - String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(proxy.getDataCenterIdToDeployIn(), proxy.getPodIdToDeployIn(), proxy.getId(), null); - - System.out.println("Assign link loal address to proxy " + proxy.getHostName() + ", link local address: " + guestIpAddress); - _consoleProxyDao.update(proxy.getId(), proxy); - } - - // for secondary storage VMs - SearchBuilder sb2 = _secStorageVmDao.createSearchBuilder(); - sb2.and("zoneId", sb2.entity().getDataCenterIdToDeployIn(), Op.EQ); - sb2.done(); - - SearchCriteria sc2 = sb2.create(); - sc2.setParameters("zoneId", zoneId); - - List secStorageVms =_secStorageVmDao.searchIncludingRemoved(sc2, null, false, false); - for(SecondaryStorageVmVO secStorageVm : secStorageVms) { - String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(zoneId, (1L << 31)); - String guestMacAddress = macAddresses[0]; - - if(secStorageVm.getState() == State.Running || secStorageVm.getState() == State.Starting) { - System.out.println("System VM " + secStorageVm.getHostName() + " is in active state, mark it to Stopping state for migration"); - secStorageVm.setState(State.Stopping); - } - - String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(secStorageVm.getDataCenterIdToDeployIn(), secStorageVm.getPodIdToDeployIn(), secStorageVm.getId(), null); - - System.out.println("Assign link loal address to secondary storage VM " + secStorageVm.getHostName() + ", link local address: " + guestIpAddress); - _secStorageVmDao.update(secStorageVm.getId(), secStorageVm); - } - - // for Domain Router VMs - // Although we can list those we are interested, but just too lazy, list all of them and check their states. - SearchBuilder sb3 = _routerDao.createSearchBuilder(); - sb3.and("zoneId", sb3.entity().getDataCenterIdToDeployIn(), Op.EQ); - sb3.done(); - - SearchCriteria sc3 = sb3.create(); - sc3.setParameters("zoneId", zoneId); - List domRs = _routerDao.searchIncludingRemoved(sc3, null, false, false); - for(DomainRouterVO router : domRs) { - if(router.getState() == State.Running || router.getState() == State.Starting) { - router.setState(State.Stopping); - - System.out.println("System VM " + router.getHostName() + " is in active state, mark it to Stopping state for migration"); - _routerDao.update(router.getId(), router); - } - } - } - - private void migrateVmInstanceLastHostId(long zoneId, long podId) { - SearchBuilder sb = _vmInstanceDao.createSearchBuilder(); - sb.and("zoneId", sb.entity().getDataCenterIdToDeployIn(), Op.EQ); - sb.and("podId", sb.entity().getPodIdToDeployIn(), Op.EQ); - sb.done(); - - Random rand = new Random(); - SearchCriteria sc = sb.create(); - sc.setParameters("zoneId", zoneId); - sc.setParameters("podId", podId); - List vmInstances = _vmInstanceDao.searchIncludingRemoved(sc, null, false, false); - List podHosts = getHostsInPod(zoneId, podId); - for(VMInstanceVO vm : vmInstances) { - if(vm.getHostId() != null) { - vm.setLastHostId(vm.getHostId()); - } else { - if(podHosts.size() > 0) { - int next = rand.nextInt(podHosts.size()); - vm.setLastHostId(podHosts.get(next).getId()); - } - } - _vmInstanceDao.update(vm.getId(), vm); - } - } - - private List getHostsInPod(long zoneId, long podId) { - SearchBuilder sb = _hostDao.createSearchBuilder(); - sb.and("zoneId", sb.entity().getDataCenterId(), Op.EQ); - sb.and("podId", sb.entity().getPodId(), Op.EQ); - sb.and("type", sb.entity().getType(), Op.EQ); - sb.done(); - - SearchCriteria sc = sb.create(); - sc.setParameters("zoneId", zoneId); - sc.setParameters("podId", podId); - sc.setParameters("type", Host.Type.Routing.toString()); - - return _hostDao.searchIncludingRemoved(sc, null, false, false); - } - - private void migrateVolumDeviceIds() { - System.out.println("Migrating device_id for volumes, this may take a while, please wait..."); - SearchCriteria sc = _vmInstanceDao.createSearchCriteria(); - List vmInstances = _vmInstanceDao.searchIncludingRemoved(sc, null, false, false); - - long deviceId = 1; - for(VMInstanceVO vm: vmInstances) { - SearchBuilder sb = _volumeDao.createSearchBuilder(); - sb.and("instanceId", sb.entity().getInstanceId(), Op.EQ); - sb.done(); - - SearchCriteria sc2 = sb.create(); - sc2.setParameters("instanceId", vm.getId()); - - List volumes = _volumeDao.searchIncludingRemoved(sc2, null, false, false); - deviceId = 1; // reset for each VM iteration - for(VolumeVO vol : volumes) { - if(vol.getVolumeType() == Volume.Type.ROOT) { - System.out.println("Setting root volume device id to zero, vol: " + vol.getName() + ", instance: " + vm.getHostName()); - - vol.setDeviceId(0L); - } else if(vol.getVolumeType() == Volume.Type.DATADISK) { - System.out.println("Setting data volume device id, vol: " + vol.getName() + ", instance: " + vm.getHostName() + ", device id: " + deviceId); - - vol.setDeviceId(deviceId); - - // don't use device ID 3 - if(++deviceId == 3) { - deviceId++; - } - } else { - System.out.println("Unsupported volume type found for volume: " + vol.getName()); - } - - _volumeDao.update(vol.getId(), vol); - } - } - - System.out.println("Migrating device_id for volumes done"); - } - - private void migrateVolumePoolType() { - System.out.println("Migrating pool type for volumes..."); - - SearchCriteria sc = _volumeDao.createSearchCriteria(); - List volumes = _volumeDao.searchIncludingRemoved(sc, null, false, false); - for(VolumeVO vol : volumes) { - if(vol.getPoolId() != null) { - StoragePoolVO pool = _poolDao.findById(vol.getPoolId()); - if(pool != null) { - vol.setPoolType(pool.getPoolType()); - - _volumeDao.update(vol.getId(), vol); - } else { - System.out.println("Unable to determine pool type for volume: " + vol.getName()); - } - } - } - - System.out.println("Migrating pool type for volumes done"); - } - - private void migrateConfiguration() { - System.out.println("Migrating 2.1 configuration variables..."); - - System.out.print("Are you migrating from 2.0 Premium Edition? (yes/no): "); - String answer = readInput(); - if(answer != null && answer.equalsIgnoreCase("yes")) { - _isPremium = true; - } - - // Save default Configuration Table values - List categories = Config.getCategories(); - for (String category : categories) { - // If this is not a premium environment, don't insert premium configuration values - if (!_isPremium && category.equals("Premium")) { - continue; - } - - List configs = Config.getConfigs(category); - for (Config c : configs) { - String name = c.key(); - - // If the value is already in the table, don't reinsert it - if (_configDao.getValue(name) != null) { - continue; - } - - String instance = "DEFAULT"; - String component = c.getComponent(); - String value = c.getDefaultValue(); - String description = c.getDescription(); - ConfigurationVO configVO = new ConfigurationVO(category, instance, component, name, value, description); - _configDao.persist(configVO); - } - - // If this is a premium environment, set the network type to be "vlan" - if (_isPremium) { - _configDao.update("network.type", "vlan"); - _configDao.update("hypervisor.type", "xenserver"); - _configDao.update("secondary.storage.vm", "true"); - _configDao.update("secstorage.encrypt.copy", "true"); - _configDao.update("secstorage.secure.copy.cert", "realhostip"); - } - - boolean externalIpAlloator = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled")); - String hyperVisor = _configDao.getValue("hypervisor.type"); - if (hyperVisor.equalsIgnoreCase("KVM") && !externalIpAlloator) { - /*For KVM, it's enabled by default*/ - _configDao.update("direct.attach.network.externalIpAllocator.enabled", "true"); - } - - // Save the mount parent to the configuration table - String mountParent = getMountParent(); - if (mountParent != null) { - _configDao.update("mount.parent", mountParent); - } - - if(_configDao.getValue("host") == null) { - String hostIpAdr = getHost(); - if (hostIpAdr != null) { - _configDao.update("host", hostIpAdr); - } - } - - // generate a single sign-on key - updateSSOKey(); - } - - System.out.println("Migrating 2.1 configuration done"); - } - - private String getEthDevice() { - String defaultRoute = Script.runSimpleBashScript("/sbin/route | grep default"); - - if (defaultRoute == null) { - return null; - } - - String[] defaultRouteList = defaultRoute.split("\\s+"); - - if (defaultRouteList.length != 8) { - return null; - } - - return defaultRouteList[7]; - } - - protected String getHost() { - NetworkInterface nic = null; - String pubNic = getEthDevice(); - - if (pubNic == null) { - return null; - } - - try { - nic = NetworkInterface.getByName(pubNic); - } catch (final SocketException e) { - return null; - } - - String[] info = NetUtils.getNetworkParams(nic); - return info[0]; - } - - private String getMountParent() { - return getEnvironmentProperty("mount.parent"); - } - - private String getEnvironmentProperty(String name) { - try { - final File propsFile = PropertiesUtil.findConfigFile("environment.properties"); - - if (propsFile == null) { - return null; - } else { - final FileInputStream finputstream = new FileInputStream(propsFile); - final Properties props = new Properties(); - props.load(finputstream); - finputstream.close(); - return props.getProperty("mount.parent"); - } - } catch (IOException e) { - return null; - } - } - - private void updateSSOKey() { - try { - String encodedKey = null; - - // Algorithm for SSO Keys is SHA1, should this be configuable? - KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1"); - SecretKey key = generator.generateKey(); - encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded()); - - _configDao.update("security.singlesignon.key", encodedKey); - } catch (NoSuchAlgorithmException ex) { - s_logger.error("error generating sso key", ex); - } - } - - private void doMigration() { - setupComponents(); - - migrateZones(); - migrateDomains(); - migrateServiceOfferings(); - migrateDiskOfferings(); - migrateVolumDeviceIds(); - migrateVolumePoolType(); - migrateConfiguration(); - - // update disk_offering_id for system VMs. As of the id-space collision for servercie_offering_ids - // before and after migration, this should be done in the last step - updateConsoleProxyServiceOfferingReferences(_consoleProxyServiceOfferingId); - updateSecondaryStorageServiceOfferingReferences(_secStorageServiceOfferingId); - updateDomainRouterServiceOfferingReferences(_domRServiceOfferingId); - - System.out.println("Migration done"); - } - - private String readInput() { - try { - Scanner in = new Scanner(System.in); - String input = in.nextLine(); - return input; - } catch(NoSuchElementException e) { - return ""; - } - } - - private void setupComponents() { - ComponentLocator.getLocator("migration", "migration-components.xml", "log4j-cloud.xml"); - ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _configDao = locator.getDao(ConfigurationDao.class); - _podDao = locator.getDao(HostPodDao.class); - _dcDao = locator.getDao(DataCenterDao.class); - _clusterDao = locator.getDao(ClusterDao.class); - _hostDao = locator.getDao(HostDao.class); - _spDao = locator.getDao(StoragePoolDao.class); - _domainDao = locator.getDao(DomainDao.class); - _serviceOffering20Dao = locator.getDao(ServiceOffering20Dao.class); - _diskOffering20Dao = locator.getDao(DiskOffering20Dao.class); - _serviceOffering21Dao = locator.getDao(ServiceOffering21Dao.class); - _diskOffering21Dao = locator.getDao(DiskOffering21Dao.class); - _consoleProxyDao = locator.getDao(ConsoleProxyDao.class); - _secStorageVmDao = locator.getDao(SecondaryStorageVmDao.class); - _vmInstanceDao = locator.getDao(VMInstanceDao.class); - _volumeDao = locator.getDao(VolumeDao.class); - _userVmDao = locator.getDao(UserVmDao.class); - _routerDao = locator.getDao(DomainRouterDao.class); - _poolDao = locator.getDao(StoragePoolDao.class); - } - - public static void main(String[] args) { - File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); - - if(file != null) { - System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); - } else { - System.out.println("Configure log4j with default properties"); - } - - new Db20to21MigrationUtil().doMigration(); - System.exit(0); - } -} +package com.cloud.migration; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.security.NoSuchAlgorithmException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Properties; +import java.util.Random; +import java.util.Scanner; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; + +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + +import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationVO; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.consoleproxy.ConsoleProxyManager; +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.HostPodDao; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.migration.DiskOffering21VO.Type; +import com.cloud.offering.ServiceOffering; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.storage.secondary.SecondaryStorageVmManager; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.PropertiesUtil; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.net.NetUtils; +import com.cloud.utils.script.Script; +import com.cloud.vm.ConsoleProxyVO; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.SecondaryStorageVmVO; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.dao.ConsoleProxyDao; +import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.SecondaryStorageVmDao; +import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.VMInstanceDao; + +public class Db20to21MigrationUtil { + private static final Logger s_logger = Logger.getLogger(Db20to21MigrationUtil.class); + + protected DataCenterDao _dcDao; + protected HostPodDao _podDao; + protected ConfigurationDao _configDao; + protected ClusterDao _clusterDao; + protected HostDao _hostDao; + protected StoragePoolDao _spDao; + protected DomainDao _domainDao; + protected ServiceOffering20Dao _serviceOffering20Dao; + protected DiskOffering20Dao _diskOffering20Dao; + protected ServiceOffering21Dao _serviceOffering21Dao; + protected DiskOffering21Dao _diskOffering21Dao; + protected ConsoleProxyDao _consoleProxyDao; + protected SecondaryStorageVmDao _secStorageVmDao; + protected VMInstanceDao _vmInstanceDao; + protected VolumeDao _volumeDao; + protected UserVmDao _userVmDao; + protected DomainRouterDao _routerDao; + protected StoragePoolDao _poolDao; + + protected long _consoleProxyServiceOfferingId; + protected long _secStorageServiceOfferingId; + protected long _domRServiceOfferingId; + protected boolean _isPremium = false; + + protected static class DcPod { + long id; + String name; + long count; + + public DcPod() { + } + } + + private void migrateZones() { + boolean createCluster = false; + String value = _configDao.getValue("xen.create.pools.in.pod"); + if (value == null || !value.equalsIgnoreCase("true")) { + s_logger.info("System is not configured to use Xen server pool, we will skip creating cluster for pods"); + } else { + createCluster = true; + } + + // Displaying summarize data center/pod configuration from old DB before we continue + GenericSearchBuilder sb = _dcDao.createSearchBuilder(DcPod.class); + sb.selectField(sb.entity().getId()); + sb.selectField(sb.entity().getName()); + sb.select("count", Func.COUNT, null); + sb.groupBy(sb.entity().getId(), sb.entity().getName()); + sb.done(); + + SearchCriteria sc = sb.create(); + List results = _dcDao.customSearchIncludingRemoved(sc, (Filter) null); + if (results.size() > 0) { + System.out.println("We've found following zones are deployed in your database"); + for (DcPod cols : results) { + System.out.println("\tid: " + cols.id + ",\tname: " + cols.name + ",\tpods in zone: " + cols.count); + } + System.out.println("From 2.0 to 2.1, pod is required to have gateway configuration"); + + for (DcPod cols : results) { + migrateZonePods(cols.id, cols.name, createCluster); + + s_logger.info("Set system VM guest MAC in zone" + cols.name); + migrateSystemVmGuestMacAndState(cols.id); + } + } else { + System.out.println("We couldn't find any zone being deployed. Skip Zone/Pod migration"); + } + } + + private void migrateZonePods(long zoneId, String zoneName, boolean createCluster) { + SearchBuilder sb = _podDao.createSearchBuilder(); + sb.and("zoneId", sb.entity().getDataCenterId(), Op.EQ); + sb.done(); + + SearchCriteria sc = sb.create(); + sc.setParameters("zoneId", zoneId); + + List pods = _podDao.searchIncludingRemoved(sc, null, false, false); + if (pods.size() > 0) { + for (HostPodVO pod : pods) { + System.out.println("Migrating pod " + pod.getName() + " in zone " + zoneName + "..."); + System.out.println("Current pod " + pod.getName() + " configuration as"); + System.out.println("\tCIDR: " + pod.getCidrAddress() + "/" + pod.getCidrSize()); + System.out.println("\tGateway: " + pod.getGateway()); + System.out.print("Please type your gateway address for the pod: "); + + String gateway = readInput(); + pod.setGateway(gateway); + _podDao.update(pod.getId(), pod); + if (createCluster) { + migrateHostsInPod(zoneId, pod.getId(), pod.getName()); + } + + System.out.println("Set last_host_id for VMs in pod " + pod.getName()); + migrateVmInstanceLastHostId(zoneId, pod.getId()); + + System.out.println("Setup link local addresses, it will take a while, please wait..."); + String ipNums = _configDao.getValue("linkLocalIp.nums"); + int nums = Integer.parseInt(ipNums); + if (nums > 16 || nums <= 0) { + nums = 10; + } + + /* local link ip address starts from 169.254.0.2 - 169.254.(nums) */ + String[] ipRanges = NetUtils.getLinkLocalIPRange(nums); + _dcDao.addLinkLocalIpAddress(zoneId, pod.getId(), ipRanges[0], ipRanges[1]); + } + } + } + + private void migrateHostsInPod(long zoneId, long podId, String podName) { + System.out.println("Creating cluster for pod " + podName); + + ClusterVO cluster = null; + + SearchBuilder sb = _hostDao.createSearchBuilder(); + sb.and("dc", sb.entity().getDataCenterId(), Op.EQ); + sb.and("pod", sb.entity().getPodId(), Op.EQ); + sb.and("type", sb.entity().getType(), Op.EQ); + sb.done(); + + SearchCriteria sc = sb.create(); + sc.setParameters("dc", zoneId); + sc.setParameters("pod", podId); + sc.setParameters("type", Host.Type.Routing); + + // join cluster for hosts in pod + List hostsInPod = _hostDao.searchIncludingRemoved(sc, null, false, false); + if (hostsInPod.size() > 0) { + if (cluster == null) { + cluster = new ClusterVO(zoneId, podId, String.valueOf(podId)); + cluster = _clusterDao.persist(cluster); + } + + for (HostVO host : hostsInPod) { + host.setClusterId(cluster.getId()); + _hostDao.update(host.getId(), host); + + System.out.println("Join host " + host.getName() + " to auto-formed cluster"); + } + } + + SearchBuilder sbPool = _spDao.createSearchBuilder(); + sbPool.and("dc", sbPool.entity().getDataCenterId(), Op.EQ); + sbPool.and("pod", sbPool.entity().getPodId(), Op.EQ); + sbPool.and("poolType", sbPool.entity().getPoolType(), Op.IN); + sbPool.done(); + + SearchCriteria scPool = sbPool.create(); + scPool.setParameters("dc", zoneId); + scPool.setParameters("pod", podId); + scPool.setParameters("poolType", StoragePoolType.NetworkFilesystem.toString(), StoragePoolType.IscsiLUN.toString()); + + List sPoolsInPod = _spDao.searchIncludingRemoved(scPool, null, false, false); + if (sPoolsInPod.size() > 0) { + if (cluster == null) { + cluster = new ClusterVO(zoneId, podId, String.valueOf(podId)); + cluster = _clusterDao.persist(cluster); + } + + for (StoragePoolVO spool : sPoolsInPod) { + spool.setClusterId(cluster.getId()); + _spDao.update(spool.getId(), spool); + + System.out.println("Join host " + spool.getName() + " to auto-formed cluster"); + } + } + } + + private void composeDomainPath(DomainVO domain, StringBuilder sb) { + if (domain.getParent() == null) { + sb.append("/"); + } else { + DomainVO parent = _domainDao.findById(domain.getParent()); + composeDomainPath(parent, sb); + + if (domain.getName().contains("/")) { + System.out.println("Domain " + domain.getName() + " contains invalid domain character, replace it with -"); + sb.append(domain.getName().replace('/', '-')); + } else { + sb.append(domain.getName()); + } + sb.append("/"); + } + } + + private void migrateDomains() { + System.out.println("Migrating domains..."); + + // we shouldn't have too many domains in the system, use a very dumb way to setup domain path + List domains = _domainDao.listAllIncludingRemoved(); + for (DomainVO domain : domains) { + StringBuilder path = new StringBuilder(); + composeDomainPath(domain, path); + + System.out.println("Convert domain path, domin: " + domain.getId() + ", path:" + path.toString()); + + domain.setPath(path.toString()); + _domainDao.update(domain.getId(), domain); + } + + System.out.println("All domains have been migrated to 2.1 format"); + } + + private void migrateServiceOfferings() { + System.out.println("Migrating service offering..."); + + long seq = getServiceOfferingStartSequence(); + + List oldServiceOfferings = _serviceOffering20Dao.listAllIncludingRemoved(); + for (ServiceOffering20VO so20 : oldServiceOfferings) { + ServiceOffering21VO so21 = new ServiceOffering21VO(so20.getName(), so20.getCpu(), so20.getRamSize(), so20.getSpeed(), so20.getRateMbps(), + so20.getMulticastRateMbps(), so20.getOfferHA(), so20.getDisplayText(), so20.getUseLocalStorage(), + false, null); + so21.setId(seq++); + so21.setDiskSize(0); + so21 = _serviceOffering21Dao.persist(so21); + + if (so20.getId().longValue() != so21.getId()) { + // Update all foreign reference from old value to new value, need to be careful with foreign key +// constraints + updateServiceOfferingReferences(so20.getId().longValue(), so21.getId()); + } + } + + boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key())); + + // create service offering for system VMs and update references + int proxyRamSize = NumbersUtil.parseInt( + _configDao.getValue(Config.ConsoleProxyRamSize.key()), + ConsoleProxyManager.DEFAULT_PROXY_VM_RAMSIZE); + ServiceOffering21VO soConsoleProxy = new ServiceOffering21VO("Fake Offering For DomP", 1, + proxyRamSize, 0, 0, 0, false, null, useLocalStorage, + true, null); + soConsoleProxy.setId(seq++); + soConsoleProxy.setUniqueName(ServiceOffering.consoleProxyDefaultOffUniqueName); + soConsoleProxy = _serviceOffering21Dao.persist(soConsoleProxy); + _consoleProxyServiceOfferingId = soConsoleProxy.getId(); + + int secStorageVmRamSize = NumbersUtil.parseInt( + _configDao.getValue(Config.SecStorageVmRamSize.key()), + SecondaryStorageVmManager.DEFAULT_SS_VM_RAMSIZE); + ServiceOffering21VO soSecondaryVm = new ServiceOffering21VO("Fake Offering For Secondary Storage VM", 1, + secStorageVmRamSize, 0, 0, 0, false, null, useLocalStorage, true, null); + soSecondaryVm.setId(seq++); + soSecondaryVm.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName); + soSecondaryVm = _serviceOffering21Dao.persist(soSecondaryVm); + _secStorageServiceOfferingId = soSecondaryVm.getId(); + + int routerRamSize = NumbersUtil.parseInt(_configDao.getValue("router.ram.size"), 128); + ServiceOffering21VO soDomainRouter = new ServiceOffering21VO("Fake Offering For DomR", 1, + routerRamSize, 0, 0, 0, false, null, useLocalStorage, true, null); + soDomainRouter.setId(seq++); + soDomainRouter.setUniqueName(ServiceOffering.routerDefaultOffUniqueName); + soDomainRouter = _serviceOffering21Dao.persist(soDomainRouter); + _domRServiceOfferingId = soDomainRouter.getId(); + + System.out.println("Service offering has been migrated to 2.1 format"); + } + + private long getServiceOfferingStartSequence() { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + long seq = 0; + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement("SELECT max(id) FROM service_offering"); + ResultSet rs = pstmt.executeQuery(); + rs.next(); + seq = rs.getLong(1); + pstmt.close(); + + pstmt = txn.prepareAutoCloseStatement("SELECT max(id) FROM disk_offering"); + rs = pstmt.executeQuery(); + rs.next(); + seq += rs.getLong(1); + pstmt.close(); + + seq += 100; // add a gap + return seq; + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + + return 10000; + } + + private void updateConsoleProxyServiceOfferingReferences(long serviceOfferingId) { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement( + "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='ConsoleProxy')"); + pstmt.setLong(1, serviceOfferingId); + + int rows = pstmt.executeUpdate(); + s_logger.info("Update volumes for console proxy service offering change, affected rows: " + rows); + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + } + + private void updateSecondaryStorageServiceOfferingReferences(long serviceOfferingId) { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement( + "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='SecondaryStorageVm')"); + pstmt.setLong(1, serviceOfferingId); + + int rows = pstmt.executeUpdate(); + s_logger.info("Update volumes for secondary storage service offering change, affected rows: " + rows); + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + } + + private void updateDomainRouterServiceOfferingReferences(long serviceOfferingId) { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement( + "UPDATE volumes SET disk_offering_id=? WHERE instance_id IN (SELECT id FROM vm_instance WHERE type='DomainRouter')"); + pstmt.setLong(1, serviceOfferingId); + + int rows = pstmt.executeUpdate(); + s_logger.info("Update volumes for secondary storage service offering change, affected rows: " + rows); + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + } + + private void updateServiceOfferingReferences(long oldServiceOfferingId, long newServiceOfferingId) { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement("UPDATE user_vm SET service_offering_id=? WHERE service_offering_id=?"); + + pstmt.setLong(1, newServiceOfferingId); + pstmt.setLong(2, oldServiceOfferingId); + + int rows = pstmt.executeUpdate(); + s_logger.info("Update user_vm for service offering change (" + oldServiceOfferingId + "->" + newServiceOfferingId + "), affected rows: " + rows); + + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + } + + private void migrateDiskOfferings() { + System.out.println("Migrating disk offering..."); + + List oldDiskOfferings = _diskOffering20Dao.listAllIncludingRemoved(); + long maxDiskOfferingId = _domRServiceOfferingId; + maxDiskOfferingId += 100; + + for (DiskOffering20VO do20 : oldDiskOfferings) { + DiskOffering21VO do21 = new DiskOffering21VO(do20.getDomainId(), do20.getName(), do20.getDisplayText(), do20.getDiskSize(), + do20.getMirrored(), null); + do21.setType(Type.Disk); + do21.setId(maxDiskOfferingId++); + + do21 = _diskOffering21Dao.persist(do21); + if (do20.getId().longValue() != do21.getId()) { + updateDiskOfferingReferences(do20.getId().longValue(), do21.getId()); + } + } + + FixupNullDiskOfferingInVolumes(); + + System.out.println("Disk offering has been migrated to 2.1 format"); + } + + private void FixupNullDiskOfferingInVolumes() { + System.out.println("Fixup NULL disk_offering_id references in volumes table ..."); + + SearchCriteria scDiskOffering = _diskOffering21Dao.createSearchCriteria(); + List offeringList = _diskOffering21Dao.searchIncludingRemoved(scDiskOffering, + new Filter(DiskOffering21VO.class, "diskSize", true, null, null), false, false); + + for (DiskOffering21VO offering : offeringList) { + s_logger.info("Disk offering name: " + offering.getName() + ", disk size: " + offering.getDiskSizeInBytes()); + } + + SearchBuilder sb = _volumeDao.createSearchBuilder(); + sb.and("diskOfferingId", sb.entity().getDiskOfferingId(), Op.NULL); + sb.done(); + + SearchCriteria sc = sb.create(); + List volumes = _volumeDao.searchIncludingRemoved(sc, null, false, false); + + if (volumes.size() > 0) { + for (VolumeVO vol : volumes) { + if (vol.getInstanceId() != null) { + VMInstanceVO vmInstance = _vmInstanceDao.findById(vol.getInstanceId()); + + if (vmInstance.getType() == VirtualMachine.Type.User) { + // if the volume is for user VM, we can retrieve the information from service_offering_id + UserVmVO userVm = _userVmDao.findById(vol.getInstanceId()); + if (userVm != null) { + // following operation requires that all service offerings should have been fixed up already + vol.setDiskOfferingId(userVm.getServiceOfferingId()); + } else { + System.out.println("Data integrity could not be fixed up for volume: " + vol.getId() + " because its owner user vm no longer exists"); + } + } else if (vmInstance.getType() == VirtualMachine.Type.ConsoleProxy) { + vol.setDiskOfferingId(this._consoleProxyServiceOfferingId); + } else if (vmInstance.getType() == VirtualMachine.Type.SecondaryStorageVm) { + vol.setDiskOfferingId(this._secStorageServiceOfferingId); + } else if (vmInstance.getType() == VirtualMachine.Type.DomainRouter) { + vol.setDiskOfferingId(this._domRServiceOfferingId); + } + } else { + System.out.println("volume: " + vol.getId() + " is standalone, fix disck_offering_id based on volume size"); + + // try to guess based on volume size and fill it in + boolean found = false; + for (DiskOffering21VO do21 : offeringList) { + if (do21.getType() == Type.Disk && vol.getSize() > do21.getDiskSizeInBytes()) { + found = true; + System.out.println("volume: " + vol.getId() + " disck_offering_id is fixed to " + do21.getId()); + vol.setDiskOfferingId(do21.getId()); + break; + } + } + + if (!found) { + System.out.println("volume: " + vol.getId() + " disck_offering_id is fixed to " + offeringList.get(offeringList.size() - 1).getId()); + vol.setDiskOfferingId(offeringList.get(offeringList.size() - 1).getId()); + } + } + + _volumeDao.update(vol.getId(), vol); + } + } + + System.out.println("Disk offering fixup is done"); + } + + private void updateDiskOfferingReferences(long oldDiskOfferingId, long newDiskOfferingId) { + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + PreparedStatement pstmt = null; + pstmt = txn.prepareAutoCloseStatement("UPDATE vm_disk SET disk_offering_id=? WHERE disk_offering_id=?"); + + pstmt.setLong(1, newDiskOfferingId); + pstmt.setLong(2, oldDiskOfferingId); + + int rows = pstmt.executeUpdate(); + pstmt.close(); + + s_logger.info("Update vm_disk for disk offering change (" + oldDiskOfferingId + "->" + newDiskOfferingId + "), affected rows: " + rows); + + pstmt = txn.prepareAutoCloseStatement("UPDATE volumes SET disk_offering_id=? WHERE disk_offering_id=?"); + pstmt.setLong(1, newDiskOfferingId); + pstmt.setLong(2, oldDiskOfferingId); + rows = pstmt.executeUpdate(); + pstmt.close(); + s_logger.info("Update volumes for disk offering change (" + oldDiskOfferingId + "->" + newDiskOfferingId + "), affected rows: " + rows); + } catch (SQLException e) { + s_logger.error("Unhandled exception: ", e); + } finally { + txn.close(); + } + } + + private void migrateSystemVmGuestMacAndState(long zoneId) { + // for console proxy VMs + SearchBuilder sb = _consoleProxyDao.createSearchBuilder(); + sb.and("zoneId", sb.entity().getDataCenterIdToDeployIn(), Op.EQ); + sb.done(); + + SearchCriteria sc = sb.create(); + sc.setParameters("zoneId", zoneId); + + List proxies = _consoleProxyDao.searchIncludingRemoved(sc, null, false, false); + for (ConsoleProxyVO proxy : proxies) { + String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(zoneId, (1L << 31)); + String guestMacAddress = macAddresses[0]; + + if (proxy.getState() == State.Running || proxy.getState() == State.Starting) { + System.out.println("System VM " + proxy.getHostName() + " is in active state, mark it to Stopping state for migration"); + proxy.setState(State.Stopping); + } + + String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(proxy.getDataCenterIdToDeployIn(), proxy.getPodIdToDeployIn(), proxy.getId(), null); + + System.out.println("Assign link loal address to proxy " + proxy.getHostName() + ", link local address: " + guestIpAddress); + _consoleProxyDao.update(proxy.getId(), proxy); + } + + // for secondary storage VMs + SearchBuilder sb2 = _secStorageVmDao.createSearchBuilder(); + sb2.and("zoneId", sb2.entity().getDataCenterIdToDeployIn(), Op.EQ); + sb2.done(); + + SearchCriteria sc2 = sb2.create(); + sc2.setParameters("zoneId", zoneId); + + List secStorageVms = _secStorageVmDao.searchIncludingRemoved(sc2, null, false, false); + for (SecondaryStorageVmVO secStorageVm : secStorageVms) { + String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(zoneId, (1L << 31)); + String guestMacAddress = macAddresses[0]; + + if (secStorageVm.getState() == State.Running || secStorageVm.getState() == State.Starting) { + System.out.println("System VM " + secStorageVm.getHostName() + " is in active state, mark it to Stopping state for migration"); + secStorageVm.setState(State.Stopping); + } + + String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(secStorageVm.getDataCenterIdToDeployIn(), secStorageVm.getPodIdToDeployIn(), secStorageVm.getId(), null); + + System.out.println("Assign link loal address to secondary storage VM " + secStorageVm.getHostName() + ", link local address: " + guestIpAddress); + _secStorageVmDao.update(secStorageVm.getId(), secStorageVm); + } + + // for Domain Router VMs + // Although we can list those we are interested, but just too lazy, list all of them and check their states. + SearchBuilder sb3 = _routerDao.createSearchBuilder(); + sb3.and("zoneId", sb3.entity().getDataCenterIdToDeployIn(), Op.EQ); + sb3.done(); + + SearchCriteria sc3 = sb3.create(); + sc3.setParameters("zoneId", zoneId); + List domRs = _routerDao.searchIncludingRemoved(sc3, null, false, false); + for (DomainRouterVO router : domRs) { + if (router.getState() == State.Running || router.getState() == State.Starting) { + router.setState(State.Stopping); + + System.out.println("System VM " + router.getHostName() + " is in active state, mark it to Stopping state for migration"); + _routerDao.update(router.getId(), router); + } + } + } + + private void migrateVmInstanceLastHostId(long zoneId, long podId) { + SearchBuilder sb = _vmInstanceDao.createSearchBuilder(); + sb.and("zoneId", sb.entity().getDataCenterIdToDeployIn(), Op.EQ); + sb.and("podId", sb.entity().getPodIdToDeployIn(), Op.EQ); + sb.done(); + + Random rand = new Random(); + SearchCriteria sc = sb.create(); + sc.setParameters("zoneId", zoneId); + sc.setParameters("podId", podId); + List vmInstances = _vmInstanceDao.searchIncludingRemoved(sc, null, false, false); + List podHosts = getHostsInPod(zoneId, podId); + for (VMInstanceVO vm : vmInstances) { + if (vm.getHostId() != null) { + vm.setLastHostId(vm.getHostId()); + } else { + if (podHosts.size() > 0) { + int next = rand.nextInt(podHosts.size()); + vm.setLastHostId(podHosts.get(next).getId()); + } + } + _vmInstanceDao.update(vm.getId(), vm); + } + } + + private List getHostsInPod(long zoneId, long podId) { + SearchBuilder sb = _hostDao.createSearchBuilder(); + sb.and("zoneId", sb.entity().getDataCenterId(), Op.EQ); + sb.and("podId", sb.entity().getPodId(), Op.EQ); + sb.and("type", sb.entity().getType(), Op.EQ); + sb.done(); + + SearchCriteria sc = sb.create(); + sc.setParameters("zoneId", zoneId); + sc.setParameters("podId", podId); + sc.setParameters("type", Host.Type.Routing.toString()); + + return _hostDao.searchIncludingRemoved(sc, null, false, false); + } + + private void migrateVolumDeviceIds() { + System.out.println("Migrating device_id for volumes, this may take a while, please wait..."); + SearchCriteria sc = _vmInstanceDao.createSearchCriteria(); + List vmInstances = _vmInstanceDao.searchIncludingRemoved(sc, null, false, false); + + long deviceId = 1; + for (VMInstanceVO vm : vmInstances) { + SearchBuilder sb = _volumeDao.createSearchBuilder(); + sb.and("instanceId", sb.entity().getInstanceId(), Op.EQ); + sb.done(); + + SearchCriteria sc2 = sb.create(); + sc2.setParameters("instanceId", vm.getId()); + + List volumes = _volumeDao.searchIncludingRemoved(sc2, null, false, false); + deviceId = 1; // reset for each VM iteration + for (VolumeVO vol : volumes) { + if (vol.getVolumeType() == Volume.Type.ROOT) { + System.out.println("Setting root volume device id to zero, vol: " + vol.getName() + ", instance: " + vm.getHostName()); + + vol.setDeviceId(0L); + } else if (vol.getVolumeType() == Volume.Type.DATADISK) { + System.out.println("Setting data volume device id, vol: " + vol.getName() + ", instance: " + vm.getHostName() + ", device id: " + deviceId); + + vol.setDeviceId(deviceId); + + // don't use device ID 3 + if (++deviceId == 3) { + deviceId++; + } + } else { + System.out.println("Unsupported volume type found for volume: " + vol.getName()); + } + + _volumeDao.update(vol.getId(), vol); + } + } + + System.out.println("Migrating device_id for volumes done"); + } + + private void migrateVolumePoolType() { + System.out.println("Migrating pool type for volumes..."); + + SearchCriteria sc = _volumeDao.createSearchCriteria(); + List volumes = _volumeDao.searchIncludingRemoved(sc, null, false, false); + for (VolumeVO vol : volumes) { + if (vol.getPoolId() != null) { + StoragePoolVO pool = _poolDao.findById(vol.getPoolId()); + if (pool != null) { + vol.setPoolType(pool.getPoolType()); + + _volumeDao.update(vol.getId(), vol); + } else { + System.out.println("Unable to determine pool type for volume: " + vol.getName()); + } + } + } + + System.out.println("Migrating pool type for volumes done"); + } + + private void migrateConfiguration() { + System.out.println("Migrating 2.1 configuration variables..."); + + System.out.print("Are you migrating from 2.0 Premium Edition? (yes/no): "); + String answer = readInput(); + if (answer != null && answer.equalsIgnoreCase("yes")) { + _isPremium = true; + } + + // Save default Configuration Table values + List categories = Config.getCategories(); + for (String category : categories) { + // If this is not a premium environment, don't insert premium configuration values + if (!_isPremium && category.equals("Premium")) { + continue; + } + + List configs = Config.getConfigs(category); + for (Config c : configs) { + String name = c.key(); + + // If the value is already in the table, don't reinsert it + if (_configDao.getValue(name) != null) { + continue; + } + + String instance = "DEFAULT"; + String component = c.getComponent(); + String value = c.getDefaultValue(); + String description = c.getDescription(); + ConfigurationVO configVO = new ConfigurationVO(category, instance, component, name, value, description); + _configDao.persist(configVO); + } + + // If this is a premium environment, set the network type to be "vlan" + if (_isPremium) { + _configDao.update("network.type", "vlan"); + _configDao.update("hypervisor.type", "xenserver"); + _configDao.update("secondary.storage.vm", "true"); + _configDao.update("secstorage.encrypt.copy", "true"); + _configDao.update("secstorage.secure.copy.cert", "realhostip"); + } + + boolean externalIpAlloator = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled")); + String hyperVisor = _configDao.getValue("hypervisor.type"); + if (hyperVisor.equalsIgnoreCase("KVM") && !externalIpAlloator) { + /* For KVM, it's enabled by default */ + _configDao.update("direct.attach.network.externalIpAllocator.enabled", "true"); + } + + // Save the mount parent to the configuration table + String mountParent = getMountParent(); + if (mountParent != null) { + _configDao.update("mount.parent", mountParent); + } + + if (_configDao.getValue("host") == null) { + String hostIpAdr = getHost(); + if (hostIpAdr != null) { + _configDao.update("host", hostIpAdr); + } + } + + // generate a single sign-on key + updateSSOKey(); + } + + System.out.println("Migrating 2.1 configuration done"); + } + + private String getEthDevice() { + String defaultRoute = Script.runSimpleBashScript("/sbin/route | grep default"); + + if (defaultRoute == null) { + return null; + } + + String[] defaultRouteList = defaultRoute.split("\\s+"); + + if (defaultRouteList.length != 8) { + return null; + } + + return defaultRouteList[7]; + } + + protected String getHost() { + NetworkInterface nic = null; + String pubNic = getEthDevice(); + + if (pubNic == null) { + return null; + } + + try { + nic = NetworkInterface.getByName(pubNic); + } catch (final SocketException e) { + return null; + } + + String[] info = NetUtils.getNetworkParams(nic); + return info[0]; + } + + private String getMountParent() { + return getEnvironmentProperty("mount.parent"); + } + + private String getEnvironmentProperty(String name) { + try { + final File propsFile = PropertiesUtil.findConfigFile("environment.properties"); + + if (propsFile == null) { + return null; + } else { + final FileInputStream finputstream = new FileInputStream(propsFile); + final Properties props = new Properties(); + props.load(finputstream); + finputstream.close(); + return props.getProperty("mount.parent"); + } + } catch (IOException e) { + return null; + } + } + + private void updateSSOKey() { + try { + String encodedKey = null; + + // Algorithm for SSO Keys is SHA1, should this be configuable? + KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1"); + SecretKey key = generator.generateKey(); + encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded()); + + _configDao.update("security.singlesignon.key", encodedKey); + } catch (NoSuchAlgorithmException ex) { + s_logger.error("error generating sso key", ex); + } + } + + private void doMigration() { + setupComponents(); + + migrateZones(); + migrateDomains(); + migrateServiceOfferings(); + migrateDiskOfferings(); + migrateVolumDeviceIds(); + migrateVolumePoolType(); + migrateConfiguration(); + + // update disk_offering_id for system VMs. As of the id-space collision for servercie_offering_ids + // before and after migration, this should be done in the last step + updateConsoleProxyServiceOfferingReferences(_consoleProxyServiceOfferingId); + updateSecondaryStorageServiceOfferingReferences(_secStorageServiceOfferingId); + updateDomainRouterServiceOfferingReferences(_domRServiceOfferingId); + + System.out.println("Migration done"); + } + + private String readInput() { + try { + Scanner in = new Scanner(System.in); + String input = in.nextLine(); + return input; + } catch (NoSuchElementException e) { + return ""; + } + } + + private void setupComponents() { + ComponentLocator.getLocator("migration", "migration-components.xml", "log4j-cloud.xml"); + ComponentLocator locator = ComponentLocator.getCurrentLocator(); + + _configDao = locator.getDao(ConfigurationDao.class); + _podDao = locator.getDao(HostPodDao.class); + _dcDao = locator.getDao(DataCenterDao.class); + _clusterDao = locator.getDao(ClusterDao.class); + _hostDao = locator.getDao(HostDao.class); + _spDao = locator.getDao(StoragePoolDao.class); + _domainDao = locator.getDao(DomainDao.class); + _serviceOffering20Dao = locator.getDao(ServiceOffering20Dao.class); + _diskOffering20Dao = locator.getDao(DiskOffering20Dao.class); + _serviceOffering21Dao = locator.getDao(ServiceOffering21Dao.class); + _diskOffering21Dao = locator.getDao(DiskOffering21Dao.class); + _consoleProxyDao = locator.getDao(ConsoleProxyDao.class); + _secStorageVmDao = locator.getDao(SecondaryStorageVmDao.class); + _vmInstanceDao = locator.getDao(VMInstanceDao.class); + _volumeDao = locator.getDao(VolumeDao.class); + _userVmDao = locator.getDao(UserVmDao.class); + _routerDao = locator.getDao(DomainRouterDao.class); + _poolDao = locator.getDao(StoragePoolDao.class); + } + + public static void main(String[] args) { + File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); + + if (file != null) { + System.out.println("Log4j configuration from : " + file.getAbsolutePath()); + DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); + } else { + System.out.println("Configure log4j with default properties"); + } + + new Db20to21MigrationUtil().doMigration(); + System.exit(0); + } +} diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 1309e260aa6..04624ae5b15 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -99,6 +99,7 @@ import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.LoadBalancer; +import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; @@ -398,7 +399,7 @@ public class ElasticLoadBalancerManagerImpl implements _elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu, _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, useLocalStorage, true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true); - _elasticLbVmOffering.setUniqueName("Cloud.Com-ElasticLBVm"); + _elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName); _elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 56c2d40eabf..6dc84bc68f7 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -645,7 +645,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true, VirtualMachine.Type.DomainRouter, true); - _offering.setUniqueName("Cloud.Com-SoftwareRouter"); + _offering.setUniqueName(ServiceOffering.routerDefaultOffUniqueName); _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering); // this can sometimes happen, if DB is manually or programmatically manipulated diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 95af635c225..731200fc765 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -160,6 +160,7 @@ import com.cloud.network.NetworkVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; +import com.cloud.offering.ServiceOffering; import com.cloud.org.Grouping.AllocationState; import com.cloud.projects.Project; import com.cloud.projects.Project.ListProjectResourcesCriteria; @@ -631,7 +632,7 @@ public class ManagementServerImpl implements ManagementServer { Long vmId = cmd.getVirtualMachineId(); Long domainId = cmd.getDomainId(); Boolean isSystem = cmd.getIsSystem(); - String vm_type_str = cmd.getSystemVmType(); + String vmTypeStr = cmd.getSystemVmType(); if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) { throw new InvalidParameterValueException("Only ROOT admins can access system's offering"); @@ -696,8 +697,15 @@ public class ManagementServerImpl implements ManagementServer { sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); } - if (vm_type_str != null) { - sc.addAnd("vm_type", SearchCriteria.Op.EQ, vm_type_str); + if (vmTypeStr != null) { + sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr); + } + + if (isSystem && vmTypeStr == null) { + // don't return console proxy and ssvm offerings is not requested with vmTypeStr + sc.addAnd("uniqueName", SearchCriteria.Op.NIN, ServiceOffering.consoleProxyDefaultOffUniqueName, + ServiceOffering.ssvmDefaultOffUniqueName, ServiceOffering.elbVmDefaultOffUniqueName); + } sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 32f4fecfb15..9d6d2886212 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -77,6 +77,7 @@ import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; import com.cloud.network.dao.NetworkDao; +import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.resource.ResourceManager; @@ -834,7 +835,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); _serviceOffering = new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, _secStorageVmRamSize, _secStorageVmCpuMHz, null, null, false, null, _useLocalStorage, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true); - _serviceOffering.setUniqueName("Cloud.com-SecondaryStorage"); + _serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName); _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering); // this can sometimes happen, if DB is manually or programmatically manipulated