Deprecate org.opendaylight.controller.sal.common.util.Futures
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / adsal / FlowServiceAdapter.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.compatibility.adsal;
9
10 import java.math.BigInteger;
11
12 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
13 import org.opendaylight.controller.sal.common.util.Rpcs;
14 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
15 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
16 import org.opendaylight.controller.sal.flowprogrammer.Flow;
17 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
18 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
19 import org.opendaylight.controller.sal.utils.Status;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 import com.google.common.util.concurrent.Futures;
39 import com.google.common.util.concurrent.ListenableFuture;
40
41 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
42
43     private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
44
45     private IFlowProgrammerService delegate;
46
47     private NotificationProviderService publish;
48
49     @Override
50     public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
51         FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
52         flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
53         publish.publish(flowRemovedBuilder.build());
54     }
55
56     @Override
57     public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
58         // TODO Auto-generated method stub
59
60     }
61
62     @Override
63     public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
64
65         Flow flow = ToSalConversionsUtils.toFlow(input, null);
66         @SuppressWarnings("unchecked")
67         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
68                 .getNode().getValue());
69         Status status = delegate.addFlowAsync(node, flow);
70         AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
71         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
72         AddFlowOutput rpcResultType = builder.build();
73         return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
74     }
75
76     @Override
77     public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
78
79         Flow flow = ToSalConversionsUtils.toFlow(input, null);
80         @SuppressWarnings("unchecked")
81         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
82                 .getNode().getValue());
83         Status status = delegate.removeFlowAsync(node, flow);
84         RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
85         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
86         RemoveFlowOutput rpcResultType = builder.build();
87         return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
88
89     }
90
91     @Override
92     public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
93         @SuppressWarnings("unchecked")
94         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
95                 .getNode().getValue());
96         Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow(), null);
97         Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow(), null);
98         Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
99         UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
100         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
101         UpdateFlowOutput rpcResultType = builder.build();
102         throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
103         // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
104     }
105 }