Get Live Help
So far we have built some sophisticated types. To create instances, we have the following options:
For this exercise, we will choose the second option (which allows us to get started much faster), and run the createOrg Groovy script in the script editor. This script populates our Org Chart model with interesting data.
The most important part of that script is the following function, which allows you to create an object and set properties on the object:
This function uses the topology service to create or update an object instance. To do that, it requires a typeName and a collection of propertyValues. The typeName is used to create a potential instance of an object of that type. The TopologyService is used to create the instance. The propertyValues are a map of (name, value) pairs. The script iterates over the properties, inspects each one and tries to set that property on the object using the appropriate API.
What happens at the end is critical. Using the topSvc.mergeData() call, we send a potential instance of an object with several properties set. The TopologyService decides whether we need to create an object or simply update the definition for an existing one.
The following is an example call to this function:
This creates a new Employee object. When using this function, you must include all the identity properties at least. You can include additional properties if you want.
With this function we almost have everything we need to create models using scripts. In order to enable iterative development, we need a way to delete old object instances. In this way, we can create a re-entrant Groovy script that cleans up obsolete objects.
The delete function is defined as follows:
Note that we use the createOrUpdateObject call to return the original object. Then we make a TopologyService call to delete it.
At the end of the script, there is a bit of code which allows you to connect the employees to Host systems. This code simply finds some Host instances and manually attaches them to the employees. This code was included so that we can verify whether the alarm propagation works properly.
In a real example, you can add a dashboard that would allow an employee to express interest in objects. Behind the scenes, this dashboard would call code that looks something like this:
...where topologyObject is the object that the user has chosen as interesting. This is pretty much what is done in the Services Operations Console. It is all done using Dashboards and Groovy.
The last step is to build dashboards to visualize the data. The createOrg Groovy script provided in the appendix creates a nice organization.
This appendix includes Groovy scripts used in the Data modeling tutorials.