git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-accounting-service@152699 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9e079107f5
commit
0c119f0bfb
|
@ -3,8 +3,10 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.data-publishing.document-store-lib-accounting-service.1-1-0" date="${buildDate}">
|
||||
<Change>Added HTTPS support #8758</Change>
|
||||
<Change>Added HTTP Redirection support #8758</Change>
|
||||
<Change>Added HAProxy discovery support #8758</Change>
|
||||
<Change>Restored Fallback capabilities #9016</Change>
|
||||
<Change>Implemented isConnectionActive() added in PersistenceBackend</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-publishing.document-store-lib-accounting-service.1-0-0" date="${buildDate}">
|
||||
<Change>First Release</Change>
|
||||
|
|
|
@ -232,6 +232,8 @@ public class HTTPCall {
|
|||
StringBuilder result = getStringBuilder(connection.getInputStream());
|
||||
String res = result.toString();
|
||||
logger.trace("Server returned content : {}", res);
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> valuesList = new ArrayList<String>();
|
||||
for (Record record : records) {
|
||||
valuesList.add(DSMapper.marshal(record));
|
||||
}
|
||||
SerializableList<String> list = new SerializableList<String>(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<Record> 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Record> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue