From 9ec79fc8c5f71be206b8cc5323760a6ab8f4fc6a Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 15 Mar 2021 15:03:42 +0100 Subject: [PATCH] Created JobUsageRecord Table sql file --- .../PersistencePostgreSQLTest.java | 55 +++++++++++++- src/test/resources/JobUsageRecordTable.sql | 19 +++++ .../resources/insert-usagerecord-example.sql | 74 +++++++++++++++---- 3 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 src/test/resources/JobUsageRecordTable.sql diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistencePostgreSQLTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistencePostgreSQLTest.java index aeb6228..3b2f027 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistencePostgreSQLTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistencePostgreSQLTest.java @@ -4,9 +4,15 @@ package org.gcube.documentstore.persistence; import org.gcube.accounting.datamodel.UsageRecord; +import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; +import org.gcube.accounting.datamodel.aggregation.AggregatedPortletUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; +import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; +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.StorageStatusRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.junit.Assert; @@ -68,14 +74,45 @@ public class PersistencePostgreSQLTest extends ContextTest { return aggregatedStorageUsageRecord; } + protected AggregatedJobUsageRecord getTestAggregatedJobUsageRecord() throws Exception { + JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord(); + AggregatedJobUsageRecord aggregatedJobUsageRecord = new AggregatedJobUsageRecord(jobUsageRecord); + return aggregatedJobUsageRecord; + } + + protected AggregatedPortletUsageRecord getTestAggregatedPortletUsageRecord() throws Exception { + PortletUsageRecord portletUsageRecord = TestUsageRecord.createTestPortletUsageRecord(); + AggregatedPortletUsageRecord aggregatedPortletUsageRecord = new AggregatedPortletUsageRecord(portletUsageRecord); + return aggregatedPortletUsageRecord; + } + + protected AggregatedStorageStatusRecord getTestAggregatedStorageStatusRecord() throws Exception { + StorageStatusRecord storageStatusRecord = TestUsageRecord.createTestStorageVolumeUsageRecord(); + AggregatedStorageStatusRecord aggregatedStorageStatusRecord = new AggregatedStorageStatusRecord(storageStatusRecord); + return aggregatedStorageStatusRecord; + } + @Test public void testSQLStatementString() throws Exception { - UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord(); PersistencePostgreSQL persistencePostgreSQL = new PersistencePostgreSQL(); + + UsageRecord usageRecord = getTestAggregatedJobUsageRecord(); String sql = persistencePostgreSQL.getSQLInsertCommand(usageRecord); logger.debug(sql); - usageRecord = TestUsageRecord.createTestStorageUsageRecord(); + usageRecord = getTestAggregatedPortletUsageRecord(); + sql = persistencePostgreSQL.getSQLInsertCommand(usageRecord); + logger.debug(sql); + + usageRecord = getTestAggregatedServiceUsageRecord(); + sql = persistencePostgreSQL.getSQLInsertCommand(usageRecord); + logger.debug(sql); + + usageRecord = getTestAggregatedStorageStatusRecord(); + sql = persistencePostgreSQL.getSQLInsertCommand(usageRecord); + logger.debug(sql); + + usageRecord = getTestAggregatedStorageUsageRecord(); sql = persistencePostgreSQL.getSQLInsertCommand(usageRecord); logger.debug(sql); } @@ -104,10 +141,22 @@ public class PersistencePostgreSQLTest extends ContextTest { PersistencePostgreSQL persistencePostgreSQL = (PersistencePostgreSQL) persistenceBackend; persistencePostgreSQL.newConnection(); for(int i=0; i<10; i++) { - UsageRecord usageRecord = getTestAggregatedServiceUsageRecord(); + UsageRecord usageRecord = getTestAggregatedJobUsageRecord(); persistencePostgreSQL.insert(usageRecord); + + usageRecord = getTestAggregatedPortletUsageRecord(); + persistencePostgreSQL.insert(usageRecord); + + usageRecord = getTestAggregatedServiceUsageRecord(); + persistencePostgreSQL.insert(usageRecord); + + usageRecord = getTestAggregatedStorageStatusRecord(); + persistencePostgreSQL.insert(usageRecord); + + usageRecord = getTestAggregatedStorageUsageRecord(); persistencePostgreSQL.insert(usageRecord); + } persistencePostgreSQL.commitAndClose(); } diff --git a/src/test/resources/JobUsageRecordTable.sql b/src/test/resources/JobUsageRecordTable.sql new file mode 100644 index 0000000..c952ece --- /dev/null +++ b/src/test/resources/JobUsageRecordTable.sql @@ -0,0 +1,19 @@ +CREATE TABLE "jobusagerecord"( + id TEXT NOT NULL, + consumer_id TEXT NOT NULL, + creation_time TIMESTAMP WITH TIME ZONE NOT NULL, + scope TEXT NOT NULL, + operation_result operation_result NOT NULL, + caller_qualifier TEXT NOT NULL DEFAULT 'TOKEN', + host TEXT NOT NULL, + service_class TEXT NOT NULL, + service_name TEXT NOT NULL, + job_name TEXT NOT NULL, + duration NUMERIC NOT NULL, + max_invocation_time NUMERIC NOT NULL, + min_invocation_time NUMERIC NOT NULL, + operation_count INTEGER NOT NULL DEFAULT 1, + aggregated BOOLEAN NOT NULL DEFAULT true, + start_time TIMESTAMP WITH TIME ZONE NOT NULL, + end_time TIMESTAMP WITH TIME ZONE NOT NULL +); \ No newline at end of file diff --git a/src/test/resources/insert-usagerecord-example.sql b/src/test/resources/insert-usagerecord-example.sql index 72094cc..c8bb65c 100644 --- a/src/test/resources/insert-usagerecord-example.sql +++ b/src/test/resources/insert-usagerecord-example.sql @@ -1,20 +1,64 @@ -INSERT INTO serviceusagerecord -(called_method,caller_host,caller_qualifier,consumer_id, -creation_time,duration,host,id, -operation_result,scope,service_class,service_name) +INSERT INTO jobusagerecord +(aggregated,caller_qualifier,consumer_id,creation_time, +duration,end_time,host,id, +job_name,max_invocation_time,min_invocation_time,operation_count, +operation_result,scope,service_class,service_name, +start_time) VALUES -('TestCalledMethod','remotehost','TestCallerQualifier','name.surname', -'2021-03-12 19:10:22.439 +0100',842,'localhost','4cc05634-683c-41e7-9110-3cb3cfb7205d', -'SUCCESS','/gcube/devNext','TestServiceClass','TestServiceName'); +('true','TestCallerQualifier','name.surname','2021-03-15 12:20:32.705 +0100', +295,'2021-03-15 12:20:32.704 +0100','localhost','17abc69a-491e-47ed-994b-9e1db0cf05fd', +'TestJobName',295,295,1, +'SUCCESS','/gcube/devNext','TestServiceClass','TestServiceName', +'2021-03-15 12:20:32.704 +0100'); +---------------------------------------------------------------------------------------- +INSERT INTO portletusagerecord +(aggregated,consumer_id,creation_time,end_time, +id,operation_count,operation_id,operation_result, +portlet_id,scope,start_time) +VALUES +('true','name.surname','2021-03-15 12:20:32.706 +0100','2021-03-15 12:20:32.705 +0100', +'724aee1c-3f7c-40b9-bb27-40211a7b10ca',1,'TestPortletOperationID','SUCCESS', +'TestPortlet','/gcube/devNext','2021-03-15 12:20:32.705 +0100'); +---------------------------------------------------------------------------------------- + +INSERT INTO serviceusagerecord +(aggregated,called_method,caller_host,caller_qualifier, +consumer_id,creation_time,duration,end_time, +host,id,max_invocation_time,min_invocation_time,operation_count, +operation_result,scope,service_class,service_name, +start_time) +VALUES +('true','TestCalledMethod','remotehost','TestCallerQualifier', +'name.surname','2021-03-15 12:20:32.987 +0100',361,'2021-03-15 12:20:32.706 +0100', +'localhost','c386cf48-b955-4683-a3da-372216e34eb3',361,361, +1,'SUCCESS','/gcube/devNext','TestServiceClass', +'TestServiceName','2021-03-15 12:20:32.706 +0100'); + +---------------------------------------------------------------------------------------- + +INSERT INTO storagestatusrecord +(aggregated,consumer_id,creation_time,data_count, +data_service_class,data_service_id,data_service_name,data_type, +data_volume,end_time,id,operation_count, +operation_result,provider_id,scope,start_time) +VALUES ('true','name.surname','2021-03-15 12:20:32.988 +0100',8117, +'dataServiceClass','dataServiceId','dataServiceName','STORAGE', +8086,'2021-03-15 12:20:32.988 +0100','21d68adf-b17f-4a19-85ac-c50ba854cf72',1, +'SUCCESS','testprotocol://providerURI','/gcube/devNext','2021-03-15 12:20:32.988 +0100'); + +---------------------------------------------------------------------------------------- + +INSERT INTO storageusagerecord +(aggregated,consumer_id,creation_time,data_type, +data_volume,end_time,id,operation_count, +operation_result,operation_type,provider_uri,resource_owner, +resource_scope,resource_uri,scope,start_time) +VALUES +('true','name.surname','2021-03-15 12:20:32.990 +0100','STORAGE', +9177,'2021-03-15 12:20:32.989 +0100','11c0f9bb-e04f-4035-a230-50160dad737e',1, +'SUCCESS','READ','testprotocol://providerURI','resource.owner', +'/infrastructure/vo','testprotocol://objectURI','/gcube/devNext','2021-03-15 12:20:32.989 +0100'); -INSERT INTO storageusagerecord -(consumer_id,creation_time,data_type,data_volume, -id,operation_result,operation_type,provider_uri, -resource_owner,resource_scope,resource_uri,scope) -VALUES -('name.surname','2021-03-12 19:10:23.031 +0100','STORAGE',1250, -'3418d820-9329-4d46-a00e-01501980afba','SUCCESS','READ','testprotocol://providerURI', -'resource.owner','/infrastructure/vo','testprotocol://objectURI','/gcube/devNext'); \ No newline at end of file