From: Martin Bobak Date: Wed, 25 Mar 2015 15:16:20 +0000 (+0100) Subject: Implementation of Rpc interfaces X-Git-Tag: release/lithium~621 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=a7ec26d06a266c5677cc823fcbec014dd9563a6a;p=openflowplugin.git Implementation of Rpc interfaces Implementation classes were created for interfaces RequestContext, RpcContext, RpcManager. MdSalRegistrationUtils class for registration of services Change-Id: I8f1f7e7342e04f94f74f7900eeaede3515b37f73 Signed-off-by: Jozef Gloncak Signed-off-by: Martin Bobak Signed-off-by: Jozef Gloncak Signed-off-by: Martin Bobak --- diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java index 383136be39..806b731022 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java @@ -8,11 +8,11 @@ package org.opendaylight.openflowplugin.impl.rpc; import com.google.common.util.concurrent.SettableFuture; +import java.util.concurrent.Future; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.common.RpcResult; -import java.util.concurrent.Future; /** * @author joe @@ -22,23 +22,42 @@ public class RequestContextImpl implements RequestContext private final RpcContext rpcContext; private SettableFuture> rpcResultFuture; - public RequestContextImpl(RpcContext rpcContext) { + public RequestContextImpl(final RpcContext rpcContext) { this.rpcContext = rpcContext; } + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.openflowplugin.api.openflow.device.RequestContext#createRequestFuture(org.opendaylight.yangtools + * .yang.binding.DataObject) + */ @Override public Future> createRequestFuture(final DataObject dataObject) { rpcResultFuture = SettableFuture.create(); return rpcResultFuture; } + /* + * (non-Javadoc) + * + * @see org.opendaylight.openflowplugin.api.openflow.device.RequestContext#requestSucceeded() + */ @Override public void requestSucceeded() { - + // TODO Auto-generated method stub + } + /* + * (non-Javadoc) + * + * @see org.opendaylight.openflowplugin.api.openflow.device.RequestContext#requestFailed(java.lang.String) + */ @Override public void requestFailed(final String exception) { + // TODO Auto-generated method stub } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java index 3e50333b5e..1d100cf485 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java @@ -86,6 +86,7 @@ public class RpcContextImpl implements RpcContext { return null; } + /** * Unregisters all services. * diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java index 123b51f318..d7ac34975e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java @@ -1,6 +1,6 @@ /** * Copyright (c) 2015 Cisco Systems, Inc. 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 @@ -35,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Sal /** * @author joe - * */ public class MdSalRegistratorUtils { @@ -44,7 +43,6 @@ public class MdSalRegistratorUtils { } public static void registerServices(final RpcContext rpcContext) { - rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext)); rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext)); rpcContext.registerRpcServiceImplementation(SalMeterService.class, new SalMeterServiceImpl(rpcContext)); rpcContext.registerRpcServiceImplementation(SalGroupService.class, new SalGroupServiceImpl(rpcContext)); @@ -64,5 +62,4 @@ public class MdSalRegistratorUtils { rpcContext.registerRpcServiceImplementation(OpendaylightQueueStatisticsService.class, new OpendaylightQueueStatisticsServiceImpl(rpcContext)); } - } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java index d335c2b4a9..6c0e8b3b9b 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java @@ -7,21 +7,33 @@ */ package org.opendaylight.openflowplugin.api.openflow.device; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import org.junit.Test; import org.mockito.Matchers; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; +import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl; import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl; +import org.opendaylight.openflowplugin.impl.services.SalFlowServiceImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; import org.opendaylight.yangtools.yang.binding.RpcService; +import org.opendaylight.yangtools.yang.common.RpcResult; public class RpcManagerImplTest { - private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 13; + private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 12; + + private static final int AWAITED_NUM_OF_CALL_ADD_NEW_REQUEST = 1; final ProviderContext mockedProviderContext = mock(ProviderContext.class); final RpcManagerImpl rpcManager = new RpcManagerImpl(mockedProviderContext); @@ -36,15 +48,38 @@ public class RpcManagerImplTest { Matchers.any(Class.class), Matchers.any(RpcService.class)); } + final RpcContext mockedRpcContext = mock(RpcContext.class); + final AddFlowInput mockedFlowInput = prepareTestingAddFlow(); + final DeviceContext mockedDeviceContext = mock(DeviceContext.class); + /** * Tests behavior of RpcContextImpl when calling rpc from MD-SAL */ @Test - public void invokeRpcTest() { - - rpcManager.deviceConnected(mockedRequestContext); -// when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(value); + public void invokeRpcTestExistsCapacityTest() throws InterruptedException, ExecutionException { + invokeRpcTestExistsCapacity(10, true); + invokeRpcTestExistsCapacity(0, false); + } + + private void invokeRpcTestExistsCapacity(final int capacity, final boolean result) throws InterruptedException, + ExecutionException { + // TODO: how to invoke service remotely? + final RpcContextImpl rpcContext = new RpcContextImpl(mockedProviderContext, mockedDeviceContext); + when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext)); + rpcContext.setRequestContextQuota(capacity); + final SalFlowService salFlowService = mockedProviderContext.getRpcService(SalFlowService.class); + final Future> addedFlow = salFlowService.addFlow(prepareTestingAddFlow()); + } + + /** + * @return + */ + private AddFlowInput prepareTestingAddFlow() { + final AddFlowInputBuilder builder = new AddFlowInputBuilder(); + builder.setFlowName("dummy flow"); + builder.setHardTimeout(10000); + return builder.build(); } }