How-to
The first step to use the API is create the connection to the server. This connection is created from the class MyDBaaSClient, details.
To connect create an instance of the class and pass the default url of the server.
MyDBaaSClient client = new MyDBaaSClient("http://localhost:8080/mydbaas");
You can test if the connection is ok. The following method returns a boolean:
boolean status = client.hasConnection();
With the client object created just invoke the various methods for querying resources.
DBaaSPool dBaaSPool = client.getMyDBaaSs(); HostPool hostPool = client.getMyHosts(); VirtualMachinePool virtualMachinePool = client.getMyVirtualMachines(); DBMSPool dbmsPool = client.getMyDBMSs(); DatabasePool databasePool = client.getMyDatabases();
The return of these methods are objects of the AbstractPool type. These objects have a list of the resources registered in the knowledge base until now.
If you know the code of a particular feature it is possible to recover the registry directly. Just use the method below informing the code and type of resource:
#The code of the resource is integer #Resource types can be: dbaas, host, machine, dbms or database ... = client.resourceLookupByID([resource id], [resource type]);
This method will return the object containing the information of the requested resource. The return type varies with the type of the parameter informed in the method.
From the objects of "Pool" type is possible to add or update new resources. These objects have the methods save() and update(). Here is an example:
#Fill out the new resource DBMS dbms = new DBMS(); #You should check the object boolean check = dbmsPool.checkEntity(dbms); #With the object checked just invoke the method to save boolean result = false; if (check) { result = dbmsPool.save(dbms); }
//... //Updating a resource object //... #Check the object boolean check = dbmsPool.checkEntity(dbms); #With the object checked just invoke the method to update boolean result = false; if (check) { result = dbmsPool.update(dbms); }
Now the cool part! Through the API you can consume the metrics monitored in the different resources. Here is a list of possible ways to consume:
To consume the metrics you need to create an object of class MyMetrics.
#You must pass client object created earlier as a parameter MyMetrics myMetrics = new MyMetrics(client);
1. Last collection of a metric:
#Retrieving the last collection of the metric Size about a particular DBMS Size size = (Size) myMetrics.getMetricSingle(Size.class, dbms, MyMetrics.RESOURCE_TYPE_DBMS, null, null);
Some metrics can generate more than one collection per cycle. For example, if a virtual machine has more than one core per processor. The agent will collect the metric of Cpu for each core. Also exists a method for recovering the metric in this case:
#Retrieving the last collection of the metric Cpu about a particular Virtual Machine List<Object> cpus = myMetrics.getMetricMulti(Cpu.class, vm, MyMetrics.RESOURCE_TYPE_VM, null, null);
This variation can also be used in options 2, 3 and 4.
2. Last collection of a metric starting from a date:
Size size = (Size) myMetrics.getMetricSingle(Size.class, dbms, MyMetrics.RESOURCE_TYPE_DBMS, "15-06-2013", null);
List<Object> cpus = myMetrics.getMetricMulti(Cpu.class, vm, MyMetrics.RESOURCE_TYPE_VM, "15-06-2013 15:30:00", null);
3. Last collection of a metric until a date:
Size size = (Size) myMetrics.getMetricSingle(Size.class, dbms, MyMetrics.RESOURCE_TYPE_DBMS, null, "01-07-2013 10:00");
List<Object> cpus = myMetrics.getMetricMulti(Cpu.class, vm, MyMetrics.RESOURCE_TYPE_VM, null, "22-05-2012");
4. Last collection of a metric between two dates:
Size size = (Size) myMetrics.getMetricSingle(Size.class, dbms, MyMetrics.RESOURCE_TYPE_DBMS, "10-06-2013", "01-07-2013");
List<Object> cpus = myMetrics.getMetricMulti(Cpu.class, vm, MyMetrics.RESOURCE_TYPE_VM, "10-06-2013", "01-07-2013");
5. All collections of a metric:
#Retrieving the all collection of the metric Size about a particular Database List<Object> sizes = myMetrics.getMetricCollection(Size.class, db, MyMetrics.RESOURCE_TYPE_DATABASE, null, null);
6. All collections of a metric starting from a date:
List<Object> sizes = myMetrics.getMetricCollection(Size.class, db, MyMetrics.RESOURCE_TYPE_DATABASE, "02-06-2012", null);
7. All collections of a metric until a date:
List<Object> sizes = myMetrics.getMetricCollection(Size.class, db, MyMetrics.RESOURCE_TYPE_DATABASE, null, "30-07-2013 12:00:00");
8. All collections of a metric between two dates:
List<Object> sizes = myMetrics.getMetricCollection(Size.class, db, MyMetrics.RESOURCE_TYPE_DATABASE, "01-01-2013", "30-06-2013");
Important! You can use the above methods for any resources and their metrics.