Search in sources :

Example 1 with ForeignSourceCollection

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection in project opennms by OpenNMS.

the class PersistenceSerializationTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    fa = new FileAnticipator();
    fsr = new MockForeignSourceRepository();
    fsr.save(new ForeignSource("cheese"));
    fsr.flush();
    fs = fsr.getForeignSource("cheese");
    //        fs.setScanInterval(scanInterval)
    XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar("2009-02-25T12:45:38.800-05:00");
    fs.setDateStamp(cal);
    List<PluginConfig> detectors = new ArrayList<PluginConfig>();
    final PluginConfig detector = new PluginConfig("food", "org.opennms.netmgt.provision.persist.detectors.FoodDetector");
    detector.addParameter("type", "cheese");
    detector.addParameter("density", "soft");
    detector.addParameter("sharpness", "mild");
    detectors.add(detector);
    fs.setDetectors(detectors);
    List<PluginConfig> policies = new ArrayList<PluginConfig>();
    PluginConfig policy = new PluginConfig("lower-case-node", "org.opennms.netmgt.provision.persist.policies.NodeCategoryPolicy");
    policy.addParameter("label", "~^[a-z]$");
    policy.addParameter("category", "Lower-Case-Nodes");
    policies.add(policy);
    policy = new PluginConfig("all-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.InclusiveInterfacePolicy");
    policies.add(policy);
    policy = new PluginConfig("10-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.MatchingInterfacePolicy");
    policy.addParameter("ipaddress", "~^10\\..*$");
    policies.add(policy);
    policy = new PluginConfig("cisco-snmp-interfaces", "org.opennms.netmgt.provision.persist.policies.MatchingSnmpInterfacePolicy");
    policy.addParameter("ifdescr", "~^(?i:LEC).*$");
    policies.add(policy);
    fs.setPolicies(policies);
    fsw = new ForeignSourceCollection();
    fsw.getForeignSources().addAll(fsr.getForeignSources());
    c = JAXBContext.newInstance(ForeignSourceCollection.class, ForeignSource.class);
    m = c.createMarshaller();
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setNormalize(true);
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 2 with ForeignSourceCollection

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection in project opennms by OpenNMS.

the class ForeignSourceRestService method getDeployedForeignSources.

/**
     * Returns all the deployed foreign sources
     *
     * @return Collection of OnmsForeignSources (ready to be XML-ified)
     */
@GET
@Path("deployed")
public ForeignSourceCollection getDeployedForeignSources() {
    readLock();
    try {
        m_deployedForeignSourceRepository.flush();
        ForeignSourceCollection retval = new ForeignSourceCollection();
        retval.getForeignSources().addAll(m_deployedForeignSourceRepository.getForeignSources());
        return retval;
    } finally {
        readUnlock();
    }
}
Also used : ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with ForeignSourceCollection

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection in project opennms by OpenNMS.

the class ForeignSourceRestService method getForeignSources.

/**
     * Returns the union of deployed and pending foreign sources
     *
     * @return Collection of OnmsForeignSources (ready to be XML-ified)
     * @throws java.text.ParseException if any.
     */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public ForeignSourceCollection getForeignSources() {
    readLock();
    try {
        final Set<ForeignSource> foreignSources = new TreeSet<ForeignSource>();
        for (final String fsName : getActiveForeignSourceNames()) {
            foreignSources.add(getActiveForeignSource(fsName));
        }
        ForeignSourceCollection retval = new ForeignSourceCollection();
        retval.getForeignSources().addAll(foreignSources);
        return retval;
    } finally {
        readUnlock();
    }
}
Also used : ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) TreeSet(java.util.TreeSet) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ForeignSourceCollection

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection in project opennms by OpenNMS.

the class ForeignSourceRestServiceIT method createForeignSource.

private void createForeignSource() throws Exception {
    // Be sure there are no foreign-sources defined
    System.err.println("[createForeignSource] : deleting existing foreign source definitions");
    ForeignSourceCollection collection = JaxbUtils.unmarshal(ForeignSourceCollection.class, sendRequest(GET, "/foreignSources", 200));
    collection.getForeignSources().forEach(f -> {
        try {
            System.err.printf("[createForeignSource] : deleting %s\n", f.getName());
            sendRequest(DELETE, "/foreignSources/" + f.getName(), 202);
            sendRequest(DELETE, "/requisitions/" + f.getName(), 202);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    });
    // Create sample foreign source
    System.err.println("[createForeignSource] : creating sample foreign source");
    String fs = "<foreign-source xmlns=\"http://xmlns.opennms.org/xsd/config/foreign-source\" name=\"test\">" + "<scan-interval>1d</scan-interval>" + "<detectors>" + "<detector class=\"org.opennms.netmgt.provision.detector.datagram.DnsDetector\" name=\"DNS\"/>" + "<detector class=\"org.opennms.netmgt.provision.detector.simple.HttpDetector\" name=\"HTTP\"/>" + "<detector class=\"org.opennms.netmgt.provision.detector.simple.HttpsDetector\" name=\"HTTPS\"/>" + "<detector class=\"org.opennms.netmgt.provision.detector.icmp.IcmpDetector\" name=\"ICMP\"/>" + "</detectors>" + "<policies>" + "<policy name=\"lower-case-node\" class=\"org.opennms.netmgt.provision.persist.policies.NodeCategoryPolicy\">" + "<parameter key=\"label\" value=\"~^[a-z]$\" />" + "<parameter key=\"category\" value=\"Lower-Case-Nodes\" />" + "</policy>" + "<policy name=\"all-ipinterfaces\" class=\"org.opennms.netmgt.provision.persist.policies.InclusiveInterfacePolicy\" />" + "</policies>" + "</foreign-source>";
    MockHttpServletResponse response = sendPost("/foreignSources", fs, 202, "/foreignSources/test");
    System.err.println("response = " + stringifyResponse(response));
}
Also used : ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

ForeignSourceCollection (org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection)4 GET (javax.ws.rs.GET)2 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Before (org.junit.Before)1 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)1 FileAnticipator (org.opennms.test.FileAnticipator)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1