Merge "Added configuration modules and closeable wrappers for FixedThreadPool, Flexib...
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / adsal / FlowServiceAdapter.java
1 package org.opendaylight.controller.sal.compatibility.adsal;
2
3 import java.util.concurrent.Future;
4
5 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
6 import org.opendaylight.controller.sal.common.util.Futures;
7 import org.opendaylight.controller.sal.common.util.Rpcs;
8 import org.opendaylight.controller.sal.compatibility.NodeMapping;
9 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
10 import org.opendaylight.controller.sal.core.ConstructionException;
11 import org.opendaylight.controller.sal.core.Node;
12 import org.opendaylight.controller.sal.flowprogrammer.Flow;
13 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
14 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
15 import org.opendaylight.controller.sal.utils.Status;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
26
27     private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
28
29     private IFlowProgrammerService delegate;
30
31     private NotificationProviderService publish;
32
33     @Override
34     public void flowRemoved(Node node, Flow flow) {
35         FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
36         flowRemovedBuilder.setNode(NodeMapping.toNodeRef(node));
37         publish.publish(flowRemovedBuilder.build());
38     }
39
40     @Override
41     public void flowErrorReported(Node node, long rid, Object err) {
42         // TODO Auto-generated method stub
43
44     }
45
46     @Override
47     public Future<RpcResult<Void>> addFlow(AddFlowInput input) {
48         try {
49             Flow flow = ToSalConversionsUtils.toFlow(input);
50             Node node = NodeMapping.toADNode(input.getNode());
51             Status status = delegate.addFlowAsync(node, flow);
52             Void rpcResultType = null;
53             return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
54         } catch (ConstructionException e) {
55             LOG.error(e.getMessage());
56         }
57         return null;
58     }
59
60     @Override
61     public Future<RpcResult<Void>> removeFlow(RemoveFlowInput input) {
62         try {
63             Flow flow = ToSalConversionsUtils.toFlow(input);
64             Node node = NodeMapping.toADNode(input.getNode());
65             Status status = delegate.removeFlowAsync(node, flow);
66             Void rpcResultType = null;
67             return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
68         } catch (ConstructionException e) {
69             LOG.error(e.getMessage());
70         }
71         return null;
72     }
73
74     @Override
75     public Future<RpcResult<Void>> updateFlow(UpdateFlowInput input) {
76         try {
77             Node node = NodeMapping.toADNode(input.getNode());
78             Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow());
79             Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow());
80             Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
81             Void rpcResultType = null;
82             return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
83         } catch (ConstructionException e) {
84             LOG.error(e.getMessage());
85         }
86         return null;
87     }
88 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.