-
Notifications
You must be signed in to change notification settings - Fork 38
Home
+ We are updating this page due to Cyclops 3.0 release.
- Java 8 and Maven 3
- PostgreSQL 9.6: set up the database tables as per instructions in
Install/schema.sh
- RabbitMQ 3.6: set up queues, exchanges and bindings as per instructions in
Install/bindings.sh
- Execute
mvn package assembly:single
in UDR, CDR, Coin and Billing folders - Fill information and credentials in each microservice's configuration file
- Start compiled JARs with their respective configuration file
java -jar service.jar service.conf
Upload usage data representing consumption of your services/users to the UDR micro service
- via RabbitMQ's queue
cyclops.udr.consume
- via HTTP POST at
IP:PORT/usage
Both accept data in JSON and require metric
, account
, usage
and unit
fields to be present. Time
field is either provided in milliseconds or generated automatically, where remaining data you might have goes into data
, as in the example below.
{
"metric": "Memory",
"account": "Martin",
"time": 1493450936000,
"usage": 1024,
"unit": "MB",
"data": {
"project": "ABC",
"host": "gentoo"
}
}
Rule engine sitting between UDR and CDR micro service expects pricing rules via HTTP POST at IP:PORT/rule
as plain text. The full documentation is available here.
An example pricing rule rating Storage
metric (3 CHF per unit of storage):
import ch.icclab.cyclops.facts.Usage;
import ch.icclab.cyclops.facts.Charge;
rule "Static rating for Storage"
salience 50
when
$usage: Usage(metric == "Storage")
then
Charge charge = new Charge($usage);
charge.setCharge(3 * $usage.getUsage());
charge.setCurrency("CHF");
retract($usage);
insert(charge);
end
And system rule that always needs to be present:
import ch.icclab.cyclops.facts.Charge;
import java.util.List;
global ch.icclab.cyclops.publish.Messenger messenger;
rule "Broadcast charge data"
salience 20
when
$charge: List( size > 0 ) from collect ( Charge() )
then
messenger.broadcast($charge);
$charge.forEach(c->retract(c));
end
Second rule engine is put between CDR and Billing micro services and expects billing rules via HTTP POST at IP:PORT/rule
as plain text. The full documentation is available here.
Two system rules are necessary, but feel free to add (with higher priority) any discounting and VAT rules you want.
import ch.icclab.cyclops.facts.BillRequest;
import ch.icclab.cyclops.facts.Charge;
import ch.icclab.cyclops.facts.Bill;
import java.util.List;
rule "Collect CDRs for the Bill Request"
salience 50
when
$request: BillRequest($accounts: accounts)
$CDRs: List(size > 0) from collect (Charge(account memberOf $accounts))
then
// bills for each currency of account\'s CDRs
List<Bill> bills = $request.process($CDRs);
// add bills to the working memory
bills.forEach(bill->insert(bill));
// remove processed CDRs and the bill request
$CDRs.forEach(c->retract(c));
retract($request);
end
import ch.icclab.cyclops.facts.Bill;
import java.util.List;
global ch.icclab.cyclops.publish.Messenger messenger;
rule "Broadcast generated bills"
salience 30
when
$bills: List(size > 0) from collect (Bill())
then
// broadcast and remove processed bills
messenger.broadcast($bills);
$bills.forEach(bill->retract(bill));
end