Difference between revisions of "Accounting Library"

From Gcube Wiki
Jump to: navigation, search
(Library)
Line 19: Line 19:
 
=== Collecting Usage Record ===
 
=== Collecting Usage Record ===
  
The library allow to collect Usage Records providing the following functionality:
+
The library allows to collect Usage Records providing the following functionality:
  
 
* Attribute Validation and Harmonization
 
* Attribute Validation and Harmonization
Line 28: Line 28:
 
* Generic Key-Value method (key:String, value:Comparable<? extends Serializable> )
 
* Generic Key-Value method (key:String, value:Comparable<? extends Serializable> )
  
For the same attribute each of the record is idempotent. This means that any of the way you are using to set a properties the value is always validated and harmonized by the same code.  
+
The methods are idempotent. This means that any of the way you are using to set a properties the value is always validated and harmonized in the same way (i.e. from the the same code).  
Different methods for different properties can be used together.
+
You can mix different methods for different properties.
  
 
Moreover you can provide a Map<String,Comparable<? extends Serializable>> to set all properties at once.
 
Moreover you can provide a Map<String,Comparable<? extends Serializable>> to set all properties at once.
Line 35: Line 35:
 
==== Usage Record Record Validation and Harmonization ====
 
==== Usage Record Record Validation and Harmonization ====
  
This library provide support to validate and harmonize the values to a common type (e.g. the string representation on an integer to a integer type, the string representation of an enum to the enum type).
+
This library provides support to validate and harmonize the values to a common type (e.g. the string representation on an integer to a integer type, the string representation of an enum to the enum type).
 
This functionality is very useful especially when the developer use a the key-value method.
 
This functionality is very useful especially when the developer use a the key-value method.
  
for further details see [[Accounting Model]].
+
For further details see [[Accounting Model]].
  
 
=== Buffering & Aggregating Usage Record ===
 
=== Buffering & Aggregating Usage Record ===
  
The library provide buffering capabilities.
+
The library provides buffering capabilities.
While the records are buffered for each new records requested to be accounted the library try to aggregate the new record with the one has already buffered. The aggregation made in this phase is lossless. In other words, the ''UsageRecord'' aggregated are only the ones having the same values for required fields.
+
For each new request of accounting a new record, the library buffers them and check is is possible to aggregate with the ones has already buffered. The aggregation made in this phase is lossless. In other words, the ''UsageRecord'' aggregated are only the ones having the same values for required fields.
  
 
=== Storing Usage Record ===
 
=== Storing Usage Record ===
Line 60: Line 60:
  
  
Every component which has to account ''UsageRecord''s must depend from this library.
+
Every components has to account ''UsageRecord''s must depend from this library.
  
In some cases you have also to depended from [[Document Store  Lib | Document Store Lib]]. The maven coordinates of  Document Store  Lib are:
+
In some cases you may also to depended from [[Document Store  Lib | Document Store Lib]]. The maven coordinates of  Document Store  Lib are:
  
 
''<groupId>'''''org.gcube.data-publishing'''''</groupId>''
 
''<groupId>'''''org.gcube.data-publishing'''''</groupId>''
Line 83: Line 83:
  
 
This library must be available on every node of the infrastructure. To respect as much possible the smartgears ZERO-DEPENDENCY paradigm a simple couchdb-connector (simple HTTP client library) has been developed.
 
This library must be available on every node of the infrastructure. To respect as much possible the smartgears ZERO-DEPENDENCY paradigm a simple couchdb-connector (simple HTTP client library) has been developed.
 +
 +
Other implementations are:
 +
 +
''<groupId>'''''org.gcube.accounting'''''</groupId>''
 +
 +
''<artifactId>'''''accounting-lib-persistence-couchbase'''''</artifactId>''
 +
 +
 +
 +
''<groupId>'''''org.gcube.accounting'''''</groupId>''
 +
 +
''<artifactId>'''''accounting-lib-persistence-mongodb'''''</artifactId>''
  
 
== Deployment ==
 
