Skip to content

Commit

Permalink
ALEC-58: Expand test coverage for smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattixtech committed Apr 22, 2019
1 parent 2fed1ee commit e5ed9cd
Show file tree
Hide file tree
Showing 73 changed files with 872 additions and 370 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml
Expand Up @@ -160,7 +160,6 @@ jobs:
mkdir -p ~/dist/
cp assembly/opennms-rpm/target/rpm/opennms-alec-plugin/RPMS/noarch/* ~/dist/
cp assembly/sentinel-rpm/target/rpm/sentinel-alec-plugin/RPMS/noarch/* ~/dist/
cp assembly/kar/target/opennms-alec-plugin.kar ~/dist/
when: always

- store_artifacts:
Expand All @@ -171,7 +170,6 @@ jobs:
root: ~/
paths:
- project
- dist/*.kar

build-debian:
executor: build-debian-executor
Expand Down Expand Up @@ -239,12 +237,6 @@ jobs:
keys:
- v1-docker-{{ checksum "smoke-test/src/main/resources/docker_fixed_images" }}

- run:
name: Make the kar available
command: |
mkdir -p ~/assembly/kar/target/
ln -s ~/dist/opennms-oce-plugin.kar ~/assembly/kar/target/opennms-oce-plugin.kar
- run:
name: Import docker images
command: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -35,4 +35,4 @@ java/bin/
dependency-reduced-pom.xml

# Ignore any copied KAR files produced for the smoke tests
smoke-test/src/main/resources/sentinel-overlay/deploy/*.kar
*.kar
2 changes: 1 addition & 1 deletion assembly/opennms-deb/pom.xml
Expand Up @@ -78,7 +78,7 @@
</goals>
<configuration>
<sourceFile>
${project.build.directory}/releases/${project.artifactId}-${project.version}/oce/org.opennms.alec.assembly.kar-${project.version}.kar
${project.build.directory}/releases/${project.artifactId}-${project.version}/alec/org.opennms.alec.assembly.kar-${project.version}.kar
</sourceFile>
<destinationFile>
${project.build.directory}/deb/usr/share/opennms/deploy/opennms-alec-plugin.kar
Expand Down
2 changes: 1 addition & 1 deletion assembly/opennms-deb/src/main/assemblies/plugin.xml
Expand Up @@ -7,7 +7,7 @@
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/oce/</outputDirectory>
<outputDirectory>/alec/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
Expand Down
2 changes: 1 addition & 1 deletion assembly/sentinel-deb/pom.xml
Expand Up @@ -78,7 +78,7 @@
</goals>
<configuration>
<sourceFile>
${project.build.directory}/releases/${project.artifactId}-${project.version}/oce/org.opennms.alec.assembly.kar-${project.version}.kar
${project.build.directory}/releases/${project.artifactId}-${project.version}/alec/org.opennms.alec.assembly.kar-${project.version}.kar
</sourceFile>
<destinationFile>
${project.build.directory}/deb/var/lib/sentinel/deploy/opennms-alec-plugin.kar
Expand Down
2 changes: 1 addition & 1 deletion assembly/sentinel-deb/src/main/assemblies/plugin.xml
Expand Up @@ -7,7 +7,7 @@
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/oce/</outputDirectory>
<outputDirectory>/alec/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
Expand Down
Expand Up @@ -3,7 +3,7 @@
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">

<!-- Configuration properties -->
<cm:property-placeholder id="modelProperties" persistent-id="org.opennms.oce.datasource.jaxb" update-strategy="reload">
<cm:property-placeholder id="modelProperties" persistent-id="org.opennms.alec.datasource.jaxb" update-strategy="reload">
<cm:default-properties>
<cm:property name="metamodelPath" value=""/>
<cm:property name="inventoryPath" value=""/>
Expand Down
Expand Up @@ -123,7 +123,7 @@ private Optional<String> getSituationIdFromAlarm(org.opennms.integration.api.v1.

public InMemoryEvent toEvent(Situation situation) {
final ImmutableInMemoryEvent.Builder eventBuilder = ImmutableInMemoryEvent.newBuilder();
eventBuilder.setUei(SITUATION_UEI).setSource("oce");
eventBuilder.setUei(SITUATION_UEI).setSource("alec");

// Use the max severity as the situation severity
final Severity maxSeverity = Severity.fromValue(situation.getAlarms().stream()
Expand All @@ -145,7 +145,7 @@ public InMemoryEvent toEvent(Situation situation) {

String description = earliestAlarm.getDescription();
if (situation.getDiagnosticText() != null) {
description += "\n<p>OCE Diagnostic: " + situation.getDiagnosticText() + "</p>";
description += "\n<p>ALEC Diagnostic: " + situation.getDiagnosticText() + "</p>";
}
eventBuilder.addParameter(ImmutableEventParameter.newInstance("situationDescr", description));
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ public class DirectAlarmFeedbackDatasource implements AlarmFeedbackListener, Ala

/**
* @param alarmFeedbackDao used to retrieve the current feedback
* @param mapper used to Map between API and OCE types
* @param mapper used to Map between API and ALEC types
*/
public DirectAlarmFeedbackDatasource(AlarmFeedbackDao alarmFeedbackDao, ApiMapper mapper) {
this.feedbackDao = Objects.requireNonNull(alarmFeedbackDao);
Expand Down
Expand Up @@ -141,7 +141,7 @@ public class DirectInventoryDatasource implements InventoryDatasource, AlarmLife
* @param nodeDao used to retrieve the current inventory
* @param alarmDao used to retrieve the current inventory
* @param edgeDao used to retrieve the current inventory
* @param mapper used to Map between API and OCE types
* @param mapper used to Map between API and ALEC types
*/
public DirectInventoryDatasource(NodeDao nodeDao, AlarmDao alarmDao, EdgeDao edgeDao, ApiMapper mapper) {
this.nodeDao = Objects.requireNonNull(nodeDao);
Expand Down
Expand Up @@ -58,12 +58,20 @@ public static Alarm toAlarm(OpennmsModelProtos.Alarm alarm) {
alarmBuilder.setNodeId(alarm.getNodeCriteria().getId());
}

// Type and instance may be empty strings and in that case we don't want to set them on the alarm we are
// creating
if(!Strings.isNullOrEmpty(alarm.getManagedObjectType())) {
alarmBuilder.setInventoryObjectType(alarm.getManagedObjectType());
}

if(!Strings.isNullOrEmpty(alarm.getManagedObjectInstance())) {
alarmBuilder.setInventoryObjectId(alarm.getManagedObjectInstance());
}

return alarmBuilder
.setId(alarm.getReductionKey())
.setTime(alarm.getLastEventTime())
.setSeverity(toSeverity(alarm.getSeverity()))
.setInventoryObjectType(alarm.getManagedObjectType())
.setInventoryObjectId(alarm.getManagedObjectInstance())
.setSummary(alarm.getLogMessage())
.setDescription(alarm.getDescription())
.build();
Expand Down
Expand Up @@ -64,7 +64,7 @@ public static Event toEvent(Situation situation) {

String description = alarmForDescr.getDescription();
if (situation.getDiagnosticText() != null) {
description += "\n<p>OCE Diagnostic: " + situation.getDiagnosticText() + "</p>";
description += "\n<p>ALEC Diagnostic: " + situation.getDiagnosticText() + "</p>";
}
e.addParam("situationDescr", description);

Expand Down
Expand Up @@ -58,7 +58,7 @@ protected synchronized DateFormat initialValue() {
private String uei;

@XmlElement(name="source")
private String source = "oce";
private String source = "alec";

@XmlElement(name="parms")
private Parameters parameters = new Parameters();
Expand Down
8 changes: 2 additions & 6 deletions datasource/opennms-kafka/src/main/resources/inventory.groovy
Expand Up @@ -26,15 +26,11 @@
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.oce.datasource.opennms
package org.opennms.alec.datasource.opennms

import com.google.common.base.Strings
import groovy.util.logging.Slf4j
import org.opennms.alec.datasource.common.inventory.Edge
import org.opennms.alec.datasource.common.inventory.ManagedObjectType
import org.opennms.alec.datasource.common.inventory.Port
import org.opennms.alec.datasource.common.inventory.Segment
import org.opennms.alec.datasource.common.inventory.TypeToInventory
import org.opennms.alec.datasource.common.inventory.*
import org.opennms.alec.datasource.opennms.EnrichedAlarm
import org.opennms.alec.datasource.opennms.InventoryFromAlarm
import org.opennms.alec.datasource.opennms.OpennmsMapper
Expand Down
Expand Up @@ -57,7 +57,7 @@ public abstract class OpennmsDatasourceIT {

@Rule
public KafkaEmbedded embeddedKafka = new KafkaEmbedded(2, true, 2,
"alarms", "alarmFeedback", "nodes", "oce-inventory", "edges");
"alarms", "alarmFeedback", "nodes", "alec-inventory", "edges");

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
Expand Down
Expand Up @@ -52,7 +52,7 @@ public void canMarshalAndUnmarshal() {
assertThat(JaxbUtils.toXml(e, Event.class), isSimilarTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<event xmlns=\"http://xmlns.opennms.org/xsd/event\">\n" +
" <uei>someuei</uei>\n" +
" <source>oce</source>\n" +
" <source>alec</source>\n" +
" <parms>\n" +
" <parm>\n" +
" <parmName>k1</parmName>\n" +
Expand All @@ -75,7 +75,7 @@ public void canMarshalAndUnmarshal() {
" <events>\n" +
" <event>\n" +
" <uei>someuei</uei>\n" +
" <source>oce</source>\n" +
" <source>alec</source>\n" +
" <parms>\n" +
" <parm>\n" +
" <parmName>k1</parmName>\n" +
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/architecture/pages/opennms_integration.adoc
Expand Up @@ -11,7 +11,7 @@ These events are then sent to _eventd_ where they are processed and enriched wit
_alarmd_ listens for events that contain alarm meta-data and creates or updates alarms that correspond to these.
In addition to the existing alarm processing that was present in OpenNMS before 24.0.0, _alarmd_ now expose a series of link:https://github.com/OpenNMS/opennms-integration-api/blob/1f08398169d10538da7379e13eb8f4cd23933450/api/src/main/java/org/opennms/integration/api/v1/alarms/AlarmPersisterExtension.java[hooks] that can be used to alter/enrich the alarms when they are created.

OCE leverages these hooks to perform additional processing and *tag* the alarms with a managed object type and managed object instance.
ALEC leverages these hooks to perform additional processing and *tag* the alarms with a managed object type and managed object instance.
See the <<managed_object_tagging>> section bellow for more details.

OpenNMS also provides facilities to be notified when alarms are in some way modified.
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/datasources/pages/overview.adoc
@@ -1,9 +1,9 @@
= OCE Datasources
= ALEC Datasources
:imagesdir: ../assets/images

== Overview

The OCE Datasource is responsible for interacting with the monitoring system and providing a feed of alarms, inventory objects and situations.
The ALEC Datasource is responsible for interacting with the monitoring system and providing a feed of alarms, inventory objects and situations.
Data sources are also responsible for creating the situations in the *monitoring system*.

We provide two datasources for integrating with OpenNMS: one for the xref:direct.adoc[monolithic deployment] and one for the xref:kafka.adoc[distributed deployment].
Expand Down
20 changes: 10 additions & 10 deletions docs/modules/engines/pages/deeplearning.adoc
Expand Up @@ -58,23 +58,23 @@ Let's take a snapshot of the current graph:
opennms-alec:datasource-snapshot /tmp/snap1
```

Now edit `/tmp/snap1/oce.situations.xml` to reflect the desired state of situations.
Now edit `/tmp/snap1/alec.situations.xml` to reflect the desired state of situations.

Build vectors from the dataset:

```
opennms-alec:tensorflow-vectorize --alarms-in /tmp/snap1/oce.alarms.xml \
--inventory-in /tmp/snap1/oce.inventory.xml \
--situations-in /tmp/snap1/oce.situations.xml \
--csv-out /tmp/snap1/oce.vector.dataset.csv
opennms-alec:tensorflow-vectorize --alarms-in /tmp/snap1/alec.alarms.xml \
--inventory-in /tmp/snap1/alec.inventory.xml \
--situations-in /tmp/snap1/alec.situations.xml \
--csv-out /tmp/snap1/alec.vector.dataset.csv
```

=== Train with Ludwig

Use Ludwig to train the model:

```
ludwig train --data_csv /tmp/snap1/oce.vector.dataset.csv --model_definition_file model.yaml
ludwig train --data_csv /tmp/snap1/alec.vector.dataset.csv --model_definition_file model.yaml
```

NOTE: Pull `model.yaml` from the `ludwig_model.yaml` file in the source tree
Expand Down Expand Up @@ -132,14 +132,14 @@ config:update
Generate situations:

```
opennms-alec:process-alarms --alarms-in /tmp/snap1/oce.alarms.xml \
--inventory-in /tmp/snap1/oce.inventory.xml \
--situations-out /tmp/snap1/oce.situations.deeplearning.trained.xml \
opennms-alec:process-alarms --alarms-in /tmp/snap1/alec.alarms.xml \
--inventory-in /tmp/snap1/alec.inventory.xml \
--situations-out /tmp/snap1/alec.situations.deeplearning.trained.xml \
--engine deeplearning
```

Compare results:

```
opennms-alec:score-situations -s peer /tmp/snap1/oce.situations.xml /tmp/snap1/oce.situations.deeplearning.trained.xml
opennms-alec:score-situations -s peer /tmp/snap1/alec.situations.xml /tmp/snap1/alec.situations.deeplearning.trained.xml
```
2 changes: 1 addition & 1 deletion docs/modules/install/pages/common_install.adoc
Expand Up @@ -98,7 +98,7 @@ Number of active alarms stored in Elasticsearch (Alarm History) [ Success ] =

=== Enable Syslogd

Let's take advantage of the Syslog patterns and event definitions provided in OCE by enabling Syslogd.
Let's take advantage of the Syslog patterns and event definitions provided in ALEC by enabling Syslogd.

Enable Syslogd by editing `$OPENNMS_HOME/etc/service-configuration.xml` and changing:
```
Expand Down
Expand Up @@ -282,7 +282,7 @@ public synchronized Optional<CEVertex> addOrUpdateAlarm(Alarm alarm) {
}
final ResourceKey resourceKey = getResourceKeyFor(alarm);
final CEVertex vertex = resourceKeyVertexMap.computeIfAbsent(resourceKey, (key) -> {
LOG.info("No existing vertex was found with resource key: {} for alarm with id: {}. Creating a new vertex.", resourceKey, alarm.getId());
LOG.info("No existing vertex was found with resource key: {} for alarm with id: {} and contents: {}. Creating a new vertex.", resourceKey, alarm.getId(), alarm);
final CEVertex v = new CEVertex(vertexIdGenerator.getAndIncrement(), resourceKey);
g.addVertex(v);
didGraphChange.set(true);
Expand Down
Expand Up @@ -75,7 +75,7 @@ public TFModel(BundleContext bundleContext, String modelPath) {
if (Strings.isNullOrEmpty(modelPath)) {
LOG.info("No model path is set. Using default model from class-path.");
try {
tempDir = Files.createTempDirectory("oce-tf");
tempDir = Files.createTempDirectory("alec-tf");
effectiveModelPath = tempDir.toAbsolutePath().toString();
if (bundleContext != null) {
// If we're given a bundle context, use it
Expand Down
Expand Up @@ -99,7 +99,7 @@ public class GraphMLConverter {
this.situations = Objects.requireNonNull(situations);
long now = new Date().getTime();
inventoryEdgeTimeNormalizer = new EdgeTimeNormalizer(now);
graph.setProperty(ONMS_GRAPHML_GRAPH_NAMESPACE, "oce");
graph.setProperty(ONMS_GRAPHML_GRAPH_NAMESPACE, "alec");
graph.setProperty(CREATED_TIMESTAMP_KEY, now);
doc.addGraph(graph);
}
Expand Down
@@ -1,4 +1,4 @@
{% set visible = edge != null && edge.namespace == "oce" %}
{% set visible = edge != null && edge.namespace == "alec" %}
{% set title = edge.properties.id %}

<table width="100%" border="0">
Expand Down
@@ -1,4 +1,4 @@
{% set visible = vertex != null && vertex.namespace == "oce" %}
{% set visible = vertex != null && vertex.namespace == "alec" %}
{% set title = vertex.properties.tooltipText %}
{% set garbageCollected = vertex.properties.garbage_collected != null && vertex.properties.garbage_collected == "true" %}

Expand Down
Expand Up @@ -85,21 +85,21 @@ public Object execute() throws Exception {
final Path outputPath = Paths.get(outputFolder);
Files.createDirectories(outputPath);

final Path inventoryPath = outputPath.resolve("oce.inventory.xml");
final Path inventoryPath = outputPath.resolve("alec.inventory.xml");
System.out.printf("Saving inventory to: %s\n", inventoryPath);
final List<InventoryObject> ios = inventoryDatasource.getInventory();
final Inventory inventory = JaxbUtils.toInventory(ios);
JaxbUtils.write(inventory, inventoryPath);
System.out.printf("Done saving %d inventory objects.\n", inventory.getModelObjectEntry().size());

final Path alarmsPath = outputPath.resolve("oce.alarms.xml");
final Path alarmsPath = outputPath.resolve("alec.alarms.xml");
System.out.printf("Saving alarms to: %s\n", alarmsPath);
final List<Alarm> apiAlarms = alarmDatasource.getAlarms();
final Alarms alarms = JaxbUtils.toAlarms(apiAlarms);
JaxbUtils.write(alarms, alarmsPath);
System.out.printf("Done saving %d alarms.\n", alarms.getAlarm().size());

final Path situationsPath = outputPath.resolve("oce.situations.xml");
final Path situationsPath = outputPath.resolve("alec.situations.xml");
System.out.printf("Saving situations to: %s\n", situationsPath);
final List<Situation> apiSituations = situationDatasource.getSituations();
final Situations situations = JaxbUtils.toSituations(apiSituations);
Expand Down
Expand Up @@ -64,12 +64,12 @@ public class ActiveStandbySituationProcessor implements SituationProcessor, Role
/**
* The redundancy domain to register with.
*/
static final String OCE_DOMAIN = "oce";
static final String ALEC_DOMAIN = "alec";

/**
* The service Id to register with the redundancy domain.
*/
private static final String OCE_SERVICE_ID = "oce.driver";
private static final String ALEC_SERVICE_ID = "alec.driver";

/**
* The domain manager.
Expand Down Expand Up @@ -108,7 +108,7 @@ public class ActiveStandbySituationProcessor implements SituationProcessor, Role
private ActiveStandbySituationProcessor(SituationDatasource situationDatasource,
DomainManagerFactory domainManagerFactory) {
this.situationDatasource = Objects.requireNonNull(situationDatasource);
domainManager = Objects.requireNonNull(domainManagerFactory).getManagerForDomain(OCE_DOMAIN);
domainManager = Objects.requireNonNull(domainManagerFactory).getManagerForDomain(ALEC_DOMAIN);
}

/**
Expand All @@ -122,10 +122,10 @@ static ActiveStandbySituationProcessor newInstance(SituationDatasource situation
DomainManagerFactory domainManagerFactory) {
ActiveStandbySituationProcessor instance = new ActiveStandbySituationProcessor(situationDatasource,
domainManagerFactory);
LOG.debug("Registering service {} for domain {}", OCE_SERVICE_ID, OCE_DOMAIN);
LOG.debug("Registering service {} for domain {}", ALEC_SERVICE_ID, ALEC_DOMAIN);
// The domain registration has to happen after the instance has been created to prevent leaking a 'this'
// reference that may be used by the domain manager before the processor has been fully constructed
instance.domainManager.register(OCE_SERVICE_ID, instance);
instance.domainManager.register(ALEC_SERVICE_ID, instance);

return instance;
}
Expand Down Expand Up @@ -198,8 +198,8 @@ Role getCurrentRole() {
* Deregister with the domain manager.
*/
void destroy() {
LOG.debug("Deregistering service {}", OCE_SERVICE_ID);
domainManager.deregister(OCE_SERVICE_ID);
LOG.debug("Deregistering service {}", ALEC_SERVICE_ID);
domainManager.deregister(ALEC_SERVICE_ID);
}

/**
Expand Down

0 comments on commit e5ed9cd

Please sign in to comment.