use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsIpInterfaceResource method updateIpInterface.
/**
* <p>updateIpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{ipAddress}")
public Response updateIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final MultivaluedMapImpl params) {
writeLock();
try {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
final OnmsIpInterface ipInterface = node.getIpInterfaceByIpAddress(ipAddress);
if (ipInterface == null) {
throw getException(Status.CONFLICT, "Can't find interface with IP address {} for node {}.", ipAddress, nodeCriteria);
}
LOG.debug("updateIpInterface: updating ip interface {}", ipInterface);
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(ipInterface);
boolean modified = false;
for (final String key : params.keySet()) {
// skip nodeId since we already know the node this is associated with and don't want to overwrite it
if ("nodeId".equals(key)) {
continue;
}
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateIpInterface: ip interface {} updated", ipInterface);
m_ipInterfaceDao.saveOrUpdate(ipInterface);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsMonitoredServiceResource method updateService.
/**
* <p>updateService</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @param serviceName a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null)
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
if (intf == null)
throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
if (service == null)
throw getException(Status.BAD_REQUEST, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
LOG.debug("updateService: updating service {}", service);
boolean modified = false;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
for (String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
if (key.equals("status")) {
if ("S".equals(value) || ("A".equals(service.getStatus()) && "F".equals(value))) {
LOG.debug("updateService: suspending polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
value = "F";
sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
}
if ("R".equals(value) || ("F".equals(service.getStatus()) && "A".equals(value))) {
LOG.debug("updateService: resuming polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
value = "A";
sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
}
}
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateSservice: service {} updated", service);
m_serviceDao.saveOrUpdate(service);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsMonitoredServiceResource method getServices.
/**
* <p>getServices</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsMonitoredServiceList} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsMonitoredServiceList getServices(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddress);
if (iface == null) {
throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
}
return new OnmsMonitoredServiceList(iface.getMonitoredServices());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsMonitoredServiceResource method deleteService.
/**
* <p>deleteService</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @param serviceName a {@link java.lang.String} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@DELETE
@Path("{service}")
public Response deleteService(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, @PathParam("service") final String serviceName) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null)
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
if (intf == null)
throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
if (service == null)
throw getException(Status.CONFLICT, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
LOG.debug("deleteService: deleting service {} from node {}", serviceName, nodeCriteria);
Event e = EventUtils.createDeleteServiceEvent("OpenNMS.REST", node.getId(), ipAddress, serviceName, -1L);
sendEvent(e);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class OnmsSnmpInterfaceResource method addSnmpInterface.
/**
* <p>addSnmpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param snmpInterface a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addSnmpInterface(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria, final OnmsSnmpInterface snmpInterface) {
writeLock();
try {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null)
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
if (snmpInterface == null)
throw getException(Status.BAD_REQUEST, "SNMP interface object cannot be null");
LOG.debug("addSnmpInterface: adding interface {}", snmpInterface);
node.addSnmpInterface(snmpInterface);
if (snmpInterface.getPrimaryIpInterface() != null) {
final OnmsIpInterface iface = snmpInterface.getPrimaryIpInterface();
iface.setSnmpInterface(snmpInterface);
// TODO Add important events here
}
m_snmpInterfaceDao.save(snmpInterface);
final Integer ifIndex = snmpInterface.getIfIndex();
return Response.created(getRedirectUri(uriInfo, ifIndex)).build();
} finally {
writeUnlock();
}
}
Aggregations