Search in sources :

Example 1 with Increase

use of org.opennms.netmgt.bsm.service.model.functions.map.Increase in project opennms by OpenNMS.

the class BusinessServiceRequestDTOMarshalTest method data.

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    final SetTo setTo = new SetTo();
    setTo.setStatus(Status.CRITICAL);
    final MapFunctionDTO increaseDto = createMapFunctionDTO(new Increase());
    final MapFunctionDTO setToDto = createMapFunctionDTO(setTo);
    final BusinessServiceRequestDTO requestDTO = new BusinessServiceRequestDTO();
    requestDTO.setReduceFunction(createReduceFunctionDTO(new HighestSeverity()));
    requestDTO.setName("Web Servers");
    requestDTO.addAttribute("dc", "RDU");
    requestDTO.addAttribute("some-key", "some-value");
    requestDTO.addChildService(2L, increaseDto, 5);
    requestDTO.addChildService(3L, setToDto, 5);
    requestDTO.addReductionKey("myReductionKeyA", increaseDto, 7, "reduction-key-a-friendly-name");
    requestDTO.addReductionKey("myReductionKeyB", increaseDto, 7, "reduction-key-b-friendly-name");
    requestDTO.addIpService(1, increaseDto, 9, "ip-service-friendly-name");
    return Arrays.asList(new Object[][] { { BusinessServiceRequestDTO.class, requestDTO, "{" + "  \"name\" : \"Web Servers\"," + "  \"attributes\" : {" + "    \"attribute\" : [ {" + "      \"key\" : \"dc\"," + "      \"value\" : \"RDU\"" + "    }, {" + "      \"key\" : \"some-key\"," + "      \"value\" : \"some-value\"" + "    } ]" + "  }," + "  \"reduce-function\" : {" + "       \"type\" : \"HighestSeverity\"," + "       \"properties\" : { }" + "  }," + "  \"child-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 5," + "           \"child-id\" : 2" + "       }," + "       {" + "           \"map-function\" : {" + "               \"type\" : \"SetTo\"," + "               \"properties\" : {" + "                   \"status\" : \"Critical\"" + "               }" + "           }," + "           \"weight\" : 5," + "           \"child-id\" : 3" + "       }," + "   ]," + "  \"ip-service-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 9," + "           \"ip-service-id\" : 1," + "           \"friendly-name\" : \"ip-service-friendly-name\"" + "       }," + "   ]," + "  \"reduction-key-edges\" : [" + "       {" + "           \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 7," + "           \"reduction-key\" : \"myReductionKeyA\"," + "           \"friendly-name\" : \"reduction-key-a-friendly-name\"" + "       }," + "       {" + "            \"map-function\" : {" + "               \"type\" : \"Increase\"," + "               \"properties\" : { }" + "           }," + "           \"weight\" : 7," + "           \"reduction-key\" : \"myReductionKeyB\"," + "           \"friendly-name\" : \"reduction-key-b-friendly-name\"" + "       }," + "   ]," + "}", "<business-service>\n" + "   <name>Web Servers</name>\n" + "   <attributes>\n" + "      <attribute>\n" + "         <key>dc</key>\n" + "         <value>RDU</value>\n" + "      </attribute>\n" + "      <attribute>\n" + "         <key>some-key</key>\n" + "         <value>some-value</value>\n" + "      </attribute>\n" + "   </attributes>\n" + "    <ip-service-edges>\n" + "      <ip-service-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>9</weight>\n" + "         <friendly-name>ip-service-friendly-name</friendly-name>\n" + "         <ip-service-id>1</ip-service-id>\n" + "      </ip-service-edge>\n" + "   </ip-service-edges>\n" + "   <child-edges>\n" + "      <child-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>5</weight>\n" + "         <child-id>2</child-id>\n" + "      </child-edge>\n" + "      <child-edge>\n" + "         <map-function>\n" + "            <type>SetTo</type>\n" + "            <properties>\n" + "               <entry>\n" + "                  <key>status</key>\n" + "                  <value>Critical</value>\n" + "               </entry>\n" + "            </properties>\n" + "         </map-function>\n" + "         <weight>5</weight>\n" + "         <child-id>3</child-id>\n" + "      </child-edge>\n" + "   </child-edges>\n" + "   <reduction-key-edges>\n" + "      <reduction-key-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>7</weight>\n" + "         <friendly-name>reduction-key-a-friendly-name</friendly-name>\n" + "         <reduction-key>myReductionKeyA</reduction-key>\n" + "      </reduction-key-edge>\n" + "      <reduction-key-edge>\n" + "         <map-function>\n" + "            <type>Increase</type>\n" + "         </map-function>\n" + "         <weight>7</weight>\n" + "         <friendly-name>reduction-key-b-friendly-name</friendly-name>\n" + "         <reduction-key>myReductionKeyB</reduction-key>\n" + "      </reduction-key-edge>\n" + "   </reduction-key-edges>\n" + "   <reduce-function>\n" + "      <type>HighestSeverity</type>\n" + "   </reduce-function>\n" + "</business-service>" } });
}
Also used : TestHelper.createMapFunctionDTO(org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) SetTo(org.opennms.netmgt.bsm.service.model.functions.map.SetTo)

