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
This commit is contained in:
Luca Frosini 2017-12-14 17:09:49 +00:00
parent 5a889f1f63
commit dabcadaf5d
1 changed files with 25 additions and 20 deletions

View File

@ -1,6 +1,3 @@
/**
*
*/
package org.gcube.documentstore.persistence; package org.gcube.documentstore.persistence;
import java.util.Arrays; 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 final String USER_AGENT = "document-store-lib-accounting-service";
private static String FORCED_URL;
private HTTPCall httpCall; private HTTPCall httpCall;
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'"; private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
@ -48,13 +47,20 @@ public class PersistenceAccountingService extends PersistenceBackend {
.addCondition(String.format(containsFormat, SERVICE_ENTRY_NAME)).setResult("$entry/text()"); .addCondition(String.format(containsFormat, SERVICE_ENTRY_NAME)).setResult("$entry/text()");
} }
protected static void forceURL(String url) {
FORCED_URL = url;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception { protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception {
String url = null;
String url = configuration.getProperty(URL_PROPERTY_KEY); if(FORCED_URL!=null) {
url = FORCED_URL;
} else {
url = configuration.getProperty(URL_PROPERTY_KEY);
if (url == null || url.compareTo("") == 0) { if (url == null || url.compareTo("") == 0) {
logger.debug("Invalid URL provided from Configuration. Looking for RunningInstance."); logger.debug("Invalid URL provided from Configuration. Looking for RunningInstance.");
SimpleQuery serviceQuery = queryForService(); SimpleQuery serviceQuery = queryForService();
@ -69,6 +75,7 @@ public class PersistenceAccountingService extends PersistenceBackend {
url = addresses.get(index); url = addresses.get(index);
} }
}
logger.debug("Accounting Service URL to be contacted is {}", url); logger.debug("Accounting Service URL to be contacted is {}", url);
httpCall = new HTTPCall(url, USER_AGENT); httpCall = new HTTPCall(url, USER_AGENT);
@ -94,10 +101,9 @@ public class PersistenceAccountingService extends PersistenceBackend {
protected void accountWithFallback(Record... records) throws Exception { protected void accountWithFallback(Record... records) throws Exception {
try { try {
send(records); send(records);
} catch (Exception e) { } catch (Throwable e) {
super.accountWithFallback(records); super.accountWithFallback(records);
} }
} }
@Override @Override
@ -117,7 +123,6 @@ public class PersistenceAccountingService extends PersistenceBackend {
@Override @Override
protected void clean() throws Exception { protected void clean() throws Exception {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }