Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04BFC1944F for ; Thu, 24 Mar 2016 15:25:29 +0000 (UTC) Received: (qmail 65313 invoked by uid 500); 24 Mar 2016 15:25:28 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 65172 invoked by uid 500); 24 Mar 2016 15:25:28 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 65030 invoked by uid 99); 24 Mar 2016 15:25:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Mar 2016 15:25:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B9CC5DFDE0; Thu, 24 Mar 2016 15:25:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: scnakandala@apache.org To: commits@airavata.apache.org Date: Thu, 24 Mar 2016 15:25:28 -0000 Message-Id: <62327e7761754bcdb7df9f791e7ab3a0@git.apache.org> In-Reply-To: <92d2febdb0e14054b426a3bcca1f3edc@git.apache.org> References: <92d2febdb0e14054b426a3bcca1f3edc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [02/10] airavata git commit: renaming data-catalog to replica catalog http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogJPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogJPAUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogJPAUtils.java deleted file mode 100644 index b8257cb..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogJPAUtils.java +++ /dev/null @@ -1,82 +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 org.apache.airavata.registry.core.data.catalog.utils; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; - -public class DataCatalogJPAUtils { - private final static Logger logger = LoggerFactory.getLogger(DataCatalogJPAUtils.class); - - private static final String PERSISTENCE_UNIT_NAME = "datacatalog_data"; - private static final String DATACATALOG_JDBC_DRIVER = "datacatalog.jdbc.driver"; - private static final String DATACATALOG_JDBC_URL = "datacatalog.jdbc.url"; - private static final String DATACATALOG_JDBC_USER = "datacatalog.jdbc.user"; - private static final String DATACATALOG_JDBC_PWD = "datacatalog.jdbc.password"; - private static final String DATACATALOG_VALIDATION_QUERY = "datacatalog.validationQuery"; - - @PersistenceUnit(unitName="datacatalog_data") - protected static EntityManagerFactory factory; - - @PersistenceContext(unitName="datacatalog_data") - private static EntityManager dataCatEntityManager; - - public static EntityManager getEntityManager() throws ApplicationSettingsException { - if (factory == null) { - String connectionProperties = "DriverClassName=" + readServerProperties(DATACATALOG_JDBC_DRIVER) + "," + - "Url=" + readServerProperties(DATACATALOG_JDBC_URL) + "?autoReconnect=true," + - "Username=" + readServerProperties(DATACATALOG_JDBC_USER) + "," + - "Password=" + readServerProperties(DATACATALOG_JDBC_PWD) + - ",validationQuery=" + readServerProperties(DATACATALOG_VALIDATION_QUERY); - System.out.println(connectionProperties); - Map properties = new HashMap(); - properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); - properties.put("openjpa.ConnectionProperties", connectionProperties); - properties.put("openjpa.DynamicEnhancementAgent", "true"); - properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported"); - properties.put("openjpa.RemoteCommitProvider","sjvm"); - properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.jdbc.QuerySQLCache", "false"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," + - " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true"); - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties); - } - dataCatEntityManager = factory.createEntityManager(); - return dataCatEntityManager; - } - - private static String readServerProperties (String propertyName) throws ApplicationSettingsException { - try { - return ServerSettings.getSetting(propertyName); - } catch (ApplicationSettingsException e) { - logger.error("Unable to read airavata-server.properties...", e); - throw new ApplicationSettingsException("Unable to read airavata-server.properties..."); - } - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogQueryGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogQueryGenerator.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogQueryGenerator.java deleted file mode 100644 index 4ddf8d3..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/DataCatalogQueryGenerator.java +++ /dev/null @@ -1,111 +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 org.apache.airavata.registry.core.data.catalog.utils; - -import org.apache.airavata.registry.cpi.ResultOrderType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.util.HashMap; -import java.util.Map; - -public class DataCatalogQueryGenerator { - - private final static Logger logger = LoggerFactory.getLogger(DataCatalogQueryGenerator.class); - private String tableName; - private Map matches=new HashMap(); - private static final String SELECT_OBJ="p"; - private static final String DELETE_OBJ="p"; - private static final String TABLE_OBJ="p"; - - public DataCatalogQueryGenerator(String tableName, Object[]... params) { - setTableName(tableName); - for (Object[] param : params) { - addMatch(param[0].toString(), param[1]); - } - } - - public String getTableName() { - return tableName; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - public void addMatch(String colName, Object matchValue){ - matches.put(colName, matchValue); - } - - public void setParameter(String colName, Object matchValue){ - addMatch(colName, matchValue); - } - - public Query selectQuery(EntityManager entityManager){ - String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ; - return generateQueryWithParameters(entityManager, queryString); - } - - public Query selectQuery(EntityManager entityManager, String orderByColumn, - ResultOrderType resultOrderType){ - String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC"; - String orderByClause = " ORDER BY " + SELECT_OBJ + "." + orderByColumn + " " + order; - String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ; - return generateQueryWithParameters(entityManager, queryString, orderByClause); - } - - public Query deleteQuery(EntityManager entityManager){ - String queryString="Delete FROM "+getTableName()+" "+TABLE_OBJ; - return generateQueryWithParameters(entityManager, queryString); - } - - private Query generateQueryWithParameters(EntityManager entityManager, String queryString) { - return generateQueryWithParameters(entityManager, queryString, ""); - } - - private Query generateQueryWithParameters(EntityManager entityManager, - String queryString, String orderByClause) { - Map queryParameters=new HashMap(); - if (matches.size()>0){ - String matchString = ""; - int paramCount=0; - for (String colName : matches.keySet()) { - String paramName="param"+paramCount; - queryParameters.put(paramName, matches.get(colName)); - if (!matchString.equals("")){ - matchString+=" AND "; - } - matchString+=TABLE_OBJ+"."+colName+" =:"+paramName; - paramCount++; - } - queryString+=" WHERE "+matchString; - } - queryString += orderByClause; - Query query = entityManager.createQuery(queryString); - for (String paramName : queryParameters.keySet()) { - query.setParameter(paramName, queryParameters.get(paramName)); - } - return query; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/ThriftDataModelConversion.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/ThriftDataModelConversion.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/ThriftDataModelConversion.java deleted file mode 100644 index 5426e8b..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/data/catalog/utils/ThriftDataModelConversion.java +++ /dev/null @@ -1,215 +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 org.apache.airavata.registry.core.data.catalog.utils; - -import org.apache.airavata.model.data.product.*; -import org.apache.airavata.registry.core.data.catalog.model.DataProduct; -import org.apache.airavata.registry.core.data.catalog.model.DataProductMetaData; -import org.apache.airavata.registry.core.data.catalog.model.DataReplicaLocation; -import org.apache.airavata.registry.core.data.catalog.model.DataReplicaMetaData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public class ThriftDataModelConversion { - - private final static Logger logger = LoggerFactory.getLogger(ThriftDataModelConversion.class); - - public static DataProductModel getDataProductModel(DataProduct dataProduct){ - if (dataProduct != null) { - DataProductModel dataProductModel = new DataProductModel(); - dataProductModel.setProductUri(dataProduct.getProductUri()); - dataProductModel.setLogicalPath(dataProduct.getLogicalPath()); - dataProductModel.setGatewayId(dataProduct.getGatewayId()); - dataProductModel.setParentProductUri(dataProduct.getParentProductUri()); - dataProductModel.setProductName(dataProduct.getProductName()); - if(dataProduct.getDataProductType() != null) - dataProductModel.setDataProductType(DataProductType.valueOf(dataProduct.getDataProductType())); - else - dataProductModel.setDataProductType(DataProductType.FILE); - dataProductModel.setProductDescription(dataProduct.getProductDescription()); - dataProductModel.setOwnerName(dataProduct.getOwnerName()); - dataProductModel.setProductSize(dataProduct.getProductSize()); - if(dataProduct.getCreationTime() != null) - dataProductModel.setCreationTime(dataProduct.getCreationTime().getTime()); - if(dataProduct.getLastModifiedTime() != null) - dataProductModel.setLastModifiedTime(dataProduct.getLastModifiedTime().getTime()); - dataProductModel.setProductMetadata(getResourceMetaData(dataProduct.getDataProductMetaData())); - if(dataProduct.getDataReplicaLocations() != null){ - ArrayList dataReplicaLocationModels = new ArrayList<>(); - dataProduct.getDataReplicaLocations().stream().forEach(r->dataReplicaLocationModels - .add(getDataReplicaLocationModel(r))); - dataProductModel.setReplicaLocations(dataReplicaLocationModels); - } - if(dataProductModel.getDataProductType().equals(DataProductType.COLLECTION) && dataProduct.getChildDataProducts() != null){ - ArrayList childDataProducts = new ArrayList<>(); - dataProduct.getChildDataProducts().stream().forEach(r->childDataProducts.add(getDataProductModel(r))); - dataProductModel.setChildProducts(childDataProducts); - } - return dataProductModel; - } - return null; - } - - public static DataProduct getDataProduct(DataProductModel dataProductModel){ - if(dataProductModel != null){ - DataProduct dataProduct = new DataProduct(); - return getUpdatedDataProduct(dataProductModel, dataProduct); - } - return null; - } - - public static DataProduct getUpdatedDataProduct(DataProductModel dataProductModel, DataProduct dataProduct){ - dataProduct.setProductUri(dataProductModel.getProductUri()); - dataProduct.setLogicalPath(dataProductModel.getLogicalPath()); - dataProduct.setGatewayId(dataProductModel.getGatewayId()); - dataProduct.setProductName(dataProductModel.getProductName()); - dataProduct.setParentProductUri(dataProductModel.getParentProductUri()); - if(dataProductModel.getDataProductType() != null) - dataProduct.setDataProductType(dataProductModel.getDataProductType().toString()); - else - dataProduct.setDataProductType(DataProductType.FILE.toString()); - dataProduct.setProductDescription(dataProductModel.getProductDescription()); - dataProduct.setOwnerName(dataProductModel.getOwnerName()); - dataProduct.setProductSize(dataProductModel.getProductSize()); - if(dataProductModel.getCreationTime() > 0) - dataProduct.setCreationTime(new Timestamp(dataProductModel.getCreationTime())); - if(dataProductModel.getLastModifiedTime() > 0) - dataProduct.setLastModifiedTime(new Timestamp(dataProductModel.getLastModifiedTime())); - ArrayList dataProductMetaData = new ArrayList<>(); - if(dataProductModel.getProductMetadata() != null) { - dataProductModel.getProductMetadata().keySet().stream().forEach(k -> { - String v = dataProductModel.getProductMetadata().get(k); - DataProductMetaData temp = new DataProductMetaData(); - temp.setProductUri(dataProduct.getProductUri()); - temp.setKey(k); - temp.setValue(v); - dataProductMetaData.add(temp); - }); - dataProduct.setDataProductMetaData(dataProductMetaData); - } - if(dataProductModel.getReplicaLocations() != null){ - ArrayList dataReplicaLocations = new ArrayList<>(); - dataProductModel.getReplicaLocations().stream().forEach(r->{ - DataReplicaLocation dataReplicaLocationModel = getDataReplicaLocation(r); - dataReplicaLocationModel.setProductUri(dataProductModel.getProductUri()); - dataReplicaLocations.add(dataReplicaLocationModel); - }); - dataProduct.setDataReplicaLocations(dataReplicaLocations); - } - if(dataProductModel.getDataProductType() == DataProductType.COLLECTION && dataProductModel.getChildProducts() != null){ - ArrayList childDataProducts = new ArrayList<>(); - dataProductModel.getChildProducts().stream().forEach(r->childDataProducts.add(getDataProduct(r))); - dataProduct.setChildDataProducts(childDataProducts); - } - return dataProduct; - } - - public static DataReplicaLocationModel getDataReplicaLocationModel(DataReplicaLocation replicaLocation){ - if (replicaLocation != null) { - DataReplicaLocationModel replicaLocationModel = new DataReplicaLocationModel(); - replicaLocationModel.setReplicaId(replicaLocation.getReplicaId()); - replicaLocationModel.setProductUri(replicaLocation.getProductUri()); - replicaLocationModel.setReplicaName(replicaLocation.getReplicaName()); - replicaLocationModel.setReplicaDescription(replicaLocation.getReplicaDescription()); - replicaLocationModel.setStorageResourceId(replicaLocation.getStorageResourceId()); - if(replicaLocation.getValidUntilTime() != null) - replicaLocationModel.setValidUntilTime(replicaLocation.getValidUntilTime().getTime()); - replicaLocationModel.setFilePath(replicaLocation.getFilePath()); - if(replicaLocation.getCreationTime() != null) - replicaLocationModel.setCreationTime(replicaLocation.getCreationTime().getTime()); - if(replicaLocation.getLastModifiedTime() != null) - replicaLocationModel.setLastModifiedTime(replicaLocation.getLastModifiedTime().getTime()); - if(replicaLocation.getReplicaLocationCategory() != null) - replicaLocationModel.setReplicaLocationCategory(ReplicaLocationCategory.valueOf(replicaLocation - .getReplicaLocationCategory().toString())); - if(replicaLocation.getReplicaPersistentType() != null) - replicaLocationModel.setReplicaPersistentType(ReplicaPersistentType.valueOf(replicaLocation - .getReplicaPersistentType().toString())); - replicaLocationModel.setReplicaMetadata(getReplicaMetaData(replicaLocation.getDataReplicaMetaData())); - return replicaLocationModel; - } - return null; - } - - public static DataReplicaLocation getDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel){ - if(dataReplicaLocationModel != null){ - DataReplicaLocation dataReplicaLocation = new DataReplicaLocation(); - return getUpdatedDataReplicaLocation(dataReplicaLocationModel, dataReplicaLocation); - } - return null; - } - - public static DataReplicaLocation getUpdatedDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel, - DataReplicaLocation dataReplicaLocation){ - dataReplicaLocation.setReplicaId(dataReplicaLocationModel.getReplicaId()); - dataReplicaLocation.setProductUri(dataReplicaLocationModel.getProductUri()); - dataReplicaLocation.setReplicaName(dataReplicaLocationModel.getReplicaName()); - dataReplicaLocation.setReplicaDescription(dataReplicaLocationModel.getReplicaDescription()); - dataReplicaLocation.setStorageResourceId(dataReplicaLocationModel.getStorageResourceId()); - dataReplicaLocation.setFilePath(dataReplicaLocationModel.getFilePath()); - if(dataReplicaLocationModel.getValidUntilTime() > 0) - dataReplicaLocation.setValidUntilTime(new Timestamp(dataReplicaLocationModel.getValidUntilTime())); - if(dataReplicaLocationModel.getCreationTime() > 0) - dataReplicaLocation.setCreationTime(new Timestamp(dataReplicaLocationModel.getCreationTime())); - if(dataReplicaLocationModel.getLastModifiedTime() > 0) - dataReplicaLocation.setLastModifiedTime(new Timestamp(dataReplicaLocationModel.getLastModifiedTime())); - if(dataReplicaLocationModel.getReplicaLocationCategory() != null) - dataReplicaLocation.setReplicaLocationCategory(dataReplicaLocationModel.getReplicaLocationCategory().toString()); - if(dataReplicaLocationModel.getReplicaPersistentType() != null) - dataReplicaLocation.setReplicaPersistentType(dataReplicaLocationModel.getReplicaPersistentType().toString()); - ArrayList dataReplicaMetadata = new ArrayList<>(); - if(dataReplicaLocation.getDataReplicaMetaData() != null){ - dataReplicaLocationModel.getReplicaMetadata().keySet().stream().forEach(k -> { - String v = dataReplicaLocationModel.getReplicaMetadata().get(k); - DataReplicaMetaData temp = new DataReplicaMetaData(); - temp.setReplicaId(dataReplicaLocationModel.getProductUri()); - temp.setKey(k); - temp.setValue(v); - dataReplicaMetadata.add(temp); - }); - dataReplicaLocation.setDataReplicaMetaData(dataReplicaMetadata); - } - return dataReplicaLocation; - } - - public static Map getResourceMetaData(Collection dataProductMetaData){ - HashMap metadata = new HashMap<>(); - if(dataProductMetaData!=null && !dataProductMetaData.isEmpty()) { - dataProductMetaData.stream().forEach(m -> metadata.put(m.getKey(),m.getValue())); - } - return metadata; - } - - public static Map getReplicaMetaData(Collection dataReplicaMetaData){ - HashMap metadata = new HashMap<>(); - if(dataReplicaMetaData!=null && !dataReplicaMetaData.isEmpty()) { - dataReplicaMetaData.stream().forEach(m -> metadata.put(m.getKey(),m.getValue())); - } - return metadata; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java index 41a9f13..8e4ed08 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/RegistryFactory.java @@ -24,7 +24,7 @@ package org.apache.airavata.registry.core.experiment.catalog.impl; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.registry.core.app.catalog.impl.AppCatalogImpl; -import org.apache.airavata.registry.core.data.catalog.impl.DataCatalogImpl; +import org.apache.airavata.registry.core.replica.catalog.impl.ReplicaCatalogImpl; import org.apache.airavata.registry.core.impl.RegistryImpl; import org.apache.airavata.registry.cpi.*; import org.slf4j.Logger; @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; public class RegistryFactory { private static ExperimentCatalog experimentCatalog; private static AppCatalog appCatalog; - private static DataCatalog replicaCatalog; + private static ReplicaCatalog replicaCatalog; private static Registry registry; private static Logger logger = LoggerFactory.getLogger(RegistryFactory.class); @@ -100,14 +100,14 @@ public class RegistryFactory { return appCatalog; } - public static DataCatalog getDataCatalog() throws DataCatalogException { + public static ReplicaCatalog getReplicaCatalog() throws ReplicaCatalogException { try { if (replicaCatalog == null) { - replicaCatalog = new DataCatalogImpl(); + replicaCatalog = new ReplicaCatalogImpl(); } } catch (Exception e) { logger.error("Unable to create data catalog instance", e); - throw new DataCatalogException(e); + throw new ReplicaCatalogException(e); } return replicaCatalog; } http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/impl/RegistryImpl.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/impl/RegistryImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/impl/RegistryImpl.java index 5207fee..0e3c006 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/impl/RegistryImpl.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/impl/RegistryImpl.java @@ -22,7 +22,7 @@ package org.apache.airavata.registry.core.impl; import org.apache.airavata.registry.core.app.catalog.impl.AppCatalogImpl; -import org.apache.airavata.registry.core.data.catalog.impl.DataCatalogImpl; +import org.apache.airavata.registry.core.replica.catalog.impl.ReplicaCatalogImpl; import org.apache.airavata.registry.core.experiment.catalog.impl.ExperimentCatalogImpl; import org.apache.airavata.registry.cpi.*; @@ -43,7 +43,7 @@ public class RegistryImpl implements Registry { } @Override - public DataCatalog getDataCatalog() throws RegistryException { - return new DataCatalogImpl(); + public ReplicaCatalog getReplicaCatalog() throws RegistryException { + return new ReplicaCatalogImpl(); } } http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java new file mode 100644 index 0000000..2da6724 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java @@ -0,0 +1,356 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.impl; + +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.data.replica.DataProductType; +import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.registry.core.replica.catalog.model.DataProduct; +import org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation; +import org.apache.airavata.registry.core.replica.catalog.utils.ReplicaCatalogJPAUtils; +import org.apache.airavata.registry.core.replica.catalog.utils.ThriftDataModelConversion; +import org.apache.airavata.registry.cpi.ReplicaCatalog; +import org.apache.airavata.registry.cpi.ReplicaCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class ReplicaCatalogImpl implements ReplicaCatalog { + + private final static Logger logger = LoggerFactory.getLogger(ReplicaCatalogImpl.class); + + @Override + public String registerDataProduct(DataProductModel productModel) throws ReplicaCatalogException { + if(productModel.getOwnerName() == null || productModel.getGatewayId() == null || productModel + .getLogicalPath() == null || !productModel.getLogicalPath().startsWith("/")){ + throw new ReplicaCatalogException("owner name, gateway id and logical path should be non empty and logical path" + + " should start with /"); + } + if(productModel.getDataProductType().equals(DataProductType.FILE) && !productModel.getLogicalPath().endsWith(productModel.getProductName())){ + if(!productModel.getLogicalPath().endsWith("/")) + productModel.setLogicalPath(productModel.getLogicalPath()+"/"); + productModel.setLogicalPath(productModel.getLogicalPath()+productModel.getProductName()); + } + //Creating parent logical dir if not exist too + String parentUri = ReplicaCatalog.schema + "://" + productModel.getOwnerName() + "@" + productModel.getGatewayId() + ":/" ; + DataProductModel tempDp; + if(!isExists(parentUri)){ + tempDp = new DataProductModel(); + tempDp.setProductUri(parentUri); + tempDp.setLogicalPath("/"); + tempDp.setOwnerName(productModel.getOwnerName()); + tempDp.setGatewayId(productModel.getGatewayId()); + tempDp.setDataProductType(DataProductType.DIR); + createDataProduct(tempDp); + } + String[] bits = productModel.getLogicalPath().split("/"); + for(int i=0; i { + r.setProductUri(productUri); + r.setReplicaId(UUID.randomUUID().toString()); + r.setCreationTime(currentTime); + r.setLastModifiedTime(currentTime); + }); + } + productModel.setCreationTime(System.currentTimeMillis()); + productModel.setLastModifiedTime(System.currentTimeMillis()); + return createDataProduct(productModel); + } + + private String createDataProduct(DataProductModel productModel) throws ReplicaCatalogException { + DataProduct dataProduct = ThriftDataModelConversion.getDataProduct(productModel); + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + em.persist(dataProduct); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return dataProduct.getProductUri(); + } + + @Override + public boolean removeDataProduct(String productUri) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataProduct dataProduct = em.find(DataProduct.class, productUri); + if(dataProduct == null) + return false; + em.getTransaction().begin(); + em.remove(dataProduct); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return true; + } + + @Override + public boolean updateDataProduct(DataProductModel productModel) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataProduct dataProduct = em.find(DataProduct.class, productModel.getProductUri()); + if(dataProduct == null) + return false; + em.getTransaction().begin(); + productModel.setCreationTime(dataProduct.getCreationTime().getTime()); + productModel.setLastModifiedTime(System.currentTimeMillis()); + em.merge(ThriftDataModelConversion.getUpdatedDataProduct(productModel, dataProduct)); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return true; + } + + @Override + public DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataProduct dataProduct = em.find(DataProduct.class, productUri); + return ThriftDataModelConversion.getDataProductModel(dataProduct); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public boolean isExists(String productUri) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataProduct dataProduct = em.find(DataProduct.class, productUri); + return dataProduct != null; + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException { + String replicaId = UUID.randomUUID().toString(); + dataReplicaLocationModel.setReplicaId(replicaId); + long currentTime = System.currentTimeMillis(); + dataReplicaLocationModel.setCreationTime(currentTime); + dataReplicaLocationModel.setLastModifiedTime(currentTime); + dataReplicaLocationModel.setCreationTime(System.currentTimeMillis()); + dataReplicaLocationModel.setLastModifiedTime(System.currentTimeMillis()); + DataReplicaLocation replicaLocation = ThriftDataModelConversion.getDataReplicaLocation(dataReplicaLocationModel); + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + em.persist(replicaLocation); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return replicaId; + } + + @Override + public boolean removeReplicaLocation(String replicaId) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataReplicaLocation replicaLocation = em.find(DataReplicaLocation.class, replicaId); + if(replicaLocation == null) + return false; + em.getTransaction().begin(); + em.remove(replicaLocation); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return true; + } + + @Override + public boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataReplicaLocation dataReplicaLocation = em.find(DataReplicaLocation.class, dataReplicaLocationModel.getReplicaId()); + if(dataReplicaLocation == null) + return false; + em.getTransaction().begin(); + dataReplicaLocationModel.setCreationTime(dataReplicaLocation.getCreationTime().getTime()); + dataReplicaLocationModel.setLastModifiedTime(System.currentTimeMillis()); + em.merge(ThriftDataModelConversion.getUpdatedDataReplicaLocation(dataReplicaLocationModel, dataReplicaLocation)); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return true; + } + + @Override + public DataReplicaLocationModel getReplicaLocation(String replicaId) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataReplicaLocation replicaLocation = em.find(DataReplicaLocation.class, replicaId); + return ThriftDataModelConversion.getDataReplicaLocationModel(replicaLocation); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public List getAllReplicaLocations(String productUri) throws ReplicaCatalogException { + EntityManager em = null; + try { + em = ReplicaCatalogJPAUtils.getEntityManager(); + DataProduct dataProduct = em.find(DataProduct.class, productUri); + if(dataProduct == null) + return null; + ArrayList dataReplicaLocationModels = new ArrayList<>(); + dataProduct.getDataReplicaLocations().stream().forEach(rl->dataReplicaLocationModels + .add(ThriftDataModelConversion.getDataReplicaLocationModel(rl))); + return dataReplicaLocationModels; + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ReplicaCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/Configuration.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/Configuration.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/Configuration.java new file mode 100644 index 0000000..881d043 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/Configuration.java @@ -0,0 +1,55 @@ +/* +* +* 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.apache.airavata.registry.core.app.catalog.model.Configuration_PK; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name ="CONFIGURATION") +@IdClass(Configuration_PK.class) +public class Configuration implements Serializable { + @Id + @Column(name = "CONFIG_KEY") + private String config_key; + + @Id + @Column(name = "CONFIG_VAL") + private String config_val; + + public String getConfig_key() { + return config_key; + } + + public String getConfig_val() { + return config_val; + } + + public void setConfig_key(String config_key) { + this.config_key = config_key; + } + + public void setConfig_val(String config_val) { + this.config_val = config_val; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProduct.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProduct.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProduct.java new file mode 100644 index 0000000..7a48f87 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProduct.java @@ -0,0 +1,187 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Collection; + +@Entity +@Table(name = "DATA_PRODUCT") +public class DataProduct { + private final static Logger logger = LoggerFactory.getLogger(DataProduct.class); + private String productUri; + private String gatewayId; + private String productName; + private String logicalPath; + private String productDescription; + private String dataProductType; + private String ownerName; + private String parentProductUri; + private int productSize; + private Timestamp creationTime; + private Timestamp lastModifiedTime; + + private DataProduct parentDataProduct; + private Collection dataReplicaLocations; + private Collection dataProductMetaData; + private Collection childDataProducts; + + @Id + @Column(name = "PRODUCT_URI") + public String getProductUri() { + return productUri; + } + + public void setProductUri(String productUri) { + this.productUri = productUri; + } + + @Column(name = "GATEWAY_ID") + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + @Column(name = "PRODUCT_NAME") + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + @Column(name = "PRODUCT_DESCRIPTION") + public String getProductDescription() { + return productDescription; + } + + public void setProductDescription(String productDescription) { + this.productDescription = productDescription; + } + + @Column(name = "LOGICAL_PATH") + public String getLogicalPath() { + return logicalPath; + } + + public void setLogicalPath(String logicalPath) { + this.logicalPath = logicalPath; + } + + @Column(name = "OWNER_NAME") + public String getOwnerName() { + return ownerName; + } + + public void setOwnerName(String ownerName) { + this.ownerName = ownerName; + } + + @Column(name = "PARENT_PRODUCT_URI") + public String getParentProductUri() { + return parentProductUri; + } + + public void setParentProductUri(String parentProductUri) { + this.parentProductUri = parentProductUri; + } + + @Column(name = "PRODUCT_TYPE") + public String getDataProductType() { + return dataProductType; + } + + public void setDataProductType(String dataProductType) { + this.dataProductType = dataProductType; + } + + @Column(name = "PRODUCT_SIZE") + public int getProductSize() { + return productSize; + } + + public void setProductSize(int productSize) { + this.productSize = productSize; + } + + @Column(name = "CREATION_TIME") + public Timestamp getCreationTime() { + return creationTime; + } + + public void setCreationTime(Timestamp creationTime) { + this.creationTime = creationTime; + } + + @Column(name = "LAST_MODIFIED_TIME") + public Timestamp getLastModifiedTime() { + return lastModifiedTime; + } + + public void setLastModifiedTime(Timestamp lastModifiedTime) { + this.lastModifiedTime = lastModifiedTime; + } + + @OneToMany(mappedBy = "dataProduct", cascade = {CascadeType.ALL}) + public Collection getDataReplicaLocations() { + return dataReplicaLocations; + } + + public void setDataReplicaLocations(Collection dataReplicaLocations) { + this.dataReplicaLocations = dataReplicaLocations; + } + + @OneToMany(mappedBy = "dataProduct", cascade = {CascadeType.ALL}) + public Collection getDataProductMetaData() { + return dataProductMetaData; + } + + public void setDataProductMetaData(Collection dataProductMetaData) { + this.dataProductMetaData = dataProductMetaData; + } + + @ManyToOne + @JoinColumn(name = "PARENT_PRODUCT_URI", referencedColumnName = "PRODUCT_URI") + public DataProduct getParentDataProduct() { + return parentDataProduct; + } + + public void setParentDataProduct(DataProduct parentDataProduct) { + this.parentDataProduct = parentDataProduct; + } + + @OneToMany(mappedBy = "parentDataProduct", cascade = {CascadeType.ALL}) + public Collection getChildDataProducts() { + return childDataProducts; + } + + public void setChildDataProducts(Collection childDataProducts) { + this.childDataProducts = childDataProducts; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData.java new file mode 100644 index 0000000..8604c69 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData.java @@ -0,0 +1,77 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; + +@Entity +@Table(name = "DATA_PRODUCT_METADATA") +@IdClass(DataProductMetaData_PK.class) +public class DataProductMetaData { + private final static Logger logger = LoggerFactory.getLogger(DataProductMetaData.class); + private String productUri; + private String key; + private String value; + + private DataProduct dataProduct; + + @Id + @Column(name = "PRODUCT_URI") + public String getProductUri() { + return productUri; + } + + public void setProductUri(String productUri) { + this.productUri = productUri; + } + + @Id + @Column(name = "METADATA_KEY") + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Column(name = "METADATA_VALUE") + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @ManyToOne + @JoinColumn(name = "PRODUCT_URI", referencedColumnName = "PRODUCT_URI") + public DataProduct getDataProduct() { + return dataProduct; + } + + public void setDataProduct(DataProduct dataProduct) { + this.dataProduct = dataProduct; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData_PK.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData_PK.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData_PK.java new file mode 100644 index 0000000..891b2fa --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataProductMetaData_PK.java @@ -0,0 +1,59 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +public class DataProductMetaData_PK implements Serializable { + private final static Logger logger = LoggerFactory.getLogger(DataProductMetaData_PK.class); + + private String productUri; + private String key; + + public String getProductUri() { + return productUri; + } + + public void setProductUri(String productUri) { + this.productUri = productUri; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object o) { + return false; + } + + @Override + public int hashCode() { + return 1; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaLocation.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaLocation.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaLocation.java new file mode 100644 index 0000000..44ce4fc --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaLocation.java @@ -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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Collection; + +@Entity +@Table(name = "DATA_REPLICA_LOCATION") +public class DataReplicaLocation { + private final static Logger logger = LoggerFactory.getLogger(DataReplicaLocation.class); + private String replicaId; + private String productUri; + private String replicaName; + private String replicaDescription; + private String storageResourceId; + private String filePath; + private String replicaLocationCategory; + private String replicaPersistentType; + private Timestamp creationTime; + private Timestamp lastModifiedTime; + private Timestamp validUntilTime; + + private DataProduct dataProduct; + private Collection dataReplicaMetaData; + + @Id + @Column(name = "REPLICA_ID") + public String getReplicaId() { + return replicaId; + } + + public void setReplicaId(String replicaId) { + this.replicaId = replicaId; + } + + @Column(name = "PRODUCT_URI") + public String getProductUri() { + return productUri; + } + + public void setProductUri(String productUri) { + this.productUri = productUri; + } + + + @Column(name = "REPLICA_NAME") + public String getReplicaName() { + return replicaName; + } + + public void setReplicaName(String replicaName) { + this.replicaName = replicaName; + } + + @Column(name = "REPLICA_DESCRIPTION") + public String getReplicaDescription() { + return replicaDescription; + } + + public void setReplicaDescription(String replicaDescription) { + this.replicaDescription = replicaDescription; + } + + @Column(name = "STORAGE_RESOURCE_ID") + public String getStorageResourceId() { + return storageResourceId; + } + + public void setStorageResourceId(String storageResourceId) { + this.storageResourceId = storageResourceId; + } + + @Column(name = "FILE_PATH") + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + @Column(name = "CREATION_TIME") + public Timestamp getCreationTime() { + return creationTime; + } + + public void setCreationTime(Timestamp creationTime) { + this.creationTime = creationTime; + } + + @Column(name = "LAST_MODIFIED_TIME") + public Timestamp getLastModifiedTime() { + return lastModifiedTime; + } + + public void setLastModifiedTime(Timestamp lastModifiedTime) { + this.lastModifiedTime = lastModifiedTime; + } + + @Column(name = "VALID_UNTIL_TIME") + public Timestamp getValidUntilTime() { + return validUntilTime; + } + + public void setValidUntilTime(Timestamp validUntilTime) { + this.validUntilTime = validUntilTime; + } + + + @Column(name = "REPLICA_LOCATION_CATEGORY") + public String getReplicaLocationCategory() { + return replicaLocationCategory; + } + + public void setReplicaLocationCategory(String replicaLocationCategory) { + this.replicaLocationCategory = replicaLocationCategory; + } + + @Column(name = "REPLICA_PERSISTENT_TYPE") + public String getReplicaPersistentType() { + return replicaPersistentType; + } + + public void setReplicaPersistentType(String replicaPersistentType) { + this.replicaPersistentType = replicaPersistentType; + } + + @ManyToOne + @JoinColumn(name = "PRODUCT_URI", referencedColumnName = "PRODUCT_URI") + public DataProduct getDataProduct() { + return dataProduct; + } + + public void setDataProduct(DataProduct dataProduct) { + this.dataProduct = dataProduct; + } + + @OneToMany(mappedBy = "dataReplicaLocation", cascade = {CascadeType.ALL}) + public Collection getDataReplicaMetaData() { + return dataReplicaMetaData; + } + + public void setDataReplicaMetaData(Collection dataReplicaMetaData) { + this.dataReplicaMetaData = dataReplicaMetaData; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData.java new file mode 100644 index 0000000..2f00321 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData.java @@ -0,0 +1,77 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; + +@Entity +@Table(name = "DATA_REPLICA_METADATA") +@IdClass(DataReplicaMetaData_PK.class) +public class DataReplicaMetaData { + private final static Logger logger = LoggerFactory.getLogger(DataReplicaMetaData.class); + private String replicaId; + private String key; + private String value; + + private DataReplicaLocation dataReplicaLocation; + + @Id + @Column(name = "REPLICA_ID") + public String getReplicaId() { + return replicaId; + } + + public void setReplicaId(String replicaId) { + this.replicaId = replicaId; + } + + @Id + @Column(name = "METADATA_KEY") + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Column(name = "METADATA_VALUE") + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @ManyToOne + @JoinColumn(name = "REPLICA_ID", referencedColumnName = "REPLICA_ID") + public DataReplicaLocation getDataReplicaLocation() { + return dataReplicaLocation; + } + + public void setDataReplicaLocation(DataReplicaLocation dataReplicaLocation) { + this.dataReplicaLocation = dataReplicaLocation; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData_PK.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData_PK.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData_PK.java new file mode 100644 index 0000000..86133c2 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/model/DataReplicaMetaData_PK.java @@ -0,0 +1,59 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.model; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +public class DataReplicaMetaData_PK implements Serializable { + private final static Logger logger = LoggerFactory.getLogger(DataReplicaMetaData_PK.class); + + private String replicaId; + private String key; + + public String getReplicaId() { + return replicaId; + } + + public void setReplicaId(String replicaId) { + this.replicaId = replicaId; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object o) { + return false; + } + + @Override + public int hashCode() { + return 1; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java new file mode 100644 index 0000000..5d9d4ec --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java @@ -0,0 +1,49 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.utils; + +public class ReplicaCatalogConstants { + // table names + public static final String DATA_RESOURCE = "DataProduct"; + public static final String DATA_REPLICA_LOCATION = "DataReplicaLocation"; + public static final String CONFIGURATION = "Configuration"; + + // DataProduct Table + public final class DataResourceConstants { + public static final String RESOURCE_ID = "resourceId"; + public static final String RESOURCE_NAME = "resourceName"; + public static final String RESOURCE_DESCRIPTION = "resourceDescription"; + public static final String RESOURCE_SIZE = "resourceSize"; + public static final String CREATION_TIME = "creationTime"; + public static final String LAST_MODIFIED_TIME = "lastModifiedTime"; + } + + // Users table + public final class DataReplicaLocationConstants { + public static final String REPLICA_ID = "replicaId"; + public static final String RESOURCE_ID = "resourceId"; + public static final String DATA_LOCATIONS = "dataLocations"; + public static final String REPLICA_NAME = "replicaName"; + public static final String REPLICA_DESCRIPTION = "replicaDescription"; + public static final String CREATION_TIME = "creationTime"; + public static final String LAST_MODIFIED_TIME = "lastModifiedTime"; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogJPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogJPAUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogJPAUtils.java new file mode 100644 index 0000000..21b3e17 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogJPAUtils.java @@ -0,0 +1,82 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.utils; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; + +public class ReplicaCatalogJPAUtils { + private final static Logger logger = LoggerFactory.getLogger(ReplicaCatalogJPAUtils.class); + + private static final String PERSISTENCE_UNIT_NAME = "datacatalog_data"; + private static final String DATACATALOG_JDBC_DRIVER = "datacatalog.jdbc.driver"; + private static final String DATACATALOG_JDBC_URL = "datacatalog.jdbc.url"; + private static final String DATACATALOG_JDBC_USER = "datacatalog.jdbc.user"; + private static final String DATACATALOG_JDBC_PWD = "datacatalog.jdbc.password"; + private static final String DATACATALOG_VALIDATION_QUERY = "datacatalog.validationQuery"; + + @PersistenceUnit(unitName="datacatalog_data") + protected static EntityManagerFactory factory; + + @PersistenceContext(unitName="datacatalog_data") + private static EntityManager dataCatEntityManager; + + public static EntityManager getEntityManager() throws ApplicationSettingsException { + if (factory == null) { + String connectionProperties = "DriverClassName=" + readServerProperties(DATACATALOG_JDBC_DRIVER) + "," + + "Url=" + readServerProperties(DATACATALOG_JDBC_URL) + "?autoReconnect=true," + + "Username=" + readServerProperties(DATACATALOG_JDBC_USER) + "," + + "Password=" + readServerProperties(DATACATALOG_JDBC_PWD) + + ",validationQuery=" + readServerProperties(DATACATALOG_VALIDATION_QUERY); + System.out.println(connectionProperties); + Map properties = new HashMap(); + properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); + properties.put("openjpa.ConnectionProperties", connectionProperties); + properties.put("openjpa.DynamicEnhancementAgent", "true"); + properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported"); + properties.put("openjpa.RemoteCommitProvider","sjvm"); + properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); + properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); + properties.put("openjpa.jdbc.QuerySQLCache", "false"); + properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," + + " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true"); + factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties); + } + dataCatEntityManager = factory.createEntityManager(); + return dataCatEntityManager; + } + + private static String readServerProperties (String propertyName) throws ApplicationSettingsException { + try { + return ServerSettings.getSetting(propertyName); + } catch (ApplicationSettingsException e) { + logger.error("Unable to read airavata-server.properties...", e); + throw new ApplicationSettingsException("Unable to read airavata-server.properties..."); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogQueryGenerator.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogQueryGenerator.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogQueryGenerator.java new file mode 100644 index 0000000..da102a9 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogQueryGenerator.java @@ -0,0 +1,111 @@ +/* + * + * 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 org.apache.airavata.registry.core.replica.catalog.utils; + +import org.apache.airavata.registry.cpi.ResultOrderType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.HashMap; +import java.util.Map; + +public class ReplicaCatalogQueryGenerator { + + private final static Logger logger = LoggerFactory.getLogger(ReplicaCatalogQueryGenerator.class); + private String tableName; + private Map matches=new HashMap(); + private static final String SELECT_OBJ="p"; + private static final String DELETE_OBJ="p"; + private static final String TABLE_OBJ="p"; + + public ReplicaCatalogQueryGenerator(String tableName, Object[]... params) { + setTableName(tableName); + for (Object[] param : params) { + addMatch(param[0].toString(), param[1]); + } + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public void addMatch(String colName, Object matchValue){ + matches.put(colName, matchValue); + } + + public void setParameter(String colName, Object matchValue){ + addMatch(colName, matchValue); + } + + public Query selectQuery(EntityManager entityManager){ + String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ; + return generateQueryWithParameters(entityManager, queryString); + } + + public Query selectQuery(EntityManager entityManager, String orderByColumn, + ResultOrderType resultOrderType){ + String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC"; + String orderByClause = " ORDER BY " + SELECT_OBJ + "." + orderByColumn + " " + order; + String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ; + return generateQueryWithParameters(entityManager, queryString, orderByClause); + } + + public Query deleteQuery(EntityManager entityManager){ + String queryString="Delete FROM "+getTableName()+" "+TABLE_OBJ; + return generateQueryWithParameters(entityManager, queryString); + } + + private Query generateQueryWithParameters(EntityManager entityManager, String queryString) { + return generateQueryWithParameters(entityManager, queryString, ""); + } + + private Query generateQueryWithParameters(EntityManager entityManager, + String queryString, String orderByClause) { + Map queryParameters=new HashMap(); + if (matches.size()>0){ + String matchString = ""; + int paramCount=0; + for (String colName : matches.keySet()) { + String paramName="param"+paramCount; + queryParameters.put(paramName, matches.get(colName)); + if (!matchString.equals("")){ + matchString+=" AND "; + } + matchString+=TABLE_OBJ+"."+colName+" =:"+paramName; + paramCount++; + } + queryString+=" WHERE "+matchString; + } + queryString += orderByClause; + Query query = entityManager.createQuery(queryString); + for (String paramName : queryParameters.keySet()) { + query.setParameter(paramName, queryParameters.get(paramName)); + } + return query; + } +}