import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupConditionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
* NULL
*/
public static void register(DataBroker dataProvider,
- RpcProviderRegistry rpcRegistry, ScheduledExecutorService executor,
+ RpcProviderRegistry rpcRegistry,
EpRendererAugmentation epRendererAugmentation) {
- if (dataProvider == null || rpcRegistry == null || executor == null) {
+ if (dataProvider == null || rpcRegistry == null) {
if (epRendererAugmentation != null) {
- LOG.warn("Couldn't register class {} for endpoint RPC because of missing required info");
+ LOG.warn("Couldn't register class {} for endpoint RPC because of missing required info", epRendererAugmentation);
}
return;
}
if (endpointRpcRegistry == null) {
synchronized (EndpointRpcRegistry.class) {
if (endpointRpcRegistry == null) {
+ ScheduledExecutorService executor = Executors
+ .newScheduledThreadPool(Math
+ .max(Runtime.getRuntime()
+ .availableProcessors() * 3, 10));
endpointRpcRegistry = new EndpointRpcRegistry(dataProvider,
rpcRegistry, executor);
}
if (registeredRenderers.isEmpty()
&& endpointRpcRegistry != null) {
endpointRpcRegistry.rpcRegistration.close();
+ endpointRpcRegistry.executor.shutdown();
endpointRpcRegistry = null;
}
}
}
}
+ public static Class<?> getAugmentationContextType(
+ final Augmentation<?> augmentation) {
+ if (augmentation == null) {
+ return null;
+ }
+ final Class<?>[] augmentationInterfaces = augmentation.getClass()
+ .getInterfaces();
+ if (augmentationInterfaces.length == 1) {
+ return augmentationInterfaces[0];
+ }
+ /*
+ * if here, then the way YANG tools generate augmentation code has
+ * changed, hence augmentation classes are not implemented by single
+ * interface anymore. This is very unlikely to happen, but if it did, we
+ * need to know about it in order to update this method.
+ */
+ LOG.error(
+ "YANG Generated Code has Changed -- augmentation object {} is NOT implemented by one interface anymore",
+ augmentation);
+ return null;
+ }
+
/**
* Constructor
*
for (Entry<String, EpRendererAugmentation> entry : registeredRenderers
.entrySet()) {
try {
- entry.getValue().buildEndpointAugmentation(eb, input);
+ Augmentation<Endpoint> augmentation = entry.getValue()
+ .buildEndpointAugmentation(input);
+ if (augmentation != null) {
+ @SuppressWarnings("unchecked")
+ Class<? extends Augmentation<Endpoint>> augmentationType = (Class<? extends Augmentation<Endpoint>>) getAugmentationContextType(augmentation);
+ eb.addAugmentation(augmentationType, augmentation);
+ }
} catch (Throwable t) {
LOG.warn("Endpoint Augmentation error while processing "
+ entry.getKey() + ". Reason: ", t);
for (Entry<String, EpRendererAugmentation> entry : registeredRenderers
.entrySet()) {
try {
- entry.getValue().buildEndpointL3Augmentation(eb, input);
+ Augmentation<EndpointL3> augmentation = entry.getValue()
+ .buildEndpointL3Augmentation(input);
+ if (augmentation != null) {
+ @SuppressWarnings("unchecked")
+ Class<? extends Augmentation<EndpointL3>> augmentationType = (Class<? extends Augmentation<EndpointL3>>) getAugmentationContextType(augmentation);
+ eb.addAugmentation(augmentationType, augmentation);
+ }
} catch (Throwable t) {
LOG.warn("L3 endpoint Augmentation error while processing "
+ entry.getKey() + ". Reason: ", t);
/*
- * Copyright (c) 2014 Huawei Technologies and others. All rights reserved.
+ * Copyright (c) 2015 Huawei Technologies 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,
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
public interface EpRendererAugmentation {
- void buildEndpointAugmentation(EndpointBuilder eb,
- RegisterEndpointInput input);
+ Augmentation<Endpoint> buildEndpointAugmentation(RegisterEndpointInput input);
- void buildEndpointL3Augmentation(EndpointL3Builder eb,
- RegisterEndpointInput input);
+ Augmentation<EndpointL3> buildEndpointL3Augmentation(RegisterEndpointInput input);
void buildL3PrefixEndpointAugmentation(EndpointL3PrefixBuilder eb,
RegisterL3PrefixEndpointInput input);
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig.LearningMode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
SwitchManager switchManager) {
this.executor = executor;
this.dataProvider = dataProvider;
- EndpointRpcRegistry.register(dataProvider, rpcRegistry, executor, endpointRpcAug);
+ EndpointRpcRegistry.register(dataProvider, rpcRegistry, endpointRpcAug);
if (dataProvider != null) {
listenerReg = dataProvider
.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
private class OfEndpointAug implements EpRendererAugmentation {
@Override
- public void buildEndpointAugmentation(EndpointBuilder eb,
- RegisterEndpointInput input) {
- // In order to support both the port-name and the data-path
- // information, allow
+ public Augmentation<Endpoint> buildEndpointAugmentation(RegisterEndpointInput input) {
+ // In order to support both the port-name and the data-path information, allow
// an EP to register without the augmentations, and resolve later.
OfOverlayContextBuilder ictx = checkAugmentation(input);
if (ictx != null) {
- eb.addAugmentation(OfOverlayContext.class, ictx.build());
+ return ictx.build();
}
+ return null;
}
@Override
- public void buildEndpointL3Augmentation(EndpointL3Builder eb,
- RegisterEndpointInput input) {
+ public Augmentation<EndpointL3> buildEndpointL3Augmentation(RegisterEndpointInput input) {
+ return null;
}
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContextL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContextL3Builder;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
OpflexConnectionService connectionService, MitLib opflexLibrary) {
this.executor = executor;
this.dataProvider = dataProvider;
- EndpointRpcRegistry.register(dataProvider, rpcRegistry, executor, endpointRpcAug);
+ EndpointRpcRegistry.register(dataProvider, rpcRegistry, endpointRpcAug);
if (dataProvider != null) {
listenerReg = dataProvider.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, endpointsIid, this,
private class OfEndpointAug implements EpRendererAugmentation {
@Override
- public void buildEndpointAugmentation(EndpointBuilder eb, RegisterEndpointInput input) {
+ public Augmentation<Endpoint> buildEndpointAugmentation(RegisterEndpointInput input) {
OpflexOverlayContextInput ictx = input.getAugmentation(OpflexOverlayContextInput.class);
- eb.addAugmentation(OpflexOverlayContext.class, new OpflexOverlayContextBuilder(ictx).build());
+ if (ictx != null)
+ return new OpflexOverlayContextBuilder(ictx).build();
+ return null;
}
@Override
- public void buildEndpointL3Augmentation(EndpointL3Builder eb, RegisterEndpointInput input) {
+ public Augmentation<EndpointL3> buildEndpointL3Augmentation(RegisterEndpointInput input) {
OpflexOverlayContextInput ictx = input.getAugmentation(OpflexOverlayContextInput.class);
- eb.addAugmentation(OpflexOverlayContextL3.class, new OpflexOverlayContextL3Builder(ictx).build());
+ if (ictx != null)
+ return new OpflexOverlayContextL3Builder(ictx).build();
+ return null;
}
@Override