Exemplo n.º 1
0
 std::string RouteContainer::getRoutes(bool styled) const {
     Json::Value routes(Json::arrayValue);
     for (auto const &r : m_routingDirectives) {
         routes.append(parseRoutingDirective(r));
     }
     if (styled) {
         return routes.toStyledString();
     } else {
         return toFastString(routes);
     }
 }
Exemplo n.º 2
0
 RouteContainer::RouteContainer(std::string const &routes) {
     Json::Reader reader;
     Json::Value routesVal;
     if (!reader.parse(routes, routesVal)) {
         throw std::runtime_error("Invalid JSON routing directive array: " +
                                  routes);
     }
     for (Json::ArrayIndex i = 0, e = routesVal.size(); i < e; ++i) {
         const Json::Value thisRoute = routesVal[i];
         m_addRoute(getDestinationFromJson(thisRoute),
                    toFastString(thisRoute));
     }
 }
Exemplo n.º 3
0
void Manifest::save(const bool primary, const std::string postfix) const
{
    auto m(m_endpoint.getSubEndpoint("m"));

    Json::Value json;
    json["fileStats"] = m_fileStats.toJson();
    json["pointStats"] = m_pointStats.toJson();
    Json::Value& fileInfo(json["fileInfo"]);

    // If we have a postfix (and therefore we're a subset), we'll just write
    // everything out together even if it's huge.  The split-up metadata is a
    // read-time optimization - we'll need to wake everything up to merge at
    // build time anyway.
    const auto n(size());
    const bool dense(n <= denseSize || postfix.size());
    fileInfo.resize(n);

    if (dense || (m.isLocal() && !arbiter::fs::mkdirp(m.root())))
    {
        for (Json::ArrayIndex i(0); i < n; ++i)
        {
            fileInfo[i] = m_fileInfo[i].toJson(primary);
        }
    }
    else
    {
        assert(postfix.empty());

        for (Json::ArrayIndex i(0); i < n; ++i)
        {
            // We're storing the file info separately, so the "fileInfo" key
            // will just contain path/bounds instead of the full info object.
            json["remote"] = true;
            json["chunkSize"] = static_cast<Json::UInt64>(chunkSize);
            fileInfo[i]["path"] = m_fileInfo[i].path();

            if (const auto b = m_fileInfo[i].bounds())
            {
                fileInfo[i]["bounds"] = b->toJson();
            }
        }

        // TODO Could pool these.
        for (Json::ArrayIndex i(0); i < n; i += chunkSize)
        {
            Json::Value chunk;
            chunk.resize(std::min(chunkSize, n - i));

            for (Json::ArrayIndex c(0); c < chunk.size(); ++c)
            {
                chunk[c] = m_fileInfo[i + c].toJson(primary);
            }

            io::ensurePut(m, std::to_string(i), chunk.toStyledString());
        }
    }

    io::ensurePut(
            m_endpoint,
            "entwine-manifest" + postfix,
            primary ? json.toStyledString() : toFastString(json));
}