== Deployment ==
  
 
'''Accounting Lib''' and the '''Accounting Persistence Lib''' are already available on gCore and smartgears bundles (gHN and wHN).
 
'''Accounting Lib''' and the '''Accounting Persistence Lib''' are already available on gCore and smartgears bundles (gHN and wHN).

Revision as of 11:07, 9 May 2016

This component is responsible of collecting, harmonizing and storing Accounting data.

Accounting Lib in the Accounting Architecture

The following image evidences the accounting-lib component as part of Accounting Architecture:

Accounting-architecture-accounting-lib.png

Library

The library has been tough to provide a common way to elaborate Usage Record (UR) (see Accounting Model to check which Usage Records are supported by default). In particular is responsible for:

  • Collecting Accounting Data

It uses facilities provided by Document Store Lib for:

  • Aggregating
  • Buffering
  • Storing

Collecting Usage Record

The library allows to collect Usage Records providing the following functionality:

  • Attribute Validation and Harmonization
  • Usage Record Validation

To set the various properties of an usage records two different methods are available

  • Developer Friendly methods (getter and setter)
  • Generic Key-Value method (key:String, value:Comparable<? extends Serializable> )

The methods are idempotent. This means that any of the way you are using to set a properties the value is always validated and harmonized in the same way (i.e. from the the same code). You can mix different methods for different properties.

Moreover you can provide a Map<String,Comparable<? extends Serializable>> to set all properties at once.

Usage Record Record Validation and Harmonization

This library provides support to validate and harmonize the values to a common type (e.g. the string representation on an integer to a integer type, the string representation of an enum to the enum type). This functionality is very useful especially when the developer use a the key-value method.

For further details see Accounting Model.

Buffering & Aggregating Usage Record

The library provides buffering capabilities. For each new request of accounting a new record, the library buffers them and check is is possible to aggregate with the ones has already buffered. The aggregation made in this phase is lossless. In other words, the UsageRecord aggregated are only the ones having the same values for required fields.

Storing Usage Record

The library discover dynamically the Accounting Persistence Lib to persist the UsageRecords. If no library is discovered or if the storing fails (e.g. for network issue) the UsageRecords are persisted using a Fallback Persistence (on filesystem). There is a recurrent task which periodically (10 min and only if an Accounting Persistence Lib has been discovered on classpath) retry to persist UsageRecords persisted from FallBack Persistence (on filesystem).

Development

The library is identified by the following maven coordinates:

<groupId>org.gcube.accounting</groupId>

<artifactId>accounting-lib</artifactId>


Every components has to account UsageRecords must depend from this library.

In some cases you may also to depended from Document Store Lib. The maven coordinates of Document Store Lib are:

<groupId>org.gcube.data-publishing</groupId>

<artifactId>document-store-lib</artifactId>


Please set the scope of both library to PROVIDED if your component runs on a container gHN or vHN.

Accounting Persistence Lib

The current implementation of persistence for this library is for CouchDB storage.

<groupId>org.gcube.accounting</groupId>

<artifactId>accounting-lib-persistence-couchdb</artifactId>

The developer MUST not depend from this library. This library is already available on container because has been included in gCore and smartgears bundles. Also, when a component does not run on a container , the component MUST not include this library as dependency. It will be responsibility of the person in charge of deploying the component to provide also that library.

This library must be available on every node of the infrastructure. To respect as much possible the smartgears ZERO-DEPENDENCY paradigm a simple couchdb-connector (simple HTTP client library) has been developed.

Other implementations are:

<groupId>org.gcube.accounting</groupId>

<artifactId>accounting-lib-persistence-couchbase</artifactId>


<groupId>org.gcube.accounting</groupId>

<artifactId>accounting-lib-persistence-mongodb</artifactId>

Deployment

Accounting Lib and the Accounting Persistence Lib are already available on gCore and smartgears bundles (gHN and wHN).