X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2Fservices%2FOpendaylightFlowStatisticsServiceImpl.java;h=f6f9878fae456d9c2236e314ece201d142a7e415;hb=73776c548ab153dee35ca4165ca0ef2413969704;hp=7879447c15176ee4db8e0164f0a4d56f7d9766ff;hpb=dc32b3883e31861ef2dde36735641e03c3207fb5;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java index 7879447c15..f6f9878fae 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,21 +7,18 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; -import com.google.common.base.Function; -import com.google.common.util.concurrent.Futures; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; -import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey; +import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerAggregateFlowMultipartService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerAggregateFlowMultipartService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; @@ -29,97 +26,109 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase; import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * @author joe - */ -public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService { - private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class); - - private final Function>, RpcResult> matchingConvertor = - new Function>, RpcResult>() { - @Override - public RpcResult apply(final RpcResult> input) { - final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext(); - TranslatorLibrary translatorLibrary = deviceContext.oook(); - RpcResult rpcResult; - if (input.isSuccessful()) { - MultipartReply reply = input.getResult().get(0); - final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName()); - final MessageTranslator messageTranslator = translatorLibrary.lookupTranslator(translatorKey); - List aggregStats = new ArrayList(); - - for (MultipartReply multipartReply : input.getResult()) { - aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null)); - } - - GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder = - new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder(); - getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats); +public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, + Delegator { - rpcResult = RpcResultBuilder - .success() - .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build()) - .build(); + private final SingleLayerAggregateFlowMultipartService singleLayerService; + private final MultiLayerAggregateFlowMultipartService multiLayerService; + private OpendaylightFlowStatisticsService delegate; - } else { - rpcResult = RpcResultBuilder - .failed() - .withRpcErrors(input.getErrors()) - .build(); - } - return rpcResult; - } - }; + public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, + deviceContext, + deviceContext.oook(), + convertorExecutor); + } - private final AggregateFlowsInTableService aggregateFlowsInTable; - private final MatchingFlowsInTableService matchingFlowsInTable; - private final AllFlowsInAllTablesService allFlowsInAllTables; - private final AllFlowsInTableService allFlowsInTable; - private final FlowsInTableService flowsInTable; + public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, + final TranslatorLibrary translatorLibrary, + final ConvertorExecutor convertorExecutor) { + singleLayerService = new SingleLayerAggregateFlowMultipartService(requestContextStack, deviceContext); + multiLayerService = new MultiLayerAggregateFlowMultipartService(requestContextStack, deviceContext, + convertorExecutor, translatorLibrary); + } - public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { - aggregateFlowsInTable = new AggregateFlowsInTableService(requestContextStack, deviceContext); - allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, deviceContext); - allFlowsInTable = new AllFlowsInTableService(requestContextStack, deviceContext); - flowsInTable = new FlowsInTableService(requestContextStack, deviceContext); - matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext); + @Override + public void setDelegate(OpendaylightFlowStatisticsService delegate) { + this.delegate = delegate; } + /** + * Get aggregate statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. + */ @Override - public Future> getAggregateFlowStatisticsFromFlowTableForAllFlows( - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { - return aggregateFlowsInTable.handleServiceCall(input); + @Deprecated + public ListenableFuture> + getAggregateFlowStatisticsFromFlowTableForAllFlows( + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + if (delegate != null) { + return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } @Override - public Future> getAggregateFlowStatisticsFromFlowTableForGivenMatch( - final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { - return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor); + public ListenableFuture> + getAggregateFlowStatisticsFromFlowTableForGivenMatch( + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { + return singleLayerService.canUseSingleLayerSerialization() + ? singleLayerService.handleAndReply(input) + : multiLayerService.handleAndReply(input); } + /** + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. + */ @Override - public Future> getAllFlowStatisticsFromFlowTable( + @Deprecated + public ListenableFuture> getAllFlowStatisticsFromFlowTable( final GetAllFlowStatisticsFromFlowTableInput input) { - return allFlowsInTable.handleServiceCall(input); + if (delegate != null) { + return delegate.getAllFlowStatisticsFromFlowTable(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } + /** + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. + */ @Override - public Future> getAllFlowsStatisticsFromAllFlowTables( - final GetAllFlowsStatisticsFromAllFlowTablesInput input) { - return allFlowsInAllTables.handleServiceCall(input); + @Deprecated + public ListenableFuture> + getAllFlowsStatisticsFromAllFlowTables(final GetAllFlowsStatisticsFromAllFlowTablesInput input) { + if (delegate != null) { + return delegate.getAllFlowsStatisticsFromAllFlowTables(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } + /** + * Get flow statistics. + * + * @deprecated provided for Be-release as backward compatibility relic. + */ @Override - public Future> getFlowStatisticsFromFlowTable( + @Deprecated + public ListenableFuture> getFlowStatisticsFromFlowTable( final GetFlowStatisticsFromFlowTableInput input) { - return flowsInTable.handleServiceCall(input); + if (delegate != null) { + return delegate.getFlowStatisticsFromFlowTable(input); + } else { + throw new IllegalAccessError("no delegate available - service is currently out of order"); + } } }