diff --git a/distro/changelog.xml b/distro/changelog.xml index 9123f80..b643994 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -3,8 +3,10 @@ Added HTTPS support #8758 + Added HTTP Redirection support #8758 Added HAProxy discovery support #8758 Restored Fallback capabilities #9016 + Implemented isConnectionActive() added in PersistenceBackend First Release diff --git a/src/main/java/org/gcube/documentstore/persistence/HTTPCall.java b/src/main/java/org/gcube/documentstore/persistence/HTTPCall.java index 000ab6f..ed94f2f 100644 --- a/src/main/java/org/gcube/documentstore/persistence/HTTPCall.java +++ b/src/main/java/org/gcube/documentstore/persistence/HTTPCall.java @@ -232,6 +232,8 @@ public class HTTPCall { StringBuilder result = getStringBuilder(connection.getInputStream()); String res = result.toString(); logger.trace("Server returned content : {}", res); + + connection.disconnect(); } diff --git a/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java b/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java index ef68391..48d77ab 100644 --- a/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java +++ b/src/main/java/org/gcube/documentstore/persistence/PersistenceAccountingService.java @@ -3,18 +3,14 @@ */ package org.gcube.documentstore.persistence; -import java.io.StringWriter; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Random; -import javax.xml.bind.JAXBContext; - import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.documentstore.persistence.HTTPCall.HTTPMETHOD; import org.gcube.documentstore.records.DSMapper; import org.gcube.documentstore.records.Record; -import org.gcube.documentstore.records.SerializableList; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.icclient.ICFactory; import org.slf4j.Logger; @@ -84,31 +80,18 @@ public class PersistenceAccountingService extends PersistenceBackend { */ @Override protected void reallyAccount(Record record) throws Exception { - String marshalledRecord = DSMapper.marshal(record); - logger.trace("Goign to persist {} {}", Record.class.getSimpleName(), marshalledRecord); - + logger.trace("Going to persist {} {}", Record.class.getSimpleName(), marshalledRecord); httpCall.call(PATH_SERVICE_INSERT_ACCOUNTING, HTTPMETHOD.POST, marshalledRecord, HTTPCall.APPLICATION_JSON_CHARSET_UTF_8); - } @Override protected void accountWithFallback(Record... records) throws Exception { try { - List valuesList = new ArrayList(); - for (Record record : records) { - valuesList.add(DSMapper.marshal(record)); - } - SerializableList list = new SerializableList(valuesList); - - JAXBContext contextRecord = JAXBContext.newInstance(SerializableList.class); - StringWriter writer = new StringWriter(); - contextRecord.createMarshaller().marshal(list, writer); - - String body = writer.toString(); - - logger.trace("Goign to persist {}s {}", Record.class.getSimpleName(), body); + List list = Arrays.asList(records); + String body = DSMapper.marshal(list); + logger.trace("Going to persist {}s {}", Record.class.getSimpleName(), body); httpCall.call(PATH_SERVICE_INSERTS_ACCOUNTING, HTTPMETHOD.POST, body, HTTPCall.APPLICATION_XML_CHARSET_UTF_8); } catch (Exception e) { @@ -127,6 +110,14 @@ public class PersistenceAccountingService extends PersistenceBackend { protected void closeConnection() throws Exception {} @Override - protected void closeAndClean() throws Exception {} + public boolean isConnectionActive() throws Exception { + return true; + } + @Override + protected void clean() throws Exception { + // TODO Auto-generated method stub + + } + } diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceAccountingServiceTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceAccountingServiceTest.java index d1f57bc..6aad1ef 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceAccountingServiceTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceAccountingServiceTest.java @@ -3,9 +3,15 @@ */ package org.gcube.documentstore.persistence; +import java.util.Arrays; +import java.util.List; + +import org.gcube.documentstore.records.DSMapper; import org.gcube.documentstore.records.Record; import org.gcube.documentstore.utility.TestUsageRecord; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it @@ -13,6 +19,8 @@ import org.junit.Test; */ public class PersistenceAccountingServiceTest extends ScopedTest { + private static final Logger logger = LoggerFactory.getLogger(PersistenceAccountingServiceTest.class); + @Test public void testSingleInsertService() throws Exception { String context = ScopedTest.getCurrentContext(); @@ -34,11 +42,17 @@ public class PersistenceAccountingServiceTest extends ScopedTest { persistenceBackend = PersistenceBackendFactory.discoverPersistenceBackend(context, (FallbackPersistenceBackend) persistenceBackend); - int count = 10; + int count = 2; Record[] records = new Record[count]; for (int i = 0; i < count; i++) { records[i] = TestUsageRecord.createTestServiceUsageRecord(); } + + + List recordList = Arrays.asList(records); + String ret = DSMapper.marshal(recordList); + logger.debug(ret); + persistenceBackend.accountWithFallback(records); } @@ -74,7 +88,7 @@ public class PersistenceAccountingServiceTest extends ScopedTest { records[i] = TestUsageRecord.createTestTaskUsageRecord(); } persistenceBackend.accountWithFallback(records); - + } @Test @@ -91,7 +105,7 @@ public class PersistenceAccountingServiceTest extends ScopedTest { records[i] = TestUsageRecord.createTestJobUsageRecord(); } persistenceBackend.accountWithFallback(records); - + } @Test @@ -113,7 +127,8 @@ public class PersistenceAccountingServiceTest extends ScopedTest { @Test public void testConfiguration() throws Exception { - PersistenceBackendConfiguration persitenceConfiguration = PersistenceBackendConfiguration.getInstance(PersistenceAccountingService.class); + PersistenceBackendConfiguration persitenceConfiguration = PersistenceBackendConfiguration + .getInstance(PersistenceAccountingService.class); PersistenceAccountingService accountingService = new PersistenceAccountingService(); accountingService.prepareConnection(persitenceConfiguration); } diff --git a/src/test/java/org/gcube/documentstore/utility/TestUsageRecord.java b/src/test/java/org/gcube/documentstore/utility/TestUsageRecord.java index 0615d53..058dd6d 100644 --- a/src/test/java/org/gcube/documentstore/utility/TestUsageRecord.java +++ b/src/test/java/org/gcube/documentstore/utility/TestUsageRecord.java @@ -233,7 +233,7 @@ public class TestUsageRecord { inputParameters.put(TEST_NESTED_MAP, parameter); - usageRecord.setInputParameters(inputParameters); + //usageRecord.setInputParameters(inputParameters); } catch (InvalidValueException e) { logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);