From 08c7806335dfa24246210329630efafea3c151ea Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 4 Mar 2016 12:32:10 +0100 Subject: API for dedicated data-tree for Honeycomb agent. Data-tree allows for better control over data processing (commit refusal, change processing ordering, additional validation etc.) than data-store (previous design). Change-Id: Id165df33da179ed925b2187fe247b2d6f672af43 Signed-off-by: Marek Gradzki --- .../v3po/impl/data/ReadableVppDataTree.java | 38 +++++++++++ .../fd/honeycomb/v3po/impl/data/VppDataTree.java | 42 ++++++++++++ .../v3po/impl/data/VppDataTreeSnapshot.java | 34 ++++++++++ .../v3po/impl/trans/DefaultVppWriter.java | 43 ++++++++++++ .../v3po/impl/trans/VppApiInvocationException.java | 76 ++++++++++++++++++++++ .../v3po/impl/trans/VppInterfacesReader.java | 56 ++++++++++++++++ .../io/fd/honeycomb/v3po/impl/trans/VppReader.java | 30 +++++++++ .../io/fd/honeycomb/v3po/impl/trans/VppWriter.java | 27 ++++++++ 8 files changed, 346 insertions(+) create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReadableVppDataTree.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTreeSnapshot.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/DefaultVppWriter.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationException.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppInterfacesReader.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppReader.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppWriter.java (limited to 'v3po/impl/src/main/java/io/fd') diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReadableVppDataTree.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReadableVppDataTree.java new file mode 100644 index 000000000..18e854a81 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/ReadableVppDataTree.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.data; + +import com.google.common.annotations.Beta; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; + +/** + * Facade over VPP data tree that allows reading tree nodes. + */ +@Beta +public interface ReadableVppDataTree { + /** + * Reads a particular node from the VPP data tree. + * + * @param path Path of the node + * @return a CheckFuture containing the result of the read. + */ + CheckedFuture>, ReadFailedException> read(YangInstanceIdentifier path); +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java new file mode 100644 index 000000000..9f64c3966 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTree.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.data; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; + +/** + * Facade over VPP data tree that allows tree modification. + */ +@Beta +public interface VppDataTree { + /** + * Commits modification to VPP data tree. + * + * @param modification VPP data tree modification + * @throws DataValidationFailedException if modification data is not valid + */ + void commit(final DataTreeModification modification) throws DataValidationFailedException; + + /** + * Creates read-only snapshot of a VppDataTree. + * + * @return Data tree snapshot. + */ + VppDataTreeSnapshot takeSnapshot(); +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTreeSnapshot.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTreeSnapshot.java new file mode 100644 index 000000000..f4d68306f --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/data/VppDataTreeSnapshot.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.data; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; + +/** + * Read-only snapshot of a {@link ReadableVppDataTree}. + */ +@Beta +public interface VppDataTreeSnapshot extends ReadableVppDataTree { + + /** + * Creates a new VPP data tree modification. + * + * @return A new data tree modification + */ + DataTreeModification newModification(); +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/DefaultVppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/DefaultVppWriter.java new file mode 100644 index 000000000..10fede190 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/DefaultVppWriter.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans; + +import java.util.Objects; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DefaultVppWriter implements VppWriter { + private static final Logger LOG = LoggerFactory.getLogger(DefaultVppWriter.class); + + @Override + public void process(@Nullable final DataObject dataBefore, @Nullable final DataObject dataAfter) + throws VppApiInvocationException { + LOG.debug("Processing modification: dataBefore={}, dataAfter={}", dataBefore, dataAfter); + + if (Objects.equals(dataBefore, dataAfter)) { + LOG.debug("No modification"); + } else if (dataBefore == null) { + LOG.debug("modification type: CREATE"); + } else if (dataAfter == null) { + LOG.debug("modification type: DELETE"); + } else { + LOG.debug("modification type: UPDATE"); + } + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationException.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationException.java new file mode 100644 index 000000000..b0076cd9c --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationException.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans; + +import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; +import javax.annotation.Nonnull; + +/** + * Throws when Vpp jAPI method invocation failed. + */ +@Beta +public class VppApiInvocationException extends Exception { + private final String methodName; + private final int ctxId; + private final int errorCode; + + /** + * Constructs an VppApiInvocationFailedException with the specified api method name and error code. + * + * @param methodName method name that failed to invoke + * @param ctxId api request context identifier + * @param errorCode negative error code value associated with this failure + * @throws NullPointerException if apiMethodName is null + * @throws IllegalArgumentException if errorCode is nonnegative + */ + public VppApiInvocationException(@Nonnull final String methodName, final int ctxId, final int errorCode) { + super(String.format("vppApi.%s failed with error code: %d (ctxId=%d) ", methodName, errorCode, ctxId)); + this.methodName = Preconditions.checkNotNull(methodName, "apiMethodName is null!"); + this.ctxId = ctxId; + Preconditions.checkArgument(errorCode < 0); + this.errorCode = errorCode; + } + + /** + * Returns method name that failed to invoke. + * + * @return method name + */ + public String getMethodName() { + return methodName; + } + + /** + * Returns api request context identifier. + * + * @return value of context identifier + */ + public int getCtxId() { + return ctxId; + } + + /** + * Returns the error code associated with this failure. + * + * @return a negative integer error code + */ + public int getErrorCode() { + return errorCode; + } +} + diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppInterfacesReader.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppInterfacesReader.java new file mode 100644 index 000000000..5db7ab8a8 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppInterfacesReader.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans; + +import java.util.Collections; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VppInterfacesReader implements VppReader { + private static final Logger LOG = LoggerFactory.getLogger(VppInterfacesReader.class); + + @Override + public Interfaces read(final InstanceIdentifier id) { + LOG.info("VppInterfacesReader.read, id={}", id); + + InterfaceBuilder ifaceBuilder = new InterfaceBuilder(); + final String interfaceName = "eth0"; + ifaceBuilder.setName(interfaceName); + ifaceBuilder.setDescription("eth0 description"); + ifaceBuilder.setEnabled(false); + ifaceBuilder.setKey(new InterfaceKey(interfaceName)); + ifaceBuilder.setType(EthernetCsmacd.class); + ifaceBuilder.setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Disabled); + + InterfacesBuilder ifacesBuilder = new InterfacesBuilder(); + ifacesBuilder.setInterface(Collections.singletonList(ifaceBuilder.build())); + return ifacesBuilder.build(); + } + + @Override + public Class getManagedDataObjectType() { + return null; + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppReader.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppReader.java new file mode 100644 index 000000000..31275f07a --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppReader.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@Beta +public interface VppReader { + + C read(InstanceIdentifier id); + + Class getManagedDataObjectType(); + +} \ No newline at end of file diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppWriter.java new file mode 100644 index 000000000..ffd576b04 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/VppWriter.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans; + +import com.google.common.annotations.Beta; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.binding.DataObject; + +@Beta +public interface VppWriter { + + void process(@Nullable C dataBefore, @Nullable C dataAfter) throws VppApiInvocationException; +} \ No newline at end of file -- cgit 1.2.3-korg