Search in sources :

Example 6 with IPServiceEdgeEntity

use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.

the class BsmTestUtils method toRequestDto.

public static BusinessServiceRequestDTO toRequestDto(BusinessServiceEntity input) {
    Objects.requireNonNull(input);
    BusinessServiceRequestDTO request = new BusinessServiceRequestDTO();
    request.setName(input.getName());
    request.setAttributes(new HashMap<>(input.getAttributes()));
    request.setReduceFunction(transform(input.getReductionFunction()));
    input.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeEntityVisitor<Void>() {

        @Override
        public Void visit(BusinessServiceChildEdgeEntity edgeEntity) {
            request.addChildService(edgeEntity.getChild().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight());
            return null;
        }

        @Override
        public Void visit(SingleReductionKeyEdgeEntity edgeEntity) {
            request.addReductionKey(edgeEntity.getReductionKey(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
            return null;
        }

        @Override
        public Void visit(IPServiceEdgeEntity edgeEntity) {
            request.addIpService(edgeEntity.getIpService().getId(), transform(edgeEntity.getMapFunction()), edgeEntity.getWeight(), edgeEntity.getFriendlyName());
            return null;
        }
    }));
    return request;
}
Also used : SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)

Example 7 with IPServiceEdgeEntity

use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.

the class FriendlyNameValidationTest method friendlyNameZero.

@Test
public void friendlyNameZero() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_EMPTY);
    edge.setMapFunction(identityEntity);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(0, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 8 with IPServiceEdgeEntity

use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method createEdge.

@SuppressWarnings("unchecked")
private <T extends Edge> T createEdge(Class<T> type, BusinessService source, MapFunction mapFunction, int weight) {
    T edge = null;
    if (type == IpServiceEdge.class) {
        edge = (T) new IpServiceEdgeImpl(this, new IPServiceEdgeEntity());
    }
    if (type == ChildEdge.class) {
        edge = (T) new ChildEdgeImpl(this, new BusinessServiceChildEdgeEntity());
    }
    if (type == ReductionKeyEdge.class) {
        edge = (T) new ReductionKeyEdgeImpl(this, new SingleReductionKeyEdgeEntity());
    }
    if (edge != null) {
        edge.setSource(source);
        edge.setMapFunction(mapFunction);
        edge.setWeight(weight);
        return edge;
    }
    throw new IllegalArgumentException("Could not create edge for type " + type);
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) ChildEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)

Example 9 with IPServiceEdgeEntity

use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.

the class BusinessServiceManagerImpl method addIpServiceEdge.

@Override
public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) {
    final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
    // Create the edge
    final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight);
    edge.setIpService(ipService);
    edge.setFriendlyName(friendlyName);
    // if already exists, no update
    final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
    long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
    if (count > 0) {
        return false;
    }
    parentEntity.addEdge(((IpServiceEdgeImpl) edge).getEntity());
    return true;
}
Also used : ReductionKeyEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl) IpService(org.opennms.netmgt.bsm.service.model.IpService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) ReductionFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.reduce.ReductionFunctionDao) ChildEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl) BusinessServiceDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReductionFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.AbstractReductionFunctionEntity) EventConstants(org.opennms.netmgt.events.api.EventConstants) MapFunction(org.opennms.netmgt.bsm.service.model.functions.map.MapFunction) BusinessServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) IpServiceEdgeImpl(org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl) BusinessServiceSearchCriteria(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteria) AbstractEdge(org.opennms.netmgt.bsm.service.internal.edge.AbstractEdge) ReductionFunction(org.opennms.netmgt.bsm.service.model.functions.reduce.ReductionFunction) Status(org.opennms.netmgt.bsm.service.model.Status) BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) EdgeEntityVisitor(org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor) NoSuchElementException(java.util.NoSuchElementException) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeDao(org.opennms.netmgt.dao.api.NodeDao) AbstractMapFunctionEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.AbstractMapFunctionEntity) BusinessServiceEdgeDao(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeDao) Set(java.util.Set) BusinessServiceGraphImpl(org.opennms.netmgt.bsm.service.model.graph.internal.BusinessServiceGraphImpl) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SingleReductionKeyEdgeEntity(org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity) Collectors(java.util.stream.Collectors) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceStateMachine(org.opennms.netmgt.bsm.service.BusinessServiceStateMachine) Objects(java.util.Objects) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) List(java.util.List) Node(org.opennms.netmgt.bsm.service.model.Node) Edge(org.opennms.netmgt.bsm.service.model.edge.Edge) MapFunctionDao(org.opennms.netmgt.bsm.persistence.api.functions.map.MapFunctionDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)

