Reply To: How to call functions in another entity ?

gnana
Participant
2 years, 3 months ago #3318
Up
1
Down
::

We have 2 options.

1. write code to traverse in BP.
2.Write code in query builder.

1. Here is the script to traverse from windows entity to service entity

Write a function at Service Level to get the status (GetRunnableStatus).

Write a custom groovy function at windows level. Call the above function after you traverse.

nodeWindowsTarget = subject;
com.digitate.ignio.data.graph.model.criteria.Filter filterAcademy = new com.digitate.ignio.data.graph.model.criteria.Filter();
filterAcademy.setField(“HostName”);
filterAcademy.setValue(subject.nodeProperties.HostName);
filterAcademy.setOperator(“=”);
List<com.digitate.ignio.data.graph.model.criteria.Filter> listFilter = new ArrayList<>();
listFilter.add(filterAcademy);
com.digitate.ignio.data.graph.model.criteria.Filters filtersAcademy = new com.digitate.ignio.data.graph.model.criteria.Filters();
filtersAcademy.setFilters(listFilter);
nodeWindowsTarget.setFilters(filtersAcademy);
com.digitate.ignio.utils.ceb.model.NodeRelationship relationshipAcademy = new com.digitate.ignio.utils.ceb.model.NodeRelationship();
relationshipAcademy.setDirection(com.digitate.ignio.data.graph.model.Direction.OUT);
relationshipAcademy.setRelationshipType(“has”);
nodeWindowsTarget.setNodeRelationship(relationshipAcademy);
def ServiceNode;
def myNode = new IgnioNode()
myNode = node.getRelatedNodeByRelationship(nodeWindowsTarget, true);
for (Object nodeRelationship : myNode.getNodeRelationships())
{
boolean nodeFound = false;
if (nodeRelationship != null) {
for (IgnioNode rNode : nodeRelationship.getRelatedNodes()) {
def rLabel = rNode.getLabel();
if (rLabel.trim().equals(“Academy_Service”)) {
ServiceNode = rNode;
nodeFound = true;
break;
}
}
}
if (nodeFound) break;
}
retMap = ServiceNode.getRunnableStatus();

A sample script for Query Builder:

String query = “GraphQuery.node(‘tom:TomcatApplication’).out(‘r1:StoreDataOn’, null).node(‘oraDB:OracleDatabase’).properties(‘tom.Name’, ‘ACME’, ‘oraDB.DBName’, ‘DB01’)”

try {
def iNode = node.executeQuery(query)

for (Object node : iNode)
{
def outMap = node.getRunnableStatus()
}
} catch (Exception ex) {

}