use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class GraphRestService method getGraphResourcesForNode.
@GET
@Path("fornode/{nodeCriteria}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphResourceDTO getGraphResourcesForNode(@PathParam("nodeCriteria") final String nodeCriteria, @DefaultValue("-1") @QueryParam("depth") final int depth) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria);
}
OnmsResource resource = m_resourceDao.getResourceForNode(node);
if (resource == null) {
throw getException(Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId());
}
final ResourceVisitor visitor = new ResourceVisitor(this);
final ResourceDTO resourceDTO = ResourceDTO.fromResource(resource, depth);
visitor.visit(resourceDTO);
return new GraphResourceDTO(resourceDTO, visitor.getGraphs());
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class GraphRestService method getGraphNames.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphNameCollection getGraphNames() {
List<String> graphNames = Lists.newLinkedList();
for (PrefabGraph prefabGraph : m_graphDao.getAllPrefabGraphs()) {
graphNames.add(prefabGraph.getName());
}
Collections.sort(graphNames);
return new GraphNameCollection(graphNames);
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class MonitoringLocationsRestService method updateMonitoringLocation.
@PUT
@Path("{monitoringLocation}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateMonitoringLocation(@PathParam("monitoringLocation") String monitoringLocation, MultivaluedMapImpl params) {
writeLock();
try {
OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocation);
LOG.debug("updateMonitoringLocation: updating monitoring location {}", monitoringLocation);
if (params.isEmpty())
return Response.notModified().build();
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(def);
wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
Object value = null;
String stringValue = params.getFirst(key);
value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateMonitoringLocation: monitoring location {} updated", monitoringLocation);
m_monitoringLocationDao.save(def);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private NodeLinkBridge convertFromModel(String mac, SharedSegment segment, String port) {
final NodeLinkBridge linknode = new NodeLinkBridge();
linknode.setNodeLocalPort(port);
for (BridgePort link : segment.getBridgePortsOnSegment()) {
final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
final Integer rempnodeId = link.getNode().getId();
final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
if (remiface != null) {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
}
remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
remlinknode.setBridgeRemoteVlan(link.getVlan());
linknode.getBridgeLinkRemoteNodes().add(remlinknode);
}
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
if (link.getMacAddress().equals(mac)) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
break;
}
}
Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
for (String shredmac : segment.getMacsOnSegment()) {
if (shredmac.equals(mac))
continue;
sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
}
Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
for (String shredmac : sharedmacs.keySet()) {
if (sharedmacs.get(shredmac).isEmpty()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
if (snmp == null) {
remlinknode.setSharedHost(shredmac + " No ip address found");
} else {
remlinknode.setSharedHost(snmp.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
}
for (String shredmac : sharedhosts.keySet()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
Set<InetAddress> ips = new HashSet<InetAddress>();
if (sharedhosts.get(shredmac).isEmpty()) {
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
ips.add(ipnettomedia.getNetAddress());
}
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
OnmsIpInterface first = null;
boolean multiplenodeids = false;
for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
if (first == null)
first = ip;
if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
multiplenodeids = true;
ips.add(ip.getIpAddress());
}
if (multiplenodeids) {
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
} else {
remlinknode.setSharedHost(first.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
}
remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
if (ips.size() == 1) {
remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
}
return linknode;
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private BridgeLinkNode convertFromModel(int nodeid, SharedSegment segment) {
final BridgeLinkNode linknode = new BridgeLinkNode();
for (BridgePort link : segment.getBridgePortsOnSegment()) {
final Integer rempnodeId = link.getNode().getId();
final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
if (link.getNode().getId().intValue() == nodeid) {
if (remiface != null) {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, null, null));
}
linknode.setBridgeLocalVlan(link.getVlan());
continue;
}
final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
if (remiface != null) {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
}
remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
remlinknode.setBridgeRemoteVlan(link.getVlan());
linknode.getBridgeLinkRemoteNodes().add(remlinknode);
}
if (segment.getBridgeBridgeLinks().isEmpty()) {
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
if (link.getNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
break;
}
}
} else {
for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
if (link.getNode().getId().intValue() == nodeid || link.getDesignatedNode().getId().intValue() == nodeid) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeBridgeLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeBridgeLinkLastPollTime()));
break;
}
}
}
Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
for (String shredmac : segment.getMacsOnSegment()) {
sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
}
Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
for (String shredmac : sharedmacs.keySet()) {
if (sharedmacs.get(shredmac).isEmpty()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
if (snmp == null) {
remlinknode.setSharedHost(shredmac + " No ip address found");
} else {
remlinknode.setSharedHost(snmp.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
}
for (String shredmac : sharedhosts.keySet()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
Set<InetAddress> ips = new HashSet<InetAddress>();
if (sharedhosts.get(shredmac).isEmpty()) {
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
ips.add(ipnettomedia.getNetAddress());
}
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
OnmsIpInterface first = null;
boolean multiplenodeids = false;
for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
if (first == null)
first = ip;
if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
multiplenodeids = true;
ips.add(ip.getIpAddress());
}
if (multiplenodeids) {
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
} else {
remlinknode.setSharedHost(first.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
}
remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
if (ips.size() == 1) {
remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
}
return linknode;
}
Aggregations