From dabcadaf5d6a74c2cd0f475eee8dbc63131d3ed0 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 14 Dec 2017 17:09:49 +0000 Subject: [PATCH] Added possibility to force URL git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-accounting-service@160518 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../PersistenceAccountingService.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java b/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java index 5937d5a..4b0e232 100644 --- a/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java +++ b/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java @@ -1,6 +1,3 @@ -/** - * - */ package org.gcube.documentstore.persistence; import java.util.Arrays; @@ -34,6 +31,8 @@ public class PersistenceAccountingService extends PersistenceBackend { private static final String USER_AGENT = "document-store-lib-accounting-service"; + private static String FORCED_URL; + private HTTPCall httpCall; private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'"; @@ -48,26 +47,34 @@ public class PersistenceAccountingService extends PersistenceBackend { .addCondition(String.format(containsFormat, SERVICE_ENTRY_NAME)).setResult("$entry/text()"); } + protected static void forceURL(String url) { + FORCED_URL = url; + } + /** * {@inheritDoc} */ @Override protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception { - - String url = configuration.getProperty(URL_PROPERTY_KEY); - if (url == null || url.compareTo("") == 0) { - logger.debug("Invalid URL provided from Configuration. Looking for RunningInstance."); - SimpleQuery serviceQuery = queryForService(); - List addresses = ICFactory.client().submit(serviceQuery); - if (addresses == null || addresses.isEmpty()) { - String error = String.format("No Running Instance %s:%s found in the current context", SERVICE_CLASS, - SERVICE_NAME); - throw new Exception(error); + String url = null; + if(FORCED_URL!=null) { + url = FORCED_URL; + } else { + url = configuration.getProperty(URL_PROPERTY_KEY); + if (url == null || url.compareTo("") == 0) { + logger.debug("Invalid URL provided from Configuration. Looking for RunningInstance."); + SimpleQuery serviceQuery = queryForService(); + List addresses = ICFactory.client().submit(serviceQuery); + if (addresses == null || addresses.isEmpty()) { + String error = String.format("No Running Instance %s:%s found in the current context", SERVICE_CLASS, + SERVICE_NAME); + throw new Exception(error); + } + Random random = new Random(); + int index = random.nextInt(addresses.size()); + + url = addresses.get(index); } - Random random = new Random(); - int index = random.nextInt(addresses.size()); - - url = addresses.get(index); } logger.debug("Accounting Service URL to be contacted is {}", url); @@ -94,10 +101,9 @@ public class PersistenceAccountingService extends PersistenceBackend { protected void accountWithFallback(Record... records) throws Exception { try { send(records); - } catch (Exception e) { + } catch (Throwable e) { super.accountWithFallback(records); } - } @Override @@ -117,7 +123,6 @@ public class PersistenceAccountingService extends PersistenceBackend { @Override protected void clean() throws Exception { // TODO Auto-generated method stub - } }