Search in sources :

Example 6 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachineTest method canRenderGraphToPng.

@Test
public void canRenderGraphToPng() {
    // Create a simple hierarchy
    MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
    // Setup the state machine
    BusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(h.getBusinessServices());
    // Render the state machine graph
    File pngFile = new File(tempFolder.getRoot(), "test.png");
    assertFalse(pngFile.getAbsolutePath() + " should not exist.", pngFile.exists());
    stateMachine.renderGraphToPng(pngFile);
    assertTrue(pngFile.getAbsolutePath() + " should exist.", pngFile.exists());
}
Also used : BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) File(java.io.File) Test(org.junit.Test)

Example 7 with BusinessServiceStateMachine

use of org.opennms.netmgt.bsm.service.BusinessServiceStateMachine in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachineTest method canReloadTheStateMachineWhilePreservingState.

@Test
public void canReloadTheStateMachineWhilePreservingState() {
    // Create a simple hierarchy
    MockBusinessServiceHierarchy h = MockBusinessServiceHierarchy.builder().withBusinessService(1).withReductionKey(1, "a1").commit().build();
    BusinessService b1 = h.getBusinessServiceById(1);
    // Setup the state machine
    BusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    LoggingStateChangeHandler stateChangeHandler = new LoggingStateChangeHandler();
    stateMachine.addHandler(stateChangeHandler, Maps.newHashMap());
    stateMachine.setBusinessServices(h.getBusinessServices());
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(b1));
    assertEquals(0, stateChangeHandler.getStateChanges().size());
    // Send an alarm and verify the updated state
    stateMachine.handleNewOrUpdatedAlarm(new MockAlarmWrapper("a1", Status.CRITICAL));
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
    assertEquals(1, stateChangeHandler.getStateChanges().size());
    // Now reload the state machine without making any changes to the hierarchies
    stateMachine.setBusinessServices(h.getBusinessServices());
    // The original status should remain
    assertEquals(Status.CRITICAL, stateMachine.getOperationalStatus(b1));
    // No additional state changes events should have been generated
    assertEquals(1, stateChangeHandler.getStateChanges().size());
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) LoggingStateChangeHandler(org.opennms.netmgt.bsm.test.LoggingStateChangeHandler) MockAlarmWrapper(org.opennms.netmgt.bsm.mock.MockAlarmWrapper) Test(org.junit.Test)

Aggregations

BusinessServiceStateMachine (org.opennms.netmgt.bsm.service.BusinessServiceStateMachine)7 Status (org.opennms.netmgt.bsm.service.model.Status)4 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)3 FormLayout (com.vaadin.ui.FormLayout)2 File (java.io.File)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 AbstractBusinessServiceVertex (org.opennms.features.topology.plugins.topo.bsm.AbstractBusinessServiceVertex)2 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)2 AlarmWrapper (org.opennms.netmgt.bsm.service.model.AlarmWrapper)2 GraphVertex (org.opennms.netmgt.bsm.service.model.graph.GraphVertex)2 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Label (com.vaadin.ui.Label)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 Layout (edu.uci.ics.jung.algorithms.layout.Layout)1