You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2012/09/12 16:43:20 UTC
svn commit: r1383979 - in
/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src:
main/java/org/apache/airavata/persistance/registry/jpa/
main/java/org/apache/airavata/persistance/registry/jpa/resources/
main/resources/META-INF/ test/java...
Author: lahiru
Date: Wed Sep 12 14:43:20 2012
New Revision: 1383979
URL: http://svn.apache.org/viewvc?rev=1383979&view=rev
Log:
adding patch by chathuri for AIRAVATA-562
Modified:
incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml
incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java?rev=1383979&r1=1383978&r2=1383979&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java Wed Sep 12 14:43:20 2012
@@ -24,10 +24,7 @@ import org.apache.airavata.persistance.r
import org.apache.airavata.persistance.registry.jpa.model.Gateway;
import org.apache.airavata.persistance.registry.jpa.model.Gateway_Worker;
import org.apache.airavata.persistance.registry.jpa.model.Users;
-import org.apache.airavata.persistance.registry.jpa.resources.AbstractResource;
-import org.apache.airavata.persistance.registry.jpa.resources.ConfigurationResource;
-import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource;
-import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
+import org.apache.airavata.persistance.registry.jpa.resources.*;
import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
import javax.persistence.EntityManager;
@@ -35,13 +32,31 @@ import javax.persistence.EntityManagerFa
import javax.persistence.Persistence;
import javax.persistence.Query;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class ResourceUtils {
private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
protected static EntityManagerFactory factory;
protected static EntityManager em;
+ public static EntityManager getEntityManager(){
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("openjpa.ConnectionURL", Utils.getJDBCURL());
+ properties.put("openjpa.ConnectionDriverName", Utils.getJDBCDriver());
+ properties.put("openjpa.ConnectionUserName",Utils.getJDBCUser());
+ properties.put("openjpa.ConnectionPassword",Utils.getJDBCPassword());
+ properties.put("openjpa.DynamicEnhancementAgent","true");
+ properties.put("openjpa.RuntimeUnenhancedClasses","supported");
+ properties.put("openjpa.Log","SQL=ERROR");
+ properties.put("openjpa.ConnectionFactoryProperties","PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000");
+
+ factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+ em = factory.createEntityManager();
+ return em;
+ }
+
/**
* @param gatewayName
* @return
@@ -61,15 +76,14 @@ public class ResourceUtils {
* @return
*/
public static boolean isGatewayExist(String gatewayName) {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
Query q = generator.selectQuery(em);
Gateway gateway = (Gateway) q.getSingleResult();
em.getTransaction().commit();
- em.close();
+// em.close();
return gateway != null;
}
@@ -79,15 +93,14 @@ public class ResourceUtils {
*/
public static boolean removeGateway(String gatewayName) {
try {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY);
generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName);
Query q = generator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
- em.close();
+// em.close();
return true;
} catch (Exception e) {
e.printStackTrace();
@@ -103,8 +116,7 @@ public class ResourceUtils {
*/
public static void addGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
try {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
Gateway gateway = new Gateway();
gateway.setGateway_name(gatewayResource.getGatewayName());
@@ -115,7 +127,7 @@ public class ResourceUtils {
gatewayWorker.setUser(user);
em.persist(gatewayWorker);
em.getTransaction().commit();
- em.close();
+// em.close();
} catch (Exception e) {
e.printStackTrace();
}
@@ -129,8 +141,7 @@ public class ResourceUtils {
*/
public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
try {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER);
generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME,
@@ -139,7 +150,7 @@ public class ResourceUtils {
Query q = generator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
- em.close();
+// em.close();
return true;
} catch (Exception e) {
e.printStackTrace();
@@ -154,8 +165,7 @@ public class ResourceUtils {
*/
public static List<ConfigurationResource> getConfigurations(String configKey) {
List<ConfigurationResource> list = new ArrayList<ConfigurationResource>();
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractResource.CONFIGURATION);
generator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configKey);
@@ -168,7 +178,7 @@ public class ResourceUtils {
}
}
em.getTransaction().commit();
- em.close();
+// em.close();
return list;
}
@@ -219,8 +229,7 @@ public class ResourceUtils {
* @param configValue
*/
public static void removeConfiguration(String configkey, String configValue) {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
// Query q = em.createQuery("Delete FROM Configuration p WHERE p.config_key = :configKey and p.config_val = :configVal");
// q.setParameter("configKey", configkey);
@@ -231,7 +240,7 @@ public class ResourceUtils {
Query q = queryGenerator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
- em.close();
+// em.close();
}
@@ -239,14 +248,13 @@ public class ResourceUtils {
* @param configkey
*/
public static void removeConfiguration(String configkey) {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = getEntityManager();
em.getTransaction().begin();
QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
Query q = queryGenerator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
- em.close();
+// em.close();
}
}
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java?rev=1383979&r1=1383978&r2=1383979&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java Wed Sep 12 14:43:20 2012
@@ -22,14 +22,11 @@ package org.apache.airavata.persistance.
import org.apache.airavata.persistance.registry.jpa.Resource;
import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
public abstract class AbstractResource implements Resource {
- private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
- protected EntityManagerFactory factory;
protected EntityManager em;
//table names
@@ -137,16 +134,13 @@ public abstract class AbstractResource i
}
-
protected AbstractResource() {
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = ResourceUtils.getEntityManager();
}
protected void begin() {
if(em == null){
- factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
- em = factory.createEntityManager();
+ em = ResourceUtils.getEntityManager();
}
em.getTransaction().begin();
}
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java?rev=1383979&r1=1383978&r2=1383979&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java Wed Sep 12 14:43:20 2012
@@ -24,9 +24,54 @@ import org.apache.airavata.persistance.r
import org.apache.airavata.persistance.registry.jpa.ResourceType;
import org.apache.airavata.persistance.registry.jpa.model.*;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
public class Utils {
+ public static Properties loadProperties(){
+ URL resource = Utils.class.getClassLoader().getResource("repository.properties");
+ Properties properties = new Properties();
+ try {
+ properties.load(resource.openStream());
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ return properties;
+ }
+
+ public static String getJDBCFullURL(){
+ String jdbcUrl = null;
+ Properties properties = loadProperties();
+ jdbcUrl = properties.getProperty("registry.jdbc.url");
+ String jdbcUser = properties.getProperty("registry.jdbc.user");
+ String jdbcPassword = properties.getProperty("registry.jdbc.password");
+ jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
+ return jdbcUrl;
+ }
+
+ public static String getJDBCURL(){
+ Properties properties = loadProperties();
+ return properties.getProperty("registry.jdbc.url");
+ }
+
+ public static String getJDBCUser(){
+ Properties properties = loadProperties();
+ return properties.getProperty("registry.jdbc.user");
+ }
+
+ public static String getJDBCPassword(){
+ Properties properties = loadProperties();
+ return properties.getProperty("registry.jdbc.password");
+ }
+
+ public static String getJDBCDriver(){
+ Properties properties = loadProperties();
+ return properties.getProperty("registry.jdbc.driver");
+ }
+
/**
*
* @param type model type
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml?rev=1383979&r1=1383978&r2=1383979&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/META-INF/persistence.xml Wed Sep 12 14:43:20 2012
@@ -53,9 +53,9 @@
<class>org.apache.airavata.persistance.registry.jpa.model.Service_Descriptor</class>
<class>org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor</class>
<class>org.apache.airavata.persistance.registry.jpa.model.Experiment</class>
- <properties>
+ <!--properties>
<property name="openjpa.ConnectionURL"
- value="jdbc:mysql://140.182.193.104:3306/persitant_data" />
+ value="jdbc:mysql://localhost:3306/persitant_data" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="airavata" />
<property name="openjpa.ConnectionPassword" value="airavata" />
@@ -64,6 +64,6 @@
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionFactoryProperties"
value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000" />
- </properties>
+ </properties-->
</persistence-unit>
-</persistence>
\ No newline at end of file
+</persistence>
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java?rev=1383979&r1=1383978&r2=1383979&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java Wed Sep 12 14:43:20 2012
@@ -14,9 +14,9 @@ public class GatewayResourceTest extends
public void setUp() throws Exception {
super.setUp();
- gatewayResource = new GatewayResource();
- gatewayResource.setGatewayName("default");
- gatewayResource.setOwner("default");
+// gatewayResource = new GatewayResource();
+// gatewayResource.setGatewayName("default");
+// gatewayResource.setOwner("default");
}
public void testSave() throws Exception {
@@ -24,30 +24,35 @@ public class GatewayResourceTest extends
}
public void testCreate() throws Exception {
- boolean result;
- HostDescriptorResource hostDescriptorResource = (HostDescriptorResource)gatewayResource.create(ResourceType.HOST_DESCRIPTOR);
- hostDescriptorResource.setHostDescName("Localhost");
- hostDescriptorResource.setUserName("admin");
- hostDescriptorResource.save();
- result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost");
- assertTrue("The result doesn't exists", result == true);
-
- ProjectResource projectResource = (ProjectResource)gatewayResource.create(ResourceType.PROJECT);
- projectResource.setName("project1");
- WorkerResource workerResource = new WorkerResource();
- workerResource.setGateway(gatewayResource);
- workerResource.setUser("admin");
- projectResource.setWorker(workerResource);
- projectResource.save();
+// boolean result;
+// HostDescriptorResource hostDescriptorResource = gatewayResource.createHostDescriptorResource("Localhost");
+//// hostDescriptorResource.setHostDescName("Localhost");
+// hostDescriptorResource.setUserName("admin");
+// hostDescriptorResource.setContent("<hostDescription xmlns=\"http://schemas.airavata.apache.org/gfac/type\">\n" +
+// " <hostName>LocalHost</hostName>\n" +
+// " <hostAddress>127.0.0.1</hostAddress>\n" +
+// "</hostDescription>");
+// hostDescriptorResource.save();
+// result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost");
+// assertTrue("The result doesn't exists", result == true);
+
+
+// ProjectResource projectResource = (ProjectResource)gatewayResource.create(ResourceType.PROJECT);
+// projectResource.setName("project1");
+// WorkerResource workerResource = new WorkerResource();
+// workerResource.setGateway(gatewayResource);
+// workerResource.setUser("admin");
+// projectResource.setWorker(workerResource);
+// projectResource.save();
// result = workerResource.isProjectExists("project1");
// assertTrue("The result doesn't exists", result == true);
}
public void testIsExists() throws Exception {
- boolean result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost");
-
- assertTrue("The result doesn't exists", result == true);
+// boolean result = gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "Localhost");
+//
+// assertTrue("The result doesn't exists", result == true);
// result = gatewayResource.isExists(ResourceType.USER, "admin");
//