Search in sources :

Example 1 with DataReplicaLocation

use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.

the class ReplicaCatalogImpl method updateReplicaLocation.

@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;
}
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 2 with DataReplicaLocation

use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.

the class ReplicaCatalogImpl method getReplicaLocation.

@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();
        }
    }
}
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 3 with DataReplicaLocation

use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.

the class ThriftDataModelConversion method getUpdatedDataProduct.

public static DataProduct getUpdatedDataProduct(DataProductModel dataProductModel, DataProduct dataProduct) {
    dataProduct.setProductUri(dataProductModel.getProductUri());
    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);
    }
    return dataProduct;
}
Also used : DataProductMetaData(org.apache.airavata.registry.core.replica.catalog.model.DataProductMetaData) ArrayList(java.util.ArrayList) DataReplicaLocation(org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation) Timestamp(java.sql.Timestamp)

Example 4 with DataReplicaLocation

use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation in project airavata by apache.

the class ReplicaCatalogImpl method removeReplicaLocation.

@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;
}
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 5 with DataReplicaLocation

use of org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation 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)

Aggregations

DataReplicaLocation (org.apache.airavata.registry.core.replica.catalog.model.DataReplicaLocation)5 EntityManager (javax.persistence.EntityManager)4 ReplicaCatalogException (org.apache.airavata.registry.cpi.ReplicaCatalogException)4 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 DataProductMetaData (org.apache.airavata.registry.core.replica.catalog.model.DataProductMetaData)1