- introduced RpcResultConvertor for converting OFJava future to requestContext's future
- RpcResultConvertor used in SalFlowServiceImpl
Change-Id: I11dc0e6f15920dab3323128749a877532a0486f8
Signed-off-by: Martin Bobak <mbobak@cisco.com>
/**
* 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
*/
package org.opendaylight.openflowplugin.impl.services;
-import java.util.concurrent.Future;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.util.concurrent.Future;
/**
* @author joe
- *
*/
// TODO: implement this
public class NodeConfigServiceImpl extends CommonService implements NodeConfigService {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService#setConfig(org.opendaylight
- * .yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput)
- */
@Override
public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
- // TODO Auto-generated method stub
- return null;
+ final RequestContext requestContext = rpcContext.createRequestContext();
+ final SettableFuture<RpcResult<SetConfigOutput>> result = rpcContext.storeOrFail(requestContext);
+ if (!result.isDone()) {
+ SetConfigInputBuilder builder = new SetConfigInputBuilder();
+ SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
+ final Xid xid = deviceContext.getNextXid();
+ builder.setXid(xid.getValue());
+ builder.setFlags(flag);
+ builder.setMissSendLen(input.getMissSearchLength());
+ builder.setVersion(version);
+ ListenableFuture<RpcResult<Void>> futureResultFromOfLib = JdkFutureAdapters.listenInPoolThread(deviceContext.getPrimaryConnectionContext().getConnectionAdapter().setConfig(builder.build()));
+ RpcResultConvertor<SetConfigOutput> rpcResultConvertor = new RpcResultConvertor<>(requestContext);
+ rpcResultConvertor.processResultFromOfJava(futureResultFromOfLib, getWaitTime());
+ } else {
+ requestContext.close();
+ }
+ return result;
}
-
}
--- /dev/null
+/*
+ * 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
+ */
+
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Created by Martin Bobak <mbobak@cisco.com> on 26.3.2015.
+ */
+public class RpcResultConvertor<T extends DataObject> {
+
+ private final RequestContext requestContext;
+
+ public RpcResultConvertor(RequestContext requestContext) {
+ this.requestContext = requestContext;
+ }
+
+ public void processResultFromOfJava(final Future<RpcResult<Void>> futureResultFromOfLib,
+ final long waitTime) {
+ try {
+ final RpcResult<Void> rpcResult = futureResultFromOfLib.get(waitTime, TimeUnit.MILLISECONDS);
+ if (!rpcResult.isSuccessful()) {
+ requestContext.getFuture().set(RpcResultBuilder.<T>failed().withRpcErrors(rpcResult.getErrors()).build());
+ requestContext.close();
+ }
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ requestContext.getFuture().set(RpcResultBuilder
+ .<T>failed()
+ .withError(RpcError.ErrorType.APPLICATION, "",
+ "Flow modification on device wasn't successfull.").build());
+ requestContext.close();
+ } catch (final Exception e) {
+ requestContext.getFuture().set(RpcResultBuilder.<T>failed()
+ .withError(RpcError.ErrorType.APPLICATION, "", "Flow translation to OF JAVA failed.").build());
+ requestContext.close();
+ }
+ }
+
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.RpcError;
final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
if (!result.isDone()) {
- try {
final Future<RpcResult<Void>> resultFromOFLib = function.apply(connectionID);
- final RpcResult<Void> rpcResult = resultFromOFLib.get(getWaitTime(), TimeUnit.MILLISECONDS);
- if (!rpcResult.isSuccessful()) {
- result.set(RpcResultBuilder.<T> failed().withRpcErrors(rpcResult.getErrors()).build());
- requestContext.close();
- }
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- result.set(RpcResultBuilder
- .<T> failed()
- .withError(RpcError.ErrorType.APPLICATION, "",
- "Flow modification on device wasn't successfull.").build());
- requestContext.close();
- } catch (final Exception e) {
- result.set(RpcResultBuilder.<T> failed()
- .withError(RpcError.ErrorType.APPLICATION, "", "Flow translation to OF JAVA failed.").build());
- requestContext.close();
- }
+
+ RpcResultConvertor<T> rpcResultConvertor = new RpcResultConvertor<>(requestContext);
+ rpcResultConvertor.processResultFromOfJava(resultFromOFLib, getWaitTime());
} else {
requestContext.close();