aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp
blob: 0797ddfb6cd73bdd5a1fa344db55eb0fb199e86f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attribute_manager_explorer.h"
#include "attribute_executor.h"
#include "attribute_vector_explorer.h"
#include "imported_attribute_vector_explorer.h"
#include "imported_attributes_repo.h"
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/searchlib/attribute/imported_attribute_vector.h>

using search::AttributeVector;
using search::attribute::ImportedAttributeVector;
using vespalib::slime::Inserter;

namespace proton {

AttributeManagerExplorer::AttributeManagerExplorer(const proton::IAttributeManager::SP &mgr)
    : _mgr(mgr)
{
}

AttributeManagerExplorer::~AttributeManagerExplorer() {}

void
AttributeManagerExplorer::get_state(const Inserter &inserter, bool full) const
{
    (void) full;
    inserter.insertObject();
}

std::vector<vespalib::string>
AttributeManagerExplorer::get_children_names() const
{
    auto& attributes = _mgr->getWritableAttributes();
    std::vector<vespalib::string> names;
    for (const auto &attr : attributes) {
        names.push_back(attr->getName());
    }
    auto imported = _mgr->getImportedAttributes();
    if (imported != nullptr) {
        std::vector<std::shared_ptr<ImportedAttributeVector>> i_list;
        imported->getAll(i_list);
        for (const auto& attr : i_list) {
            names.push_back(attr->getName());
        }
    }
    return names;
}

std::unique_ptr<vespalib::StateExplorer>
AttributeManagerExplorer::get_child(vespalib::stringref name) const
{
    auto guard = _mgr->getAttribute(name);
    if (!guard || !guard->getSP()) {
        auto imported = _mgr->getImportedAttributes();
        if (imported != nullptr) {
            auto& imported_attr = imported->get(name);
            if (imported_attr) {
                return std::make_unique<ImportedAttributeVectorExplorer>(imported_attr);
            }
        }
    }
    auto attr = guard ? guard->getSP() : std::shared_ptr<AttributeVector>();
    if (attr && _mgr->getWritableAttribute(name) != nullptr) {
        auto executor = std::make_unique<AttributeExecutor>(_mgr, std::move(attr));
        return std::make_unique<AttributeVectorExplorer>(std::move(executor));
    }
    return {};
}

} // namespace proton