Search in sources :

Example 51 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FilesystemForeignSourceRepositoryTest method createRequisition.

private Requisition createRequisition() throws Exception {
    Requisition r = m_foreignSourceRepository.importResourceRequisition(new ClassPathResource("/requisition-test.xml"));
    m_foreignSourceRepository.save(r);
    m_foreignSourceRepository.flush();
    return r;
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 52 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FusedForeignSourceRepositoryTest method doImport.

protected void doImport(final Resource resource) {
    final Requisition req = m_repository.importResourceRequisition(resource);
    req.updateLastImported();
    m_repository.save(req);
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 53 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FusedForeignSourceRepositoryTest method testSpc674RaceCondition.

@Test
public void testSpc674RaceCondition() throws Exception {
    final String foreignSource = "spc674";
    System.err.println("=== create a requisition like the ReST service does, import it immediately ===");
    final Requisition initial = new Requisition(foreignSource);
    initial.putNode(createNode("1"));
    initial.updateDateStamp();
    m_pending.save(initial);
    final URL node1Snapshot = createSnapshot(foreignSource);
    Resource resource = new UrlResource(node1Snapshot);
    doImport(resource);
    Thread.sleep(5);
    List<String> files = getImports(foreignSource);
    assertEquals(1, files.size());
    System.err.println("=== create another snapshot, but don't import it yet ===");
    initial.putNode(createNode("2"));
    initial.updateDateStamp();
    m_pending.save(initial);
    final URL node2Snapshot = createSnapshot(foreignSource);
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(3, files.size());
    System.err.println("=== create yet another snapshot, and don't import it yet ===");
    initial.putNode(createNode("3"));
    initial.updateDateStamp();
    m_pending.save(initial);
    final URL node3Snapshot = createSnapshot(foreignSource);
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(4, files.size());
    System.err.println("=== import of the second file finishes ===");
    doImport(new UrlResource(node2Snapshot));
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(2, files.size());
    System.err.println("=== fourth node is sent to the ReST interface ===");
    final Requisition currentPending = RequisitionFileUtils.getLatestPendingOrSnapshotRequisition(m_pending, foreignSource);
    assertNotNull(currentPending);
    assertEquals(initial.getDate(), currentPending.getDate());
    currentPending.putNode(createNode("4"));
    currentPending.updateDateStamp();
    m_pending.save(currentPending);
    final URL node4Snapshot = createSnapshot(foreignSource);
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(4, files.size());
    System.err.println("=== import of the third file finishes ===");
    doImport(new UrlResource(node3Snapshot));
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(2, files.size());
    System.err.println("=== import of the fourth file finishes ===");
    doImport(new UrlResource(node4Snapshot));
    Thread.sleep(5);
    files = getImports(foreignSource);
    assertEquals(1, files.size());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) URL(java.net.URL) Test(org.junit.Test)

Example 54 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FusedForeignSourceRepositoryTest method tearDown.

@After
public final void tearDown() {
    /* 
         * since we share the filesystem with other tests, best
         * to make sure it's totally clean here.
         */
    for (ForeignSource fs : m_pending.getForeignSources()) {
        m_pending.delete(fs);
    }
    for (ForeignSource fs : m_active.getForeignSources()) {
        m_active.delete(fs);
    }
    for (Requisition r : m_pending.getRequisitions()) {
        m_pending.delete(r);
    }
    for (Requisition r : m_active.getRequisitions()) {
        m_active.delete(r);
    }
    m_pending.flush();
    m_active.flush();
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) After(org.junit.After)

Example 55 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class QueueingForeignSourceRepositoryTest method testGetRequisition.

@Test
public void testGetRequisition() throws Exception {
    Requisition requisition = createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    assertRequisitionsMatch("requisitions must match", m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName), m_foreignSourceRepository.getRequisition(foreignSource));
    assertRequisitionsMatch("foreign source is the expected one", requisition, m_foreignSourceRepository.getRequisition(foreignSource));
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)70 Test (org.junit.Test)31 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)16 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)11 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)11 UrlResource (org.springframework.core.io.UrlResource)10 File (java.io.File)9 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)8 Resource (org.springframework.core.io.Resource)8 IOException (java.io.IOException)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 InetAddress (java.net.InetAddress)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3