Search in sources :

Example 21 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class NodeRestService method removeCategoryFromNode.

@DELETE
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response removeCategoryFromNode(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("categoryName") String categoryName) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory category = getCategory(node, categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
        }
        LOG.debug("deleteCaegory: deleting category {} from node {}", categoryName, nodeCriteria);
        node.getCategories().remove(category);
        m_nodeDao.saveOrUpdate(node);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 22 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class NodeRestService method updateCategoryForNode.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response updateCategoryForNode(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("categoryName") final String categoryName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory category = getCategory(node, categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
        }
        LOG.debug("updateCategory: updating category {}", category);
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
        boolean updated = false;
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                updated = true;
            }
        }
        if (updated) {
            LOG.debug("updateCategory: category {} updated", category);
            m_categoryDao.saveOrUpdate(category);
        } else {
            LOG.debug("updateCategory: no fields updated in category {}", category);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 23 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class NodeCacheImpl method populateBodyWithNodeInfo.

/**
     * utility method to populate a Map with the most import node attributes
     *
     * @param body the map
     * @param node the node object
     */
private static void populateBodyWithNodeInfo(Map<String, String> body, OnmsNode node) {
    body.put("nodelabel", node.getLabel());
    body.put("nodesysname", node.getSysName());
    body.put("nodesyslocation", node.getSysLocation());
    body.put("foreignsource", node.getForeignSource());
    body.put("foreignid", node.getForeignId());
    body.put("operatingsystem", node.getOperatingSystem());
    StringBuilder categories = new StringBuilder();
    for (Iterator<OnmsCategory> i = node.getCategories().iterator(); i.hasNext(); ) {
        categories.append(((OnmsCategory) i.next()).getName());
        if (i.hasNext()) {
            categories.append(",");
        }
    }
    body.put("categories", categories.toString());
    if (archiveAssetData) {
        // parent information
        OnmsNode parent = node.getParent();
        if (parent != null) {
            if (parent.getLabel() != null)
                body.put("parent-nodelabel", parent.getLabel());
            if (parent.getNodeId() != null)
                body.put("parent-nodeid", parent.getNodeId());
            if (parent.getForeignSource() != null)
                body.put("parent-foreignsource", parent.getForeignSource());
            if (parent.getForeignId() != null)
                body.put("parent-foreignid", parent.getForeignId());
        }
        //assetRecord.
        OnmsAssetRecord assetRecord = node.getAssetRecord();
        if (assetRecord != null) {
            //geolocation
            OnmsGeolocation gl = assetRecord.getGeolocation();
            if (gl != null) {
                if (gl.getLatitude() != null)
                    body.put("asset-latitude", gl.getLatitude().toString());
                if (gl.getLongitude() != null)
                    body.put("asset-longitude", gl.getLongitude().toString());
            }
            //assetRecord
            if (assetRecord.getRegion() != null && !"".equals(assetRecord.getRegion()))
                body.put("asset-region", assetRecord.getRegion());
            if (assetRecord.getBuilding() != null && !"".equals(assetRecord.getBuilding()))
                body.put("asset-building", assetRecord.getBuilding());
            if (assetRecord.getFloor() != null && !"".equals(assetRecord.getFloor()))
                body.put("asset-floor", assetRecord.getFloor());
            if (assetRecord.getRoom() != null && !"".equals(assetRecord.getRoom()))
                body.put("asset-room", assetRecord.getRoom());
            if (assetRecord.getRack() != null && !"".equals(assetRecord.getRack()))
                body.put("asset-rack", assetRecord.getRack());
            if (assetRecord.getSlot() != null && !"".equals(assetRecord.getSlot()))
                body.put("asset-slot", assetRecord.getSlot());
            if (assetRecord.getPort() != null && !"".equals(assetRecord.getPort()))
                body.put("asset-port", assetRecord.getPort());
            if (assetRecord.getCategory() != null && !"".equals(assetRecord.getCategory()))
                body.put("asset-category", assetRecord.getCategory());
            if (assetRecord.getDisplayCategory() != null && !"".equals(assetRecord.getDisplayCategory()))
                body.put("asset-displaycategory", assetRecord.getDisplayCategory());
            if (assetRecord.getNotifyCategory() != null && !"".equals(assetRecord.getNotifyCategory()))
                body.put("asset-notifycategory", assetRecord.getNotifyCategory());
            if (assetRecord.getPollerCategory() != null && !"".equals(assetRecord.getPollerCategory()))
                body.put("asset-pollercategory", assetRecord.getPollerCategory());
            if (assetRecord.getThresholdCategory() != null && !"".equals(assetRecord.getThresholdCategory()))
                body.put("asset-thresholdcategory", assetRecord.getThresholdCategory());
            if (assetRecord.getManagedObjectType() != null && !"".equals(assetRecord.getManagedObjectType()))
                body.put("asset-managedobjecttype", assetRecord.getManagedObjectType());
            if (assetRecord.getManagedObjectInstance() != null && !"".equals(assetRecord.getManagedObjectInstance()))
                body.put("asset-managedobjectinstance", assetRecord.getManagedObjectInstance());
            if (assetRecord.getManufacturer() != null && !"".equals(assetRecord.getManufacturer()))
                body.put("asset-manufacturer", assetRecord.getManufacturer());
            if (assetRecord.getVendor() != null && !"".equals(assetRecord.getVendor()))
                body.put("asset-vendor", assetRecord.getVendor());
            if (assetRecord.getModelNumber() != null && !"".equals(assetRecord.getModelNumber()))
                body.put("asset-modelnumber", assetRecord.getModelNumber());
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation)

Example 24 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class AvailabilityDatabasePopulator method getCategory.

private OnmsCategory getCategory(String categoryName) {
    OnmsCategory cat = getCategoryDao().findByName(categoryName);
    if (cat == null) {
        cat = new OnmsCategory(categoryName);
        cat.getAuthorizedGroups().add(categoryName + "Group");
        getCategoryDao().save(cat);
        getCategoryDao().flush();
    }
    return cat;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 25 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)54 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StringReader (java.io.StringReader)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2