import com.google.common.base.Optional;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Maps;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
private static final String ALIEN_SYSTEM_FLOW_ID = "#UF$TABLE*";
private static final AtomicInteger UNACCOUNTED_FLOWS_COUNTER = new AtomicInteger(0);
- private final BiMap<FlowRegistryKey, FlowDescriptor> flowRegistry = HashBiMap.create();
+ private final BiMap<FlowRegistryKey, FlowDescriptor> flowRegistry = Maps.synchronizedBiMap(HashBiMap.create());
private final DataBroker dataBroker;
private final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifier;
private final List<ListenableFuture<List<Optional<FlowCapableNode>>>> lastFillFutures = new ArrayList<>();
@Override
public void store(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
- synchronized (flowRegistryKey) {
- try {
- LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
- flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
- flowRegistry.put(flowRegistryKey, flowDescriptor);
- } catch (IllegalArgumentException ex) {
- LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
- flowDescriptor.getTableKey().getId());
- final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
- final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
- create(flowDescriptor.getTableKey().getId(), newFlowId);
- flowRegistry.put(flowRegistryKey, newFlowDescriptor);
- }
+ try {
+ LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
+ flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
+ flowRegistry.put(flowRegistryKey, flowDescriptor);
+ } catch (IllegalArgumentException ex) {
+ LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
+ flowDescriptor.getTableKey().getId());
+ final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
+ final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
+ create(flowDescriptor.getTableKey().getId(), newFlowId);
+ flowRegistry.put(flowRegistryKey, newFlowDescriptor);
}
}
@Override
public void update(final FlowRegistryKey newFlowRegistryKey, final FlowDescriptor flowDescriptor) {
- synchronized (newFlowRegistryKey) {
- LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode());
- flowRegistry.forcePut(newFlowRegistryKey, flowDescriptor);
- }
+ LOG.trace("Updating the entry with hash: {}", newFlowRegistryKey.hashCode());
+ flowRegistry.forcePut(newFlowRegistryKey, flowDescriptor);
}
@Override
@Override
public void removeDescriptor(final FlowRegistryKey flowRegistryKey) {
- synchronized (flowRegistryKey) {
- LOG.trace("Removing flow descriptor for flow hash : {}", flowRegistryKey.hashCode());
- flowRegistry.remove(flowRegistryKey);
- }
+ LOG.trace("Removing flow descriptor for flow hash : {}", flowRegistryKey.hashCode());
+ flowRegistry.remove(flowRegistryKey);
}
@Override
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
+import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final ListenableFuture<RpcResult<AddFlowOutput>> future =
flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey));
-
return future;
}
@Override
public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
- LOG.trace("Calling remove flow for flow with ID ={}.", input.getFlowRef());
-
final ListenableFuture<RpcResult<RemoveFlowOutput>> future =
flowRemove.processFlowModInputBuilders(flowRemove.toFlowModInputs(input));
Futures.addCallback(future, new RemoveFlowCallback(input));
-
return future;
}
- private final String errorsToString(final Collection<RpcError> rpcErrors) {
- final StringBuilder errors = new StringBuilder();
- if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
- for (final RpcError rpcError : rpcErrors) {
- errors.append(rpcError.getMessage());
- }
- }
- return errors.toString();
- }
-
@Override
public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
final UpdatedFlow updated = input.getUpdatedFlow();
}
@VisibleForTesting
- static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
+ private static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
return nodePath.augmentation(FlowCapableNode.class)
.child(Table.class, flowDescriptor.getTableKey())
flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
}
- LOG.debug("flow add with id={},finished without error,", flowDescriptor.getFlowId().getValue());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Flow add with id={} finished without error", flowDescriptor.getFlowId().getValue());
+ }
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
}
} else {
- LOG.error("flow add failed for flow={}, errors={}", input.toString(), errorsToString(rpcResult.getErrors()));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Flow add failed for flow={}, errors={}", input,
+ ErrorUtil.errorsToString(rpcResult.getErrors()));
+ }
}
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.error("Service call for adding flow={} failed, reason {} .", input.toString(), throwable);
+ LOG.warn("Service call for adding flow={} failed, reason: {}", input, throwable);
}
}
@Override
public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("flow removed finished without error,");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Flow remove finished without error for flow={}", input);
}
FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
deviceContext.getDeviceFlowRegistry().removeDescriptor(flowRegistryKey);
+
if (itemLifecycleListener != null) {
final FlowDescriptor flowDescriptor =
deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
}
}
} else {
- LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Flow remove failed for flow={}, errors={}", input,
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.error("Service call for removing flow with id {} failed ,reason {}",input.getFlowRef().getValue(), throwable);
+ LOG.warn("Service call for removing flow={} failed, reason: {}", input, throwable);
}
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.error("Service call for updating flow failed, reason{}", throwable);
+ LOG.warn("Service call for updating flow={} failed, reason: {}", input, throwable);
}
}
}
\ No newline at end of file
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collection;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@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());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group add with id={} finished without error", input.getGroupId().getValue());
}
deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
addIfNecessaryToDS(input.getGroupId(), input);
} else {
- LOG.error("group add with id={} failed, errors={}", input.getGroupId().getValue(),
- errorsToString(result.getErrors()));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group add with id={} failed, errors={}", input.getGroupId().getValue(),
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Service call for group add failed for id={}. Exception: {}", input.getGroupId().getValue(), t);
+ LOG.warn("Service call for adding group={} failed, reason: {}", input.getGroupId().getValue(), t);
}
});
-
return resultFuture;
}
@Override
public void onSuccess(@Nullable RpcResult<UpdateGroupOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Group update for original id {} succeded", input.getOriginalGroup().getGroupId().getValue());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group update with original id={} finished without error",
+ input.getOriginalGroup().getGroupId().getValue());
}
removeIfNecessaryFromDS(input.getOriginalGroup().getGroupId());
addIfNecessaryToDS(input.getUpdatedGroup().getGroupId(), input.getUpdatedGroup());
- }else{
- LOG.error("group update failed with id={}, errors={}", input.getOriginalGroup().getGroupId(),
- errorsToString(result.getErrors()));
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group update with original id={} failed, errors={}",
+ input.getOriginalGroup().getGroupId(), ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Service call for group update failed for id={}. Exception: {}",
+ LOG.warn("Service call for updating group={} failed, reason: {}",
input.getOriginalGroup().getGroupId(), t);
}
});
@Override
public void onSuccess(@Nullable RpcResult<RemoveGroupOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Group remove for id {} succeded", input.getGroupId().getValue());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue());
}
removeGroup.getDeviceRegistry().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
removeIfNecessaryFromDS(input.getGroupId());
- }else{
- LOG.error("group remove failed with id={}, errors={}", input.getGroupId().getValue(),
- errorsToString(result.getErrors()));
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Group remove with id={} failed, errors={}", input.getGroupId().getValue(),
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Service call for group remove failed for id={}. Exception: {}",
+ LOG.warn("Service call for removing group={} failed, reason: {}",
input.getGroupId().getValue(), t);
}
});
}
}
- static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey>
+ private static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey>
createGroupPath(final GroupId groupId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
return nodePath.augmentation(FlowCapableNode.class).
child(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group.class, new GroupKey(groupId));
}
-
- private final String errorsToString(final Collection<RpcError> rpcErrors) {
- final StringBuilder errors = new StringBuilder();
- if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
- for (final RpcError rpcError : rpcErrors) {
- errors.append(rpcError.getMessage());
- }
- }
- return errors.toString();
- }
}
\ No newline at end of file
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collection;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
-
final ListenableFuture<RpcResult<AddMeterOutput>> resultFuture = addMeter.handleServiceCall(input);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddMeterOutput>>() {
@Override
public void onSuccess(@Nullable RpcResult<AddMeterOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Meter add finished without error, id={}", input.getMeterId());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter add with id={} finished without error", input.getMeterId());
}
deviceContext.getDeviceMeterRegistry().store(input.getMeterId());
addIfNecessaryToDS(input.getMeterId(),input);
} else {
- LOG.error("Meter add with id {} failed with error {}", input.getMeterId(),
- errorsToString(result.getErrors()));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter add with id={} failed, errors={}", input.getMeterId(),
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
+ LOG.warn("Service call for adding meter={} failed, reason: {}", input.getMeterId(), t);
}
});
-
return resultFuture;
}
@Override
public void onSuccess(@Nullable RpcResult<UpdateMeterOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Meter update finished without error, id={}", input.getOriginalMeter().getMeterId());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter update with id={} finished without error", input.getOriginalMeter().getMeterId());
}
if (itemLifecycleListener != null) {
removeIfNecessaryFromDS(input.getOriginalMeter().getMeterId());
addIfNecessaryToDS(input.getUpdatedMeter().getMeterId(),input.getUpdatedMeter());
}
- }else{
- LOG.error("Meter update with id {} failed with error {}", input.getOriginalMeter().getMeterId(),
- errorsToString(result.getErrors()));
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(),
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Service call for meter update failed. for id={}. Exception {}.",
+ LOG.warn("Service call for updating meter={} failed, reason: {}",
input.getOriginalMeter().getMeterId(),t);
}
});
removeMeter.getDeviceRegistry().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
final ListenableFuture<RpcResult<RemoveMeterOutput>> resultFuture = removeMeter.handleServiceCall(input);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveMeterOutput>>() {
-
@Override
public void onSuccess(@Nullable RpcResult<RemoveMeterOutput> result) {
if (result.isSuccessful()) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Meter remove finished without error, id={}", input.getMeterId());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter remove with id={} finished without error", input.getMeterId());
}
removeIfNecessaryFromDS(input.getMeterId());
- }else{
- LOG.error("Meter remove with id {} failed with error {}", input.getMeterId(),
- errorsToString(result.getErrors()));
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Meter remove with id={} failed, errors={}", input.getMeterId(),
+ ErrorUtil.errorsToString(result.getErrors()));
+ }
}
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Service call for meter remove failed for id={}. Exception {}",input.getMeterId(),t);
+ LOG.warn("Service call for removing meter={} failed, reason: {}",input.getMeterId(),t);
}
});
-
return resultFuture;
}
private void removeIfNecessaryFromDS(final MeterId meterId) {
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> meterPath
- = createMeterPath(meterId,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+ = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(meterPath);
}
}
private void addIfNecessaryToDS(final MeterId meterId, final Meter data) {
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> groupPath
- = createMeterPath(meterId,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+ = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build());
}
}
- static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> createMeterPath(final MeterId meterId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+ private static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> createMeterPath(final MeterId meterId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter.class, new MeterKey(meterId));
}
-
- private final String errorsToString(final Collection<RpcError> rpcErrors) {
- final StringBuilder errors = new StringBuilder();
- if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
- for (final RpcError rpcError : rpcErrors) {
- errors.append(rpcError.getMessage());
- }
- }
- return errors.toString();
- }
}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.openflowplugin.impl.util;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.common.RpcError;
+
+/**
+ * Util class for {@link RpcError}.
+ */
+public final class ErrorUtil {
+
+ private ErrorUtil() {
+ throw new IllegalStateException("This class should not be instantiated.");
+ }
+
+ public static final String errorsToString(final Collection<RpcError> rpcErrors) {
+ final StringBuilder errors = new StringBuilder();
+ if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
+ for (final RpcError rpcError : rpcErrors) {
+ errors.append(rpcError.getMessage());
+ }
+ }
+ return errors.toString();
+ }
+
+}