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 <T> List<T> executeQuery(Query query) { - return (List<T>)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 @@ -<?xml version="1.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. ---> -<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - -<hibernate-mapping> - <class name="com.cloud.stack.models.CloudStackAccount" table="account" lazy="true"> - <id name="id" type="string" column="uuid" > - </id> - <property name="name"> - <column name="account_name" /> - </property> - <property name="defaultZoneId"> - <column name="default_zone_id" /> - </property> - </class> -</hibernate-mapping> - 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 @@ -<?xml version="1.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. ---> -<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - -<hibernate-mapping> - <class name="com.cloud.stack.models.CloudStackConfiguration" table="configuration" lazy="true"> - <id name="name" type="string" column="name" > - </id> - <property name="category"> - <column name="category" /> - </property> - <property name="value"> - <column name="value" /> - </property> - <property name="description"> - <column name="description" /> - </property> - </class> -</hibernate-mapping> - 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 @@ -<?xml version="1.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. ---> -<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - -<hibernate-mapping> - <class name="com.cloud.stack.models.CloudStackServiceOffering" table="disk_offering" lazy="true"> - <id name="id" type="string" column="uuid" > - </id> - <property name="name"> - <column name="name" /> - </property> - <property name="domainId"> - <column name="domain_id" /> - </property> - </class> -</hibernate-mapping> - 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 @@ <fileset dir="${jar.dir}"> <include name="cloud-awsapi.jar" /> <include name="cloud-jasypt-1.8.jar" /> + <include name="cloud-utils.jar" /> </fileset> </copy> <copy todir="${server.deploy.to.dir}/webapps7080/awsapi/WEB-INF/lib"> 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. <dao name="Site2SiteVpnGatewayDao" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" singleton="false"/> <dao name="Site2SiteVpnConnectionDao" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" singleton="false"/> </configuration-server> -</components.xml> + + <awsapi-ec2server class="com.cloud.bridge.service.EC2MainServlet"> + <dao name="CloudStackConfigurationDao" class="com.cloud.bridge.persist.dao.CloudStackConfigurationDaoImpl" singleton="false"/> + <dao name="UserCredentialsDao" class="com.cloud.bridge.persist.dao.UserCredentialsDaoImpl" singleton="false"/> + <dao name="CloudStackSvcOfferingDao" class="com.cloud.bridge.persist.dao.CloudStackSvcOfferingDaoImpl" singleton="false"/> + <dao name="OfferingDao" class="com.cloud.bridge.persist.dao.OfferingDaoImpl" singleton="false"/> + <dao name="CloudStackAccountDao" class="com.cloud.bridge.persist.dao.CloudStackAccountDaoImpl" singleton="false"/> + </awsapi-ec2server> + + <awsapi-s3server class="com.cloud.bridge.service.S3RestServlet"> + <dao name="CloudStackConfigurationDao" class="com.cloud.bridge.persist.dao.CloudStackConfigurationDaoImpl" singleton="false"/> + <dao name="MHostDao" class="com.cloud.bridge.persist.dao.MHostDaoImpl" singleton="false"/> + <dao name="SHostDao" class="com.cloud.bridge.persist.dao.SHostDaoImpl" singleton="false"/> + <dao name="UserCredentialsDao" class="com.cloud.bridge.persist.dao.UserCredentialsDaoImpl" singleton="false"/> + <dao name="BucketPolicyDao" class="com.cloud.bridge.persist.dao.BucketPolicyDaoImpl" singleton="false"/> + <dao name="MHostMountDao" class="com.cloud.bridge.persist.dao.MHostMountDaoImpl" singleton="false"/> + <dao name="SAclDao" class="com.cloud.bridge.persist.dao.SAclDaoImpl" singleton="false"/> + <dao name="SBucketDao" class="com.cloud.bridge.persist.dao.SBucketDaoImpl" singleton="false"/> + <dao name="SMetaDao" class="com.cloud.bridge.persist.dao.SMetaDaoImpl" singleton="false"/> + <dao name="SObjectDao" class="com.cloud.bridge.persist.dao.SObjectDaoImpl" singleton="false"/> + <dao name="SObjectItemDao" class="com.cloud.bridge.persist.dao.SObjectItemDaoImpl" singleton="false"/> + <dao name="MultiPartPartsDao" class="com.cloud.bridge.persist.dao.MultiPartPartsDaoImpl" singleton="false"/> + <dao name="MultiPartUploadsDao" class="com.cloud.bridge.persist.dao.MultiPartUploadsDaoImpl" singleton="false"/> + <dao name="MultipartMetaDao" class="com.cloud.bridge.persist.dao.MultipartMetaDaoImpl" singleton="false"/> + <dao name="UserCredentialsDao" class="com.cloud.bridge.persist.dao.UserCredentialsDaoImpl" singleton="false"/> + </awsapi-s3server> + +</components.xml> \ 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");
