use of org.opennms.rancid.Tuple in project opennms by OpenNMS.
the class InventoryReportCalculator method calculate.
/**
* <p>calculate</p>
*/
public void calculate() {
rnbi = new RwsNbinventoryreport();
rnbi.setUser(user);
rnbi.setReportRequestDate(StringUtils.toStringEfficiently(reportRequestDate));
boolean withKey = false;
if (theField.compareTo("") != 0) {
withKey = true;
rnbi.setTheField(theField);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d");
Date tmp_date = new Date();
try {
tmp_date = format.parse(theDate);
} catch (ParseException pe) {
tmp_date = Calendar.getInstance().getTime();
}
LOG.debug("calculate:report date[{}]", tmp_date.toString());
rnbi.setReportDate(tmp_date.toString());
int totalGroups = 0;
int groupsMatching = 0;
int groupWithoutNodes = 0;
int groupsWithNodesWithoutinventoryAtAll = 0;
int groupsWithNodesWithoutinventoryAtReportDate = 0;
for (String groupName : getGroups()) {
LOG.debug("calculate:report group [{}]", groupName);
totalGroups++;
GroupSet gs = new GroupSet();
gs.setGroupSetName(groupName);
int totalNodes = 0;
int nodeMatching = 0;
int nodesWithoutinventoryAtAll = 0;
int nodesWithoutinventoryAtReportDate = 0;
boolean groupHasDevices = false;
boolean groupHasNodesWithoutinventoryAtAll = false;
boolean groupHasNodesWithoutinventoryAtrequestDate = false;
for (String deviceName : getDeviceListOnGroup(groupName)) {
totalNodes++;
LOG.debug("calculate:report device [{}]", deviceName);
RancidNode rancidNode = getFullNode(groupName, deviceName);
if (rancidNode == null) {
groupHasNodesWithoutinventoryAtAll = true;
nodesWithoutinventoryAtAll++;
continue;
}
InventoryNode invNode = new InventoryNode(rancidNode);
boolean found = false;
for (String versionMatch : getVersionListOnDevice(deviceName, groupName)) {
invNode = (InventoryNode) rancidNode.getNodeVersions().get(versionMatch);
LOG.debug("calculate:report parsing InventoryNode version[{}] date [{}]", invNode.getVersionId(), invNode.getCreationDate());
if (tmp_date.compareTo(invNode.getCreationDate()) > 0) {
found = true;
LOG.debug("calculate:report Date found is [{}] version is [{}]", invNode.getCreationDate(), versionMatch);
break;
}
}
//end for on version
if (found == false) {
LOG.debug("calculate: device has no configuration at this date[{}]", deviceName);
groupHasNodesWithoutinventoryAtrequestDate = true;
nodesWithoutinventoryAtReportDate++;
continue;
}
//we have groupname devicename and version
NodeBaseInventory nodeBaseInv = getNodeBaseInventory(deviceName, groupName, invNode.getVersionId());
Nbisinglenode nbisn = new Nbisinglenode();
boolean includeNbisn = false;
nbisn.setConfigurationurl(nodeBaseInv.getConfigurationurl());
nbisn.setCreationdate(nodeBaseInv.getCreationdate());
nbisn.setDevicename(nodeBaseInv.getDevicename());
nbisn.setGroupname(nodeBaseInv.getGroupname());
nbisn.setStatus(nodeBaseInv.getStatus());
nbisn.setSwconfigurationurl(nodeBaseInv.getSwconfigurationurl());
nbisn.setVersion(nodeBaseInv.getVersion());
List<InventoryElement2RP> ie2rpList = new ArrayList<InventoryElement2RP>();
for (InventoryElement2 ie2 : nodeBaseInv.getIe()) {
InventoryElement2RP ie2rp = new InventoryElement2RP();
boolean addInventoryElement = false;
for (Tuple tuple : ie2.getTupleList()) {
if (withKey) {
if (Pattern.matches(theField, tuple.getDescription()) || Pattern.matches(theField, tuple.getName())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
if (tuple.getName().equalsIgnoreCase("name")) {
ie2rp.setName(tuple.getDescription());
} else {
TupleRP trp = new TupleRP();
trp.setName(tuple.getName());
trp.setDescription(tuple.getDescription());
ie2rp.addTupleRP(trp);
}
}
for (InventoryMemory im : ie2.getMemoryList()) {
if (withKey) {
if (Pattern.matches(theField, "Memory") || Pattern.matches(theField, im.getType())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
InventoryMemoryRP imrp = new InventoryMemoryRP();
imrp.setType(im.getType());
imrp.setSize(im.getSize());
ie2rp.addInventoryMemoryRP(imrp);
}
for (InventorySoftware is : ie2.getSoftwareList()) {
if (withKey) {
if (Pattern.matches(theField, "Software") || Pattern.matches(theField, is.getType()) || Pattern.matches(theField, is.getVersion())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
InventorySoftwareRP isrp = new InventorySoftwareRP();
isrp.setType(is.getType());
isrp.setVersion(is.getVersion());
ie2rp.addInventorySoftwareRP(isrp);
}
if (addInventoryElement)
ie2rpList.add(ie2rp);
}
nbisn.setInventoryElement2RP(ie2rpList);
if (includeNbisn) {
nodeMatching++;
groupHasDevices = true;
gs.addNbisinglenode(nbisn);
}
}
gs.setTotalNodes(totalNodes);
gs.setNodesMatching(nodeMatching);
gs.setNodesWithoutinventoryAtReportDate(nodesWithoutinventoryAtReportDate);
gs.setNodesWithoutinventoryAtAll(nodesWithoutinventoryAtAll);
rnbi.addGroupSet(gs);
if (groupHasDevices)
groupsMatching++;
else
groupWithoutNodes++;
if (groupHasDevices && groupHasNodesWithoutinventoryAtAll)
groupsWithNodesWithoutinventoryAtAll++;
if (groupHasDevices && groupHasNodesWithoutinventoryAtrequestDate)
groupsWithNodesWithoutinventoryAtReportDate++;
}
//end for groups
rnbi.setTotalGroups(totalGroups);
rnbi.setGroupsMatching(groupsMatching);
rnbi.setGroupsWithNodesWithoutinventoryAtAll(groupsWithNodesWithoutinventoryAtAll);
rnbi.setGroupsWithNodesWithoutinventoryAtReportDate(groupsWithNodesWithoutinventoryAtReportDate);
rnbi.setGroupWithoutNodes(groupWithoutNodes);
}
Aggregations