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();
}
}
}
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;
}
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();
}
}
}
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);
}
}
Aggregations