Redefine the resourcepool to provide context 24/30324/2
authorKai GAO <gaok12@mails.tsinghua.edu.cn>
Tue, 24 Nov 2015 12:16:27 +0000 (20:16 +0800)
committerKai GAO <gaok12@mails.tsinghua.edu.cn>
Mon, 30 Nov 2015 03:01:06 +0000 (11:01 +0800)
Patch set 2: fix checkstyle

Change-Id: Ibdd86fa9864e98eb2ef47e22d8ebb4d06193d7f4
Signed-off-by: Kai GAO <gaok12@mails.tsinghua.edu.cn>
13 files changed:
.gitignore
README.md
alto-core/resourcepool/api/pom.xml
alto-core/resourcepool/api/src/main/java/org/opendaylight/alto/core/resourcepool/ResourcepoolUtils.java [new file with mode: 0644]
alto-core/resourcepool/api/src/main/yang/alto-resourcepool.yang
alto-core/resourcepool/impl/src/main/java/org/opendaylight/alto/core/resourcepool/impl/AltoResourcepoolProvider.java
alto-core/resourcepool/impl/src/main/java/org/opendaylight/alto/core/resourcepool/impl/AltoResourcepoolServiceHelper.java [deleted file]
alto-core/standard-service-models/model-base/impl/src/main/java/org/opendaylight/alto/core/impl/AltoModelBaseProvider.java
alto-core/standard-service-models/model-endpointcost/api/src/main/java/org/opendaylight/alto/core/service/model/endpointcost/EndpointcostUtils.java [new file with mode: 0644]
alto-core/standard-service-models/model-endpointcost/api/src/main/yang/alto-model-endpointcost-rfc7285.yang
alto-core/standard-service-models/model-endpointcost/api/src/main/yang/alto-model-endpointcost.yang
alto-core/standard-service-models/model-endpointcost/impl/src/main/java/org/opendaylight/alto/core/impl/endpointcost/test/AltoEndpointCostProvider.java
alto-core/standard-service-models/model-networkmap/impl/src/main/java/org/opendaylight/alto/core/impl/networkmap/test/AltoNetworkmapProvider.java

index 8caa6d24b097af105566b4729dd7c221a5f9f6d0..178c8cf3db64575e2ecc495e98990c1fba27d70f 100644 (file)
@@ -1,3 +1,4 @@
+.NERDTreeBookmarksFile
 *.class
 *.swp
 **/target
