Repository: airavata Updated Branches: refs/heads/develop a2ff43253 -> 04f6f5934
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/ThriftDataModelConversion.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ThriftDataModelConversion.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ThriftDataModelConversion.java new file mode 100644 index 0000000..ece579c --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ThriftDataModelConversion.java @@ -0,0 +1,215 @@ +/* +* +* 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.model.data.replica.*; +import org.apache.airavata.registry.core.replica.catalog.model.DataProduct; +import org.apache.airavata.registry.core.replica.catalog.model.DataProductMetaData; +import org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation; +import org.apache.airavata.registry.core.replica.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<DataReplicaLocationModel> 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<DataProductModel> 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> 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<DataReplicaLocation> 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<DataProduct> 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> 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<String, String> getResourceMetaData(Collection<DataProductMetaData> dataProductMetaData){ + HashMap<String, String> metadata = new HashMap<>(); + if(dataProductMetaData!=null && !dataProductMetaData.isEmpty()) { + dataProductMetaData.stream().forEach(m -> metadata.put(m.getKey(),m.getValue())); + } + return metadata; + } + + public static Map<String, String> getReplicaMetaData(Collection<DataReplicaMetaData> dataReplicaMetaData){ + HashMap<String, String> 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/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/resources/META-INF/persistence.xml b/modules/registry/registry-core/src/main/resources/META-INF/persistence.xml index 54215fa..2d8eb7d 100644 --- a/modules/registry/registry-core/src/main/resources/META-INF/persistence.xml +++ b/modules/registry/registry-core/src/main/resources/META-INF/persistence.xml @@ -95,11 +95,11 @@ </persistence-unit> <persistence-unit name="datacatalog_data"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> - <class>org.apache.airavata.registry.core.data.catalog.model.DataProduct</class> - <class>org.apache.airavata.registry.core.data.catalog.model.DataReplicaLocation</class> - <class>org.apache.airavata.registry.core.data.catalog.model.DataProductMetaData</class> - <class>org.apache.airavata.registry.core.data.catalog.model.DataReplicaMetaData</class> - <class>org.apache.airavata.registry.core.data.catalog.model.Configuration</class> + <class>org.apache.airavata.registry.core.replica.catalog.model.DataProduct</class> + <class>org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation</class> + <class>org.apache.airavata.registry.core.replica.catalog.model.DataProductMetaData</class> + <class>org.apache.airavata.registry.core.replica.catalog.model.DataReplicaMetaData</class> + <class>org.apache.airavata.registry.core.replica.catalog.model.Configuration</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> <persistence-unit name="workflowcatalog_data"> http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java deleted file mode 100644 index 627a6e6..0000000 --- a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/DataCatalogTest.java +++ /dev/null @@ -1,100 +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.data.catalog; - -import org.apache.airavata.data.catalog.util.Initialize; -import org.apache.airavata.model.data.product.*; -import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory; -import org.apache.airavata.registry.cpi.DataCatalog; -import org.apache.airavata.registry.cpi.DataCatalogException; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; - -public class DataCatalogTest { - private final static Logger logger = LoggerFactory.getLogger(DataCatalogTest.class); - private static Initialize initialize; - private static DataCatalog datacatalog; - private static DataProductModel dataProductModel; - private static DataReplicaLocationModel replicaLocationModel; - - @BeforeClass - public static void setUp() { - try { - System.out.println("********** SET UP ************"); - initialize = new Initialize("datacatalog-derby.sql"); - initialize.initializeDB(); - datacatalog = RegistryFactory.getDataCatalog(); - dataProductModel = new DataProductModel(); - dataProductModel.setProductName("test-file.txt"); - dataProductModel.setOwnerName("scnakandala"); - dataProductModel.setGatewayId("default"); - dataProductModel.setLogicalPath("/test/test/test"); - dataProductModel.setDataProductType(DataProductType.FILE); - HashMap<String, String> resMetadata = new HashMap<>(); - resMetadata.put("name", "name"); - dataProductModel.setProductMetadata(resMetadata); - - replicaLocationModel = new DataReplicaLocationModel(); - replicaLocationModel.setReplicaName("1-st-replica"); - replicaLocationModel.setReplicaLocationCategory(ReplicaLocationCategory.COMPUTE_RESOURCE); - replicaLocationModel.setReplicaPersistentType(ReplicaPersistentType.PERSISTENT); - HashMap<String, String> rMetadata = new HashMap<>(); - rMetadata.put("name", "name"); - replicaLocationModel.setReplicaMetadata(rMetadata); - dataProductModel.addToReplicaLocations(replicaLocationModel); - } catch (DataCatalogException e) { - logger.error(e.getMessage(), e); - } - } - - @AfterClass - public static void tearDown() throws Exception { - System.out.println("********** TEAR DOWN ************"); - initialize.stopDerbyServer(); - } - - @Test - public void testDataCatalog(){ - try { - String productUri = datacatalog.registerDataProduct(dataProductModel); - org.junit.Assert.assertNotNull(productUri); - dataProductModel = datacatalog.getDataProduct(productUri); - Assert.assertNotNull(dataProductModel); - boolean result = datacatalog.removeDataProduct(productUri); - Assert.assertTrue(result); - productUri = datacatalog.registerDataProduct(dataProductModel); - Assert.assertNotNull(productUri); - result = datacatalog.removeDataProduct(productUri); - Assert.assertTrue(result); - result = datacatalog.removeDataProduct(productUri); - Assert.assertFalse(result); - } catch (DataCatalogException e) { - e.printStackTrace(); - Assert.fail(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/util/Initialize.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/util/Initialize.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/util/Initialize.java deleted file mode 100644 index 002e51e..0000000 --- a/modules/registry/registry-core/src/test/java/org/apache/airavata/data/catalog/util/Initialize.java +++ /dev/null @@ -1,315 +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.data.catalog.util; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.registry.core.data.catalog.utils.DataCatalogConstants; -import org.apache.derby.drda.NetworkServerControl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.InetAddress; -import java.net.URI; -import java.sql.*; -import java.util.StringTokenizer; - -public class Initialize { - private static final Logger logger = LoggerFactory.getLogger(Initialize.class); - public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer"; - public String scriptName = "datacatalog-derby.sql"; - private NetworkServerControl server; - private static final String delimiter = ";"; - private String jdbcUrl = null; - private String jdbcDriver = null; - private String jdbcUser = null; - private String jdbcPassword = null; - - public Initialize(String scriptName) { - this.scriptName = scriptName; - } - - public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) { - if (suffix.length() > buffer.length()) { - return false; - } - // this loop is done on purpose to avoid memory allocation performance - // problems on various JDKs - // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and - // implementation is ok though does allocation/copying - // StringBuffer.toString().endsWith() does massive memory - // allocation/copying on JDK 1.5 - // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169 - int endIndex = suffix.length() - 1; - int bufferIndex = buffer.length() - 1; - while (endIndex >= 0) { - if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) { - return false; - } - bufferIndex--; - endIndex--; - } - return true; - } - - private static boolean isServerStarted(NetworkServerControl server, int ntries) - { - for (int i = 1; i <= ntries; i ++) - { - try { - Thread.sleep(500); - server.ping(); - return true; - } - catch (Exception e) { - if (i == ntries) - return false; - } - } - return false; - } - - public void initializeDB() { - try{ - jdbcDriver = ServerSettings.getSetting("datacatalog.jdbc.driver"); - jdbcUrl = ServerSettings.getSetting("datacatalog.jdbc.url"); - jdbcUser = ServerSettings.getSetting("datacatalog.jdbc.user"); - jdbcPassword = ServerSettings.getSetting("datacatalog.jdbc.password"); - jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; - } catch (ApplicationSettingsException e) { - logger.error("Unable to read properties", e); - } - - startDerbyInServerMode(); - if(!isServerStarted(server, 20)){ - throw new RuntimeException("Derby server could not started within five seconds..."); - } - Connection conn = null; - try { - Class.forName(jdbcDriver).newInstance(); - conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword); - if (!isDatabaseStructureCreated(DataCatalogConstants.CONFIGURATION, conn)) { - executeSQLScript(conn); - logger.info("New Database created for Data Catalog !!!"); - } else { - logger.debug("Database already created for Data Catalog!"); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RuntimeException("Database failure", e); - } finally { - try { - if (conn != null){ - if (!conn.getAutoCommit()) { - conn.commit(); - } - conn.close(); - } - } catch (SQLException e) { - logger.error(e.getMessage(), e); - } - } - } - - public static boolean isDatabaseStructureCreated(String tableName, Connection conn) { - try { - System.out.println("Running a query to test the database tables existence."); - // check whether the tables are already created with a query - Statement statement = null; - try { - statement = conn.createStatement(); - ResultSet rs = statement.executeQuery("select * from " + tableName); - if (rs != null) { - rs.close(); - } - } finally { - try { - if (statement != null) { - statement.close(); - } - } catch (SQLException e) { - return false; - } - } - } catch (SQLException e) { - return false; - } - - return true; - } - - private void executeSQLScript(Connection conn) throws Exception { - StringBuffer sql = new StringBuffer(); - BufferedReader reader = null; - try{ - - InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(scriptName); - reader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("//")) { - continue; - } - if (line.startsWith("--")) { - continue; - } - StringTokenizer st = new StringTokenizer(line); - if (st.hasMoreTokens()) { - String token = st.nextToken(); - if ("REM".equalsIgnoreCase(token)) { - continue; - } - } - sql.append(" ").append(line); - - // SQL defines "--" as a comment to EOL - // and in Oracle it may contain a hint - // so we cannot just remove it, instead we must end it - if (line.indexOf("--") >= 0) { - sql.append("\n"); - } - if ((checkStringBufferEndsWith(sql, delimiter))) { - executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn); - sql.replace(0, sql.length(), ""); - } - } - // Catch any statements not followed by ; - if (sql.length() > 0) { - executeSQL(sql.toString(), conn); - } - }catch (IOException e){ - logger.error("Error occurred while executing SQL script for creating Airavata Data Catalog database", e); - throw new Exception("Error occurred while executing SQL script for creating Airavata Data Catalog database", e); - }finally { - if (reader != null) { - reader.close(); - } - } - } - - private static void executeSQL(String sql, Connection conn) throws Exception { - // Check and ignore empty statements - if ("".equals(sql.trim())) { - return; - } - - Statement statement = null; - try { - logger.debug("SQL : " + sql); - - boolean ret; - int updateCount = 0, updateCountTotal = 0; - statement = conn.createStatement(); - ret = statement.execute(sql); - updateCount = statement.getUpdateCount(); - do { - if (!ret) { - if (updateCount != -1) { - updateCountTotal += updateCount; - } - } - ret = statement.getMoreResults(); - if (ret) { - updateCount = statement.getUpdateCount(); - } - } while (ret); - - logger.debug(sql + " : " + updateCountTotal + " rows affected"); - - SQLWarning warning = conn.getWarnings(); - while (warning != null) { - logger.warn(warning + " sql warning"); - warning = warning.getNextWarning(); - } - conn.clearWarnings(); - } catch (SQLException e) { - if (e.getSQLState().equals("X0Y32")) { - // eliminating the table already exception for the derby - // database - logger.info("Table Already Exists", e); - } else { - throw new Exception("Error occurred while executing : " + sql, e); - } - } finally { - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - logger.error("Error occurred while closing result set.", e); - } - } - } - } - - private void startDerbyInServerMode() { - try { - System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true"); - server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"), - 20000, - jdbcUser, jdbcPassword); - java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true); - server.start(consoleWriter); - } catch (IOException e) { - logger.error("Unable to start Apache derby in the server mode! Check whether " + - "specified port is available"); - } catch (Exception e) { - logger.error("Unable to start Apache derby in the server mode! Check whether " + - "specified port is available"); - } - - } - - public static int getPort(String jdbcURL){ - try{ - String cleanURI = jdbcURL.substring(5); - URI uri = URI.create(cleanURI); - return uri.getPort(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return -1; - } - } - - private void startDerbyInEmbeddedMode(){ - try { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); - DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close(); - } catch (ClassNotFoundException e) { - logger.error(e.getMessage(), e); - } catch (SQLException e) { - logger.error(e.getMessage(), e); - } - } - - public void stopDerbyServer() { - try { - server.shutdown(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java new file mode 100644 index 0000000..f787ee4 --- /dev/null +++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java @@ -0,0 +1,100 @@ +/* + * + * 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.replica.catalog; + +import org.apache.airavata.replica.catalog.util.Initialize; +import org.apache.airavata.model.data.replica.*; +import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory; +import org.apache.airavata.registry.cpi.ReplicaCatalog; +import org.apache.airavata.registry.cpi.ReplicaCatalogException; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; + +public class ReplicaCatalogTest { + private final static Logger logger = LoggerFactory.getLogger(ReplicaCatalogTest.class); + private static Initialize initialize; + private static ReplicaCatalog datacatalog; + private static DataProductModel dataProductModel; + private static DataReplicaLocationModel replicaLocationModel; + + @BeforeClass + public static void setUp() { + try { + System.out.println("********** SET UP ************"); + initialize = new Initialize("datacatalog-derby.sql"); + initialize.initializeDB(); + datacatalog = RegistryFactory.getReplicaCatalog(); + dataProductModel = new DataProductModel(); + dataProductModel.setProductName("test-file.txt"); + dataProductModel.setOwnerName("scnakandala"); + dataProductModel.setGatewayId("default"); + dataProductModel.setLogicalPath("/test/test/test"); + dataProductModel.setDataProductType(DataProductType.FILE); + HashMap<String, String> resMetadata = new HashMap<>(); + resMetadata.put("name", "name"); + dataProductModel.setProductMetadata(resMetadata); + + replicaLocationModel = new DataReplicaLocationModel(); + replicaLocationModel.setReplicaName("1-st-replica"); + replicaLocationModel.setReplicaLocationCategory(ReplicaLocationCategory.COMPUTE_RESOURCE); + replicaLocationModel.setReplicaPersistentType(ReplicaPersistentType.PERSISTENT); + HashMap<String, String> rMetadata = new HashMap<>(); + rMetadata.put("name", "name"); + replicaLocationModel.setReplicaMetadata(rMetadata); + dataProductModel.addToReplicaLocations(replicaLocationModel); + } catch (ReplicaCatalogException e) { + logger.error(e.getMessage(), e); + } + } + + @AfterClass + public static void tearDown() throws Exception { + System.out.println("********** TEAR DOWN ************"); + initialize.stopDerbyServer(); + } + + @Test + public void testReplicaCatalog(){ + try { + String productUri = datacatalog.registerDataProduct(dataProductModel); + org.junit.Assert.assertNotNull(productUri); + dataProductModel = datacatalog.getDataProduct(productUri); + Assert.assertNotNull(dataProductModel); + boolean result = datacatalog.removeDataProduct(productUri); + Assert.assertTrue(result); + productUri = datacatalog.registerDataProduct(dataProductModel); + Assert.assertNotNull(productUri); + result = datacatalog.removeDataProduct(productUri); + Assert.assertTrue(result); + result = datacatalog.removeDataProduct(productUri); + Assert.assertFalse(result); + } catch (ReplicaCatalogException e) { + e.printStackTrace(); + Assert.fail(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/util/Initialize.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/util/Initialize.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/util/Initialize.java new file mode 100644 index 0000000..989a775 --- /dev/null +++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/util/Initialize.java @@ -0,0 +1,315 @@ +/* + * + * 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.replica.catalog.util; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.core.replica.catalog.utils.ReplicaCatalogConstants; +import org.apache.derby.drda.NetworkServerControl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.URI; +import java.sql.*; +import java.util.StringTokenizer; + +public class Initialize { + private static final Logger logger = LoggerFactory.getLogger(Initialize.class); + public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer"; + public String scriptName = "datacatalog-derby.sql"; + private NetworkServerControl server; + private static final String delimiter = ";"; + private String jdbcUrl = null; + private String jdbcDriver = null; + private String jdbcUser = null; + private String jdbcPassword = null; + + public Initialize(String scriptName) { + this.scriptName = scriptName; + } + + public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) { + if (suffix.length() > buffer.length()) { + return false; + } + // this loop is done on purpose to avoid memory allocation performance + // problems on various JDKs + // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and + // implementation is ok though does allocation/copying + // StringBuffer.toString().endsWith() does massive memory + // allocation/copying on JDK 1.5 + // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169 + int endIndex = suffix.length() - 1; + int bufferIndex = buffer.length() - 1; + while (endIndex >= 0) { + if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) { + return false; + } + bufferIndex--; + endIndex--; + } + return true; + } + + private static boolean isServerStarted(NetworkServerControl server, int ntries) + { + for (int i = 1; i <= ntries; i ++) + { + try { + Thread.sleep(500); + server.ping(); + return true; + } + catch (Exception e) { + if (i == ntries) + return false; + } + } + return false; + } + + public void initializeDB() { + try{ + jdbcDriver = ServerSettings.getSetting("datacatalog.jdbc.driver"); + jdbcUrl = ServerSettings.getSetting("datacatalog.jdbc.url"); + jdbcUser = ServerSettings.getSetting("datacatalog.jdbc.user"); + jdbcPassword = ServerSettings.getSetting("datacatalog.jdbc.password"); + jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + } catch (ApplicationSettingsException e) { + logger.error("Unable to read properties", e); + } + + startDerbyInServerMode(); + if(!isServerStarted(server, 20)){ + throw new RuntimeException("Derby server could not started within five seconds..."); + } + Connection conn = null; + try { + Class.forName(jdbcDriver).newInstance(); + conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword); + if (!isDatabaseStructureCreated(ReplicaCatalogConstants.CONFIGURATION, conn)) { + executeSQLScript(conn); + logger.info("New Database created for Data Catalog !!!"); + } else { + logger.debug("Database already created for Data Catalog!"); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RuntimeException("Database failure", e); + } finally { + try { + if (conn != null){ + if (!conn.getAutoCommit()) { + conn.commit(); + } + conn.close(); + } + } catch (SQLException e) { + logger.error(e.getMessage(), e); + } + } + } + + public static boolean isDatabaseStructureCreated(String tableName, Connection conn) { + try { + System.out.println("Running a query to test the database tables existence."); + // check whether the tables are already created with a query + Statement statement = null; + try { + statement = conn.createStatement(); + ResultSet rs = statement.executeQuery("select * from " + tableName); + if (rs != null) { + rs.close(); + } + } finally { + try { + if (statement != null) { + statement.close(); + } + } catch (SQLException e) { + return false; + } + } + } catch (SQLException e) { + return false; + } + + return true; + } + + private void executeSQLScript(Connection conn) throws Exception { + StringBuffer sql = new StringBuffer(); + BufferedReader reader = null; + try{ + + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(scriptName); + reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (line.startsWith("//")) { + continue; + } + if (line.startsWith("--")) { + continue; + } + StringTokenizer st = new StringTokenizer(line); + if (st.hasMoreTokens()) { + String token = st.nextToken(); + if ("REM".equalsIgnoreCase(token)) { + continue; + } + } + sql.append(" ").append(line); + + // SQL defines "--" as a comment to EOL + // and in Oracle it may contain a hint + // so we cannot just remove it, instead we must end it + if (line.indexOf("--") >= 0) { + sql.append("\n"); + } + if ((checkStringBufferEndsWith(sql, delimiter))) { + executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn); + sql.replace(0, sql.length(), ""); + } + } + // Catch any statements not followed by ; + if (sql.length() > 0) { + executeSQL(sql.toString(), conn); + } + }catch (IOException e){ + logger.error("Error occurred while executing SQL script for creating Airavata Data Catalog database", e); + throw new Exception("Error occurred while executing SQL script for creating Airavata Data Catalog database", e); + }finally { + if (reader != null) { + reader.close(); + } + } + } + + private static void executeSQL(String sql, Connection conn) throws Exception { + // Check and ignore empty statements + if ("".equals(sql.trim())) { + return; + } + + Statement statement = null; + try { + logger.debug("SQL : " + sql); + + boolean ret; + int updateCount = 0, updateCountTotal = 0; + statement = conn.createStatement(); + ret = statement.execute(sql); + updateCount = statement.getUpdateCount(); + do { + if (!ret) { + if (updateCount != -1) { + updateCountTotal += updateCount; + } + } + ret = statement.getMoreResults(); + if (ret) { + updateCount = statement.getUpdateCount(); + } + } while (ret); + + logger.debug(sql + " : " + updateCountTotal + " rows affected"); + + SQLWarning warning = conn.getWarnings(); + while (warning != null) { + logger.warn(warning + " sql warning"); + warning = warning.getNextWarning(); + } + conn.clearWarnings(); + } catch (SQLException e) { + if (e.getSQLState().equals("X0Y32")) { + // eliminating the table already exception for the derby + // database + logger.info("Table Already Exists", e); + } else { + throw new Exception("Error occurred while executing : " + sql, e); + } + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + logger.error("Error occurred while closing result set.", e); + } + } + } + } + + private void startDerbyInServerMode() { + try { + System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true"); + server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"), + 20000, + jdbcUser, jdbcPassword); + java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true); + server.start(consoleWriter); + } catch (IOException e) { + logger.error("Unable to start Apache derby in the server mode! Check whether " + + "specified port is available"); + } catch (Exception e) { + logger.error("Unable to start Apache derby in the server mode! Check whether " + + "specified port is available"); + } + + } + + public static int getPort(String jdbcURL){ + try{ + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getPort(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return -1; + } + } + + private void startDerbyInEmbeddedMode(){ + try { + Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); + DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close(); + } catch (ClassNotFoundException e) { + logger.error(e.getMessage(), e); + } catch (SQLException e) { + logger.error(e.getMessage(), e); + } + } + + public void stopDerbyServer() { + try { + server.shutdown(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java deleted file mode 100644 index 42eff2a..0000000 --- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalog.java +++ /dev/null @@ -1,50 +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.cpi; - - -import org.apache.airavata.model.data.product.DataProductModel; -import org.apache.airavata.model.data.product.DataReplicaLocationModel; - -import java.util.List; - -public interface DataCatalog { - String schema = "airavata-dp"; - - String registerDataProduct(DataProductModel product) throws DataCatalogException; - - boolean removeDataProduct(String productUri) throws DataCatalogException; - - boolean updateDataProduct(DataProductModel product) throws DataCatalogException; - - DataProductModel getDataProduct(String productUri) throws DataCatalogException; - - boolean isExists(String productUri) throws DataCatalogException; - - String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws DataCatalogException; - - boolean removeReplicaLocation(String replicaId) throws DataCatalogException; - - boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws DataCatalogException; - - DataReplicaLocationModel getReplicaLocation(String replicaId) throws DataCatalogException; - - List<DataReplicaLocationModel> getAllReplicaLocations(String productUri) throws DataCatalogException; -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalogException.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalogException.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalogException.java deleted file mode 100644 index 9bc4da9..0000000 --- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataCatalogException.java +++ /dev/null @@ -1,35 +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.cpi; - -public class DataCatalogException extends Exception{ - - public DataCatalogException(Throwable e) { - super(e); - } - - public DataCatalogException(String message) { - super(message, null); - } - - public DataCatalogException(String message, Throwable e) { - super(message, e); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java index e51389c..60531c8 100644 --- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java +++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java @@ -25,5 +25,5 @@ public interface Registry { public ExperimentCatalog getExperimentCatalog() throws RegistryException; public ExperimentCatalog getExperimentCatalog(String gatewayId, String username, String password) throws RegistryException; public AppCatalog getAppCatalog() throws RegistryException; - public DataCatalog getDataCatalog() throws RegistryException; + public ReplicaCatalog getReplicaCatalog() throws RegistryException; } http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java new file mode 100644 index 0000000..1897356 --- /dev/null +++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java @@ -0,0 +1,50 @@ +/** + * 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.cpi; + + +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.data.replica.DataReplicaLocationModel; + +import java.util.List; + +public interface ReplicaCatalog { + String schema = "airavata-dp"; + + String registerDataProduct(DataProductModel product) throws ReplicaCatalogException; + + boolean removeDataProduct(String productUri) throws ReplicaCatalogException; + + boolean updateDataProduct(DataProductModel product) throws ReplicaCatalogException; + + DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException; + + boolean isExists(String productUri) throws ReplicaCatalogException; + + String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException; + + boolean removeReplicaLocation(String replicaId) throws ReplicaCatalogException; + + boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException; + + DataReplicaLocationModel getReplicaLocation(String replicaId) throws ReplicaCatalogException; + + List<DataReplicaLocationModel> getAllReplicaLocations(String productUri) throws ReplicaCatalogException; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalogException.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalogException.java b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalogException.java new file mode 100644 index 0000000..f0eb5cd --- /dev/null +++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalogException.java @@ -0,0 +1,35 @@ +/** + * 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.cpi; + +public class ReplicaCatalogException extends Exception{ + + public ReplicaCatalogException(Throwable e) { + super(e); + } + + public ReplicaCatalogException(String message) { + super(message, null); + } + + public ReplicaCatalogException(String message, Throwable e) { + super(message, e); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/thrift-interface-descriptions/airavata-apis/airavata_api.thrift ---------------------------------------------------------------------- diff --git a/thrift-interface-descriptions/airavata-apis/airavata_api.thrift b/thrift-interface-descriptions/airavata-apis/airavata_api.thrift index 3835c8e..5fcdb88 100644 --- a/thrift-interface-descriptions/airavata-apis/airavata_api.thrift +++ b/thrift-interface-descriptions/airavata-apis/airavata_api.thrift @@ -40,7 +40,7 @@ include "../data-models/resource-catalog-models/storage_resource_model.thrift" include "../data-models/resource-catalog-models/gateway_resource_profile_model.thrift" include "../data-models/resource-catalog-models/data_movement_models.thrift" include "../data-models/workflow-models/workflow_data_model.thrift" -include "../data-models/data-catalog-models/data_catalog_models.thrift" +include "../data-models/replica-catalog-models/replica_catalog_models.thrift" namespace java org.apache.airavata.api namespace php Airavata.API @@ -2962,21 +2962,21 @@ service Airavata { /** - * API Methods related to data catalog + * API Methods related to replica catalog **/ - string registerDataProduct(1: required security_model.AuthzToken authzToken, 2: required data_catalog_models.DataProductModel dataProductModel) + string registerDataProduct(1: required security_model.AuthzToken authzToken, 2: required replica_catalog_models.DataProductModel dataProductModel) throws (1: airavata_errors.InvalidRequestException ire, 2: airavata_errors.AiravataClientException ace, 3: airavata_errors.AiravataSystemException ase, 4: airavata_errors.AuthorizationException ae) - data_catalog_models.DataProductModel getDataProduct(1: required security_model.AuthzToken authzToken, 2: required string dataProductUri) + replica_catalog_models.DataProductModel getDataProduct(1: required security_model.AuthzToken authzToken, 2: required string dataProductUri) throws (1: airavata_errors.InvalidRequestException ire, 2: airavata_errors.AiravataClientException ace, 3: airavata_errors.AiravataSystemException ase, 4: airavata_errors.AuthorizationException ae) - string registerReplicaLocation(1: required security_model.AuthzToken authzToken, 2: required data_catalog_models.DataReplicaLocationModel replicaLocationModel) + string registerReplicaLocation(1: required security_model.AuthzToken authzToken, 2: required replica_catalog_models.DataReplicaLocationModel replicaLocationModel) throws (1: airavata_errors.InvalidRequestException ire, 2: airavata_errors.AiravataClientException ace, 3: airavata_errors.AiravataSystemException ase, http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/thrift-interface-descriptions/data-models/airavata_data_models.thrift ---------------------------------------------------------------------- diff --git a/thrift-interface-descriptions/data-models/airavata_data_models.thrift b/thrift-interface-descriptions/data-models/airavata_data_models.thrift index 12ac253..8d49b1a 100644 --- a/thrift-interface-descriptions/data-models/airavata_data_models.thrift +++ b/thrift-interface-descriptions/data-models/airavata_data_models.thrift @@ -30,7 +30,7 @@ include "experiment-catalog-models/process_model.thrift" include "experiment-catalog-models/scheduling_model.thrift" include "experiment-catalog-models/status_models.thrift" include "resource-catalog-models/data_movement_models.thrift" -include "data-catalog-models/data_catalog_models.thrift" +include "replica-catalog-models/replica_catalog_models.thrift" namespace java org.apache.airavata.model namespace php Airavata.Model http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/thrift-interface-descriptions/data-models/data-catalog-models/data_catalog_models.thrift ---------------------------------------------------------------------- diff --git a/thrift-interface-descriptions/data-models/data-catalog-models/data_catalog_models.thrift b/thrift-interface-descriptions/data-models/data-catalog-models/data_catalog_models.thrift deleted file mode 100644 index 9876b20..0000000 --- a/thrift-interface-descriptions/data-models/data-catalog-models/data_catalog_models.thrift +++ /dev/null @@ -1,73 +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. - * - */ - namespace java org.apache.airavata.model.data.product - namespace php Airavata.Model.Data.Product - namespace cpp apache.airavata.model.data.product - namespace py apache.airavata.model.data.product - -enum ReplicaLocationCategory { - GATEWAY_DATA_STORE, - COMPUTE_RESOURCE, - LONG_TERM_STORAGE_RESOURCE, - OTHER -} - -enum ReplicaPersistentType { - TRANSIENT, - PERSISTENT -} - -enum DataProductType { - DIR, - FILE, - COLLECTION, -} - -struct DataProductModel { - 1: optional string productUri, - 2: optional string gatewayId, - 3: optional string parentProductUri, - 4: optional string logicalPath, - 5: optional string productName, - 6: optional string productDescription, - 7: optional string ownerName, - 8: optional DataProductType dataProductType, - 9: optional i32 productSize, - 10: optional i64 creationTime, - 11: optional i64 lastModifiedTime, - 12: optional map<string, string> productMetadata, - 13: optional list<DataReplicaLocationModel> replicaLocations, - 14: optional list<DataProductModel> childProducts -} - -struct DataReplicaLocationModel { - 1: optional string replicaId, - 2: optional string productUri, - 3: optional string replicaName, - 4: optional string replicaDescription, - 5: optional i64 creationTime, - 6: optional i64 lastModifiedTime, - 7: optional i64 validUntilTime, - 8: optional ReplicaLocationCategory replicaLocationCategory, - 9: optional ReplicaPersistentType replicaPersistentType, - 10: optional string storageResourceId, - 11: optional string filePath, - 12: optional map<string, string> replicaMetadata -} http://git-wip-us.apache.org/repos/asf/airavata/blob/04f6f593/thrift-interface-descriptions/data-models/replica-catalog-models/replica_catalog_models.thrift ---------------------------------------------------------------------- diff --git a/thrift-interface-descriptions/data-models/replica-catalog-models/replica_catalog_models.thrift b/thrift-interface-descriptions/data-models/replica-catalog-models/replica_catalog_models.thrift new file mode 100644 index 0000000..424f532 --- /dev/null +++ b/thrift-interface-descriptions/data-models/replica-catalog-models/replica_catalog_models.thrift @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + namespace java org.apache.airavata.model.data.replica + namespace php Airavata.Model.Data.Replica + namespace cpp apache.airavata.model.data.replica + namespace py apache.airavata.model.data.replica + +enum ReplicaLocationCategory { + GATEWAY_DATA_STORE, + COMPUTE_RESOURCE, + LONG_TERM_STORAGE_RESOURCE, + OTHER +} + +enum ReplicaPersistentType { + TRANSIENT, + PERSISTENT +} + +enum DataProductType { + DIR, + FILE, + COLLECTION, +} + +struct DataProductModel { + 1: optional string productUri, + 2: optional string gatewayId, + 3: optional string parentProductUri, + 4: optional string logicalPath, + 5: optional string productName, + 6: optional string productDescription, + 7: optional string ownerName, + 8: optional DataProductType dataProductType, + 9: optional i32 productSize, + 10: optional i64 creationTime, + 11: optional i64 lastModifiedTime, + 12: optional map<string, string> productMetadata, + 13: optional list<DataReplicaLocationModel> replicaLocations, + 14: optional list<DataProductModel> childProducts +} + +struct DataReplicaLocationModel { + 1: optional string replicaId, + 2: optional string productUri, + 3: optional string replicaName, + 4: optional string replicaDescription, + 5: optional i64 creationTime, + 6: optional i64 lastModifiedTime, + 7: optional i64 validUntilTime, + 8: optional ReplicaLocationCategory replicaLocationCategory, + 9: optional ReplicaPersistentType replicaPersistentType, + 10: optional string storageResourceId, + 11: optional string filePath, + 12: optional map<string, string> replicaMetadata +}
