Search in sources :

Example 26 with Transactional

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) StringIntervalPropertyEditor(org.opennms.netmgt.provision.persist.StringIntervalPropertyEditor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with Transactional

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;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with Transactional

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;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private IsisLinkNode convertFromModel(int nodeid, IsIsLink link) {
    IsisLinkNode linknode = new IsisLinkNode();
    linknode.setIsisCircIfIndex(link.getIsisCircIfIndex());
    linknode.setIsisCircAdminState(IsisAdminState.getTypeString(link.getIsisCircAdminState().getValue()));
    IsIsElement isiselement = m_isisElementDao.findByIsIsSysId(link.getIsisISAdjNeighSysID());
    if (isiselement != null) {
        linknode.setIsisISAdjNeighSysID(getAdjSysIDString(link.getIsisISAdjNeighSysID(), isiselement.getNode().getLabel()));
        linknode.setIsisISAdjUrl(getNodeUrl(isiselement.getNode().getId()));
    } else {
        linknode.setIsisISAdjNeighSysID(link.getIsisISAdjNeighSysID());
    }
    linknode.setIsisISAdjNeighSysType(IsisISAdjNeighSysType.getTypeString(link.getIsisISAdjNeighSysType().getValue()));
    linknode.setIsisISAdjNeighSNPAAddress(link.getIsisISAdjNeighSNPAAddress());
    linknode.setIsisISAdjState(IsisISAdjState.get(link.getIsisISAdjState().getValue()).toString());
    linknode.setIsisISAdjNbrExtendedCircID(link.getIsisISAdjNbrExtendedCircID());
    OnmsSnmpInterface remiface = null;
    if (isiselement != null) {
        IsIsLink adjLink = m_isisLinkDao.get(isiselement.getNode().getId(), link.getIsisISAdjIndex(), link.getIsisCircIndex());
        if (adjLink != null) {
            remiface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(isiselement.getNode().getId(), adjLink.getIsisCircIfIndex());
        }
    }
    if (remiface == null) {
        remiface = getFromPhysAddress(link.getIsisISAdjNeighSNPAAddress());
    }
    if (remiface != null) {
        linknode.setIsisISAdjNeighPort(getPortString(remiface.getIfIndex(), remiface.getIfName(), remiface.getIfAlias()));
        linknode.setIsisISAdjUrl(getSnmpInterfaceUrl(remiface.getNode().getId(), remiface.getIfIndex()));
    } else {
        linknode.setIsisISAdjNeighPort("(Isis IS Adj Index: " + link.getIsisISAdjIndex() + ")");
    }
    linknode.setIsisLinkCreateTime(Util.formatDateToUIString(link.getIsisLinkCreateTime()));
    linknode.setIsisLinkLastPollTime(Util.formatDateToUIString(link.getIsisLinkLastPollTime()));
    return linknode;
}
Also used : IsIsLink(org.opennms.netmgt.model.IsIsLink) IsIsElement(org.opennms.netmgt.model.IsIsElement) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private LldpLinkNode convertFromModel(int nodeid, LldpLink link) {
    LldpLinkNode linknode = new LldpLinkNode();
    linknode.setLldpPortString(getPortString(link.getLldpPortId(), link.getLldpPortIdSubType()));
    linknode.setLldpPortDescr(link.getLldpPortDescr());
    linknode.setLldpPortUrl(getSnmpInterfaceUrl(Integer.valueOf(nodeid), link.getLldpPortIfindex()));
    linknode.setLldpRemSysName(link.getLldpRemSysname());
    linknode.setLldpRemPortString(getPortString(link.getLldpRemPortId(), link.getLldpRemPortIdSubType()));
    linknode.setLldpRemPortDescr(link.getLldpRemPortDescr());
    linknode.setLldpCreateTime(Util.formatDateToUIString(link.getLldpLinkCreateTime()));
    linknode.setLldpLastPollTime(Util.formatDateToUIString(link.getLldpLinkLastPollTime()));
    OnmsNode remNode = null;
    List<LldpElement> lldpremelements = m_lldpElementDao.findByChassisId(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType());
    if (lldpremelements.size() == 1) {
        remNode = lldpremelements.get(0).getNode();
    } else if (lldpremelements.size() > 1) {
        linknode.setLldpRemChassisIdString(getChassisIdString("Found " + lldpremelements.size() + " nodes for", link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        return linknode;
    } else {
        final Criteria criteria = new Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", link.getLldpRemSysname()));
        List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
        if (nodes.size() == 1)
            remNode = nodes.get(0);
    }
    if (remNode != null) {
        linknode.setLldpRemChassisIdString(getChassisIdString(remNode.getLabel(), link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        linknode.setLldpRemChassisIdUrl(getNodeUrl(remNode.getId()));
        if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
            try {
                Integer remIfIndex = Integer.getInteger(link.getLldpRemPortId());
                linknode.setLldpRemPortUrl(getSnmpInterfaceUrl(Integer.valueOf(remNode.getId()), remIfIndex));
            } catch (Exception e) {
            }
        }
    } else {
        linknode.setLldpRemChassisIdString(getChassisIdString(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
    }
    return linknode;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) List(java.util.List) ArrayList(java.util.ArrayList) LldpElement(org.opennms.netmgt.model.LldpElement) Criteria(org.opennms.core.criteria.Criteria) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)4561 Test (org.junit.Test)1387 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)724 DAOException (com.tomasio.projects.trainning.exception.DAOException)385 CoreException (com.tomasio.projects.trainning.exeption.CoreException)372 ArrayList (java.util.ArrayList)324 Date (java.util.Date)252 Query (javax.persistence.Query)218 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)213 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)211 WithMockUser (org.springframework.security.test.context.support.WithMockUser)204 HashMap (java.util.HashMap)187 List (java.util.List)163 User (io.github.jhipster.sample.domain.User)150 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)135 HashSet (java.util.HashSet)135 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)132 UUID (java.util.UUID)131 Rollback (org.springframework.test.annotation.Rollback)109 ParseException (java.text.ParseException)108