Ejemplo n.º 1
0
void DirectorPlugin::pass(HttpRequest* r, const std::string& directorName,
                          const std::string& backendName) {
    auto i = directors_.find(directorName);
    if (i == directors_.end()) {
        r->log(Severity::error,
               "director.pass(): No director with name '%s' configured.",
               directorName.c_str());
        internalServerError(r);
        return;
    }
    Director* director = i->second.get();

    // custom backend route
    Backend* backend = nullptr;
    if (!backendName.empty()) {
        backend = director->findBackend(backendName);

        if (!backend) {
            // explicit backend specified, but not found -> do not serve.
            r->log(Severity::error, "director: Requested backend '%s' not found.",
                   backendName.c_str());
            internalServerError(r);
            return;
        }
    }

#if !defined(NDEBUG)
    server().log(Severity::trace, "director: passing request to %s [backend %s].",
                 director->name().c_str(), backend->name().c_str());
#endif

    auto rn = requestNotes(r);
    rn->manager = director;

    r->onPostProcess.connect(std::bind(&DirectorPlugin::addVia, this, r));

    director->schedule(rn, backend);

    return;
}
Ejemplo n.º 2
0
void DirectorPlugin::balance(HttpRequest* r, const std::string& directorName,
                             const std::string& bucketName) {
    auto i = directors_.find(directorName);
    if (i == directors_.end()) {
        r->log(Severity::error,
               "director.balance(): No director with name '%s' configured.",
               directorName.c_str());
        internalServerError(r);
        return;
    }
    Director* director = i->second.get();

    RequestShaper::Node* bucket = nullptr;
    if (!bucketName.empty()) {
        bucket = director->findBucket(bucketName);
        if (!bucket) {
            // explicit bucket specified, but not found -> ignore.
            bucket = director->rootBucket();
            r->log(Severity::error,
                   "director: Requested bucket '%s' not found in director '%s'. "
                   "Assigning root bucket.",
                   bucketName.c_str(), directorName.c_str());
        }
    } else {
        bucket = director->rootBucket();
    }

    auto rn = requestNotes(r);
    rn->manager = director;

    r->onPostProcess.connect(std::bind(&DirectorPlugin::addVia, this, r));

#if !defined(NDEBUG)
    server().log(Severity::trace, "director: passing request to %s [%s].",
                 director->name().c_str(), bucket->name().c_str());
#endif

    director->schedule(rn, bucket);
}  // }}}