Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E94E7B7D for ; Fri, 31 Aug 2012 18:54:02 +0000 (UTC) Received: (qmail 24085 invoked by uid 500); 31 Aug 2012 18:54:02 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 24041 invoked by uid 500); 31 Aug 2012 18:54:02 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 23842 invoked by uid 99); 31 Aug 2012 18:54:02 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 18:54:02 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A850122D3D; Fri, 31 Aug 2012 18:54:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: prachidamle@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [6/6] Moved Awsapi (EC2/S3) from Hibernate framework to CloudStack Generic Dao Framework Message-Id: <20120831185401.A850122D3D@tyr.zones.apache.org> Date: Fri, 31 Aug 2012 18:54:01 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/util/CloudStackSessionFactory.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/util/CloudStackSessionFactory.java b/awsapi/src/com/cloud/bridge/util/CloudStackSessionFactory.java deleted file mode 100644 index ac5e2d5..0000000 --- a/awsapi/src/com/cloud/bridge/util/CloudStackSessionFactory.java +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.bridge.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; -import org.jasypt.properties.EncryptableProperties; -import org.apache.log4j.Logger; - -public class CloudStackSessionFactory { - private static CloudStackSessionFactory instance; - public static final Logger logger = Logger.getLogger(CloudStackSessionFactory.class); - - private SessionFactory factory; - - private CloudStackSessionFactory() { - Configuration cfg = new Configuration(); - File file = ConfigurationHelper.findConfigurationFile("CloudStack.cfg.xml"); - - File propertiesFile = ConfigurationHelper.findConfigurationFile("db.properties"); - Properties dbProp = null; - String dbName = null; - String dbHost = null; - String dbUser = null; - String dbPassword = null; - String dbPort = null; - - if (null != propertiesFile) { - - if(EncryptionSecretKeyCheckerUtil.useEncryption()){ - StandardPBEStringEncryptor encryptor = EncryptionSecretKeyCheckerUtil.getEncryptor(); - dbProp = new EncryptableProperties(encryptor); - } else { - dbProp = new Properties(); - } - - try { - dbProp.load( new FileInputStream( propertiesFile )); - } catch (FileNotFoundException e) { - logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e); - } catch (IOException e) { - logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e); - } - } - - - // - // we are packaging hibernate mapping files along with the class files, - // make sure class loader use the same class path when initializing hibernate mapping. - // This is important when we are deploying and testing at different environment (Tomcat/JUnit test runner) - // - if(file != null && dbProp != null){ - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - cfg.configure(file); - - dbHost = dbProp.getProperty( "db.cloud.host" ); - dbName = dbProp.getProperty( "db.cloud.name" ); - dbUser = dbProp.getProperty( "db.cloud.username" ); - dbPassword = dbProp.getProperty( "db.cloud.password" ); - dbPort = dbProp.getProperty( "db.cloud.port" ); - - cfg.setProperty("hibernate.connection.url", "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName); - cfg.setProperty("hibernate.connection.username", dbUser); - cfg.setProperty("hibernate.connection.password", dbPassword); - - - factory = cfg.buildSessionFactory(); - }else{ - logger.warn("Unable to open load db configuration"); - throw new RuntimeException("nable to open load db configuration"); - } - } - - public synchronized static CloudStackSessionFactory getInstance() { - if(instance == null) { - instance = new CloudStackSessionFactory(); - } - return instance; - } - - public Session openSession() { - return factory.openSession(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/util/QueryHelper.java ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/bridge/util/QueryHelper.java b/awsapi/src/com/cloud/bridge/util/QueryHelper.java deleted file mode 100644 index 1a1b582..0000000 --- a/awsapi/src/com/cloud/bridge/util/QueryHelper.java +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.bridge.util; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.hibernate.Query; - -public class QueryHelper { - public static void bindParameters(Query query, Object[] params) { - int pos = 0; - if(params != null && params.length > 0) { - for(Object param : params) { - if(param instanceof Byte) - query.setByte(pos++, ((Byte)param).byteValue()); - else if(param instanceof Short) - query.setShort(pos++, ((Short)param).shortValue()); - else if(param instanceof Integer) - query.setInteger(pos++, ((Integer)param).intValue()); - else if(param instanceof Long) - query.setLong(pos++, ((Long)param).longValue()); - else if(param instanceof Float) - query.setFloat(pos++, ((Float)param).floatValue()); - else if(param instanceof Double) - query.setDouble(pos++, ((Double)param).doubleValue()); - else if(param instanceof Boolean) - query.setBoolean(pos++, ((Boolean)param).booleanValue()); - else if(param instanceof Character) - query.setCharacter(pos++, ((Character)param).charValue()); - else if(param instanceof Date) - query.setDate(pos++, (Date)param); - else if(param instanceof Calendar) - query.setCalendar(pos++, (Calendar)param); - else if(param instanceof CalendarDateParam) - query.setCalendarDate(pos++, ((CalendarDateParam)param).dateValue()); - else if(param instanceof TimestampParam) - query.setTimestamp(pos++, ((TimestampParam)param).timestampValue()); - else if(param instanceof TimeParam) - query.setTime(pos++, ((TimeParam)param).timeValue()); - else if(param instanceof String) - query.setString(pos++, (String)param); - else if(param instanceof TextParam) - query.setText(pos++, ((TextParam)param).textValue()); - else if(param instanceof byte[]) - query.setBinary(pos++, (byte[])param); - else if(param instanceof BigDecimal) - query.setBigDecimal(pos++, (BigDecimal)param); - else if(param instanceof BigInteger) - query.setBigInteger(pos++, (BigInteger)param); - else if(param instanceof Locale) - query.setLocale(pos++, (Locale)param); - else if(param instanceof EntityParam) - query.setEntity(pos++, ((EntityParam)param).entityValue()); - else if(param instanceof Serializable) - query.setSerializable(pos++, (Serializable)param); - else - query.setEntity(pos++, param); - } - } - } - - public static List executeQuery(Query query) { - return (List)query.list(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/stack/models/CloudStackAccount.hbm.xml ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/stack/models/CloudStackAccount.hbm.xml b/awsapi/src/com/cloud/stack/models/CloudStackAccount.hbm.xml deleted file mode 100644 index 7996797..0000000 --- a/awsapi/src/com/cloud/stack/models/CloudStackAccount.hbm.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/stack/models/CloudStackConfiguration.hbm.xml ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/stack/models/CloudStackConfiguration.hbm.xml b/awsapi/src/com/cloud/stack/models/CloudStackConfiguration.hbm.xml deleted file mode 100644 index 134e6f1..0000000 --- a/awsapi/src/com/cloud/stack/models/CloudStackConfiguration.hbm.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/stack/models/CloudStackServiceOffering.hbm.xml ---------------------------------------------------------------------- diff --git a/awsapi/src/com/cloud/stack/models/CloudStackServiceOffering.hbm.xml b/awsapi/src/com/cloud/stack/models/CloudStackServiceOffering.hbm.xml deleted file mode 100644 index 2bbcfd1..0000000 --- a/awsapi/src/com/cloud/stack/models/CloudStackServiceOffering.hbm.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/build/build-aws-api.xml ---------------------------------------------------------------------- diff --git a/build/build-aws-api.xml b/build/build-aws-api.xml index 04db516..9ab267e 100644 --- a/build/build-aws-api.xml +++ b/build/build-aws-api.xml @@ -223,6 +223,7 @@ + http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/client/tomcatconf/components.xml.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index beaac13..3c4b9fd 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -226,4 +226,31 @@ under the License. - + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-cglib.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-cglib.jar b/deps/awsapi-lib/cloud-cglib.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-commons-dbcp-1.4.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-commons-dbcp-1.4.jar b/deps/awsapi-lib/cloud-commons-dbcp-1.4.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-commons-pool-1.5.6.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-commons-pool-1.5.6.jar b/deps/awsapi-lib/cloud-commons-pool-1.5.6.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-ehcache.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-ehcache.jar b/deps/awsapi-lib/cloud-ehcache.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-javax.persistence-2.0.0.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-javax.persistence-2.0.0.jar b/deps/awsapi-lib/cloud-javax.persistence-2.0.0.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/deps/awsapi-lib/cloud-utils.jar ---------------------------------------------------------------------- diff --git a/deps/awsapi-lib/cloud-utils.jar b/deps/awsapi-lib/cloud-utils.jar new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/utils/src/com/cloud/utils/db/Transaction.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/db/Transaction.java b/utils/src/com/cloud/utils/db/Transaction.java index fc49bb0..755de8b 100755 --- a/utils/src/com/cloud/utils/db/Transaction.java +++ b/utils/src/com/cloud/utils/db/Transaction.java @@ -79,6 +79,7 @@ public class Transaction { public static final short CLOUD_DB = 0; public static final short USAGE_DB = 1; + public static final short AWSAPI_DB = 2; public static final short CONNECTED_DB = -1; private static AtomicLong s_id = new AtomicLong(); @@ -223,7 +224,18 @@ public class Transaction { return null; } } - + public static Connection getStandaloneAwsapiConnection() { + try { + Connection conn = s_awsapiDS.getConnection(); + if (s_connLogger.isTraceEnabled()) { + s_connLogger.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); + } + return conn; + } catch (SQLException e) { + s_logger.warn("Unexpected exception: ", e); + return null; + } +} protected void attach(TransactionAttachment value) { _stack.push(new StackElement(ATTACHMENT, value)); } @@ -525,8 +537,18 @@ public class Transaction { throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; + case AWSAPI_DB: + if(s_awsapiDS != null) { + _conn = s_awsapiDS.getConnection(); + } else { + s_logger.warn("A static-initialized variable becomes null, process is dying?"); + throw new CloudRuntimeException("Database is not initialized, process is dying?"); + } + break; + default: - throw new CloudRuntimeException("No database selected for the transaction"); + + throw new CloudRuntimeException("No database selected for the transaction"); } _conn.setAutoCommit(!_txn); @@ -953,6 +975,7 @@ public class Transaction { private static DataSource s_ds; private static DataSource s_usageDS; + private static DataSource s_awsapiDS; static { try { final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); @@ -1035,6 +1058,17 @@ public class Transaction { final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(usageConnectionFactory, usageConnectionPool, new StackKeyedObjectPoolFactory(), null, false, false); s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool()); + + //configure awsapi db + final String awsapiDbName = dbProps.getProperty("db.awsapi.name"); + final GenericObjectPool awsapiConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, + usageMaxWait, usageMaxIdle); + final ConnectionFactory awsapiConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://"+cloudHost + ":" + cloudPort + "/" + awsapiDbName + + "?autoReconnect="+usageAutoReconnect, cloudUsername, cloudPassword); + final PoolableConnectionFactory awsapiPoolableConnectionFactory = new PoolableConnectionFactory(awsapiConnectionFactory, awsapiConnectionPool, + new StackKeyedObjectPoolFactory(), null, false, false); + s_awsapiDS = new PoolingDataSource(awsapiPoolableConnectionFactory.getPool()); + } catch (final Exception e) { final GenericObjectPool connectionPool = new GenericObjectPool(null, 5); final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud", "cloud", "cloud");