Example 10 with IPServiceEdgeEntity

use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.

the class DefaultBusinessServiceStateMachineIT method canGetOperationalStatusForIpServices.

@Test
public void canGetOperationalStatusForIpServices() {
    // Setup the the test hierarchy
    SimpleTestHierarchy simpleTestHierarchy = new SimpleTestHierarchy(populator);
    simpleTestHierarchy.getServices().forEach(entity -> businessServiceDao.save(entity));
    final BusinessServiceEntity root = simpleTestHierarchy.getRoot();
    final IPServiceEdgeEntity serviceChild1 = simpleTestHierarchy.getServiceChild1();
    final IPServiceEdgeEntity serviceChild2 = simpleTestHierarchy.getServiceChild2();
    // Setup the State Machine
    DefaultBusinessServiceStateMachine stateMachine = new DefaultBusinessServiceStateMachine();
    stateMachine.setBusinessServices(simpleTestHierarchy.getServices().stream().map(s -> wrap(s)).collect(Collectors.toList()));
    // Verify the initial state
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(root)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(simpleTestHierarchy.getChild1())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(simpleTestHierarchy.getChild2())));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    // Node lost service alarm
    String nodeLostServiceReductionKey = ReductionKeyHelper.getNodeLostServiceReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.NODE_LOST_SERVICE_EVENT_UEI, OnmsSeverity.WARNING, nodeLostServiceReductionKey));
    // Verify state
    assertEquals(Status.WARNING, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    // Interface down alarm
    String interfaceDownReductionKey = ReductionKeyHelper.getInterfaceDownReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.INTERFACE_DOWN_EVENT_UEI, OnmsSeverity.MINOR, interfaceDownReductionKey));
    // Verify state
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    assertEquals(Status.MINOR, stateMachine.getOperationalStatus(wrap(root)));
    // Node down alarm
    String nodeDownReductionKey = ReductionKeyHelper.getNodeDownReductionKey(serviceChild1.getIpService());
    stateMachine.handleNewOrUpdatedAlarm(createAlarmWrapper(EventConstants.NODE_DOWN_EVENT_UEI, OnmsSeverity.MAJOR, nodeDownReductionKey));
    // Verify state
    Assert.assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(serviceChild1)));
    Assert.assertEquals(Status.NORMAL, stateMachine.getOperationalStatus(wrap(serviceChild2)));
    Assert.assertEquals(Status.MAJOR, stateMachine.getOperationalStatus(wrap(root)));
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Test(org.junit.Test)

Aggregations

IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)10 Test (org.junit.Test)6 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 ConstraintViolation (javax.validation.ConstraintViolation)3 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)3 SingleReductionKeyEdgeEntity (org.opennms.netmgt.bsm.persistence.api.SingleReductionKeyEdgeEntity)3 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)3 IpServiceEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.IpServiceEdgeImpl)3 BusinessServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEdgeEntity)2 EdgeEntityVisitor (org.opennms.netmgt.bsm.persistence.api.EdgeEntityVisitor)2 ChildEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ChildEdgeImpl)2 ReductionKeyEdgeImpl (org.opennms.netmgt.bsm.service.internal.edge.ReductionKeyEdgeImpl)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Criteria (org.opennms.core.criteria.Criteria)1 BusinessServiceDao (org.opennms.netmgt.bsm.persistence.api.BusinessServiceDao)1