kmcpeake
Committed by Gerrit Code Review

CHANGE 1:

Patch to show API for Alarms in Fault Management.
AlarmsWebResource.java & Alarm.java show what the external REST API for alarms would look like.
See more info at https://wiki.onosproject.org/display/ONOS/Fault+Management
Everything else is very early and work-in-progress/mostly just stubbed out, and not ready for review but all advice welcome.

CHANGE 2:
[ONOS-3203] Update re. comments on FM API draft.
Comments were from Thomas Vachuska regarding https://gerrit.onosproject.org/#/c/6180/
Change-Id: If8d330d1b18b503e89849587e2d4388bf67becc0
Showing 39 changed files with 2731 additions and 0 deletions
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.faultmanagement" origin="BTI Systems" version="${project.version}"
18 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
19 + features="${project.artifactId}">
20 + <description>${project.description}</description>
21 +
22 + <artifact>mvn:${project.groupId}/onos-app-fm-mgr/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-app-fm-web/${project.version}</artifact>
24 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <feature>onos-drivers</feature>
22 + <bundle>mvn:${project.groupId}/onos-app-fm-mgr/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-app-fm-web/${project.version}</bundle>
24 + </feature>
25 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19 + <modelVersion>4.0.0</modelVersion>
20 +
21 + <parent>
22 + <groupId>org.onosproject</groupId>
23 + <artifactId>onos-app-fm</artifactId>
24 + <version>1.4.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 +
28 + <artifactId>onos-app-fm-onosfw</artifactId>
29 + <packaging>pom</packaging>
30 +
31 + <description>ONOS framework applications</description>
32 +
33 + <dependencies>
34 + <dependency>
35 + <groupId>org.onosproject</groupId>
36 + <artifactId>onos-app-fm-web</artifactId>
37 + <version>${project.version}</version>
38 + </dependency>
39 + <dependency>
40 + <groupId>org.onosproject</groupId>
41 + <artifactId>onos-app-fm-mgr</artifactId>
42 + <version>${project.version}</version>
43 + </dependency>
44 + </dependencies>
45 +
46 +</project>
1 +<?xml version="1.0"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project
18 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
19 + xmlns="http://maven.apache.org/POM/4.0.0"
20 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21 + <modelVersion>4.0.0</modelVersion>
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-app-fm</artifactId>
25 + <version>1.4.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-fm-mgr</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <dependencies>
33 + <dependency>
34 + <groupId>javax.ws.rs</groupId>
35 + <artifactId>jsr311-api</artifactId>
36 + <version>1.1.1</version>
37 + </dependency>
38 + <dependency>
39 + <groupId>org.onosproject</groupId>
40 + <artifactId>onos-incubator-api</artifactId>
41 + </dependency>
42 + <dependency>
43 + <groupId>org.onosproject</groupId>
44 + <artifactId>onos-core-serializers</artifactId>
45 + <version>${project.version}</version>
46 + </dependency>
47 + <dependency>
48 + <groupId>org.osgi</groupId>
49 + <artifactId>org.osgi.compendium</artifactId>
50 + <version>5.0.0</version>
51 + <type>jar</type>
52 + </dependency>
53 + </dependencies>
54 +</project>
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.impl;
17 +
18 +import static com.google.common.base.Strings.isNullOrEmpty;
19 +import java.util.Dictionary;
20 +import java.util.HashSet;
21 +import java.util.Map;
22 +import java.util.Set;
23 +import java.util.concurrent.ConcurrentHashMap;
24 +import java.util.concurrent.atomic.AtomicLong;
25 +import org.apache.felix.scr.annotations.Activate;
26 +import org.apache.felix.scr.annotations.Component;
27 +import org.apache.felix.scr.annotations.Deactivate;
28 +import org.apache.felix.scr.annotations.Modified;
29 +import org.apache.felix.scr.annotations.Property;
30 +import static org.onlab.util.Tools.nullIsNotFound;
31 +
32 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
33 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
34 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent;
35 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId;
36 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmListener;
37 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService;
38 +import org.onosproject.net.ConnectPoint;
39 +import org.onosproject.net.DeviceId;
40 +import org.slf4j.Logger;
41 +import static org.slf4j.LoggerFactory.getLogger;
42 +import org.apache.felix.scr.annotations.Service;
43 +import static org.onlab.util.Tools.get;
44 +import org.onosproject.core.ApplicationId;
45 +import org.onosproject.core.IdGenerator;
46 +import org.onosproject.core.CoreService;
47 +import org.apache.felix.scr.annotations.Reference;
48 +import org.apache.felix.scr.annotations.ReferenceCardinality;
49 +import org.onlab.util.ItemNotFoundException;
50 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
51 +import org.osgi.service.component.ComponentContext;
52 +
53 +/**
54 + * Implementation of the Alarm service.
55 + */
56 +@Component(immediate = true)
57 +@Service
58 +public class AlarmsManager implements AlarmService {
59 +
60 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 + protected CoreService coreService;
62 + private final Logger log = getLogger(getClass());
63 + private ApplicationId appId;
64 + private IdGenerator idGenerator;
65 +
66 +
67 + @Property(name = "fmDevices", value = "127.0.0.1", label = "Instance-specific configurations")
68 + private String devConfigs;
69 +
70 + private final Map<AlarmId, Alarm> alarms = new ConcurrentHashMap<>();
71 +
72 +
73 + private final AtomicLong alarmIdGenerator = new AtomicLong(0);
74 +
75 + @Override
76 + public Alarm update(final Alarm replacement) {
77 +
78 + final Alarm found = alarms.get(replacement.id());
79 + if (found == null) {
80 + throw new ItemNotFoundException("Alarm with id " + replacement.id() + " found");
81 + }
82 + final Alarm updated = new DefaultAlarm.Builder(found).
83 + withAcknowledged(replacement.acknowledged()).
84 + withAssignedUser(replacement.assignedUser()).build();
85 + alarms.put(replacement.id(), updated);
86 + return updated;
87 + }
88 +
89 + @Override
90 + public int getActiveAlarmCount(final DeviceId deviceId) {
91 + //TODO
92 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
93 + }
94 + private static final String NOT_SUPPORTED_YET = "Not supported yet.";
95 +
96 + @Override
97 + public Alarm getAlarm(final AlarmId alarmId) {
98 + return nullIsNotFound(
99 + alarms.get(alarmId),
100 + "Alarm is not found");
101 + }
102 +
103 + @Override
104 + public Set<Alarm> getAlarms() {
105 + //TODO
106 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
107 + }
108 +
109 + @Override
110 + public Set<Alarm> getActiveAlarms() {
111 + // Enpty set if no values
112 + return alarms.isEmpty() ? new HashSet<>() : new HashSet<>(alarms.values());
113 +
114 + }
115 +
116 + private static DefaultAlarm generateFake(final DeviceId deviceId, final AlarmId alarmId) {
117 +
118 + return new DefaultAlarm.Builder(
119 + alarmId, deviceId, "NE is not reachable", Alarm.SeverityLevel.MAJOR, System.currentTimeMillis()).
120 + withTimeUpdated(System.currentTimeMillis()).
121 + withServiceAffecting(true)
122 + .withAcknowledged(true).
123 + withManuallyClearable(true)
124 + .withAssignedUser("user1").build();
125 + }
126 +
127 + @Override
128 + public Set<Alarm> getAlarms(final Alarm.SeverityLevel severity) {
129 + //TODO
130 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
131 + }
132 +
133 + @Override
134 + public Set<Alarm> getAlarms(final DeviceId deviceId) {
135 + //TODO
136 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
137 + }
138 +
139 + @Override
140 + public Set<Alarm> getAlarms(final DeviceId deviceId, final AlarmEntityId source) {
141 + //TODO
142 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
143 + }
144 +
145 + @Override
146 + public Set<Alarm> getAlarmsForLink(final ConnectPoint src, final ConnectPoint dst) {
147 + //TODO
148 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
149 + }
150 +
151 + @Override
152 + public Set<Alarm> getAlarmsForFlow(final DeviceId deviceId, final long flowId) {
153 + //TODO
154 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
155 + }
156 +
157 + private void discoverAlarmsForDevice(final DeviceId deviceId) {
158 + final AlarmId alarmId = new AlarmId(alarmIdGenerator.incrementAndGet());
159 +
160 + // TODO In a new thread invoke SNMP Provider with DeviceId and device type and when done update our of alarms
161 + //
162 + alarms.put(alarmId, generateFake(deviceId, alarmId));
163 +
164 + }
165 +
166 + private class InternalAlarmListener implements AlarmListener {
167 +
168 + @Override
169 + public void event(final AlarmEvent event) {
170 + // TODO
171 + throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
172 + }
173 + }
174 +
175 + @Activate
176 + public void activate(final ComponentContext context) {
177 + log.info("Activate ...");
178 + appId = coreService.registerApplication("org.onos.faultmanagement.alarms");
179 + idGenerator = coreService.getIdGenerator("alarm-ids");
180 + log.info("Started with appId={} idGenerator={}", appId, idGenerator);
181 +
182 + final boolean result = modified(context);
183 + log.info("modified result = {}", result);
184 +
185 + }
186 +
187 + @Deactivate
188 + public void deactivate(final ComponentContext context) {
189 + log.info("Deactivate ...");
190 + // cfgService.unregisterProperties(getClass(), false);
191 +
192 + log.info("Stopped");
193 + }
194 +
195 + @Modified
196 + public boolean modified(final ComponentContext context) {
197 + log.info("context={}", context);
198 + if (context == null) {
199 + log.info("No configuration file");
200 + return false;
201 + }
202 + final Dictionary<?, ?> properties = context.getProperties();
203 + final String ipaddresses = get(properties, "fmDevices");
204 + log.info("Settings: devConfigs={}", ipaddresses);
205 + if (!isNullOrEmpty(ipaddresses)) {
206 + discover(ipaddresses);
207 +
208 + }
209 + return true;
210 + }
211 +
212 + private void discover(final String ipaddresses) {
213 + for (String deviceEntry : ipaddresses.split(",")) {
214 + final DeviceId deviceId = DeviceId.deviceId(deviceEntry);
215 + if (deviceId != null) {
216 + log.info("Device {} needs to have its alarms refreshed!", deviceId);
217 + discoverAlarmsForDevice(deviceId);
218 + }
219 + }
220 + }
221 +
222 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Fault Management application implementation.
19 + */
20 +package org.onosproject.faultmanagement.impl;
1 +<?xml version="1.0"?>
2 +<!--
3 +~ Copyright 2015 Open Networking Laboratory
4 +~
5 +~ Licensed under the Apache License, Version 2.0 (the "License");
6 +~ you may not use this file except in compliance with the License.
7 +~ You may obtain a copy of the License at
8 +~
9 +~ http://www.apache.org/licenses/LICENSE-2.0
10 +~
11 +~ Unless required by applicable law or agreed to in writing, software
12 +~ distributed under the License is distributed on an "AS IS" BASIS,
13 +~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +~ See the License for the specific language governing permissions and
15 +~ limitations under the License.
16 +-->
17 +<project
18 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
19 + xmlns="http://maven.apache.org/POM/4.0.0"
20 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21 + <modelVersion>4.0.0</modelVersion>
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-app-fm</artifactId>
25 + <version>1.4.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 +
30 + <artifactId>onos-app-fm-web</artifactId>
31 + <packaging>bundle</packaging>
32 + <properties>
33 + <web.context>/onos/v1/fm</web.context>
34 + <api.version>1.0.0</api.version>
35 + <api.title>ONOS Fault Management Application REST API</api.title>
36 + <api.description>
37 + APIs for interacting with the Fault Management application.
38 + </api.description>
39 + <api.package>org.onos.faultmanagement.web</api.package>
40 + </properties>
41 +
42 + <dependencies>
43 + <dependency>
44 + <groupId>javax.ws.rs</groupId>
45 + <artifactId>jsr311-api</artifactId>
46 + <version>1.1.1</version>
47 + </dependency>
48 + <dependency>
49 + <groupId>org.onosproject</groupId>
50 + <artifactId>onos-incubator-api</artifactId>
51 + <version>${project.version}</version>
52 + <type>jar</type>
53 + </dependency>
54 + <dependency>
55 + <groupId>org.onosproject</groupId>
56 + <artifactId>onlab-osgi</artifactId>
57 + <version>${project.version}</version>
58 + <classifier>tests</classifier>
59 + <scope>test</scope>
60 + </dependency>
61 + <dependency>
62 + <groupId>com.sun.jersey</groupId>
63 + <artifactId>jersey-client</artifactId>
64 + <version>1.19</version>
65 + <scope>test</scope>
66 + <type>jar</type>
67 + </dependency>
68 + <dependency>
69 + <groupId>org.onosproject</groupId>
70 + <artifactId>onos-core-common</artifactId>
71 + <version>${project.version}</version>
72 + <scope>test</scope>
73 + <type>jar</type>
74 + </dependency>
75 + <dependency>
76 + <groupId>org.onosproject</groupId>
77 + <artifactId>onos-rest</artifactId>
78 + <version>${project.version}</version>
79 + <scope>test</scope>
80 + <type>jar</type>
81 + </dependency>
82 +
83 + <dependency>
84 + <groupId>org.onosproject</groupId>
85 + <artifactId>onos-rest</artifactId>
86 + <version>${project.version}</version>
87 + <classifier>tests</classifier>
88 + <scope>test</scope>
89 + </dependency>
90 +
91 + <dependency>
92 + <groupId>com.sun.jersey.jersey-test-framework</groupId>
93 + <artifactId>jersey-test-framework-core</artifactId>
94 + <version>1.19</version>
95 + </dependency>
96 +
97 + </dependencies>
98 + <build>
99 + <plugins>
100 + <plugin>
101 + <groupId>org.apache.felix</groupId>
102 + <artifactId>maven-bundle-plugin</artifactId>
103 + <extensions>true</extensions>
104 + <configuration>
105 + <instructions>
106 + <_wab>src/main/webapp/</_wab>
107 + <Include-Resource>
108 + WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
109 + {maven-resources}
110 + </Include-Resource>
111 + <Bundle-SymbolicName>
112 + ${project.groupId}.${project.artifactId}
113 + </Bundle-SymbolicName>
114 + <Import-Package>
115 + org.slf4j,
116 + org.osgi.framework,
117 + javax.ws.rs,
118 + javax.ws.rs.core,
119 + com.sun.jersey.api.core,
120 + com.sun.jersey.spi.container.servlet,
121 + com.sun.jersey.server.impl.container.servlet,
122 + com.fasterxml.jackson.databind,
123 + com.fasterxml.jackson.databind.node,
124 + com.fasterxml.jackson.core,
125 + org.apache.karaf.shell.commands,
126 + org.apache.commons.lang.math.*,
127 + com.google.common.*,
128 + org.onlab.packet.*,
129 + org.onlab.rest.*,
130 + org.onosproject.*,
131 + org.onlab.util.*,
132 + org.jboss.netty.util.*
133 + </Import-Package>
134 + <Web-ContextPath>${web.context}</Web-ContextPath>
135 + </instructions>
136 + </configuration>
137 + </plugin>
138 + </plugins>
139 + </build>
140 +
141 +</project>
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import org.onosproject.codec.CodecContext;
20 +import org.onosproject.codec.JsonCodec;
21 +
22 +import com.fasterxml.jackson.databind.node.ObjectNode;
23 +
24 +import static com.google.common.base.Preconditions.checkNotNull;
25 +import org.onosproject.net.DeviceId;
26 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
27 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
28 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId;
29 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
30 +import org.slf4j.Logger;
31 +import static org.slf4j.LoggerFactory.getLogger;
32 +
33 +/**
34 + * Implementation of encoder for Alarm codec.
35 + */
36 +public final class AlarmCodec extends JsonCodec<Alarm> {
37 +
38 + private final Logger log = getLogger(getClass());
39 +
40 + @Override
41 + public ObjectNode encode(final Alarm alarm, final CodecContext context) {
42 + checkNotNull(alarm, "Alarm cannot be null");
43 +
44 + return context.mapper().createObjectNode()
45 + .put("id", alarm.id().fingerprint())
46 + .put("deviceId", alarm.deviceId().toString())
47 + .put("description", alarm.description())
48 + .put("source",
49 + alarm.source() == null ? null
50 + : alarm.source().toString())
51 + .put("timeRaised", alarm.timeRaised())
52 + .put("timeUpdated", alarm.timeUpdated())
53 + .put("timeCleared", alarm.timeCleared())
54 + .put("severity", alarm.severity().toString())
55 + .put("serviceAffecting", alarm.serviceAffecting())
56 + .put("acknowledged", alarm.acknowledged())
57 + .put("manuallyClearable", alarm.manuallyClearable())
58 + .put("assignedUser", alarm.assignedUser());
59 +
60 + }
61 +
62 + @Override
63 + public Alarm decode(final ObjectNode json, final CodecContext context) {
64 + if (json == null || !json.isObject()) {
65 + return null;
66 + }
67 +
68 + log.debug("id={}, full json={} ", json.get("id"), json);
69 + final Long id = json.get("id").asLong();
70 +
71 + final DeviceId deviceId = DeviceId.deviceId(json.get("deviceId").asText());
72 + final String description = json.get("description").asText();
73 + final Long timeRaised = json.get("timeRaised").asLong();
74 + final Long timeUpdated = json.get("timeUpdated").asLong();
75 +
76 + final JsonNode jsonTimeCleared = json.get("timeCleared");
77 + final Long timeCleared = jsonTimeCleared == null || jsonTimeCleared.isNull() ? null : jsonTimeCleared.asLong();
78 +
79 + final Alarm.SeverityLevel severity
80 + = Alarm.SeverityLevel.valueOf(json.get("severity").asText().toUpperCase());
81 +
82 + final Boolean serviceAffecting = json.get("serviceAffecting").asBoolean();
83 + final Boolean acknowledged = json.get("acknowledged").asBoolean();
84 + final Boolean manuallyClearable = json.get("manuallyClearable").asBoolean();
85 +
86 + final JsonNode jsonAssignedUser = json.get("assignedUser");
87 + final String assignedUser
88 + = jsonAssignedUser == null || jsonAssignedUser.isNull() ? null : jsonAssignedUser.asText();
89 +
90 + return new DefaultAlarm.Builder(
91 + AlarmId.valueOf(id), deviceId, description, severity, timeRaised).forSource(AlarmEntityId.NONE).
92 + withTimeUpdated(timeUpdated).
93 + withTimeCleared(timeCleared).
94 + withServiceAffecting(serviceAffecting).
95 + withAcknowledged(acknowledged).
96 + withManuallyClearable(manuallyClearable).
97 + withAssignedUser(assignedUser).
98 + build();
99 +
100 + }
101 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import com.fasterxml.jackson.databind.ObjectMapper;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import java.io.IOException;
21 +import java.io.InputStream;
22 +import org.onosproject.rest.AbstractWebResource;
23 +
24 +import javax.ws.rs.core.Response;
25 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
26 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId;
27 +
28 +import javax.ws.rs.Consumes;
29 +import javax.ws.rs.DefaultValue;
30 +import javax.ws.rs.GET;
31 +import javax.ws.rs.PUT;
32 +import javax.ws.rs.Path;
33 +import javax.ws.rs.PathParam;
34 +import javax.ws.rs.Produces;
35 +import javax.ws.rs.QueryParam;
36 +import javax.ws.rs.core.MediaType;
37 +import org.onosproject.codec.CodecService;
38 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService;
39 +import org.slf4j.Logger;
40 +import static org.slf4j.LoggerFactory.getLogger;
41 +
42 +/**
43 + * Alarms on devices or ONOS.
44 + */
45 +@Path("alarms")
46 +public class AlarmsWebResource extends AbstractWebResource {
47 +
48 + public static final String ALARM_NOT_FOUND = "Alarm is not found";
49 +
50 + private final Logger log = getLogger(getClass());
51 +
52 + public AlarmsWebResource() {
53 + get(CodecService.class).registerCodec(Alarm.class, new AlarmCodec());
54 + }
55 +
56 + /**
57 + * Get all alarms. Returns a list of all alarms across all devices.
58 + *
59 + * @param includeCleared include recently cleared alarms in response
60 + * @return JSON encoded set of alarms
61 + */
62 + @GET
63 + @Produces(MediaType.APPLICATION_JSON)
64 + public Response getAlarms(@DefaultValue("false") @QueryParam("includeCleared") final boolean includeCleared
65 + ) {
66 +
67 + log.info("Requesting all alarms, includeCleared={}", includeCleared);
68 + final AlarmService service = get(AlarmService.class);
69 +
70 + final Iterable<Alarm> alarms = includeCleared
71 + ? service.getAlarms()
72 + : service.getActiveAlarms();
73 +
74 + final ObjectNode result = new ObjectMapper().createObjectNode();
75 + result.set("alarms",
76 + codec(Alarm.class).
77 + encode(alarms, this));
78 + return ok(result.toString()).build();
79 +
80 + }
81 +
82 + /**
83 + * Get specified alarm. Returns details of the specified alarm.
84 + *
85 + * @param id ONOS allocated identifier
86 + * @return JSON encoded alarm
87 + */
88 + @GET
89 + @Path("{id}")
90 + @Produces(MediaType.APPLICATION_JSON)
91 + public Response getAlarm(@PathParam("id") final String id) {
92 + log.info("HTTP GET alarm for id={}", id);
93 +
94 + final AlarmId alarmId = toAlarmId(id);
95 + final Alarm alarm = get(AlarmService.class).getAlarm(alarmId);
96 +
97 + final ObjectNode result = mapper().createObjectNode();
98 + result.set("alarm", codec(Alarm.class).encode(alarm, this));
99 + return ok(result.toString()).build();
100 + }
101 +
102 + /**
103 + * Update book-keeping fields on the alarm. Returns an up-to-date version of the alarm. Some of its fields may have
104 + * been updated since the REST client last retrieved the alarm being updated.
105 + *
106 + * @param alarmIdPath
107 + * @param stream input JSON
108 + * @return updated JSON encoded alarm
109 + */
110 + @PUT
111 + @Path("{alarm_id}")
112 + @Consumes(MediaType.APPLICATION_JSON)
113 + @Produces(MediaType.APPLICATION_JSON)
114 + public Response update(@PathParam("alarm_id") final String alarmIdPath, final InputStream stream) {
115 + log.info("PUT NEW ALARM at /{}", alarmIdPath);
116 +
117 + try {
118 + final ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
119 + log.info("jsonTree={}", jsonTree);
120 +
121 + final Alarm alarm = codec(Alarm.class).decode(jsonTree, this);
122 +
123 + final AlarmService service = get(AlarmService.class);
124 +
125 + if (Long.parseLong(alarmIdPath) != alarm.id().fingerprint()) {
126 + throw new IllegalArgumentException("id in path is " + Long.parseLong(alarmIdPath)
127 + + " but payload uses id=" + alarm.id().fingerprint());
128 +
129 + }
130 + final Alarm updated = service.update(alarm);
131 + final ObjectNode encoded = new AlarmCodec().encode(updated, this);
132 + return ok(encoded.toString()).build();
133 +
134 + } catch (IOException ioe) {
135 + throw new IllegalArgumentException(ioe);
136 + }
137 + }
138 +
139 + private static AlarmId toAlarmId(final String id) {
140 + try {
141 + return AlarmId.valueOf(Long.parseLong(id));
142 + } catch (NumberFormatException ex) {
143 + throw new IllegalArgumentException("Alarm id should be numeric", ex);
144 + }
145 +
146 + }
147 +
148 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Fault management web support.
19 + */
20 +package org.onosproject.faultmanagement.web;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 +~ Copyright 2015 Open Networking Laboratory
4 +~
5 +~ Licensed under the Apache License, Version 2.0 (the "License");
6 +~ you may not use this file except in compliance with the License.
7 +~ You may obtain a copy of the License at
8 +~
9 +~ http://www.apache.org/licenses/LICENSE-2.0
10 +~
11 +~ Unless required by applicable law or agreed to in writing, software
12 +~ distributed under the License is distributed on an "AS IS" BASIS,
13 +~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +~ See the License for the specific language governing permissions and
15 +~ limitations under the License.
16 +-->
17 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
18 + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
19 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 + id="ONOS" version="2.5">
21 + <display-name>FM2 REST API v1.0</display-name>
22 +
23 + <servlet>
24 + <servlet-name>JAX-RS Service</servlet-name>
25 + <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
26 + <init-param>
27 + <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
28 + <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
29 + </init-param>
30 + <init-param>
31 + <param-name>com.sun.jersey.config.property.classnames</param-name>
32 + <param-value>
33 + org.onosproject.faultmanagement.web.AlarmsWebResource</param-value>
34 + </init-param>
35 + <load-on-startup>10</load-on-startup>
36 + </servlet>
37 +
38 + <servlet-mapping>
39 + <servlet-name>JAX-RS Service</servlet-name>
40 + <url-pattern>/*</url-pattern>
41 + </servlet-mapping>
42 +</web-app>
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import java.util.Map;
19 +import java.util.concurrent.ConcurrentHashMap;
20 +
21 +import org.onosproject.codec.CodecContext;
22 +import org.onosproject.codec.JsonCodec;
23 +
24 +
25 +import com.fasterxml.jackson.databind.ObjectMapper;
26 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
27 +
28 +/**
29 + * Mock codec context for use in codec unit tests.
30 + */
31 +public class AlarmCodecContext implements CodecContext {
32 +
33 + private final ObjectMapper mapper = new ObjectMapper();
34 + private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>();
35 +
36 + /**
37 + * Constructs a new mock codec context.
38 + */
39 + public AlarmCodecContext() {
40 + codecs.clear();
41 + registerCodec(Alarm.class, new AlarmCodec());
42 +
43 + }
44 +
45 + @Override
46 + public ObjectMapper mapper() {
47 + return mapper;
48 + }
49 +
50 + @SuppressWarnings("unchecked")
51 + @Override
52 + public <T> T getService(Class<T> serviceClass) {
53 + // TODO
54 + return null;
55 + }
56 +
57 + /**
58 + * Registers the specified JSON codec for the given entity class.
59 + *
60 + * @param entityClass entity class
61 + * @param codec JSON codec
62 + * @param <T> entity type
63 + */
64 + public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
65 + codecs.putIfAbsent(entityClass, codec);
66 + }
67 +
68 + @SuppressWarnings("unchecked")
69 + @Override
70 + public <T> JsonCodec<T> codec(Class<T> entityClass) {
71 + return codecs.get(entityClass);
72 + }
73 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import java.io.IOException;
21 +import java.io.InputStream;
22 +import static org.hamcrest.MatcherAssert.assertThat;
23 +import static org.hamcrest.Matchers.is;
24 +import static org.hamcrest.Matchers.notNullValue;
25 +import static org.hamcrest.Matchers.nullValue;
26 +
27 +import org.junit.Test;
28 +import org.onosproject.codec.JsonCodec;
29 +import static org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm;
30 +import org.onosproject.net.DeviceId;
31 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
32 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId;
33 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId;
34 +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
35 +
36 +public class AlarmCodecTest {
37 +
38 + private final AlarmCodecContext context = new AlarmCodecContext();
39 +
40 + // Use this to check handling for miminal Alarm
41 + private final Alarm alarmMinimumFields = new DefaultAlarm.Builder(
42 + new AlarmId(44),
43 + DeviceId.deviceId("of:2222000000000000"),
44 + "NE unreachable",
45 + Alarm.SeverityLevel.CLEARED,
46 + 1).
47 + build();
48 +
49 + // Use this to check handling for fully populated Alarm
50 + private final Alarm alarmWithSource = new DefaultAlarm.Builder(
51 + new AlarmId(44),
52 + DeviceId.deviceId("of:2222000000000000"),
53 + "NE unreachable",
54 + Alarm.SeverityLevel.CLEARED, 1).
55 + forSource(AlarmEntityId.alarmEntityId("port:1/2/3/4")).
56 + withTimeUpdated(2).
57 + withTimeCleared(3L).
58 + withServiceAffecting(true).
59 + withAcknowledged(true).
60 + withManuallyClearable(true).
61 + withAssignedUser("the assigned user").build();
62 +
63 + @Test
64 + public void alarmCodecTestWithOptionalFieldMissing() {
65 + //context.registerService(AlarmService.class, new AlarmServiceAdapter());
66 + final JsonCodec<Alarm> codec = context.codec(Alarm.class);
67 + assertThat(codec, is(notNullValue()));
68 +
69 + final ObjectNode alarmJson = codec.encode(alarmMinimumFields, context);
70 + assertThat(alarmJson, notNullValue());
71 + assertThat(alarmJson, matchesAlarm(alarmMinimumFields));
72 +
73 + }
74 +
75 + @Test
76 + public void alarmCodecTestWithOptionalField() {
77 + final JsonCodec<Alarm> codec = context.codec(Alarm.class);
78 + assertThat(codec, is(notNullValue()));
79 +
80 + final ObjectNode alarmJson = codec.encode(alarmWithSource, context);
81 + assertThat(alarmJson, notNullValue());
82 + assertThat(alarmJson, matchesAlarm(alarmWithSource));
83 +
84 + }
85 +
86 + @Test
87 + public void verifyMinimalAlarmIsEncoded() throws Exception {
88 + final JsonCodec<Alarm> alarmCodec = context.codec(Alarm.class);
89 +
90 + final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-minimal.json");
91 + assertCommon(alarm);
92 +
93 + assertThat(alarm.timeCleared(), nullValue());
94 + assertThat(alarm.assignedUser(), nullValue());
95 +
96 + }
97 +
98 + @Test
99 + public void verifyFullyLoadedAlarmIsEncoded() throws Exception {
100 + final JsonCodec<Alarm> alarmCodec = context.codec(Alarm.class);
101 +
102 + final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-full.json");
103 + assertCommon(alarm);
104 +
105 + assertThat(alarm.timeCleared(), is(2222L));
106 + assertThat(alarm.assignedUser(), is("foo"));
107 +
108 + }
109 +
110 + private void assertCommon(final Alarm alarm) {
111 + assertThat(alarm.id(), is(new AlarmId(10L)));
112 + assertThat(alarm.description(), is("NE is not reachable"));
113 + assertThat(alarm.source(), is(AlarmEntityId.NONE));
114 + assertThat(alarm.timeRaised(), is(999L));
115 + assertThat(alarm.timeUpdated(), is(1111L));
116 + assertThat(alarm.severity(), is(Alarm.SeverityLevel.MAJOR));
117 + assertThat(alarm.serviceAffecting(), is(true));
118 + assertThat(alarm.acknowledged(), is(false));
119 + assertThat(alarm.manuallyClearable(), is(true));
120 + }
121 +
122 + /**
123 + * Reads in a rule from the given resource and decodes it.
124 + *
125 + * @param resourceName resource to use to read the JSON for the rule
126 + * @return decoded flow rule
127 + * @throws IOException if processing the resource failsdecode
128 + */
129 + private Alarm getDecodedAlarm(final JsonCodec<Alarm> codec, final String resourceName) throws IOException {
130 + final InputStream jsonStream = AlarmCodecTest.class
131 + .getResourceAsStream(resourceName);
132 + final JsonNode json = context.mapper().readTree(jsonStream);
133 + assertThat(json, notNullValue());
134 + final Alarm result = codec.decode((ObjectNode) json, context);
135 + assertThat(result, notNullValue());
136 + return result;
137 + }
138 +
139 +
140 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import org.hamcrest.Description;
19 +import org.hamcrest.TypeSafeDiagnosingMatcher;
20 +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
21 +
22 +import com.fasterxml.jackson.databind.JsonNode;
23 +
24 +/**
25 + * Hamcrest matcher for alarms.
26 + */
27 +public final class AlarmJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
28 +
29 + private final Alarm alarm;
30 +
31 + private AlarmJsonMatcher(final Alarm alarm) {
32 + this.alarm = alarm;
33 + }
34 +
35 + @Override
36 + public boolean matchesSafely(final JsonNode jsonAlarm, final Description description) {
37 + final String jsonAlarmId = jsonAlarm.get("id").asText();
38 + final String alarmId = Long.toString(alarm.id().fingerprint());
39 + if (!jsonAlarmId.equals(alarmId)) {
40 + description.appendText("alarm id was " + jsonAlarmId);
41 + return false;
42 + }
43 +
44 + final String jsonDeviceId = jsonAlarm.get("deviceId").asText();
45 + final String alarmDeviceId = alarm.deviceId().toString();
46 + if (!jsonDeviceId.equals(alarmDeviceId)) {
47 + description.appendText("DeviceId was " + jsonDeviceId);
48 + return false;
49 + }
50 +
51 +
52 + final String jsonDescription = jsonAlarm.get("description").asText();
53 + final String alarmDesc = alarm.description();
54 + if (!jsonDescription.equals(alarmDesc)) {
55 + description.appendText("description was " + jsonDescription);
56 + return false;
57 + }
58 +
59 + final long jsonTimeRaised = jsonAlarm.get("timeRaised").asLong();
60 + final long timeRaised = alarm.timeRaised();
61 + if (timeRaised != jsonTimeRaised) {
62 + description.appendText("timeRaised was " + jsonTimeRaised);
63 + return false;
64 + }
65 +
66 +
67 + final long jsonTimeUpdated = jsonAlarm.get("timeUpdated").asLong();
68 + final long timeUpdated = alarm.timeUpdated();
69 + if (timeUpdated != jsonTimeUpdated) {
70 + description.appendText("timeUpdated was " + jsonTimeUpdated);
71 + return false;
72 + }
73 +
74 + final JsonNode jsonTimeClearedNode = jsonAlarm.get("timeCleared");
75 +
76 + if (alarm.timeCleared() != null) {
77 + final Long jsonTimeCleared = jsonTimeClearedNode.longValue();
78 + final Long timeCleared = alarm.timeCleared();
79 +
80 + if (!timeCleared.equals(jsonTimeCleared)) {
81 + description.appendText("Time Cleared was " + jsonTimeCleared);
82 + return false;
83 + }
84 + } else {
85 + // No clear time not specified, JSON representation must be empty
86 + if (!jsonTimeClearedNode.isNull()) {
87 + description.appendText("Time Cleared should be null");
88 + return false;
89 + }
90 + }
91 +
92 + final String jsonSeverity = jsonAlarm.get("severity").asText();
93 + final String severity = alarm.severity().toString();
94 + if (!severity.equals(jsonSeverity)) {
95 + description.appendText("severity was " + jsonSeverity);
96 + return false;
97 + }
98 +
99 + final JsonNode jsonAlarmNode = jsonAlarm.get("source");
100 +
101 + if (alarm.source() != null) {
102 + final String jsonSource = jsonAlarmNode.textValue();
103 + final String source = alarm.source().toString();
104 +
105 + if (!source.equals(jsonSource)) {
106 + description.appendText("source was " + jsonSource);
107 + return false;
108 + }
109 + } else {
110 + // source not specified, JSON representation must be empty
111 + if (!jsonAlarmNode.isNull()) {
112 + description.appendText("source should be null");
113 + return false;
114 + }
115 + }
116 +
117 + // In progress
118 + return true;
119 + }
120 +
121 + @Override
122 + public void describeTo(final Description description) {
123 + description.appendText(alarm.toString());
124 + }
125 +
126 + /**
127 + * Factory to allocate a alarm matcher.
128 + *
129 + * @param alarm alarm object we are looking for
130 + * @return matcher
131 + */
132 + public static AlarmJsonMatcher matchesAlarm(final Alarm alarm) {
133 + return new AlarmJsonMatcher(alarm);
134 + }
135 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.faultmanagement.web;
17 +
18 +import com.sun.jersey.api.client.WebResource;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +
22 +import static org.hamcrest.MatcherAssert.assertThat;
23 +import static org.hamcrest.Matchers.containsString;
24 +import static org.hamcrest.Matchers.not;
25 +import org.junit.Ignore;
26 +import org.onlab.osgi.ServiceDirectory;
27 +import org.onlab.osgi.TestServiceDirectory;
28 +import org.onlab.rest.BaseResource;
29 +import org.onosproject.codec.CodecService;
30 +import org.onosproject.codec.impl.CodecManager;
31 +import org.onosproject.rest.ResourceTest;
32 +
33 +/**
34 + * Test of the Fault Management Web REST API for Alarms.
35 + */
36 +public class AlarmsWebResourceTest extends ResourceTest {
37 +
38 + @Before
39 + public void setUp() {
40 +
41 + final CodecManager codecService = new CodecManager();
42 + codecService.activate();
43 +
44 + final ServiceDirectory testDirectory
45 + = new TestServiceDirectory()
46 + // Currently no alarms-service implemented
47 + // .add(AlarmsService.class, alarmsService)
48 + .add(CodecService.class, codecService);
49 + BaseResource.setServiceDirectory(testDirectory);
50 + }
51 +
52 + @Test
53 + @Ignore
54 + public void getAllAlarms() {
55 + final WebResource rs = resource();
56 + final String response = rs.path("/alarms").get(String.class);
57 + // Ensure hard-coded alarms returned okay
58 + assertThat(response, containsString("\"NE is not reachable\","));
59 + assertThat(response, containsString("\"Equipment Missing\","));
60 + }
61 +
62 + @Test
63 + @Ignore
64 + public void getAlarm() {
65 + final WebResource rs = resource();
66 + final String response = rs.path("/alarms/1").get(String.class);
67 + // Ensure hard-coded alarms returned okay
68 + assertThat(response, containsString("\"NE is not reachable\","));
69 + assertThat(response, not(containsString("\"Equipment Missing\",")));
70 + }
71 +
72 +}
1 +{
2 + "id": 10,
3 + "deviceId": "of:123",
4 + "description": "NE is not reachable",
5 + "source": "none:none",
6 + "timeRaised": 999,
7 + "timeUpdated": 1111,
8 + "timeUpdated": 1111,
9 + "timeCleared": 2222,
10 + "severity": "MAJOR",
11 + "serviceAffecting": true,
12 + "acknowledged": false,
13 + "manuallyClearable": true,
14 + "assignedUser": "foo"
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "id": 10,
3 + "deviceId": "of:123",
4 + "description": "NE is not reachable",
5 + "source": "none:none",
6 + "timeRaised": 999,
7 + "timeUpdated": 1111,
8 + "severity": "MAJOR",
9 + "serviceAffecting": true,
10 + "acknowledged": false,
11 + "manuallyClearable": true
12 +}
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-apps</artifactId>
25 + <version>1.4.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-fm</artifactId>
30 + <packaging>pom</packaging>
31 +
32 + <description>ONOS framework applications</description>
33 +
34 + <modules>
35 + <module>fmmgr</module>
36 + <module>fmweb</module>
37 + <module>app</module>
38 + </modules>
39 + <dependencies>
40 + <dependency>
41 + <groupId>org.onosproject</groupId>
42 + <artifactId>onlab-junit</artifactId>
43 + <scope>test</scope>
44 + </dependency>
45 + <dependency>
46 + <groupId>com.google.guava</groupId>
47 + <artifactId>guava-testlib</artifactId>
48 + <scope>test</scope>
49 + </dependency>
50 + <dependency>
51 + <groupId>org.easymock</groupId>
52 + <artifactId>easymock</artifactId>
53 + <scope>test</scope>
54 + </dependency>
55 + </dependencies>
56 +</project>
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
31 <modules> 31 <modules>
32 <module>aaa</module> 32 <module>aaa</module>
33 <module>acl</module> 33 <module>acl</module>
34 + <module>faultmanagement</module>
34 <module>fwd</module> 35 <module>fwd</module>
35 <module>mobility</module> 36 <module>mobility</module>
36 <module>proxyarp</module> 37 <module>proxyarp</module>
......
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import org.onosproject.net.DeviceId;
19 +
20 +/**
21 + * Representation of an Alarm. At a given instant there can be only one alarm
22 + * with the same deviceId + description + source combination.
23 + */
24 +public interface Alarm {
25 +
26 + /**
27 + * Returns the unique alarm id within this ONOS instance.
28 + *
29 + * @return alarm identifier
30 + */
31 + AlarmId id();
32 +
33 + /**
34 + * The device to which this alarm is related.
35 + *
36 + * @return a device id
37 + */
38 + DeviceId deviceId();
39 +
40 + /**
41 + * Returns a description of alarm.
42 + * <p>
43 + * It may encapsulate Event Type as described by ITU Recommendation X.736
44 + * ITU, Quoting https://tools.ietf.org/html/rfc3877 these include: other,
45 + * communicationsAlarm, qualityOfServiceAlarm, processingErrorAlarm,
46 + * equipmentAlarm, environmentalAlarm, integrityViolation,
47 + * operationalViolation, physicalViolation,
48 + * securityServiceOrMechanismViolation, timeDomainViolation
49 + * <p>
50 + * It may encapsulate Probable Cause as described by ITU Recommendation
51 + * X.736 ITU, Quoting
52 + * https://www.iana.org/assignments/ianaitualarmtc-mib/ianaitualarmtc-mib
53 + * these include : aIS, callSetUpFailure, degradedSignal,
54 + * farEndReceiverFailure, framingError, and hundreds more constants.
55 + * <p>
56 + * It may encapsulate a vendor-specific description of the underlying fault.
57 + *
58 + * @return description of alarm
59 + */
60 + String description();
61 +
62 + /**
63 + * Returns an entity within the context of this alarm's device. It may be
64 + * null if deviceId sufficiently identifies the location. As an example, the
65 + * source may indicate a port number
66 + *
67 + * @return source of alarm within the alarm's referenced Device.
68 + */
69 + AlarmEntityId source();
70 +
71 + /**
72 + * Returns the time when raised.
73 + *
74 + * @return time when raised, in milliseconds since start of epoch
75 + */
76 + long timeRaised();
77 +
78 + /**
79 + * Returns time at which the alarm was updated most recently, due to some
80 + * change in the device, or ONOS. If the alarm has been cleared, this is the
81 + * time at which the alarm was cleared.
82 + *
83 + * @return time when last updated, in milliseconds since start of epoch
84 + */
85 + long timeUpdated();
86 +
87 + /**
88 + * Returns the time when cleared. Null indicated no clear time, i.e. the
89 + * alarm is still active.
90 + *
91 + * @return time when cleared, in milliseconds since start of epoch or null
92 + * if uncleared.
93 + */
94 + Long timeCleared();
95 +
96 + /**
97 + * Returns the severity. Note, that cleared alarms may have EITHER
98 + * SeverityLevel = CLEARED, or may be not present; both scenarios should be
99 + * handled.
100 + *
101 + * @return severity of the alarm
102 + */
103 + SeverityLevel severity();
104 +
105 + /**
106 + * Returns true if alarm is service affecting Note: Whilst X.733 combines
107 + * service-affecting state with severity (where severities of critical and
108 + * major are deemed service-affecting) ONOS keeps these attributes separate.
109 + *
110 + * @return whether service affecting (true indicates it is)
111 + */
112 + boolean serviceAffecting();
113 +
114 + /**
115 + * Returns a flag to indicate if this alarm has been acknowledged. All
116 + * alarms are unacknowledged until and unless an ONOS user takes action to
117 + * indicate so.
118 + *
119 + * @return whether alarm is currently acknowledged (true indicates it is)
120 + */
121 + boolean acknowledged();
122 +
123 + /**
124 + * Returns a flag to indicate if this alarm is manually-cleared by a user action within ONOS. Some stateless events
125 + * e.g. backup-failure or upgrade-failure, may be mapped by ONOS to alarms, and these may be deemed manually-
126 + * clearable. The more typical case is that an alarm represents a persistent fault on or related to a device and
127 + * such alarms are never manually clearable, i.e. a configuration or operational state must occur for the alarm to
128 + * clear.
129 + *
130 + * @return whether it may be cleared by a user action (true indicates it is)
131 + */
132 + boolean manuallyClearable();
133 +
134 + /**
135 + * Returns the user to whom this alarm is assigned; this is for future use
136 + * and always returns null in this release. It is anticipated that in future ONOS
137 + * releases, the existing JAAS user/key/role configuration will be extended
138 + * to include a mechanism whereby some groups of users may allocate alarms
139 + * to other users for bookkeeping and administrative purposes, and that ONOS
140 + * will additionally provide a REST based mechanism, to retrieve from JAAS,
141 + * the set of users to whom alarm assignment is possible for the current
142 + * user.
143 + *
144 + * @return the assigned user; always null in this release.
145 + */
146 + String assignedUser();
147 +
148 + /**
149 + * Represents the severity level on an alarm, as per ITU-T X.733
150 + * specifications.
151 + * <p>
152 + * The precedence is as follows for : Critical &gt; Major &gt; Minor &gt; Warning.
153 + */
154 + enum SeverityLevel {
155 +
156 + /**
157 + * From X.733: This indicates the clearing of one or more previously
158 + * reported alarms. This alarm clears all alarms for this managed object
159 + * that have the same Alarm type, Probable cause and Specific problems
160 + * (if given). Multiple associated notifications may be cleared by using
161 + * the Correlated notifications parameter (defined below). This
162 + * Recommendation | International Standard does not require that the
163 + * clearing of previously reported alarms be reported. Therefore, a
164 + * managing system cannot assume that the absence of an alarm with the
165 + * Cleared severity level means that the condition that caused the
166 + * generation of previous alarms is still present. Managed object
167 + * definers shall state if, and under which conditions, the Cleared
168 + * severity level is used.
169 + */
170 + CLEARED,
171 + /**
172 + * From X.733: This indicates that the severity level cannot be
173 + * determined.
174 + */
175 + INDETERMINATE,
176 + /**
177 + * From X.733: This indicates that a service affecting condition has
178 + * occurred and an immediate corrective action is required. Such a
179 + * severity can be reported, for example, when a managed object becomes
180 + * totally out of service and its capability must be restored.
181 + */
182 + CRITICAL,
183 + /**
184 + * X.733 definition: This indicates that a service affecting condition
185 + * has developed and an urgent corrective action is required. Such a
186 + * severity can be reported, for example, when there is a severe
187 + * degradation in the capability of the managed object and its full
188 + * capability must be restored.
189 + */
190 + MAJOR,
191 + /**
192 + * From X.733: This indicates the existence of a non-service affecting
193 + * fault condition and that corrective action should be taken in order
194 + * to prevent a more serious (for example, service affecting) fault.
195 + * Such a severity can be reported, for example, when the detected alarm
196 + * condition is not currently degrading the capacity of the managed
197 + * object.
198 + */
199 + MINOR,
200 + /**
201 + * From X.733: This indicates the detection of a potential or impending
202 + * service affecting fault, before any significant effects have been
203 + * felt. Action should be taken to further diagnose (if necessary) and
204 + * correct the problem in order to prevent it from becoming a more
205 + * serious service affecting fault.
206 + */
207 + WARNING;
208 +
209 + }
210 +
211 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +import com.google.common.collect.ImmutableSet;
20 +import java.net.URI;
21 +import java.util.Objects;
22 +import java.util.Set;
23 +
24 +/**
25 + * Immutable representation of a alarm source. It is meaningful within the
26 + * context of a device.
27 + */
28 +public final class AlarmEntityId {
29 +
30 + public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none"));
31 + public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other");
32 +
33 + private final URI uri;
34 +
35 + private AlarmEntityId(final URI uri) {
36 + this.uri = uri;
37 + }
38 +
39 + protected AlarmEntityId() {
40 + uri = NONE.uri;
41 + }
42 +
43 + public static AlarmEntityId alarmEntityId(final String string) {
44 + return alarmEntityId(URI.create(string));
45 + }
46 +
47 + public static AlarmEntityId alarmEntityId(final URI uri) {
48 + checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme");
49 + return new AlarmEntityId(uri);
50 + }
51 +
52 + @Override
53 + public String toString() {
54 + return uri.toString();
55 + }
56 +
57 + @Override
58 + public int hashCode() {
59 + return Objects.hash(uri);
60 +
61 + }
62 +
63 + @Override
64 + public boolean equals(final Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 + if (obj instanceof AlarmEntityId) {
69 + final AlarmEntityId other = (AlarmEntityId) obj;
70 + return Objects.equals(this.uri, other.uri);
71 + }
72 + return false;
73 + }
74 +
75 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import org.onosproject.event.AbstractEvent;
19 +
20 +/**
21 + * Entity that represents Alarm events.
22 + */
23 +public class AlarmEvent extends AbstractEvent<AlarmEvent.Type, Alarm> {
24 +
25 +
26 + /**
27 + * Creates an event of a given type and for the specified alarm and the
28 + * current time.
29 + *
30 + * @param type topology event type
31 + * @param alarm the alarm
32 + */
33 + public AlarmEvent(Type type, Alarm alarm) {
34 + super(type, alarm);
35 + }
36 +
37 + /**
38 + * Creates an event of a given type and for the specified alarm and time.
39 + *
40 + * @param type link event type
41 + * @param alarm the alarm
42 + * @param time occurrence time
43 + */
44 + public AlarmEvent(Type type, Alarm alarm,
45 + long time) {
46 + super(type, alarm, time);
47 + }
48 +
49 + /**
50 + * Type of alarm events.
51 + */
52 + public enum Type {
53 + /**
54 + * A Raised Alarm.
55 + */
56 + RAISE,
57 +
58 + /**
59 + * A Cleared Alarm.
60 + */
61 + CLEAR
62 + }
63 +
64 +
65 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import com.google.common.annotations.Beta;
19 +
20 +import java.util.Objects;
21 +
22 +import static com.google.common.base.MoreObjects.toStringHelper;
23 +
24 +/**
25 + * Alarm identifier suitable as an external key.
26 + * <p>
27 + * This class is immutable.</p>
28 + */
29 +@Beta
30 +public final class AlarmId {
31 +
32 + private final long id;
33 +
34 + /**
35 + * Instantiates a new Alarm id.
36 + *
37 + * @param id the id
38 + */
39 + public AlarmId(final long id) {
40 + this.id = id;
41 + }
42 +
43 + /**
44 + * Creates an alarm identifier from the specified long representation.
45 + *
46 + * @param value long value
47 + * @return intent identifier
48 + */
49 + public static AlarmId valueOf(final long value) {
50 + return new AlarmId(value);
51 + }
52 +
53 + /**
54 + * Returns the backing integer index.
55 + *
56 + * @return backing integer index
57 + */
58 + public long fingerprint() {
59 + return id;
60 + }
61 +
62 + @Override
63 + public int hashCode() {
64 + return Objects.hash(id);
65 + }
66 +
67 + @Override
68 + public boolean equals(final Object obj) {
69 + if (this == obj) {
70 + return true;
71 + }
72 + if (obj instanceof AlarmId) {
73 + final AlarmId other = (AlarmId) obj;
74 + return Objects.equals(this.id, other.id);
75 + }
76 + return false;
77 + }
78 +
79 + @Override
80 + public String toString() {
81 + return toStringHelper(this).add("id", id).toString();
82 + }
83 +
84 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import org.onosproject.event.EventListener;
19 +
20 +
21 +/**
22 + * Entity capable of receiving Alarm related events.
23 + */
24 +public interface AlarmListener extends EventListener<AlarmEvent> {
25 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import org.onosproject.net.DeviceId;
19 +import org.onosproject.net.provider.Provider;
20 +
21 +/**
22 + * Abstraction of a Alarm provider.
23 + */
24 +public interface AlarmProvider extends Provider {
25 +
26 + /**
27 + * Triggers an asynchronous discovery of the alarms on the specified device,
28 + * intended to refresh internal alarm model for the device. An indirect
29 + * result of this should be invocation of
30 + * {@link org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService#updateAlarmList} )}
31 + * at some later point in time.
32 + *
33 + * @param deviceId ID of device to be probed
34 + */
35 + void triggerProbe(DeviceId deviceId);
36 +
37 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +
19 +import org.onosproject.net.provider.ProviderRegistry;
20 +
21 +/**
22 + * Abstraction of a alarm provider registry.
23 + */
24 +public interface AlarmProviderRegistry extends ProviderRegistry<AlarmProvider, AlarmProviderService> {
25 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.provider.ProviderService;
21 +
22 +import java.util.Collection;
23 +
24 +/**
25 + * The interface Alarm provider service.
26 + */
27 +public interface AlarmProviderService extends ProviderService<AlarmProvider> {
28 +
29 + /**
30 + * Sends active alarm list for a device.
31 + *
32 + * @param deviceId identity of the device
33 + * @param alarms list of device alarms
34 + */
35 + void updateAlarmList(DeviceId deviceId, Collection<Alarm> alarms);
36 +
37 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import com.google.common.annotations.Beta;
19 +//import org.onosproject.event.ListenerService;
20 +
21 +import java.util.Set;
22 +import org.onosproject.net.ConnectPoint;
23 +import org.onosproject.net.DeviceId;
24 +
25 +/**
26 + * Service for interacting with the alarm handling of devices. Unless stated
27 + * otherwise method return active AND recently-cleared alarms.
28 + */
29 +@Beta
30 +public interface AlarmService {
31 +// extends ListenerService<AlarmEvent, AlarmListener> {
32 +
33 + /**
34 + * Alarm should be updated in ONOS's internal representation; only
35 + * administration/book-keeping fields may be updated. Attempting to update
36 + * fields which are mapped directly from device is prohibited.
37 + *
38 + * @param replacement alarm with updated book-keeping fields
39 + * @return updated alarm (including any recent device derived changes)
40 +
41 + * @throws java.lang.IllegalStateException if attempt to update not allowed
42 + * fields.
43 + */
44 + Alarm update(Alarm replacement);
45 +
46 + /**
47 + * Returns the number of ACTIVE alarms on a device.
48 + *
49 + * @param deviceId the device
50 + * @return number of alarms
51 + */
52 + int getActiveAlarmCount(DeviceId deviceId);
53 +
54 + /**
55 + * Returns the alarm with the specified identifier.
56 + *
57 + * @param alarmId alarm identifier
58 + * @return alarm or null if one with the given identifier is not known
59 + */
60 + Alarm getAlarm(AlarmId alarmId);
61 +
62 + /**
63 + * Returns all of the alarms.
64 + *
65 + * @return the alarms
66 + */
67 + Set<Alarm> getAlarms();
68 +
69 + /**
70 + * Returns all of the ACTIVE alarms. Recently cleared alarms excluded.
71 + *
72 + * @return the alarms
73 + */
74 + Set<Alarm> getActiveAlarms();
75 +
76 + /**
77 + * Returns the alarms with the specified severity.
78 + *
79 + * @param severity the alarm severity
80 + * @return the active alarms with a particular severity
81 + */
82 + Set<Alarm> getAlarms(Alarm.SeverityLevel severity);
83 +
84 + /**
85 + * Returns the alarm for a given device, regardless of source within that
86 + * device.
87 + *
88 + * @param deviceId the device
89 + * @return the alarms
90 + */
91 + Set<Alarm> getAlarms(DeviceId deviceId);
92 +
93 + /**
94 + * Returns the alarm for a given device and source.
95 + *
96 + * @param deviceId the device
97 + * @param source the source within the device
98 + * @return the alarms
99 + */
100 + Set<Alarm> getAlarms(DeviceId deviceId, AlarmEntityId source);
101 +
102 + /**
103 + * Returns the alarm affecting a given link.
104 + *
105 + * @param src one end of the link
106 + * @param dst one end of the link
107 + * @return the alarms
108 + */
109 + Set<Alarm> getAlarmsForLink(ConnectPoint src, ConnectPoint dst);
110 +
111 + /**
112 + * Returns the alarm affecting a given flow.
113 + *
114 + * @param deviceId the device
115 + * @param flowId the flow
116 + * @return the alarms
117 + */
118 + Set<Alarm> getAlarmsForFlow(DeviceId deviceId, long flowId);
119 +
120 +// Support retrieving alarms affecting other ONOS entity types may be added in future release
121 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import org.onosproject.net.DeviceId;
19 +
20 +import java.util.Objects;
21 +
22 +import static com.google.common.base.MoreObjects.toStringHelper;
23 +import static com.google.common.base.Preconditions.checkNotNull;
24 +
25 +/**
26 + * Default implementation of an alarm.
27 + */
28 +public final class DefaultAlarm implements Alarm {
29 +
30 + private final AlarmId id;
31 +
32 + private final DeviceId deviceId;
33 + private final String description;
34 + private final AlarmEntityId source;
35 + private final long timeRaised;
36 + private final long timeUpdated;
37 + private final Long timeCleared;
38 + private final SeverityLevel severity;
39 + private final boolean isServiceAffecting;
40 + private final boolean isAcknowledged;
41 + private final boolean isManuallyClearable;
42 + private final String assignedUser;
43 +
44 + /**
45 + * Instantiates a new Default alarm.
46 + *
47 + * @param id the id
48 + * @param deviceId the device id
49 + * @param description the description
50 + * @param source the source, null indicates none.
51 + * @param timeRaised the time raised.
52 + * @param timeUpdated the time last updated.
53 + * @param timeCleared the time cleared, null indicates uncleared.
54 + * @param severity the severity
55 + * @param isServiceAffecting the service affecting
56 + * @param isAcknowledged the acknowledged
57 + * @param isManuallyClearable the manually clearable
58 + * @param assignedUser the assigned user, `null` indicates none.
59 + */
60 + private DefaultAlarm(final AlarmId id,
61 + final DeviceId deviceId,
62 + final String description,
63 + final AlarmEntityId source,
64 + final long timeRaised,
65 + final long timeUpdated,
66 + final Long timeCleared,
67 + final SeverityLevel severity,
68 + final boolean isServiceAffecting,
69 + final boolean isAcknowledged,
70 + final boolean isManuallyClearable,
71 + final String assignedUser) {
72 + this.id = id;
73 + this.deviceId = deviceId;
74 + this.description = description;
75 + this.source = source;
76 + this.timeRaised = timeRaised;
77 + this.timeUpdated = timeUpdated;
78 + this.timeCleared = timeCleared;
79 + this.severity = severity;
80 + this.isServiceAffecting = isServiceAffecting;
81 + this.isAcknowledged = isAcknowledged;
82 + this.isManuallyClearable = isManuallyClearable;
83 + this.assignedUser = assignedUser;
84 + }
85 +
86 + @Override
87 + public AlarmId id() {
88 + return id;
89 + }
90 +
91 + @Override
92 + public DeviceId deviceId() {
93 + return deviceId;
94 + }
95 +
96 + @Override
97 + public String description() {
98 + return description;
99 + }
100 +
101 + @Override
102 + public AlarmEntityId source() {
103 + return source;
104 + }
105 +
106 + @Override
107 + public long timeRaised() {
108 + return timeRaised;
109 + }
110 +
111 + @Override
112 + public long timeUpdated() {
113 + return timeUpdated;
114 + }
115 +
116 + @Override
117 + public Long timeCleared() {
118 + return timeCleared;
119 + }
120 +
121 + @Override
122 + public SeverityLevel severity() {
123 + return severity;
124 + }
125 +
126 + @Override
127 + public boolean serviceAffecting() {
128 + return isServiceAffecting;
129 + }
130 +
131 + @Override
132 + public boolean acknowledged() {
133 + return isAcknowledged;
134 + }
135 +
136 + @Override
137 + public boolean manuallyClearable() {
138 + return isManuallyClearable;
139 + }
140 +
141 + @Override
142 + public String assignedUser() {
143 + return assignedUser;
144 + }
145 +
146 + @Override
147 + public int hashCode() {
148 + return Objects.hash(id, deviceId, description,
149 + source, timeRaised, timeUpdated, timeCleared, severity,
150 + isServiceAffecting, isAcknowledged,
151 + isManuallyClearable, assignedUser);
152 + }
153 +
154 + @Override
155 + public boolean equals(final Object obj) {
156 + if (obj == null) {
157 + return false;
158 + }
159 + if (getClass() != obj.getClass()) {
160 + return false;
161 + }
162 + final DefaultAlarm other = (DefaultAlarm) obj;
163 + if (!Objects.equals(this.id, other.id)) {
164 + return false;
165 + }
166 + if (!Objects.equals(this.deviceId, other.deviceId)) {
167 + return false;
168 + }
169 + if (!Objects.equals(this.description, other.description)) {
170 + return false;
171 + }
172 + if (!Objects.equals(this.source, other.source)) {
173 + return false;
174 + }
175 + if (this.timeRaised != other.timeRaised) {
176 + return false;
177 + }
178 + if (this.timeUpdated != other.timeUpdated) {
179 + return false;
180 + }
181 + if (!Objects.equals(this.timeCleared, other.timeCleared)) {
182 + return false;
183 + }
184 + if (this.severity != other.severity) {
185 + return false;
186 + }
187 + if (this.isServiceAffecting != other.isServiceAffecting) {
188 + return false;
189 + }
190 + if (this.isAcknowledged != other.isAcknowledged) {
191 + return false;
192 + }
193 + if (this.isManuallyClearable != other.isManuallyClearable) {
194 + return false;
195 + }
196 + if (!Objects.equals(this.assignedUser, other.assignedUser)) {
197 + return false;
198 + }
199 + return true;
200 + }
201 +
202 + @Override
203 + public String toString() {
204 + return toStringHelper(this)
205 + .add("id", id)
206 + .add("deviceId", deviceId)
207 + .add("description", description)
208 + .add("source", source)
209 + .add("timeRaised", timeRaised)
210 + .add("timeUpdated", timeUpdated)
211 + .add("timeCleared", timeCleared)
212 + .add("severity", severity)
213 + .add("serviceAffecting", isServiceAffecting)
214 + .add("acknowledged", isAcknowledged)
215 + .add("manuallyClearable", isManuallyClearable)
216 + .add("assignedUser", assignedUser)
217 + .toString();
218 + }
219 +
220 + public static class Builder {
221 +
222 + // Manadatory fields ..
223 + private final AlarmId id;
224 + private final DeviceId deviceId;
225 + private final String description;
226 + private final SeverityLevel severity;
227 + private final long timeRaised;
228 +
229 + // Optional fields ..
230 + private AlarmEntityId source = AlarmEntityId.NONE;
231 + private long timeUpdated;
232 + private Long timeCleared = null;
233 + private boolean isServiceAffecting = false;
234 + private boolean isAcknowledged = false;
235 + private boolean isManuallyClearable = false;
236 + private String assignedUser = null;
237 +
238 + public Builder(final Alarm alarm) {
239 + this(alarm.id(), alarm.deviceId(), alarm.description(), alarm.severity(), alarm.timeRaised());
240 + this.source = AlarmEntityId.NONE;
241 + this.timeUpdated = alarm.timeUpdated();
242 + this.timeCleared = alarm.timeCleared();
243 + this.isServiceAffecting = alarm.serviceAffecting();
244 + this.isAcknowledged = alarm.acknowledged();
245 + this.isManuallyClearable = alarm.manuallyClearable();
246 + this.assignedUser = alarm.assignedUser();
247 +
248 + }
249 +
250 + public Builder(final AlarmId id, final DeviceId deviceId,
251 + final String description, final SeverityLevel severity, final long timeRaised) {
252 + super();
253 + this.id = id;
254 + this.deviceId = deviceId;
255 + this.description = description;
256 + this.severity = severity;
257 + this.timeRaised = timeRaised;
258 + // Unless specified time-updated is same as raised.
259 + this.timeUpdated = timeRaised;
260 + }
261 +
262 + public Builder forSource(final AlarmEntityId source) {
263 + this.source = source;
264 + return this;
265 + }
266 +
267 + public Builder withTimeUpdated(final long timeUpdated) {
268 + this.timeUpdated = timeUpdated;
269 + return this;
270 + }
271 +
272 + public Builder withTimeCleared(final Long timeCleared) {
273 + this.timeCleared = timeCleared;
274 + return this;
275 + }
276 +
277 + public Builder withServiceAffecting(final boolean isServiceAffecting) {
278 + this.isServiceAffecting = isServiceAffecting;
279 + return this;
280 + }
281 +
282 + public Builder withAcknowledged(final boolean isAcknowledged) {
283 + this.isAcknowledged = isAcknowledged;
284 + return this;
285 + }
286 +
287 + public Builder withManuallyClearable(final boolean isManuallyClearable) {
288 + this.isManuallyClearable = isManuallyClearable;
289 + return this;
290 + }
291 +
292 + public Builder withAssignedUser(final String assignedUser) {
293 + this.assignedUser = assignedUser;
294 + return this;
295 + }
296 +
297 + public DefaultAlarm build() {
298 + checkNotNull(id, "Must specify an alarm id");
299 + checkNotNull(deviceId, "Must specify a device");
300 + checkNotNull(description, "Must specify a description");
301 + checkNotNull(timeRaised, "Must specify a time raised");
302 + checkNotNull(timeUpdated, "Must specify a time updated");
303 + checkNotNull(severity, "Must specify a severity");
304 +
305 + return new DefaultAlarm(id, deviceId, description, source, timeRaised, timeUpdated, timeCleared,
306 + severity, isServiceAffecting, isAcknowledged, isManuallyClearable, assignedUser);
307 + }
308 + }
309 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +/**
17 + * Abstractions for interacting with alarms. An alarm is a persistent indication
18 + * of a fault that clears only when the triggering condition has been resolved.
19 + */
20 +package org.onosproject.incubator.net.faultmanagement.alarm;
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +import static org.junit.Assert.assertEquals;
20 +import org.junit.Test;
21 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
22 +import static org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId.alarmEntityId;
23 +
24 +/**
25 + * Test of the alarm source identifier.
26 + *
27 + */
28 +public class AlarmEntityIdTest {
29 +
30 + /**
31 + * Checks that the class is immutable.
32 + */
33 + @Test
34 + public void testImmutability() {
35 + assertThatClassIsImmutable(AlarmEntityId.class);
36 + }
37 +
38 + @Test
39 + public void string() {
40 + assertEquals("och:foo",
41 + alarmEntityId("och:foo").toString());
42 + }
43 +
44 + @Test
45 + public void basics() {
46 + new EqualsTester()
47 + .addEqualityGroup(
48 + alarmEntityId("och:foo"),
49 + alarmEntityId("och:foo"))
50 + .addEqualityGroup(alarmEntityId("och:bar"))
51 + .testEquals();
52 +
53 + }
54 +
55 + @Test
56 + public void validSchemaPermitted() {
57 + alarmEntityId("none:foo");
58 + alarmEntityId("port:foo");
59 + alarmEntityId("och:foo");
60 + alarmEntityId("other:foo");
61 +
62 + }
63 +
64 + @Test(expected = IllegalArgumentException.class)
65 + public void verifyUnexpectedSchemaRejected() {
66 + alarmEntityId("junk:foo");
67 + }
68 +
69 + @Test(expected = IllegalArgumentException.class)
70 + public void verifyCorruptSchemaRejected() {
71 + alarmEntityId("other:");
72 + }
73 +
74 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +import org.junit.Test;
20 +
21 +import static org.hamcrest.Matchers.is;
22 +import static org.hamcrest.Matchers.not;
23 +import static org.junit.Assert.assertEquals;
24 +import static org.junit.Assert.assertThat;
25 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26 +
27 +/**
28 + * This class tests the immutability, equality, and non-equality of
29 + * {@link AlarmId}.
30 + */
31 +public class AlarmIdTest {
32 + private static final long ID_A = 1L;
33 + private static final long ID_B = 2L;
34 + private static final long ID_Z = 987654321L;
35 +
36 + /**
37 + * Tests the immutability of {@link AlarmId}.
38 + */
39 + @Test
40 + public void intentIdFollowsGuidelineForImmutableObject() {
41 + assertThatClassIsImmutable(AlarmId.class);
42 + }
43 +
44 + /**
45 + * Tests equality of {@link AlarmId}.
46 + */
47 + @Test
48 + public void testEquality() {
49 + final AlarmId id1 = new AlarmId(ID_A);
50 + final AlarmId id2 = new AlarmId(ID_A);
51 +
52 + assertThat(id1, is(id2));
53 + }
54 +
55 +
56 + /**
57 + * Tests non-equality of {@link AlarmId}.
58 + */
59 + @Test
60 + public void testNonEquality() {
61 + final AlarmId id1 = new AlarmId(ID_A);
62 + final AlarmId id2 = new AlarmId(ID_B);
63 +
64 + assertThat(id1, is(not(id2)));
65 + }
66 +
67 + @Test
68 + public void valueOf() {
69 + final AlarmId id = new AlarmId(0xdeadbeefL);
70 + assertEquals("incorrect valueOf", id, AlarmId.valueOf(0xdeadbeefL));
71 + }
72 +
73 + /**
74 + * Tests the equals(), hashCode() and toString() methods.
75 + */
76 + @Test
77 + public void testEquals() {
78 + final AlarmId id1 = new AlarmId(11111L);
79 + final AlarmId sameAsId1 = new AlarmId(11111L);
80 + final AlarmId id2 = new AlarmId(22222L);
81 +
82 + new EqualsTester()
83 + .addEqualityGroup(id1, sameAsId1)
84 + .addEqualityGroup(id2)
85 + .testEquals();
86 + }
87 +
88 + /**
89 + * Tests construction of an AlarmId object.
90 + */
91 + @Test
92 + public void testConstruction() {
93 + final AlarmId id1 = new AlarmId(ID_Z);
94 + assertEquals(id1.fingerprint(), ID_Z);
95 +
96 + // No default constructor so no need to test it !
97 + }
98 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.incubator.net.faultmanagement.alarm;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +import org.junit.Test;
22 +import static org.junit.Assert.*;
23 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24 +import org.onosproject.net.DeviceId;
25 +
26 +public class DefaultAlarmTest {
27 +
28 + @Test
29 + public void testImmutability() {
30 + assertThatClassIsImmutable(DefaultAlarm.class);
31 + }
32 +
33 + /**
34 + * Checks the construction of a DefaultAlarm object.
35 + */
36 + @Test
37 + public void testConstruction() {
38 + final String nameValue = "name3";
39 + final DefaultAlarm a = new DefaultAlarm.Builder(AlarmId.valueOf(4),
40 + DeviceId.NONE, nameValue, Alarm.SeverityLevel.CLEARED, 3).build();
41 +
42 + assertThat(a, is(notNullValue()));
43 + final DefaultAlarm b = new DefaultAlarm.Builder(a).build();
44 +
45 + assertEquals(a, b);
46 + }
47 +}
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
41 <module>pcep</module> 41 <module>pcep</module>
42 <module>ovsdb</module> 42 <module>ovsdb</module>
43 <module>bgp</module> 43 <module>bgp</module>
44 + <module>snmp</module>
44 </modules> 45 </modules>
45 46
46 <dependencies> 47 <dependencies>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-snmp-providers</artifactId>
25 + <version>1.4.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-snmp-provider-alarm</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS SNMP protocol alarm provider</description>
33 +
34 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.snmp.alarm.impl;
17 +
18 +import org.apache.felix.scr.annotations.Component;
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider;
21 +import org.onosproject.net.provider.AbstractProvider;
22 +import org.onosproject.net.provider.ProviderId;
23 +import org.slf4j.Logger;
24 +
25 +import static org.slf4j.LoggerFactory.getLogger;
26 +
27 +/**
28 + * Provider which uses an SNMP controller to detect network device alarms. The class leverages functionality from
29 + *
30 + * @see <a href="https://github.com/btisystems/snmp-core">https://github.com/btisystems/snmp-core</a>
31 + * @see <a href="https://github.com/btisystems/mibbler">https://github.com/btisystems/mibbler</a>
32 + */
33 +@Component(immediate = true)
34 +public class SNMPAlarmProvider extends AbstractProvider implements AlarmProvider {
35 +
36 + private static final Logger LOG = getLogger(SNMPAlarmProvider.class);
37 +
38 + /**
39 + * Creates a SNMP alarm provider, dummy class provided as template, tbd later.
40 + */
41 + public SNMPAlarmProvider() {
42 + super(new ProviderId("snmp", "org.onosproject.provider.alarm"));
43 + }
44 +
45 + @Override
46 + public void triggerProbe(final DeviceId deviceId) {
47 +
48 + // TODO in shout term should this just be synchronous and return result?
49 + LOG.info("Run a SNMP discovery for device at {} when done invoke on AlarmProviderService", deviceId);
50 +
51 + // TODO Look up AlarmProviderService
52 + // TODO Decide threading
53 + // TODO Decide shouldn't it be generic not alarm-specific ? Its user responsible for passing in OID list ?
54 + // Same for its callack AlarmProviderService ?
55 + }
56 +
57 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Provider that uses SNMP as a means of discovering alarms on devices.
19 + */
20 +package org.onosproject.provider.snmp.alarm.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-providers</artifactId>
25 + <version>1.4.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-snmp-providers</artifactId>
30 + <packaging>pom</packaging>
31 +
32 + <description>ONOS SNMP Protocol Adapters</description>
33 +
34 + <modules>
35 + <module>alarm</module>
36 + </modules>
37 +
38 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +#
2 +# devices which may have faults.
3 +# TODO change to NetworkConfig subsystem.
4 +#
5 +fmDevices = 172.27.7.110,172.27.7.110,3.3.3.3
6 +