Search in sources :

Example 6 with InventoryNode

use of org.opennms.rancid.InventoryNode in project opennms by OpenNMS.

the class InventoryService method getRancidNodeList.

/**
 * <p>getRancidNodeList</p>
 *
 * @param nodeid a int.
 * @param group a {@link java.lang.String} object.
 * @return a java$util$Map object.
 */
public Map<String, Object> getRancidNodeList(int nodeid, String group) {
    LOG.debug("getRancidlist start: nodeid: {} group: {}", nodeid, group);
    Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
    String rancidName = (String) nodeModel.get("id");
    List<InventoryWrapper> ranlist = new ArrayList<>();
    RancidNode rn;
    try {
        rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, group, rancidName);
        nodeModel.put("devicename", rn.getDeviceName());
    } catch (RancidApiException e) {
        if (e.getRancidCode() == 2) {
            LOG.debug("No Inventory found in CVS repository for nodeid:{} nodeLabel: {}", nodeid, rancidName);
        } else {
            nodeModel.put("RWSStatus", e.getLocalizedMessage());
            LOG.error(e.getLocalizedMessage());
        }
        return nodeModel;
    }
    RWSResourceList versionList;
    try {
        versionList = RWSClientApi.getRWSResourceConfigList(m_cp, group, rancidName);
    } catch (RancidApiException e) {
        nodeModel.put("RWSStatus", e.getLocalizedMessage());
        LOG.error(e.getLocalizedMessage());
        return nodeModel;
    }
    List<String> versionListStr = versionList.getResource();
    Iterator<String> iter1 = versionListStr.iterator();
    String vs;
    while (iter1.hasNext()) {
        vs = iter1.next();
        InventoryNode in = (InventoryNode) rn.getNodeVersions().get(vs);
        InventoryWrapper inwr = new InventoryWrapper(in.getVersionId(), in.getCreationDate(), group, in.getConfigurationUrl());
        ranlist.add(inwr);
    }
    nodeModel.put("grouptable", ranlist);
    return nodeModel;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) ArrayList(java.util.ArrayList) RancidApiException(org.opennms.rancid.RancidApiException) RWSResourceList(org.opennms.rancid.RWSResourceList) InventoryNode(org.opennms.rancid.InventoryNode)

Example 7 with InventoryNode

use of org.opennms.rancid.InventoryNode in project opennms by OpenNMS.

the class InventoryService method getInventory.

/**
 * <p>getInventory</p>
 *
 * @param nodeid a int.
 * @param group a {@link java.lang.String} object.
 * @param version a {@link java.lang.String} object.
 * @return a java$util$Map object.
 */
public Map<String, Object> getInventory(int nodeid, String group, String version) {
    LOG.debug("getInventoryNode start: nodeid: {} group: {} version: {}", nodeid, group, version);
    Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
    String rancidName = (String) nodeModel.get("id");
    try {
        RancidNode rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, group, rancidName);
        InventoryNode in = (InventoryNode) rn.getNodeVersions().get(version);
        nodeModel.put("devicename", rancidName);
        nodeModel.put("groupname", group);
        nodeModel.put("version", version);
        nodeModel.put("status", in.getParent().getState());
        nodeModel.put("creationdate", in.getCreationDate());
        nodeModel.put("swconfigurationurl", in.getSoftwareImageUrl());
        nodeModel.put("configurationurl", in.getConfigurationUrl());
        LOG.debug("getInventoryNode date: {}", in.getCreationDate());
        List<InventoryElement2> ie = RWSClientApi.getRWSRancidNodeInventoryElement2(m_cp, rn, version);
        Iterator<InventoryElement2> iter1 = ie.iterator();
        while (iter1.hasNext()) {
            InventoryElement2 ietmp = iter1.next();
            LOG.debug("Adding inventory: {}", ietmp.expand());
        }
        nodeModel.put("inventory", ie);
    } catch (RancidApiException e) {
        if (e.getRancidCode() == 2) {
            LOG.debug("No Inventory found in CVS repository for nodeid:{} nodeLabel: {}", nodeid, rancidName);
        } else {
            nodeModel.put("RWSStatus", e.getLocalizedMessage());
            LOG.error(e.getLocalizedMessage());
        }
    }
    return nodeModel;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RancidApiException(org.opennms.rancid.RancidApiException) InventoryElement2(org.opennms.rancid.InventoryElement2) InventoryNode(org.opennms.rancid.InventoryNode)

Aggregations

InventoryNode (org.opennms.rancid.InventoryNode)7 RancidNode (org.opennms.rancid.RancidNode)7 RancidApiException (org.opennms.rancid.RancidApiException)5 ArrayList (java.util.ArrayList)4 RWSResourceList (org.opennms.rancid.RWSResourceList)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 InventoryElement2 (org.opennms.rancid.InventoryElement2)2 InventoryMemory (org.opennms.rancid.InventoryMemory)1 InventorySoftware (org.opennms.rancid.InventorySoftware)1 RWSBucket (org.opennms.rancid.RWSBucket)1 BucketItem (org.opennms.rancid.RWSBucket.BucketItem)1 Tuple (org.opennms.rancid.Tuple)1