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;
}
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());
}
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);
}
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;
}
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)));
}
Aggregations