[ONOS-4164] Failed path info store

Change-Id: I8e16493ce479d2489b16fc76b56f55455927cb56
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
index 8276f3d..9b90da0 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
@@ -17,6 +17,8 @@
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import com.google.common.collect.ImmutableSet;
+
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -30,15 +32,19 @@
 
 import org.onlab.util.KryoNamespace;
 import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.resource.label.LabelResource;
 import org.onosproject.incubator.net.resource.label.LabelResourceId;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.intent.Constraint;
 import org.onosproject.net.Link;
 import org.onosproject.net.resource.ResourceConsumer;
 import org.onosproject.pce.pceservice.TunnelConsumerId;
+import org.onosproject.pce.pceservice.LspType;
 import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
 import org.onosproject.pce.pcestore.api.PceStore;
 import org.onosproject.store.serializers.KryoNamespaces;
 import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.DistributedSet;
 import org.onosproject.store.service.Serializer;
 import org.onosproject.store.service.StorageService;
 
@@ -53,11 +59,15 @@
 public class DistributedPceStore implements PceStore {
 
     private static final String DEVICE_ID_NULL = "Device ID cannot be null";
+    private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null";
+    private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
+    private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null";
+    private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null";
     private static final String LINK_NULL = "LINK cannot be null";
-    private static final String TUNNEL_ID_NULL = "Tunnel ID cannot be null";
-    private static final String LABEL_RESOURCE_ID_NULL = "Label Resource ID cannot be null";
+    private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null";
+    private static final String PATH_INFO_NULL = "Path Info cannot be null";
     private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
-    private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label info cannot be null";
+    private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
     private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
 
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -74,6 +84,9 @@
     // Mapping tunnel with device local info with tunnel consumer id
     private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
 
+    // List of Failed path info
+    private DistributedSet<PcePathInfo> failedPathSet;
+
     @Activate
     protected void activate() {
         globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
@@ -91,6 +104,7 @@
                         new KryoNamespace.Builder()
                                 .register(KryoNamespaces.API)
                                 .register(Link.class,
+                                          LabelResource.class,
                                           LabelResourceId.class)
                                 .build()))
                 .build();
@@ -108,6 +122,22 @@
                                 .build()))
                 .build();
 
+        failedPathSet = storageService.<PcePathInfo>setBuilder()
+                .withName("failed-path-info")
+                .withSerializer(Serializer.using(
+                        new KryoNamespace.Builder()
+                                .register(KryoNamespaces.API)
+                                .register(PcePathInfo.class,
+                                          //TODO: Instead of Constraint.class need to add actual implemented class
+                                          //TODO: on this interface like CostConstraint.class and
+                                          //TODO: BandwidthConstraint.class. Will be added once it is confirmed.
+                                          Constraint.class,
+                                          LspType.class)
+                                .build()))
+
+                .build()
+                .asDistributedSet();
+
         log.info("Started");
     }
 
@@ -135,6 +165,12 @@
     }
 
     @Override
+    public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
+        checkNotNull(failedPathInfo, PATH_INFO_NULL);
+        return failedPathSet.contains(failedPathInfo);
+    }
+
+    @Override
     public int getGlobalNodeLabelCount() {
         return globalNodeLabelMap.size();
     }
@@ -150,6 +186,11 @@
     }
 
     @Override
+    public int getFailedPathInfoCount() {
+        return failedPathSet.size();
+    }
+
+    @Override
     public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
        return globalNodeLabelMap.entrySet().stream()
                  .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
@@ -168,6 +209,11 @@
     }
 
     @Override
+    public Iterable<PcePathInfo> getFailedPathInfos() {
+       return ImmutableSet.copyOf(failedPathSet);
+    }
+
+    @Override
     public LabelResourceId getGlobalNodeLabel(DeviceId id) {
         checkNotNull(id, DEVICE_ID_NULL);
         return globalNodeLabelMap.get(id).value();
@@ -210,6 +256,12 @@
     }
 
     @Override
+    public void addFailedPathInfo(PcePathInfo failedPathInfo) {
+        checkNotNull(failedPathInfo, PATH_INFO_NULL);
+        failedPathSet.add(failedPathInfo);
+    }
+
+    @Override
     public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
         checkNotNull(tunnelId, TUNNEL_ID_NULL);
         checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
@@ -275,4 +327,15 @@
         }
         return true;
     }
+
+    @Override
+    public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
+        checkNotNull(failedPathInfo, PATH_INFO_NULL);
+
+        if (!failedPathSet.remove(failedPathInfo)) {
+            log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
+            return false;
+        }
+        return true;
+    }
 }