Bulk-add copyright headers to java files
[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 import java.util.concurrent.Future;
12
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.controller.sal.common.util.Futures;
15 import org.opendaylight.controller.sal.common.util.Rpcs;
16 import org.opendaylight.controller.sal.compatibility.InventoryMapping;
17 import org.opendaylight.controller.sal.compatibility.NodeMapping;
18 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
19 import org.opendaylight.controller.sal.core.ConstructionException;
20 import org.opendaylight.controller.sal.flowprogrammer.Flow;
21 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
22 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
23 import org.opendaylight.controller.sal.utils.Status;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
43
44     private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
45
46     private IFlowProgrammerService delegate;
47
48     private NotificationProviderService publish;
49
50     @Override
51     public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
52         FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
53         flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
54         publish.publish(flowRemovedBuilder.build());
55     }
56
57     @Override
58     public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
59         // TODO Auto-generated method stub
60
61     }
62
63     @Override
64     public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
65
66         Flow flow = ToSalConversionsUtils.toFlow(input, null);
67         @SuppressWarnings("unchecked")
68         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
69                 .getNode().getValue());
70         Status status = delegate.addFlowAsync(node, flow);
71         AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
72         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
73         AddFlowOutput rpcResultType = builder.build();
74         return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
75     }
76
77     @Override
78     public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
79
80         Flow flow = ToSalConversionsUtils.toFlow(input, null);
81         @SuppressWarnings("unchecked")
82         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
83                 .getNode().getValue());
84         Status status = delegate.removeFlowAsync(node, flow);
85         RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
86         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
87         RemoveFlowOutput rpcResultType = builder.build();
88         return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
89
90     }
91
92     @Override
93     public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
94         @SuppressWarnings("unchecked")
95         org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
96                 .getNode().getValue());
97         Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow(), null);
98         Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow(), null);
99         Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
100         UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
101         builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
102         UpdateFlowOutput rpcResultType = builder.build();
103         throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
104         // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
105     }
106 }