index 566d61a9f85632457486fc917f61855190655858..7ec3255a9a0729d2f508983cc11a51aa2f8cf926 100644 (file)
--- a/README.md
+++ b/README.md
 ~~~
 {
     "input": {
-        "service-reference":"/alto-resourcepool:resource-pool/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-base']"
+        "service-reference":"/alto-resourcepool:context[alto-resourcepool:context-id='00000000-0000-0000-0000-000000000000']/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-base']/alto-resourcepool:context-tag[alto-resourcepool:tag='NEED TO CHECK THE RESOURCEPOOL']"
     }
 }
 
 
 {
     "input": {
-        "service-reference":"/alto-resourcepool:resource-pool/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-networkmap']",
+        "service-reference":"/alto-resourcepool:context[alto-resourcepool:context-id='00000000-0000-0000-0000-000000000000']/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-networkmap']/alto-resourcepool:context-tag[alto-resourcepool:tag='NEED TO CHECK THE RESOURCEPOOL']",
         "type":"alto-model-networkmap:resource-type-networkmap",
         "networkmap-filter": {
             "pid": ["PID1", "PID2", "PID3"],
@@ -34,7 +34,7 @@
 
 {
     "input": {
-        "service-reference":"/alto-resourcepool:resource-pool/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-endpointcost']",
+        "service-reference":"/alto-resourcepool:context[alto-resourcepool:context-id='00000000-0000-0000-0000-000000000000']/alto-resourcepool:resource[alto-resourcepool:resource-id='test-model-endpointcost']/alto-resourcepool:context-tag[alto-resourcepool:tag='NEED TO CHECK THE RESOURCEPOOL']",
         "type":"alto-model-endpointcost:resource-type-endpointcost",
         "endpointcost-params": {
             "cost-type": {
index 66509f41416e1ca345396095b214c897c19710d6..835ec5c4556664cde509d368f9eaba63004b318c 100644 (file)
@@ -20,6 +20,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <version>0.2.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
+  <properties>
+    <sal-binding-api.version>1.3.0-SNAPSHOT</sal-binding-api.version>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.opendaylight.alto.core</groupId>
@@ -36,5 +40,22 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.mdsal.model</groupId>
       <artifactId>ietf-inet-types-2013-07-15</artifactId>
     </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>ietf-yang-types-20130715</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.mdsal</groupId>
+      <artifactId>mdsal-common-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+      <version>${sal-binding-api.version}</version>
+    </dependency>
+
   </dependencies>
 </project>
diff --git a/alto-core/resourcepool/api/src/main/java/org/opendaylight/alto/core/resourcepool/ResourcepoolUtils.java b/alto-core/resourcepool/api/src/main/java/org/opendaylight/alto/core/resourcepool/ResourcepoolUtils.java
new file mode 100644 (file)
index 0000000..a096584
--- /dev/null
@@ -0,0 +1,304 @@
+/*
+ * Copyright (c) 2015 Yale University and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.alto.core.resourcepool;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import com.google.common.base.Optional;
+
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourceType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ServiceContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ContextKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.Resource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.ResourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.ResourceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.CapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.ContextTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.ContextTagBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.ContextTagKey;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.Tag;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+public class ResourcepoolUtils {
+
+    public static final String DEFAULT_CONTEXT = "00000000-0000-0000-0000-000000000000";
+
+    public static InstanceIdentifier<Context> getDefaultContextIID() {
+        return getContextIID(DEFAULT_CONTEXT);
+    }
+
+    public static InstanceIdentifier<Context> getContextIID(String cid) {
+        Uuid _cid = new Uuid(cid);
+        return getContextIID(_cid);
+    }
+
+    public static InstanceIdentifier<Context> getContextIID(Uuid cid) {
+        ContextKey key = new ContextKey(cid);
+        return getContextIID(key);
+    }
+
+    public static InstanceIdentifier<Context> getContextIID(ContextKey key) {
+        return InstanceIdentifier.builder(Context.class, key).build();
+    }
+
+    public static InstanceIdentifier<Resource> getResourceIID(String cid, String rid) {
+        Uuid _cid = new Uuid(cid);
+        ResourceId _rid = new ResourceId(rid);
+
+        return getResourceIID(_cid, _rid);
+    }
+
+    public static InstanceIdentifier<Resource> getResourceIID(String cid, ResourceId rid) {
+        Uuid _cid = new Uuid(cid);
+        return getResourceIID(_cid, rid);
+    }
+
+    public static InstanceIdentifier<Resource> getResourceIID(Uuid cid, String rid) {
+        ResourceId _rid = new ResourceId(rid);
+        return getResourceIID(cid, _rid);
+    }
+
+    public static InstanceIdentifier<Resource> getResourceIID(Uuid cid, ResourceId rid) {
+        ContextKey contextKey = new ContextKey(cid);
+        ResourceKey resourceKey = new ResourceKey(rid);
+
+        return InstanceIdentifier.builder(Context.class, contextKey)
+                                    .child(Resource.class, resourceKey).build();
+    }
+
+    public static InstanceIdentifier<ContextTag> getContextTagIID(String cid, String rid, String tag) {
+        Uuid _cid = new Uuid(cid);
+        ResourceId _rid = new ResourceId(rid);
+        Tag _tag = new Tag(tag);
+
+        return getContextTagIID(_cid, _rid, _tag);
+    }
+
+    public static InstanceIdentifier<ContextTag> getContextTagIID(Uuid cid, ResourceId rid, Tag tag) {
+        ContextKey contextKey = new ContextKey(cid);
+        ResourceKey resourceKey = new ResourceKey(rid);
+        ContextTagKey contextTagKey = new ContextTagKey(tag);
+
+        return InstanceIdentifier.builder(Context.class, contextKey)
+                                    .child(Resource.class, resourceKey)
+                                    .child(ContextTag.class, contextTagKey).build();
+    }
+
+    public static boolean contextExists(String cid, ReadTransaction rx)
+                            throws InterruptedException, ExecutionException {
+        return contextExists(new Uuid(cid), rx);
+    }
+
+    public static boolean contextExists(Uuid cid, ReadTransaction rx)
+                            throws InterruptedException, ExecutionException {
+        return contextExists(new ContextKey(cid), rx);
+    }
+
+    public static boolean contextExists(ContextKey key, ReadTransaction rx)
+                            throws InterruptedException, ExecutionException {
+        Optional<Context> context;
+        context = rx.read(LogicalDatastoreType.OPERATIONAL, getContextIID(key)).get();
+
+        return (context.isPresent());
+    }
+
+    public static void createContext(String cid, final WriteTransaction wx) {
+        createContext(new Uuid(cid), wx);
+    }
+
+    public static void createContext(Uuid cid, final WriteTransaction wx) {
+        ContextBuilder builder = new ContextBuilder();
+        builder.setContextId(cid);
+        builder.setResource(new LinkedList<Resource>());
+
+        /* DO NOT submit because this might be just one step in a sequence of write operations */
+        wx.put(LogicalDatastoreType.OPERATIONAL, getContextIID(cid), builder.build());
+    }
+
+    public static void deleteContext(String cid, final WriteTransaction wx) {
+        deleteContext(new Uuid(cid), wx);
+    }
+
+    public static void deleteContext(Uuid cid, final WriteTransaction wx) {
+        /* DO NOT submit because this might be just one step in a sequence of write operations */
+        wx.delete(LogicalDatastoreType.OPERATIONAL, getContextIID(cid));
+    }
+
+    public static boolean resourceExists(String cid, String rid, ReadTransaction rx)
+                            throws InterruptedException, ExecutionException {
+        return resourceExists(new Uuid(cid), new ResourceId(rid), rx);
+    }
+
+    public static boolean resourceExists(Uuid cid, ResourceId rid, ReadTransaction rx)
+                            throws InterruptedException, ExecutionException {
+        InstanceIdentifier<Resource> iid = getResourceIID(cid, rid);
+
+        Optional<Resource> resource;
+        resource = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get();
+
+        return (resource.isPresent());
+    }
+
+    public static void createResource(String cid, String rid,
+                                        Class<? extends ResourceType> type,
+                                        final WriteTransaction wx) {
+        Uuid _cid = new Uuid(cid);
+        ResourceId _rid = new ResourceId(rid);
+
+        createResource(_cid, _rid, type, wx);
+    }
+
+    public static void createResource(Uuid cid, ResourceId rid,
+                                        Class<? extends ResourceType> type,
+                                        final WriteTransaction wx) {
+        createResourceWithCapabilities(cid, rid, type, null, wx);
+    }
+
+    public static void createResourceWithCapabilities(String cid, String rid,
+                                                        Class<? extends ResourceType> type,
+                                                        Capabilities capabilities,
+                                                        final WriteTransaction wx) {
+        Uuid contextId = new Uuid(cid);
+        ResourceId resourceId = new ResourceId(rid);
+
+        createResourceWithCapabilities(contextId, resourceId, type, capabilities, wx);
+    }
+
+    public static void createResourceWithCapabilities(Uuid cid, ResourceId rid,
+                                                        Class<? extends ResourceType> type,
+                                                        Capabilities capabilities,
+                                                        final WriteTransaction wx) {
+        ResourceBuilder builder = new ResourceBuilder();
+        builder.setResourceId(rid);
+        builder.setType(type);
+        builder.setContextTag(new LinkedList<ContextTag>());
+        if (capabilities == null) {
+            capabilities = new CapabilitiesBuilder().build();
+        }
+        builder.setCapabilities(capabilities);
+
+        InstanceIdentifier<Resource> iid = getResourceIID(cid, rid);
+
+        /* DO NOT submit because this might be just one step in a sequence of write operations */
+        wx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build());
+    }
+
+    public static void deleteResource(String cid, String rid, final WriteTransaction wx) {
+        Uuid contextId = new Uuid(cid);
+        ResourceId resourceId = new ResourceId(rid);
+
+        deleteResource(contextId, resourceId, wx);
+    }
+
+    public static void deleteResource(Uuid cid, ResourceId rid, final WriteTransaction wx) {
+        InstanceIdentifier<Resource> iid = getResourceIID(cid, rid);
+
+        /* DO NOT submit because this might be just one step in a sequence of write operations */
+        wx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+    }
+
+    public static void updateResource(Uuid cid, ResourceId rid, Tag tag,
+                                        List<InstanceIdentifier<?>> dependencies,
+                                        final WriteTransaction wx) {
+        ContextTagBuilder ctBuilder = new ContextTagBuilder();
+        ctBuilder.setTag(tag);
+        /*
+         * Unfortunately the resources must handle the dependency resolving themselves
+         * */
+        if (dependencies == null) {
+            dependencies = new LinkedList<InstanceIdentifier<?>>();
+        }
+        ctBuilder.setDependency(dependencies);
+
+        ResourceBuilder rscBuilder = new ResourceBuilder();
+        rscBuilder.setResourceId(rid);
+        rscBuilder.setDefaultTag(tag);
+        rscBuilder.setContextTag(Arrays.asList(ctBuilder.build()));
+
+        InstanceIdentifier<Resource> iid = getResourceIID(cid, rid);
+
+        /* DO NOT submit because this might be just one step in a sequence of write operations */
+        wx.merge(LogicalDatastoreType.OPERATIONAL, iid, rscBuilder.build());
+    }
+
+    /*
+     * For those who don't have dependencies
+     * */
+    public static void lazyUpdateResource(String cid, String rid, final WriteTransaction wx) {
+        Uuid contextId = new Uuid(cid);
+        ResourceId resourceId = new ResourceId(rid);
+
+        lazyUpdateResource(contextId, resourceId, wx);
+    }
+
+    public static void lazyUpdateResource(Uuid cid, ResourceId rid, final WriteTransaction wx) {
+        String stripped = getUUID().replace("-", "");
+
+        updateResource(cid, rid, new Tag(stripped), null, wx);
+    }
+
+    public static String getUUID() {
+        return UUID.randomUUID().toString();
+    }
+
+    public static final class ContextTagListener implements DataChangeListener {
+
+        private RoutedRpcRegistration<? extends RpcService> m_registration = null;
+        private InstanceIdentifier<Resource> m_iid = null;
+
+        public ContextTagListener(InstanceIdentifier<Resource> resourceIID,
+                                    RoutedRpcRegistration<? extends RpcService> registration) {
+            m_iid = resourceIID;
+            m_registration = registration;
+        }
+
+        public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+            for (InstanceIdentifier<?> path: change.getRemovedPaths()) {
+                if (path.getTargetType().equals(ContextTag.class)) {
+                    if (m_iid.contains(path)) {
+                        // Only manage resource's own context tag
+                        m_registration.unregisterPath(ServiceContext.class, path);
+                    }
+                }
+            }
+
+            for (InstanceIdentifier<?> path: change.getCreatedData().keySet()) {
+                if (path.getTargetType().equals(ContextTag.class)) {
+                    if (m_iid.contains(path)) {
+                        // Only manage resource's own context tag
+                        m_registration.registerPath(ServiceContext.class, path);
+                    }
+                }
+            }
+        }
+    }
+}
index 454d89660bc8bf95bd480412fad201f15c70da10..8230e9b0913583380777fafefcaa5680290f197a 100644 (file)
@@ -13,6 +13,10 @@ module alto-resourcepool {
         prefix "yang-ext";
     }
 
+    import "ietf-yang-types" {
+        prefix "ietf-types";
+    }
+
     import "ietf-inet-types" {
         prefix "ietf-inet";
     }
@@ -35,110 +39,55 @@ module alto-resourcepool {
             "The basic type identity for ALTO resourcepool";
     }
 
-    identity "capability-category" {
-        description
-            "The basic identity for capability categories";
-    }
-
-    grouping "capability-spec" {
-        leaf "category" {
-            type identityref {
-                base "capability-category";
-            }
-        }
-
-        choice "spec" {
-        }
-    }
-
-    grouping "resource-desc" {
-        leaf "resource-id" {
-            type alto-types:resource-id;
-        }
-
-        leaf "local" {
-            type boolean;
-            default true;
-        }
+    list "context" {
+        config false;
 
-        leaf "uri" {
-            type ietf-inet:uri;
-        }
+        key "context-id";
 
-        leaf "type" {
-            type identityref {
-                base "resource-type";
-            }
+        leaf "context-id" {
+            type ietf-types:uuid;
+            default "00000000-0000-0000-0000-000000000000";
         }
 
-        list "capability" {
-            uses "capability-spec";
-        }
+        list "resource" {
+            key "resource-id";
 
-        list "dependency" {
             leaf "resource-id" {
                 type alto-types:resource-id;
             }
-        }
-    }
-
-    grouping "resource-service" {
-        leaf "service-instance" {
-            type instance-identifier;
-        }
-    }
-
-    container "resource-pool" {
-        config false;
-
-        list "resource" {
-            key "resource-id";
-
-            yang-ext:context-instance "service-context";
-
-            uses "resource-desc";
 
-            uses "resource-service";
-
-            leaf "refcount" {
-                type uint16;
+            leaf "type" {
+                type identityref {
+                    base "resource-type";
+                }
             }
 
-            leaf "tag" {
-                type alto-types:tag;
+            container "capabilities" {
             }
-        }
-    }
 
-    rpc "add-resource" {
-        input {
-            uses "resource-desc";
-
-            uses "resource-service";
-        }
-    }
-
-    rpc "remove-resource" {
-        input {
-            leaf "resource-id" {
-                type alto-types:resource-id;
+            leaf "default-tag" {
+                type leafref {
+                    path "../context-tag/tag";
+                }
             }
-        }
-    }
 
-    rpc "update-resource" {
-        input {
-            uses "resource-desc";
+            list "context-tag" {
+                key "tag";
 
-            uses "resource-service";
-        }
-    }
+                leaf "tag" {
+                    type alto-types:tag;
+                }
 
-    rpc "verify-resource" {
-        input {
-            uses "resource-desc";
+                yang-ext:context-instance "service-context";
 
-            uses "resource-service";
+                leaf-list "dependency" {
+                    type instance-identifier {
+                        require-instance true;
+                        description
+                            "Should point to a ../../../resource/context-tag instance (in the same context)";
+                    }
+                }
+            }
         }
     }
 }
index cf0b7704f40b7b77c62aadce0ca512087307d555..47d78732d65ef59a422fc5e78591512a0b807912 100644 (file)
 
 package org.opendaylight.alto.core.resourcepool.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.SettableFuture;
-//import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.CheckedFuture;
-
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import java.util.LinkedList;
-//import java.util.List;
-//import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-//import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 
-//import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AddResourceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AltoResourcepoolService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.CapabilitySpec;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.RemoveResourceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourceDesc;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePool;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePoolBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourceService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.UpdateResourceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.VerifyResourceInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.desc.Dependency;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceKey;
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
-
-//import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-//import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.opendaylight.alto.core.resourcepool.impl.AltoResourcepoolServiceHelper.ResourceCallback;
-
-public class AltoResourcepoolProvider implements BindingAwareProvider, AutoCloseable, AltoResourcepoolService {
+public class AltoResourcepoolProvider implements BindingAwareProvider, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(AltoResourcepoolProvider.class);
 
-    private InstanceIdentifier<ResourcePool> m_rpIID;
-
-    private DataBroker m_dataBrokerService = null;
-    // TODO private NotificationProviderService notificationService = null;
-
-    private RpcRegistration<AltoResourcepoolService> m_serviceReg = null;
+    private DataBroker m_dataBroker = null;
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
         LOG.info("AltoResourcesProvider Session Initiated");
 
-        m_dataBrokerService = session.getSALService(DataBroker.class);
-        m_serviceReg = session.addRpcImplementation(AltoResourcepoolService.class, this);
-        assert m_dataBrokerService != null;
-        assert m_serviceReg != null;
-
-        m_rpIID = InstanceIdentifier.builder(ResourcePool.class).build();
+        m_dataBroker = session.getSALService(DataBroker.class);
+        assert m_dataBroker != null;
 
         try {
-            createTopLevelContainers();
+            createDefaultContext();
         } catch (Exception e) {
             LOG.error("Failed to create top-level containers for ALTO services");
         }
     }
 
-    protected void createTopLevelContainers()
-            throws TransactionCommitFailedException, InterruptedException, ExecutionException {
-        WriteTransaction wx = m_dataBrokerService.newWriteOnlyTransaction();
-
-        ResourcePool rp;
+    protected void createDefaultContext()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-        rp = new ResourcePoolBuilder().setResource(new LinkedList<Resource>()).build();
-        wx.put(LogicalDatastoreType.OPERATIONAL, m_rpIID, rp);
+        ResourcepoolUtils.createContext(ResourcepoolUtils.DEFAULT_CONTEXT, wx);
 
         wx.submit().get();
-        // Only proceed if the top-level containers are created successfully
     }
 
-    protected void deleteTopLevelContainers() throws Exception {
-        WriteTransaction wx = m_dataBrokerService.newWriteOnlyTransaction();
+    protected void deleteDefaultContext() throws Exception {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-        wx.delete(LogicalDatastoreType.OPERATIONAL, m_rpIID);
+        ResourcepoolUtils.deleteContext(ResourcepoolUtils.DEFAULT_CONTEXT, wx);
 
         wx.submit().get();
     }
@@ -120,188 +63,10 @@ public class AltoResourcepoolProvider implements BindingAwareProvider, AutoClose
     @Override
     public void close() throws Exception {
         try {
-            deleteTopLevelContainers();
+            deleteDefaultContext();
         } catch (Exception e) {
             /* Exit anyway */
         }
-        if (m_serviceReg != null) {
-            m_serviceReg.close();
-        }
         LOG.info("AltoResourcesProvider Closed");
     }
-
-    protected InstanceIdentifier<Resource> getResourceIID(ResourceId rid) {
-        ResourceKey key = new ResourceKey(rid);
-        return InstanceIdentifier.builder(ResourcePool.class).child(Resource.class, key).build();
-    }
-
-    protected ListenableFuture<RpcResult<Void>> failWithError(String errorMessage) {
-        return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, errorMessage).buildFuture();
-    }
-
-    @Override
-    public Future<RpcResult<Void>> addResource(final AddResourceInput input) {
-        final ReadWriteTransaction rwx = m_dataBrokerService.newReadWriteTransaction();
-
-        final ResourceDesc desc = (ResourceDesc)input;
-        final ResourceService service = (ResourceService)input;
-        return rpcTemplate(rwx, desc, service, new ResourceCallback() {
-            @Override
-            public ListenableFuture<RpcResult<Void>> apply(Optional<Resource> resource) {
-                if (resource.isPresent()) {
-                    return failWithError("Adding resource failure: already exists");
-                }
-
-                InstanceIdentifier<Resource> rIID = getResourceIID(desc.getResourceId());
-
-                ResourceBuilder builder = new ResourceBuilder();
-                builder.fieldsFrom(desc);
-                builder.fieldsFrom(service);
-                builder.setRefcount(0);
-                /* TODO setTag() and dynamic tag generation */
-
-                rwx.put(LogicalDatastoreType.OPERATIONAL, rIID, builder.build());
-                CheckedFuture<Void, ? extends Exception> write = rwx.submit();
-
-                try {
-                    write.get();
-                    return RpcResultBuilder.<Void>success().buildFuture();
-                } catch (Exception e) {
-                    return failWithError("Failed to update data store: " + e.getMessage());
-                }
-            }
-        });
-    }
-
-    @Override
-    public Future<RpcResult<Void>> removeResource(RemoveResourceInput input) {
-        //TODO
-        return null;
-    }
-
-    @Override
-    public Future<RpcResult<Void>> updateResource(UpdateResourceInput input) {
-        //TODO
-        return null;
-    }
-
-    @Override
-    public Future<RpcResult<Void>> verifyResource(final VerifyResourceInput input) {
-        ReadTransaction rx = m_dataBrokerService.newReadOnlyTransaction();
-
-        ListenableFuture<String> message;
-        message = _verifyResource(rx, (ResourceDesc)input, (ResourceService)input);
-
-        Future<RpcResult<Void>> result;
-        result = Futures.transform(message, new AsyncFunction<String, RpcResult<Void>>() {
-            @Override
-            public ListenableFuture<RpcResult<Void>> apply(String errorMessage) {
-                if (errorMessage != null) {
-                    return failWithError("Verification failure: " + errorMessage);
-                }
-                return RpcResultBuilder.<Void>success().buildFuture();
-            }
-        });
-        return result;
-    }
-
-    protected ListenableFuture<RpcResult<Void>> rpcTemplate(final ReadTransaction rx,
-                                                    final ResourceDesc desc,
-                                                    final ResourceService service,
-                                                    final ResourceCallback callback) {
-        ListenableFuture<String> message;
-        message = _verifyResource(rx, desc, service);
-
-        ListenableFuture<RpcResult<Void>> result;
-        result = Futures.transform(message, new AsyncFunction<String, RpcResult<Void>>() {
-            @Override
-            public ListenableFuture<RpcResult<Void>> apply(String errorMessage) {
-                if (errorMessage != null) {
-                    return failWithError("Verification failure: " + errorMessage);
-                }
-
-                InstanceIdentifier<Resource> rIID = getResourceIID(desc.getResourceId());
-                ListenableFuture<Optional<Resource>> resource;
-                resource = rx.read(LogicalDatastoreType.OPERATIONAL, rIID);
-
-                return Futures.transform(resource, callback);
-            }
-        });
-        return result;
-    }
-
-    protected ListenableFuture<String> _verifyResource(ReadTransaction rx,
-                                                final ResourceDesc desc,
-                                                final ResourceService service) {
-        ListenableFuture<Optional<ResourcePool>> pool;
-        pool = rx.read(LogicalDatastoreType.OPERATIONAL, m_rpIID);
-
-        ListenableFuture<String> result;
-        result = Futures.transform(pool, new AsyncFunction<Optional<ResourcePool>, String>() {
-            @Override
-            public ListenableFuture<String> apply(Optional<ResourcePool> pool) {
-                String message = null;
-
-                if (!pool.isPresent()) {
-                    message = "Failed to read top-level container";
-                } else {
-                    ResourcePool rp = pool.get();
-                    message = __verifyResource(desc, service, rp);
-                }
-
-                SettableFuture<String> messageFuture = SettableFuture.<String>create();
-                messageFuture.set(message);
-                return messageFuture;
-            }
-        });
-        return result;
-    }
-
-    protected String __verifyResource(ResourceDesc desc, ResourceService service, ResourcePool rp) {
-        if ((desc == null) || (service == null)) {
-            return "Missing desc or service";
-        }
-
-        if (desc.getResourceId() == null) {
-            return "Resource Id must not be null";
-        }
-
-        /* If resource is local, the uri must be provided.  Otherwise the uri will be emitted. */
-        if (Boolean.FALSE.equals(desc.isLocal())) {
-            if ((desc.getUri() == null) || (desc.getUri().equals(""))) {
-                return "URI must be provided for remote resourcepool";
-            }
-        }
-
-        if (desc.getType() == null) {
-            return "Type must not be null";
-        }
-        //TODO validate the type
-
-        // TODO Use type validator to validate the capabilities
-        if (desc.getCapability() == null) {
-        }
-
-        if (desc.getCapability() != null) {
-            for (CapabilitySpec spec: desc.getCapability()) {
-                //TODO validate the capability spec
-            }
-        }
-
-        if (desc.getDependency() != null) {
-            Set<ResourceId> available = new HashSet<ResourceId>();
-
-            for (Resource resource: rp.getResource()) {
-                available.add(resource.getResourceId());
-            }
-
-            for (Dependency dependency: desc.getDependency()) {
-                ResourceId rid = dependency.getResourceId();
-                if (!available.contains(rid)) {
-                    return "Unresolved dependency: " + rid.getValue();
-                }
-            }
-        }
-        return null;
-    }
 }
diff --git a/alto-core/resourcepool/impl/src/main/java/org/opendaylight/alto/core/resourcepool/impl/AltoResourcepoolServiceHelper.java b/alto-core/resourcepool/impl/src/main/java/org/opendaylight/alto/core/resourcepool/impl/AltoResourcepoolServiceHelper.java
deleted file mode 100644 (file)
index 2c8fc55..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright Â© 2015 Yale University and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.alto.core.resourcepool.impl;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.AsyncFunction;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
-
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-class AltoResourcepoolServiceHelper {
-
-    public static interface VerificationCallback
-            extends AsyncFunction<String, RpcResult<Void>> {
-    }
-
-    public static interface ResourceCallback
-            extends AsyncFunction<Optional<Resource>, RpcResult<Void>> {
-    }
-}
index f270301b60185b81e2924eb5b565ef31ec7c1ccb..d5ae61e236c5e188843c8e606b8fef6ff0cef9df 100644 (file)
@@ -7,25 +7,27 @@
  */
 package org.opendaylight.alto.core.impl;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.util.concurrent.Future;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils.ContextTagListener;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AddResourceInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePool;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ServiceContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.Resource;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.AltoModelBaseService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.ResourceTypeError;
@@ -35,50 +37,68 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev15102
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.alto.response.error.response.ErrorResponseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.rev151021.alto.response.error.response.error.response.ErrorBuilder;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AltoResourcepoolService;
-
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 public class AltoModelBaseProvider implements BindingAwareProvider, AutoCloseable, AltoModelBaseService {
 
     private static final Logger LOG = LoggerFactory.getLogger(AltoModelBaseProvider.class);
 
-    private DataBroker m_dataBrokerService = null;
+    private DataBroker m_dataBroker = null;
     private RoutedRpcRegistration<AltoModelBaseService> m_serviceReg = null;
-    private AltoResourcepoolService m_resourcepoolService = null;
+    private ListenerRegistration<DataChangeListener> m_listener = null;
 
-    private static final ResourceId TEST_BASE_RID = new ResourceId("test-model-base");
+    private static final String TEST_BASE_NAME = "test-model-base";
+    private static final ResourceId TEST_BASE_RID = new ResourceId(TEST_BASE_NAME);
     private InstanceIdentifier<Resource> m_testIID = null;
 
-    protected InstanceIdentifier<Resource> getResourceIID(ResourceId rid) {
-        ResourceKey key = new ResourceKey(rid);
-        return InstanceIdentifier.builder(ResourcePool.class).child(Resource.class, key).build();
+    protected void createContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+        ResourcepoolUtils.createResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_BASE_NAME, ResourceTypeError.class, wx);
+
+        ResourcepoolUtils.lazyUpdateResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_BASE_NAME, wx);
+
+        wx.submit().get();
     }
 
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("AltoModelBaseProvider Session Initiated");
+    protected void removeContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-        m_dataBrokerService = session.getSALService(DataBroker.class);
-        m_serviceReg = session.addRoutedRpcImplementation(AltoModelBaseService.class, this);
+        ResourcepoolUtils.deleteResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_BASE_NAME, wx);
 
-        ResourceBuilder builder = new ResourceBuilder();
-        builder.setResourceId(TEST_BASE_RID).setType(ResourceTypeError.class);
+        wx.submit().get();
+    }
 
-        AddResourceInputBuilder inputBuilder = new AddResourceInputBuilder();
-        inputBuilder.fieldsFrom(builder.build());
+    protected void setupListener() {
+        ContextTagListener listener = new ContextTagListener(m_testIID, m_serviceReg);
+        m_listener = m_dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                                        m_testIID,listener, DataChangeScope.SUBTREE);
 
-        try {
-            AltoResourcepoolService resourcepool;
-            resourcepool = session.getRpcService(AltoResourcepoolService.class);
+        assert m_listener != null;
+    }
 
-            RpcResult<Void> result;
-            result = resourcepool.addResource(inputBuilder.build()).get();
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        LOG.info("AltoModelBaseProvider Session Initiated");
 
-            assert result.isSuccessful();
+        m_dataBroker = session.getSALService(DataBroker.class);
+        m_testIID = ResourcepoolUtils.getResourceIID(ResourcepoolUtils.DEFAULT_CONTEXT, TEST_BASE_NAME);
+        m_serviceReg = session.addRoutedRpcImplementation(AltoModelBaseService.class, this);
 
-            m_testIID = getResourceIID(TEST_BASE_RID);
-            m_serviceReg.registerPath(ServiceContext.class, m_testIID);
+        try {
+            setupListener();
+            createContextTag();
         } catch (Exception e) {
         }
     }
@@ -86,6 +106,15 @@ public class AltoModelBaseProvider implements BindingAwareProvider, AutoCloseabl
     @Override
     public void close() throws Exception {
         LOG.info("AltoModelBaseProvider Closed");
+
+        if (m_serviceReg != null) {
+            m_serviceReg.close();
+        }
+
+        try {
+            removeContextTag();
+        } catch (Exception e) {
+        }
     }
 
     @Override
diff --git a/alto-core/standard-service-models/model-endpointcost/api/src/main/java/org/opendaylight/alto/core/service/model/endpointcost/EndpointcostUtils.java b/alto-core/standard-service-models/model-endpointcost/api/src/main/java/org/opendaylight/alto/core/service/model/endpointcost/EndpointcostUtils.java
new file mode 100644 (file)
index 0000000..ce21a94
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright Â© 2015 Yale University and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.alto.core.service.model.endpointcost;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.CostMetric;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.context.resource.capabilities.CostType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.context.resource.capabilities.CostTypeBuilder;
+
+public class EndpointcostUtils {
+
+    public static CostType createCostTypeCapability(String metric, String mode) {
+        return createCostTypeCapability(new CostMetric(metric), mode);
+    }
+
+    public static CostType createCostTypeCapability(CostMetric metric, String mode) {
+        CostTypeBuilder builder = new CostTypeBuilder();
+        builder.setCostMetric(metric);
+        builder.setCostMode(mode);
+
+        return builder.build();
+    }
+}
index 12e4e19f10655037820c3857e6065e2d1b4fe3dc..641e780904b9049c4836e2a87aa99c3d1a349e8e 100644 (file)
@@ -42,7 +42,9 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request/alto-ecs:endpointcost-request/alto-ecs:endpointcost-params/alto-ecs:filter" {
+    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request"
+            + "/alto-ecs:endpointcost-request"
+            + "/alto-ecs:endpointcost-params/alto-ecs:filter" {
         ext:augment-identifier "rfc7285-endpoint-filter";
 
         case "endpoint-filter-data" {
@@ -71,7 +73,9 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response/alto-ecs:endpointcost-response/alto-ecs:endpointcost-data" {
+    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response"
+            + "/alto-ecs:endpointcost-response"
+            + "/alto-ecs:endpointcost-data" {
         ext:augment-identifier "rfc7285-endpoint-cost-map";
 
         case "endpoint-costmap-data" {
@@ -91,7 +95,11 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request/alto-ecs:endpointcost-request/alto-ecs:endpointcost-params/alto-ecs:filter/endpoint-filter-data/endpoint-filter/source/address" {
+    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request"
+            + "/alto-ecs:endpointcost-request"
+            + "/alto-ecs:endpointcost-params"
+            + "/alto-ecs:filter/endpoint-filter-data"
+            + "/endpoint-filter/source/address" {
         ext:augment-identifier "rfc7285-endpoint-filter-source";
 
         case ipv4 {
@@ -103,7 +111,11 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request/alto-ecs:endpointcost-request/alto-ecs:endpointcost-params/alto-ecs:filter/endpoint-filter-data/endpoint-filter/destination/address" {
+    augment "/alto-ecs:query/alto-ecs:input/alto-ecs:request"
+            + "/alto-ecs:endpointcost-request"
+            + "/alto-ecs:endpointcost-params"
+            + "/alto-ecs:filter/endpoint-filter-data"
+            + "/endpoint-filter/destination/address" {
         ext:augment-identifier "rfc7285-endpoint-filter-destination";
         case ipv4 {
             uses "ipv4-address-data";
@@ -114,7 +126,10 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response/alto-ecs:endpointcost-response/alto-ecs:endpointcost-data/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/source/address" {
+    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response"
+            + "/alto-ecs:endpointcost-response"
+            + "/alto-ecs:endpointcost-data"
+            + "/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/source/address" {
         ext:augment-identifier "rfc7285-endpoint-costmap-source";
 
         case ipv4 {
@@ -127,7 +142,10 @@ module alto-model-endpointcost-rfc7285 {
     }
 
 
-    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response/alto-ecs:endpointcost-response/alto-ecs:endpointcost-data/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/destination/address" {
+    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response"
+            + "/alto-ecs:endpointcost-response"
+            + "/alto-ecs:endpointcost-data"
+            + "/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/destination/address" {
         ext:augment-identifier "rfc7285-endpoint-costmap-destination";
 
         case ipv4 {
@@ -139,7 +157,10 @@ module alto-model-endpointcost-rfc7285 {
         }
     }
 
-    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response/alto-ecs:endpointcost-response/alto-ecs:endpointcost-data/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/cost" {
+    augment "/alto-ecs:query/alto-ecs:output/alto-ecs:response"
+            + "/alto-ecs:endpointcost-response"
+            + "/alto-ecs:endpointcost-data"
+            + "/endpoint-costmap-data/endpoint-cost-map/endpoint-cost/cost" {
         ext:augment-identifier "rfc7825-endpoint-costmap-cost";
 
         case numerical {
index 2171275d2f09507903fd11d874314d1d4e8dde16..e17e5111e70b5f31ce0bf79d838b3d7e90b24a36 100644 (file)
@@ -25,6 +25,10 @@ module alto-model-endpointcost {
         prefix "ietf-inet";
     }
 
+    import "yang-ext" {
+        prefix "yang-ext";
+    }
+
     organization "Yale University";
 
     contact "alto-dev@lists.opendaylight.org";
@@ -105,21 +109,21 @@ module alto-model-endpointcost {
         }
     }
 
-    augment "/alto-resourcepool:resource-pool/alto-resourcepool:resource/alto-resourcepool:capability/alto-resourcepool:spec/" {
-        case "cost-type-spec" {
-            uses "cost-type-data";
-        }
-    }
+    augment "/alto-resourcepool:context"
+            + "/alto-resourcepool:resource"
+            + "/alto-resourcepool:capabilities" {
+        yang-ext:augment-identifier "capabilities-cost-type";
 
-    augment "/alto-resourcepool:verify-resource/alto-resourcepool:input/alto-resourcepool:capability/alto-resourcepool:spec/" {
-        case "cost-type-spec" {
-            uses "cost-type-data";
-        }
-    }
+        list "cost-type" {
+            unique "cost-metric cost-mode";
 
-    augment "/alto-resourcepool:add-resource/alto-resourcepool:input/alto-resourcepool:capability/alto-resourcepool:spec/" {
-        case "cost-type-spec" {
-            uses "cost-type-data";
+            leaf "cost-metric" {
+                type alto-types:cost-metric;
+            }
+
+            leaf "cost-mode" {
+                type string;
+            }
         }
     }
 }
index 2fdc9d5263d7fce50f745b69b281e3af88b79a07..ed43b1beb5d2a2b9046aea2adb666993cb21a54f 100644 (file)
@@ -8,39 +8,45 @@
 package org.opendaylight.alto.core.impl.endpointcost.test;
 
 import java.math.BigDecimal;
-import java.util.concurrent.Future;
+import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AddResourceInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AltoResourcepoolService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePool;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ServiceContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.desc.Capability;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.desc.CapabilityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceKey;
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils.ContextTagListener;
+import org.opendaylight.alto.core.service.model.endpointcost.EndpointcostUtils;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.CostMetric;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.Resource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.CapabilitiesBuilder;
+
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.AltoModelEndpointcostService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.CapabilitiesCostType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.CapabilitiesCostTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.QueryInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.QueryOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.QueryOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.alto.request.endpointcost.request.EndpointcostRequest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.alto.response.endpointcost.response.EndpointcostResponseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.cost.type.data.CostType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.cost.type.data.CostTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.endpointcost.request.data.EndpointcostParams;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.verify.resource.input.capability.spec.CostTypeSpecBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.Ipv4AddressData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.Ipv6AddressData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.TypedAddressData;
@@ -52,14 +58,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpoint
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.endpointcostmap.response.data.endpoint.cost.map.endpoint.cost.DestinationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.endpointcostmap.response.data.endpoint.cost.map.endpoint.cost.SourceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.input.request.endpointcost.request.endpointcost.params.filter.EndpointFilterData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.EndpointCostmapDataBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.endpoint.costmap.data.endpoint.cost.map.endpoint.cost.cost.NumericalBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.endpoint.costmap.data.endpoint.cost.map.endpoint.cost.cost.OrdinalBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.EndpointCostmapDataBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.typed.address.data.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.alto.response.endpointcost.response.EndpointcostResponseBuilder;
 
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
@@ -70,57 +75,69 @@ public class AltoEndpointCostProvider implements BindingAwareProvider, AutoClose
 
     private static final Logger LOG = LoggerFactory.getLogger(AltoEndpointCostProvider.class);
 
-    private DataBroker m_dataBrokerService = null;
+    private DataBroker m_dataBroker = null;
     private RoutedRpcRegistration<AltoModelEndpointcostService> m_serviceReg = null;
-    private AltoResourcepoolService m_resourcepoolService = null;
+    private ListenerRegistration<DataChangeListener> m_listener = null;
 
-    private static final ResourceId TEST_ENDPOINTCOST_RID = new ResourceId("test-model-endpointcost");
+    private static final String TEST_ENDPOINTCOST_NAME = "test-model-endpointcost";
+    private static final ResourceId TEST_ENDPOINTCOST_RID = new ResourceId(TEST_ENDPOINTCOST_NAME);
     private static final CostMetric COST_METRIC_ROUTINGCOST = new CostMetric("routingcost");
+    private static final String COST_MODE_ORDINAL = "ordinal";
     private InstanceIdentifier<Resource> m_testIID = null;
 
-    protected InstanceIdentifier<Resource> getResourceIID(ResourceId rid) {
-        ResourceKey key = new ResourceKey(rid);
-        return InstanceIdentifier.builder(ResourcePool.class).child(Resource.class, key).build();
-    }
+    protected void createContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("AltoModelEndpointCostProvider Session Initiated");
+        CapabilitiesCostTypeBuilder cctBuilder = new CapabilitiesCostTypeBuilder();
+        cctBuilder.setCostType(Arrays.asList(
+                EndpointcostUtils.createCostTypeCapability(COST_METRIC_ROUTINGCOST,
+                                                            COST_MODE_ORDINAL)
+        ));
+        CapabilitiesBuilder builder = new CapabilitiesBuilder();
+        builder.addAugmentation(CapabilitiesCostType.class, cctBuilder.build());
 
-        m_dataBrokerService = session.getSALService(DataBroker.class);
-        m_serviceReg = session.addRoutedRpcImplementation(AltoModelEndpointcostService.class, this);
+        ResourcepoolUtils.createResourceWithCapabilities(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_ENDPOINTCOST_NAME,
+                                            ResourceTypeEndpointcost.class,
+                                            builder.build(), wx);
 
-        CostTypeBuilder ctBuilder = new CostTypeBuilder();
-        ctBuilder.setCostMetric(COST_METRIC_ROUTINGCOST);
-        ctBuilder.setCostMode("ordinal");
+        ResourcepoolUtils.lazyUpdateResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_ENDPOINTCOST_NAME, wx);
 
-        CostTypeSpecBuilder ctsBuilder = new CostTypeSpecBuilder();
-        ctsBuilder.setCostType(ctBuilder.build());
+        wx.submit().get();
+    }
 
-        CapabilityBuilder capBuilder = new CapabilityBuilder();
-        capBuilder.setSpec(ctsBuilder.build());
+    protected void removeContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-        LinkedList<Capability> capabilityList = new LinkedList<Capability>();
-        capabilityList.add(capBuilder.build());
+        ResourcepoolUtils.deleteResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_ENDPOINTCOST_NAME, wx);
 
-        ResourceBuilder builder = new ResourceBuilder();
-        builder.setResourceId(TEST_ENDPOINTCOST_RID).setType(ResourceTypeEndpointcost.class);
-        builder.setCapability(capabilityList);
+        wx.submit().get();
+    }
 
-        AddResourceInputBuilder inputBuilder = new AddResourceInputBuilder();
-        inputBuilder.fieldsFrom(builder.build());
+    protected void setupListener() {
+        ContextTagListener listener = new ContextTagListener(m_testIID, m_serviceReg);
+        m_listener = m_dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                                        m_testIID,listener, DataChangeScope.SUBTREE);
 
-        try {
-            AltoResourcepoolService resourcepool;
-            resourcepool = session.getRpcService(AltoResourcepoolService.class);
+        assert m_listener != null;
+    }
 
-            RpcResult<Void> result;
-            result = resourcepool.addResource(inputBuilder.build()).get();
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        LOG.info("AltoModelEndpointCostProvider Session Initiated");
 
-            assert result.isSuccessful();
+        m_dataBroker = session.getSALService(DataBroker.class);
+        m_testIID = ResourcepoolUtils.getResourceIID(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                                        TEST_ENDPOINTCOST_NAME);
+        m_serviceReg = session.addRoutedRpcImplementation(AltoModelEndpointcostService.class, this);
 
-            m_testIID = getResourceIID(TEST_ENDPOINTCOST_RID);
-            m_serviceReg.registerPath(ServiceContext.class, m_testIID);
+        try {
+            setupListener();
+            createContextTag();
         } catch (Exception e) {
         }
     }
@@ -128,6 +145,15 @@ public class AltoEndpointCostProvider implements BindingAwareProvider, AutoClose
     @Override
     public void close() throws Exception {
         LOG.info("AltoModelBaseProvider Closed");
+
+        if (m_serviceReg != null) {
+            m_serviceReg.close();
+        }
+
+        try {
+            removeContextTag();
+        } catch (Exception e) {
+        }
     }
 
     protected Cost createNumericalCost(double cost) {
@@ -189,7 +215,7 @@ public class AltoEndpointCostProvider implements BindingAwareProvider, AutoClose
         EndpointcostParams params = request.getEndpointcostParams();
 
         CostType costType = params.getCostType();
-        if (!costType.getCostMode().equals("ordinal")) {
+        if (!costType.getCostMode().equals(COST_MODE_ORDINAL)) {
             LOG.warn(costType.getCostMode().toString());
             return RpcResultBuilder.<QueryOutput>failed().buildFuture();
         }
index 442f17f5108931d75379a24ef57af016eb22c6d6..1e6ed8af774a0c28ea8ff7f3bbaea3f990ea851e 100644 (file)
@@ -7,30 +7,34 @@
  */
 package org.opendaylight.alto.core.impl.networkmap.test;
 
-import java.util.concurrent.Future;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
+import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils.ContextTagListener;
+
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AddResourceInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.AltoResourcepoolService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ResourcePool;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.ServiceContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.Resource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.resource.pool.ResourceKey;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.PidName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.ResourceId;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.Resource;
+
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeIpv6;
@@ -50,8 +54,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv6PrefixList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv6PrefixListBuilder;
 
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
@@ -62,42 +66,56 @@ public class AltoNetworkmapProvider implements BindingAwareProvider, AutoCloseab
 
     private static final Logger LOG = LoggerFactory.getLogger(AltoNetworkmapProvider.class);
 
-    private DataBroker m_dataBrokerService = null;
+    private DataBroker m_dataBroker = null;
     private RoutedRpcRegistration<AltoModelNetworkmapService> m_serviceReg = null;
-    private AltoResourcepoolService m_resourcepoolService = null;
+    private ListenerRegistration<DataChangeListener> m_listener = null;
 
-    private static final ResourceId TEST_NETWORKMAP_RID = new ResourceId("test-model-networkmap");
+    private static final String TEST_NETWORKMAP_NAME = "test-model-networkmap";
+    private static final ResourceId TEST_NETWORKMAP_RID = new ResourceId(TEST_NETWORKMAP_NAME);
     private InstanceIdentifier<Resource> m_testIID = null;
 
-    protected InstanceIdentifier<Resource> getResourceIID(ResourceId rid) {
-        ResourceKey key = new ResourceKey(rid);
-        return InstanceIdentifier.builder(ResourcePool.class).child(Resource.class, key).build();
+    protected void createContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+        ResourcepoolUtils.createResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_NETWORKMAP_NAME,
+                                            ResourceTypeNetworkmap.class, wx);
+
+        ResourcepoolUtils.lazyUpdateResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_NETWORKMAP_NAME, wx);
+
+        wx.submit().get();
     }
 
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("AltoModelNetworkProvider Session Initiated");
+    protected void removeContextTag()
+            throws InterruptedException, ExecutionException, TransactionCommitFailedException  {
+        WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
 
-        m_dataBrokerService = session.getSALService(DataBroker.class);
-        m_serviceReg = session.addRoutedRpcImplementation(AltoModelNetworkmapService.class, this);
+        ResourcepoolUtils.deleteResource(ResourcepoolUtils.DEFAULT_CONTEXT,
+                                            TEST_NETWORKMAP_NAME, wx);
 
-        ResourceBuilder builder = new ResourceBuilder();
-        builder.setResourceId(TEST_NETWORKMAP_RID).setType(ResourceTypeNetworkmap.class);
+        wx.submit().get();
+    }
 
-        AddResourceInputBuilder inputBuilder = new AddResourceInputBuilder();
-        inputBuilder.fieldsFrom(builder.build());
+    protected void setupListener() {
+        ContextTagListener listener = new ContextTagListener(m_testIID, m_serviceReg);
+        m_listener = m_dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                                        m_testIID,listener, DataChangeScope.SUBTREE);
 
-        try {
-            AltoResourcepoolService resourcepool;
-            resourcepool = session.getRpcService(AltoResourcepoolService.class);
+        assert m_listener != null;
+    }
 
-            RpcResult<Void> result;
-            result = resourcepool.addResource(inputBuilder.build()).get();
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        LOG.info("AltoModelNetworkProvider Session Initiated");
 
-            assert result.isSuccessful();
+        m_dataBroker = session.getSALService(DataBroker.class);
+        m_serviceReg = session.addRoutedRpcImplementation(AltoModelNetworkmapService.class, this);
+        m_testIID = ResourcepoolUtils.getResourceIID(ResourcepoolUtils.DEFAULT_CONTEXT, TEST_NETWORKMAP_NAME);
 
-            m_testIID = getResourceIID(TEST_NETWORKMAP_RID);
-            m_serviceReg.registerPath(ServiceContext.class, m_testIID);
+        try {
+            setupListener();
+            createContextTag();
         } catch (Exception e) {
         }
     }
@@ -105,6 +123,15 @@ public class AltoNetworkmapProvider implements BindingAwareProvider, AutoCloseab
     @Override
     public void close() throws Exception {
         LOG.info("AltoModelBaseProvider Closed");
+
+        if (m_serviceReg != null) {
+            m_serviceReg.close();
+        }
+
+        try {
+            removeContextTag();
+        } catch (Exception e) {
+        }
     }
 
     @Override