From 8f87a72d730f6ef25b30046d9f69ff155346be16 Mon Sep 17 00:00:00 2001 From: Vaclav Demcak Date: Thu, 24 Apr 2014 17:58:31 +0200 Subject: [PATCH] fix for BUG-621 - convertion from xtend to java in compatibility/flow-management-compatibility Change-Id: I171d673230c0e5212f4902e2bd33f12691fc2444 Signed-off-by: Vaclav Demcak --- .../flow-management-compatibility/pom.xml | 8 - .../compatibility/ConfigurationReader.java | 62 +++++++ .../compatibility/FRMRuntimeDataProvider.java | 122 +++++++++++++ .../FRMRuntimeDataProvider.xtend | 172 ------------------ .../compatibility/FlowCommitTransaction.java | 99 ++++++++++ .../frm/compatibility/FlowConfigMapping.java | 109 +++++++++++ .../frm/compatibility/FlowConfigMapping.xtend | 66 ------- .../compatibility/FlowManagementReader.java | 2 +- 8 files changed, 393 insertions(+), 247 deletions(-) create mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/ConfigurationReader.java create mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.java delete mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.xtend create mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowCommitTransaction.java create mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.java delete mode 100644 opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.xtend diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml b/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml index 93ce0dd4f7..7770c15349 100644 --- a/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml @@ -14,10 +14,6 @@ com.google.guava guava - - org.eclipse.xtend - org.eclipse.xtend.lib - org.opendaylight.controller forwardingrulesmanager @@ -67,10 +63,6 @@ - - org.eclipse.xtend - xtend-maven-plugin - diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/ConfigurationReader.java b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/ConfigurationReader.java new file mode 100644 index 0000000000..411af282bd --- /dev/null +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/ConfigurationReader.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2014 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.controller.md.frm.compatibility; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.controller.forwardingrulesmanager.FlowConfig; +import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager; +import org.opendaylight.controller.sal.compatibility.NodeMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.FlowsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfigurationReader implements FlowManagementReader { + + private final static Logger LOG = LoggerFactory.getLogger(ConfigurationReader.class); + + private IForwardingRulesManager manager; + + @Override + public Flows readAllFlows() { + List staticFlows = this.manager.getStaticFlows(); + List flowMap = new ArrayList(staticFlows.size()); + + for (FlowConfig conf : staticFlows) { + flowMap.add(FlowConfigMapping.toConfigurationFlow(conf)); + } + final FlowsBuilder flowsBuilder = new FlowsBuilder(); + return (flowsBuilder.setFlow(flowMap)).build(); + } + + @Override + public Flow readFlow(final FlowKey key) { + try { + final FlowConfig flowConf = + this.manager.getStaticFlow(String.valueOf(key.getId()), NodeMapping.toADNode(key.getNode())); + return FlowConfigMapping.toConfigurationFlow(flowConf); + } catch (Exception e) { + String errMsg = MessageFormat.format("readFlow by key {} fail", key); + LOG.error(errMsg, e); + throw new RuntimeException(errMsg, e); + } + } + + public IForwardingRulesManager getManager() { + return this.manager; + } + + public void setManager(final IForwardingRulesManager manager) { + this.manager = manager; + } +} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.java b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.java new file mode 100644 index 0000000000..be3add1042 --- /dev/null +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.java @@ -0,0 +1,122 @@ +/** + * Copyright (c) 2014 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.controller.md.frm.compatibility; + +import java.util.Collections; + +import org.opendaylight.controller.forwardingrulesmanager.FlowConfig; +import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager; +import org.opendaylight.controller.md.sal.common.api.data.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; +import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider; +import org.opendaylight.controller.sal.common.util.Arguments; +import org.opendaylight.controller.sal.common.util.Rpcs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey; +import org.opendaylight.yangtools.concepts.Registration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; + +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; + +public class FRMRuntimeDataProvider implements RuntimeDataProvider, DataCommitHandler,DataObject> { + + private final static InstanceIdentifier FLOWS_PATH = InstanceIdentifier. builder(Flows.class).toInstance(); + + private final FlowManagementReader configuration = new ConfigurationReader(); + private DataChangeListener, DataObject> changeListener; + private DataProviderService dataService; + private IForwardingRulesManager manager; + + public Registration, DataObject>> init() { + return this.dataService.registerCommitHandler(FRMRuntimeDataProvider.FLOWS_PATH, this); + } + + @Override + public DataObject readConfigurationData(final InstanceIdentifier path) { + return this.readFrom(this.configuration, path); + } + + @Override + public DataObject readOperationalData(final InstanceIdentifier path) { + return this.readFrom(this.configuration, path); + } + + public DataObject readFrom(final FlowManagementReader store, final InstanceIdentifier path) { + if (Objects.equal(FRMRuntimeDataProvider.FLOWS_PATH, path)) { + return store.readAllFlows(); + } + if (FRMRuntimeDataProvider.FLOWS_PATH.contains(path)) { + return store.readFlow(this.toFlowKey(path)); + } + return null; + } + + @Override + public FlowCommitTransaction requestCommit(final DataModification, DataObject> modification) { + return new FlowCommitTransaction(this, modification); + } + + public FlowKey toFlowKey(final InstanceIdentifier identifier) { + Preconditions.> checkNotNull(identifier); + + Iterable path = identifier.getPathArguments(); + PathArgument get = path.iterator().next(); + final Identifier itemKey = Arguments. checkInstanceOf(get, IdentifiableItem.class).getKey(); + return Arguments. checkInstanceOf(itemKey, FlowKey.class); + } + + public RpcResult finish(final FlowCommitTransaction transaction) { + Iterable toRemove = transaction.getToRemove(); + for (final FlowConfig flow : toRemove) { + this.manager.removeStaticFlow(flow.getName(), flow.getNode()); + } + Iterable toUpdate = transaction.getToUpdate(); + for (final FlowConfig flow : toUpdate) { + this.manager.removeStaticFlow(flow.getName(), flow.getNode()); + this.manager.addStaticFlow(flow); + } + return Rpcs. getRpcResult(true, null, Collections. emptySet()); + } + + public RpcResult rollback(final FlowCommitTransaction transaction) { + return null; + } + + public DataProviderService getDataService() { + return this.dataService; + } + + public void setDataService(final DataProviderService dataService) { + this.dataService = dataService; + } + + public DataChangeListener, DataObject> getChangeListener() { + return this.changeListener; + } + + public void setChangeListener(final DataChangeListener, DataObject> changeListener) { + this.changeListener = changeListener; + } + + public IForwardingRulesManager getManager() { + return this.manager; + } + + public void setManager(final IForwardingRulesManager manager) { + this.manager = manager; + } +} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.xtend b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.xtend deleted file mode 100644 index 2d4e7d2c60..0000000000 --- a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FRMRuntimeDataProvider.xtend +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2014 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.controller.md.frm.compatibility - -import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier -import org.opendaylight.yangtools.yang.binding.DataObject -import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler -import org.opendaylight.controller.md.sal.common.api.data.DataModification -import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction -import org.opendaylight.controller.sal.binding.api.data.DataProviderService -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows -import org.opendaylight.controller.md.sal.common.api.data.DataChangeListener -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.FlowsBuilder -import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager -import static com.google.common.base.Preconditions.*; -import static extension org.opendaylight.controller.md.frm.compatibility.FlowConfigMapping.*; -import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*; -import org.opendaylight.controller.sal.common.util.Arguments -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem -import org.opendaylight.yangtools.yang.common.RpcResult -import org.opendaylight.controller.forwardingrulesmanager.FlowConfig -import java.util.HashSet -import org.opendaylight.controller.sal.common.util.Rpcs -import java.util.Collections -import org.opendaylight.yangtools.yang.common.RpcError - -class FRMRuntimeDataProvider implements RuntimeDataProvider, DataCommitHandler, DataObject> { - - static val FLOWS_PATH = InstanceIdentifier.builder(Flows).toInstance; - - @Property - var DataProviderService dataService; - - @Property - var DataChangeListener changeListener; - - @Property - var IForwardingRulesManager manager; - - FlowManagementReader configuration = new ConfigurationReader(); - - def init() { - //dataService.registerDataChangeListener(FLOWS_PATH, changeListener); - dataService.registerCommitHandler(FLOWS_PATH, this); - } - - override readConfigurationData(InstanceIdentifier path) { - return readFrom(configuration, path); - } - - override DataObject readOperationalData(InstanceIdentifier path) { - return readFrom(configuration, path); - } - - def DataObject readFrom(FlowManagementReader store, InstanceIdentifier path) { - if (FLOWS_PATH == path) { - return store.readAllFlows(); - } - if (FLOWS_PATH.contains(path)) { - return store.readFlow(path.toFlowKey()); - } - return null; - } - - override FlowCommitTransaction requestCommit( - DataModification modification) { - return new FlowCommitTransaction(this,modification); - } - - def toFlowKey(InstanceIdentifier identifier) { - checkNotNull(identifier) - val item = Arguments.checkInstanceOf(identifier.path.get(1),IdentifiableItem); - val key = Arguments.checkInstanceOf(item.key,FlowKey) - return key; - } - - def RpcResult finish(FlowCommitTransaction transaction) { - for(flw: transaction.toRemove) { - manager.removeStaticFlow(flw.name,flw.node) - } - - for(flw: transaction.toUpdate) { - manager.removeStaticFlow(flw.name,flw.node); - manager.addStaticFlow(flw); - } - - return Rpcs.getRpcResult(true,null,Collections.emptySet()) - } - - def RpcResult rollback(FlowCommitTransaction transaction) { - // NOOP: We did not changed any state. - } - -} - -class ConfigurationReader implements FlowManagementReader { - - @Property - var IForwardingRulesManager manager; - - override Flows readAllFlows() { - val it = new FlowsBuilder(); - flow = manager.staticFlows.map[ - toConfigurationFlow(); - ] - return it.build(); - } - - override readFlow(FlowKey key) { - val flowCfg = manager.getStaticFlow(String.valueOf(key.id), key.node.toADNode()); - return flowCfg.toConfigurationFlow; - } -} - -public static class FlowCommitTransaction implements DataCommitTransaction, DataObject> { - - @Property - val DataModification, DataObject> modification; - - @Property - val FRMRuntimeDataProvider flowManager; - - @Property - val toAdd = new HashSet(); - - @Property - var Iterable toUpdate - - @Property - var Iterable toRemove - - - new(FRMRuntimeDataProvider flowManager,DataModification, DataObject> modification) { - super(); - _flowManager = flowManager; - _modification = modification; - processModification(); - } - - override finish() throws IllegalStateException { - return flowManager.finish(this); - } - - override rollback() throws IllegalStateException -{ - return flowManager.rollback(this); - } - - def processModification() { - val updated = modification.updatedConfigurationData.entrySet; - - val _toUpdate = updated.filter[key.isFlowPath].map[ - return (value as Flow).toFlowConfig - ] - toUpdate = _toUpdate as Iterable - - - val _toRemove = modification.removedConfigurationData.filter[isFlowPath].map[ - toFlowConfig - ] - toRemove = _toRemove as Iterable - - } -} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowCommitTransaction.java b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowCommitTransaction.java new file mode 100644 index 0000000000..bf0050d6c0 --- /dev/null +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowCommitTransaction.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2014 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.controller.md.frm.compatibility; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import org.opendaylight.controller.forwardingrulesmanager.FlowConfig; +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; + +public class FlowCommitTransaction implements DataCommitTransaction, DataObject> { + + private final DataModification, DataObject> modification; + private final HashSet toAdd = new HashSet(); + private final FRMRuntimeDataProvider flowManager; + private Iterable toUpdate; + private Iterable toRemove; + + public FlowCommitTransaction( + final FRMRuntimeDataProvider flowManager, + final DataModification, DataObject> modification) { + this.flowManager = flowManager; + this.modification = modification; + this.processModification(); + } + + @Override + public RpcResult finish() throws IllegalStateException { + return this.flowManager.finish(this); + } + + @Override + public RpcResult rollback() throws IllegalStateException { + return this.flowManager.rollback(this); + } + + public void processModification() { + final Set, DataObject>> updated = + this.modification.getUpdatedConfigurationData().entrySet(); + final List forUpdate = new ArrayList(updated.size()); + + if (updated != null && !(updated.isEmpty())) { + for (Entry, DataObject> entry : updated) { + if (FlowConfigMapping.isFlowPath(entry.getKey())) { + forUpdate.add(FlowConfigMapping.toFlowConfig((Flow) entry.getValue())); + } + } + } + this.toUpdate = Collections.unmodifiableCollection(forUpdate); + + final Set> removedConfigurationData = + this.modification.getRemovedConfigurationData(); + final List forRemove = new ArrayList(removedConfigurationData.size()); + + if (removedConfigurationData != null && !(removedConfigurationData.isEmpty())) { + for (InstanceIdentifier data : removedConfigurationData) { + if (FlowConfigMapping.isFlowPath(data)) { + forRemove.add(FlowConfigMapping.toFlowConfig(data)); + } + } + } + this.toRemove = Collections.unmodifiableCollection(forRemove); + } + + @Override + public DataModification, DataObject> getModification() { + return this.modification; + } + + public FRMRuntimeDataProvider getFlowManager() { + return this.flowManager; + } + + public HashSet getToAdd() { + return this.toAdd; + } + + public Iterable getToUpdate() { + return this.toUpdate; + } + + public Iterable getToRemove() { + return this.toRemove; + } +} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.java b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.java new file mode 100644 index 0000000000..58c60ec1c5 --- /dev/null +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2014 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.controller.md.frm.compatibility; + +import java.text.MessageFormat; +import java.util.Iterator; + +import org.opendaylight.controller.forwardingrulesmanager.FlowConfig; +import org.opendaylight.controller.sal.compatibility.MDFlowMapping; +import org.opendaylight.controller.sal.compatibility.NodeMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FlowConfigMapping { + + private final static Logger LOG = LoggerFactory.getLogger(FlowConfigMapping.class); + + /* nodes/node/flow -> 0 / 1 / 2 */ + private static final int FLOW_KEY_IDENTIFIER_DEEP = 2; + + public static Flow toConfigurationFlow(final FlowConfig sourceCfg) { + final FlowAdded source = MDFlowMapping.flowAdded(sourceCfg.getFlow()); + final FlowBuilder flowBuilder = new FlowBuilder(); + flowBuilder.setInstructions(source.getInstructions()); + flowBuilder.setCookie(source.getCookie()); + flowBuilder.setHardTimeout(source.getHardTimeout()); + flowBuilder.setIdleTimeout(source.getIdleTimeout()); + flowBuilder.setMatch(source.getMatch()); + flowBuilder.setNode(source.getNode()); + + FlowKey flowKey = + new FlowKey(Long.valueOf(sourceCfg.getName()), flowBuilder.getNode()); + flowBuilder.setKey(flowKey); + return flowBuilder.build(); + } + + public static FlowConfig toFlowConfig(final Flow sourceCfg) { + try { + final FlowConfig flowConfig = new FlowConfig(); + flowConfig.setName(String.valueOf(sourceCfg.getId())); + flowConfig.setNode(NodeMapping.toADNode(sourceCfg.getNode())); + return flowConfig; + } catch (Exception e) { + String errMsg = MessageFormat.format("Convert from Flow {} to FlowConfig fail", sourceCfg); + LOG.error(errMsg, e); + throw new RuntimeException(errMsg, e); + } + } + + public static FlowConfig toFlowConfig(final InstanceIdentifier identifier) { + try { + PathArgument pathArg = FlowConfigMapping.getSecondPathArgumentFromPath(identifier); + if (pathArg != null) { + final FlowConfig flowConfig = new FlowConfig(); + FlowKey key = ((IdentifiableItem) pathArg).getKey(); + flowConfig.setName(String.valueOf(key.getId())); + flowConfig.setNode(NodeMapping.toADNode(key.getNode())); + return flowConfig; + } + return null; + } catch (Exception e) { + String errMsg = MessageFormat.format("Convert from InstanceIdentifier {} to FlowConfig fail", identifier); + LOG.error(errMsg, e); + throw new RuntimeException(errMsg, e); + } + } + + public static boolean isFlowPath(final InstanceIdentifier path) { + PathArgument pathArg = FlowConfigMapping.getSecondPathArgumentFromPath(path); + if (pathArg == null) { + return false; + } + if (pathArg instanceof IdentifiableItem) { + final Identifiable key = ((IdentifiableItem>) pathArg).getKey(); + if ((key instanceof FlowKey)) { + return true; + } + } + return false; + } + + private static PathArgument getSecondPathArgumentFromPath(final InstanceIdentifier path) { + if (path != null && path.getPathArguments() != null) { + Iterator iterator = path.getPathArguments().iterator(); + int deep = 0; + while (iterator.hasNext()) { + PathArgument pathArg = iterator.next(); + if (deep == FlowConfigMapping.FLOW_KEY_IDENTIFIER_DEEP) { + return pathArg; + } + deep++; + } + } + return null; + } +} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.xtend b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.xtend deleted file mode 100644 index e15b3c6c85..0000000000 --- a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowConfigMapping.xtend +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2014 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.controller.md.frm.compatibility - -import org.opendaylight.controller.forwardingrulesmanager.FlowConfig -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder - -import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.* -import static org.opendaylight.controller.sal.compatibility.MDFlowMapping.* -import static org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils.* - -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem -import org.opendaylight.yangtools.yang.binding.Identifiable - -class FlowConfigMapping { - - static def toConfigurationFlow(FlowConfig sourceCfg) { - val source = flowAdded(sourceCfg.flow); - val it = new FlowBuilder(); - instructions = source.instructions; - cookie = source.cookie; - hardTimeout = source.hardTimeout - idleTimeout = source.idleTimeout - match = source.match - node = source.node - key = new FlowKey(Long.parseLong(sourceCfg.name),node); - return it.build(); - } - - static def toFlowConfig(Flow sourceCfg) { - val it = new FlowConfig; - name = String.valueOf(sourceCfg.id); - node = sourceCfg.node.toADNode(); - - return it - } - - static def toFlowConfig(InstanceIdentifier identifier) { - val it = new FlowConfig() - val FlowKey key = ((identifier.path.get(2) as IdentifiableItem).key) - name = String.valueOf(key.id); - node = key.node.toADNode(); - - return it; - } - - static def boolean isFlowPath(InstanceIdentifier path) { - if(path.path.size < 2) return false; - if (path.path.get(2) instanceof IdentifiableItem) { - val IdentifiableItem> item = path.path.get(2) as IdentifiableItem>; - val Identifiable key = item.key; - if (key instanceof FlowKey) { - return true; - } - } - return false; - } -} diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowManagementReader.java b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowManagementReader.java index 017263e264..cb61c8a095 100644 --- a/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowManagementReader.java +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/src/main/java/org/opendaylight/controller/md/frm/compatibility/FlowManagementReader.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the -- 2.36.6