-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
package org.opendaylight.openflowplugin.impl.services.sal;
+import com.google.common.collect.EvictingQueue;
+import com.google.common.collect.Queues;
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.MoreExecutors;
-import java.util.concurrent.Future;
+import java.time.LocalDateTime;
+import java.util.Queue;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupCache;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerGroupService;
import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGroupService;
import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
+import org.opendaylight.openflowplugin.impl.util.PathUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final SingleLayerGroupService<RemoveGroupOutput> removeGroupMessage;
private final DeviceContext deviceContext;
+ private final FlowGroupCacheManager provider ;
+
+ public static final int FLOWGROUP_CACHE_SIZE = 10000;
public SalGroupServiceImpl(final RequestContextStack requestContextStack,
final DeviceContext deviceContext,
- final ConvertorExecutor convertorExecutor) {
+ final ConvertorExecutor convertorExecutor,
+ final FlowGroupCacheManager provider) {
this.deviceContext = deviceContext;
+ this.provider = provider;
addGroup = new MultiLayerGroupService<>(requestContextStack,
deviceContext,
AddGroupOutput.class,
}
@Override
- public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
+ public ListenableFuture<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
final ListenableFuture<RpcResult<AddGroupOutput>> resultFuture =
addGroupMessage.canUseSingleLayerSerialization()
? addGroupMessage.handleServiceCall(input)
: addGroup.handleServiceCall(input);
-
+ String nodeId = PathUtil.extractNodeId(input.getNode()).getValue();
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddGroupOutput>>() {
@Override
public void onSuccess(RpcResult<AddGroupOutput> result) {
if (result.isSuccessful()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Group add with id={} finished without error", input.getGroupId().getValue());
+ LOG.debug("adding group successful {}", input.getGroupId());
+ FlowGroupCache cache = new FlowGroupCache(input.getGroupId().toString(),
+ input.getGroupType().getName(), FlowGroupStatus.ADDED,
+ LocalDateTime.now());
+ if (provider.getAllNodesFlowGroupCache().containsKey(nodeId)) {
+ provider.getAllNodesFlowGroupCache().get(nodeId).add(cache);
+ } else {
+ Queue<FlowGroupCache> flowGroupCacheList =
+ Queues.synchronizedQueue(EvictingQueue.create(FLOWGROUP_CACHE_SIZE));
+ flowGroupCacheList.add(cache);
+ provider.getAllNodesFlowGroupCache().put(nodeId, flowGroupCacheList);
}
- deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Group add with id={} failed, errors={}", input.getGroupId().getValue(),
@Override
public void onFailure(Throwable throwable) {
- LOG.warn("Service call for adding group={} failed, reason: {}",
+ LOG.warn("Service call for adding group={} failed",
input.getGroupId().getValue(),
throwable);
}
@Override
- public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
+ public ListenableFuture<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
final ListenableFuture<RpcResult<UpdateGroupOutput>> resultFuture =
updateGroupMessage.canUseSingleLayerSerialization()
? updateGroupMessage.handleServiceCall(input.getUpdatedGroup())
@Override
public void onSuccess(RpcResult<UpdateGroupOutput> result) {
if (result.isSuccessful()) {
+ NodeId nodeId = PathUtil.extractNodeId(input.getNode());
+ FlowGroupCache cache = new FlowGroupCache(
+ input.getUpdatedGroup().getGroupId().getValue().toString(),
+ input.getUpdatedGroup().getGroupType().getName(), FlowGroupStatus.MODIFIED,
+ LocalDateTime.now());
+ if (provider.getAllNodesFlowGroupCache().containsKey(nodeId.getValue())) {
+ provider.getAllNodesFlowGroupCache().get(nodeId.getValue()).add(cache);
+ } else {
+ Queue<FlowGroupCache> flowGroupCacheList =
+ Queues.synchronizedQueue(EvictingQueue.create(FLOWGROUP_CACHE_SIZE));
+ flowGroupCacheList.add(cache);
+ provider.getAllNodesFlowGroupCache().put(nodeId.getValue(), flowGroupCacheList);
+ }
if (LOG.isDebugEnabled()) {
LOG.debug("Group update with original id={} finished without error",
input.getOriginalGroup().getGroupId().getValue());
@Override
public void onFailure(Throwable throwable) {
- LOG.warn("Service call for updating group={} failed, reason: {}",
+ LOG.warn("Service call for updating group={} failed",
input.getOriginalGroup().getGroupId(), throwable);
}
}, MoreExecutors.directExecutor());
}
@Override
- public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
+ public ListenableFuture<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
final ListenableFuture<RpcResult<RemoveGroupOutput>> resultFuture =
removeGroupMessage.canUseSingleLayerSerialization()
? removeGroupMessage.handleServiceCall(input)
public void onSuccess(RpcResult<RemoveGroupOutput> result) {
if (result.isSuccessful()) {
if (LOG.isDebugEnabled()) {
+ NodeId nodeId = PathUtil.extractNodeId(input.getNode());
LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue());
+ FlowGroupCache cache = new FlowGroupCache(input.getGroupId().getValue().toString(),
+ input.getGroupType().getName(), FlowGroupStatus.REMOVED,
+ LocalDateTime.now());
+ if (provider.getAllNodesFlowGroupCache().containsKey(nodeId.getValue())) {
+ provider.getAllNodesFlowGroupCache().get(nodeId.getValue()).add(cache);
+ } else {
+ Queue<FlowGroupCache> flowGroupCacheList =
+ Queues.synchronizedQueue(EvictingQueue.create(FLOWGROUP_CACHE_SIZE));
+ flowGroupCacheList.add(cache);
+ provider.getAllNodesFlowGroupCache().put(nodeId.getValue(), flowGroupCacheList);
+ }
}
- removeGroup.getDeviceRegistry().getDeviceGroupRegistry().addMark(input.getGroupId());
} else {
LOG.warn("Group remove with id={} failed, errors={}", input.getGroupId().getValue(),
ErrorUtil.errorsToString(result.getErrors()));
@Override
public void onFailure(Throwable throwable) {
- LOG.warn("Service call for removing group={} failed, reason: {}",
+ LOG.warn("Service call for removing group={} failed",
input.getGroupId().getValue(), throwable);
}
}, MoreExecutors.directExecutor());