Example 2 with Increase

use of org.opennms.netmgt.bsm.service.model.functions.map.Increase in project opennms by OpenNMS.

the class BusinessServiceEdgeEditWindow method getMapFunction.

@SuppressWarnings("unchecked")
private MapFunction getMapFunction() {
    try {
        final MapFunction mapFunction = ((Class<? extends MapFunction>) m_mapFunctionSelect.getValue()).newInstance();
        mapFunction.accept(new MapFunctionVisitor<Void>() {

            @Override
            public Void visit(Decrease decrease) {
                return null;
            }

            @Override
            public Void visit(Identity identity) {
                return null;
            }

            @Override
            public Void visit(Ignore ignore) {
                return null;
            }

            @Override
            public Void visit(Increase increase) {
                return null;
            }

            @Override
            public Void visit(SetTo setTo) {
                setTo.setStatus((Status) m_mapFunctionSeveritySelect.getValue());
                return null;
            }
        });
        return mapFunction;
    } catch (final InstantiationException | IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) Decrease(org.opennms.netmgt.bsm.service.model.functions.map.Decrease) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) SetTo(org.opennms.netmgt.bsm.service.model.functions.map.SetTo)

Example 3 with Increase

use of org.opennms.netmgt.bsm.service.model.functions.map.Increase in project opennms by OpenNMS.

the class MapFunctionTest method verifyIncrease.

@Test
public void verifyIncrease() {
    Increase increase = new Increase();
    Assert.assertEquals(Status.WARNING, increase.map(Status.NORMAL).get());
    Assert.assertEquals(Status.MINOR, increase.map(Status.WARNING).get());
    Assert.assertEquals(Status.MAJOR, increase.map(Status.MINOR).get());
    Assert.assertEquals(Status.CRITICAL, increase.map(Status.MAJOR).get());
    Assert.assertEquals(Status.CRITICAL, increase.map(Status.CRITICAL).get());
}
Also used : Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) Test(org.junit.Test)

Example 4 with Increase

use of org.opennms.netmgt.bsm.service.model.functions.map.Increase in project opennms by OpenNMS.

the class BusinessServiceManagerImplIT method ensureNoDanglingMapFunctions.

@Test
public void ensureNoDanglingMapFunctions() {
    // Create a business service with an edge
    final BusinessService bs = this.createBusinessService("bs1");
    bs.addReductionKeyEdge("my-reduction-key", new Increase(), Edge.DEFAULT_WEIGHT, "My Reduction Key");
    bs.save();
    // Ensure there is an associated mapping function
    assertEquals(1, mapFunctionDao.countAll());
    Iterables.getOnlyElement(bs.getReductionKeyEdges()).setMapFunction(new Decrease());
    bs.save();
    // Ensure there is still only one associated mapping function
    assertEquals(1, mapFunctionDao.countAll());
    // Delete an edge
    bs.delete();
    // Ensure there are no mapping functions left
    assertEquals(0, mapFunctionDao.countAll());
}
Also used : BsmTestUtils.createDummyBusinessService(org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Decrease(org.opennms.netmgt.bsm.service.model.functions.map.Decrease) Increase(org.opennms.netmgt.bsm.service.model.functions.map.Increase) Test(org.junit.Test)

Aggregations

Increase (org.opennms.netmgt.bsm.service.model.functions.map.Increase)4 Test (org.junit.Test)2 Decrease (org.opennms.netmgt.bsm.service.model.functions.map.Decrease)2 SetTo (org.opennms.netmgt.bsm.service.model.functions.map.SetTo)2 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)1 Status (org.opennms.netmgt.bsm.service.model.Status)1 Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)1 Ignore (org.opennms.netmgt.bsm.service.model.functions.map.Ignore)1 MapFunction (org.opennms.netmgt.bsm.service.model.functions.map.MapFunction)1 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)1 BsmTestUtils.createDummyBusinessService (org.opennms.netmgt.bsm.test.BsmTestUtils.createDummyBusinessService)1 TestHelper.createMapFunctionDTO (org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO)1