Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for get/get-config with no filter in path API #503

Merged
2 commits merged into from Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/cpp/core/CMakeLists.txt
Expand Up @@ -136,6 +136,7 @@ set(libydk_src
src/capabilities_parser.cpp
src/crud_service.cpp
src/entity.cpp
src/entity_collection.cpp
src/entity_data_node_walker.cpp
src/entity_lookup.cpp
src/entity_util.cpp
Expand Down Expand Up @@ -164,6 +165,7 @@ set(libydk_src
src/path/annotation.cpp
src/path/capability.cpp
src/path/data_node.cpp
src/path/data_node_collection.cpp
src/path/path.cpp
src/path/repository.cpp
src/path/root_data_node.cpp
Expand Down
37 changes: 21 additions & 16 deletions sdk/cpp/core/src/crud_service.cpp
Expand Up @@ -38,12 +38,12 @@ using namespace std;

namespace ydk {

static string get_config_data_payload(Entity & entity, path::ServiceProvider & provider);
static string get_xml_subtree_filter_payload(Entity & entity, path::ServiceProvider & provider);
static std::shared_ptr<path::DataNode> execute_rpc(path::ServiceProvider & provider, Entity & entity,
static string get_config_data_payload(const Entity & entity, path::ServiceProvider & provider);
static string get_xml_subtree_filter_payload(const Entity & entity, path::ServiceProvider & provider);
static path::DataNodeCollection execute_rpc(path::ServiceProvider & provider, const Entity & entity,
const string & operation, const string & data_tag, bool set_config_flag);
static shared_ptr<Entity> get_top_entity_from_filter(Entity & filter);
static bool operation_succeeded(shared_ptr<path::DataNode> node);
static shared_ptr<Entity> get_top_entity_from_filter(const Entity & filter);
static bool operation_succeeded(const path::DataNodeCollection & node);

CrudService::CrudService()
{
Expand Down Expand Up @@ -85,30 +85,35 @@ shared_ptr<Entity> CrudService::read_config(path::ServiceProvider & provider, En
return read_datanode(filter, execute_rpc(provider, filter, "ydk:read", "filter", true));
}

shared_ptr<Entity> CrudService::read_datanode(Entity & filter, shared_ptr<path::DataNode> read_data_node)
shared_ptr<Entity> CrudService::read_datanode(const Entity & filter, const path::DataNodeCollection & read_data_nodes) const
{
if (read_data_node == nullptr)
if (read_data_nodes.get_data_nodes().size() == 0)
return {};
shared_ptr<Entity> top_entity = get_top_entity_from_filter(filter);
get_entity_from_data_node(read_data_node->get_children()[0].get(), top_entity);
for(auto entry : read_data_nodes.get_data_nodes())
{
get_entity_from_data_node(entry.second->get_children()[0].get(), top_entity);
break;
}
return top_entity;
}

static bool operation_succeeded(shared_ptr<path::DataNode> node)
static bool operation_succeeded(const path::DataNodeCollection & node)
{
YLOG_INFO("Operation {}", ((node == nullptr)?"succeeded":"failed"));
return node == nullptr;
auto n = node.get_data_nodes();
YLOG_INFO("Operation {}", ((n.size() == 0)?"succeeded":"failed"));
return n.size() == 0;
}

static shared_ptr<Entity> get_top_entity_from_filter(Entity & filter)
static shared_ptr<Entity> get_top_entity_from_filter(const Entity & filter)
{
if(filter.parent == nullptr)
return filter.clone_ptr();

return get_top_entity_from_filter(*(filter.parent));
}

static shared_ptr<path::DataNode> execute_rpc(path::ServiceProvider & provider, Entity & entity,
static path::DataNodeCollection execute_rpc(path::ServiceProvider & provider, const Entity & entity,
const string & operation, const string & data_tag, bool set_config_flag)
{
// if(data_tag == "entity")
Expand Down Expand Up @@ -136,9 +141,9 @@ static shared_ptr<path::DataNode> execute_rpc(path::ServiceProvider & provider,
return (*ydk_rpc)(provider);
}

static string get_config_data_payload(Entity & entity, path::ServiceProvider & provider)
static string get_config_data_payload(const Entity & entity, path::ServiceProvider & provider)
{
const ydk::path::DataNode& datanode = get_data_node_from_entity(entity, provider.get_root_schema());
ydk::path::DataNode& datanode = get_data_node_from_entity(entity, provider.get_root_schema());

const path::DataNode* dn = &datanode;
while(dn!= nullptr && dn->get_parent()!=nullptr)
Expand All @@ -149,7 +154,7 @@ static string get_config_data_payload(Entity & entity, path::ServiceProvider & p
return payload;
}

static string get_xml_subtree_filter_payload(Entity & entity, path::ServiceProvider & provider)
static string get_xml_subtree_filter_payload(const Entity & entity, path::ServiceProvider & provider)
{
XmlSubtreeCodec xml_subtree_codec{};
YLOG_DEBUG("Encoding the subtree filter request using XML subtree codec");
Expand Down
4 changes: 2 additions & 2 deletions sdk/cpp/core/src/crud_service.hpp
Expand Up @@ -38,7 +38,7 @@ namespace ydk

namespace path
{
class DataNode;
class DataNodeCollection;
class ServiceProvider;
}

Expand All @@ -60,7 +60,7 @@ class CrudService : public Service
std::shared_ptr<Entity> read_config(path::ServiceProvider & provider, Entity & filter);

private:
std::shared_ptr<Entity> read_datanode(Entity & filter, std::shared_ptr<path::DataNode> read_data_node);
std::shared_ptr<Entity> read_datanode(const Entity & filter, const path::DataNodeCollection & read_data_node) const;
};

}
Expand Down
71 changes: 71 additions & 0 deletions sdk/cpp/core/src/entity_collection.cpp
@@ -0,0 +1,71 @@
//
// @file any_data.cpp
// @brief The main ydk public header.
//
// YANG Development Kit
// Copyright 2016 Cisco Systems. All rights reserved
//
////////////////////////////////////////////////////////////////
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
//
//////////////////////////////////////////////////////////////////

#include <vector>

#include "logger.hpp"
#include "types.hpp"

using namespace std;

namespace ydk
{
EntityCollection::EntityCollection()
{
}

EntityCollection::EntityCollection(const std::vector<Entity*> & data)
{
for(auto d : data)
{
if(d!=nullptr)
{
entities[d->get_segment_path()] = shared_ptr<Entity>(d);
}
}
}

EntityCollection::EntityCollection(const std::vector<std::shared_ptr<Entity>> & data)
{
for(auto d : data)
{
if(d!=nullptr)
{
entities[d->get_segment_path()] = d;
}
}
}

EntityCollection::~EntityCollection()
{
}

const std::map<std::string, std::shared_ptr<Entity>> & EntityCollection::get_entities() const
{
return entities;
}
}
10 changes: 5 additions & 5 deletions sdk/cpp/core/src/entity_data_node_walker.cpp
Expand Up @@ -40,8 +40,8 @@ using namespace std;

namespace ydk
{
static void populate_data_node(Entity & entity, path::DataNode & data_node);
static void walk_children(Entity & entity, path::DataNode & data_node);
static void populate_data_node(const Entity & entity, path::DataNode & data_node);
static void walk_children(const Entity & entity, path::DataNode & data_node);
static void populate_name_values(path::DataNode & parent_data_node, EntityPath & path);
static bool data_node_is_leaf(path::DataNode & data_node);
static bool data_node_is_list(path::DataNode & data_node);
Expand All @@ -54,7 +54,7 @@ static path::Annotation get_annotation(YFilter yfilter);
//////////////////////////////////////////////////////////////////////////
// DataNode* from Entity
//////////////////////////////////////////////////////////////////////////
path::DataNode& get_data_node_from_entity(Entity & entity, path::RootSchemaNode & root_schema)
path::DataNode& get_data_node_from_entity(const Entity & entity, path::RootSchemaNode & root_schema)
{
EntityPath root_path = entity.get_entity_path(nullptr);
auto & root_data_node = root_schema.create_datanode(root_path.path);
Expand All @@ -69,7 +69,7 @@ path::DataNode& get_data_node_from_entity(Entity & entity, path::RootSchemaNode
return root_data_node;
}

static void walk_children(Entity & entity, path::DataNode & data_node)
static void walk_children(const Entity & entity, path::DataNode & data_node)
{
std::map<string, shared_ptr<Entity>> children = entity.get_children();
YLOG_DEBUG("Children count for: {} : {}",entity.get_entity_path(entity.parent).path, children.size());
Expand All @@ -84,7 +84,7 @@ static void walk_children(Entity & entity, path::DataNode & data_node)
}
}

static void populate_data_node(Entity & entity, path::DataNode & parent_data_node)
static void populate_data_node(const Entity & entity, path::DataNode & parent_data_node)
{
EntityPath path = entity.get_entity_path(entity.parent);
path::DataNode* data_node = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion sdk/cpp/core/src/entity_data_node_walker.hpp
Expand Up @@ -36,7 +36,7 @@ namespace ydk {

class Entity;

path::DataNode& get_data_node_from_entity(Entity & entity, path::RootSchemaNode & root_schema);
path::DataNode& get_data_node_from_entity(const Entity & entity, path::RootSchemaNode & root_schema);

void get_entity_from_data_node(path::DataNode * node, std::shared_ptr<Entity> entity);

Expand Down
9 changes: 6 additions & 3 deletions sdk/cpp/core/src/executor_service.cpp
Expand Up @@ -67,11 +67,14 @@ shared_ptr<Entity> ExecutorService::execute_rpc(NetconfServiceProvider & provide

// Handle output
auto output = rpc_entity.get_child_by_name("output", "");
if (output != nullptr && result_datanode != nullptr)
if (output != nullptr && result_datanode.get_data_nodes().size() != 0)
{
auto filter = result_datanode->get_children()[0].get();
for(auto entry : result_datanode.get_data_nodes())
{
auto filter = entry.second->get_children()[0].get();

get_entity_from_data_node(filter, top_entity);
get_entity_from_data_node(filter, top_entity);
}
return top_entity;
}
else
Expand Down