mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-cloudstack
This commit is contained in:
commit
4f93161c10
@ -1,4 +1,4 @@
|
|||||||
#!/cygdrive/c/python26/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
# or more contributor license agreements. See the NOTICE file
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
|||||||
@ -1,25 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="test"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/antlr-2.7.6.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/antlr-2.7.6.jar"/>
|
||||||
@ -44,7 +25,6 @@ under the License.
|
|||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/commons-io-1.4.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/commons-io-1.4.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/commons-logging-1.1.1.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/commons-logging-1.1.1.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/dom4j-1.6.1.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/dom4j-1.6.1.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/hibernate3.jar"/>
|
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/httpcore-4.0.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/httpcore-4.0.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/javassist-3.9.0.GA.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/javassist-3.9.0.GA.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/jaxb-api-2.1.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/jaxb-api-2.1.jar"/>
|
||||||
@ -81,5 +61,8 @@ under the License.
|
|||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/rampart-lib/xmlsec-1.4.2.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/rampart-lib/xmlsec-1.4.2.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/awsapi-lib/rampart-lib/xmltooling-1.2.0.jar"/>
|
<classpathentry kind="lib" path="/deps/awsapi-lib/rampart-lib/xmltooling-1.2.0.jar"/>
|
||||||
<classpathentry kind="lib" path="/deps/cloud-servlet-api.jar"/>
|
<classpathentry kind="lib" path="/deps/cloud-servlet-api.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/deps/cloud-javax.persistence-2.0.0.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||||
|
<classpathentry kind="lib" path="/deps/cloud-ehcache.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<!--
|
|
||||||
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-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
|
||||||
|
|
||||||
<hibernate-configuration>
|
|
||||||
<session-factory>
|
|
||||||
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
|
|
||||||
<property name="hibernate.connection.pool_size">20</property>
|
|
||||||
<property name="hibernate.connection.autocommit">false</property>
|
|
||||||
|
|
||||||
<!-- transactiion isolation level : 1 - read uncommitted, 2 - read committed, 4 - repeatable read, 8 - Serializable -->
|
|
||||||
<property name="hibernate.connection.isolation">2</property>
|
|
||||||
|
|
||||||
<property name="hibernate.order_updates">true</property>
|
|
||||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
|
||||||
|
|
||||||
<property name="show_sql">false</property>
|
|
||||||
<!-- to debug hibernate generated SQL, open following configuration property -->
|
|
||||||
<!--
|
|
||||||
<property name="show_sql">true</property>
|
|
||||||
<property name="hibernate.format_sql">true</property>
|
|
||||||
-->
|
|
||||||
<!-- Mapping files -->
|
|
||||||
<mapping resource="com/cloud/bridge/model/UserCredentials.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SHost.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/MHost.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/MHostMount.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SBucket.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SObject.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SObjectItem.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SMeta.hbm.xml"/>
|
|
||||||
<mapping resource="com/cloud/bridge/model/SAcl.hbm.xml"/>
|
|
||||||
</session-factory>
|
|
||||||
</hibernate-configuration>
|
|
||||||
@ -37,15 +37,16 @@ import java.io.InputStream;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import com.cloud.bridge.model.UserCredentials;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
|
||||||
import com.cloud.bridge.service.UserContext;
|
import com.cloud.bridge.service.UserContext;
|
||||||
import com.cloud.bridge.util.AuthenticationUtils;
|
import com.cloud.bridge.util.AuthenticationUtils;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
|
||||||
|
|
||||||
public class AuthenticationHandler implements Handler {
|
public class AuthenticationHandler implements Handler {
|
||||||
protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
|
protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
|
||||||
|
protected final UserCredentialsDaoImpl ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
|
||||||
private DocumentBuilderFactory dbf = null;
|
private DocumentBuilderFactory dbf = null;
|
||||||
|
|
||||||
protected HandlerDescription handlerDesc = new HandlerDescription( "EC2AuthenticationHandler" );
|
protected HandlerDescription handlerDesc = new HandlerDescription( "EC2AuthenticationHandler" );
|
||||||
@ -111,13 +112,15 @@ public class AuthenticationHandler implements Handler {
|
|||||||
logger.debug( "X509 cert's uniqueId: " + uniqueId );
|
logger.debug( "X509 cert's uniqueId: " + uniqueId );
|
||||||
|
|
||||||
// -> find the Cloud API key and the secret key from the cert's uniqueId
|
// -> find the Cloud API key and the secret key from the cert's uniqueId
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
/* UserCredentialsDao credentialDao = new UserCredentialsDao();
|
||||||
UserCredentials cloudKeys = credentialDao.getByCertUniqueId( uniqueId );
|
UserCredentials cloudKeys = credentialDao.getByCertUniqueId( uniqueId );
|
||||||
if ( null == cloudKeys ) {
|
*/
|
||||||
logger.error( "Cert does not map to Cloud API keys: " + uniqueId );
|
UserCredentialsVO cloudKeys = ucDao.getByCertUniqueId(uniqueId);
|
||||||
throw new AxisFault( "User not properly registered: Certificate does not map to Cloud API Keys", "Client.Blocked" );
|
if ( null == cloudKeys ) {
|
||||||
}
|
logger.error( "Cert does not map to Cloud API keys: " + uniqueId );
|
||||||
else UserContext.current().initContext( cloudKeys.getAccessKey(), cloudKeys.getSecretKey(), cloudKeys.getAccessKey(), "SOAP Request", null );
|
throw new AxisFault( "User not properly registered: Certificate does not map to Cloud API Keys", "Client.Blocked" );
|
||||||
|
}
|
||||||
|
else UserContext.current().initContext( cloudKeys.getAccessKey(), cloudKeys.getSecretKey(), cloudKeys.getAccessKey(), "SOAP Request", null );
|
||||||
//System.out.println( "end of cert match: " + UserContext.current().getSecretKey());
|
//System.out.println( "end of cert match: " + UserContext.current().getSecretKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,10 +29,11 @@ import org.apache.axis2.AxisFault;
|
|||||||
import org.apache.axis2.description.HandlerDescription;
|
import org.apache.axis2.description.HandlerDescription;
|
||||||
import org.apache.axis2.description.Parameter;
|
import org.apache.axis2.description.Parameter;
|
||||||
|
|
||||||
import com.cloud.bridge.model.UserCredentials;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
|
||||||
import com.cloud.bridge.service.UserContext;
|
import com.cloud.bridge.service.UserContext;
|
||||||
import com.cloud.bridge.util.S3SoapAuth;
|
import com.cloud.bridge.util.S3SoapAuth;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For SOAP compatibility.
|
* For SOAP compatibility.
|
||||||
@ -40,7 +41,7 @@ import com.cloud.bridge.util.S3SoapAuth;
|
|||||||
|
|
||||||
public class AuthenticationHandler implements Handler {
|
public class AuthenticationHandler implements Handler {
|
||||||
protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
|
protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
|
||||||
|
protected final UserCredentialsDaoImpl ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
|
||||||
protected HandlerDescription handlerDesc = new HandlerDescription( "default handler" );
|
protected HandlerDescription handlerDesc = new HandlerDescription( "default handler" );
|
||||||
private String name = "S3AuthenticationHandler";
|
private String name = "S3AuthenticationHandler";
|
||||||
|
|
||||||
@ -190,8 +191,7 @@ public class AuthenticationHandler implements Handler {
|
|||||||
private String lookupSecretKey( String accessKey )
|
private String lookupSecretKey( String accessKey )
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
UserCredentialsVO cloudKeys = ucDao.getByAccessKey( accessKey );
|
||||||
UserCredentials cloudKeys = credentialDao.getByAccessKey( accessKey );
|
|
||||||
if ( null == cloudKeys ) {
|
if ( null == cloudKeys ) {
|
||||||
logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
|
logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -21,8 +21,8 @@ import org.apache.axis2.description.AxisService;
|
|||||||
import org.apache.axis2.engine.ServiceLifeCycle;
|
import org.apache.axis2.engine.ServiceLifeCycle;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
|
||||||
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +38,7 @@ public class ServiceEngineLifecycle implements ServiceLifeCycle {
|
|||||||
public void startUp(ConfigurationContext config, AxisService service) {
|
public void startUp(ConfigurationContext config, AxisService service) {
|
||||||
// initialize service provider during Axis engine startup
|
// initialize service provider during Axis engine startup
|
||||||
try{
|
try{
|
||||||
UserCredentialsDao.preCheckTableExistence();
|
//UserCredentialsDao.preCheckTableExistence();
|
||||||
ServiceProvider.getInstance();
|
ServiceProvider.getInstance();
|
||||||
ServiceEngineLifecycle.initialized = true;
|
ServiceEngineLifecycle.initialized = true;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|||||||
59
awsapi/src/com/cloud/bridge/model/BucketPolicyVO.java
Normal file
59
awsapi/src/com/cloud/bridge/model/BucketPolicyVO.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="bucket_policies")
|
||||||
|
public class BucketPolicyVO {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@Column(name="BucketName")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Column(name="OwnerCanonicalID")
|
||||||
|
private String ownerCanonicalID;
|
||||||
|
|
||||||
|
@Column(name="Policy")
|
||||||
|
private String policy;
|
||||||
|
|
||||||
|
public BucketPolicyVO() { }
|
||||||
|
public BucketPolicyVO(String bucketName, String client, String policy) {
|
||||||
|
this.bucketName = bucketName;
|
||||||
|
this.ownerCanonicalID = client;
|
||||||
|
this.policy = policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getBucketName() {
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
public void setBucketName(String bucketName) {
|
||||||
|
this.bucketName = bucketName;
|
||||||
|
}
|
||||||
|
public String getOwnerCanonicalID() {
|
||||||
|
return ownerCanonicalID;
|
||||||
|
}
|
||||||
|
public void setOwnerCanonicalID(String ownerCanonicalID) {
|
||||||
|
this.ownerCanonicalID = ownerCanonicalID;
|
||||||
|
}
|
||||||
|
public String getPolicy() {
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
public void setPolicy(String policy) {
|
||||||
|
this.policy = policy;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
awsapi/src/com/cloud/bridge/model/CloudStackAccountVO.java
Normal file
34
awsapi/src/com/cloud/bridge/model/CloudStackAccountVO.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="account")
|
||||||
|
public class CloudStackAccountVO {
|
||||||
|
|
||||||
|
@Column(name="uuid")
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
@Column(name="default_zone_id")
|
||||||
|
private Long defaultZoneId = null;
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDefaultZoneId() {
|
||||||
|
return defaultZoneId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultZoneId(Long defaultZoneId) {
|
||||||
|
this.defaultZoneId = defaultZoneId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="configuration")
|
||||||
|
public class CloudStackConfigurationVO {
|
||||||
|
@Id
|
||||||
|
@Column(name="name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name="value", length=4095)
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
@DB
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="disk_offering")
|
||||||
|
public class CloudStackServiceOfferingVO {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name="id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Column(name="name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name="domain_id")
|
||||||
|
private String domainId;
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getDomainId() {
|
||||||
|
return domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDomainId(String domainId) {
|
||||||
|
this.domainId = domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,55 +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.bridge.model.MHost" table="mhost" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="host">
|
|
||||||
<column name="Host" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="hostKey">
|
|
||||||
<column name="MHostKey" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="version">
|
|
||||||
<column name="Version" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="lastHeartbeatTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="LastHeartbeatTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<set name="localSHosts" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="MHostID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.SHost" />
|
|
||||||
</set>
|
|
||||||
|
|
||||||
<set name="mounts" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="MHostID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.MHostMount" />
|
|
||||||
</set>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -1,46 +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.bridge.model.MHostMount" table="mhost_mount" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="mountPath">
|
|
||||||
<column name="MountPath" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="lastMountTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="LastMountTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<many-to-one name="mhost" column="MHostID"
|
|
||||||
class="com.cloud.bridge.model.MHost"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
<many-to-one name="shost" column="SHostID"
|
|
||||||
class="com.cloud.bridge.model.SHost"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -19,18 +19,46 @@ package com.cloud.bridge.model;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class MHostMount implements Serializable {
|
import javax.persistence.Column;
|
||||||
private static final long serialVersionUID = -1119494563131099642L;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="mhost_mount")
|
||||||
|
public class MHostMountVO implements Serializable {
|
||||||
|
private static final long serialVersionUID = -1119494563131099642L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private MHost mhost;
|
@Column(name="MHostID")
|
||||||
private SHost shost;
|
private long mHostID;
|
||||||
|
|
||||||
|
@Column(name="SHostID")
|
||||||
|
private long sHostID;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private MHostVO mhost;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private SHostVO shost;
|
||||||
|
|
||||||
|
@Column(name="MountPath")
|
||||||
private String mountPath;
|
private String mountPath;
|
||||||
|
|
||||||
|
@Column(name="LastMountTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date lastMountTime;
|
private Date lastMountTime;
|
||||||
|
|
||||||
public MHostMount() {
|
public MHostMountVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -41,19 +69,35 @@ public class MHostMount implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MHost getMhost() {
|
public long getmHostID() {
|
||||||
|
return mHostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setmHostID(long mHostID) {
|
||||||
|
this.mHostID = mHostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getsHostID() {
|
||||||
|
return sHostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setsHostID(long sHostID) {
|
||||||
|
this.sHostID = sHostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MHostVO getMhost() {
|
||||||
return mhost;
|
return mhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMhost(MHost mhost) {
|
public void setMhost(MHostVO mhost) {
|
||||||
this.mhost = mhost;
|
this.mhost = mhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SHost getShost() {
|
public SHostVO getShost() {
|
||||||
return shost;
|
return shost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShost(SHost shost) {
|
public void setShost(SHostVO shost) {
|
||||||
this.shost = shost;
|
this.shost = shost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +122,11 @@ public class MHostMount implements Serializable {
|
|||||||
if(this == other)
|
if(this == other)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!(other instanceof MHostMount))
|
if(!(other instanceof MHostMountVO))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return getMhost().equals(((MHostMount)other).getMhost()) &&
|
return getMhost().equals(((MHostMountVO)other).getMhost()) &&
|
||||||
getShost().equals(((MHostMount)other).getShost());
|
getShost().equals(((MHostMountVO)other).getShost());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -21,20 +21,46 @@ import java.util.Date;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MHost implements Serializable {
|
import javax.persistence.Column;
|
||||||
private static final long serialVersionUID = 4848254624679753930L;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="mhost")
|
||||||
|
public class MHostVO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 4848254624679753930L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="MHostKey", nullable=false)
|
||||||
private String hostKey;
|
private String hostKey;
|
||||||
|
|
||||||
|
@Column(name="Host")
|
||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
|
@Column(name="Version")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@Column(name="LastHeartbeatTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date lastHeartbeatTime;
|
private Date lastHeartbeatTime;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Set<SHostVO> localSHosts = new HashSet<SHostVO>();
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Set<MHostMountVO> mounts = new HashSet<MHostMountVO>();
|
||||||
|
|
||||||
private Set<SHost> localSHosts = new HashSet<SHost>();
|
public MHostVO() {
|
||||||
private Set<MHostMount> mounts = new HashSet<MHostMount>();
|
|
||||||
|
|
||||||
public MHost() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -77,19 +103,19 @@ public class MHost implements Serializable {
|
|||||||
this.lastHeartbeatTime = lastHeartbeatTime;
|
this.lastHeartbeatTime = lastHeartbeatTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SHost> getLocalSHosts() {
|
public Set<SHostVO> getLocalSHosts() {
|
||||||
return localSHosts;
|
return localSHosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocalSHosts(Set<SHost> localSHosts) {
|
public void setLocalSHosts(Set<SHostVO> localSHosts) {
|
||||||
this.localSHosts = localSHosts;
|
this.localSHosts = localSHosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<MHostMount> getMounts() {
|
public Set<MHostMountVO> getMounts() {
|
||||||
return mounts;
|
return mounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMounts(Set<MHostMount> mounts) {
|
public void setMounts(Set<MHostMountVO> mounts) {
|
||||||
this.mounts = mounts;
|
this.mounts = mounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +124,10 @@ public class MHost implements Serializable {
|
|||||||
if(this == other)
|
if(this == other)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!(other instanceof MHost))
|
if(!(other instanceof MHostVO))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return hostKey == ((MHost)other).getHostKey();
|
return hostKey == ((MHostVO)other).getHostKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
108
awsapi/src/com/cloud/bridge/model/MultiPartPartsVO.java
Normal file
108
awsapi/src/com/cloud/bridge/model/MultiPartPartsVO.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="multipart_parts")
|
||||||
|
public class MultiPartPartsVO {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="UploadID")
|
||||||
|
private Long uploadid;
|
||||||
|
|
||||||
|
@Column(name="partNumber")
|
||||||
|
private int partNumber;
|
||||||
|
|
||||||
|
@Column(name="MD5")
|
||||||
|
private String md5;
|
||||||
|
|
||||||
|
@Column(name="StoredPath")
|
||||||
|
private String storedPath;
|
||||||
|
|
||||||
|
@Column(name="StoredSize")
|
||||||
|
private Long storedSize;
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
public MultiPartPartsVO() { }
|
||||||
|
|
||||||
|
public MultiPartPartsVO(int uploadId, int partNumber, String md5,
|
||||||
|
String storedPath, int size, Date date) {
|
||||||
|
this.uploadid = new Long(uploadId);
|
||||||
|
this.partNumber = partNumber;
|
||||||
|
this.md5 = md5;
|
||||||
|
this.storedPath = storedPath;
|
||||||
|
this.storedSize = new Long(size);
|
||||||
|
this.createTime = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUploadid() {
|
||||||
|
return uploadid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadid(Long uploadid) {
|
||||||
|
this.uploadid = uploadid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPartNumber() {
|
||||||
|
return partNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartNumber(int partNumber) {
|
||||||
|
this.partNumber = partNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMd5() {
|
||||||
|
return md5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMd5(String md5) {
|
||||||
|
this.md5 = md5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredPath() {
|
||||||
|
return storedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredPath(String storedPath) {
|
||||||
|
this.storedPath = storedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getStoredSize() {
|
||||||
|
return storedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredSize(Long storedSize) {
|
||||||
|
this.storedSize = storedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
94
awsapi/src/com/cloud/bridge/model/MultiPartUploadsVO.java
Normal file
94
awsapi/src/com/cloud/bridge/model/MultiPartUploadsVO.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="multipart_uploads")
|
||||||
|
|
||||||
|
public class MultiPartUploadsVO {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="AccessKey")
|
||||||
|
private String accessKey;
|
||||||
|
|
||||||
|
@Column(name="BucketName")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Column(name="NameKey")
|
||||||
|
private String nameKey;
|
||||||
|
|
||||||
|
@Column(name="x_amz_acl")
|
||||||
|
private String amzAcl;
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
public MultiPartUploadsVO() {}
|
||||||
|
|
||||||
|
public MultiPartUploadsVO(String accessKey, String bucketName, String key, String cannedAccess, Date tod) {
|
||||||
|
this.accessKey = accessKey;
|
||||||
|
this.bucketName = bucketName;
|
||||||
|
this.nameKey = key;
|
||||||
|
this.amzAcl = cannedAccess;
|
||||||
|
this.createTime = tod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessKey() {
|
||||||
|
return accessKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessKey(String accessKey) {
|
||||||
|
this.accessKey = accessKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBucketName() {
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBucketName(String bucketName) {
|
||||||
|
this.bucketName = bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameKey() {
|
||||||
|
return nameKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameKey(String nameKey) {
|
||||||
|
this.nameKey = nameKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmzAcl() {
|
||||||
|
return amzAcl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmzAcl(String amzAcl) {
|
||||||
|
this.amzAcl = amzAcl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
59
awsapi/src/com/cloud/bridge/model/MultipartMetaVO.java
Normal file
59
awsapi/src/com/cloud/bridge/model/MultipartMetaVO.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="multipart_meta")
|
||||||
|
|
||||||
|
public class MultipartMetaVO {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="UploadID")
|
||||||
|
private long uploadID;
|
||||||
|
|
||||||
|
@Column(name="Name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name="Value")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public long getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUploadID() {
|
||||||
|
return uploadID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadID(long uploadID) {
|
||||||
|
this.uploadID = uploadID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
46
awsapi/src/com/cloud/bridge/model/OfferingBundleVO.java
Normal file
46
awsapi/src/com/cloud/bridge/model/OfferingBundleVO.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="offering_bundle")
|
||||||
|
public class OfferingBundleVO {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@Column(name="AmazonEC2Offering")
|
||||||
|
private String amazonOffering;
|
||||||
|
|
||||||
|
@Column(name="CloudStackOffering")
|
||||||
|
private String cloudstackOffering;
|
||||||
|
|
||||||
|
public long getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmazonOffering() {
|
||||||
|
return amazonOffering;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmazonOffering(String amazonOffering) {
|
||||||
|
this.amazonOffering = amazonOffering;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCloudstackOffering() {
|
||||||
|
return cloudstackOffering;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloudstackOffering(String cloudstackOffering) {
|
||||||
|
this.cloudstackOffering = cloudstackOffering;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,54 +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.bridge.model.SAcl" table="acl" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="target">
|
|
||||||
<column name="Target" />
|
|
||||||
</property>
|
|
||||||
<property name="targetId">
|
|
||||||
<column name="TargetID" />
|
|
||||||
</property>
|
|
||||||
<property name="granteeType">
|
|
||||||
<column name="GranteeType" />
|
|
||||||
</property>
|
|
||||||
<property name="granteeCanonicalId">
|
|
||||||
<column name="GranteeCanonicalID" />
|
|
||||||
</property>
|
|
||||||
<property name="permission">
|
|
||||||
<column name="Permission" />
|
|
||||||
</property>
|
|
||||||
<property name="grantOrder">
|
|
||||||
<column name="GrantOrder" />
|
|
||||||
</property>
|
|
||||||
<property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="CreateTime" />
|
|
||||||
</property>
|
|
||||||
<property name="lastModifiedTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="LastModifiedTime" />
|
|
||||||
</property>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -37,8 +37,7 @@ import com.cloud.bridge.util.Triple;
|
|||||||
* < permission1, permission2, symbol >
|
* < permission1, permission2, symbol >
|
||||||
* when given an aclRequestString, a target (i.e. bucket or object) and the ID of the owner.
|
* when given an aclRequestString, a target (i.e. bucket or object) and the ID of the owner.
|
||||||
*/
|
*/
|
||||||
public class SAcl implements Serializable {
|
public interface SAcl {
|
||||||
private static final long serialVersionUID = 7900837117165018850L;
|
|
||||||
|
|
||||||
public static final int GRANTEE_USER = 0;
|
public static final int GRANTEE_USER = 0;
|
||||||
public static final int GRANTEE_ALLUSERS = 1;
|
public static final int GRANTEE_ALLUSERS = 1;
|
||||||
@ -52,95 +51,6 @@ public class SAcl implements Serializable {
|
|||||||
public static final int PERMISSION_WRITE_ACL = 8;
|
public static final int PERMISSION_WRITE_ACL = 8;
|
||||||
public static final int PERMISSION_FULL = (PERMISSION_READ | PERMISSION_WRITE | PERMISSION_READ_ACL | PERMISSION_WRITE_ACL);
|
public static final int PERMISSION_FULL = (PERMISSION_READ | PERMISSION_WRITE | PERMISSION_READ_ACL | PERMISSION_WRITE_ACL);
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String target;
|
|
||||||
private long targetId;
|
|
||||||
|
|
||||||
private int granteeType;
|
|
||||||
private String granteeCanonicalId;
|
|
||||||
|
|
||||||
private int permission;
|
|
||||||
private int grantOrder;
|
|
||||||
|
|
||||||
private Date createTime;
|
|
||||||
private Date lastModifiedTime;
|
|
||||||
|
|
||||||
public SAcl() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTarget() {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTarget(String target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTargetId() {
|
|
||||||
return targetId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargetId(long targetId) {
|
|
||||||
this.targetId = targetId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGranteeType() {
|
|
||||||
return granteeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGranteeType(int granteeType) {
|
|
||||||
this.granteeType = granteeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGranteeCanonicalId() {
|
|
||||||
return granteeCanonicalId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGranteeCanonicalId(String granteeCanonicalId) {
|
|
||||||
this.granteeCanonicalId = granteeCanonicalId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPermission() {
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermission(int permission) {
|
|
||||||
this.permission = permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGrantOrder() {
|
|
||||||
return grantOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrantOrder(int grantOrder) {
|
|
||||||
this.grantOrder = grantOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreateTime() {
|
|
||||||
return createTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreateTime(Date createTime) {
|
|
||||||
this.createTime = createTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastModifiedTime() {
|
|
||||||
return lastModifiedTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastModifiedTime(Date lastModifiedTime) {
|
|
||||||
this.lastModifiedTime = lastModifiedTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return an OrderedPair
|
/** Return an OrderedPair
|
||||||
* < permission, grantee >
|
* < permission, grantee >
|
||||||
* comprising
|
* comprising
|
||||||
@ -153,9 +63,9 @@ public class SAcl implements Serializable {
|
|||||||
* @param aclRequestString - The requested ACL from the set of AWS S3 canned ACLs
|
* @param aclRequestString - The requested ACL from the set of AWS S3 canned ACLs
|
||||||
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
||||||
*/
|
*/
|
||||||
public static OrderedPair <Integer,Integer> getCannedAccessControls ( String aclRequestString, String target )
|
//public static OrderedPair <Integer,Integer> getCannedAccessControls ( String aclRequestString, String target );
|
||||||
throws UnsupportedException
|
|
||||||
{
|
/* {
|
||||||
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
||||||
// All users granted READ access.
|
// All users granted READ access.
|
||||||
return new OrderedPair <Integer,Integer> (PERMISSION_READ,GRANTEE_ALLUSERS);
|
return new OrderedPair <Integer,Integer> (PERMISSION_READ,GRANTEE_ALLUSERS);
|
||||||
@ -184,7 +94,7 @@ public class SAcl implements Serializable {
|
|||||||
}
|
}
|
||||||
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/** Return a Triple
|
/** Return a Triple
|
||||||
* < permission1, permission2, symbol >
|
* < permission1, permission2, symbol >
|
||||||
* comprising
|
* comprising
|
||||||
@ -200,8 +110,8 @@ public class SAcl implements Serializable {
|
|||||||
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
||||||
* @param ownerID - An ID for the owner, if used in place of symbols "A" or "*"
|
* @param ownerID - An ID for the owner, if used in place of symbols "A" or "*"
|
||||||
*/
|
*/
|
||||||
public static Triple <Integer,Integer,String> getCannedAccessControls ( String aclRequestString, String target, String ownerID )
|
//public static Triple <Integer,Integer,String> getCannedAccessControls ( String aclRequestString, String target, String ownerID );
|
||||||
throws UnsupportedException
|
/* throws UnsupportedException
|
||||||
{
|
{
|
||||||
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
||||||
// Owner gets FULL_CONTROL and the anonymous principal (the 'A' symbol here) is granted READ access.
|
// Owner gets FULL_CONTROL and the anonymous principal (the 'A' symbol here) is granted READ access.
|
||||||
@ -235,5 +145,5 @@ public class SAcl implements Serializable {
|
|||||||
}
|
}
|
||||||
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
254
awsapi/src/com/cloud/bridge/model/SAclVO.java
Normal file
254
awsapi/src/com/cloud/bridge/model/SAclVO.java
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
// 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.model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
import com.cloud.bridge.service.exception.UnsupportedException;
|
||||||
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.bridge.util.Triple;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model of stored ACLs to remember the ACL permissions per canonicalUserID per grantee
|
||||||
|
* Hold the AWS S3 grantee and permission constants.
|
||||||
|
*
|
||||||
|
* This class implements two forms of getCannedAccessControls mappings, as static methods,
|
||||||
|
*
|
||||||
|
* (a) an OrderedPair which provides a maplet across
|
||||||
|
* < permission, grantee >
|
||||||
|
* when given an aclRequestString and a target (i.e. bucket or object),
|
||||||
|
*
|
||||||
|
* (b) a Triplet
|
||||||
|
* < permission1, permission2, symbol >
|
||||||
|
* when given an aclRequestString, a target (i.e. bucket or object) and the ID of the owner.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name="acl")
|
||||||
|
public class SAclVO implements SAcl {
|
||||||
|
private static final long serialVersionUID = 7900837117165018850L;
|
||||||
|
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
@Column(name="Target")
|
||||||
|
private String target;
|
||||||
|
|
||||||
|
@Column(name="TargetID")
|
||||||
|
private long targetId;
|
||||||
|
|
||||||
|
@Column(name="GranteeType")
|
||||||
|
private int granteeType;
|
||||||
|
|
||||||
|
@Column(name="GranteeCanonicalID")
|
||||||
|
private String granteeCanonicalId;
|
||||||
|
|
||||||
|
@Column(name="Permission")
|
||||||
|
private int permission;
|
||||||
|
|
||||||
|
@Column(name="GrantOrder")
|
||||||
|
private int grantOrder;
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name="LastModifiedTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
|
private Date lastModifiedTime;
|
||||||
|
|
||||||
|
public SAclVO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTargetId() {
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetId(long targetId) {
|
||||||
|
this.targetId = targetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGranteeType() {
|
||||||
|
return granteeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGranteeType(int granteeType) {
|
||||||
|
this.granteeType = granteeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGranteeCanonicalId() {
|
||||||
|
return granteeCanonicalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGranteeCanonicalId(String granteeCanonicalId) {
|
||||||
|
this.granteeCanonicalId = granteeCanonicalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermission(int permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGrantOrder() {
|
||||||
|
return grantOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrantOrder(int grantOrder) {
|
||||||
|
this.grantOrder = grantOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastModifiedTime() {
|
||||||
|
return lastModifiedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastModifiedTime(Date lastModifiedTime) {
|
||||||
|
this.lastModifiedTime = lastModifiedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return an OrderedPair
|
||||||
|
* < permission, grantee >
|
||||||
|
* comprising
|
||||||
|
* a permission - which is one of SAcl.PERMISSION_PASS, SAcl.PERMISSION_NONE, SAcl.PERMISSION_READ,
|
||||||
|
* SAcl.PERMISSION_WRITE, SAcl.PERMISSION_READ_ACL, SAcl.PERMISSION_WRITE_ACL, SAcl.PERMISSION_FULL
|
||||||
|
* a grantee - which is one of GRANTEE_ALLUSERS, GRANTEE_AUTHENTICATED, GRANTEE_USER
|
||||||
|
*
|
||||||
|
* Access controls that are specified via the "x-amz-acl:" headers in REST requests for buckets.
|
||||||
|
* The ACL request string is treated as a request for a known cannedAccessPolicy
|
||||||
|
* @param aclRequestString - The requested ACL from the set of AWS S3 canned ACLs
|
||||||
|
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
||||||
|
*/
|
||||||
|
public static OrderedPair <Integer,Integer> getCannedAccessControls ( String aclRequestString, String target )
|
||||||
|
throws UnsupportedException
|
||||||
|
{
|
||||||
|
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
||||||
|
// All users granted READ access.
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_READ,GRANTEE_ALLUSERS);
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "public-read-write" ))
|
||||||
|
// All users granted READ and WRITE access
|
||||||
|
return new OrderedPair <Integer,Integer> ((PERMISSION_READ | PERMISSION_WRITE),GRANTEE_ALLUSERS);
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "authenticated-read" ))
|
||||||
|
// Authenticated users have READ access
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_READ,GRANTEE_AUTHENTICATED);
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "private" ))
|
||||||
|
// Only Owner gets FULL_CONTROL
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_FULL,GRANTEE_USER);
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "bucket-owner-read" ))
|
||||||
|
{
|
||||||
|
// Object Owner gets FULL_CONTROL, Bucket Owner gets READ
|
||||||
|
if ( target.equalsIgnoreCase( "SBucket" ))
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_READ, GRANTEE_USER);
|
||||||
|
else
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_FULL, GRANTEE_USER);
|
||||||
|
}
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "bucket-owner-full-control" ))
|
||||||
|
{
|
||||||
|
// Object Owner gets FULL_CONTROL, Bucket Owner gets FULL_CONTROL
|
||||||
|
// This is equivalent to private when used with PUT Bucket
|
||||||
|
return new OrderedPair <Integer,Integer> (PERMISSION_FULL,GRANTEE_USER);
|
||||||
|
}
|
||||||
|
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return a Triple
|
||||||
|
* < permission1, permission2, symbol >
|
||||||
|
* comprising
|
||||||
|
* two permissions - which is one of SAcl.PERMISSION_PASS, SAcl.PERMISSION_NONE, SAcl.PERMISSION_READ,
|
||||||
|
* SAcl.PERMISSION_WRITE, SAcl.PERMISSION_READ_ACL, SAcl.PERMISSION_WRITE_ACL, SAcl.PERMISSION_FULL
|
||||||
|
* permission1 applies to objects, permission2 applies to buckets.
|
||||||
|
* a symbol to indicate whether the principal is anonymous (i.e. string "A") or authenticated user (i.e.
|
||||||
|
* string "*") - otherwise null indicates a single ACL for all users.
|
||||||
|
*
|
||||||
|
* Access controls that are specified via the "x-amz-acl:" headers in REST requests for buckets.
|
||||||
|
* The ACL request string is treated as a request for a known cannedAccessPolicy
|
||||||
|
* @param aclRequestString - The requested ACL from the set of AWS S3 canned ACLs
|
||||||
|
* @param target - Either "SBucket" or otherwise assumed to be for a single object item
|
||||||
|
* @param ownerID - An ID for the owner, if used in place of symbols "A" or "*"
|
||||||
|
*/
|
||||||
|
public static Triple <Integer,Integer,String> getCannedAccessControls ( String aclRequestString, String target, String ownerID )
|
||||||
|
throws UnsupportedException
|
||||||
|
{
|
||||||
|
if ( aclRequestString.equalsIgnoreCase( "public-read" ))
|
||||||
|
// Owner gets FULL_CONTROL and the anonymous principal (the 'A' symbol here) is granted READ access.
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL, PERMISSION_READ,"A");
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "public-read-write" ))
|
||||||
|
// Owner gets FULL_CONTROL and the anonymous principal (the 'A' symbol here) is granted READ and WRITE access
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL, (PERMISSION_READ | PERMISSION_WRITE),"A");
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "authenticated-read" ))
|
||||||
|
// Owner gets FULL_CONTROL and ANY principal authenticated as a registered S3 user (the '*' symbol here) is granted READ access
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL, PERMISSION_READ,"*");
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "private" ))
|
||||||
|
// This is termed the "private" or default ACL, "Owner gets FULL_CONTROL"
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL, PERMISSION_FULL,null);
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "bucket-owner-read" ))
|
||||||
|
{
|
||||||
|
// Object Owner gets FULL_CONTROL, Bucket Owner gets READ
|
||||||
|
// This is equivalent to private when used with PUT Bucket
|
||||||
|
if ( target.equalsIgnoreCase( "SBucket" ))
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL,PERMISSION_FULL ,null);
|
||||||
|
else
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL,PERMISSION_READ,ownerID);
|
||||||
|
}
|
||||||
|
else if (aclRequestString.equalsIgnoreCase( "bucket-owner-full-control" ))
|
||||||
|
{
|
||||||
|
// Object Owner gets FULL_CONTROL, Bucket Owner gets FULL_CONTROL
|
||||||
|
// This is equivalent to private when used with PUT Bucket
|
||||||
|
if ( target.equalsIgnoreCase( "SBucket" ))
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL, PERMISSION_FULL, null);
|
||||||
|
else
|
||||||
|
return new Triple <Integer, Integer, String> (PERMISSION_FULL,PERMISSION_FULL, ownerID);
|
||||||
|
}
|
||||||
|
else throw new UnsupportedException( "Unknown Canned Access Policy: " + aclRequestString + " is not supported" );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,56 +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.bridge.model.SBucket" table="sbucket" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="name">
|
|
||||||
<column name="Name" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="ownerCanonicalId">
|
|
||||||
<column name="OwnerCanonicalId" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="CreateTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="versioningStatus">
|
|
||||||
<column name="VersioningStatus" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<many-to-one name="shost" column="SHostID"
|
|
||||||
class="com.cloud.bridge.model.SHost"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<set name="objectsInBucket" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="SBucketID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.SObject" />
|
|
||||||
</set>
|
|
||||||
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -31,14 +31,13 @@ import java.util.Set;
|
|||||||
* VersioningStatus
|
* VersioningStatus
|
||||||
* For ORM see "com/cloud/bridge/model/SHost.hbm.xml"
|
* For ORM see "com/cloud/bridge/model/SHost.hbm.xml"
|
||||||
*/
|
*/
|
||||||
public class SBucket implements Serializable {
|
public interface SBucket {
|
||||||
private static final long serialVersionUID = 7430267766019671273L;
|
|
||||||
|
public static final int VERSIONING_NULL = 0;
|
||||||
public static final int VERSIONING_NULL = 0;
|
|
||||||
public static final int VERSIONING_ENABLED = 1;
|
public static final int VERSIONING_ENABLED = 1;
|
||||||
public static final int VERSIONING_SUSPENDED = 2;
|
public static final int VERSIONING_SUSPENDED = 2;
|
||||||
|
|
||||||
private Long id;
|
/* private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String ownerCanonicalId;
|
private String ownerCanonicalId;
|
||||||
@ -124,5 +123,5 @@ public class SBucket implements Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getName().hashCode();
|
return getName().hashCode();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
169
awsapi/src/com/cloud/bridge/model/SBucketVO.java
Normal file
169
awsapi/src/com/cloud/bridge/model/SBucketVO.java
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
// 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.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the relation
|
||||||
|
* Id,
|
||||||
|
* Name,
|
||||||
|
* OwnerCanonicalId,
|
||||||
|
* SHost,
|
||||||
|
* CreateTime,
|
||||||
|
* VersioningStatus
|
||||||
|
* For ORM see "com/cloud/bridge/model/SHost.hbm.xml"
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="sbucket")
|
||||||
|
public class SBucketVO implements SBucket {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="Name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name="OwnerCanonicalID")
|
||||||
|
private String ownerCanonicalId;
|
||||||
|
|
||||||
|
@Column(name="SHostID")
|
||||||
|
private long shostID;
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name="VersioningStatus")
|
||||||
|
private int versioningStatus;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private SHostVO shost;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Set<SObjectVO> objectsInBucket = new HashSet<SObjectVO>();
|
||||||
|
|
||||||
|
public SBucketVO() {
|
||||||
|
versioningStatus = VERSIONING_NULL;
|
||||||
|
this.createTime = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SBucketVO(String bucketName, Date currentGMTTime,
|
||||||
|
String canonicalUserId, SHostVO first) {
|
||||||
|
this.versioningStatus = VERSIONING_NULL;
|
||||||
|
this.name = bucketName;
|
||||||
|
this.createTime = new Date();
|
||||||
|
this.ownerCanonicalId = canonicalUserId;
|
||||||
|
this.shost = first;
|
||||||
|
this.shostID = shost.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnerCanonicalId() {
|
||||||
|
return ownerCanonicalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnerCanonicalId(String ownerCanonicalId) {
|
||||||
|
this.ownerCanonicalId = ownerCanonicalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getShostID() {
|
||||||
|
return shostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShostID(long shostID) {
|
||||||
|
this.shostID = shostID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SHostVO getShost() {
|
||||||
|
return shost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShost(SHostVO shost) {
|
||||||
|
this.shost = shost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getVersioningStatus() {
|
||||||
|
return versioningStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersioningStatus( int versioningStatus ) {
|
||||||
|
this.versioningStatus = versioningStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<SObjectVO> getObjectsInBucket() {
|
||||||
|
return objectsInBucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObjectsInBucket(Set<SObjectVO> objectsInBucket) {
|
||||||
|
this.objectsInBucket = objectsInBucket;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if(this == other)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(!(other instanceof SBucketVO))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return getName().equals(((SBucketVO)other).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getName().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,60 +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.bridge.model.SHost" table="shost" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="host">
|
|
||||||
<column name="Host" />
|
|
||||||
</property>
|
|
||||||
<property name="hostType">
|
|
||||||
<column name="HostType" />
|
|
||||||
</property>
|
|
||||||
<property name="exportRoot">
|
|
||||||
<column name="ExportRoot" />
|
|
||||||
</property>
|
|
||||||
<property name="userOnHost">
|
|
||||||
<column name="UserOnHost"/>
|
|
||||||
</property>
|
|
||||||
<property name="userPassword">
|
|
||||||
<column name="UserPassword"/>
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<many-to-one name="mhost" column="MHostID"
|
|
||||||
class="com.cloud.bridge.model.MHost"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<set name="buckets" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="SHostID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.SBucket" />
|
|
||||||
</set>
|
|
||||||
|
|
||||||
<set name="mounts" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="SHostID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.MHostMount" />
|
|
||||||
</set>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -20,17 +20,19 @@ import java.io.Serializable;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SHost implements Serializable {
|
public interface SHost {
|
||||||
private static final long serialVersionUID = 213346565810468018L;
|
|
||||||
|
|
||||||
public static final int STORAGE_HOST_TYPE_LOCAL = 0;
|
public static final int STORAGE_HOST_TYPE_LOCAL = 0;
|
||||||
public static final int STORAGE_HOST_TYPE_NFS = 1;
|
public static final int STORAGE_HOST_TYPE_NFS = 1;
|
||||||
|
public static enum StorageHostType {
|
||||||
private Long id;
|
STORAGE_HOST_TYPE_LOCAL, //0
|
||||||
|
STORAGE_HOST_TYPE_NFS //1
|
||||||
|
}
|
||||||
|
/* private Long id;
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private int hostType;
|
private int hostType;
|
||||||
private MHost mhost;
|
private MHostVO mhost;
|
||||||
private String exportRoot;
|
private String exportRoot;
|
||||||
private String userOnHost;
|
private String userOnHost;
|
||||||
private String userPassword;
|
private String userPassword;
|
||||||
@ -89,11 +91,11 @@ public class SHost implements Serializable {
|
|||||||
this.userPassword = userPassword;
|
this.userPassword = userPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MHost getMhost() {
|
public MHostVO getMhost() {
|
||||||
return mhost;
|
return mhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMhost(MHost mhost) {
|
public void setMhost(MHostVO mhost) {
|
||||||
this.mhost = mhost;
|
this.mhost = mhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,5 +113,5 @@ public class SHost implements Serializable {
|
|||||||
|
|
||||||
public void setMounts(Set<MHostMount> mounts) {
|
public void setMounts(Set<MHostMount> mounts) {
|
||||||
this.mounts = mounts;
|
this.mounts = mounts;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
152
awsapi/src/com/cloud/bridge/model/SHostVO.java
Normal file
152
awsapi/src/com/cloud/bridge/model/SHostVO.java
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
// 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.model;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="shost")
|
||||||
|
public class SHostVO implements SHost{
|
||||||
|
private static final long serialVersionUID = 213346565810468018L;
|
||||||
|
|
||||||
|
public static final int STORAGE_HOST_TYPE_LOCAL = 0;
|
||||||
|
public static final int STORAGE_HOST_TYPE_NFS = 1;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="Host")
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
@Column(name="HostType")
|
||||||
|
private int hostType;
|
||||||
|
|
||||||
|
@Column(name="MHostID")
|
||||||
|
private long mhostid;
|
||||||
|
|
||||||
|
@Column(name="ExportRoot")
|
||||||
|
private String exportRoot;
|
||||||
|
|
||||||
|
@Column(name="UserOnHost")
|
||||||
|
private String userOnHost;
|
||||||
|
|
||||||
|
@Column(name="UserPassword")
|
||||||
|
private String userPassword;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private MHostVO mhost;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Set<SBucket> buckets = new HashSet<SBucket>();
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Set<MHostMountVO> mounts = new HashSet<MHostMountVO>();
|
||||||
|
|
||||||
|
public SHostVO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHostType() {
|
||||||
|
return hostType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostType(int hostType) {
|
||||||
|
this.hostType = hostType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMhostid() {
|
||||||
|
return mhostid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMhostid(long mhostid) {
|
||||||
|
this.mhostid = mhostid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportRoot() {
|
||||||
|
return exportRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExportRoot(String exportRoot) {
|
||||||
|
this.exportRoot = exportRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserOnHost() {
|
||||||
|
return userOnHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserOnHost(String userOnHost) {
|
||||||
|
this.userOnHost = userOnHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserPassword() {
|
||||||
|
return userPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserPassword(String userPassword) {
|
||||||
|
this.userPassword = userPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MHostVO getMhost() {
|
||||||
|
return mhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMhost(MHostVO mhost) {
|
||||||
|
this.mhost = mhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<SBucket> getBuckets() {
|
||||||
|
return buckets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuckets(Set<SBucket> buckets) {
|
||||||
|
this.buckets = buckets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<MHostMountVO> getMounts() {
|
||||||
|
return mounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMounts(Set<MHostMountVO> mounts) {
|
||||||
|
this.mounts = mounts;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,41 +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.bridge.model.SMeta" table="meta" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
<property name="target">
|
|
||||||
<column name="Target" />
|
|
||||||
</property>
|
|
||||||
<property name="targetId">
|
|
||||||
<column name="TargetID" />
|
|
||||||
</property>
|
|
||||||
<property name="name">
|
|
||||||
<column name="Name" />
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<column name="Value" />
|
|
||||||
</property>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -18,18 +18,36 @@ package com.cloud.bridge.model;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class SMeta implements Serializable {
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="meta")
|
||||||
|
public class SMetaVO implements Serializable {
|
||||||
private static final long serialVersionUID = 7459503272337054283L;
|
private static final long serialVersionUID = 7459503272337054283L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="Target")
|
||||||
private String target;
|
private String target;
|
||||||
|
|
||||||
|
@Column(name="TargetID")
|
||||||
private long targetId;
|
private long targetId;
|
||||||
|
|
||||||
|
@Column(name="Name")
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
|
||||||
|
|
||||||
public SMeta() {
|
@Column(name="Value")
|
||||||
}
|
private String value;
|
||||||
|
|
||||||
|
public SMetaVO() {}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -76,11 +94,11 @@ public class SMeta implements Serializable {
|
|||||||
if(this == other)
|
if(this == other)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!(other instanceof SMeta))
|
if(!(other instanceof SMetaVO))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return getTarget().equals(((SMeta)other).getTarget()) && getTargetId() == ((SMeta)other).getTargetId()
|
return getTarget().equals(((SMetaVO)other).getTarget()) && getTargetId() == ((SMetaVO)other).getTargetId()
|
||||||
&& getName().equals(((SMeta)other).getName());
|
&& getName().equals(((SMetaVO)other).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1,59 +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.bridge.model.SObject" table="sobject" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="nameKey">
|
|
||||||
<column name="NameKey" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="ownerCanonicalId">
|
|
||||||
<column name="OwnerCanonicalId" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="nextSequence">
|
|
||||||
<column name="NextSequence" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="deletionMark">
|
|
||||||
<column name="DeletionMark" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="CreateTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<many-to-one name="bucket" column="SBucketID"
|
|
||||||
class="com.cloud.bridge.model.SBucket"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<set name="items" inverse="true" lazy="true" cascade="all-delete-orphan">
|
|
||||||
<key column="SObjectID" />
|
|
||||||
<one-to-many class="com.cloud.bridge.model.SObjectItem" />
|
|
||||||
</set>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -1,62 +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.bridge.model.SObjectItem" table="sobject_item" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
|
|
||||||
<property name="version">
|
|
||||||
<column name="Version" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="md5">
|
|
||||||
<column name="MD5" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="storedPath">
|
|
||||||
<column name="StoredPath" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="storedSize">
|
|
||||||
<column name="StoredSize" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="CreateTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="lastModifiedTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="LastModifiedTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<property name="lastAccessTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
|
|
||||||
<column name="LastAccessTime" />
|
|
||||||
</property>
|
|
||||||
|
|
||||||
<many-to-one name="theObject" column="SObjectID"
|
|
||||||
class="com.cloud.bridge.model.SObject"
|
|
||||||
cascade="none"
|
|
||||||
/>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -19,22 +19,56 @@ package com.cloud.bridge.model;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class SObjectItem implements Serializable {
|
import javax.persistence.Column;
|
||||||
private static final long serialVersionUID = -7351173256185687851L;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="sobject_item")
|
||||||
|
public class SObjectItemVO {
|
||||||
|
private static final long serialVersionUID = -7351173256185687851L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private SObject theObject;
|
@Column(name="SObjectID")
|
||||||
|
private long sObjectID;
|
||||||
|
|
||||||
|
@Column(name="Version")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@Column(name="MD5")
|
||||||
private String md5;
|
private String md5;
|
||||||
|
|
||||||
|
@Column(name="StoredPath")
|
||||||
private String storedPath;
|
private String storedPath;
|
||||||
|
|
||||||
|
@Column(name="StoredSize")
|
||||||
private long storedSize;
|
private long storedSize;
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name="LastModifiedTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date lastModifiedTime;
|
private Date lastModifiedTime;
|
||||||
|
|
||||||
|
@Column(name="LastAccessTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date lastAccessTime;
|
private Date lastAccessTime;
|
||||||
|
|
||||||
public SObjectItem() {
|
@Transient
|
||||||
|
private SObjectVO theObject;
|
||||||
|
public SObjectItemVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -45,14 +79,22 @@ public class SObjectItem implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SObject getTheObject() {
|
public SObjectVO getTheObject() {
|
||||||
return theObject;
|
return theObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTheObject(SObject theObject) {
|
public void setTheObject(SObjectVO theObject) {
|
||||||
this.theObject = theObject;
|
this.theObject = theObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getsObjectID() {
|
||||||
|
return sObjectID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setsObjectID(long sObjectID) {
|
||||||
|
this.sObjectID = sObjectID;
|
||||||
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
@ -114,22 +156,22 @@ public class SObjectItem implements Serializable {
|
|||||||
if(this == other)
|
if(this == other)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!(other instanceof SObjectItem))
|
if(!(other instanceof SObjectItemVO))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(version != null) {
|
if(version != null) {
|
||||||
if(!version.equals(((SObjectItem)other).getVersion()))
|
if(!version.equals(((SObjectItemVO)other).getVersion()))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if(((SObjectItem)other).getVersion() != null)
|
if(((SObjectItemVO)other).getVersion() != null)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(theObject.getId() != null) {
|
if(theObject.getId() != null) {
|
||||||
if(!theObject.getId().equals(((SObjectItem)other).getTheObject()))
|
if(!theObject.getId().equals(((SObjectItemVO)other).getTheObject()))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if(((SObjectItem)other).getTheObject() != null)
|
if(((SObjectItemVO)other).getTheObject() != null)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -16,30 +16,58 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.bridge.model;
|
package com.cloud.bridge.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SObject implements Serializable {
|
import javax.persistence.Column;
|
||||||
private static final long serialVersionUID = 8566744941395660486L;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="sobject")
|
||||||
|
public class SObjectVO {
|
||||||
|
//private static final long serialVersionUID = 8566744941395660486L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="SBucketID")
|
||||||
|
private long bucketID;
|
||||||
|
|
||||||
|
@Column(name="NameKey")
|
||||||
private String nameKey;
|
private String nameKey;
|
||||||
|
|
||||||
|
@Column(name="OwnerCanonicalID")
|
||||||
private String ownerCanonicalId;
|
private String ownerCanonicalId;
|
||||||
|
|
||||||
|
@Column(name="NextSequence")
|
||||||
private int nextSequence;
|
private int nextSequence;
|
||||||
private String deletionMark; // This must also a unique ID to give to the REST client
|
|
||||||
|
|
||||||
|
@Column(name="DeletionMark")
|
||||||
|
private String deletionMark; // This must also a unique ID to give to the REST client
|
||||||
|
|
||||||
|
@Column(name="CreateTime")
|
||||||
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
@Transient
|
||||||
private SBucket bucket;
|
private SBucket bucket;
|
||||||
|
|
||||||
private Set<SObjectItem> items = new HashSet<SObjectItem>();
|
@Transient
|
||||||
|
private Set<SObjectItemVO> items = new HashSet<SObjectItemVO>();
|
||||||
public SObject() {
|
|
||||||
|
public SObjectVO() {
|
||||||
deletionMark = null;
|
deletionMark = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +79,14 @@ public class SObject implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getBucketID() {
|
||||||
|
return bucketID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBucketID(long bucketID) {
|
||||||
|
this.bucketID = bucketID;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNameKey() {
|
public String getNameKey() {
|
||||||
return nameKey;
|
return nameKey;
|
||||||
}
|
}
|
||||||
@ -99,20 +135,20 @@ public class SObject implements Serializable {
|
|||||||
this.bucket = bucket;
|
this.bucket = bucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SObjectItem> getItems() {
|
public Set<SObjectItemVO> getItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(Set<SObjectItem> items) {
|
public void setItems(Set<SObjectItemVO> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteItem( long id ) {
|
public void deleteItem( long id ) {
|
||||||
Iterator<SObjectItem> it = getItems().iterator();
|
Iterator<SObjectItemVO> it = getItems().iterator();
|
||||||
|
|
||||||
while( it.hasNext())
|
while( it.hasNext())
|
||||||
{
|
{
|
||||||
SObjectItem oneItem = it.next();
|
SObjectItemVO oneItem = it.next();
|
||||||
if (id == oneItem.getId()) {
|
if (id == oneItem.getId()) {
|
||||||
boolean bRemoved = items.remove( oneItem );
|
boolean bRemoved = items.remove( oneItem );
|
||||||
System.out.println( "deleteItem from sobject: " + bRemoved );
|
System.out.println( "deleteItem from sobject: " + bRemoved );
|
||||||
@ -121,15 +157,15 @@ public class SObject implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SObjectItem getLatestVersion( boolean versioningOff ) {
|
public SObjectItemVO getLatestVersion( boolean versioningOff ) {
|
||||||
Iterator<SObjectItem> it = getItems().iterator();
|
Iterator<SObjectItemVO> it = getItems().iterator();
|
||||||
int maxVersion = 0;
|
int maxVersion = 0;
|
||||||
int curVersion = 0;
|
int curVersion = 0;
|
||||||
SObjectItem latestItem = null;
|
SObjectItemVO latestItem = null;
|
||||||
|
|
||||||
while( it.hasNext())
|
while( it.hasNext())
|
||||||
{
|
{
|
||||||
SObjectItem item = it.next();
|
SObjectItemVO item = it.next();
|
||||||
|
|
||||||
// If versioning is off then return the item with the null version string (if exists)
|
// If versioning is off then return the item with the null version string (if exists)
|
||||||
// For example, the bucket could have allowed versioning and then it was suspended
|
// For example, the bucket could have allowed versioning and then it was suspended
|
||||||
@ -160,12 +196,12 @@ public class SObject implements Serializable {
|
|||||||
* @param wantVersion
|
* @param wantVersion
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public SObjectItem getVersion( String wantVersion )
|
public SObjectItemVO getVersion( String wantVersion )
|
||||||
{
|
{
|
||||||
Iterator<SObjectItem> it = getItems().iterator();
|
Iterator<SObjectItemVO> it = getItems().iterator();
|
||||||
while( it.hasNext())
|
while( it.hasNext())
|
||||||
{
|
{
|
||||||
SObjectItem item = it.next();
|
SObjectItemVO item = it.next();
|
||||||
String curVersion = item.getVersion();
|
String curVersion = item.getVersion();
|
||||||
if (null != curVersion && wantVersion.equalsIgnoreCase( curVersion )) return item;
|
if (null != curVersion && wantVersion.equalsIgnoreCase( curVersion )) return item;
|
||||||
}
|
}
|
||||||
@ -177,17 +213,17 @@ public class SObject implements Serializable {
|
|||||||
if(this == other)
|
if(this == other)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(!(other instanceof SObject))
|
if(!(other instanceof SObjectVO))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!getNameKey().equals(((SObject)other).getNameKey()))
|
if(!getNameKey().equals(((SObjectVO)other).getNameKey()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(getBucket() != null) {
|
if(getBucket() != null) {
|
||||||
if(!getBucket().equals(((SObject)other).getBucket()))
|
if(!getBucket().equals(((SObjectVO)other).getBucket()))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if(((SObject)other).getBucket() != null)
|
if(((SObjectVO)other).getBucket() != null)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,38 +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.bridge.model.UserCredentials" table="usercredentials" lazy="true">
|
|
||||||
<id name="id" type="long" column="ID" >
|
|
||||||
<generator class="native" />
|
|
||||||
</id>
|
|
||||||
<property name="accessKey">
|
|
||||||
<column name="AccessKey" />
|
|
||||||
</property>
|
|
||||||
<property name="secretKey">
|
|
||||||
<column name="SecretKey" />
|
|
||||||
</property>
|
|
||||||
<property name="certUniqueId">
|
|
||||||
<column name="CertUniqueId" />
|
|
||||||
</property>
|
|
||||||
</class>
|
|
||||||
</hibernate-mapping>
|
|
||||||
|
|
||||||
@ -18,17 +18,39 @@ package com.cloud.bridge.model;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class UserCredentials implements Serializable {
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="usercredentials")
|
||||||
|
public class UserCredentialsVO{
|
||||||
private static final long serialVersionUID = 7459503272337054299L;
|
private static final long serialVersionUID = 7459503272337054299L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name="AccessKey")
|
||||||
private String accessKey;
|
private String accessKey;
|
||||||
|
|
||||||
|
@Column(name="SecretKey")
|
||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|
||||||
|
@Column(name="CertUniqueId")
|
||||||
private String certUniqueId;
|
private String certUniqueId;
|
||||||
|
|
||||||
public UserCredentials() {
|
public UserCredentialsVO() { }
|
||||||
}
|
|
||||||
|
|
||||||
|
public UserCredentialsVO(String accessKey, String secretKey) {
|
||||||
|
this.accessKey = accessKey;
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -65,14 +87,14 @@ public class UserCredentials implements Serializable {
|
|||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) return true;
|
if (this == other) return true;
|
||||||
|
|
||||||
if (!(other instanceof UserCredentials)) return false;
|
if (!(other instanceof UserCredentialsVO)) return false;
|
||||||
|
|
||||||
// The cert id can be null. The cert is unused in the REST API.
|
// The cert id can be null. The cert is unused in the REST API.
|
||||||
if ( getAccessKey().equals(((UserCredentials)other).getAccessKey()) &&
|
if ( getAccessKey().equals(((UserCredentialsVO)other).getAccessKey()) &&
|
||||||
getSecretKey().equals(((UserCredentials)other).getSecretKey()))
|
getSecretKey().equals(((UserCredentialsVO)other).getSecretKey()))
|
||||||
{
|
{
|
||||||
String thisCertId = getCertUniqueId();
|
String thisCertId = getCertUniqueId();
|
||||||
String otherCertId = ((UserCredentials)other).getCertUniqueId();
|
String otherCertId = ((UserCredentialsVO)other).getCertUniqueId();
|
||||||
|
|
||||||
if (null == thisCertId && null == otherCertId) return true;
|
if (null == thisCertId && null == otherCertId) return true;
|
||||||
|
|
||||||
@ -1,118 +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.persist;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import com.cloud.bridge.util.QueryHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provide methods for getting, saving, deleting or updating state per session or, in a given session, returnin a List in
|
|
||||||
* response to queryEntities for a particular instantation of the EntityDao generic class, as defined here.
|
|
||||||
* Any instantation of EntityDao passes in the class for which it is instantiating. For example a new instance of SBucketDao
|
|
||||||
* passes in com.cloud.bridge.model.SBucket as its clazz.
|
|
||||||
* Instantiators, providing an Entity definition, are the classes
|
|
||||||
* MHostDao,
|
|
||||||
* MHostMountDao,
|
|
||||||
* SAclDao,
|
|
||||||
* SBucketDao,
|
|
||||||
* SHostDao,
|
|
||||||
* SMetaDao,
|
|
||||||
* SObjectDao,
|
|
||||||
* SObjectItemDao,
|
|
||||||
* CloudStackSvcOfferingDao
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EntityDao<T> {
|
|
||||||
private Class<?> clazz;
|
|
||||||
|
|
||||||
private boolean isCloudStackSession = false;
|
|
||||||
|
|
||||||
// Constructor to implement CloudStackSvcOffering: see class CloudStackSvcOfferingDao
|
|
||||||
public EntityDao(Class<?> clazz){
|
|
||||||
this(clazz, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityDao(Class<?> clazz, boolean isCloudStackSession) {
|
|
||||||
this.clazz = clazz;
|
|
||||||
this.isCloudStackSession = isCloudStackSession;
|
|
||||||
// Note : beginTransaction can be called multiple times
|
|
||||||
// "If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the
|
|
||||||
// context of the existing underlying transaction." from the Hibernate spec
|
|
||||||
PersistContext.beginTransaction(isCloudStackSession);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public T get(Serializable id) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
return (T)session.get(clazz, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T save(T entity) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
session.saveOrUpdate(entity);
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T update(T entity) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
session.saveOrUpdate(entity);
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(T entity) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
session.delete(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T queryEntity(String hql, Object[] params) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
Query query = session.createQuery(hql);
|
|
||||||
query.setMaxResults(1);
|
|
||||||
QueryHelper.bindParameters(query, params);
|
|
||||||
return (T)query.uniqueResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> queryEntities(String hql, Object[] params) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
Query query = session.createQuery(hql);
|
|
||||||
QueryHelper.bindParameters(query, params);
|
|
||||||
|
|
||||||
return (List<T>)query.list();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> queryEntities(String hql, int offset, int limit, Object[] params) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
Query query = session.createQuery(hql);
|
|
||||||
QueryHelper.bindParameters(query, params);
|
|
||||||
query.setFirstResult(offset);
|
|
||||||
query.setMaxResults(limit);
|
|
||||||
return (List<T>)query.list();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int executeUpdate(String hql, Object[] params) {
|
|
||||||
Session session = PersistContext.getSession(isCloudStackSession);
|
|
||||||
Query query = session.createQuery(hql);
|
|
||||||
QueryHelper.bindParameters(query, params);
|
|
||||||
|
|
||||||
return query.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,102 +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.persist;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.usertype.UserType;
|
|
||||||
|
|
||||||
import com.cloud.bridge.util.DateHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GMTDateTimeUserType implements a Hibernate user type, it deals with GMT date/time conversion
|
|
||||||
* between Java Date/Calendar and MySQL DATE types
|
|
||||||
*/
|
|
||||||
public class GMTDateTimeUserType implements UserType {
|
|
||||||
|
|
||||||
private static final int[] SQL_TYPES = { Types.VARBINARY };
|
|
||||||
|
|
||||||
public Class<?> returnedClass() { return Date.class; }
|
|
||||||
|
|
||||||
public boolean equals(Object x, Object y) {
|
|
||||||
if (x == y)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (x == null || y == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return x.equals(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode(Object x) {
|
|
||||||
if(x != null)
|
|
||||||
return x.hashCode();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deepCopy(Object value) {
|
|
||||||
if(value != null)
|
|
||||||
return ((Date)value).clone();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMutable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
|
|
||||||
String dateString = resultSet.getString(names[0]);
|
|
||||||
if(dateString != null)
|
|
||||||
return DateHelper.parseDateString(DateHelper.GMT_TIMEZONE, dateString);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void nullSafeSet(PreparedStatement statement, Object value, int index)
|
|
||||||
throws HibernateException, SQLException {
|
|
||||||
if (value == null) {
|
|
||||||
statement.setNull(index, Types.TIMESTAMP);
|
|
||||||
} else {
|
|
||||||
Date dt = (Date)value;
|
|
||||||
statement.setString(index, DateHelper.getDateDisplayString(DateHelper.GMT_TIMEZONE, dt));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object assemble(Serializable cached, Object owner) throws HibernateException {
|
|
||||||
return DateHelper.parseDateString(DateHelper.GMT_TIMEZONE, (String)cached);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Serializable disassemble(Object value) throws HibernateException {
|
|
||||||
return DateHelper.getDateDisplayString(DateHelper.GMT_TIMEZONE, (Date)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object replace(Object original, Object target, Object owner) throws HibernateException {
|
|
||||||
return ((Date)original).clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] sqlTypes() {
|
|
||||||
return SQL_TYPES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,359 +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.persist;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
|
|
||||||
import com.cloud.bridge.util.CloudSessionFactory;
|
|
||||||
import com.cloud.bridge.util.CloudStackSessionFactory;
|
|
||||||
import com.cloud.bridge.util.OrderedPair;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* We use Per-thread based hibernate session and transaction pattern. Transaction will be
|
|
||||||
* started implicitly by EntityDao instances and be committed implicitly in the end of
|
|
||||||
* request-process cycle. All requests are guarded by a dynamic proxy.
|
|
||||||
*
|
|
||||||
* We will try to keep transaction management as implicit as we can, so that
|
|
||||||
* most of service layer implementation contains business-logic only, all business logic are
|
|
||||||
* built on top of domain object model, and all persistent layer handling lie within persist layer
|
|
||||||
* in Dao classes.
|
|
||||||
*
|
|
||||||
* PersistContext class also provides per-thread based registry service and global named-lock service
|
|
||||||
*/
|
|
||||||
public class PersistContext {
|
|
||||||
protected final static Logger logger = Logger.getLogger(PersistContext.class);
|
|
||||||
|
|
||||||
private static final CloudSessionFactory sessionFactory;
|
|
||||||
|
|
||||||
private static final ThreadLocal<Session> threadSession = new ThreadLocal<Session>();
|
|
||||||
private static final ThreadLocal<Transaction> threadTransaction = new ThreadLocal<Transaction>();
|
|
||||||
private static final ThreadLocal<Map<String, Object>> threadStore = new ThreadLocal<Map<String, Object>>();
|
|
||||||
|
|
||||||
private static final CloudStackSessionFactory cloudStackSessionFactory;
|
|
||||||
private static final ThreadLocal<Session> threadCloudStackSession = new ThreadLocal<Session>();
|
|
||||||
private static final ThreadLocal<Transaction> threadCloudStackTransaction = new ThreadLocal<Transaction>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
sessionFactory = CloudSessionFactory.getInstance();
|
|
||||||
cloudStackSessionFactory = CloudStackSessionFactory.getInstance();
|
|
||||||
} catch(HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
throw new PersistException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Session getSession(boolean cloudStackSession) {
|
|
||||||
Session s = null;
|
|
||||||
try {
|
|
||||||
if(cloudStackSession){
|
|
||||||
s = threadCloudStackSession.get();
|
|
||||||
if(s == null) {
|
|
||||||
s = cloudStackSessionFactory.openSession();
|
|
||||||
threadCloudStackSession.set(s);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
s = threadSession.get();
|
|
||||||
if(s == null) {
|
|
||||||
s = sessionFactory.openSession();
|
|
||||||
threadSession.set(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
throw new PersistException(e);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Session getSession() {
|
|
||||||
return getSession(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeSession() {
|
|
||||||
closeSession(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeSession(boolean cloudStackSession) {
|
|
||||||
try {
|
|
||||||
if(cloudStackSession){
|
|
||||||
Session s = (Session) threadCloudStackSession.get();
|
|
||||||
threadCloudStackSession.set(null);
|
|
||||||
if (s != null && s.isOpen())
|
|
||||||
s.close();
|
|
||||||
}else{
|
|
||||||
Session s = (Session) threadSession.get();
|
|
||||||
threadSession.set(null);
|
|
||||||
|
|
||||||
if (s != null && s.isOpen())
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}catch(HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
throw new PersistException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void beginTransaction(boolean cloudStackTxn) {
|
|
||||||
Transaction tx = null;
|
|
||||||
try {
|
|
||||||
if(cloudStackTxn){
|
|
||||||
tx = threadCloudStackTransaction.get();
|
|
||||||
}else{
|
|
||||||
tx = threadTransaction.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx == null) {
|
|
||||||
tx = getSession(cloudStackTxn).beginTransaction();
|
|
||||||
if(cloudStackTxn){
|
|
||||||
threadCloudStackTransaction.set(tx);
|
|
||||||
}else{
|
|
||||||
threadTransaction.set(tx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
throw new PersistException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void beginTransaction() {
|
|
||||||
beginTransaction(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commitTransaction(boolean cloudStackTxn) {
|
|
||||||
Transaction tx = null;
|
|
||||||
|
|
||||||
if(cloudStackTxn){
|
|
||||||
tx = threadCloudStackTransaction.get();
|
|
||||||
}else{
|
|
||||||
tx = threadTransaction.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ){
|
|
||||||
tx.commit();
|
|
||||||
}
|
|
||||||
if(cloudStackTxn){
|
|
||||||
threadCloudStackTransaction.set(null);
|
|
||||||
}else{
|
|
||||||
threadTransaction.set(null);
|
|
||||||
}
|
|
||||||
} catch (HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
|
|
||||||
rollbackTransaction(cloudStackTxn);
|
|
||||||
throw new PersistException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void commitTransaction() {
|
|
||||||
commitTransaction(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollbackTransaction(boolean cloudStackTxn) {
|
|
||||||
Transaction tx = null;
|
|
||||||
|
|
||||||
if(cloudStackTxn){
|
|
||||||
tx = (Transaction)threadCloudStackTransaction.get();
|
|
||||||
threadCloudStackTransaction.set(null);
|
|
||||||
}else{
|
|
||||||
tx = (Transaction)threadTransaction.get();
|
|
||||||
threadTransaction.set(null);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
|
|
||||||
tx.rollback();
|
|
||||||
}
|
|
||||||
} catch (HibernateException e) {
|
|
||||||
logger.error("Exception " + e.getMessage(), e);
|
|
||||||
throw new PersistException(e);
|
|
||||||
} finally {
|
|
||||||
closeSession(cloudStackTxn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rollbackTransaction() {
|
|
||||||
rollbackTransaction(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void flush() {
|
|
||||||
commitTransaction();
|
|
||||||
beginTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* acquireNamedLock/releaseNamedLock must be called in pairs and within the same thread
|
|
||||||
* they can not be called recursively neither
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param timeoutSeconds
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean acquireNamedLock(String name, int timeoutSeconds) {
|
|
||||||
Connection jdbcConnection = getJDBCConnection(name, true);
|
|
||||||
if(jdbcConnection == null) {
|
|
||||||
logger.warn("Unable to acquire named lock connection for named lock: " + name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try {
|
|
||||||
pstmt = jdbcConnection.prepareStatement("SELECT COALESCE(GET_LOCK(?, ?),0)");
|
|
||||||
|
|
||||||
pstmt.setString(1, name);
|
|
||||||
pstmt.setInt(2, timeoutSeconds);
|
|
||||||
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs != null && rs.first()) {
|
|
||||||
if(rs.getInt(1) > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
logger.error("GET_LOCK() timed out on lock : " + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("GET_LOCK() throws exception ", e);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("GET_LOCK() throws exception ", e);
|
|
||||||
} finally {
|
|
||||||
if (pstmt != null) {
|
|
||||||
try {
|
|
||||||
pstmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseJDBCConnection(name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean releaseNamedLock(String name) {
|
|
||||||
Connection jdbcConnection = getJDBCConnection(name, false);
|
|
||||||
if(jdbcConnection == null) {
|
|
||||||
logger.error("Unable to acquire DB connection for global lock system");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try {
|
|
||||||
pstmt = jdbcConnection.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");
|
|
||||||
pstmt.setString(1, name);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if(rs != null && rs.first())
|
|
||||||
return rs.getInt(1) > 0;
|
|
||||||
logger.error("RELEASE_LOCK() returns unexpected result : " + rs.getInt(1));
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("RELEASE_LOCK() throws exception ", e);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("RELEASE_LOCK() throws exception ", e);
|
|
||||||
} finally {
|
|
||||||
releaseJDBCConnection(name);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private static Connection getJDBCConnection(String name, boolean allocNew) {
|
|
||||||
String registryKey = "JDBC-Connection." + name;
|
|
||||||
OrderedPair<Session, Connection> info = (OrderedPair<Session, Connection>)getThreadStoreObject(registryKey);
|
|
||||||
if(info == null && allocNew) {
|
|
||||||
Session session = sessionFactory.openSession();
|
|
||||||
Connection connection = session.connection();
|
|
||||||
if(connection == null) {
|
|
||||||
session.close();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection.setAutoCommit(true);
|
|
||||||
} catch(SQLException e) {
|
|
||||||
logger.warn("Unexpected exception " + e.getMessage(), e);
|
|
||||||
try {
|
|
||||||
connection.close();
|
|
||||||
session.close();
|
|
||||||
} catch(Throwable ex) {
|
|
||||||
logger.warn("Unexpected exception " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerThreadStoreObject(registryKey, new OrderedPair<Session, Connection>(session, connection));
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(info != null)
|
|
||||||
return info.getSecond();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void releaseJDBCConnection(String name) {
|
|
||||||
String registryKey = "JDBC-Connection." + name;
|
|
||||||
OrderedPair<Session, Connection> info = (OrderedPair<Session, Connection>)unregisterThreadStoreObject(registryKey);
|
|
||||||
if(info != null) {
|
|
||||||
try {
|
|
||||||
info.getSecond().close();
|
|
||||||
info.getFirst().close();
|
|
||||||
} catch(Throwable e) {
|
|
||||||
logger.warn("Unexpected exception " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerThreadStoreObject(String name, Object object) {
|
|
||||||
Map<String, Object> store = getThreadStore();
|
|
||||||
store.put(name, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getThreadStoreObject(String name) {
|
|
||||||
Map<String, Object> store = getThreadStore();
|
|
||||||
return store.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object unregisterThreadStoreObject(String name) {
|
|
||||||
Map<String, Object> store = getThreadStore();
|
|
||||||
if(store.containsKey(name)) {
|
|
||||||
Object value = store.get(name);
|
|
||||||
store.remove(name);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, Object> getThreadStore() {
|
|
||||||
Map<String, Object> store = threadStore.get();
|
|
||||||
if(store == null) {
|
|
||||||
store = new HashMap<String, Object>();
|
|
||||||
threadStore.set(store);
|
|
||||||
}
|
|
||||||
return store;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,36 +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.persist;
|
|
||||||
|
|
||||||
public class PersistException extends RuntimeException {
|
|
||||||
private static final long serialVersionUID = -7137918292537610367L;
|
|
||||||
|
|
||||||
public PersistException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistException(Throwable e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistException(String message, Throwable e) {
|
|
||||||
super(message, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,159 +1,12 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.io.File;
|
import com.cloud.bridge.model.BucketPolicyVO;
|
||||||
import java.io.FileInputStream;
|
import com.cloud.utils.db.GenericDao;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
public interface BucketPolicyDao extends GenericDao<BucketPolicyVO, Long> {
|
||||||
|
|
||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
void deletePolicy(String bucketName);
|
||||||
|
|
||||||
public class BucketPolicyDao {
|
BucketPolicyVO getByName(String bucketName);
|
||||||
public static final Logger logger = Logger.getLogger(BucketPolicyDao.class);
|
|
||||||
|
|
||||||
private Connection conn = null;
|
|
||||||
private String dbName = null;
|
|
||||||
private String dbUser = null;
|
|
||||||
private String dbPassword = null;
|
|
||||||
private String dbHost = null;
|
|
||||||
private String dbPort = null;
|
|
||||||
|
|
||||||
public BucketPolicyDao()
|
|
||||||
{
|
|
||||||
File propertiesFile = ConfigurationHelper.findConfigurationFile("db.properties");
|
|
||||||
Properties EC2Prop = null;
|
|
||||||
|
|
||||||
if (null != propertiesFile) {
|
|
||||||
EC2Prop = new Properties();
|
|
||||||
try {
|
|
||||||
EC2Prop.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);
|
|
||||||
}
|
|
||||||
dbHost = EC2Prop.getProperty( "db.cloud.host" );
|
|
||||||
dbName = EC2Prop.getProperty( "db.awsapi.name" );
|
|
||||||
dbUser = EC2Prop.getProperty( "db.cloud.username" );
|
|
||||||
dbPassword = EC2Prop.getProperty( "db.cloud.password" );
|
|
||||||
dbPort = EC2Prop.getProperty( "db.cloud.port" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPolicy( String bucketName, String owner, String policy )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "INSERT INTO bucket_policies (BucketName, OwnerCanonicalID, Policy) VALUES (?,?,?)" );
|
|
||||||
statement.setString( 1, bucketName );
|
|
||||||
statement.setString( 2, owner );
|
|
||||||
statement.setString( 3, policy );
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Since a bucket policy can exist before its bucket we also need to keep the policy's owner
|
|
||||||
* so we can restrict who modifies it (because of the "s3:CreateBucket" action).
|
|
||||||
*/
|
|
||||||
public String getPolicyOwner( String bucketName )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String owner = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT OwnerCanonicalID FROM bucket_policies WHERE BucketName=?" );
|
|
||||||
statement.setString( 1, bucketName );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) owner = rs.getString( "OwnerCanonicalID" );
|
|
||||||
statement.close();
|
|
||||||
return owner;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPolicy( String bucketName )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String policy = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT Policy FROM bucket_policies WHERE BucketName=?" );
|
|
||||||
statement.setString( 1, bucketName );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) policy = rs.getString( "Policy" );
|
|
||||||
statement.close();
|
|
||||||
return policy;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy( String bucketName )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "DELETE FROM bucket_policies WHERE BucketName=?" );
|
|
||||||
statement.setString( 1, bucketName );
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openConnection()
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
if (null == conn) {
|
|
||||||
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
|
|
||||||
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeConnection() throws SQLException {
|
|
||||||
if (null != conn) conn.close();
|
|
||||||
conn = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,72 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import com.cloud.bridge.model.BucketPolicyVO;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={BucketPolicyDao.class})
|
||||||
|
public class BucketPolicyDaoImpl extends GenericDaoBase<BucketPolicyVO, Long> implements BucketPolicyDao{
|
||||||
|
public static final Logger logger = Logger.getLogger(BucketPolicyDaoImpl.class);
|
||||||
|
public BucketPolicyDaoImpl(){ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since a bucket policy can exist before its bucket we also need to keep the policy's owner
|
||||||
|
* so we can restrict who modifies it (because of the "s3:CreateBucket" action).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BucketPolicyVO getByName( String bucketName ) {
|
||||||
|
SearchBuilder <BucketPolicyVO> searchByBucket = createSearchBuilder();
|
||||||
|
searchByBucket.and("BucketName", searchByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<BucketPolicyVO> sc = searchByBucket.create();
|
||||||
|
sc.setParameters("BucketName", bucketName);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deletePolicy( String bucketName ) {
|
||||||
|
SearchBuilder <BucketPolicyVO> deleteByBucket = createSearchBuilder();
|
||||||
|
deleteByBucket.and("BucketName", deleteByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<BucketPolicyVO> sc = deleteByBucket.create();
|
||||||
|
sc.setParameters("BucketName", bucketName);
|
||||||
|
remove(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,35 +1,11 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import com.cloud.bridge.model.CloudStackAccountVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
public interface CloudStackAccountDao extends
|
||||||
import com.cloud.stack.models.CloudStackAccount;
|
GenericDao<CloudStackAccountVO, String> {
|
||||||
|
String getDefaultZoneId(String accountId);
|
||||||
|
|
||||||
|
|
||||||
public class CloudStackAccountDao extends EntityDao<CloudStackAccount> {
|
|
||||||
public static final Logger logger = Logger.getLogger(CloudStackAccountDao.class);
|
|
||||||
|
|
||||||
public CloudStackAccountDao() {
|
|
||||||
super(CloudStackAccount.class, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CloudStackAccount getdefaultZoneId( String id ) {
|
|
||||||
return queryEntity("from CloudStackAccount where id=?", new Object[] {id});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,39 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.CloudStackAccountVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={CloudStackAccountDao.class})
|
||||||
|
public class CloudStackAccountDaoImpl extends GenericDaoBase<CloudStackAccountVO, String> implements CloudStackAccountDao {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultZoneId(String accountId) {
|
||||||
|
|
||||||
|
SearchBuilder<CloudStackAccountVO> SearchByUUID = createSearchBuilder();
|
||||||
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchByUUID.and("uuid", SearchByUUID.entity().getUuid(),
|
||||||
|
SearchCriteria.Op.EQ);
|
||||||
|
SearchByUUID.done();
|
||||||
|
SearchCriteria<CloudStackAccountVO> sc = SearchByUUID.create();
|
||||||
|
sc.setParameters("uuid", accountId);
|
||||||
|
CloudStackAccountVO account = findOneBy(sc);
|
||||||
|
if (null != account)
|
||||||
|
if(null != account.getDefaultZoneId())
|
||||||
|
return Long.toString(account.getDefaultZoneId());
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
txn.commit();
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,42 +1,9 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import com.cloud.bridge.model.CloudStackConfigurationVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
|
||||||
import com.cloud.stack.models.CloudStackConfiguration;
|
|
||||||
|
|
||||||
|
|
||||||
public class CloudStackConfigurationDao extends EntityDao<CloudStackConfiguration> {
|
|
||||||
public static final Logger logger = Logger.getLogger(CloudStackConfigurationDao.class);
|
|
||||||
|
|
||||||
public CloudStackConfigurationDao() {
|
|
||||||
super(CloudStackConfiguration.class, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getConfigValue( String configName ){
|
|
||||||
CloudStackConfiguration config = queryEntity("from CloudStackConfiguration where name=?", new Object[] {configName});
|
|
||||||
if(config != null){
|
|
||||||
return config.getValue();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface CloudStackConfigurationDao extends GenericDao<CloudStackConfigurationVO, String> {
|
||||||
|
|
||||||
|
public String getConfigValue(String name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.CloudStackConfigurationVO;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
|
||||||
|
@Local(value={CloudStackConfigurationDao.class})
|
||||||
|
public class CloudStackConfigurationDaoImpl extends GenericDaoBase<CloudStackConfigurationVO, String> implements CloudStackConfigurationDao {
|
||||||
|
private static final Logger s_logger = Logger.getLogger(CloudStackConfigurationDaoImpl.class);
|
||||||
|
|
||||||
|
final SearchBuilder<CloudStackConfigurationVO> NameSearch= createSearchBuilder();
|
||||||
|
|
||||||
|
public CloudStackConfigurationDaoImpl() { }
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DB
|
||||||
|
public String getConfigValue(String name) {
|
||||||
|
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.currentTxn();
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<CloudStackConfigurationVO> sc = NameSearch.create();
|
||||||
|
sc.setParameters("name", name);
|
||||||
|
return findOneBy(sc).getValue();
|
||||||
|
}finally {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,42 +1,13 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import com.cloud.bridge.model.CloudStackServiceOfferingVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
public interface CloudStackSvcOfferingDao extends GenericDao<CloudStackServiceOfferingVO, String>{
|
||||||
import com.cloud.stack.models.CloudStackConfiguration;
|
|
||||||
import com.cloud.stack.models.CloudStackServiceOffering;
|
|
||||||
|
|
||||||
|
public CloudStackServiceOfferingVO getSvcOfferingByName(String name);
|
||||||
|
|
||||||
public class CloudStackSvcOfferingDao extends EntityDao<CloudStackServiceOffering> {
|
public CloudStackServiceOfferingVO getSvcOfferingById(String id);
|
||||||
public static final Logger logger = Logger.getLogger(CloudStackSvcOfferingDao.class);
|
|
||||||
|
|
||||||
public CloudStackSvcOfferingDao() {
|
|
||||||
super(CloudStackServiceOffering.class, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CloudStackServiceOffering getSvcOfferingByName( String name ){
|
|
||||||
return queryEntity("from CloudStackServiceOffering where name=?", new Object[] {name});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CloudStackServiceOffering getSvcOfferingById( String id ){
|
|
||||||
return queryEntity("from CloudStackServiceOffering where id=?", new Object[] {id});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,75 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.CloudStackServiceOfferingVO;
|
||||||
|
import com.cloud.bridge.model.SHostVO;
|
||||||
|
import com.cloud.stack.models.CloudStackConfiguration;
|
||||||
|
import com.cloud.stack.models.CloudStackServiceOffering;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={CloudStackSvcOfferingDao.class})
|
||||||
|
public class CloudStackSvcOfferingDaoImpl extends GenericDaoBase<CloudStackServiceOfferingVO, String> implements CloudStackSvcOfferingDao {
|
||||||
|
public static final Logger logger = Logger.getLogger(CloudStackSvcOfferingDaoImpl.class);
|
||||||
|
|
||||||
|
public CloudStackSvcOfferingDaoImpl() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CloudStackServiceOfferingVO getSvcOfferingByName( String name ){
|
||||||
|
SearchBuilder <CloudStackServiceOfferingVO> searchByName = createSearchBuilder();
|
||||||
|
searchByName.and("name", searchByName.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
|
searchByName.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<CloudStackServiceOfferingVO> sc = searchByName.create();
|
||||||
|
sc.setParameters("name", name);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public CloudStackServiceOfferingVO getSvcOfferingById( String id ){
|
||||||
|
SearchBuilder <CloudStackServiceOfferingVO> searchByID = createSearchBuilder();
|
||||||
|
searchByID.and("id", searchByID.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
|
searchByID.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<CloudStackServiceOfferingVO> sc = searchByID.create();
|
||||||
|
sc.setParameters("id", id);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,30 +1,12 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import com.cloud.bridge.model.MHost;
|
import com.cloud.bridge.model.MHostVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface MHostDao extends GenericDao<MHostVO, Long> {
|
||||||
|
|
||||||
|
MHostVO getByHostKey(String hostKey);
|
||||||
|
|
||||||
|
public void updateHeartBeat(MHostVO mhost);
|
||||||
|
|
||||||
public class MHostDao extends EntityDao<MHost> {
|
|
||||||
public MHostDao() {
|
|
||||||
super(MHost.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MHost getByHostKey(String hostKey) {
|
|
||||||
return queryEntity("from MHost where hostKey=?", new Object[] {hostKey});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
61
awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java
Normal file
61
awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MHostVO;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={MHostDao.class})
|
||||||
|
public class MHostDaoImpl extends GenericDaoBase<MHostVO, Long> implements MHostDao{
|
||||||
|
final SearchBuilder<MHostVO> NameSearch= createSearchBuilder();
|
||||||
|
|
||||||
|
public MHostDaoImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@DB
|
||||||
|
@Override
|
||||||
|
public MHostVO getByHostKey(String hostKey) {
|
||||||
|
NameSearch.and("MHostKey", NameSearch.entity().getHostKey(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MHostVO> sc = NameSearch.create();
|
||||||
|
sc.setParameters("MHostKey", hostKey);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateHeartBeat(MHostVO mhost) {
|
||||||
|
Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
update(mhost.getId(), mhost);
|
||||||
|
txn.commit();
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,30 +1,11 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import com.cloud.bridge.model.MHostMount;
|
import com.cloud.bridge.model.MHostMountVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface MHostMountDao extends GenericDao<MHostMountVO, Long> {
|
||||||
|
|
||||||
|
MHostMountVO getHostMount(long mHostId, long sHostId);
|
||||||
|
|
||||||
|
|
||||||
public class MHostMountDao extends EntityDao<MHostMount> {
|
|
||||||
public MHostMountDao() {
|
|
||||||
super(MHostMount.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MHostMount getHostMount(long mHostId, long sHostId) {
|
|
||||||
return queryEntity("from MHostMount where mhost=? and shost=?", new Object[] { mHostId, sHostId } );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MHostMountVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={MHostMountDao.class})
|
||||||
|
public class MHostMountDaoImpl extends GenericDaoBase<MHostMountVO, Long> implements MHostMountDao {
|
||||||
|
final SearchBuilder<MHostMountVO> SearchByMHostID = createSearchBuilder();
|
||||||
|
public MHostMountDaoImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MHostMountVO getHostMount(long mHostId, long sHostId) {
|
||||||
|
SearchByMHostID.and("MHostID", SearchByMHostID.entity().getmHostID(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByMHostID.and("SHostID", SearchByMHostID.entity().getsHostID(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MHostMountVO> sc = SearchByMHostID.create();
|
||||||
|
sc.setParameters("MHostID", mHostId);
|
||||||
|
sc.setParameters("SHostID", sHostId);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultiPartPartsVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface MultiPartPartsDao extends GenericDao<MultiPartPartsVO, Long> {
|
||||||
|
|
||||||
|
List<MultiPartPartsVO> getParts(int uploadId, int maxParts, int startAt);
|
||||||
|
|
||||||
|
int getnumParts(int uploadId, int endMarker);
|
||||||
|
|
||||||
|
MultiPartPartsVO findByUploadID(int uploadId, int partNumber);
|
||||||
|
|
||||||
|
void updateParts(MultiPartPartsVO partVO, int uploadId, int partNumber);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultiPartPartsVO;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={MultiPartPartsDao.class})
|
||||||
|
public class MultiPartPartsDaoImpl extends GenericDaoBase<MultiPartPartsVO, Long> implements MultiPartPartsDao {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MultiPartPartsVO> getParts(int uploadId, int maxParts, int startAt ) {
|
||||||
|
|
||||||
|
SearchBuilder<MultiPartPartsVO> ByUploadID = createSearchBuilder();
|
||||||
|
ByUploadID.and("UploadID", ByUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
|
||||||
|
ByUploadID.and("partNumber", ByUploadID.entity().getPartNumber(), SearchCriteria.Op.GT);
|
||||||
|
ByUploadID.and("partNumber", ByUploadID.entity().getPartNumber(), SearchCriteria.Op.LT);
|
||||||
|
Filter filter = new Filter(MultiPartPartsVO.class, "partNumber", Boolean.TRUE, null, null);
|
||||||
|
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultiPartPartsVO> sc = ByUploadID.create();
|
||||||
|
sc.setParameters("UploadID", new Long(uploadId));
|
||||||
|
sc.setParameters("partNumber", startAt);
|
||||||
|
sc.setParameters("partNumber", maxParts);
|
||||||
|
return listBy(sc, filter);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getnumParts( int uploadId, int endMarker ) {
|
||||||
|
SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
|
||||||
|
byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
|
||||||
|
byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.GT);
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
|
||||||
|
sc.setParameters("UploadID", new Long(uploadId));
|
||||||
|
sc.setParameters("partNumber", endMarker);
|
||||||
|
return listBy(sc).size();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultiPartPartsVO findByUploadID(int uploadId, int partNumber) {
|
||||||
|
|
||||||
|
SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
|
||||||
|
byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
|
||||||
|
byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
|
||||||
|
sc.setParameters("UploadID", new Long(uploadId));
|
||||||
|
sc.setParameters("partNumber", partNumber);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateParts(MultiPartPartsVO partVO, int uploadId, int partNumber) {
|
||||||
|
|
||||||
|
SearchBuilder<MultiPartPartsVO> byUploadID = createSearchBuilder();
|
||||||
|
byUploadID.and("UploadID", byUploadID.entity().getUploadid(), SearchCriteria.Op.EQ);
|
||||||
|
byUploadID.and("partNumber", byUploadID.entity().getPartNumber(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultiPartPartsVO> sc = byUploadID.create();
|
||||||
|
sc.setParameters("UploadID", new Long(uploadId));
|
||||||
|
sc.setParameters("partNumber", partNumber);
|
||||||
|
update(partVO, sc);
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultiPartUploadsVO;
|
||||||
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface MultiPartUploadsDao extends
|
||||||
|
GenericDao<MultiPartUploadsVO, Long> {
|
||||||
|
|
||||||
|
OrderedPair<String, String> multipartExits(int uploadId);
|
||||||
|
|
||||||
|
void deleteUpload(int uploadId);
|
||||||
|
|
||||||
|
String getAtrributeValue(String attribute, int uploadid);
|
||||||
|
|
||||||
|
List<MultiPartUploadsVO> getInitiatedUploads(String bucketName,
|
||||||
|
int maxParts, String prefix, String keyMarker, String uploadIdMarker);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultiPartPartsVO;
|
||||||
|
import com.cloud.bridge.model.MultiPartUploadsVO;
|
||||||
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.utils.db.Attribute;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={MultiPartUploadsDao.class})
|
||||||
|
public class MultiPartUploadsDaoImpl extends GenericDaoBase<MultiPartUploadsVO, Long> implements MultiPartUploadsDao {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderedPair<String,String> multipartExits( int uploadId ) {
|
||||||
|
MultiPartUploadsVO uploadvo = null;
|
||||||
|
|
||||||
|
Transaction txn = null;
|
||||||
|
try {
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
uploadvo = findById(new Long(uploadId));
|
||||||
|
if (null != uploadvo)
|
||||||
|
return new OrderedPair<String,String>(uploadvo.getAccessKey(), uploadvo.getNameKey());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUpload(int uploadId) {
|
||||||
|
|
||||||
|
Transaction txn = null;
|
||||||
|
try {
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
remove(new Long(uploadId));
|
||||||
|
txn.commit();
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAtrributeValue(String attribute, int uploadid) {
|
||||||
|
Transaction txn = null;
|
||||||
|
MultiPartUploadsVO uploadvo = null;
|
||||||
|
try {
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
uploadvo = findById(new Long(uploadid));
|
||||||
|
if (null != uploadvo) {
|
||||||
|
if ( attribute.equalsIgnoreCase("AccessKey") )
|
||||||
|
return uploadvo.getAccessKey();
|
||||||
|
else if ( attribute.equalsIgnoreCase("x_amz_acl") )
|
||||||
|
return uploadvo.getAmzAcl();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MultiPartUploadsVO> getInitiatedUploads(String bucketName, int maxParts, String prefix, String keyMarker, String uploadIdMarker) {
|
||||||
|
|
||||||
|
List<MultiPartUploadsVO> uploadList = new ArrayList<MultiPartUploadsVO>();
|
||||||
|
|
||||||
|
SearchBuilder<MultiPartUploadsVO> byBucket = createSearchBuilder();
|
||||||
|
byBucket.and("BucketName", byBucket.entity().getBucketName() , SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
if (null != prefix)
|
||||||
|
byBucket.and("NameKey", byBucket.entity().getNameKey(), SearchCriteria.Op.LIKE);
|
||||||
|
if (null != uploadIdMarker)
|
||||||
|
byBucket.and("NameKey", byBucket.entity().getNameKey(), SearchCriteria.Op.GT);
|
||||||
|
if (null != uploadIdMarker)
|
||||||
|
byBucket.and("ID", byBucket.entity().getId(), SearchCriteria.Op.GT);
|
||||||
|
|
||||||
|
Filter filter = new Filter(MultiPartUploadsVO.class, "nameKey", Boolean.TRUE, null, null);
|
||||||
|
filter.addOrderBy(MultiPartUploadsVO.class, "createTime", Boolean.TRUE);
|
||||||
|
|
||||||
|
Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultiPartUploadsVO> sc = byBucket.create();
|
||||||
|
sc.setParameters("BucketName", bucketName);
|
||||||
|
if (null != prefix)
|
||||||
|
sc.setParameters("NameKey", prefix);
|
||||||
|
if (null != uploadIdMarker)
|
||||||
|
sc.setParameters("NameKey", keyMarker);
|
||||||
|
if (null != uploadIdMarker)
|
||||||
|
sc.setParameters("ID", uploadIdMarker);
|
||||||
|
listBy(sc, filter);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -34,42 +34,25 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultiPartPartsVO;
|
||||||
|
import com.cloud.bridge.model.MultiPartUploadsVO;
|
||||||
|
import com.cloud.bridge.model.MultipartMetaVO;
|
||||||
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
||||||
import com.cloud.bridge.service.core.s3.S3MultipartPart;
|
import com.cloud.bridge.service.core.s3.S3MultipartPart;
|
||||||
import com.cloud.bridge.service.core.s3.S3MultipartUpload;
|
import com.cloud.bridge.service.core.s3.S3MultipartUpload;
|
||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
import com.cloud.bridge.util.ConfigurationHelper;
|
||||||
import com.cloud.bridge.util.OrderedPair;
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
public class MultipartLoadDao {
|
public class MultipartLoadDao {
|
||||||
public static final Logger logger = Logger.getLogger(MultipartLoadDao.class);
|
public static final Logger logger = Logger.getLogger(MultipartLoadDao.class);
|
||||||
|
|
||||||
private Connection conn = null;
|
|
||||||
private String dbName = null;
|
|
||||||
private String dbUser = null;
|
|
||||||
private String dbPassword = null;
|
|
||||||
private String dbHost = null;
|
|
||||||
private String dbPort = null;
|
|
||||||
|
|
||||||
public MultipartLoadDao() {
|
protected final MultipartMetaDao mpartMetaDao = ComponentLocator.inject(MultipartMetaDaoImpl.class);
|
||||||
File propertiesFile = ConfigurationHelper.findConfigurationFile("db.properties");
|
protected final MultiPartPartsDao mpartPartsDao = ComponentLocator.inject(MultiPartPartsDaoImpl.class);
|
||||||
Properties EC2Prop = null;
|
protected final MultiPartUploadsDao mpartUploadDao = ComponentLocator.inject(MultiPartUploadsDaoImpl.class);
|
||||||
|
|
||||||
if (null != propertiesFile) {
|
public MultipartLoadDao() {}
|
||||||
EC2Prop = new Properties();
|
|
||||||
try {
|
|
||||||
EC2Prop.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);
|
|
||||||
}
|
|
||||||
dbHost = EC2Prop.getProperty( "db.cloud.host" );
|
|
||||||
dbName = EC2Prop.getProperty( "db.awsapi.name" );
|
|
||||||
dbUser = EC2Prop.getProperty( "db.cloud.username" );
|
|
||||||
dbPassword = EC2Prop.getProperty( "db.cloud.password" );
|
|
||||||
dbPort = EC2Prop.getProperty( "db.cloud.port" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a multipart upload exists with the uploadId value then return the non-null creators
|
* If a multipart upload exists with the uploadId value then return the non-null creators
|
||||||
@ -77,30 +60,13 @@ public class MultipartLoadDao {
|
|||||||
*
|
*
|
||||||
* @param uploadId
|
* @param uploadId
|
||||||
* @return creator of the multipart upload, and NameKey of upload
|
* @return creator of the multipart upload, and NameKey of upload
|
||||||
* @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public OrderedPair<String,String> multipartExits( int uploadId )
|
public OrderedPair<String,String> multipartExits( int uploadId )
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
PreparedStatement statement = null;
|
return mpartUploadDao.multipartExits(uploadId);
|
||||||
String accessKey = null;
|
|
||||||
String nameKey = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT AccessKey, NameKey FROM multipart_uploads WHERE ID=?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if ( rs.next()) {
|
|
||||||
accessKey = rs.getString( "AccessKey" );
|
|
||||||
nameKey = rs.getString( "NameKey" );
|
|
||||||
return new OrderedPair<String,String>( accessKey, nameKey );
|
|
||||||
}
|
|
||||||
else return null;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,23 +76,9 @@ public class MultipartLoadDao {
|
|||||||
*
|
*
|
||||||
* @param uploadId
|
* @param uploadId
|
||||||
*
|
*
|
||||||
* @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
|
|
||||||
*/
|
*/
|
||||||
public void deleteUpload( int uploadId )
|
public void deleteUpload( int uploadId ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
mpartUploadDao.deleteUpload(uploadId);
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "DELETE FROM multipart_uploads WHERE ID=?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,26 +86,9 @@ public class MultipartLoadDao {
|
|||||||
*
|
*
|
||||||
* @param uploadId
|
* @param uploadId
|
||||||
* @return the access key value defining the initiator
|
* @return the access key value defining the initiator
|
||||||
* @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
*/
|
*/
|
||||||
public String getInitiator( int uploadId )
|
public String getInitiator( int uploadId ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
return mpartUploadDao.getAtrributeValue("AccessKey", uploadId);
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String initiator = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT AccessKey FROM multipart_uploads WHERE ID=?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) initiator = rs.getString( "AccessKey" );
|
|
||||||
statement.close();
|
|
||||||
return initiator;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,47 +100,38 @@ public class MultipartLoadDao {
|
|||||||
* @param cannedAccess
|
* @param cannedAccess
|
||||||
*
|
*
|
||||||
* @return if positive its the uploadId to be returned to the client
|
* @return if positive its the uploadId to be returned to the client
|
||||||
*
|
*
|
||||||
* @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
|
|
||||||
*/
|
*/
|
||||||
public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta )
|
public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
int uploadId = -1;
|
int uploadId = -1;
|
||||||
|
Transaction txn = null;
|
||||||
openConnection();
|
|
||||||
try {
|
try {
|
||||||
Date tod = new Date();
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
java.sql.Timestamp dateTime = new Timestamp( tod.getTime());
|
Date tod = new Date();
|
||||||
|
MultiPartUploadsVO uploadVO = new MultiPartUploadsVO(accessKey,
|
||||||
|
bucketName, key, cannedAccess, tod);
|
||||||
|
uploadVO = mpartUploadDao.persist(uploadVO);
|
||||||
|
|
||||||
statement = conn.prepareStatement ( "INSERT INTO multipart_uploads (AccessKey, BucketName, NameKey, x_amz_acl, CreateTime) VALUES (?,?,?,?,?)" );
|
if (null != uploadVO) {
|
||||||
statement.setString( 1, accessKey );
|
uploadId = uploadVO.getId().intValue();
|
||||||
statement.setString( 2, bucketName );
|
if (null != meta) {
|
||||||
statement.setString( 3, key );
|
for (int i = 0; i < meta.length; i++) {
|
||||||
statement.setString( 4, cannedAccess );
|
MultipartMetaVO mpartMeta = new MultipartMetaVO();
|
||||||
statement.setTimestamp( 5, dateTime );
|
mpartMeta.setUploadID(uploadId);
|
||||||
int count = statement.executeUpdate();
|
S3MetaDataEntry entry = meta[i];
|
||||||
statement.close();
|
mpartMeta.setName(entry.getName());
|
||||||
|
mpartMeta.setValue(entry.getValue());
|
||||||
|
mpartMetaDao.persist(mpartMeta);
|
||||||
|
}
|
||||||
|
txn.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -> we need the newly entered ID
|
|
||||||
statement = conn.prepareStatement ( "SELECT ID FROM multipart_uploads WHERE AccessKey=? AND BucketName=? AND NameKey=? AND CreateTime=?" );
|
|
||||||
statement.setString( 1, accessKey );
|
|
||||||
statement.setString( 2, bucketName );
|
|
||||||
statement.setString( 3, key );
|
|
||||||
statement.setTimestamp( 4, dateTime );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
uploadId = rs.getInt( "ID" );
|
|
||||||
saveMultipartMeta( uploadId, meta );
|
|
||||||
}
|
|
||||||
statement.close();
|
|
||||||
return uploadId;
|
return uploadId;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
txn.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remember all the individual parts that make up the entire multipart upload so that once
|
* Remember all the individual parts that make up the entire multipart upload so that once
|
||||||
@ -219,49 +145,28 @@ public class MultipartLoadDao {
|
|||||||
* @param size
|
* @param size
|
||||||
* @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
* @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
*/
|
*/
|
||||||
public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size )
|
public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
int id = -1;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
try {
|
||||||
Date tod = new Date();
|
MultiPartPartsVO partVO = null;
|
||||||
java.sql.Timestamp dateTime = new java.sql.Timestamp( tod.getTime());
|
|
||||||
|
|
||||||
// -> are we doing an update or an insert? (are we over writting an existing entry?)
|
partVO = mpartPartsDao.findByUploadID(uploadId, partNumber);
|
||||||
statement = conn.prepareStatement ( "SELECT ID FROM multipart_parts WHERE UploadID=? AND partNumber=?" );
|
// -> are we doing an update or an insert? (are we over writting an
|
||||||
statement.setInt( 1, uploadId );
|
// existing entry?)
|
||||||
statement.setInt( 2, partNumber );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) id = rs.getInt( "ID" );
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
if ( -1 == id )
|
if (null == partVO) {
|
||||||
{
|
MultiPartPartsVO part = new MultiPartPartsVO(uploadId,
|
||||||
statement = conn.prepareStatement ( "INSERT INTO multipart_parts (UploadID, partNumber, MD5, StoredPath, StoredSize, CreateTime) VALUES (?,?,?,?,?,?)" );
|
partNumber, md5, storedPath, size, new Date());
|
||||||
statement.setInt( 1, uploadId );
|
mpartPartsDao.persist(part);
|
||||||
statement.setInt( 2, partNumber );
|
} else {
|
||||||
statement.setString( 3, md5 );
|
partVO.setMd5(md5);
|
||||||
statement.setString( 4, storedPath );
|
partVO.setStoredSize(new Long(size));
|
||||||
statement.setInt( 5, size );
|
partVO.setCreateTime(new Date());
|
||||||
statement.setTimestamp( 6, dateTime );
|
partVO.setUploadid(new Long(uploadId));
|
||||||
|
partVO.setPartNumber(partNumber);
|
||||||
|
mpartPartsDao.updateParts(partVO, uploadId, partNumber);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{ statement = conn.prepareStatement ( "UPDATE multipart_parts SET MD5=?, StoredSize=?, CreateTime=? WHERE UploadId=? AND partNumber=?" );
|
|
||||||
statement.setString( 1, md5 );
|
|
||||||
statement.setInt( 2, size );
|
|
||||||
statement.setTimestamp( 3, dateTime );
|
|
||||||
statement.setInt( 4, uploadId );
|
|
||||||
statement.setInt( 5, partNumber );
|
|
||||||
}
|
|
||||||
count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,24 +175,8 @@ public class MultipartLoadDao {
|
|||||||
* @param uploadId
|
* @param uploadId
|
||||||
* @return the value defined in the x-amz-acl header or null
|
* @return the value defined in the x-amz-acl header or null
|
||||||
*/
|
*/
|
||||||
public String getCannedAccess( int uploadId )
|
public String getCannedAccess( int uploadId ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
return mpartUploadDao.getAtrributeValue("x_amz_acl", uploadId);
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String access = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT x_amz_acl FROM multipart_uploads WHERE ID=?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) access = rs.getString( "x_amz_acl" );
|
|
||||||
statement.close();
|
|
||||||
return access;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -302,31 +191,25 @@ public class MultipartLoadDao {
|
|||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
List<S3MetaDataEntry> metaList = new ArrayList<S3MetaDataEntry>();
|
List<S3MetaDataEntry> metaList = new ArrayList<S3MetaDataEntry>();
|
||||||
PreparedStatement statement = null;
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
List<MultipartMetaVO> metaVO;
|
||||||
openConnection();
|
|
||||||
try {
|
try {
|
||||||
statement = conn.prepareStatement ( "SELECT Name, Value FROM multipart_meta WHERE UploadID=?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
metaVO = mpartMetaDao.getByUploadID(uploadId);
|
||||||
ResultSet rs = statement.executeQuery();
|
for (MultipartMetaVO multipartMetaVO : metaVO) {
|
||||||
|
S3MetaDataEntry oneMeta = new S3MetaDataEntry();
|
||||||
while (rs.next())
|
oneMeta.setName( multipartMetaVO.getName());
|
||||||
{
|
oneMeta.setValue( multipartMetaVO.getValue());
|
||||||
S3MetaDataEntry oneMeta = new S3MetaDataEntry();
|
metaList.add( oneMeta );
|
||||||
oneMeta.setName( rs.getString( "Name" ));
|
count++;
|
||||||
oneMeta.setValue( rs.getString( "Value" ));
|
}
|
||||||
metaList.add( oneMeta );
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
if ( 0 == count )
|
if ( 0 == count )
|
||||||
return null;
|
return null;
|
||||||
else return metaList.toArray(new S3MetaDataEntry[0]);
|
else return metaList.toArray(new S3MetaDataEntry[0]);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,52 +229,33 @@ public class MultipartLoadDao {
|
|||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
S3MultipartUpload[] inProgress = new S3MultipartUpload[maxParts];
|
S3MultipartUpload[] inProgress = new S3MultipartUpload[maxParts];
|
||||||
PreparedStatement statement = null;
|
|
||||||
boolean isTruncated = false;
|
boolean isTruncated = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
|
List<MultiPartUploadsVO> uploadList;
|
||||||
// -> SQL like condition requires the '%' as a wildcard marker
|
// -> SQL like condition requires the '%' as a wildcard marker
|
||||||
if (null != prefix) prefix = prefix + "%";
|
if (null != prefix) prefix = prefix + "%";
|
||||||
|
|
||||||
StringBuffer queryStr = new StringBuffer();
|
|
||||||
queryStr.append( "SELECT ID, AccessKey, NameKey, CreateTime FROM multipart_uploads WHERE BucketName=? " );
|
|
||||||
if (null != prefix ) queryStr.append( "AND NameKey like ? " );
|
|
||||||
if (null != keyMarker ) queryStr.append( "AND NameKey > ? ");
|
|
||||||
if (null != uploadIdMarker) queryStr.append( "AND ID > ? " );
|
|
||||||
queryStr.append( "ORDER BY NameKey, CreateTime" );
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( queryStr.toString());
|
|
||||||
statement.setString( pos++, bucketName );
|
|
||||||
if (null != prefix ) statement.setString( pos++, prefix );
|
|
||||||
if (null != keyMarker ) statement.setString( pos++, keyMarker );
|
|
||||||
if (null != uploadIdMarker) statement.setString( pos, uploadIdMarker );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next() && i < maxParts)
|
|
||||||
{
|
|
||||||
Calendar tod = Calendar.getInstance();
|
|
||||||
tod.setTime( rs.getTimestamp( "CreateTime" ));
|
|
||||||
|
|
||||||
inProgress[i] = new S3MultipartUpload();
|
try {
|
||||||
inProgress[i].setId( rs.getInt( "ID" ));
|
uploadList = mpartUploadDao.getInitiatedUploads(bucketName, maxParts, prefix, keyMarker, uploadIdMarker);
|
||||||
inProgress[i].setAccessKey( rs.getString( "AccessKey" ));
|
for (MultiPartUploadsVO uploadsVO : uploadList) {
|
||||||
inProgress[i].setLastModified( tod );
|
Calendar tod = Calendar.getInstance();
|
||||||
inProgress[i].setBucketName( bucketName );
|
tod.setTime(uploadsVO.getCreateTime());
|
||||||
inProgress[i].setKey( rs.getString( "NameKey" ));
|
inProgress[i] = new S3MultipartUpload();
|
||||||
i++;
|
inProgress[i].setId( uploadsVO.getId().intValue());
|
||||||
}
|
inProgress[i].setAccessKey(uploadsVO.getAccessKey());
|
||||||
|
inProgress[i].setLastModified( tod );
|
||||||
if (rs.next()) isTruncated = true;
|
inProgress[i].setBucketName( bucketName );
|
||||||
statement.close();
|
inProgress[i].setKey(uploadsVO.getNameKey());
|
||||||
|
i++;
|
||||||
if (i < maxParts) inProgress = (S3MultipartUpload[])resizeArray(inProgress,i);
|
}
|
||||||
return new OrderedPair<S3MultipartUpload[], Boolean>(inProgress, isTruncated);
|
|
||||||
|
if (i < maxParts)
|
||||||
} finally {
|
inProgress = (S3MultipartUpload[]) resizeArray(inProgress, i);
|
||||||
closeConnection();
|
return new OrderedPair<S3MultipartUpload[], Boolean>(inProgress,
|
||||||
|
isTruncated);
|
||||||
|
}finally {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -411,41 +275,30 @@ public class MultipartLoadDao {
|
|||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
{
|
{
|
||||||
S3MultipartPart[] parts = new S3MultipartPart[maxParts];
|
S3MultipartPart[] parts = new S3MultipartPart[maxParts];
|
||||||
PreparedStatement statement = null;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
List<MultiPartPartsVO> partsVO;
|
||||||
openConnection();
|
try {
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT partNumber, MD5, StoredSize, StoredPath, CreateTime " +
|
partsVO = mpartPartsDao.getParts(uploadId, startAt + maxParts + 1, startAt);
|
||||||
"FROM multipart_parts " +
|
|
||||||
"WHERE UploadID=? " +
|
for (MultiPartPartsVO partVO : partsVO) {
|
||||||
"AND partNumber > ? AND partNumber < ? " +
|
Calendar tod = Calendar.getInstance();
|
||||||
"ORDER BY partNumber" );
|
tod.setTime(partVO.getCreateTime());
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
statement.setInt( 2, startAt );
|
parts[i] = new S3MultipartPart();
|
||||||
statement.setInt( 3, startAt + maxParts + 1 );
|
parts[i].setPartNumber(partVO.getPartNumber());
|
||||||
ResultSet rs = statement.executeQuery();
|
parts[i].setEtag(partVO.getMd5());
|
||||||
|
parts[i].setLastModified(tod);
|
||||||
while (rs.next() && i < maxParts)
|
parts[i].setSize(partVO.getStoredSize().intValue());
|
||||||
{
|
parts[i].setPath(partVO.getStoredPath());
|
||||||
Calendar tod = Calendar.getInstance();
|
i++;
|
||||||
tod.setTime( rs.getTimestamp( "CreateTime" ));
|
}
|
||||||
|
|
||||||
parts[i] = new S3MultipartPart();
|
|
||||||
parts[i].setPartNumber( rs.getInt( "partNumber" ));
|
|
||||||
parts[i].setEtag( rs.getString( "MD5" ).toLowerCase());
|
|
||||||
parts[i].setLastModified( tod );
|
|
||||||
parts[i].setSize( rs.getInt( "StoredSize" ));
|
|
||||||
parts[i].setPath( rs.getString( "StoredPath" ));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
if (i < maxParts) parts = (S3MultipartPart[])resizeArray(parts,i);
|
if (i < maxParts) parts = (S3MultipartPart[])resizeArray(parts,i);
|
||||||
return parts;
|
return parts;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,25 +310,8 @@ public class MultipartLoadDao {
|
|||||||
* @return number of parts with partNumber greater than endMarker
|
* @return number of parts with partNumber greater than endMarker
|
||||||
* @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
* @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
||||||
*/
|
*/
|
||||||
public int numParts( int uploadId, int endMarker )
|
public int numParts( int uploadId, int endMarker ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
return mpartPartsDao.getnumParts(uploadId, endMarker);
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT count(*) FROM multipart_parts WHERE UploadID=? AND partNumber > ?" );
|
|
||||||
statement.setInt( 1, uploadId );
|
|
||||||
statement.setInt( 2, endMarker );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) count = rs.getInt( 1 );
|
|
||||||
statement.close();
|
|
||||||
return count;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -485,46 +321,30 @@ public class MultipartLoadDao {
|
|||||||
* @param uploadId - defines an in-process multipart upload
|
* @param uploadId - defines an in-process multipart upload
|
||||||
* @param meta - an array of meta data to be assocated with the uploadId value
|
* @param meta - an array of meta data to be assocated with the uploadId value
|
||||||
*
|
*
|
||||||
* @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
|
|
||||||
*/
|
*/
|
||||||
private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta )
|
private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta ) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
if (null == meta) return;
|
||||||
{
|
|
||||||
if (null == meta) return;
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
Transaction txn = null;
|
||||||
try {
|
try {
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
for( int i=0; i < meta.length; i++ )
|
for( int i=0; i < meta.length; i++ )
|
||||||
{
|
{
|
||||||
S3MetaDataEntry entry = meta[i];
|
S3MetaDataEntry entry = meta[i];
|
||||||
statement = conn.prepareStatement ( "INSERT INTO multipart_meta (UploadID, Name, Value) VALUES (?,?,?)" );
|
MultipartMetaVO metaVO = new MultipartMetaVO();
|
||||||
statement.setInt( 1, uploadId );
|
metaVO.setUploadID(uploadId);
|
||||||
statement.setString( 2, entry.getName());
|
metaVO.setName(entry.getName());
|
||||||
statement.setString( 3, entry.getValue());
|
metaVO.setValue(entry.getValue());
|
||||||
int count = statement.executeUpdate();
|
metaVO=mpartMetaDao.persist(metaVO);
|
||||||
statement.close();
|
|
||||||
}
|
}
|
||||||
|
txn.commit();
|
||||||
} finally {
|
} finally {
|
||||||
closeConnection();
|
txn.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection()
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
if (null == conn) {
|
|
||||||
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
|
|
||||||
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeConnection() throws SQLException {
|
/**
|
||||||
if (null != conn) conn.close();
|
|
||||||
conn = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reallocates an array with a new size, and copies the contents
|
* Reallocates an array with a new size, and copies the contents
|
||||||
* of the old array to the new array.
|
* of the old array to the new array.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultipartMetaVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface MultipartMetaDao extends GenericDao<MultipartMetaVO, Long> {
|
||||||
|
|
||||||
|
List<MultipartMetaVO> getByUploadID(long uploadID);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.MultipartMetaVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={MultipartMetaDao.class})
|
||||||
|
public class MultipartMetaDaoImpl extends GenericDaoBase<MultipartMetaVO, Long> implements MultipartMetaDao {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MultipartMetaVO> getByUploadID (long uploadID) {
|
||||||
|
SearchBuilder <MultipartMetaVO> searchByUID = createSearchBuilder();
|
||||||
|
searchByUID.and("UploadID", searchByUID.entity().getUploadID(), SearchCriteria.Op.EQ);
|
||||||
|
searchByUID.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<MultipartMetaVO> sc = searchByUID.create();
|
||||||
|
sc.setParameters("UploadID", uploadID);
|
||||||
|
return listBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,169 +1,18 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.io.File;
|
import com.cloud.bridge.model.OfferingBundleVO;
|
||||||
import java.io.FileInputStream;
|
import com.cloud.utils.db.GenericDao;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
public interface OfferingDao extends GenericDao<OfferingBundleVO, Long> {
|
||||||
|
|
||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
int getOfferingCount();
|
||||||
|
|
||||||
|
String getCloudOffering(String amazonEC2Offering);
|
||||||
|
|
||||||
public class OfferingDao extends BaseDao {
|
String getAmazonOffering(String cloudStackOffering);
|
||||||
public static final Logger logger = Logger.getLogger(OfferingDao.class);
|
|
||||||
|
|
||||||
private Connection conn = null;
|
void setOfferMapping(String amazonEC2Offering, String cloudStackOffering);
|
||||||
|
|
||||||
public OfferingDao()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOfferingCount()
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT count(*) FROM offering_bundle" );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) result = rs.getInt(1);
|
|
||||||
statement.close();
|
|
||||||
return result;
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCloudOffering( String amazonEC2Offering )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String result = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT CloudStackOffering FROM offering_bundle WHERE AmazonEC2Offering=?" );
|
|
||||||
statement.setString( 1, amazonEC2Offering );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) result = rs.getString( "CloudStackOffering" );
|
|
||||||
statement.close();
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAmazonOffering( String cloudStackOffering )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String result = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "SELECT AmazonEC2Offering FROM offering_bundle WHERE CloudStackOffering=?" );
|
|
||||||
statement.setString( 1, cloudStackOffering );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) result = rs.getString( "AmazonEC2Offering" );
|
|
||||||
statement.close();
|
|
||||||
return result;
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOfferMapping( String amazonEC2Offering, String cloudStackOffering )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
int id = -1;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
openConnection();
|
void deleteOfferMapping(String amazonEC2Offering);
|
||||||
try {
|
|
||||||
// -> are we doing an update or an insert? (are we over writing an existing entry?)
|
|
||||||
statement = conn.prepareStatement ( "SELECT ID FROM offering_bundle WHERE AmazonEC2Offering=?" );
|
|
||||||
statement.setString( 1, amazonEC2Offering );
|
|
||||||
ResultSet rs = statement.executeQuery();
|
|
||||||
if (rs.next()) id = rs.getInt( "ID" );
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
if ( -1 == id )
|
|
||||||
{
|
|
||||||
statement = conn.prepareStatement ( "INSERT INTO offering_bundle (AmazonEC2Offering, CloudStackOffering) VALUES (?,?)" );
|
|
||||||
statement.setString( 1, amazonEC2Offering );
|
|
||||||
statement.setString( 2, cloudStackOffering );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ statement = conn.prepareStatement ( "UPDATE offering_bundle SET CloudStackOffering=? WHERE AmazonEC2Offering=?" );
|
|
||||||
statement.setString( 1, cloudStackOffering );
|
|
||||||
statement.setString( 2, amazonEC2Offering );
|
|
||||||
}
|
|
||||||
count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteOfferMapping( String amazonEC2Offering )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "DELETE FROM offering_bundle WHERE AmazonEC2Offering=?" );
|
|
||||||
statement.setString( 1, amazonEC2Offering );
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openConnection()
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
|
|
||||||
{
|
|
||||||
if (null == conn) {
|
|
||||||
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
|
|
||||||
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + awsapi_dbName, dbUser, dbPassword );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeConnection() throws SQLException
|
|
||||||
{
|
|
||||||
if (null != conn) conn.close();
|
|
||||||
conn = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
135
awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java
Normal file
135
awsapi/src/com/cloud/bridge/persist/dao/OfferingDaoImpl.java
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.OfferingBundleVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={OfferingDao.class})
|
||||||
|
public class OfferingDaoImpl extends GenericDaoBase<OfferingBundleVO, Long> implements OfferingDao {
|
||||||
|
public static final Logger logger = Logger.getLogger(OfferingDaoImpl.class);
|
||||||
|
|
||||||
|
public OfferingDaoImpl() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOfferingCount() {
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
return listAll().size();
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCloudOffering( String amazonEC2Offering ) {
|
||||||
|
|
||||||
|
SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
|
||||||
|
searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
|
||||||
|
searchByAmazon.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
|
||||||
|
sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
|
||||||
|
return findOneBy(sc).getCloudstackOffering();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAmazonOffering( String cloudStackOffering ) {
|
||||||
|
|
||||||
|
SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
|
||||||
|
searchByAmazon.and("CloudStackOffering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
|
||||||
|
searchByAmazon.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
|
||||||
|
sc.setParameters("CloudStackOffering", cloudStackOffering);
|
||||||
|
return findOneBy(sc).getAmazonOffering();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOfferMapping( String amazonEC2Offering, String cloudStackOffering ) {
|
||||||
|
|
||||||
|
SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
|
||||||
|
searchByAmazon.and("CloudStackOffering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
|
||||||
|
searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getCloudstackOffering() , SearchCriteria.Op.EQ);
|
||||||
|
searchByAmazon.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
OfferingBundleVO offering = null;
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
|
||||||
|
sc.setParameters("CloudStackOffering", cloudStackOffering);
|
||||||
|
sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
|
||||||
|
offering = findOneBy(sc);
|
||||||
|
if (null == offering) {
|
||||||
|
offering = new OfferingBundleVO();
|
||||||
|
}
|
||||||
|
offering.setAmazonOffering(amazonEC2Offering);
|
||||||
|
offering.setCloudstackOffering(cloudStackOffering);
|
||||||
|
if (null == offering)
|
||||||
|
offering = persist(offering);
|
||||||
|
else
|
||||||
|
update(offering.getID(), offering);
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteOfferMapping( String amazonEC2Offering ) {
|
||||||
|
SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
|
||||||
|
searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
|
||||||
|
searchByAmazon.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
|
||||||
|
sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
|
||||||
|
remove(sc);
|
||||||
|
txn.commit();
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,76 +1,21 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SAcl;
|
import com.cloud.bridge.model.SAcl;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.bridge.model.SAclVO;
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
|
||||||
import com.cloud.bridge.service.core.s3.S3AccessControlList;
|
import com.cloud.bridge.service.core.s3.S3AccessControlList;
|
||||||
import com.cloud.bridge.service.core.s3.S3Grant;
|
import com.cloud.bridge.service.core.s3.S3Grant;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public class SAclDao extends EntityDao<SAcl> {
|
public interface SAclDao extends GenericDao<SAclVO, Long> {
|
||||||
|
|
||||||
public SAclDao() {
|
|
||||||
super(SAcl.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SAcl> listGrants(String target, long targetId) {
|
|
||||||
return queryEntities("from SAcl where target=? and targetId=? order by grantOrder asc",
|
|
||||||
new Object[] { target, new Long(targetId)});
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SAcl> listGrants(String target, long targetId, String userCanonicalId) {
|
List<SAclVO> listGrants(String target, long targetId, String userCanonicalId);
|
||||||
return queryEntities("from SAcl where target=? and targetId=? and granteeCanonicalId=? order by grantOrder asc",
|
|
||||||
new Object[] { target, new Long(targetId), userCanonicalId });
|
void save(String target, long targetId, S3AccessControlList acl);
|
||||||
}
|
|
||||||
|
SAcl save(String target, long targetId, S3Grant grant, int grantOrder);
|
||||||
|
|
||||||
|
List<SAclVO> listGrants(String target, long targetId);
|
||||||
|
|
||||||
public void save(String target, long targetId, S3AccessControlList acl) {
|
|
||||||
// -> the target's ACLs are being redefined
|
|
||||||
executeUpdate("delete from SAcl where target=? and targetId=?", new Object[] { target, new Long(targetId)});
|
|
||||||
|
|
||||||
if(acl != null) {
|
|
||||||
S3Grant[] grants = acl.getGrants();
|
|
||||||
if(grants != null && grants.length > 0) {
|
|
||||||
int grantOrder = 1;
|
|
||||||
for(S3Grant grant : grants) {
|
|
||||||
save(target, targetId, grant, grantOrder++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SAcl save(String target, long targetId, S3Grant grant, int grantOrder) {
|
|
||||||
SAcl aclEntry = new SAcl();
|
|
||||||
aclEntry.setTarget(target);
|
|
||||||
aclEntry.setTargetId(targetId);
|
|
||||||
aclEntry.setGrantOrder(grantOrder);
|
|
||||||
|
|
||||||
int grantee = grant.getGrantee();
|
|
||||||
aclEntry.setGranteeType(grantee);
|
|
||||||
aclEntry.setPermission(grant.getPermission());
|
|
||||||
aclEntry.setGranteeCanonicalId(grant.getCanonicalUserID());
|
|
||||||
|
|
||||||
Date ts = new Date();
|
|
||||||
aclEntry.setCreateTime(ts);
|
|
||||||
aclEntry.setLastModifiedTime(ts);
|
|
||||||
PersistContext.getSession().save(aclEntry);
|
|
||||||
return aclEntry;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
127
awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java
Normal file
127
awsapi/src/com/cloud/bridge/persist/dao/SAclDaoImpl.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SAcl;
|
||||||
|
import com.cloud.bridge.model.SAclVO;
|
||||||
|
import com.cloud.bridge.service.core.s3.S3AccessControlList;
|
||||||
|
import com.cloud.bridge.service.core.s3.S3Grant;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SAclDao.class})
|
||||||
|
public class SAclDaoImpl extends GenericDaoBase<SAclVO, Long> implements SAclDao {
|
||||||
|
|
||||||
|
public SAclDaoImpl() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SAclVO> listGrants(String target, long targetId) {
|
||||||
|
SearchBuilder<SAclVO> SearchByTarget = createSearchBuilder();
|
||||||
|
SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.done();
|
||||||
|
Filter filter = new Filter(SAclVO.class, "grantOrder", Boolean.TRUE, null, null);
|
||||||
|
Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SAclVO> sc = SearchByTarget.create();
|
||||||
|
sc.setParameters("Target", target);
|
||||||
|
sc.setParameters("TargetID", targetId);
|
||||||
|
return listBy(sc, filter);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SAclVO> listGrants(String target, long targetId, String userCanonicalId) {
|
||||||
|
SearchBuilder<SAclVO> SearchByAcl = createSearchBuilder();
|
||||||
|
SearchByAcl.and("Target", SearchByAcl.entity().getTarget(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByAcl.and("TargetID", SearchByAcl.entity().getTargetId(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByAcl.and("GranteeCanonicalID", SearchByAcl.entity().getGranteeCanonicalId(), SearchCriteria.Op.EQ);
|
||||||
|
Filter filter = new Filter(SAclVO.class, "grantOrder", Boolean.TRUE, null, null);
|
||||||
|
Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SAclVO> sc = SearchByAcl.create();
|
||||||
|
sc.setParameters("Target", target);
|
||||||
|
sc.setParameters("TargetID", targetId);
|
||||||
|
sc.setParameters("GranteeCanonicalID", userCanonicalId);
|
||||||
|
return listBy(sc, filter);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(String target, long targetId, S3AccessControlList acl) {
|
||||||
|
SearchBuilder<SAclVO> SearchByTarget = createSearchBuilder();
|
||||||
|
SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SAclVO> sc = SearchByTarget.create();
|
||||||
|
sc.setParameters("Target", target);
|
||||||
|
sc.setParameters("TargetID", targetId);
|
||||||
|
this.remove(sc);
|
||||||
|
if(acl != null) {
|
||||||
|
S3Grant[] grants = acl.getGrants();
|
||||||
|
if(grants != null && grants.length > 0) {
|
||||||
|
int grantOrder = 1;
|
||||||
|
for(S3Grant grant : grants) {
|
||||||
|
save(target, targetId, grant, grantOrder++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
txn.commit();
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAcl save(String target, long targetId, S3Grant grant, int grantOrder) {
|
||||||
|
SAclVO aclEntry = new SAclVO();
|
||||||
|
aclEntry.setTarget(target);
|
||||||
|
aclEntry.setTargetId(targetId);
|
||||||
|
aclEntry.setGrantOrder(grantOrder);
|
||||||
|
|
||||||
|
int grantee = grant.getGrantee();
|
||||||
|
aclEntry.setGranteeType(grantee);
|
||||||
|
aclEntry.setPermission(grant.getPermission());
|
||||||
|
aclEntry.setGranteeCanonicalId(grant.getCanonicalUserID());
|
||||||
|
|
||||||
|
Date ts = new Date();
|
||||||
|
aclEntry.setCreateTime(ts);
|
||||||
|
aclEntry.setLastModifiedTime(ts);
|
||||||
|
aclEntry = this.persist(aclEntry);
|
||||||
|
return aclEntry;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,37 +1,14 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SBucket;
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public class SBucketDao extends EntityDao<SBucket> {
|
public interface SBucketDao extends GenericDao<SBucketVO, Long> {
|
||||||
public SBucketDao() {
|
|
||||||
super(SBucket.class);
|
SBucketVO getByName(String bucketName);
|
||||||
}
|
|
||||||
|
List<SBucketVO> listBuckets(String canonicalId);
|
||||||
|
|
||||||
public SBucket getByName(String bucketName) {
|
|
||||||
return queryEntity("from SBucket where name=?", new Object[] {bucketName});
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SBucket> listBuckets(String canonicalId) {
|
|
||||||
return queryEntities("from SBucket where ownerCanonicalId=? order by createTime asc",
|
|
||||||
new Object[] {canonicalId});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
72
awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java
Normal file
72
awsapi/src/com/cloud/bridge/persist/dao/SBucketDaoImpl.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SBucket;
|
||||||
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SBucketDao.class})
|
||||||
|
public class SBucketDaoImpl extends GenericDaoBase<SBucketVO, Long> implements SBucketDao {
|
||||||
|
|
||||||
|
public SBucketDaoImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SBucketVO getByName(String bucketName) {
|
||||||
|
SearchBuilder<SBucketVO> SearchByName = createSearchBuilder();
|
||||||
|
SearchByName.and("Name", SearchByName.entity().getName(), SearchCriteria.Op.EQ);
|
||||||
|
//Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SBucketVO> sc = SearchByName.create();
|
||||||
|
sc.setParameters("Name", bucketName);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SBucketVO> listBuckets(String canonicalId) {
|
||||||
|
SearchBuilder<SBucketVO> ByCanonicalID = createSearchBuilder();
|
||||||
|
ByCanonicalID.and("OwnerCanonicalID", ByCanonicalID.entity().getOwnerCanonicalId(), SearchCriteria.Op.EQ);
|
||||||
|
Filter filter = new Filter(SBucketVO.class, "createTime", Boolean.TRUE, null, null);
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SBucketVO> sc = ByCanonicalID.create();
|
||||||
|
sc.setParameters("OwnerCanonicalID", canonicalId);
|
||||||
|
return listBy(sc, filter);
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,35 +1,12 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SHost;
|
import com.cloud.bridge.model.SHostVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface SHostDao extends GenericDao<SHostVO, Long> {
|
||||||
|
|
||||||
|
SHostVO getByHost(String host);
|
||||||
|
|
||||||
|
SHostVO getLocalStorageHost(long mhostId, String storageRoot);
|
||||||
|
|
||||||
public class SHostDao extends EntityDao<SHost> {
|
|
||||||
public SHostDao() {
|
|
||||||
super(SHost.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SHost getByHost(String host) {
|
|
||||||
return queryEntity("from SHost where host=?", new Object[] { host });
|
|
||||||
}
|
|
||||||
|
|
||||||
public SHost getLocalStorageHost(long mhostId, String storageRoot) {
|
|
||||||
return queryEntity("from SHost where mhost=? and exportRoot=?",
|
|
||||||
new Object[] { new Long(mhostId), storageRoot});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
67
awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java
Normal file
67
awsapi/src/com/cloud/bridge/persist/dao/SHostDaoImpl.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SHostVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SHostDao.class})
|
||||||
|
public class SHostDaoImpl extends GenericDaoBase<SHostVO, Long> implements SHostDao {
|
||||||
|
public SHostDaoImpl() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SHostVO getByHost(String host) {
|
||||||
|
SearchBuilder <SHostVO> HostSearch = createSearchBuilder();
|
||||||
|
HostSearch.and("Host", HostSearch.entity().getHost(), SearchCriteria.Op.EQ);
|
||||||
|
HostSearch.done();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SHostVO> sc = HostSearch.create();
|
||||||
|
sc.setParameters("Host", host);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SHostVO getLocalStorageHost(long mhostId, String storageRoot) {
|
||||||
|
SearchBuilder <SHostVO> LocalStorageHostSearch = createSearchBuilder();
|
||||||
|
LocalStorageHostSearch.and("MHostID", LocalStorageHostSearch.entity().getMhostid(), SearchCriteria.Op.EQ);
|
||||||
|
LocalStorageHostSearch.and("ExportRoot", LocalStorageHostSearch.entity().getExportRoot(), SearchCriteria.Op.EQ);
|
||||||
|
LocalStorageHostSearch.done();
|
||||||
|
Transaction txn = Transaction.currentTxn();
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SHostVO> sc = LocalStorageHostSearch.create();
|
||||||
|
sc.setParameters("MHostID", mhostId);
|
||||||
|
sc.setParameters("ExportRoot", storageRoot);
|
||||||
|
return findOneBy(sc);
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,55 +1,17 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SMeta;
|
import com.cloud.bridge.model.SMetaVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
|
||||||
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public class SMetaDao extends EntityDao<SMeta> {
|
public interface SMetaDao extends GenericDao<SMetaVO, Long> {
|
||||||
public SMetaDao() {
|
|
||||||
super(SMeta.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SMeta> getByTarget(String target, long targetId) {
|
|
||||||
return queryEntities("from SMeta where target=? and targetId=?", new Object[] {target, targetId});
|
|
||||||
}
|
|
||||||
|
|
||||||
public SMeta save(String target, long targetId, S3MetaDataEntry entry) {
|
List<SMetaVO> getByTarget(String target, long targetId);
|
||||||
SMeta meta = new SMeta();
|
|
||||||
meta.setTarget(target);
|
SMetaVO save(String target, long targetId, S3MetaDataEntry entry);
|
||||||
meta.setTargetId(targetId);
|
|
||||||
meta.setName(entry.getName());
|
void save(String target, long targetId, S3MetaDataEntry[] entries);
|
||||||
meta.setValue(entry.getValue());
|
|
||||||
|
|
||||||
PersistContext.getSession().save(meta);
|
|
||||||
return meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(String target, long targetId, S3MetaDataEntry[] entries) {
|
|
||||||
// To redefine the target's metadaa
|
|
||||||
executeUpdate("delete from SMeta where target=? and targetId=?", new Object[] { target, new Long(targetId)});
|
|
||||||
|
|
||||||
if(entries != null) {
|
|
||||||
for(S3MetaDataEntry entry : entries)
|
|
||||||
save(target, targetId, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
88
awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java
Normal file
88
awsapi/src/com/cloud/bridge/persist/dao/SMetaDaoImpl.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SMetaVO;
|
||||||
|
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SMetaDao.class})
|
||||||
|
public class SMetaDaoImpl extends GenericDaoBase<SMetaVO, Long> implements SMetaDao {
|
||||||
|
|
||||||
|
public SMetaDaoImpl() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SMetaVO> getByTarget(String target, long targetId) {
|
||||||
|
SearchBuilder <SMetaVO> SearchByTarget = createSearchBuilder();
|
||||||
|
SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.done();
|
||||||
|
Transaction txn = Transaction.open( Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SMetaVO> sc = SearchByTarget.create();
|
||||||
|
sc.setParameters("Target", target);
|
||||||
|
sc.setParameters("TargetID", targetId);
|
||||||
|
return listBy(sc);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SMetaVO save(String target, long targetId, S3MetaDataEntry entry) {
|
||||||
|
SMetaVO meta = new SMetaVO();
|
||||||
|
meta.setTarget(target);
|
||||||
|
meta.setTargetId(targetId);
|
||||||
|
meta.setName(entry.getName());
|
||||||
|
meta.setValue(entry.getValue());
|
||||||
|
meta = this.persist(meta);
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(String target, long targetId, S3MetaDataEntry[] entries) {
|
||||||
|
// To redefine the target's metadaa
|
||||||
|
SearchBuilder <SMetaVO> SearchByTarget = createSearchBuilder();
|
||||||
|
SearchByTarget.and("Target", SearchByTarget.entity().getTarget(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByTarget.and("TargetID", SearchByTarget.entity().getTargetId(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SMetaVO> sc = SearchByTarget.create();
|
||||||
|
sc.setParameters("Target", target);
|
||||||
|
sc.setParameters("TargetID", targetId);
|
||||||
|
this.remove(sc);
|
||||||
|
|
||||||
|
if(entries != null) {
|
||||||
|
for(S3MetaDataEntry entry : entries)
|
||||||
|
save(target, targetId, entry);
|
||||||
|
}
|
||||||
|
txn.commit();
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,76 +1,19 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SBucket;
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
import com.cloud.bridge.model.SObject;
|
import com.cloud.bridge.model.SObjectVO;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
import com.cloud.bridge.util.EntityParam;
|
|
||||||
|
|
||||||
public class SObjectDao extends EntityDao<SObject> {
|
public interface SObjectDao extends GenericDao<SObjectVO, Long> {
|
||||||
public SObjectDao() {
|
|
||||||
super(SObject.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SObject getByNameKey(SBucket bucket, String nameKey) {
|
List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix,
|
||||||
return queryEntity("from SObject where bucket=? and nameKey=?",
|
String marker, int maxKeys);
|
||||||
new Object[] { new EntityParam(bucket), nameKey });
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SObject> listBucketObjects(SBucket bucket, String prefix, String marker, int maxKeys) {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
List<Object> params = new ArrayList<Object>();
|
|
||||||
|
|
||||||
sb.append("from SObject o left join fetch o.items where deletionMark is null and o.bucket=?");
|
List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix,
|
||||||
params.add(new EntityParam(bucket));
|
String marker, int maxKeys);
|
||||||
|
|
||||||
if(prefix != null && !prefix.isEmpty()) {
|
SObjectVO getByNameKey(SBucketVO bucket, String nameKey);
|
||||||
sb.append(" and o.nameKey like ?");
|
|
||||||
params.add(new String(prefix + "%"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(marker != null && !marker.isEmpty()) {
|
|
||||||
sb.append(" and o.nameKey > ?");
|
|
||||||
params.add(marker);
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryEntities(sb.toString(), 0, maxKeys, params.toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SObject> listAllBucketObjects(SBucket bucket, String prefix, String marker, int maxKeys) {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
List<Object> params = new ArrayList<Object>();
|
|
||||||
|
|
||||||
sb.append("from SObject o left join fetch o.items where o.bucket=?");
|
|
||||||
params.add(new EntityParam(bucket));
|
|
||||||
|
|
||||||
if(prefix != null && !prefix.isEmpty()) {
|
|
||||||
sb.append(" and o.nameKey like ?");
|
|
||||||
params.add(new String(prefix + "%"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(marker != null && !marker.isEmpty()) {
|
|
||||||
sb.append(" and o.nameKey > ?");
|
|
||||||
params.add(marker);
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryEntities(sb.toString(), 0, maxKeys, params.toArray());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
119
awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
Normal file
119
awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SBucket;
|
||||||
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
|
import com.cloud.bridge.model.SObjectItemVO;
|
||||||
|
import com.cloud.bridge.model.SObjectVO;
|
||||||
|
import com.cloud.bridge.util.EntityParam;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SObjectDao.class})
|
||||||
|
public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements SObjectDao {
|
||||||
|
protected final SObjectItemDao itemDao = ComponentLocator.inject(SObjectItemDaoImpl.class);
|
||||||
|
|
||||||
|
public SObjectDaoImpl() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SObjectVO getByNameKey(SBucketVO bucket, String nameKey) {
|
||||||
|
SObjectVO object = null;
|
||||||
|
SearchBuilder<SObjectVO> SearchByName = createSearchBuilder();
|
||||||
|
SearchByName.and("SBucketID", SearchByName.entity().getBucketID() , SearchCriteria.Op.EQ);
|
||||||
|
SearchByName.and("NameKey", SearchByName.entity().getNameKey() , SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SObjectVO> sc = SearchByName.create();
|
||||||
|
sc.setParameters("SBucketID", bucket.getId());
|
||||||
|
sc.setParameters("NameKey", nameKey);
|
||||||
|
object = findOneBy(sc);
|
||||||
|
if (null != object) {
|
||||||
|
Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(
|
||||||
|
itemDao.getItems(object.getId()));
|
||||||
|
object.setItems(items);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
List<Object> params = new ArrayList<Object>();
|
||||||
|
SearchBuilder<SObjectVO> SearchByBucket = createSearchBuilder();
|
||||||
|
List<SObjectVO> objects = new ArrayList<SObjectVO>();
|
||||||
|
|
||||||
|
SearchByBucket.and("SBucketID", SearchByBucket.entity().getBucketID(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByBucket.and("DeletionMark", SearchByBucket.entity().getDeletionMark(), SearchCriteria.Op.NULL);
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SObjectVO> sc = SearchByBucket.create();
|
||||||
|
sc.setParameters("SBucketID", bucket.getId());
|
||||||
|
objects = listBy(sc);
|
||||||
|
for (SObjectVO sObjectVO : objects) {
|
||||||
|
Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(itemDao.getItems(sObjectVO.getId()));
|
||||||
|
sObjectVO.setItems(items);
|
||||||
|
}
|
||||||
|
return objects;
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
List<Object> params = new ArrayList<Object>();
|
||||||
|
SearchBuilder<SObjectVO> getAllBuckets = createSearchBuilder();
|
||||||
|
List<SObjectVO> objects = new ArrayList<SObjectVO>();
|
||||||
|
getAllBuckets.and("SBucketID", getAllBuckets.entity().getBucketID(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
Transaction txn = Transaction.currentTxn(); // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SObjectVO> sc = getAllBuckets.create();
|
||||||
|
sc.setParameters("SBucketID", bucket.getId());
|
||||||
|
objects = listBy(sc);
|
||||||
|
for (SObjectVO sObjectVO : objects) {
|
||||||
|
Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(itemDao.getItems(sObjectVO.getId()));
|
||||||
|
sObjectVO.setItems(items);
|
||||||
|
}
|
||||||
|
return objects;
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,30 +1,14 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SObjectItem;
|
import java.util.List;
|
||||||
import com.cloud.bridge.persist.EntityDao;
|
|
||||||
|
import com.cloud.bridge.model.SObjectItemVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface SObjectItemDao extends GenericDao<SObjectItemVO, Long> {
|
||||||
|
|
||||||
|
SObjectItemVO getByObjectIdNullVersion(long id);
|
||||||
|
|
||||||
|
List<SObjectItemVO> getItems(long sobjectID);
|
||||||
|
|
||||||
public class SObjectItemDao extends EntityDao<SObjectItem> {
|
|
||||||
public SObjectItemDao() {
|
|
||||||
super(SObjectItem.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SObjectItem getByObjectIdNullVersion(long id) {
|
|
||||||
return queryEntity("from SObjectItem where theObject=? and version is null", new Object[] { id });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.SObjectItemVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={SObjectItemDao.class})
|
||||||
|
public class SObjectItemDaoImpl extends GenericDaoBase<SObjectItemVO, Long> implements SObjectItemDao {
|
||||||
|
|
||||||
|
|
||||||
|
public SObjectItemDaoImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SObjectItemVO getByObjectIdNullVersion(long id) {
|
||||||
|
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
SearchBuilder <SObjectItemVO> SearchByID = createSearchBuilder();
|
||||||
|
SearchByID.and("ID", SearchByID.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SObjectItemVO> sc = SearchByID.create();
|
||||||
|
sc.setParameters("ID", id);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SObjectItemVO> getItems(long sobjectID) {
|
||||||
|
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
SearchBuilder<SObjectItemVO> SearchBySobjectID = createSearchBuilder();
|
||||||
|
SearchBySobjectID.and("SObjectID", SearchBySobjectID.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<SObjectItemVO> sc = SearchBySobjectID.create();
|
||||||
|
sc.setParameters("SObjectID", sobjectID);
|
||||||
|
return listBy(sc);
|
||||||
|
//findOneIncludingRemovedBy(sc);
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,169 +1,12 @@
|
|||||||
// 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.persist.dao;
|
package com.cloud.bridge.persist.dao;
|
||||||
|
|
||||||
import java.sql.*;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
public interface UserCredentialsDao extends GenericDao<UserCredentialsVO, Long> {
|
||||||
|
|
||||||
import com.cloud.bridge.model.UserCredentials;
|
UserCredentialsVO getByAccessKey(String cloudAccessKey);
|
||||||
import com.cloud.bridge.service.exception.NoSuchObjectException;
|
|
||||||
|
|
||||||
|
UserCredentialsVO getByCertUniqueId(String certId);
|
||||||
|
|
||||||
public class UserCredentialsDao extends BaseDao{
|
|
||||||
public static final Logger logger = Logger.getLogger(UserCredentialsDao.class);
|
|
||||||
|
|
||||||
private Connection conn = null;
|
|
||||||
|
|
||||||
public UserCredentialsDao() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserKeys( String cloudAccessKey, String cloudSecretKey )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
UserCredentials user = getByAccessKey( cloudAccessKey );
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
if ( null == user ) {
|
|
||||||
// -> do an insert since the user does not exist yet
|
|
||||||
statement = conn.prepareStatement ( "INSERT INTO usercredentials (AccessKey, SecretKey) VALUES(?,?)" );
|
|
||||||
statement.setString( 1, cloudAccessKey );
|
|
||||||
statement.setString( 2, cloudSecretKey );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// -> do an update since the user exists
|
|
||||||
statement = conn.prepareStatement ( "UPDATE usercredentials SET SecretKey=? WHERE AccessKey=?" );
|
|
||||||
statement.setString( 1, cloudSecretKey );
|
|
||||||
statement.setString( 2, cloudAccessKey );
|
|
||||||
}
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCertificateId( String cloudAccessKey, String certId )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
UserCredentials user = getByAccessKey( cloudAccessKey );
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
|
|
||||||
if (null == user) throw new NoSuchObjectException( "Cloud API Access Key [" + cloudAccessKey + "] is unknown" );
|
|
||||||
|
|
||||||
openConnection();
|
|
||||||
try {
|
|
||||||
statement = conn.prepareStatement ( "UPDATE usercredentials SET CertUniqueId=? WHERE AccessKey=?" );
|
|
||||||
statement.setString( 1, certId );
|
|
||||||
statement.setString( 2, cloudAccessKey );
|
|
||||||
int count = statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserCredentials getByAccessKey( String cloudAccessKey )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
openConnection();
|
|
||||||
|
|
||||||
UserCredentials user = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = conn.prepareStatement ( "SELECT SecretKey, CertUniqueId FROM usercredentials WHERE AccessKey=?" );
|
|
||||||
statement.setString( 1, cloudAccessKey );
|
|
||||||
statement.executeQuery();
|
|
||||||
ResultSet rs = statement.getResultSet ();
|
|
||||||
if (rs.next()) {
|
|
||||||
user = new UserCredentials();
|
|
||||||
user.setAccessKey( cloudAccessKey );
|
|
||||||
user.setSecretKey( rs.getString( "SecretKey" ));
|
|
||||||
user.setCertUniqueId( rs.getString( "CertUniqueId" ));
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserCredentials getByCertUniqueId( String certId )
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
openConnection();
|
|
||||||
|
|
||||||
UserCredentials user = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = conn.prepareStatement ( "SELECT AccessKey, SecretKey FROM usercredentials WHERE CertUniqueId=?" );
|
|
||||||
statement.setString( 1, certId );
|
|
||||||
statement.executeQuery();
|
|
||||||
ResultSet rs = statement.getResultSet ();
|
|
||||||
if (rs.next()) {
|
|
||||||
user = new UserCredentials();
|
|
||||||
user.setAccessKey( rs.getString( "AccessKey" ));
|
|
||||||
user.setSecretKey( rs.getString( "SecretKey" ));
|
|
||||||
user.setCertUniqueId( certId );
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openConnection()
|
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
if (null == conn) {
|
|
||||||
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
|
|
||||||
conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + "/" + awsapi_dbName, dbUser, dbPassword );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeConnection() throws SQLException {
|
|
||||||
if (null != conn) conn.close();
|
|
||||||
conn = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void preCheckTableExistence() throws Exception{
|
|
||||||
UserCredentialsDao dao = new UserCredentialsDao();
|
|
||||||
dao.checkTableExistence();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkTableExistence() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
openConnection();
|
|
||||||
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = conn.prepareStatement ( "SELECT * FROM usercredentials " );
|
|
||||||
statement.executeQuery();
|
|
||||||
ResultSet rs = statement.getResultSet ();
|
|
||||||
if (rs.next()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
|
||||||
Statement statement = conn.createStatement();
|
|
||||||
statement.execute( "create table usercredentials(id integer auto_increment primary key, AccessKey varchar(1000), SecretKey varchar(1000), CertUniqueId varchar(1000))" );
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
finally{
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
// 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.persist.dao;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
@Local(value={UserCredentialsDao.class})
|
||||||
|
public class UserCredentialsDaoImpl extends GenericDaoBase<UserCredentialsVO, Long> implements UserCredentialsDao {
|
||||||
|
public static final Logger logger = Logger.getLogger(UserCredentialsDaoImpl.class);
|
||||||
|
|
||||||
|
public UserCredentialsDaoImpl() {}
|
||||||
|
|
||||||
|
@DB
|
||||||
|
@Override
|
||||||
|
public UserCredentialsVO getByAccessKey( String cloudAccessKey ) {
|
||||||
|
SearchBuilder<UserCredentialsVO> SearchByAccessKey = createSearchBuilder();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchByAccessKey.and("AccessKey", SearchByAccessKey.entity()
|
||||||
|
.getAccessKey(), SearchCriteria.Op.EQ);
|
||||||
|
SearchByAccessKey.done();
|
||||||
|
SearchCriteria<UserCredentialsVO> sc = SearchByAccessKey.create();
|
||||||
|
sc.setParameters("AccessKey", cloudAccessKey);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}finally {
|
||||||
|
txn.commit();
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserCredentialsVO getByCertUniqueId( String certId ) {
|
||||||
|
SearchBuilder<UserCredentialsVO> SearchByCertID = createSearchBuilder();
|
||||||
|
SearchByCertID.and("CertUniqueId", SearchByCertID.entity().getCertUniqueId(), SearchCriteria.Op.EQ);
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
try {
|
||||||
|
txn.start();
|
||||||
|
SearchCriteria<UserCredentialsVO> sc = SearchByCertID.create();
|
||||||
|
sc.setParameters("CertUniqueId", certId);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}finally {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -27,12 +27,18 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
|
||||||
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
|
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
import com.cloud.bridge.persist.dao.CloudStackConfigurationDaoImpl;
|
||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
import com.cloud.bridge.util.ConfigurationHelper;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.component.Inject;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
|
@DB
|
||||||
public class EC2MainServlet extends HttpServlet{
|
public class EC2MainServlet extends HttpServlet{
|
||||||
|
|
||||||
private static final long serialVersionUID = 2201599478145974479L;
|
private static final long serialVersionUID = 2201599478145974479L;
|
||||||
@ -41,23 +47,23 @@ public class EC2MainServlet extends HttpServlet{
|
|||||||
public static final String EC2_SOAP_SERVLET_PATH="/services/AmazonEC2/";
|
public static final String EC2_SOAP_SERVLET_PATH="/services/AmazonEC2/";
|
||||||
public static final String ENABLE_EC2_API="enable.ec2.api";
|
public static final String ENABLE_EC2_API="enable.ec2.api";
|
||||||
private static boolean isEC2APIEnabled = false;
|
private static boolean isEC2APIEnabled = false;
|
||||||
|
public static final Logger logger = Logger.getLogger(EC2MainServlet.class);
|
||||||
|
CloudStackConfigurationDao csDao = ComponentLocator.inject(CloudStackConfigurationDaoImpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We build the path to where the keystore holding the WS-Security X509 certificates
|
* We build the path to where the keystore holding the WS-Security X509 certificates
|
||||||
* are stored.
|
* are stored.
|
||||||
*/
|
*/
|
||||||
|
@DB
|
||||||
public void init( ServletConfig config ) throws ServletException {
|
public void init( ServletConfig config ) throws ServletException {
|
||||||
try{
|
try{
|
||||||
ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
|
ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
|
||||||
UserCredentialsDao.preCheckTableExistence();
|
|
||||||
// check if API is enabled
|
// check if API is enabled
|
||||||
CloudStackConfigurationDao csDao = new CloudStackConfigurationDao();
|
|
||||||
String value = csDao.getConfigValue(ENABLE_EC2_API);
|
String value = csDao.getConfigValue(ENABLE_EC2_API);
|
||||||
if(value != null){
|
if(value != null){
|
||||||
isEC2APIEnabled = Boolean.valueOf(value);
|
isEC2APIEnabled = Boolean.valueOf(value);
|
||||||
}
|
}
|
||||||
PersistContext.commitTransaction(true);
|
logger.info("Value of EC2 API Flag ::" + value);
|
||||||
PersistContext.closeSession(true);
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new ServletException("Error initializing awsapi: " + e.getMessage());
|
throw new ServletException("Error initializing awsapi: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,10 +94,9 @@ import com.amazon.ec2.RunInstancesResponse;
|
|||||||
import com.amazon.ec2.StartInstancesResponse;
|
import com.amazon.ec2.StartInstancesResponse;
|
||||||
import com.amazon.ec2.StopInstancesResponse;
|
import com.amazon.ec2.StopInstancesResponse;
|
||||||
import com.amazon.ec2.TerminateInstancesResponse;
|
import com.amazon.ec2.TerminateInstancesResponse;
|
||||||
import com.cloud.bridge.model.UserCredentials;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
import com.cloud.bridge.persist.dao.OfferingDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.OfferingDao;
|
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
|
||||||
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
||||||
import com.cloud.bridge.service.core.ec2.EC2AssociateAddress;
|
import com.cloud.bridge.service.core.ec2.EC2AssociateAddress;
|
||||||
import com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup;
|
import com.cloud.bridge.service.core.ec2.EC2AuthorizeRevokeSecurityGroup;
|
||||||
@ -140,11 +139,15 @@ import com.cloud.bridge.util.AuthenticationUtils;
|
|||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
import com.cloud.bridge.util.ConfigurationHelper;
|
||||||
import com.cloud.bridge.util.EC2RestAuth;
|
import com.cloud.bridge.util.EC2RestAuth;
|
||||||
import com.cloud.stack.models.CloudStackAccount;
|
import com.cloud.stack.models.CloudStackAccount;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
|
||||||
public class EC2RestServlet extends HttpServlet {
|
public class EC2RestServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6168996266762804888L;
|
private static final long serialVersionUID = -6168996266762804888L;
|
||||||
|
protected final UserCredentialsDaoImpl ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
|
||||||
|
protected final OfferingDaoImpl ofDao = ComponentLocator.inject(OfferingDaoImpl.class);
|
||||||
|
|
||||||
public static final Logger logger = Logger.getLogger(EC2RestServlet.class);
|
public static final Logger logger = Logger.getLogger(EC2RestServlet.class);
|
||||||
|
|
||||||
@ -278,8 +281,6 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
logger.error("Unsupported action " + action);
|
logger.error("Unsupported action " + action);
|
||||||
throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
|
throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
|
||||||
}
|
}
|
||||||
PersistContext.commitTransaction();
|
|
||||||
PersistContext.commitTransaction(true);
|
|
||||||
|
|
||||||
} catch( EC2ServiceException e ) {
|
} catch( EC2ServiceException e ) {
|
||||||
response.setStatus(e.getErrorCode());
|
response.setStatus(e.getErrorCode());
|
||||||
@ -306,8 +307,6 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
PersistContext.closeSession();
|
|
||||||
PersistContext.closeSession(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +342,7 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
private void setUserKeys( HttpServletRequest request, HttpServletResponse response ) {
|
private void setUserKeys( HttpServletRequest request, HttpServletResponse response ) {
|
||||||
String[] accessKey = null;
|
String[] accessKey = null;
|
||||||
String[] secretKey = null;
|
String[] secretKey = null;
|
||||||
|
Transaction txn = null;
|
||||||
try {
|
try {
|
||||||
// -> all these parameters are required
|
// -> all these parameters are required
|
||||||
accessKey = request.getParameterValues( "accesskey" );
|
accessKey = request.getParameterValues( "accesskey" );
|
||||||
@ -369,15 +368,20 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
UserContext context = UserContext.current();
|
UserContext context = UserContext.current();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
// -> use the keys to see if the account actually exists
|
// -> use the keys to see if the account actually exists
|
||||||
ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
|
ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
/* UserCredentialsDao credentialDao = new UserCredentialsDao();
|
||||||
credentialDao.setUserKeys( accessKey[0], secretKey[0] );
|
credentialDao.setUserKeys( );
|
||||||
|
*/ UserCredentialsVO user = new UserCredentialsVO(accessKey[0], secretKey[0]);
|
||||||
|
ucDao.persist(user);
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
logger.error("SetUserKeys " + e.getMessage(), e);
|
logger.error("SetUserKeys " + e.getMessage(), e);
|
||||||
response.setStatus(401);
|
response.setStatus(401);
|
||||||
endResponse(response, e.toString());
|
endResponse(response, e.toString());
|
||||||
|
txn.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response.setStatus(200);
|
response.setStatus(200);
|
||||||
@ -402,6 +406,7 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
*/
|
*/
|
||||||
private void setCertificate( HttpServletRequest request, HttpServletResponse response )
|
private void setCertificate( HttpServletRequest request, HttpServletResponse response )
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
Transaction txn = null;
|
||||||
try {
|
try {
|
||||||
// [A] Pull the cert and cloud AccessKey from the request
|
// [A] Pull the cert and cloud AccessKey from the request
|
||||||
String[] certificate = request.getParameterValues( "cert" );
|
String[] certificate = request.getParameterValues( "cert" );
|
||||||
@ -437,10 +442,16 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
// [C] Associate the cert's uniqueId with the Cloud API keys
|
// [C] Associate the cert's uniqueId with the Cloud API keys
|
||||||
String uniqueId = AuthenticationUtils.X509CertUniqueId( userCert );
|
String uniqueId = AuthenticationUtils.X509CertUniqueId( userCert );
|
||||||
logger.debug( "SetCertificate, uniqueId: " + uniqueId );
|
logger.debug( "SetCertificate, uniqueId: " + uniqueId );
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
/* UserCredentialsDao credentialDao = new UserCredentialsDao();
|
||||||
credentialDao.setCertificateId( accessKey[0], uniqueId );
|
credentialDao.setCertificateId( accessKey[0], uniqueId );
|
||||||
response.setStatus(200);
|
*/
|
||||||
|
txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
|
||||||
|
user.setCertUniqueId(uniqueId);
|
||||||
|
ucDao.update(user.getId(), user);
|
||||||
|
response.setStatus(200);
|
||||||
endResponse(response, "User certificate set successfully");
|
endResponse(response, "User certificate set successfully");
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
} catch( NoSuchObjectException e ) {
|
} catch( NoSuchObjectException e ) {
|
||||||
logger.error("SetCertificate exception " + e.getMessage(), e);
|
logger.error("SetCertificate exception " + e.getMessage(), e);
|
||||||
@ -449,7 +460,10 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
logger.error("SetCertificate exception " + e.getMessage(), e);
|
logger.error("SetCertificate exception " + e.getMessage(), e);
|
||||||
response.sendError(500, "SetCertificate exception " + e.getMessage());
|
response.sendError(500, "SetCertificate exception " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -464,7 +478,8 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
* algorithm.
|
* algorithm.
|
||||||
*/
|
*/
|
||||||
private void deleteCertificate( HttpServletRequest request, HttpServletResponse response )
|
private void deleteCertificate( HttpServletRequest request, HttpServletResponse response )
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
Transaction txn = null;
|
||||||
try {
|
try {
|
||||||
String [] accessKey = request.getParameterValues( "AWSAccessKeyId" );
|
String [] accessKey = request.getParameterValues( "AWSAccessKeyId" );
|
||||||
if ( null == accessKey || 0 == accessKey.length ) {
|
if ( null == accessKey || 0 == accessKey.length ) {
|
||||||
@ -483,10 +498,16 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
certStore.store( fsOut, keystorePassword.toCharArray());
|
certStore.store( fsOut, keystorePassword.toCharArray());
|
||||||
|
|
||||||
// -> dis-associate the cert's uniqueId with the Cloud API keys
|
// -> dis-associate the cert's uniqueId with the Cloud API keys
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
/* UserCredentialsDao credentialDao = new UserCredentialsDao();
|
||||||
credentialDao.setCertificateId( accessKey[0], null );
|
credentialDao.setCertificateId( accessKey[0], null );
|
||||||
|
|
||||||
|
*/ txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
|
||||||
|
user.setCertUniqueId(null);
|
||||||
|
ucDao.update(user.getId(), user);
|
||||||
response.setStatus(200);
|
response.setStatus(200);
|
||||||
endResponse(response, "User certificate deleted successfully");
|
endResponse(response, "User certificate deleted successfully");
|
||||||
|
txn.commit();
|
||||||
}
|
}
|
||||||
else response.setStatus(404);
|
else response.setStatus(404);
|
||||||
|
|
||||||
@ -497,6 +518,8 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
logger.error("DeleteCertificate exception " + e.getMessage(), e);
|
logger.error("DeleteCertificate exception " + e.getMessage(), e);
|
||||||
response.sendError(500, "DeleteCertificate exception " + e.getMessage());
|
response.sendError(500, "DeleteCertificate exception " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
txn.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +570,7 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OfferingDao ofDao = new OfferingDao();
|
|
||||||
ofDao.setOfferMapping( amazonOffer, cloudOffer );
|
ofDao.setOfferMapping( amazonOffer, cloudOffer );
|
||||||
|
|
||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
@ -596,9 +619,7 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OfferingDao ofDao = new OfferingDao();
|
|
||||||
ofDao.deleteOfferMapping( amazonOffer );
|
ofDao.deleteOfferMapping( amazonOffer );
|
||||||
|
|
||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
logger.error("DeleteOfferMapping " + e.getMessage(), e);
|
logger.error("DeleteOfferMapping " + e.getMessage(), e);
|
||||||
response.setStatus(401);
|
response.setStatus(401);
|
||||||
@ -1695,8 +1716,8 @@ public class EC2RestServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// [B] Use the cloudAccessKey to get the users secret key in the db
|
// [B] Use the cloudAccessKey to get the users secret key in the db
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
UserCredentialsVO cloudKeys = ucDao.getByAccessKey( cloudAccessKey );
|
||||||
UserCredentials cloudKeys = credentialDao.getByAccessKey( cloudAccessKey );
|
|
||||||
if ( null == cloudKeys )
|
if ( null == cloudKeys )
|
||||||
{
|
{
|
||||||
logger.debug( cloudAccessKey + " is not defined in the EC2 service - call SetUserKeys" );
|
logger.debug( cloudAccessKey + " is not defined in the EC2 service - call SetUserKeys" );
|
||||||
|
|||||||
@ -43,9 +43,12 @@ import org.w3c.dom.NodeList;
|
|||||||
|
|
||||||
import com.cloud.bridge.io.MultiPartDimeInputStream;
|
import com.cloud.bridge.io.MultiPartDimeInputStream;
|
||||||
import com.cloud.bridge.model.SAcl;
|
import com.cloud.bridge.model.SAcl;
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
|
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
|
||||||
|
import com.cloud.bridge.persist.dao.CloudStackConfigurationDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
||||||
|
|
||||||
|
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
|
||||||
import com.cloud.bridge.service.controller.s3.S3BucketAction;
|
import com.cloud.bridge.service.controller.s3.S3BucketAction;
|
||||||
import com.cloud.bridge.service.controller.s3.S3ObjectAction;
|
import com.cloud.bridge.service.controller.s3.S3ObjectAction;
|
||||||
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
||||||
@ -57,26 +60,29 @@ import com.cloud.bridge.service.core.s3.S3Grant;
|
|||||||
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
||||||
import com.cloud.bridge.service.core.s3.S3PutObjectRequest;
|
import com.cloud.bridge.service.core.s3.S3PutObjectRequest;
|
||||||
import com.cloud.bridge.service.core.s3.S3PutObjectResponse;
|
import com.cloud.bridge.service.core.s3.S3PutObjectResponse;
|
||||||
import com.cloud.bridge.service.exception.InternalErrorException;
|
|
||||||
import com.cloud.bridge.service.exception.InvalidBucketName;
|
import com.cloud.bridge.service.exception.InvalidBucketName;
|
||||||
import com.cloud.bridge.service.exception.NoSuchObjectException;
|
|
||||||
import com.cloud.bridge.service.exception.PermissionDeniedException;
|
import com.cloud.bridge.service.exception.PermissionDeniedException;
|
||||||
import com.cloud.bridge.util.AuthenticationUtils;
|
|
||||||
import com.cloud.bridge.util.ConfigurationHelper;
|
import com.cloud.bridge.util.ConfigurationHelper;
|
||||||
import com.cloud.bridge.util.HeaderParam;
|
import com.cloud.bridge.util.HeaderParam;
|
||||||
import com.cloud.bridge.util.RestAuth;
|
import com.cloud.bridge.util.RestAuth;
|
||||||
import com.cloud.bridge.util.S3SoapAuth;
|
import com.cloud.bridge.util.S3SoapAuth;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
public class S3RestServlet extends HttpServlet {
|
public class S3RestServlet extends HttpServlet {
|
||||||
private static final long serialVersionUID = -6168996266762804877L;
|
private static final long serialVersionUID = -6168996266762804877L;
|
||||||
public static final String ENABLE_S3_API="enable.s3.api";
|
public static final String ENABLE_S3_API="enable.s3.api";
|
||||||
private static boolean isS3APIEnabled = false;
|
private static boolean isS3APIEnabled = false;
|
||||||
|
|
||||||
public static final Logger logger = Logger.getLogger(S3RestServlet.class);
|
public static final Logger logger = Logger.getLogger(S3RestServlet.class);
|
||||||
|
protected final CloudStackConfigurationDao csDao = ComponentLocator.inject(CloudStackConfigurationDaoImpl.class);
|
||||||
|
protected final UserCredentialsDao ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
processRequest( req, resp, "GET" );
|
processRequest( req, resp, "GET" );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||||
{
|
{
|
||||||
@ -106,15 +112,13 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
public void init( ServletConfig config ) throws ServletException {
|
public void init( ServletConfig config ) throws ServletException {
|
||||||
try{
|
try{
|
||||||
ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
|
ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
|
||||||
UserCredentialsDao.preCheckTableExistence();
|
|
||||||
// check if API is enabled
|
// check if API is enabled
|
||||||
CloudStackConfigurationDao csDao = new CloudStackConfigurationDao();
|
|
||||||
String value = csDao.getConfigValue(ENABLE_S3_API);
|
String value = csDao.getConfigValue(ENABLE_S3_API);
|
||||||
if(value != null) {
|
if(value != null) {
|
||||||
isS3APIEnabled = Boolean.valueOf(value);
|
isS3APIEnabled = Boolean.valueOf(value);
|
||||||
}
|
}
|
||||||
PersistContext.commitTransaction(true);
|
logger.info("S3Engine :: Configuration value is : " + value);
|
||||||
PersistContext.closeSession(true);
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new ServletException("Error initializing awsapi: " + e.getMessage());
|
throw new ServletException("Error initializing awsapi: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -130,6 +134,7 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
*/
|
*/
|
||||||
private void processRequest( HttpServletRequest request, HttpServletResponse response, String method )
|
private void processRequest( HttpServletRequest request, HttpServletResponse response, String method )
|
||||||
{
|
{
|
||||||
|
Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
|
||||||
try {
|
try {
|
||||||
logRequest(request);
|
logRequest(request);
|
||||||
|
|
||||||
@ -164,12 +169,13 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
txn.start();
|
||||||
// -> authenticated calls
|
// -> authenticated calls
|
||||||
if ( !((method.equalsIgnoreCase( "POST" ) && !(request.getQueryString().equalsIgnoreCase("delete"))) ) ){
|
if ( !((method.equalsIgnoreCase( "POST" ) && !(request.getQueryString().equalsIgnoreCase("delete"))) ) ){
|
||||||
S3AuthParams params = extractRequestHeaders( request );
|
S3AuthParams params = extractRequestHeaders( request );
|
||||||
authenticateRequest( request, params );
|
authenticateRequest( request, params );
|
||||||
}
|
}
|
||||||
|
|
||||||
ServletAction action = routeRequest(request);
|
ServletAction action = routeRequest(request);
|
||||||
if ( action != null ) {
|
if ( action != null ) {
|
||||||
action.execute(request, response);
|
action.execute(request, response);
|
||||||
@ -178,35 +184,30 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
response.setStatus(404);
|
response.setStatus(404);
|
||||||
endResponse(response, "File not found");
|
endResponse(response, "File not found");
|
||||||
}
|
}
|
||||||
|
txn.close();
|
||||||
PersistContext.commitTransaction();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( InvalidBucketName e) {
|
catch( InvalidBucketName e) {
|
||||||
PersistContext.rollbackTransaction();
|
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
response.setStatus(400);
|
response.setStatus(400);
|
||||||
endResponse(response, "Invalid Bucket Name - " + e.toString());
|
endResponse(response, "Invalid Bucket Name - " + e.toString());
|
||||||
}
|
}
|
||||||
catch(PermissionDeniedException e) {
|
catch(PermissionDeniedException e) {
|
||||||
PersistContext.rollbackTransaction();
|
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
response.setStatus(403);
|
response.setStatus(403);
|
||||||
endResponse(response, "Access denied - " + e.toString());
|
endResponse(response, "Access denied - " + e.toString());
|
||||||
}
|
}
|
||||||
catch(Throwable e) {
|
catch(Throwable e) {
|
||||||
PersistContext.rollbackTransaction();
|
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
response.setStatus(404);
|
response.setStatus(404);
|
||||||
endResponse(response, "Bad request");
|
endResponse(response, "Bad request");
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
PersistContext.closeSession();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +240,7 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
*
|
*
|
||||||
* As with all REST calls HTTPS should be used to ensure their security.
|
* As with all REST calls HTTPS should be used to ensure their security.
|
||||||
*/
|
*/
|
||||||
|
@DB
|
||||||
private void setUserKeys( HttpServletRequest request, HttpServletResponse response ) {
|
private void setUserKeys( HttpServletRequest request, HttpServletResponse response ) {
|
||||||
String[] accessKey = null;
|
String[] accessKey = null;
|
||||||
String[] secretKey = null;
|
String[] secretKey = null;
|
||||||
@ -266,8 +268,14 @@ public class S3RestServlet extends HttpServlet {
|
|||||||
try {
|
try {
|
||||||
// -> use the keys to see if the account actually exists
|
// -> use the keys to see if the account actually exists
|
||||||
//ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
|
//ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
//UserCredentialsDaoImpl credentialDao = new UserCredentialsDao();
|
||||||
credentialDao.setUserKeys( accessKey[0], secretKey[0] );
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
txn.start();
|
||||||
|
UserCredentialsVO user = new UserCredentialsVO(accessKey[0], secretKey[0]);
|
||||||
|
user = ucDao.persist(user);
|
||||||
|
txn.commit();
|
||||||
|
txn.close();
|
||||||
|
//credentialDao.setUserKeys( accessKey[0], secretKey[0] );
|
||||||
|
|
||||||
} catch( Exception e ) {
|
} catch( Exception e ) {
|
||||||
logger.error("SetUserKeys " + e.getMessage(), e);
|
logger.error("SetUserKeys " + e.getMessage(), e);
|
||||||
@ -586,7 +594,6 @@ private S3ObjectAction routePlainPostRequest (HttpServletRequest request)
|
|||||||
xml.append( "</soap:Body></soap:Envelope>" );
|
xml.append( "</soap:Body></soap:Envelope>" );
|
||||||
|
|
||||||
endResponse(response, xml.toString());
|
endResponse(response, xml.toString());
|
||||||
PersistContext.commitTransaction();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,7 +612,6 @@ private S3ObjectAction routePlainPostRequest (HttpServletRequest request)
|
|||||||
xml.append( "</soap:Body></soap:Envelope>" );
|
xml.append( "</soap:Body></soap:Envelope>" );
|
||||||
|
|
||||||
endResponse(response, xml.toString());
|
endResponse(response, xml.toString());
|
||||||
PersistContext.commitTransaction();
|
|
||||||
}
|
}
|
||||||
catch(PermissionDeniedException e) {
|
catch(PermissionDeniedException e) {
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
@ -618,7 +624,6 @@ private S3ObjectAction routePlainPostRequest (HttpServletRequest request)
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
PersistContext.closeSession();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,14 +49,18 @@ import com.amazon.s3.GetBucketAccessControlPolicyResponse;
|
|||||||
import com.amazon.s3.ListAllMyBucketsResponse;
|
import com.amazon.s3.ListAllMyBucketsResponse;
|
||||||
import com.amazon.s3.ListBucketResponse;
|
import com.amazon.s3.ListBucketResponse;
|
||||||
import com.cloud.bridge.io.MTOMAwareResultStreamWriter;
|
import com.cloud.bridge.io.MTOMAwareResultStreamWriter;
|
||||||
|
import com.cloud.bridge.model.BucketPolicyVO;
|
||||||
import com.cloud.bridge.model.SAcl;
|
import com.cloud.bridge.model.SAcl;
|
||||||
|
import com.cloud.bridge.model.SAclVO;
|
||||||
import com.cloud.bridge.model.SBucket;
|
import com.cloud.bridge.model.SBucket;
|
||||||
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
import com.cloud.bridge.model.SHost;
|
import com.cloud.bridge.model.SHost;
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
|
||||||
import com.cloud.bridge.persist.dao.BucketPolicyDao;
|
import com.cloud.bridge.persist.dao.BucketPolicyDao;
|
||||||
|
import com.cloud.bridge.persist.dao.BucketPolicyDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.MultipartLoadDao;
|
import com.cloud.bridge.persist.dao.MultipartLoadDao;
|
||||||
import com.cloud.bridge.persist.dao.SAclDao;
|
import com.cloud.bridge.persist.dao.SAclDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.SBucketDao;
|
import com.cloud.bridge.persist.dao.SBucketDao;
|
||||||
|
import com.cloud.bridge.persist.dao.SBucketDaoImpl;
|
||||||
import com.cloud.bridge.service.S3Constants;
|
import com.cloud.bridge.service.S3Constants;
|
||||||
import com.cloud.bridge.service.S3RestServlet;
|
import com.cloud.bridge.service.S3RestServlet;
|
||||||
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
import com.cloud.bridge.service.controller.s3.ServiceProvider;
|
||||||
@ -81,16 +85,13 @@ import com.cloud.bridge.service.core.s3.S3ListAllMyBucketsResponse;
|
|||||||
import com.cloud.bridge.service.core.s3.S3ListBucketObjectEntry;
|
import com.cloud.bridge.service.core.s3.S3ListBucketObjectEntry;
|
||||||
import com.cloud.bridge.service.core.s3.S3ListBucketRequest;
|
import com.cloud.bridge.service.core.s3.S3ListBucketRequest;
|
||||||
import com.cloud.bridge.service.core.s3.S3ListBucketResponse;
|
import com.cloud.bridge.service.core.s3.S3ListBucketResponse;
|
||||||
import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
|
|
||||||
import com.cloud.bridge.service.core.s3.S3MultipartUpload;
|
import com.cloud.bridge.service.core.s3.S3MultipartUpload;
|
||||||
import com.cloud.bridge.service.core.s3.S3PolicyContext;
|
import com.cloud.bridge.service.core.s3.S3PolicyContext;
|
||||||
import com.cloud.bridge.service.core.s3.S3PutObjectRequest;
|
|
||||||
import com.cloud.bridge.service.core.s3.S3Response;
|
import com.cloud.bridge.service.core.s3.S3Response;
|
||||||
import com.cloud.bridge.service.core.s3.S3SetBucketAccessControlPolicyRequest;
|
import com.cloud.bridge.service.core.s3.S3SetBucketAccessControlPolicyRequest;
|
||||||
import com.cloud.bridge.service.core.s3.S3BucketPolicy.PolicyAccess;
|
import com.cloud.bridge.service.core.s3.S3BucketPolicy.PolicyAccess;
|
||||||
import com.cloud.bridge.service.core.s3.S3PolicyAction.PolicyActions;
|
import com.cloud.bridge.service.core.s3.S3PolicyAction.PolicyActions;
|
||||||
import com.cloud.bridge.service.core.s3.S3PolicyCondition.ConditionKeys;
|
import com.cloud.bridge.service.core.s3.S3PolicyCondition.ConditionKeys;
|
||||||
import com.cloud.bridge.service.exception.InternalErrorException;
|
|
||||||
import com.cloud.bridge.service.exception.InvalidBucketName;
|
import com.cloud.bridge.service.exception.InvalidBucketName;
|
||||||
import com.cloud.bridge.service.exception.InvalidRequestContentException;
|
import com.cloud.bridge.service.exception.InvalidRequestContentException;
|
||||||
import com.cloud.bridge.service.exception.NetworkIOException;
|
import com.cloud.bridge.service.exception.NetworkIOException;
|
||||||
@ -108,10 +109,14 @@ import com.cloud.bridge.util.Triple;
|
|||||||
import com.cloud.bridge.util.XSerializer;
|
import com.cloud.bridge.util.XSerializer;
|
||||||
import com.cloud.bridge.util.XSerializerXmlAdapter;
|
import com.cloud.bridge.util.XSerializerXmlAdapter;
|
||||||
import com.cloud.bridge.util.XmlHelper;
|
import com.cloud.bridge.util.XmlHelper;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
|
||||||
public class S3BucketAction implements ServletAction {
|
public class S3BucketAction implements ServletAction {
|
||||||
protected final static Logger logger = Logger.getLogger(S3BucketAction.class);
|
protected final static Logger logger = Logger.getLogger(S3BucketAction.class);
|
||||||
|
protected final BucketPolicyDao bPolicyDao = ComponentLocator.inject(BucketPolicyDaoImpl.class);
|
||||||
|
protected final SBucketDao bucketDao = ComponentLocator.inject(SBucketDaoImpl.class);
|
||||||
|
|
||||||
private DocumentBuilderFactory dbf = null;
|
private DocumentBuilderFactory dbf = null;
|
||||||
public S3BucketAction() {
|
public S3BucketAction() {
|
||||||
@ -347,18 +352,16 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
String policy = streamToString( request.getInputStream());
|
String policy = streamToString( request.getInputStream());
|
||||||
|
|
||||||
// [A] Is there an owner of an existing policy or bucket?
|
// [A] Is there an owner of an existing policy or bucket?
|
||||||
BucketPolicyDao policyDao = new BucketPolicyDao();
|
SBucketVO bucket = bucketDao.getByName( bucketName );
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
|
||||||
SBucket bucket = bucketDao.getByName( bucketName );
|
|
||||||
String owner = null;
|
String owner = null;
|
||||||
|
|
||||||
if ( null != bucket )
|
if ( null != bucket )
|
||||||
{
|
{
|
||||||
owner = bucket.getOwnerCanonicalId();
|
owner = bucket.getOwnerCanonicalId();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ try {
|
{ try {
|
||||||
owner = policyDao.getPolicyOwner( bucketName );
|
owner = bPolicyDao.getByName(bucketName).getOwnerCanonicalID();
|
||||||
}
|
}
|
||||||
catch( Exception e ) {}
|
catch( Exception e ) {}
|
||||||
}
|
}
|
||||||
@ -366,36 +369,42 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
|
|
||||||
// [B] "The bucket owner by default has permissions to attach bucket policies to their buckets using PUT Bucket policy."
|
// [B] "The bucket owner by default has permissions to attach bucket policies to their buckets using PUT Bucket policy."
|
||||||
// -> the bucket owner may want to restrict the IP address from where this can be executed
|
// -> the bucket owner may want to restrict the IP address from where this can be executed
|
||||||
String client = UserContext.current().getCanonicalUserId();
|
String client = UserContext.current().getCanonicalUserId();
|
||||||
S3PolicyContext context = new S3PolicyContext( PolicyActions.PutBucketPolicy, bucketName );
|
S3PolicyContext context = new S3PolicyContext(
|
||||||
switch( S3Engine.verifyPolicy( context )) {
|
PolicyActions.PutBucketPolicy, bucketName);
|
||||||
case ALLOW:
|
|
||||||
break;
|
switch (S3Engine.verifyPolicy(context)) {
|
||||||
|
case ALLOW:
|
||||||
case DEFAULT_DENY:
|
break;
|
||||||
if (null != owner && !client.equals( owner )) {
|
|
||||||
response.setStatus(405);
|
case DEFAULT_DENY:
|
||||||
return;
|
if (null != owner && !client.equals(owner)) {
|
||||||
}
|
response.setStatus(405);
|
||||||
break;
|
return;
|
||||||
|
}
|
||||||
case DENY:
|
break;
|
||||||
response.setStatus(403);
|
case DENY:
|
||||||
return;
|
response.setStatus(403);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
// [B] Place the policy into the database over writting an existing policy
|
// [B] Place the policy into the database over writting an existing policy
|
||||||
try {
|
try {
|
||||||
// -> first make sure that the policy is valid by parsing it
|
// -> first make sure that the policy is valid by parsing it
|
||||||
PolicyParser parser = new PolicyParser();
|
PolicyParser parser = new PolicyParser();
|
||||||
S3BucketPolicy sbp = parser.parse( policy, bucketName );
|
S3BucketPolicy sbp = parser.parse( policy, bucketName );
|
||||||
|
bPolicyDao.deletePolicy(bucketName);
|
||||||
policyDao.deletePolicy( bucketName );
|
|
||||||
if (null != policy && !policy.isEmpty()) policyDao.addPolicy( bucketName, client, policy );
|
if (null != policy && !policy.isEmpty()) {
|
||||||
|
BucketPolicyVO bpolicy = new BucketPolicyVO(bucketName, client, policy);
|
||||||
|
bpolicy = bPolicyDao.persist(bpolicy);
|
||||||
|
//policyDao.addPolicy( bucketName, client, policy );
|
||||||
|
}
|
||||||
|
|
||||||
if (null != sbp) ServiceProvider.getInstance().setBucketPolicy( bucketName, sbp );
|
if (null != sbp) ServiceProvider.getInstance().setBucketPolicy( bucketName, sbp );
|
||||||
response.setStatus(200);
|
response.setStatus(200);
|
||||||
|
txn.commit();
|
||||||
|
txn.close();
|
||||||
}
|
}
|
||||||
catch( PermissionDeniedException e ) {
|
catch( PermissionDeniedException e ) {
|
||||||
logger.error("Put Bucket Policy failed due to " + e.getMessage(), e);
|
logger.error("Put Bucket Policy failed due to " + e.getMessage(), e);
|
||||||
@ -416,185 +425,193 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
|
|
||||||
// [A] Is there an owner of an existing policy or bucket?
|
// [A] Is there an owner of an existing policy or bucket?
|
||||||
BucketPolicyDao policyDao = new BucketPolicyDao();
|
SBucketVO bucket = bucketDao.getByName(bucketName);
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
String owner = null;
|
||||||
SBucket bucket = bucketDao.getByName( bucketName );
|
|
||||||
String owner = null;
|
|
||||||
|
|
||||||
if ( null != bucket )
|
|
||||||
{
|
|
||||||
owner = bucket.getOwnerCanonicalId();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ try {
|
|
||||||
owner = policyDao.getPolicyOwner( bucketName );
|
|
||||||
}
|
|
||||||
catch( Exception e ) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (null != bucket) {
|
||||||
// [B] "The bucket owner by default has permissions to retrieve bucket policies using GET Bucket policy."
|
owner = bucket.getOwnerCanonicalId();
|
||||||
// -> the bucket owner may want to restrict the IP address from where this can be executed
|
} else {
|
||||||
String client = UserContext.current().getCanonicalUserId();
|
try {
|
||||||
S3PolicyContext context = new S3PolicyContext( PolicyActions.GetBucketPolicy, bucketName );
|
owner = bPolicyDao.getByName(bucketName).getOwnerCanonicalID();
|
||||||
switch( S3Engine.verifyPolicy( context )) {
|
} catch (Exception e) {
|
||||||
case ALLOW:
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case DEFAULT_DENY:
|
|
||||||
if (null != owner && !client.equals( owner )) {
|
|
||||||
response.setStatus(405);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DENY:
|
|
||||||
response.setStatus(403);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// [B] Pull the policy from the database if one exists
|
|
||||||
try {
|
|
||||||
String policy = policyDao.getPolicy( bucketName );
|
|
||||||
if ( null == policy ) {
|
|
||||||
response.setStatus(404);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
response.setStatus(200);
|
|
||||||
response.setContentType("application/json");
|
|
||||||
S3RestServlet.endResponse(response, policy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( Exception e ) {
|
|
||||||
logger.error("Get Bucket Policy failed due to " + e.getMessage(), e);
|
|
||||||
response.setStatus(500);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeDeleteBucketPolicy(HttpServletRequest request, HttpServletResponse response)
|
// [B]
|
||||||
{
|
// "The bucket owner by default has permissions to retrieve bucket policies using GET Bucket policy."
|
||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
// -> the bucket owner may want to restrict the IP address from where
|
||||||
|
// this can be executed
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
String client = UserContext.current().getCanonicalUserId();
|
||||||
SBucket bucket = bucketDao.getByName( bucketName );
|
S3PolicyContext context = new S3PolicyContext(
|
||||||
if (bucket != null)
|
PolicyActions.GetBucketPolicy, bucketName);
|
||||||
{
|
switch (S3Engine.verifyPolicy(context)) {
|
||||||
String client = UserContext.current().getCanonicalUserId();
|
case ALLOW:
|
||||||
if (!client.equals( bucket.getOwnerCanonicalId())) {
|
break;
|
||||||
response.setStatus(405);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
case DEFAULT_DENY:
|
||||||
BucketPolicyDao policyDao = new BucketPolicyDao();
|
if (null != owner && !client.equals(owner)) {
|
||||||
String policy = policyDao.getPolicy( bucketName );
|
response.setStatus(405);
|
||||||
if ( null == policy ) {
|
return;
|
||||||
response.setStatus(204);
|
}
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
ServiceProvider.getInstance().deleteBucketPolicy( bucketName );
|
case DENY:
|
||||||
policyDao.deletePolicy( bucketName );
|
response.setStatus(403);
|
||||||
response.setStatus(200);
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( Exception e ) {
|
|
||||||
logger.error("Delete Bucket Policy failed due to " + e.getMessage(), e);
|
|
||||||
response.setStatus(500);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeGetAllBuckets(HttpServletRequest request, HttpServletResponse response)
|
// [B] Pull the policy from the database if one exists
|
||||||
throws IOException, XMLStreamException
|
try {
|
||||||
{
|
String policy = bPolicyDao.getByName(bucketName).getPolicy();
|
||||||
Calendar cal = Calendar.getInstance();
|
if (null == policy) {
|
||||||
cal.set( 1970, 1, 1 );
|
response.setStatus(404);
|
||||||
S3ListAllMyBucketsRequest engineRequest = new S3ListAllMyBucketsRequest();
|
} else {
|
||||||
engineRequest.setAccessKey(UserContext.current().getAccessKey());
|
response.setStatus(200);
|
||||||
engineRequest.setRequestTimestamp( cal );
|
response.setContentType("application/json");
|
||||||
engineRequest.setSignature( "" );
|
S3RestServlet.endResponse(response, policy);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Get Bucket Policy failed due to " + e.getMessage(), e);
|
||||||
|
response.setStatus(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeDeleteBucketPolicy(HttpServletRequest request,
|
||||||
|
HttpServletResponse response) {
|
||||||
|
String bucketName = (String) request
|
||||||
|
.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
|
|
||||||
S3ListAllMyBucketsResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest(engineRequest);
|
SBucketVO bucket = bucketDao.getByName(bucketName);
|
||||||
|
if (bucket != null) {
|
||||||
// To allow the all buckets list to be serialized via Axiom classes
|
String client = UserContext.current().getCanonicalUserId();
|
||||||
ListAllMyBucketsResponse allBuckets = S3SerializableServiceImplementation.toListAllMyBucketsResponse( engineResponse );
|
if (!client.equals(bucket.getOwnerCanonicalId())) {
|
||||||
|
response.setStatus(405);
|
||||||
OutputStream outputStream = response.getOutputStream();
|
return;
|
||||||
response.setStatus(200);
|
}
|
||||||
response.setContentType("application/xml");
|
}
|
||||||
// The content-type literally should be "application/xml; charset=UTF-8"
|
|
||||||
// but any compliant JVM supplies utf-8 by default
|
try {
|
||||||
|
|
||||||
// MTOMAwareResultStreamWriter resultWriter = new MTOMAwareResultStreamWriter ("ListAllMyBucketsResult", outputStream );
|
String policy = bPolicyDao.getByName(bucketName).getPolicy();
|
||||||
// resultWriter.startWrite();
|
if (null == policy) {
|
||||||
// resultWriter.writeout(allBuckets);
|
response.setStatus(204);
|
||||||
// resultWriter.stopWrite();
|
} else {
|
||||||
StringBuffer xml = new StringBuffer();
|
ServiceProvider.getInstance().deleteBucketPolicy(bucketName);
|
||||||
xml.append( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" );
|
bPolicyDao.deletePolicy(bucketName);
|
||||||
xml.append("<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");
|
response.setStatus(200);
|
||||||
xml.append("<Owner><ID>");
|
}
|
||||||
xml.append(engineResponse.getOwner().getID()).append("</ID>");
|
} catch (Exception e) {
|
||||||
xml.append("<DisplayName>").append(engineResponse.getOwner().getDisplayName()).append("</DisplayName>");
|
logger.error(
|
||||||
xml.append("</Owner>").append("<Buckets>");
|
"Delete Bucket Policy failed due to " + e.getMessage(), e);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
response.setStatus(500);
|
||||||
for (S3ListAllMyBucketsEntry entry :engineResponse.getBuckets()) {
|
}
|
||||||
xml.append("<Bucket>").append("<Name>").append(entry.getName()).append("</Name>");
|
}
|
||||||
xml.append("<CreationDate>").append(sdf.format(entry.getCreationDate().getTime())).append("</CreationDate>");
|
|
||||||
xml.append("</Bucket>");
|
public void executeGetAllBuckets(HttpServletRequest request,
|
||||||
}
|
HttpServletResponse response) throws IOException,
|
||||||
xml.append("</Buckets>").append("</ListAllMyBucketsResult>");
|
XMLStreamException {
|
||||||
response.setStatus(200);
|
Calendar cal = Calendar.getInstance();
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
cal.set(1970, 1, 1);
|
||||||
S3RestServlet.endResponse(response, xml.toString());
|
S3ListAllMyBucketsRequest engineRequest = new S3ListAllMyBucketsRequest();
|
||||||
|
engineRequest.setAccessKey(UserContext.current().getAccessKey());
|
||||||
|
engineRequest.setRequestTimestamp(cal);
|
||||||
|
engineRequest.setSignature("");
|
||||||
|
|
||||||
|
S3ListAllMyBucketsResponse engineResponse = ServiceProvider
|
||||||
|
.getInstance().getS3Engine().handleRequest(engineRequest);
|
||||||
|
|
||||||
|
// To allow the all buckets list to be serialized via Axiom classes
|
||||||
|
ListAllMyBucketsResponse allBuckets = S3SerializableServiceImplementation
|
||||||
|
.toListAllMyBucketsResponse(engineResponse);
|
||||||
|
|
||||||
|
OutputStream outputStream = response.getOutputStream();
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setContentType("application/xml");
|
||||||
|
// The content-type literally should be "application/xml; charset=UTF-8"
|
||||||
|
// but any compliant JVM supplies utf-8 by default
|
||||||
|
|
||||||
|
// MTOMAwareResultStreamWriter resultWriter = new
|
||||||
|
// MTOMAwareResultStreamWriter ("ListAllMyBucketsResult", outputStream
|
||||||
|
// );
|
||||||
|
// resultWriter.startWrite();
|
||||||
|
// resultWriter.writeout(allBuckets);
|
||||||
|
// resultWriter.stopWrite();
|
||||||
|
StringBuffer xml = new StringBuffer();
|
||||||
|
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||||
|
xml.append("<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");
|
||||||
|
xml.append("<Owner><ID>");
|
||||||
|
xml.append(engineResponse.getOwner().getID()).append("</ID>");
|
||||||
|
xml.append("<DisplayName>")
|
||||||
|
.append(engineResponse.getOwner().getDisplayName())
|
||||||
|
.append("</DisplayName>");
|
||||||
|
xml.append("</Owner>").append("<Buckets>");
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||||
|
for (S3ListAllMyBucketsEntry entry : engineResponse.getBuckets()) {
|
||||||
|
xml.append("<Bucket>").append("<Name>").append(entry.getName())
|
||||||
|
.append("</Name>");
|
||||||
|
xml.append("<CreationDate>")
|
||||||
|
.append(sdf.format(entry.getCreationDate().getTime()))
|
||||||
|
.append("</CreationDate>");
|
||||||
|
xml.append("</Bucket>");
|
||||||
|
}
|
||||||
|
xml.append("</Buckets>").append("</ListAllMyBucketsResult>");
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
|
S3RestServlet.endResponse(response, xml.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeGetBucket(HttpServletRequest request, HttpServletResponse response)
|
public void executeGetBucket(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, XMLStreamException
|
throws IOException, XMLStreamException
|
||||||
{
|
{
|
||||||
S3ListBucketRequest engineRequest = new S3ListBucketRequest();
|
S3ListBucketRequest engineRequest = new S3ListBucketRequest();
|
||||||
engineRequest.setBucketName((String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY));
|
engineRequest.setBucketName((String) request
|
||||||
engineRequest.setDelimiter(request.getParameter("delimiter"));
|
.getAttribute(S3Constants.BUCKET_ATTR_KEY));
|
||||||
engineRequest.setMarker(request.getParameter("marker"));
|
engineRequest.setDelimiter(request.getParameter("delimiter"));
|
||||||
engineRequest.setPrefix(request.getParameter("prefix"));
|
engineRequest.setMarker(request.getParameter("marker"));
|
||||||
|
engineRequest.setPrefix(request.getParameter("prefix"));
|
||||||
int maxKeys = Converter.toInt(request.getParameter("max-keys"), 1000);
|
|
||||||
engineRequest.setMaxKeys(maxKeys);
|
|
||||||
try {
|
|
||||||
S3ListBucketResponse engineResponse = ServiceProvider.getInstance().getS3Engine().listBucketContents( engineRequest, false );
|
|
||||||
|
|
||||||
// To allow the all list buckets result to be serialized via Axiom classes
|
|
||||||
ListBucketResponse oneBucket = S3SerializableServiceImplementation.toListBucketResponse( engineResponse );
|
|
||||||
|
|
||||||
OutputStream outputStream = response.getOutputStream();
|
|
||||||
response.setStatus(200);
|
|
||||||
response.setContentType("application/xml");
|
|
||||||
// The content-type literally should be "application/xml; charset=UTF-8"
|
|
||||||
// but any compliant JVM supplies utf-8 by default;
|
|
||||||
|
|
||||||
MTOMAwareResultStreamWriter resultWriter = new MTOMAwareResultStreamWriter ("ListBucketResult", outputStream );
|
|
||||||
resultWriter.startWrite();
|
|
||||||
resultWriter.writeout(oneBucket);
|
|
||||||
resultWriter.stopWrite();
|
|
||||||
} catch (NoSuchObjectException nsoe) {
|
|
||||||
response.setStatus(404);
|
|
||||||
response.setContentType("application/xml");
|
|
||||||
|
|
||||||
StringBuffer xmlError = new StringBuffer();
|
int maxKeys = Converter.toInt(request.getParameter("max-keys"), 1000);
|
||||||
xmlError.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
engineRequest.setMaxKeys(maxKeys);
|
||||||
|
try {
|
||||||
|
S3ListBucketResponse engineResponse = ServiceProvider.getInstance()
|
||||||
|
.getS3Engine().listBucketContents(engineRequest, false);
|
||||||
|
|
||||||
|
// To allow the all list buckets result to be serialized via Axiom
|
||||||
|
// classes
|
||||||
|
ListBucketResponse oneBucket = S3SerializableServiceImplementation
|
||||||
|
.toListBucketResponse(engineResponse);
|
||||||
|
|
||||||
|
OutputStream outputStream = response.getOutputStream();
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setContentType("application/xml");
|
||||||
|
// The content-type literally should be
|
||||||
|
// "application/xml; charset=UTF-8"
|
||||||
|
// but any compliant JVM supplies utf-8 by default;
|
||||||
|
|
||||||
|
MTOMAwareResultStreamWriter resultWriter = new MTOMAwareResultStreamWriter(
|
||||||
|
"ListBucketResult", outputStream);
|
||||||
|
resultWriter.startWrite();
|
||||||
|
resultWriter.writeout(oneBucket);
|
||||||
|
resultWriter.stopWrite();
|
||||||
|
} catch (NoSuchObjectException nsoe) {
|
||||||
|
response.setStatus(404);
|
||||||
|
response.setContentType("application/xml");
|
||||||
|
|
||||||
|
StringBuffer xmlError = new StringBuffer();
|
||||||
|
xmlError.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||||
.append("<Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message>")
|
.append("<Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message>")
|
||||||
.append("<BucketName>").append((String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY))
|
.append("<BucketName>")
|
||||||
|
.append((String) request
|
||||||
|
.getAttribute(S3Constants.BUCKET_ATTR_KEY))
|
||||||
.append("</BucketName>")
|
.append("</BucketName>")
|
||||||
.append("<RequestId>1DEADBEEF9</RequestId>") //TODO
|
.append("<RequestId>1DEADBEEF9</RequestId>") // TODO
|
||||||
.append("<HostId>abCdeFgHiJ1k2LmN3op4q56r7st89</HostId>") //TODO
|
.append("<HostId>abCdeFgHiJ1k2LmN3op4q56r7st89</HostId>") // TODO
|
||||||
.append("</Error>");
|
.append("</Error>");
|
||||||
S3RestServlet.endResponse(response, xmlError.toString());
|
S3RestServlet.endResponse(response, xmlError.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,8 +657,7 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
SBucketVO sbucket = bucketDao.getByName( bucketName );
|
||||||
SBucket sbucket = bucketDao.getByName( bucketName );
|
|
||||||
if (sbucket == null) {
|
if (sbucket == null) {
|
||||||
response.setStatus( 404 );
|
response.setStatus( 404 );
|
||||||
return;
|
return;
|
||||||
@ -834,111 +850,124 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
public void executePutBucketAcl(HttpServletRequest request, HttpServletResponse response) throws IOException
|
public void executePutBucketAcl(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
// [A] Determine that there is an applicable bucket which might have an ACL set
|
// [A] Determine that there is an applicable bucket which might have an ACL set
|
||||||
|
|
||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
String bucketName = (String) request
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
SBucket bucket = bucketDao.getByName( bucketName );
|
SBucketVO bucket = bucketDao.getByName(bucketName);
|
||||||
String owner = null;
|
String owner = null;
|
||||||
if ( null != bucket )
|
if (null != bucket)
|
||||||
owner = bucket.getOwnerCanonicalId();
|
owner = bucket.getOwnerCanonicalId();
|
||||||
if (null == owner)
|
if (null == owner) {
|
||||||
{
|
logger.error("ACL update failed since " + bucketName
|
||||||
logger.error( "ACL update failed since " + bucketName + " does not exist" );
|
+ " does not exist");
|
||||||
throw new IOException("ACL update failed");
|
throw new IOException("ACL update failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// [B] Obtain the grant request which applies to the acl request string. This latter is supplied as the value of the x-amz-acl header.
|
// [B] Obtain the grant request which applies to the acl request string.
|
||||||
|
// This latter is supplied as the value of the x-amz-acl header.
|
||||||
S3SetBucketAccessControlPolicyRequest engineRequest = new S3SetBucketAccessControlPolicyRequest();
|
|
||||||
S3Grant grantRequest = new S3Grant();
|
S3SetBucketAccessControlPolicyRequest engineRequest = new S3SetBucketAccessControlPolicyRequest();
|
||||||
S3AccessControlList aclRequest = new S3AccessControlList();
|
S3Grant grantRequest = new S3Grant();
|
||||||
|
S3AccessControlList aclRequest = new S3AccessControlList();
|
||||||
String aclRequestString = request.getHeader("x-amz-acl");
|
|
||||||
OrderedPair <Integer,Integer> accessControlsForBucketOwner = SAcl.getCannedAccessControls(aclRequestString,"SBucket");
|
String aclRequestString = request.getHeader("x-amz-acl");
|
||||||
grantRequest.setPermission(accessControlsForBucketOwner.getFirst());
|
OrderedPair<Integer, Integer> accessControlsForBucketOwner = SAclVO.getCannedAccessControls(aclRequestString, "SBucket");
|
||||||
grantRequest.setGrantee(accessControlsForBucketOwner.getSecond());
|
grantRequest.setPermission(accessControlsForBucketOwner.getFirst());
|
||||||
grantRequest.setCanonicalUserID(owner);
|
grantRequest.setGrantee(accessControlsForBucketOwner.getSecond());
|
||||||
aclRequest.addGrant(grantRequest);
|
grantRequest.setCanonicalUserID(owner);
|
||||||
engineRequest.setAcl(aclRequest);
|
aclRequest.addGrant(grantRequest);
|
||||||
engineRequest.setBucketName(bucketName);
|
engineRequest.setAcl(aclRequest);
|
||||||
|
engineRequest.setBucketName(bucketName);
|
||||||
|
|
||||||
// [C] Allow an S3Engine to handle the S3SetBucketAccessControlPolicyRequest
|
// [C] Allow an S3Engine to handle the
|
||||||
S3Response engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest(engineRequest);
|
// S3SetBucketAccessControlPolicyRequest
|
||||||
response.setStatus( engineResponse.getResultCode());
|
S3Response engineResponse = ServiceProvider.getInstance().getS3Engine()
|
||||||
|
.handleRequest(engineRequest);
|
||||||
|
response.setStatus(engineResponse.getResultCode());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executePutBucketVersioning(HttpServletRequest request, HttpServletResponse response) throws IOException
|
public void executePutBucketVersioning(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
String bucketName = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
String versioningStatus = null;
|
String versioningStatus = null;
|
||||||
Node item = null;
|
Node item = null;
|
||||||
|
|
||||||
if (null == bucketName) {
|
if (null == bucketName) {
|
||||||
logger.error( "executePutBucketVersioning - no bucket name given" );
|
logger.error("executePutBucketVersioning - no bucket name given");
|
||||||
response.setStatus( 400 );
|
response.setStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -> is the XML as defined?
|
|
||||||
try {
|
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
|
||||||
Document restXML = db.parse( request.getInputStream());
|
|
||||||
NodeList match = S3RestServlet.getElement( restXML, "http://s3.amazonaws.com/doc/2006-03-01/", "Status" );
|
|
||||||
if ( 0 < match.getLength())
|
|
||||||
{
|
|
||||||
item = match.item(0);
|
|
||||||
versioningStatus = new String( item.getFirstChild().getNodeValue());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ logger.error( "executePutBucketVersioning - cannot find Status tag in XML body" );
|
|
||||||
response.setStatus( 400 );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( Exception e ) {
|
|
||||||
logger.error( "executePutBucketVersioning - failed to parse XML due to " + e.getMessage(), e);
|
|
||||||
response.setStatus(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Irrespective of what the ACLs say only the owner can turn on versioning on a bucket.
|
|
||||||
// The bucket owner may want to restrict the IP address from which this can occur.
|
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
|
||||||
SBucket sbucket = bucketDao.getByName( bucketName );
|
|
||||||
|
|
||||||
String client = UserContext.current().getCanonicalUserId();
|
|
||||||
if (!client.equals( sbucket.getOwnerCanonicalId()))
|
|
||||||
throw new PermissionDeniedException( "Access Denied - only the owner can turn on versioing on a bucket" );
|
|
||||||
|
|
||||||
S3PolicyContext context = new S3PolicyContext( PolicyActions.PutBucketVersioning, bucketName );
|
|
||||||
if (PolicyAccess.DENY == S3Engine.verifyPolicy( context )) {
|
|
||||||
response.setStatus(403);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// -> is the XML as defined?
|
||||||
if (versioningStatus.equalsIgnoreCase( "Enabled" )) sbucket.setVersioningStatus( 1 );
|
try {
|
||||||
else if (versioningStatus.equalsIgnoreCase( "Suspended")) sbucket.setVersioningStatus( 2 );
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
else {
|
Document restXML = db.parse(request.getInputStream());
|
||||||
logger.error( "executePutBucketVersioning - unknown state: [" + versioningStatus + "]" );
|
NodeList match = S3RestServlet.getElement(restXML,
|
||||||
response.setStatus( 400 );
|
"http://s3.amazonaws.com/doc/2006-03-01/", "Status");
|
||||||
return;
|
if (0 < match.getLength()) {
|
||||||
}
|
item = match.item(0);
|
||||||
bucketDao.update( sbucket );
|
versioningStatus = new String(item.getFirstChild()
|
||||||
|
.getNodeValue());
|
||||||
} catch( PermissionDeniedException e ) {
|
} else {
|
||||||
logger.error( "executePutBucketVersioning - failed due to " + e.getMessage(), e);
|
logger.error("executePutBucketVersioning - cannot find Status tag in XML body");
|
||||||
throw e;
|
response.setStatus(400);
|
||||||
|
return;
|
||||||
} catch( Exception e ) {
|
}
|
||||||
logger.error( "executePutBucketVersioning - failed due to " + e.getMessage(), e);
|
} catch (Exception e) {
|
||||||
response.setStatus(500);
|
logger.error(
|
||||||
return;
|
"executePutBucketVersioning - failed to parse XML due to "
|
||||||
}
|
+ e.getMessage(), e);
|
||||||
response.setStatus(200);
|
response.setStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Irrespective of what the ACLs say only the owner can turn on
|
||||||
|
// versioning on a bucket.
|
||||||
|
// The bucket owner may want to restrict the IP address from which
|
||||||
|
// this can occur.
|
||||||
|
|
||||||
|
SBucketVO sbucket = bucketDao.getByName(bucketName);
|
||||||
|
|
||||||
|
String client = UserContext.current().getCanonicalUserId();
|
||||||
|
if (!client.equals(sbucket.getOwnerCanonicalId()))
|
||||||
|
throw new PermissionDeniedException(
|
||||||
|
"Access Denied - only the owner can turn on versioing on a bucket");
|
||||||
|
|
||||||
|
S3PolicyContext context = new S3PolicyContext(
|
||||||
|
PolicyActions.PutBucketVersioning, bucketName);
|
||||||
|
if (PolicyAccess.DENY == S3Engine.verifyPolicy(context)) {
|
||||||
|
response.setStatus(403);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versioningStatus.equalsIgnoreCase("Enabled"))
|
||||||
|
sbucket.setVersioningStatus(1);
|
||||||
|
else if (versioningStatus.equalsIgnoreCase("Suspended"))
|
||||||
|
sbucket.setVersioningStatus(2);
|
||||||
|
else {
|
||||||
|
logger.error("executePutBucketVersioning - unknown state: ["
|
||||||
|
+ versioningStatus + "]");
|
||||||
|
response.setStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bucketDao.update(sbucket.getId(), sbucket);
|
||||||
|
|
||||||
|
} catch (PermissionDeniedException e) {
|
||||||
|
logger.error(
|
||||||
|
"executePutBucketVersioning - failed due to "
|
||||||
|
+ e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(
|
||||||
|
"executePutBucketVersioning - failed due to "
|
||||||
|
+ e.getMessage(), e);
|
||||||
|
response.setStatus(500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
response.setStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executePutBucketLogging(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public void executePutBucketLogging(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
@ -949,7 +978,7 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
public void executePutBucketWebsite(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public void executePutBucketWebsite(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
// TODO -- LoPri - Undertake checks on Put Bucket Website
|
// TODO -- LoPri - Undertake checks on Put Bucket Website
|
||||||
// Tested using configuration <Directory /Users/john1/S3-Mount>\nAllowOverride FileInfo AuthConfig Limit...</Directory> in httpd.conf
|
// Tested using configuration <Directory /Users/john1/S3-Mount>\nAllowOverride FileInfo AuthConfig Limit...</Directory> in httpd.conf
|
||||||
// Need some way of using AllowOverride to allow use of .htaccess and then pushing .httaccess file to bucket subdirectory of mount point
|
// Need some way of using AllowOverride to allow use of .htaccess and then pushing .httaccess file to bucket subdirectory of mount point
|
||||||
// Currently has noop effect in the sense that a running apachectl process sees the directory contents without further action
|
// Currently has noop effect in the sense that a running apachectl process sees the directory contents without further action
|
||||||
response.setStatus(200);
|
response.setStatus(200);
|
||||||
}
|
}
|
||||||
@ -976,128 +1005,145 @@ private void executeMultiObjectDelete(HttpServletRequest request, HttpServletRes
|
|||||||
public void executeListMultipartUploads(HttpServletRequest request, HttpServletResponse response) throws IOException
|
public void executeListMultipartUploads(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
// [A] Obtain parameters and do basic bucket verification
|
// [A] Obtain parameters and do basic bucket verification
|
||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
String bucketName = (String) request
|
||||||
String delimiter = request.getParameter("delimiter");
|
.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
String keyMarker = request.getParameter("key-marker");
|
String delimiter = request.getParameter("delimiter");
|
||||||
String prefix = request.getParameter("prefix");
|
String keyMarker = request.getParameter("key-marker");
|
||||||
int maxUploads = 1000;
|
String prefix = request.getParameter("prefix");
|
||||||
int nextUploadId = 0;
|
int maxUploads = 1000;
|
||||||
String nextKey = null;
|
int nextUploadId = 0;
|
||||||
boolean isTruncated = false;
|
String nextKey = null;
|
||||||
S3MultipartUpload[] uploads = null;
|
boolean isTruncated = false;
|
||||||
S3MultipartUpload onePart = null;
|
S3MultipartUpload[] uploads = null;
|
||||||
|
S3MultipartUpload onePart = null;
|
||||||
String temp = request.getParameter("max-uploads");
|
String temp = request.getParameter("max-uploads");
|
||||||
if (null != temp) {
|
if (null != temp) {
|
||||||
maxUploads = Integer.parseInt( temp );
|
maxUploads = Integer.parseInt(temp);
|
||||||
if (maxUploads > 1000 || maxUploads < 0) maxUploads = 1000;
|
if (maxUploads > 1000 || maxUploads < 0)
|
||||||
}
|
maxUploads = 1000;
|
||||||
|
}
|
||||||
// -> upload-id-marker is ignored unless key-marker is also specified
|
|
||||||
String uploadIdMarker = request.getParameter("upload-id-marker");
|
// -> upload-id-marker is ignored unless key-marker is also specified
|
||||||
if (null == keyMarker) uploadIdMarker = null;
|
String uploadIdMarker = request.getParameter("upload-id-marker");
|
||||||
|
if (null == keyMarker)
|
||||||
// -> does the bucket exist, we may need it to verify access permissions
|
uploadIdMarker = null;
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
|
||||||
SBucket bucket = bucketDao.getByName(bucketName);
|
// -> does the bucket exist, we may need it to verify access permissions
|
||||||
if (bucket == null) {
|
SBucketVO bucket = bucketDao.getByName(bucketName);
|
||||||
logger.error( "listMultipartUpload failed since " + bucketName + " does not exist" );
|
if (bucket == null) {
|
||||||
response.setStatus(404);
|
logger.error("listMultipartUpload failed since " + bucketName
|
||||||
return;
|
+ " does not exist");
|
||||||
|
response.setStatus(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
S3PolicyContext context = new S3PolicyContext(
|
||||||
|
PolicyActions.ListBucketMultipartUploads, bucketName);
|
||||||
|
context.setEvalParam(ConditionKeys.Prefix, prefix);
|
||||||
|
context.setEvalParam(ConditionKeys.Delimiter, delimiter);
|
||||||
|
S3Engine.verifyAccess(context, "SBucket", bucket.getId(),
|
||||||
|
SAcl.PERMISSION_READ);
|
||||||
|
|
||||||
|
// [B] Query the multipart table to get the list of current uploads
|
||||||
|
try {
|
||||||
|
MultipartLoadDao uploadDao = new MultipartLoadDao();
|
||||||
|
OrderedPair<S3MultipartUpload[], Boolean> result = uploadDao
|
||||||
|
.getInitiatedUploads(bucketName, maxUploads, prefix,
|
||||||
|
keyMarker, uploadIdMarker);
|
||||||
|
uploads = result.getFirst();
|
||||||
|
isTruncated = result.getSecond().booleanValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(
|
||||||
|
"List Multipart Uploads failed due to " + e.getMessage(), e);
|
||||||
|
response.setStatus(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer xml = new StringBuffer();
|
||||||
|
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||||
|
xml.append("<ListMultipartUploadsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");
|
||||||
|
xml.append("<Bucket>").append(bucketName).append("</Bucket>");
|
||||||
|
xml.append("<KeyMarker>").append((null == keyMarker ? "" : keyMarker))
|
||||||
|
.append("</KeyMarker>");
|
||||||
|
xml.append("<UploadIdMarker>")
|
||||||
|
.append((null == uploadIdMarker ? "" : uploadIdMarker))
|
||||||
|
.append("</UploadIdMarker>");
|
||||||
|
|
||||||
|
// [C] Construct the contents of the <Upload> element
|
||||||
|
StringBuffer partsList = new StringBuffer();
|
||||||
|
for (int i = 0; i < uploads.length; i++) {
|
||||||
|
onePart = uploads[i];
|
||||||
|
if (null == onePart)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (delimiter != null && !delimiter.isEmpty()) {
|
||||||
|
// -> is this available only in the CommonPrefixes element?
|
||||||
|
if (StringHelper.substringInBetween(onePart.getKey(), prefix,
|
||||||
|
delimiter) != null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextKey = onePart.getKey();
|
||||||
|
nextUploadId = onePart.getId();
|
||||||
|
partsList.append("<Upload>");
|
||||||
|
partsList.append("<Key>").append(nextKey).append("</Key>");
|
||||||
|
partsList.append("<UploadId>").append(nextUploadId)
|
||||||
|
.append("</UploadId>");
|
||||||
|
partsList.append("<Initiator>");
|
||||||
|
partsList.append("<ID>").append(onePart.getAccessKey())
|
||||||
|
.append("</ID>");
|
||||||
|
partsList.append("<DisplayName></DisplayName>");
|
||||||
|
partsList.append("</Initiator>");
|
||||||
|
partsList.append("<Owner>");
|
||||||
|
partsList.append("<ID>").append(onePart.getAccessKey())
|
||||||
|
.append("</ID>");
|
||||||
|
partsList.append("<DisplayName></DisplayName>");
|
||||||
|
partsList.append("</Owner>");
|
||||||
|
partsList.append("<StorageClass>STANDARD</StorageClass>");
|
||||||
|
partsList
|
||||||
|
.append("<Initiated>")
|
||||||
|
.append(DatatypeConverter.printDateTime(onePart
|
||||||
|
.getLastModified())).append("</Initiated>");
|
||||||
|
partsList.append("</Upload>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// [D] Construct the contents of the <CommonPrefixes> elements (if any)
|
||||||
|
for (int i = 0; i < uploads.length; i++) {
|
||||||
|
onePart = uploads[i];
|
||||||
|
if (null == onePart)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (delimiter != null && !delimiter.isEmpty()) {
|
||||||
|
String subName = StringHelper.substringInBetween(
|
||||||
|
onePart.getKey(), prefix, delimiter);
|
||||||
|
if (subName != null) {
|
||||||
|
partsList.append("<CommonPrefixes>");
|
||||||
|
partsList.append("<Prefix>");
|
||||||
|
if (prefix != null && prefix.length() > 0)
|
||||||
|
partsList.append(prefix + delimiter + subName);
|
||||||
|
else
|
||||||
|
partsList.append(subName);
|
||||||
|
partsList.append("</Prefix>");
|
||||||
|
partsList.append("</CommonPrefixes>");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
S3PolicyContext context = new S3PolicyContext( PolicyActions.ListBucketMultipartUploads, bucketName );
|
}
|
||||||
context.setEvalParam( ConditionKeys.Prefix, prefix );
|
|
||||||
context.setEvalParam( ConditionKeys.Delimiter, delimiter );
|
|
||||||
S3Engine.verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_READ );
|
|
||||||
|
|
||||||
|
// [D] Finish off the response
|
||||||
// [B] Query the multipart table to get the list of current uploads
|
xml.append("<NextKeyMarker>").append((null == nextKey ? "" : nextKey))
|
||||||
try {
|
.append("</NextKeyMarker>");
|
||||||
MultipartLoadDao uploadDao = new MultipartLoadDao();
|
xml.append("<NextUploadIdMarker>")
|
||||||
OrderedPair<S3MultipartUpload[],Boolean> result = uploadDao.getInitiatedUploads( bucketName, maxUploads, prefix, keyMarker, uploadIdMarker );
|
.append((0 == nextUploadId ? "" : nextUploadId))
|
||||||
uploads = result.getFirst();
|
.append("</NextUploadIdMarker>");
|
||||||
isTruncated = result.getSecond().booleanValue();
|
xml.append("<MaxUploads>").append(maxUploads).append("</MaxUploads>");
|
||||||
}
|
xml.append("<IsTruncated>").append(isTruncated)
|
||||||
catch( Exception e ) {
|
.append("</IsTruncated>");
|
||||||
logger.error("List Multipart Uploads failed due to " + e.getMessage(), e);
|
|
||||||
response.setStatus(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuffer xml = new StringBuffer();
|
xml.append(partsList.toString());
|
||||||
xml.append( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" );
|
xml.append("</ListMultipartUploadsResult>");
|
||||||
xml.append( "<ListMultipartUploadsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">" );
|
|
||||||
xml.append( "<Bucket>" ).append( bucketName ).append( "</Bucket>" );
|
|
||||||
xml.append( "<KeyMarker>").append((null == keyMarker ? "" : keyMarker)).append( "</KeyMarker>" );
|
|
||||||
xml.append( "<UploadIdMarker>").append((null == uploadIdMarker ? "" : uploadIdMarker)).append( "</UploadIdMarker>" );
|
|
||||||
|
|
||||||
|
|
||||||
// [C] Construct the contents of the <Upload> element
|
|
||||||
StringBuffer partsList = new StringBuffer();
|
|
||||||
for( int i=0; i < uploads.length; i++ )
|
|
||||||
{
|
|
||||||
onePart = uploads[i];
|
|
||||||
if (null == onePart) break;
|
|
||||||
|
|
||||||
if (delimiter != null && !delimiter.isEmpty())
|
|
||||||
{
|
|
||||||
// -> is this available only in the CommonPrefixes element?
|
|
||||||
if (StringHelper.substringInBetween(onePart.getKey(), prefix, delimiter) != null)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
nextKey = onePart.getKey();
|
|
||||||
nextUploadId = onePart.getId();
|
|
||||||
partsList.append( "<Upload>" );
|
|
||||||
partsList.append( "<Key>" ).append( nextKey ).append( "</Key>" );
|
|
||||||
partsList.append( "<UploadId>" ).append( nextUploadId ).append( "</UploadId>" );
|
|
||||||
partsList.append( "<Initiator>" );
|
|
||||||
partsList.append( "<ID>" ).append( onePart.getAccessKey()).append( "</ID>" );
|
|
||||||
partsList.append( "<DisplayName></DisplayName>" );
|
|
||||||
partsList.append( "</Initiator>" );
|
|
||||||
partsList.append( "<Owner>" );
|
|
||||||
partsList.append( "<ID>" ).append( onePart.getAccessKey()).append( "</ID>" );
|
|
||||||
partsList.append( "<DisplayName></DisplayName>" );
|
|
||||||
partsList.append( "</Owner>" );
|
|
||||||
partsList.append( "<StorageClass>STANDARD</StorageClass>" );
|
|
||||||
partsList.append( "<Initiated>" ).append( DatatypeConverter.printDateTime( onePart.getLastModified())).append( "</Initiated>" );
|
|
||||||
partsList.append( "</Upload>" );
|
|
||||||
}
|
|
||||||
|
|
||||||
// [D] Construct the contents of the <CommonPrefixes> elements (if any)
|
|
||||||
for( int i=0; i < uploads.length; i++ )
|
|
||||||
{
|
|
||||||
onePart = uploads[i];
|
|
||||||
if (null == onePart) break;
|
|
||||||
|
|
||||||
if (delimiter != null && !delimiter.isEmpty())
|
response.setStatus(200);
|
||||||
{
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
String subName = StringHelper.substringInBetween(onePart.getKey(), prefix, delimiter);
|
S3RestServlet.endResponse(response, xml.toString());
|
||||||
if (subName != null)
|
|
||||||
{
|
|
||||||
partsList.append( "<CommonPrefixes>" );
|
|
||||||
partsList.append( "<Prefix>" );
|
|
||||||
if ( prefix != null && prefix.length() > 0 )
|
|
||||||
partsList.append( prefix + delimiter + subName );
|
|
||||||
else partsList.append( subName );
|
|
||||||
partsList.append( "</Prefix>" );
|
|
||||||
partsList.append( "</CommonPrefixes>" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// [D] Finish off the response
|
|
||||||
xml.append( "<NextKeyMarker>" ).append((null == nextKey ? "" : nextKey)).append( "</NextKeyMarker>" );
|
|
||||||
xml.append( "<NextUploadIdMarker>" ).append((0 == nextUploadId ? "" : nextUploadId)).append( "</NextUploadIdMarker>" );
|
|
||||||
xml.append( "<MaxUploads>" ).append( maxUploads ).append( "</MaxUploads>" );
|
|
||||||
xml.append( "<IsTruncated>" ).append( isTruncated ).append( "</IsTruncated>" );
|
|
||||||
|
|
||||||
xml.append( partsList.toString());
|
|
||||||
xml.append( "</ListMultipartUploadsResult>" );
|
|
||||||
|
|
||||||
response.setStatus(200);
|
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
|
||||||
S3RestServlet.endResponse(response, xml.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String streamToString( InputStream is ) throws IOException
|
private String streamToString( InputStream is ) throws IOException
|
||||||
|
|||||||
@ -45,9 +45,12 @@ import com.amazon.s3.CopyObjectResponse;
|
|||||||
import com.amazon.s3.GetObjectAccessControlPolicyResponse;
|
import com.amazon.s3.GetObjectAccessControlPolicyResponse;
|
||||||
import com.cloud.bridge.io.MTOMAwareResultStreamWriter;
|
import com.cloud.bridge.io.MTOMAwareResultStreamWriter;
|
||||||
import com.cloud.bridge.model.SAcl;
|
import com.cloud.bridge.model.SAcl;
|
||||||
|
import com.cloud.bridge.model.SAclVO;
|
||||||
import com.cloud.bridge.model.SBucket;
|
import com.cloud.bridge.model.SBucket;
|
||||||
|
import com.cloud.bridge.model.SBucketVO;
|
||||||
import com.cloud.bridge.persist.dao.MultipartLoadDao;
|
import com.cloud.bridge.persist.dao.MultipartLoadDao;
|
||||||
import com.cloud.bridge.persist.dao.SBucketDao;
|
import com.cloud.bridge.persist.dao.SBucketDao;
|
||||||
|
import com.cloud.bridge.persist.dao.SBucketDaoImpl;
|
||||||
import com.cloud.bridge.service.S3Constants;
|
import com.cloud.bridge.service.S3Constants;
|
||||||
import com.cloud.bridge.service.S3RestServlet;
|
import com.cloud.bridge.service.S3RestServlet;
|
||||||
import com.cloud.bridge.service.UserContext;
|
import com.cloud.bridge.service.UserContext;
|
||||||
@ -79,9 +82,11 @@ import com.cloud.bridge.util.DateHelper;
|
|||||||
import com.cloud.bridge.util.HeaderParam;
|
import com.cloud.bridge.util.HeaderParam;
|
||||||
import com.cloud.bridge.util.ServletRequestDataSource;
|
import com.cloud.bridge.util.ServletRequestDataSource;
|
||||||
import com.cloud.bridge.util.OrderedPair;
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
|
||||||
public class S3ObjectAction implements ServletAction {
|
public class S3ObjectAction implements ServletAction {
|
||||||
protected final static Logger logger = Logger.getLogger(S3ObjectAction.class);
|
protected final static Logger logger = Logger.getLogger(S3ObjectAction.class);
|
||||||
|
protected final SBucketDao bucketDao = ComponentLocator.inject(SBucketDaoImpl.class);
|
||||||
|
|
||||||
private DocumentBuilderFactory dbf = null;
|
private DocumentBuilderFactory dbf = null;
|
||||||
|
|
||||||
@ -273,8 +278,7 @@ public class S3ObjectAction implements ServletAction {
|
|||||||
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
|
||||||
String key = (String)request.getAttribute(S3Constants.OBJECT_ATTR_KEY);
|
String key = (String)request.getAttribute(S3Constants.OBJECT_ATTR_KEY);
|
||||||
|
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
SBucketVO bucket = bucketDao.getByName( bucketName );
|
||||||
SBucket bucket = bucketDao.getByName( bucketName );
|
|
||||||
String owner = null;
|
String owner = null;
|
||||||
if ( null != bucket )
|
if ( null != bucket )
|
||||||
owner = bucket.getOwnerCanonicalId();
|
owner = bucket.getOwnerCanonicalId();
|
||||||
@ -296,7 +300,7 @@ public class S3ObjectAction implements ServletAction {
|
|||||||
S3AccessControlList aclRequest = new S3AccessControlList();
|
S3AccessControlList aclRequest = new S3AccessControlList();
|
||||||
|
|
||||||
String aclRequestString = request.getHeader("x-amz-acl");
|
String aclRequestString = request.getHeader("x-amz-acl");
|
||||||
OrderedPair <Integer,Integer> accessControlsForObjectOwner = SAcl.getCannedAccessControls(aclRequestString,"SObject");
|
OrderedPair <Integer,Integer> accessControlsForObjectOwner = SAclVO.getCannedAccessControls(aclRequestString,"SObject");
|
||||||
grantRequest.setPermission(accessControlsForObjectOwner.getFirst());
|
grantRequest.setPermission(accessControlsForObjectOwner.getFirst());
|
||||||
grantRequest.setGrantee(accessControlsForObjectOwner.getSecond());
|
grantRequest.setGrantee(accessControlsForObjectOwner.getSecond());
|
||||||
grantRequest.setCanonicalUserID(owner);
|
grantRequest.setCanonicalUserID(owner);
|
||||||
@ -484,6 +488,11 @@ public class S3ObjectAction implements ServletAction {
|
|||||||
|
|
||||||
S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );
|
S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );
|
||||||
response.setStatus( engineResponse.getResultCode());
|
response.setStatus( engineResponse.getResultCode());
|
||||||
|
|
||||||
|
//bucket lookup for non-existance key
|
||||||
|
|
||||||
|
if ( engineResponse.getResultCode() == 404 )
|
||||||
|
return;
|
||||||
|
|
||||||
String deleteMarker = engineResponse.getDeleteMarker();
|
String deleteMarker = engineResponse.getDeleteMarker();
|
||||||
if ( null != deleteMarker ) {
|
if ( null != deleteMarker ) {
|
||||||
@ -891,8 +900,7 @@ public class S3ObjectAction implements ServletAction {
|
|||||||
|
|
||||||
|
|
||||||
// -> does the bucket exist, we may need it to verify access permissions
|
// -> does the bucket exist, we may need it to verify access permissions
|
||||||
SBucketDao bucketDao = new SBucketDao();
|
SBucketVO bucket = bucketDao.getByName(bucketName);
|
||||||
SBucket bucket = bucketDao.getByName(bucketName);
|
|
||||||
if (bucket == null) {
|
if (bucket == null) {
|
||||||
logger.error( "listUploadParts failed since " + bucketName + " does not exist" );
|
logger.error( "listUploadParts failed since " + bucketName + " does not exist" );
|
||||||
response.setStatus(404);
|
response.setStatus(404);
|
||||||
|
|||||||
@ -35,18 +35,19 @@ import java.util.TimerTask;
|
|||||||
import org.apache.axis2.AxisFault;
|
import org.apache.axis2.AxisFault;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.xml.DOMConfigurator;
|
import org.apache.log4j.xml.DOMConfigurator;
|
||||||
import org.hibernate.SessionException;
|
|
||||||
|
|
||||||
import com.amazon.s3.AmazonS3SkeletonInterface;
|
import com.amazon.s3.AmazonS3SkeletonInterface;
|
||||||
import com.amazon.ec2.AmazonEC2SkeletonInterface;
|
import com.amazon.ec2.AmazonEC2SkeletonInterface;
|
||||||
import com.cloud.bridge.model.MHost;
|
import com.cloud.bridge.model.MHostVO;
|
||||||
import com.cloud.bridge.model.SHost;
|
import com.cloud.bridge.model.SHost;
|
||||||
import com.cloud.bridge.model.UserCredentials;
|
import com.cloud.bridge.model.SHostVO;
|
||||||
import com.cloud.bridge.persist.PersistContext;
|
import com.cloud.bridge.model.UserCredentialsVO;
|
||||||
import com.cloud.bridge.persist.PersistException;
|
|
||||||
import com.cloud.bridge.persist.dao.MHostDao;
|
import com.cloud.bridge.persist.dao.MHostDao;
|
||||||
|
import com.cloud.bridge.persist.dao.MHostDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.SHostDao;
|
import com.cloud.bridge.persist.dao.SHostDao;
|
||||||
|
import com.cloud.bridge.persist.dao.SHostDaoImpl;
|
||||||
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
import com.cloud.bridge.persist.dao.UserCredentialsDao;
|
||||||
|
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
|
||||||
import com.cloud.bridge.service.EC2SoapServiceImpl;
|
import com.cloud.bridge.service.EC2SoapServiceImpl;
|
||||||
import com.cloud.bridge.service.UserInfo;
|
import com.cloud.bridge.service.UserInfo;
|
||||||
import com.cloud.bridge.service.core.ec2.EC2Engine;
|
import com.cloud.bridge.service.core.ec2.EC2Engine;
|
||||||
@ -57,17 +58,23 @@ import com.cloud.bridge.util.ConfigurationHelper;
|
|||||||
import com.cloud.bridge.util.DateHelper;
|
import com.cloud.bridge.util.DateHelper;
|
||||||
import com.cloud.bridge.util.NetHelper;
|
import com.cloud.bridge.util.NetHelper;
|
||||||
import com.cloud.bridge.util.OrderedPair;
|
import com.cloud.bridge.util.OrderedPair;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
public class ServiceProvider {
|
public class ServiceProvider {
|
||||||
protected final static Logger logger = Logger.getLogger(ServiceProvider.class);
|
protected final static Logger logger = Logger.getLogger(ServiceProvider.class);
|
||||||
|
protected final MHostDao mhostDao = ComponentLocator.inject(MHostDaoImpl.class);
|
||||||
|
protected final SHostDao shostDao = ComponentLocator.inject(SHostDaoImpl.class);
|
||||||
|
protected final UserCredentialsDao ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
|
||||||
|
|
||||||
public final static long HEARTBEAT_INTERVAL = 10000;
|
public final static long HEARTBEAT_INTERVAL = 10000;
|
||||||
|
|
||||||
private static ServiceProvider instance;
|
private static ServiceProvider instance;
|
||||||
|
|
||||||
private Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, Object>();
|
private Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, Object>();
|
||||||
private Timer timer = new Timer();
|
private Timer timer = new Timer();
|
||||||
private MHost mhost;
|
private MHostVO mhost;
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
private boolean useSubDomain = false; // use DNS sub domain for bucket name
|
private boolean useSubDomain = false; // use DNS sub domain for bucket name
|
||||||
private String serviceEndpoint = null;
|
private String serviceEndpoint = null;
|
||||||
@ -81,6 +88,8 @@ public class ServiceProvider {
|
|||||||
|
|
||||||
protected ServiceProvider() throws IOException {
|
protected ServiceProvider() throws IOException {
|
||||||
// register service implementation object
|
// register service implementation object
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
txn.close();
|
||||||
engine = new S3Engine();
|
engine = new S3Engine();
|
||||||
EC2_engine = new EC2Engine();
|
EC2_engine = new EC2Engine();
|
||||||
serviceMap.put(AmazonS3SkeletonInterface.class, new S3SerializableServiceImplementation(engine));
|
serviceMap.put(AmazonS3SkeletonInterface.class, new S3SerializableServiceImplementation(engine));
|
||||||
@ -93,11 +102,9 @@ public class ServiceProvider {
|
|||||||
try {
|
try {
|
||||||
instance = new ServiceProvider();
|
instance = new ServiceProvider();
|
||||||
instance.initialize();
|
instance.initialize();
|
||||||
PersistContext.commitTransaction();
|
|
||||||
} catch(Throwable e) {
|
} catch(Throwable e) {
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
PersistContext.closeSession();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
@ -172,27 +179,34 @@ public class ServiceProvider {
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo getUserInfo(String accessKey)
|
public UserInfo getUserInfo(String accessKey) {
|
||||||
throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
|
||||||
UserInfo info = new UserInfo();
|
UserInfo info = new UserInfo();
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
UserCredentialsDao credentialDao = new UserCredentialsDao();
|
try {
|
||||||
UserCredentials cloudKeys = credentialDao.getByAccessKey( accessKey );
|
txn.start();
|
||||||
if ( null == cloudKeys ) {
|
UserCredentialsVO cloudKeys = ucDao.getByAccessKey( accessKey );
|
||||||
logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
|
if ( null == cloudKeys ) {
|
||||||
return null;
|
logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
|
||||||
} else {
|
return null;
|
||||||
info.setAccessKey( accessKey );
|
} else {
|
||||||
info.setSecretKey( cloudKeys.getSecretKey());
|
info.setAccessKey( accessKey );
|
||||||
info.setCanonicalUserId(accessKey);
|
info.setSecretKey( cloudKeys.getSecretKey());
|
||||||
info.setDescription( "S3 REST request" );
|
info.setCanonicalUserId(accessKey);
|
||||||
return info;
|
info.setDescription( "S3 REST request" );
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
txn.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DB
|
||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
if(logger.isInfoEnabled())
|
if(logger.isInfoEnabled())
|
||||||
logger.info("Initializing ServiceProvider...");
|
logger.info("Initializing ServiceProvider...");
|
||||||
|
|
||||||
|
Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
|
//txn.close();
|
||||||
|
|
||||||
File file = ConfigurationHelper.findConfigurationFile("log4j-cloud.xml");
|
File file = ConfigurationHelper.findConfigurationFile("log4j-cloud.xml");
|
||||||
if(file != null) {
|
if(file != null) {
|
||||||
@ -226,14 +240,16 @@ public class ServiceProvider {
|
|||||||
setupHost(hostKey, host);
|
setupHost(hostKey, host);
|
||||||
|
|
||||||
// we will commit and start a new transaction to allow host info be flushed to DB
|
// we will commit and start a new transaction to allow host info be flushed to DB
|
||||||
PersistContext.flush();
|
//PersistContext.flush();
|
||||||
|
|
||||||
String localStorageRoot = properties.getProperty("storage.root");
|
String localStorageRoot = properties.getProperty("storage.root");
|
||||||
if (localStorageRoot != null) setupLocalStorage(localStorageRoot);
|
if (localStorageRoot != null) setupLocalStorage(localStorageRoot);
|
||||||
|
|
||||||
multipartDir = properties.getProperty("storage.multipartDir");
|
multipartDir = properties.getProperty("storage.multipartDir");
|
||||||
|
|
||||||
|
Transaction txn1 = Transaction.open(Transaction.AWSAPI_DB);
|
||||||
timer.schedule(getHeartbeatTask(), HEARTBEAT_INTERVAL, HEARTBEAT_INTERVAL);
|
timer.schedule(getHeartbeatTask(), HEARTBEAT_INTERVAL, HEARTBEAT_INTERVAL);
|
||||||
|
txn1.close();
|
||||||
|
|
||||||
if(logger.isInfoEnabled())
|
if(logger.isInfoEnabled())
|
||||||
logger.info("ServiceProvider initialized");
|
logger.info("ServiceProvider initialized");
|
||||||
@ -264,45 +280,41 @@ public class ServiceProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
MHostDao mhostDao = new MHostDao();
|
|
||||||
mhost.setLastHeartbeatTime(DateHelper.currentGMTTime());
|
mhost.setLastHeartbeatTime(DateHelper.currentGMTTime());
|
||||||
mhostDao.update(mhost);
|
mhostDao.updateHeartBeat(mhost);
|
||||||
PersistContext.commitTransaction();
|
|
||||||
} catch(Throwable e){
|
} catch(Throwable e){
|
||||||
logger.error("Unexpected exception " + e.getMessage(), e);
|
logger.error("Unexpected exception " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
PersistContext.closeSession();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupHost(String hostKey, String host) {
|
private void setupHost(String hostKey, String host) {
|
||||||
MHostDao mhostDao = new MHostDao();
|
|
||||||
mhost = mhostDao.getByHostKey(hostKey);
|
mhost = mhostDao.getByHostKey(hostKey);
|
||||||
if(mhost == null) {
|
if(mhost == null) {
|
||||||
mhost = new MHost();
|
mhost = new MHostVO();
|
||||||
mhost.setHostKey(hostKey);
|
mhost.setHostKey(hostKey);
|
||||||
mhost.setHost(host);
|
mhost.setHost(host);
|
||||||
mhost.setLastHeartbeatTime(DateHelper.currentGMTTime());
|
mhost.setLastHeartbeatTime(DateHelper.currentGMTTime());
|
||||||
mhostDao.save(mhost);
|
mhost = mhostDao.persist(mhost);
|
||||||
} else {
|
} else {
|
||||||
mhost.setHost(host);
|
mhost.setHost(host);
|
||||||
mhostDao.update(mhost);
|
mhostDao.update(mhost.getId(), mhost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLocalStorage(String storageRoot) {
|
private void setupLocalStorage(String storageRoot) {
|
||||||
SHostDao shostDao = new SHostDao();
|
SHostVO shost = shostDao.getLocalStorageHost(mhost.getId(), storageRoot);
|
||||||
SHost shost = shostDao.getLocalStorageHost(mhost.getId(), storageRoot);
|
|
||||||
if(shost == null) {
|
if(shost == null) {
|
||||||
shost = new SHost();
|
shost = new SHostVO();
|
||||||
shost.setMhost(mhost);
|
shost.setMhost(mhost);
|
||||||
mhost.getLocalSHosts().add(shost);
|
shost.setMhostid(mhost.getId());
|
||||||
shost.setHostType(SHost.STORAGE_HOST_TYPE_LOCAL);
|
shost.setHostType(SHost.STORAGE_HOST_TYPE_LOCAL);
|
||||||
shost.setHost(NetHelper.getHostName());
|
shost.setHost(NetHelper.getHostName());
|
||||||
shost.setExportRoot(storageRoot);
|
shost.setExportRoot(storageRoot);
|
||||||
PersistContext.getSession().save(shost);
|
shostDao.persist(shost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,35 +330,36 @@ public class ServiceProvider {
|
|||||||
return (T) Proxy.newProxyInstance(serviceObject.getClass().getClassLoader(),
|
return (T) Proxy.newProxyInstance(serviceObject.getClass().getClassLoader(),
|
||||||
new Class[] { serviceInterface },
|
new Class[] { serviceInterface },
|
||||||
new InvocationHandler() {
|
new InvocationHandler() {
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method,
|
||||||
Object result = null;
|
Object[] args) throws Throwable {
|
||||||
try {
|
Object result = null;
|
||||||
result = method.invoke(serviceObject, args);
|
try {
|
||||||
PersistContext.commitTransaction();
|
result = method.invoke(serviceObject, args);
|
||||||
PersistContext.commitTransaction(true);
|
} catch (Throwable e) {
|
||||||
} catch (PersistException e) {
|
// Rethrow the exception to Axis:
|
||||||
} catch (SessionException e) {
|
// Check if the exception is an AxisFault or a
|
||||||
} catch(Throwable e) {
|
// RuntimeException
|
||||||
// Rethrow the exception to Axis:
|
// enveloped AxisFault and if so, pass it on as
|
||||||
// Check if the exception is an AxisFault or a RuntimeException
|
// such. Otherwise
|
||||||
// enveloped AxisFault and if so, pass it on as such. Otherwise
|
// log to help debugging and throw as is.
|
||||||
// log to help debugging and throw as is.
|
if (e.getCause() != null
|
||||||
if (e.getCause() != null && e.getCause() instanceof AxisFault)
|
&& e.getCause() instanceof AxisFault)
|
||||||
throw e.getCause();
|
throw e.getCause();
|
||||||
else if (e.getCause() != null && e.getCause().getCause() != null
|
else if (e.getCause() != null
|
||||||
&& e.getCause().getCause() instanceof AxisFault)
|
&& e.getCause().getCause() != null
|
||||||
throw e.getCause().getCause();
|
&& e.getCause().getCause() instanceof AxisFault)
|
||||||
else {
|
throw e.getCause().getCause();
|
||||||
logger.warn("Unhandled exception " + e.getMessage(), e);
|
else {
|
||||||
throw e;
|
logger.warn(
|
||||||
}
|
"Unhandled exception " + e.getMessage(),
|
||||||
} finally {
|
e);
|
||||||
PersistContext.closeSession();
|
throw e;
|
||||||
PersistContext.closeSession(true);
|
}
|
||||||
}
|
} finally {
|
||||||
return result;
|
}
|
||||||
}
|
return result;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@ -22,6 +22,9 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -32,12 +35,15 @@ import java.util.UUID;
|
|||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hibernate.ejb.criteria.expression.UnaryArithmeticOperation.Operation;
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.cloud.bridge.persist.dao.CloudStackSvcOfferingDao;
|
import com.cloud.bridge.model.CloudStackServiceOfferingVO;
|
||||||
import com.cloud.bridge.persist.dao.CloudStackAccountDao;
|
import com.cloud.bridge.persist.dao.CloudStackAccountDao;
|
||||||
import com.cloud.bridge.persist.dao.OfferingDao;
|
import com.cloud.bridge.persist.dao.CloudStackAccountDaoImpl;
|
||||||
|
import com.cloud.bridge.persist.dao.CloudStackSvcOfferingDao;
|
||||||
|
import com.cloud.bridge.persist.dao.CloudStackSvcOfferingDaoImpl;
|
||||||
|
import com.cloud.bridge.persist.dao.OfferingDaoImpl;
|
||||||
|
import com.cloud.bridge.persist.dao.SObjectItemDaoImpl;
|
||||||
import com.cloud.bridge.service.UserContext;
|
import com.cloud.bridge.service.UserContext;
|
||||||
|
|
||||||
import com.cloud.bridge.service.core.ec2.EC2ImageAttributes.ImageAttribute;
|
import com.cloud.bridge.service.core.ec2.EC2ImageAttributes.ImageAttribute;
|
||||||
@ -70,6 +76,8 @@ import com.cloud.stack.models.CloudStackUser;
|
|||||||
import com.cloud.stack.models.CloudStackUserVm;
|
import com.cloud.stack.models.CloudStackUserVm;
|
||||||
import com.cloud.stack.models.CloudStackVolume;
|
import com.cloud.stack.models.CloudStackVolume;
|
||||||
import com.cloud.stack.models.CloudStackZone;
|
import com.cloud.stack.models.CloudStackZone;
|
||||||
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EC2Engine processes the ec2 commands and calls their cloudstack analogs
|
* EC2Engine processes the ec2 commands and calls their cloudstack analogs
|
||||||
@ -80,6 +88,9 @@ public class EC2Engine {
|
|||||||
String managementServer = null;
|
String managementServer = null;
|
||||||
String cloudAPIPort = null;
|
String cloudAPIPort = null;
|
||||||
|
|
||||||
|
protected final CloudStackSvcOfferingDao scvoDao = ComponentLocator.inject(CloudStackSvcOfferingDaoImpl.class);
|
||||||
|
protected final OfferingDaoImpl ofDao = ComponentLocator.inject(OfferingDaoImpl.class);
|
||||||
|
CloudStackAccountDao accDao = ComponentLocator.inject(CloudStackAccountDaoImpl.class);
|
||||||
private CloudStackApi _eng = null;
|
private CloudStackApi _eng = null;
|
||||||
|
|
||||||
private CloudStackAccount currentAccount = null;
|
private CloudStackAccount currentAccount = null;
|
||||||
@ -110,7 +121,6 @@ public class EC2Engine {
|
|||||||
managementServer = EC2Prop.getProperty( "managementServer" );
|
managementServer = EC2Prop.getProperty( "managementServer" );
|
||||||
cloudAPIPort = EC2Prop.getProperty( "cloudAPIPort", null );
|
cloudAPIPort = EC2Prop.getProperty( "cloudAPIPort", null );
|
||||||
|
|
||||||
OfferingDao ofDao = new OfferingDao();
|
|
||||||
try {
|
try {
|
||||||
if(ofDao.getOfferingCount() == 0) {
|
if(ofDao.getOfferingCount() == 0) {
|
||||||
String strValue = EC2Prop.getProperty("m1.small.serviceId");
|
String strValue = EC2Prop.getProperty("m1.small.serviceId");
|
||||||
@ -1469,7 +1479,7 @@ public class EC2Engine {
|
|||||||
if(request.getInstanceType() != null){
|
if(request.getInstanceType() != null){
|
||||||
instanceType = request.getInstanceType();
|
instanceType = request.getInstanceType();
|
||||||
}
|
}
|
||||||
CloudStackServiceOffering svcOffering = getCSServiceOfferingId(instanceType);
|
CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
|
||||||
if(svcOffering == null){
|
if(svcOffering == null){
|
||||||
logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
|
logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
|
||||||
throw new EC2ServiceException(ClientError.Unsupported, "instanceType: [" + instanceType + "] not found!");
|
throw new EC2ServiceException(ClientError.Unsupported, "instanceType: [" + instanceType + "] not found!");
|
||||||
@ -1779,12 +1789,11 @@ public class EC2Engine {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private CloudStackServiceOffering getCSServiceOfferingId(String instanceType){
|
private CloudStackServiceOfferingVO getCSServiceOfferingId(String instanceType){
|
||||||
try {
|
try {
|
||||||
if (null == instanceType) instanceType = "m1.small";
|
if (null == instanceType) instanceType = "m1.small";
|
||||||
|
|
||||||
CloudStackSvcOfferingDao dao = new CloudStackSvcOfferingDao();
|
return scvoDao.getSvcOfferingByName(instanceType);
|
||||||
return dao.getSvcOfferingByName(instanceType);
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error( "Error while retrieving ServiceOffering information by name - ", e);
|
logger.error( "Error while retrieving ServiceOffering information by name - ", e);
|
||||||
@ -1802,8 +1811,8 @@ public class EC2Engine {
|
|||||||
*/
|
*/
|
||||||
private String serviceOfferingIdToInstanceType( String serviceOfferingId ){
|
private String serviceOfferingIdToInstanceType( String serviceOfferingId ){
|
||||||
try{
|
try{
|
||||||
CloudStackSvcOfferingDao dao = new CloudStackSvcOfferingDao();
|
|
||||||
CloudStackServiceOffering offering = dao.getSvcOfferingById(serviceOfferingId);
|
CloudStackServiceOfferingVO offering = scvoDao.getSvcOfferingById(serviceOfferingId); //dao.getSvcOfferingById(serviceOfferingId);
|
||||||
if(offering == null){
|
if(offering == null){
|
||||||
logger.warn( "No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]" );
|
logger.warn( "No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]" );
|
||||||
return "m1.small";
|
return "m1.small";
|
||||||
@ -2260,9 +2269,7 @@ public class EC2Engine {
|
|||||||
*/
|
*/
|
||||||
private String getDefaultZoneId(String accountId) {
|
private String getDefaultZoneId(String accountId) {
|
||||||
try {
|
try {
|
||||||
CloudStackAccountDao dao = new CloudStackAccountDao();
|
return accDao.getDefaultZoneId(accountId);
|
||||||
CloudStackAccount account = dao.getdefaultZoneId(accountId);
|
|
||||||
return account.getDefaultZoneId();
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error( "Error while retrieving Account information by id - ", e);
|
logger.error( "Error while retrieving Account information by id - ", e);
|
||||||
throw new EC2ServiceException(ServerError.InternalError, e.getMessage());
|
throw new EC2ServiceException(ServerError.InternalError, e.getMessage());
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@ package com.cloud.bridge.service.core.s3;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.bridge.model.SAcl;
|
import com.cloud.bridge.model.SAcl;
|
||||||
|
import com.cloud.bridge.model.SAclVO;
|
||||||
import com.cloud.bridge.model.SBucket;
|
import com.cloud.bridge.model.SBucket;
|
||||||
import com.cloud.bridge.service.exception.UnsupportedException;
|
import com.cloud.bridge.service.exception.UnsupportedException;
|
||||||
|
|
||||||
@ -64,12 +65,12 @@ public class S3Grant {
|
|||||||
/* Return an array of S3Grants holding the permissions of grantees by grantee type and their canonicalUserIds.
|
/* Return an array of S3Grants holding the permissions of grantees by grantee type and their canonicalUserIds.
|
||||||
* Used by S3 engine to get ACL policy requests for buckets and objects.
|
* Used by S3 engine to get ACL policy requests for buckets and objects.
|
||||||
*/
|
*/
|
||||||
public static S3Grant[] toGrants(List<SAcl> grants) {
|
public static S3Grant[] toGrants(List<SAclVO> grants) {
|
||||||
if(grants != null)
|
if(grants != null)
|
||||||
{
|
{
|
||||||
S3Grant[] entries = new S3Grant[grants.size()];
|
S3Grant[] entries = new S3Grant[grants.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(SAcl acl: grants) {
|
for(SAclVO acl: grants) {
|
||||||
entries[i] = new S3Grant();
|
entries[i] = new S3Grant();
|
||||||
entries[i].setGrantee(acl.getGranteeType());
|
entries[i].setGrantee(acl.getGranteeType());
|
||||||
entries[i].setCanonicalUserID(acl.getGranteeCanonicalId());
|
entries[i].setCanonicalUserID(acl.getGranteeCanonicalId());
|
||||||
|
|||||||
@ -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 CloudSessionFactory {
|
|
||||||
private static CloudSessionFactory instance;
|
|
||||||
public static final Logger logger = Logger.getLogger(CloudSessionFactory.class);
|
|
||||||
|
|
||||||
private SessionFactory factory;
|
|
||||||
|
|
||||||
private CloudSessionFactory() {
|
|
||||||
Configuration cfg = new Configuration();
|
|
||||||
File file = ConfigurationHelper.findConfigurationFile("hibernate.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.awsapi.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 CloudSessionFactory getInstance() {
|
|
||||||
if(instance == null) {
|
|
||||||
instance = new CloudSessionFactory();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Session openSession() {
|
|
||||||
return factory.openSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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>
|
|
||||||
|
|
||||||
@ -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>
|
|
||||||
|
|
||||||
@ -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>
|
|
||||||
|
|
||||||
@ -223,6 +223,7 @@
|
|||||||
<fileset dir="${jar.dir}">
|
<fileset dir="${jar.dir}">
|
||||||
<include name="cloud-awsapi.jar" />
|
<include name="cloud-awsapi.jar" />
|
||||||
<include name="cloud-jasypt-1.8.jar" />
|
<include name="cloud-jasypt-1.8.jar" />
|
||||||
|
<include name="cloud-utils.jar" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="${server.deploy.to.dir}/webapps7080/awsapi/WEB-INF/lib">
|
<copy todir="${server.deploy.to.dir}/webapps7080/awsapi/WEB-INF/lib">
|
||||||
|
|||||||
@ -226,4 +226,31 @@ under the License.
|
|||||||
<dao name="Site2SiteVpnGatewayDao" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" singleton="false"/>
|
<dao name="Site2SiteVpnGatewayDao" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" singleton="false"/>
|
||||||
<dao name="Site2SiteVpnConnectionDao" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" singleton="false"/>
|
<dao name="Site2SiteVpnConnectionDao" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" singleton="false"/>
|
||||||
</configuration-server>
|
</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>
|
||||||
1
debian/cloud-deps.install
vendored
1
debian/cloud-deps.install
vendored
@ -27,7 +27,6 @@
|
|||||||
/usr/share/java/cloud-log4j.jar
|
/usr/share/java/cloud-log4j.jar
|
||||||
/usr/share/java/cloud-trilead-ssh2-build213.jar
|
/usr/share/java/cloud-trilead-ssh2-build213.jar
|
||||||
/usr/share/java/cloud-cglib.jar
|
/usr/share/java/cloud-cglib.jar
|
||||||
/usr/share/java/cloud-mysql-connector-java-5.1.7-bin.jar
|
|
||||||
/usr/share/java/cloud-xenserver-5.6.100-1.jar
|
/usr/share/java/cloud-xenserver-5.6.100-1.jar
|
||||||
/usr/share/java/cloud-xmlrpc-common-3.*.jar
|
/usr/share/java/cloud-xmlrpc-common-3.*.jar
|
||||||
/usr/share/java/cloud-xmlrpc-client-3.*.jar
|
/usr/share/java/cloud-xmlrpc-client-3.*.jar
|
||||||
|
|||||||
2
debian/control
vendored
2
debian/control
vendored
@ -86,7 +86,7 @@ Provides: vmops-client
|
|||||||
Conflicts: vmops-client
|
Conflicts: vmops-client
|
||||||
Replaces: vmops-client
|
Replaces: vmops-client
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: openjdk-6-jre, cloud-deps (= ${source:Version}), cloud-utils (= ${source:Version}), cloud-server (= ${source:Version}), cloud-client-ui (= ${source:Version}), cloud-setup (= ${source:Version}), cloud-python (= ${source:Version}), tomcat6, libws-commons-util-java, libcommons-dbcp-java, libcommons-collections-java, libcommons-httpclient-java, sysvinit-utils, chkconfig, sudo, jsvc, python-mysqldb, python-paramiko, augeas-tools, genisoimage, cloud-system-iso
|
Depends: openjdk-6-jre, cloud-deps (= ${source:Version}), cloud-utils (= ${source:Version}), cloud-server (= ${source:Version}), cloud-client-ui (= ${source:Version}), cloud-setup (= ${source:Version}), cloud-python (= ${source:Version}), tomcat6, libws-commons-util-java, libcommons-dbcp-java, libcommons-collections-java, libcommons-httpclient-java, sysvinit-utils, chkconfig, sudo, jsvc, python-mysqldb, python-paramiko, augeas-tools, genisoimage, cloud-system-iso, libmysql-java (>= 5.1)
|
||||||
Description: CloudStack client
|
Description: CloudStack client
|
||||||
The CloudStack management server is the central point of coordination,
|
The CloudStack management server is the central point of coordination,
|
||||||
management, and intelligence in the CloudStack Cloud Stack. This package
|
management, and intelligence in the CloudStack Cloud Stack. This package
|
||||||
|
|||||||
0
deps/awsapi-lib/cloud-cglib.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-cglib.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-commons-dbcp-1.4.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-commons-dbcp-1.4.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-commons-pool-1.5.6.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-commons-pool-1.5.6.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-ehcache.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-ehcache.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-javax.persistence-2.0.0.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-javax.persistence-2.0.0.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-utils.jar
vendored
Normal file
0
deps/awsapi-lib/cloud-utils.jar
vendored
Normal file
@ -79,6 +79,7 @@ public class Transaction {
|
|||||||
|
|
||||||
public static final short CLOUD_DB = 0;
|
public static final short CLOUD_DB = 0;
|
||||||
public static final short USAGE_DB = 1;
|
public static final short USAGE_DB = 1;
|
||||||
|
public static final short AWSAPI_DB = 2;
|
||||||
public static final short CONNECTED_DB = -1;
|
public static final short CONNECTED_DB = -1;
|
||||||
|
|
||||||
private static AtomicLong s_id = new AtomicLong();
|
private static AtomicLong s_id = new AtomicLong();
|
||||||
@ -223,7 +224,18 @@ public class Transaction {
|
|||||||
return null;
|
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) {
|
protected void attach(TransactionAttachment value) {
|
||||||
_stack.push(new StackElement(ATTACHMENT, value));
|
_stack.push(new StackElement(ATTACHMENT, value));
|
||||||
}
|
}
|
||||||
@ -525,8 +537,18 @@ public class Transaction {
|
|||||||
throw new CloudRuntimeException("Database is not initialized, process is dying?");
|
throw new CloudRuntimeException("Database is not initialized, process is dying?");
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
throw new CloudRuntimeException("No database selected for the transaction");
|
|
||||||
|
throw new CloudRuntimeException("No database selected for the transaction");
|
||||||
}
|
}
|
||||||
_conn.setAutoCommit(!_txn);
|
_conn.setAutoCommit(!_txn);
|
||||||
|
|
||||||
@ -953,6 +975,7 @@ public class Transaction {
|
|||||||
|
|
||||||
private static DataSource s_ds;
|
private static DataSource s_ds;
|
||||||
private static DataSource s_usageDS;
|
private static DataSource s_usageDS;
|
||||||
|
private static DataSource s_awsapiDS;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
|
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
|
||||||
@ -1035,6 +1058,17 @@ public class Transaction {
|
|||||||
final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(usageConnectionFactory, usageConnectionPool,
|
final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(usageConnectionFactory, usageConnectionPool,
|
||||||
new StackKeyedObjectPoolFactory(), null, false, false);
|
new StackKeyedObjectPoolFactory(), null, false, false);
|
||||||
s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool());
|
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) {
|
} catch (final Exception e) {
|
||||||
final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
|
final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
|
||||||
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud", "cloud", "cloud");
|
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud", "cloud", "cloud");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user