Fixed url path
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-accounting-service@152926 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
915b6c0808
commit
131aff326f
|
@ -25,7 +25,6 @@ public class PersistenceAccountingService extends PersistenceBackend {
|
|||
private static final Logger logger = LoggerFactory.getLogger(PersistenceAccountingService.class);
|
||||
|
||||
public static final String PATH_SERVICE_INSERT_ACCOUNTING = "/insert/record";
|
||||
public static final String PATH_SERVICE_INSERTS_ACCOUNTING = "/insert/records";
|
||||
|
||||
public static final String URL_PROPERTY_KEY = "URL";
|
||||
|
||||
|
@ -75,25 +74,26 @@ public class PersistenceAccountingService extends PersistenceBackend {
|
|||
httpCall = new HTTPCall(url, USER_AGENT);
|
||||
}
|
||||
|
||||
protected void send(Record... records) throws Exception {
|
||||
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_INSERT_ACCOUNTING, HTTPMETHOD.POST, body, HTTPCall.APPLICATION_XML_CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void reallyAccount(Record record) throws Exception {
|
||||
String marshalledRecord = DSMapper.marshal(record);
|
||||
logger.trace("Going to persist {} {}", Record.class.getSimpleName(), marshalledRecord);
|
||||
httpCall.call(PATH_SERVICE_INSERT_ACCOUNTING, HTTPMETHOD.POST, marshalledRecord, HTTPCall.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
send(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accountWithFallback(Record... records) throws Exception {
|
||||
try {
|
||||
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);
|
||||
|
||||
send(records);
|
||||
} catch (Exception e) {
|
||||
super.accountWithFallback(records);
|
||||
}
|
||||
|
|
|
@ -74,23 +74,6 @@ public class PersistenceAccountingServiceTest extends ScopedTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleInsertTask() throws Exception {
|
||||
String context = ScopedTest.getCurrentContext();
|
||||
|
||||
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(context);
|
||||
persistenceBackend = PersistenceBackendFactory.discoverPersistenceBackend(context,
|
||||
(FallbackPersistenceBackend) persistenceBackend);
|
||||
|
||||
int count = 10;
|
||||
Record[] records = new Record[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
records[i] = TestUsageRecord.createTestTaskUsageRecord();
|
||||
}
|
||||
persistenceBackend.accountWithFallback(records);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleInsertJob() throws Exception {
|
||||
String context = ScopedTest.getCurrentContext();
|
||||
|
|
|
@ -3,22 +3,19 @@
|
|||
*/
|
||||
package org.gcube.documentstore.utility;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -70,8 +67,9 @@ public class TestUsageRecord {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate A Random long in a range between min and max.
|
||||
* This function is internally used to set random duration.
|
||||
* Generate A Random long in a range between min and max. This function is
|
||||
* internally used to set random duration.
|
||||
*
|
||||
* @return the generated random long
|
||||
*/
|
||||
public static long generateRandomLong(long min, long max) {
|
||||
|
@ -80,6 +78,7 @@ public class TestUsageRecord {
|
|||
|
||||
/**
|
||||
* Create a valid #ServiceUsageRecord with scope set automatically.
|
||||
*
|
||||
* @return the created #ServiceUsageRecord
|
||||
*/
|
||||
public static ServiceUsageRecord createTestServiceUsageRecord() {
|
||||
|
@ -104,6 +103,7 @@ public class TestUsageRecord {
|
|||
return usageRecord;
|
||||
|
||||
}
|
||||
|
||||
public final static String TEST_RESOUCE_OWNER = "resource.owner";
|
||||
public final static String TEST_RESOUCE_SCOPE = TEST_SCOPE;
|
||||
|
||||
|
@ -115,6 +115,7 @@ public class TestUsageRecord {
|
|||
|
||||
/**
|
||||
* Create a valid #StorageUsageRecord with scope set automatically.
|
||||
*
|
||||
* @return the created #StorageUsageRecord
|
||||
*/
|
||||
public static StorageUsageRecord createTestStorageUsageRecord() {
|
||||
|
@ -136,7 +137,6 @@ public class TestUsageRecord {
|
|||
|
||||
usageRecord.setQualifier("image/png");
|
||||
|
||||
|
||||
} catch (InvalidValueException | URISyntaxException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -147,6 +147,7 @@ public class TestUsageRecord {
|
|||
|
||||
/**
|
||||
* Create a valid #StorageVolumeUsageRecord with scope set automatically.
|
||||
*
|
||||
* @return the created #StorageVolumeUsageRecord
|
||||
*/
|
||||
public static StorageStatusRecord createTestStorageVolumeUsageRecord() {
|
||||
|
@ -162,8 +163,6 @@ public class TestUsageRecord {
|
|||
usageRecord.setDataServiceId("dataServiceId");
|
||||
usageRecord.setProviderId(new URI(TEST_PROVIDER_URI));
|
||||
|
||||
|
||||
|
||||
} catch (InvalidValueException | URISyntaxException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -181,59 +180,12 @@ public class TestUsageRecord {
|
|||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setJobId(TEST_JOB_ID);
|
||||
usageRecord.setJobName(TEST_JOB_NAME);
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
|
||||
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
|
||||
|
||||
usageRecord.setJobStartTime(startTime);
|
||||
usageRecord.setJobEndTime(endTime);
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
}
|
||||
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static TaskUsageRecord createTestTaskUsageRecord() {
|
||||
|
||||
TaskUsageRecord usageRecord = new TaskUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setTaskId(TEST_TASK_ID);
|
||||
usageRecord.setTaskId(TEST_JOB_ID);
|
||||
usageRecord.setHost(TEST_HOST);
|
||||
|
||||
usageRecord.setRefHostingNodeId(UUID.randomUUID().toString());
|
||||
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
|
||||
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
|
||||
|
||||
usageRecord.setTaskStartTime(startTime);
|
||||
usageRecord.setTaskEndTime(endTime);
|
||||
|
||||
HashMap<String, Serializable> inputParameters = new HashMap<>();
|
||||
inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
|
||||
|
||||
HashMap<String, Serializable> parameter = new HashMap<>();
|
||||
parameter.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
parameter.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
|
||||
|
||||
inputParameters.put(TEST_NESTED_MAP, parameter);
|
||||
|
||||
//usageRecord.setInputParameters(inputParameters);
|
||||
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
|
||||
usageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
||||
usageRecord.setServiceName(TEST_SERVICE_NAME);
|
||||
usageRecord.setJobName(TEST_JOB_NAME);
|
||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
|
@ -242,7 +194,6 @@ public class TestUsageRecord {
|
|||
return usageRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
@ -269,7 +220,4 @@ public class TestUsageRecord {
|
|||
return usageRecord;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue