+.NERDTreeBookmarksFile
*.class
*.swp
**/target
~~~
{
"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"],
{
"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": {
<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>
<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>
--- /dev/null
+/*
+ * 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);
+ }
+ }
+ }
+ }
+ }
+}
prefix "yang-ext";
}
+ import "ietf-yang-types" {
+ prefix "ietf-types";
+ }
+
import "ietf-inet-types" {
prefix "ietf-inet";
}
"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)";
+ }
+ }
+ }
}
}
}
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();
}
@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;
- }
}
+++ /dev/null
-/*
- * 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>> {
- }
-}
*/
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;
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) {
}
}
@Override
public void close() throws Exception {
LOG.info("AltoModelBaseProvider Closed");
+
+ if (m_serviceReg != null) {
+ m_serviceReg.close();
+ }
+
+ try {
+ removeContextTag();
+ } catch (Exception e) {
+ }
}
@Override
--- /dev/null
+/*
+ * 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();
+ }
+}
}
}
- 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" {
}
}
- 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" {
}
}
- 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 {
}
}
- 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";
}
}
- 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 {
}
- 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 {
}
}
- 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 {
prefix "ietf-inet";
}
+ import "yang-ext" {
+ prefix "yang-ext";
+ }
+
organization "Yale University";
contact "alto-dev@lists.opendaylight.org";
}
}
- 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;
+ }
}
}
}
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;
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;
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) {
}
}
@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) {
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();
}
*/
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;
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;
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) {
}
}
@Override
public void close() throws Exception {
LOG.info("AltoModelBaseProvider Closed");
+
+ if (m_serviceReg != null) {
+ m_serviceReg.close();
+ }
+
+ try {
+ removeContextTag();
+ } catch (Exception e) {
+ }
}
@Override