Search in sources :

Example 6 with Requisition

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

the class FusedForeignSourceRepositoryTest method createSnapshot.

protected URL createSnapshot(final String foreignSource) throws MalformedURLException {
    System.err.println("--- creating snapshot for " + foreignSource + " ---");
    Requisition pending = m_pending.getRequisition(foreignSource);
    Requisition deployed = m_active.getRequisition(foreignSource);
    final Date deployedDate = deployed == null ? null : deployed.getDate();
    final Date pendingDate = pending == null ? null : pending.getDate();
    if (deployedDate == null)
        return RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pending.getDate()).toURI().toURL();
    if (pendingDate == null)
        return m_active.getRequisitionURL(foreignSource);
    final URL url;
    if (deployedDate.before(pendingDate)) {
        url = RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pendingDate).toURI().toURL();
    } else {
        url = m_active.getRequisitionURL(foreignSource);
    }
    System.err.println("deployedDate = " + deployedDate);
    System.err.println("pendingDate  = " + pendingDate);
    System.err.println("url          = " + url);
    return url;
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Date(java.util.Date) URL(java.net.URL)

Example 7 with Requisition

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

the class FusedForeignSourceRepositoryTest method getSummaryForRequisition.

protected String getSummaryForRequisition(final File file) {
    final Requisition requisition = JaxbUtils.unmarshal(Requisition.class, new FileSystemResource(file));
    final StringBuilder sb = new StringBuilder();
    if (requisition.getNodeCount() > 0) {
        sb.append("(");
        final Iterator<RequisitionNode> nodeIterator = requisition.getNodes().iterator();
        while (nodeIterator.hasNext()) {
            sb.append(nodeIterator.next().getNodeLabel());
            if (nodeIterator.hasNext())
                sb.append(", ");
        }
        sb.append(")");
    }
    final String requisitionSummary = file.getPath() + sb.toString() + ": " + requisition.getDate().getTime();
    return requisitionSummary;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 8 with Requisition

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

the class FusedForeignSourceRepositoryTest method multipleSnapshotTest.

@Test
public void multipleSnapshotTest() throws URISyntaxException, InterruptedException {
    Requisition pendingReq = new Requisition("test");
    pendingReq.putNode(createNode("1"));
    m_pending.save(pendingReq);
    m_pending.flush();
    final String foreignSource = pendingReq.getForeignSource();
    pendingReq = m_pending.getRequisition(foreignSource);
    final File pendingSnapshotA = RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pendingReq.getDate());
    // Now, start a new pending update after the original snapshot is "in progress"
    pendingReq.updateDateStamp();
    m_pending.save(pendingReq);
    m_pending.flush();
    final File pendingSnapshotB = RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pendingReq.getDate());
    // "import" the A snapshot
    m_repository.importResourceRequisition(new FileSystemResource(pendingSnapshotA));
    assertFalse(pendingSnapshotA.exists());
    assertTrue(pendingSnapshotB.exists());
    // since there's still a newer snapshot in-progress, it is safe to delete the pending test.xml
    URL pendingUrl = m_pending.getRequisitionURL(foreignSource);
    assertNotNull(pendingUrl);
    assertFalse(new File(pendingUrl.toURI()).exists());
    // then, "import" the B snapshot
    final Requisition bReq = m_repository.importResourceRequisition(new FileSystemResource(pendingSnapshotB));
    assertFalse(pendingSnapshotA.exists());
    assertFalse(pendingSnapshotB.exists());
    // now the pending test.xml should be gone
    pendingUrl = m_pending.getRequisitionURL(foreignSource);
    assertNotNull(pendingUrl);
    assertFalse(new File(pendingUrl.toURI()).exists());
    // the last (B) pending import should match the deployed
    final Requisition deployedRequisition = m_active.getRequisition(foreignSource);
    assertEquals(deployedRequisition.getDate().getTime(), bReq.getDate().getTime());
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) URL(java.net.URL) Test(org.junit.Test)

Example 9 with Requisition

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

the class FusedForeignSourceRepositoryTest method simpleSnapshotTest.

@Test
public void simpleSnapshotTest() throws URISyntaxException {
    Requisition pendingReq = new Requisition("test");
    pendingReq.putNode(createNode("1"));
    m_pending.save(pendingReq);
    m_pending.flush();
    pendingReq = m_pending.getRequisition(pendingReq.getForeignSource());
    final File pendingSnapshot = RequisitionFileUtils.createSnapshot(m_pending, pendingReq.getForeignSource(), pendingReq.getDate());
    m_repository.importResourceRequisition(new FileSystemResource(pendingSnapshot));
    assertFalse(pendingSnapshot.exists());
    final URL pendingUrl = m_pending.getRequisitionURL(pendingReq.getForeignSource());
    final File pendingFile = new File(pendingUrl.toURI());
    assertFalse(pendingFile.exists());
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) URL(java.net.URL) Test(org.junit.Test)

Example 10 with Requisition

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

the class FusedForeignSourceRepositoryTest method integrationTest.

@Test
public void integrationTest() {
    /*
         * First, the user creates a requisition in the UI, or RESTful
         * interface.
         */
    Requisition pendingReq = new Requisition("test");
    pendingReq.putNode(createNode("1"));
    m_pending.save(pendingReq);
    m_pending.flush();
    /* 
         * Then, the user makes a foreign source configuration to go along
         * with that requisition.
         */
    ForeignSource pendingSource = m_repository.getForeignSource("test");
    assertTrue(pendingSource.isDefault());
    pendingSource.setDetectors(new ArrayList<PluginConfig>());
    m_pending.save(pendingSource);
    m_pending.flush();
    /*
         * Now we got an import event, so we import that requisition file,
         * and save it.  The ForeignSource in the pending repository should
         * match the one in the active one, now.
         */
    Requisition activeReq = m_repository.importResourceRequisition(new UrlResource(m_pending.getRequisitionURL("test")));
    ForeignSource activeSource = m_active.getForeignSource("test");
    // and the foreign source should be the same as the one we made earlier, only this time it's active
    assertEquals(activeSource.getName(), pendingSource.getName());
    assertEquals(activeSource.getDetectorNames(), pendingSource.getDetectorNames());
    assertEquals(activeSource.getScanInterval(), pendingSource.getScanInterval());
    assertRequisitionsMatch("active and pending requisitions should match", activeReq, pendingReq);
    /*
         * Since it's been officially deployed, the requisition and foreign
         * source should no longer be in the pending repo.
         */
    assertNull("the requisition should be null in the pending repo", m_pending.getRequisition("test"));
    assertTrue("the foreign source should be default since there's no specific in the pending repo", m_pending.getForeignSource("test").isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) UrlResource(org.springframework.core.io.UrlResource) 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