X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-compability%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompability%2Fimpl%2FMdSalFlowServiceAdapter.java;fp=opendaylight%2Fmd-sal%2Fsal-compability%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompability%2Fimpl%2FMdSalFlowServiceAdapter.java;h=ae8888f9e2a1437b8ed25c1c8799b4b9ed1895b8;hb=abe57e821d9955ae2c5a4d4ee13ad6ba365667f5;hp=0000000000000000000000000000000000000000;hpb=71306ae62ba5e4b32edc655cb202d2294c92379e;p=controller.git diff --git a/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/impl/MdSalFlowServiceAdapter.java b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/impl/MdSalFlowServiceAdapter.java new file mode 100644 index 0000000000..ae8888f9e2 --- /dev/null +++ b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/impl/MdSalFlowServiceAdapter.java @@ -0,0 +1,125 @@ +package org.opendaylight.controller.sal.compability.impl; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.flowprogrammer.Flow; +import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; +import org.opendaylight.controller.sal.utils.Status; +import org.opendaylight.controller.sal.utils.StatusCode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.opendaylight.controller.sal.compability.FromSalConversionsUtils.*; + +public class MdSalFlowServiceAdapter implements IPluginInFlowProgrammerService { + + private static final Logger LOG = LoggerFactory + .getLogger(MdSalFlowServiceAdapter.class); + private SalFlowService delegate; + + public SalFlowService getDelegate() { + return delegate; + } + + public void setDelegate(SalFlowService delegate) { + this.delegate = delegate; + } + + @Override + // node isn't used in the method + public Status addFlow(Node node, Flow flow) { + AddFlowInput input = addFlowInput(node, flow); + Future> future = delegate.addFlow(input); + RpcResult result; + try { + result = future.get(); + return toStatus(result); // how get status from result? conversion? + } catch (InterruptedException | ExecutionException e) { + LOG.error("Flow Add not processed", e); + return new Status(StatusCode.INTERNALERROR); + } + } + + @Override + // old Flow - what it the purpose? + public Status modifyFlow(Node node, Flow oldFlow, Flow newFlow) { + UpdateFlowInput input = updateFlowInput(node,oldFlow,newFlow); + Future> future = delegate.updateFlow(input); + RpcResult result; + try { + result = future.get(); + return toStatus(result); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Flow Modify not processed", e); + return new Status(StatusCode.INTERNALERROR); + } + } + + @Override + public Status removeFlow(Node node, Flow flow) { + RemoveFlowInput input = removeFlowInput(node,flow); + Future> future = delegate.removeFlow(input); + RpcResult result; + try { + result = future.get(); + return toStatus(result); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Flow Modify not processed", e); + return new Status(StatusCode.INTERNALERROR); + } + } + + @Override + public Status addFlowAsync(Node node, Flow flow, long rid) { + AddFlowInput input = addFlowInput(node, flow); + delegate.addFlow(input); + return new Status(StatusCode.SUCCESS); + } + + @Override + public Status modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, + long rid) { + UpdateFlowInput input = updateFlowInput(node,oldFlow,newFlow); + delegate.updateFlow(input); + return new Status(StatusCode.SUCCESS); + } + + @Override + public Status removeFlowAsync(Node node, Flow flow, long rid) { + RemoveFlowInput input = removeFlowInput(node,flow); + delegate.removeFlow(input); + return new Status(StatusCode.SUCCESS); + } + + @Override + public Status removeAllFlows(Node node) { + throw new UnsupportedOperationException("Not present in MD-SAL"); + } + + @Override + public Status syncSendBarrierMessage(Node node) { + + return null; + } + + @Override + public Status asyncSendBarrierMessage(Node node) { + // TODO Auto-generated method stub + return null; + } + + private Status toStatus(RpcResult result) { + if(result.isSuccessful()) { + return new Status(StatusCode.SUCCESS); + } else { + return new Status(StatusCode.INTERNALERROR); + } + } +}