Search in sources :

Example 11 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method isExists.

@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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException)

Example 12 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method registerReplicaLocation.

@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;
}
Also used : EntityManager(javax.persistence.EntityManager) DataReplicaLocation(org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException)

Example 13 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogImpl method getChildDataProducts.

@Override
public List<DataProductModel> getChildDataProducts(String productUri) throws ReplicaCatalogException {
    EntityManager em = null;
    try {
        em = ReplicaCatalogJPAUtils.getEntityManager();
        DataProduct dataProduct = em.find(DataProduct.class, productUri);
        Collection<DataProduct> childProducts = dataProduct.getChildDataProducts();
        ArrayList<DataProductModel> returnModels = new ArrayList<>();
        childProducts.stream().forEach(cp -> {
            returnModels.add(ThriftDataModelConversion.getDataProductModel(cp));
        });
        return returnModels;
    } 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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) DataProduct(org.apache.airavata.registry.core.replica.catalog.model.DataProduct) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel)

Example 14 with ReplicaCatalogException

use of org.apache.airavata.registry.cpi.ReplicaCatalogException in project airavata by apache.

the class ReplicaCatalogTest method setUp.

@BeforeClass
public static void setUp() {
    try {
        System.out.println("********** SET UP ************");
        initialize = new Initialize("replicacatalog-derby.sql");
        initialize.initializeDB();
        replicacatalog = RegistryFactory.getReplicaCatalog();
        dataProductModel = new DataProductModel();
        dataProductModel.setProductName("test-file.txt");
        dataProductModel.setOwnerName("scnakandala");
        dataProductModel.setGatewayId("default");
        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);
    }
}
Also used : HashMap(java.util.HashMap) Initialize(org.apache.airavata.replica.catalog.util.Initialize) ReplicaCatalogException(org.apache.airavata.registry.cpi.ReplicaCatalogException) BeforeClass(org.junit.BeforeClass)

Aggregations

ReplicaCatalogException (org.apache.airavata.registry.cpi.ReplicaCatalogException)14 EntityManager (javax.persistence.EntityManager)13 DataProduct (org.apache.airavata.registry.core.replica.catalog.model.DataProduct)9 DataReplicaLocation (org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation)4 ArrayList (java.util.ArrayList)3 DataProductModel (org.apache.airavata.model.data.replica.DataProductModel)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Query (javax.persistence.Query)1 DataReplicaLocationModel (org.apache.airavata.model.data.replica.DataReplicaLocationModel)1 Initialize (org.apache.airavata.replica.catalog.util.Initialize)1 BeforeClass (org.junit.BeforeClass)1