From b731e2f1dd0972409b136aebc7b463dd72c9cfad Mon Sep 17 00:00:00 2001 From: CNlucius Date: Tue, 13 Sep 2016 11:40:12 +0800 Subject: ONOSFW-171 O/S-SFC-ONOS scenario documentation Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365 Signed-off-by: CNlucius --- .../src/onos/apps/faultmanagement/app/app.xml | 24 --- .../src/onos/apps/faultmanagement/app/features.xml | 25 --- .../src/onos/apps/faultmanagement/app/pom.xml | 46 ----- .../src/onos/apps/faultmanagement/fmmgr/pom.xml | 54 ----- .../faultmanagement/impl/AlarmsManager.java | 222 --------------------- .../faultmanagement/impl/package-info.java | 20 -- .../src/onos/apps/faultmanagement/fmweb/pom.xml | 141 ------------- .../faultmanagement/web/AlarmCodec.java | 101 ---------- .../faultmanagement/web/AlarmsWebResource.java | 148 -------------- .../faultmanagement/web/package-info.java | 20 -- .../fmweb/src/main/webapp/WEB-INF/web.xml | 42 ---- .../faultmanagement/web/AlarmCodecContext.java | 73 ------- .../faultmanagement/web/AlarmCodecTest.java | 140 ------------- .../faultmanagement/web/AlarmJsonMatcher.java | 135 ------------- .../faultmanagement/web/AlarmsWebResourceTest.java | 72 ------- .../faultmanagement/web/alarm-full.json | 15 -- .../faultmanagement/web/alarm-minimal.json | 12 -- framework/src/onos/apps/faultmanagement/pom.xml | 56 ------ 18 files changed, 1346 deletions(-) delete mode 100644 framework/src/onos/apps/faultmanagement/app/app.xml delete mode 100644 framework/src/onos/apps/faultmanagement/app/features.xml delete mode 100644 framework/src/onos/apps/faultmanagement/app/pom.xml delete mode 100644 framework/src/onos/apps/faultmanagement/fmmgr/pom.xml delete mode 100644 framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/AlarmsManager.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/package-info.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/pom.xml delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmCodec.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/package-info.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/main/webapp/WEB-INF/web.xml delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecContext.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecTest.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmJsonMatcher.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmsWebResourceTest.java delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-full.json delete mode 100644 framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-minimal.json delete mode 100644 framework/src/onos/apps/faultmanagement/pom.xml (limited to 'framework/src/onos/apps/faultmanagement') diff --git a/framework/src/onos/apps/faultmanagement/app/app.xml b/framework/src/onos/apps/faultmanagement/app/app.xml deleted file mode 100644 index 288ccc49..00000000 --- a/framework/src/onos/apps/faultmanagement/app/app.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - ${project.description} - - mvn:${project.groupId}/onos-app-fm-mgr/${project.version} - mvn:${project.groupId}/onos-app-fm-web/${project.version} - diff --git a/framework/src/onos/apps/faultmanagement/app/features.xml b/framework/src/onos/apps/faultmanagement/app/features.xml deleted file mode 100644 index 86aab911..00000000 --- a/framework/src/onos/apps/faultmanagement/app/features.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - onos-api - onos-drivers - mvn:${project.groupId}/onos-app-fm-mgr/${project.version} - mvn:${project.groupId}/onos-app-fm-web/${project.version} - - diff --git a/framework/src/onos/apps/faultmanagement/app/pom.xml b/framework/src/onos/apps/faultmanagement/app/pom.xml deleted file mode 100644 index c446c0ae..00000000 --- a/framework/src/onos/apps/faultmanagement/app/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - 4.0.0 - - - org.onosproject - onos-app-fm - 1.4.0-rc1 - ../pom.xml - - - onos-app-fm-onosfw - pom - - ONOS framework applications - - - - org.onosproject - onos-app-fm-web - ${project.version} - - - org.onosproject - onos-app-fm-mgr - ${project.version} - - - - diff --git a/framework/src/onos/apps/faultmanagement/fmmgr/pom.xml b/framework/src/onos/apps/faultmanagement/fmmgr/pom.xml deleted file mode 100644 index a6bb3103..00000000 --- a/framework/src/onos/apps/faultmanagement/fmmgr/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - org.onosproject - onos-app-fm - 1.4.0-rc1 - ../pom.xml - - - onos-app-fm-mgr - bundle - - - - javax.ws.rs - jsr311-api - 1.1.1 - - - org.onosproject - onos-incubator-api - - - org.onosproject - onos-core-serializers - ${project.version} - - - org.osgi - org.osgi.compendium - 5.0.0 - jar - - - diff --git a/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/AlarmsManager.java b/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/AlarmsManager.java deleted file mode 100644 index 74fe7072..00000000 --- a/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/AlarmsManager.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.impl; - -import static com.google.common.base.Strings.isNullOrEmpty; -import java.util.Dictionary; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Modified; -import org.apache.felix.scr.annotations.Property; -import static org.onlab.util.Tools.nullIsNotFound; - -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmListener; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; -import org.apache.felix.scr.annotations.Service; -import static org.onlab.util.Tools.get; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.IdGenerator; -import org.onosproject.core.CoreService; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.util.ItemNotFoundException; -import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; -import org.osgi.service.component.ComponentContext; - -/** - * Implementation of the Alarm service. - */ -@Component(immediate = true) -@Service -public class AlarmsManager implements AlarmService { - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - private final Logger log = getLogger(getClass()); - private ApplicationId appId; - private IdGenerator idGenerator; - - - @Property(name = "fmDevices", value = "127.0.0.1", label = "Instance-specific configurations") - private String devConfigs; - - private final Map alarms = new ConcurrentHashMap<>(); - - - private final AtomicLong alarmIdGenerator = new AtomicLong(0); - - @Override - public Alarm update(final Alarm replacement) { - - final Alarm found = alarms.get(replacement.id()); - if (found == null) { - throw new ItemNotFoundException("Alarm with id " + replacement.id() + " found"); - } - final Alarm updated = new DefaultAlarm.Builder(found). - withAcknowledged(replacement.acknowledged()). - withAssignedUser(replacement.assignedUser()).build(); - alarms.put(replacement.id(), updated); - return updated; - } - - @Override - public int getActiveAlarmCount(final DeviceId deviceId) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - private static final String NOT_SUPPORTED_YET = "Not supported yet."; - - @Override - public Alarm getAlarm(final AlarmId alarmId) { - return nullIsNotFound( - alarms.get(alarmId), - "Alarm is not found"); - } - - @Override - public Set getAlarms() { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - @Override - public Set getActiveAlarms() { - // Enpty set if no values - return alarms.isEmpty() ? new HashSet<>() : new HashSet<>(alarms.values()); - - } - - private static DefaultAlarm generateFake(final DeviceId deviceId, final AlarmId alarmId) { - - return new DefaultAlarm.Builder( - alarmId, deviceId, "NE is not reachable", Alarm.SeverityLevel.MAJOR, System.currentTimeMillis()). - withTimeUpdated(System.currentTimeMillis()). - withServiceAffecting(true) - .withAcknowledged(true). - withManuallyClearable(true) - .withAssignedUser("user1").build(); - } - - @Override - public Set getAlarms(final Alarm.SeverityLevel severity) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - @Override - public Set getAlarms(final DeviceId deviceId) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - @Override - public Set getAlarms(final DeviceId deviceId, final AlarmEntityId source) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - @Override - public Set getAlarmsForLink(final ConnectPoint src, final ConnectPoint dst) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - @Override - public Set getAlarmsForFlow(final DeviceId deviceId, final long flowId) { - //TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - - private void discoverAlarmsForDevice(final DeviceId deviceId) { - final AlarmId alarmId = new AlarmId(alarmIdGenerator.incrementAndGet()); - - // TODO In a new thread invoke SNMP Provider with DeviceId and device type and when done update our of alarms - // - alarms.put(alarmId, generateFake(deviceId, alarmId)); - - } - - private class InternalAlarmListener implements AlarmListener { - - @Override - public void event(final AlarmEvent event) { - // TODO - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); - } - } - - @Activate - public void activate(final ComponentContext context) { - log.info("Activate ..."); - appId = coreService.registerApplication("org.onos.faultmanagement.alarms"); - idGenerator = coreService.getIdGenerator("alarm-ids"); - log.info("Started with appId={} idGenerator={}", appId, idGenerator); - - final boolean result = modified(context); - log.info("modified result = {}", result); - - } - - @Deactivate - public void deactivate(final ComponentContext context) { - log.info("Deactivate ..."); - // cfgService.unregisterProperties(getClass(), false); - - log.info("Stopped"); - } - - @Modified - public boolean modified(final ComponentContext context) { - log.info("context={}", context); - if (context == null) { - log.info("No configuration file"); - return false; - } - final Dictionary properties = context.getProperties(); - final String ipaddresses = get(properties, "fmDevices"); - log.info("Settings: devConfigs={}", ipaddresses); - if (!isNullOrEmpty(ipaddresses)) { - discover(ipaddresses); - - } - return true; - } - - private void discover(final String ipaddresses) { - for (String deviceEntry : ipaddresses.split(",")) { - final DeviceId deviceId = DeviceId.deviceId(deviceEntry); - if (deviceId != null) { - log.info("Device {} needs to have its alarms refreshed!", deviceId); - discoverAlarmsForDevice(deviceId); - } - } - } - -} diff --git a/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/package-info.java b/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/package-info.java deleted file mode 100644 index a3f56459..00000000 --- a/framework/src/onos/apps/faultmanagement/fmmgr/src/main/java/org/onosproject/faultmanagement/impl/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Fault Management application implementation. - */ -package org.onosproject.faultmanagement.impl; diff --git a/framework/src/onos/apps/faultmanagement/fmweb/pom.xml b/framework/src/onos/apps/faultmanagement/fmweb/pom.xml deleted file mode 100644 index edaa9d3c..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/pom.xml +++ /dev/null @@ -1,141 +0,0 @@ - - - - 4.0.0 - - org.onosproject - onos-app-fm - 1.4.0-rc1 - ../pom.xml - - - - onos-app-fm-web - bundle - - /onos/v1/fm - 1.0.0 - ONOS Fault Management Application REST API - - APIs for interacting with the Fault Management application. - - org.onos.faultmanagement.web - - - - - javax.ws.rs - jsr311-api - 1.1.1 - - - org.onosproject - onos-incubator-api - ${project.version} - jar - - - org.onosproject - onlab-osgi - ${project.version} - tests - test - - - com.sun.jersey - jersey-client - 1.19 - test - jar - - - org.onosproject - onos-core-common - ${project.version} - test - jar - - - org.onosproject - onos-rest - ${project.version} - test - jar - - - - org.onosproject - onos-rest - ${project.version} - tests - test - - - - com.sun.jersey.jersey-test-framework - jersey-test-framework-core - 1.19 - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - <_wab>src/main/webapp/ - - WEB-INF/classes/apidoc/swagger.json=target/swagger.json, - {maven-resources} - - - ${project.groupId}.${project.artifactId} - - - org.slf4j, - org.osgi.framework, - javax.ws.rs, - javax.ws.rs.core, - com.sun.jersey.api.core, - com.sun.jersey.spi.container.servlet, - com.sun.jersey.server.impl.container.servlet, - com.fasterxml.jackson.databind, - com.fasterxml.jackson.databind.node, - com.fasterxml.jackson.core, - org.apache.karaf.shell.commands, - org.apache.commons.lang.math.*, - com.google.common.*, - org.onlab.packet.*, - org.onlab.rest.*, - org.onosproject.*, - org.onlab.util.*, - org.jboss.netty.util.* - - ${web.context} - - - - - - - diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmCodec.java b/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmCodec.java deleted file mode 100644 index a764c908..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmCodec.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import com.fasterxml.jackson.databind.JsonNode; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; -import org.onosproject.net.DeviceId; -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; -import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; -import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Implementation of encoder for Alarm codec. - */ -public final class AlarmCodec extends JsonCodec { - - private final Logger log = getLogger(getClass()); - - @Override - public ObjectNode encode(final Alarm alarm, final CodecContext context) { - checkNotNull(alarm, "Alarm cannot be null"); - - return context.mapper().createObjectNode() - .put("id", alarm.id().fingerprint()) - .put("deviceId", alarm.deviceId().toString()) - .put("description", alarm.description()) - .put("source", - alarm.source() == null ? null - : alarm.source().toString()) - .put("timeRaised", alarm.timeRaised()) - .put("timeUpdated", alarm.timeUpdated()) - .put("timeCleared", alarm.timeCleared()) - .put("severity", alarm.severity().toString()) - .put("serviceAffecting", alarm.serviceAffecting()) - .put("acknowledged", alarm.acknowledged()) - .put("manuallyClearable", alarm.manuallyClearable()) - .put("assignedUser", alarm.assignedUser()); - - } - - @Override - public Alarm decode(final ObjectNode json, final CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - log.debug("id={}, full json={} ", json.get("id"), json); - final Long id = json.get("id").asLong(); - - final DeviceId deviceId = DeviceId.deviceId(json.get("deviceId").asText()); - final String description = json.get("description").asText(); - final Long timeRaised = json.get("timeRaised").asLong(); - final Long timeUpdated = json.get("timeUpdated").asLong(); - - final JsonNode jsonTimeCleared = json.get("timeCleared"); - final Long timeCleared = jsonTimeCleared == null || jsonTimeCleared.isNull() ? null : jsonTimeCleared.asLong(); - - final Alarm.SeverityLevel severity - = Alarm.SeverityLevel.valueOf(json.get("severity").asText().toUpperCase()); - - final Boolean serviceAffecting = json.get("serviceAffecting").asBoolean(); - final Boolean acknowledged = json.get("acknowledged").asBoolean(); - final Boolean manuallyClearable = json.get("manuallyClearable").asBoolean(); - - final JsonNode jsonAssignedUser = json.get("assignedUser"); - final String assignedUser - = jsonAssignedUser == null || jsonAssignedUser.isNull() ? null : jsonAssignedUser.asText(); - - return new DefaultAlarm.Builder( - AlarmId.valueOf(id), deviceId, description, severity, timeRaised).forSource(AlarmEntityId.NONE). - withTimeUpdated(timeUpdated). - withTimeCleared(timeCleared). - withServiceAffecting(serviceAffecting). - withAcknowledged(acknowledged). - withManuallyClearable(manuallyClearable). - withAssignedUser(assignedUser). - build(); - - } -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java b/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java deleted file mode 100644 index 56c891cd..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import java.io.IOException; -import java.io.InputStream; -import org.onosproject.rest.AbstractWebResource; - -import javax.ws.rs.core.Response; -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import org.onosproject.codec.CodecService; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; -import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Alarms on devices or ONOS. - */ -@Path("alarms") -public class AlarmsWebResource extends AbstractWebResource { - - public static final String ALARM_NOT_FOUND = "Alarm is not found"; - - private final Logger log = getLogger(getClass()); - - public AlarmsWebResource() { - get(CodecService.class).registerCodec(Alarm.class, new AlarmCodec()); - } - - /** - * Get all alarms. Returns a list of all alarms across all devices. - * - * @param includeCleared include recently cleared alarms in response - * @return JSON encoded set of alarms - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response getAlarms(@DefaultValue("false") @QueryParam("includeCleared") final boolean includeCleared - ) { - - log.info("Requesting all alarms, includeCleared={}", includeCleared); - final AlarmService service = get(AlarmService.class); - - final Iterable alarms = includeCleared - ? service.getAlarms() - : service.getActiveAlarms(); - - final ObjectNode result = new ObjectMapper().createObjectNode(); - result.set("alarms", - codec(Alarm.class). - encode(alarms, this)); - return ok(result.toString()).build(); - - } - - /** - * Get specified alarm. Returns details of the specified alarm. - * - * @param id ONOS allocated identifier - * @return JSON encoded alarm - */ - @GET - @Path("{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response getAlarm(@PathParam("id") final String id) { - log.info("HTTP GET alarm for id={}", id); - - final AlarmId alarmId = toAlarmId(id); - final Alarm alarm = get(AlarmService.class).getAlarm(alarmId); - - final ObjectNode result = mapper().createObjectNode(); - result.set("alarm", codec(Alarm.class).encode(alarm, this)); - return ok(result.toString()).build(); - } - - /** - * Update book-keeping fields on the alarm. Returns an up-to-date version of the alarm. Some of its fields may have - * been updated since the REST client last retrieved the alarm being updated. - * - * @param alarmIdPath - * @param stream input JSON - * @return updated JSON encoded alarm - */ - @PUT - @Path("{alarm_id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response update(@PathParam("alarm_id") final String alarmIdPath, final InputStream stream) { - log.info("PUT NEW ALARM at /{}", alarmIdPath); - - try { - final ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - log.info("jsonTree={}", jsonTree); - - final Alarm alarm = codec(Alarm.class).decode(jsonTree, this); - - final AlarmService service = get(AlarmService.class); - - if (Long.parseLong(alarmIdPath) != alarm.id().fingerprint()) { - throw new IllegalArgumentException("id in path is " + Long.parseLong(alarmIdPath) - + " but payload uses id=" + alarm.id().fingerprint()); - - } - final Alarm updated = service.update(alarm); - final ObjectNode encoded = new AlarmCodec().encode(updated, this); - return ok(encoded.toString()).build(); - - } catch (IOException ioe) { - throw new IllegalArgumentException(ioe); - } - } - - private static AlarmId toAlarmId(final String id) { - try { - return AlarmId.valueOf(Long.parseLong(id)); - } catch (NumberFormatException ex) { - throw new IllegalArgumentException("Alarm id should be numeric", ex); - } - - } - -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/package-info.java b/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/package-info.java deleted file mode 100644 index 9c291231..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Fault management web support. - */ -package org.onosproject.faultmanagement.web; diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/faultmanagement/fmweb/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 18671f01..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - FM2 REST API v1.0 - - - JAX-RS Service - com.sun.jersey.spi.container.servlet.ServletContainer - - com.sun.jersey.config.property.resourceConfigClass - com.sun.jersey.api.core.ClassNamesResourceConfig - - - com.sun.jersey.config.property.classnames - - org.onosproject.faultmanagement.web.AlarmsWebResource - - 10 - - - - JAX-RS Service - /* - - diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecContext.java b/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecContext.java deleted file mode 100644 index 89886e8a..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecContext.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; - - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; - -/** - * Mock codec context for use in codec unit tests. - */ -public class AlarmCodecContext implements CodecContext { - - private final ObjectMapper mapper = new ObjectMapper(); - private final Map, JsonCodec> codecs = new ConcurrentHashMap<>(); - - /** - * Constructs a new mock codec context. - */ - public AlarmCodecContext() { - codecs.clear(); - registerCodec(Alarm.class, new AlarmCodec()); - - } - - @Override - public ObjectMapper mapper() { - return mapper; - } - - @SuppressWarnings("unchecked") - @Override - public T getService(Class serviceClass) { - // TODO - return null; - } - - /** - * Registers the specified JSON codec for the given entity class. - * - * @param entityClass entity class - * @param codec JSON codec - * @param entity type - */ - public void registerCodec(Class entityClass, JsonCodec codec) { - codecs.putIfAbsent(entityClass, codec); - } - - @SuppressWarnings("unchecked") - @Override - public JsonCodec codec(Class entityClass) { - return codecs.get(entityClass); - } -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecTest.java b/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecTest.java deleted file mode 100644 index 3009b99a..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmCodecTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import java.io.IOException; -import java.io.InputStream; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; - -import org.junit.Test; -import org.onosproject.codec.JsonCodec; -import static org.onosproject.faultmanagement.web.AlarmJsonMatcher.matchesAlarm; -import org.onosproject.net.DeviceId; -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEntityId; -import org.onosproject.incubator.net.faultmanagement.alarm.AlarmId; -import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; - -public class AlarmCodecTest { - - private final AlarmCodecContext context = new AlarmCodecContext(); - - // Use this to check handling for miminal Alarm - private final Alarm alarmMinimumFields = new DefaultAlarm.Builder( - new AlarmId(44), - DeviceId.deviceId("of:2222000000000000"), - "NE unreachable", - Alarm.SeverityLevel.CLEARED, - 1). - build(); - - // Use this to check handling for fully populated Alarm - private final Alarm alarmWithSource = new DefaultAlarm.Builder( - new AlarmId(44), - DeviceId.deviceId("of:2222000000000000"), - "NE unreachable", - Alarm.SeverityLevel.CLEARED, 1). - forSource(AlarmEntityId.alarmEntityId("port:1/2/3/4")). - withTimeUpdated(2). - withTimeCleared(3L). - withServiceAffecting(true). - withAcknowledged(true). - withManuallyClearable(true). - withAssignedUser("the assigned user").build(); - - @Test - public void alarmCodecTestWithOptionalFieldMissing() { - //context.registerService(AlarmService.class, new AlarmServiceAdapter()); - final JsonCodec codec = context.codec(Alarm.class); - assertThat(codec, is(notNullValue())); - - final ObjectNode alarmJson = codec.encode(alarmMinimumFields, context); - assertThat(alarmJson, notNullValue()); - assertThat(alarmJson, matchesAlarm(alarmMinimumFields)); - - } - - @Test - public void alarmCodecTestWithOptionalField() { - final JsonCodec codec = context.codec(Alarm.class); - assertThat(codec, is(notNullValue())); - - final ObjectNode alarmJson = codec.encode(alarmWithSource, context); - assertThat(alarmJson, notNullValue()); - assertThat(alarmJson, matchesAlarm(alarmWithSource)); - - } - - @Test - public void verifyMinimalAlarmIsEncoded() throws Exception { - final JsonCodec alarmCodec = context.codec(Alarm.class); - - final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-minimal.json"); - assertCommon(alarm); - - assertThat(alarm.timeCleared(), nullValue()); - assertThat(alarm.assignedUser(), nullValue()); - - } - - @Test - public void verifyFullyLoadedAlarmIsEncoded() throws Exception { - final JsonCodec alarmCodec = context.codec(Alarm.class); - - final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-full.json"); - assertCommon(alarm); - - assertThat(alarm.timeCleared(), is(2222L)); - assertThat(alarm.assignedUser(), is("foo")); - - } - - private void assertCommon(final Alarm alarm) { - assertThat(alarm.id(), is(new AlarmId(10L))); - assertThat(alarm.description(), is("NE is not reachable")); - assertThat(alarm.source(), is(AlarmEntityId.NONE)); - assertThat(alarm.timeRaised(), is(999L)); - assertThat(alarm.timeUpdated(), is(1111L)); - assertThat(alarm.severity(), is(Alarm.SeverityLevel.MAJOR)); - assertThat(alarm.serviceAffecting(), is(true)); - assertThat(alarm.acknowledged(), is(false)); - assertThat(alarm.manuallyClearable(), is(true)); - } - - /** - * Reads in a rule from the given resource and decodes it. - * - * @param resourceName resource to use to read the JSON for the rule - * @return decoded flow rule - * @throws IOException if processing the resource failsdecode - */ - private Alarm getDecodedAlarm(final JsonCodec codec, final String resourceName) throws IOException { - final InputStream jsonStream = AlarmCodecTest.class - .getResourceAsStream(resourceName); - final JsonNode json = context.mapper().readTree(jsonStream); - assertThat(json, notNullValue()); - final Alarm result = codec.decode((ObjectNode) json, context); - assertThat(result, notNullValue()); - return result; - } - - -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmJsonMatcher.java b/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmJsonMatcher.java deleted file mode 100644 index 14bb45f3..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmJsonMatcher.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeDiagnosingMatcher; -import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; - -import com.fasterxml.jackson.databind.JsonNode; - -/** - * Hamcrest matcher for alarms. - */ -public final class AlarmJsonMatcher extends TypeSafeDiagnosingMatcher { - - private final Alarm alarm; - - private AlarmJsonMatcher(final Alarm alarm) { - this.alarm = alarm; - } - - @Override - public boolean matchesSafely(final JsonNode jsonAlarm, final Description description) { - final String jsonAlarmId = jsonAlarm.get("id").asText(); - final String alarmId = Long.toString(alarm.id().fingerprint()); - if (!jsonAlarmId.equals(alarmId)) { - description.appendText("alarm id was " + jsonAlarmId); - return false; - } - - final String jsonDeviceId = jsonAlarm.get("deviceId").asText(); - final String alarmDeviceId = alarm.deviceId().toString(); - if (!jsonDeviceId.equals(alarmDeviceId)) { - description.appendText("DeviceId was " + jsonDeviceId); - return false; - } - - - final String jsonDescription = jsonAlarm.get("description").asText(); - final String alarmDesc = alarm.description(); - if (!jsonDescription.equals(alarmDesc)) { - description.appendText("description was " + jsonDescription); - return false; - } - - final long jsonTimeRaised = jsonAlarm.get("timeRaised").asLong(); - final long timeRaised = alarm.timeRaised(); - if (timeRaised != jsonTimeRaised) { - description.appendText("timeRaised was " + jsonTimeRaised); - return false; - } - - - final long jsonTimeUpdated = jsonAlarm.get("timeUpdated").asLong(); - final long timeUpdated = alarm.timeUpdated(); - if (timeUpdated != jsonTimeUpdated) { - description.appendText("timeUpdated was " + jsonTimeUpdated); - return false; - } - - final JsonNode jsonTimeClearedNode = jsonAlarm.get("timeCleared"); - - if (alarm.timeCleared() != null) { - final Long jsonTimeCleared = jsonTimeClearedNode.longValue(); - final Long timeCleared = alarm.timeCleared(); - - if (!timeCleared.equals(jsonTimeCleared)) { - description.appendText("Time Cleared was " + jsonTimeCleared); - return false; - } - } else { - // No clear time not specified, JSON representation must be empty - if (!jsonTimeClearedNode.isNull()) { - description.appendText("Time Cleared should be null"); - return false; - } - } - - final String jsonSeverity = jsonAlarm.get("severity").asText(); - final String severity = alarm.severity().toString(); - if (!severity.equals(jsonSeverity)) { - description.appendText("severity was " + jsonSeverity); - return false; - } - - final JsonNode jsonAlarmNode = jsonAlarm.get("source"); - - if (alarm.source() != null) { - final String jsonSource = jsonAlarmNode.textValue(); - final String source = alarm.source().toString(); - - if (!source.equals(jsonSource)) { - description.appendText("source was " + jsonSource); - return false; - } - } else { - // source not specified, JSON representation must be empty - if (!jsonAlarmNode.isNull()) { - description.appendText("source should be null"); - return false; - } - } - - // In progress - return true; - } - - @Override - public void describeTo(final Description description) { - description.appendText(alarm.toString()); - } - - /** - * Factory to allocate a alarm matcher. - * - * @param alarm alarm object we are looking for - * @return matcher - */ - public static AlarmJsonMatcher matchesAlarm(final Alarm alarm) { - return new AlarmJsonMatcher(alarm); - } -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmsWebResourceTest.java b/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmsWebResourceTest.java deleted file mode 100644 index 0b7d9811..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/java/org/onosproject/faultmanagement/web/AlarmsWebResourceTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.faultmanagement.web; - -import com.sun.jersey.api.client.WebResource; -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import org.junit.Ignore; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.osgi.TestServiceDirectory; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecService; -import org.onosproject.codec.impl.CodecManager; -import org.onosproject.rest.ResourceTest; - -/** - * Test of the Fault Management Web REST API for Alarms. - */ -public class AlarmsWebResourceTest extends ResourceTest { - - @Before - public void setUp() { - - final CodecManager codecService = new CodecManager(); - codecService.activate(); - - final ServiceDirectory testDirectory - = new TestServiceDirectory() - // Currently no alarms-service implemented - // .add(AlarmsService.class, alarmsService) - .add(CodecService.class, codecService); - BaseResource.setServiceDirectory(testDirectory); - } - - @Test - @Ignore - public void getAllAlarms() { - final WebResource rs = resource(); - final String response = rs.path("/alarms").get(String.class); - // Ensure hard-coded alarms returned okay - assertThat(response, containsString("\"NE is not reachable\",")); - assertThat(response, containsString("\"Equipment Missing\",")); - } - - @Test - @Ignore - public void getAlarm() { - final WebResource rs = resource(); - final String response = rs.path("/alarms/1").get(String.class); - // Ensure hard-coded alarms returned okay - assertThat(response, containsString("\"NE is not reachable\",")); - assertThat(response, not(containsString("\"Equipment Missing\","))); - } - -} diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-full.json b/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-full.json deleted file mode 100644 index 215fc938..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-full.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "id": 10, - "deviceId": "of:123", - "description": "NE is not reachable", - "source": "none:none", - "timeRaised": 999, - "timeUpdated": 1111, - "timeUpdated": 1111, - "timeCleared": 2222, - "severity": "MAJOR", - "serviceAffecting": true, - "acknowledged": false, - "manuallyClearable": true, - "assignedUser": "foo" -} \ No newline at end of file diff --git a/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-minimal.json b/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-minimal.json deleted file mode 100644 index 4a24db09..00000000 --- a/framework/src/onos/apps/faultmanagement/fmweb/src/test/resources/org/onosproject/faultmanagement/web/alarm-minimal.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": 10, - "deviceId": "of:123", - "description": "NE is not reachable", - "source": "none:none", - "timeRaised": 999, - "timeUpdated": 1111, - "severity": "MAJOR", - "serviceAffecting": true, - "acknowledged": false, - "manuallyClearable": true -} \ No newline at end of file diff --git a/framework/src/onos/apps/faultmanagement/pom.xml b/framework/src/onos/apps/faultmanagement/pom.xml deleted file mode 100644 index 3ea3bc81..00000000 --- a/framework/src/onos/apps/faultmanagement/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - 4.0.0 - - - org.onosproject - onos-apps - 1.4.0-rc1 - ../pom.xml - - - onos-app-fm - pom - - ONOS framework applications - - - fmmgr - fmweb - app - - - - org.onosproject - onlab-junit - test - - - com.google.guava - guava-testlib - test - - - org.easymock - easymock - test - - - -- cgit 1.2.3-korg