ONOS-6245:Intent_mini_summary
Change-Id: I35fe2b5b3f2a24680bbef93ee31e4655b972ff45
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
index 570d696..2251ff2 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
@@ -77,6 +77,7 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
+import org.onosproject.net.intent.util.IntentMiniSummary;
import org.onosproject.net.key.DeviceKey;
import org.onosproject.net.mcast.McastRoute;
import org.onosproject.net.meter.Band;
@@ -122,6 +123,7 @@
registerCodec(Host.class, new HostCodec());
registerCodec(HostLocation.class, new HostLocationCodec());
registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
+ registerCodec(IntentMiniSummary.class, new IntentMiniSummaryCodec());
registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
registerCodec(SinglePointToMultiPointIntent.class, new SinglePointToMultiPointIntentCodec());
registerCodec(Intent.class, new IntentCodec());
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/IntentMiniSummaryCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/IntentMiniSummaryCodec.java
new file mode 100644
index 0000000..aeca1e2
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/IntentMiniSummaryCodec.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.codec.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.intent.util.IntentMiniSummary;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Intent MiniSummary JSON codec.
+ */
+public class IntentMiniSummaryCodec extends JsonCodec<IntentMiniSummary> {
+ private static final String TOTAL = "total";
+ private static final String INSTALLREQ = "installReq";
+ private static final String COMPILING = "compiling";
+ private static final String INSTALLING = "installing";
+ private static final String INSTALLED = "installed";
+ private static final String RECOMPILING = "recompiling";
+ private static final String WITHDRAWREQ = "withdrawReq";
+ private static final String WITHDRAWING = "withdrawing";
+ private static final String WITHDRAWN = "withdrawn";
+ private static final String FAILED = "failed";
+ private static final String UNKNOWNSTATE = "unknownState";
+
+ @Override
+ public ObjectNode encode(IntentMiniSummary intentminisummary, CodecContext context) {
+ checkNotNull(intentminisummary, "intentminisummary cannot be null");
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode result = mapper.createObjectNode()
+ .put(TOTAL, intentminisummary.getTotal())
+ .put(INSTALLED, intentminisummary.getInstalled())
+ .put(FAILED, intentminisummary.getFailed())
+ .put(INSTALLREQ, intentminisummary.getInstallReq())
+ .put(INSTALLING, intentminisummary.getInstalling())
+ .put(COMPILING, intentminisummary.getCompiling())
+ .put(RECOMPILING, intentminisummary.getRecompiling())
+ .put(WITHDRAWREQ, intentminisummary.getWithdrawReq())
+ .put(WITHDRAWING, intentminisummary.getWithdrawing())
+ .put(WITHDRAWN, intentminisummary.getWithdrawn())
+ .put(UNKNOWNSTATE, intentminisummary.getUnknownState());
+ return result;
+ }
+}