2015-09-13 20:25:26 +00:00
|
|
|
///
|
2018-07-20 11:15:59 +00:00
|
|
|
/// Copyright 2015-2018 Oliver Giles
|
2015-09-13 20:25:26 +00:00
|
|
|
///
|
|
|
|
/// This file is part of Laminar
|
|
|
|
///
|
|
|
|
/// Laminar is free software: you can redistribute it and/or modify
|
|
|
|
/// it under the terms of the GNU General Public License as published by
|
|
|
|
/// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
/// (at your option) any later version.
|
|
|
|
///
|
|
|
|
/// Laminar is distributed in the hope that it will be useful,
|
|
|
|
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
/// GNU General Public License for more details.
|
|
|
|
///
|
|
|
|
/// You should have received a copy of the GNU General Public License
|
|
|
|
/// along with Laminar. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
///
|
2017-12-20 06:24:25 +00:00
|
|
|
#ifndef LAMINAR_LAMINAR_H_
|
|
|
|
#define LAMINAR_LAMINAR_H_
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
#include "interface.h"
|
|
|
|
#include "run.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "database.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2018-09-28 07:36:10 +00:00
|
|
|
#include <kj/filesystem.h>
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
// Node name to node object map
|
2018-04-20 11:18:10 +00:00
|
|
|
typedef std::unordered_map<std::string, std::shared_ptr<Node>> NodeMap;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
struct Server;
|
2015-11-01 10:28:22 +00:00
|
|
|
class Json;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
// The main class implementing the application's business logic.
|
|
|
|
// It owns a Server to manage the HTTP/websocket and Cap'n Proto RPC
|
|
|
|
// interfaces and communicates via the LaminarInterface methods and
|
|
|
|
// the LaminarClient objects (see interface.h)
|
2016-07-25 11:59:45 +00:00
|
|
|
class Laminar final : public LaminarInterface {
|
2015-09-13 20:25:26 +00:00
|
|
|
public:
|
2018-09-28 07:36:10 +00:00
|
|
|
Laminar(const char* homePath);
|
|
|
|
~Laminar() noexcept override;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
// Runs the application forever
|
|
|
|
void run();
|
|
|
|
// Call this in a signal handler to make run() return
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
// Implementations of LaminarInterface
|
|
|
|
std::shared_ptr<Run> queueJob(std::string name, ParamMap params = ParamMap()) override;
|
|
|
|
void registerClient(LaminarClient* client) override;
|
|
|
|
void deregisterClient(LaminarClient* client) override;
|
2017-08-10 05:25:20 +00:00
|
|
|
void registerWaiter(LaminarWaiter* waiter) override;
|
|
|
|
void deregisterWaiter(LaminarWaiter* waiter) override;
|
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
void sendStatus(LaminarClient* client) override;
|
2017-12-21 06:19:45 +00:00
|
|
|
bool setParam(std::string job, uint buildNum, std::string param, std::string value) override;
|
2018-09-28 07:36:10 +00:00
|
|
|
kj::Maybe<kj::Own<const kj::ReadableFile>> getArtefact(std::string path) override;
|
2018-09-10 11:51:43 +00:00
|
|
|
bool handleBadgeRequest(std::string job, std::string& badge) override;
|
2017-12-29 09:14:10 +00:00
|
|
|
std::string getCustomCss() override;
|
2018-02-24 16:53:11 +00:00
|
|
|
void abortAll() override;
|
2018-04-06 15:04:50 +00:00
|
|
|
void notifyConfigChanged() override;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool loadConfiguration();
|
|
|
|
void assignNewJobs();
|
2018-07-20 11:15:59 +00:00
|
|
|
bool tryStartRun(std::shared_ptr<Run> run, int queueIndex);
|
|
|
|
kj::Promise<void> handleRunStep(Run *run);
|
2015-12-06 12:47:43 +00:00
|
|
|
void runFinished(Run*);
|
2018-09-28 07:36:10 +00:00
|
|
|
bool nodeCanQueue(const Node&, std::string jobName) const;
|
2015-11-01 10:28:22 +00:00
|
|
|
// expects that Json has started an array
|
2017-12-21 06:19:45 +00:00
|
|
|
void populateArtifacts(Json& out, std::string job, uint num) const;
|
2015-11-01 10:28:22 +00:00
|
|
|
|
2018-07-20 11:15:59 +00:00
|
|
|
Run* activeRun(const std::string name, uint num) {
|
|
|
|
auto it = activeJobs.byNameNumber().find(boost::make_tuple(name, num));
|
|
|
|
return it == activeJobs.byNameNumber().end() ? nullptr : it->get();
|
2015-11-01 10:28:22 +00:00
|
|
|
}
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
std::list<std::shared_ptr<Run>> queuedJobs;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, uint> buildNums;
|
|
|
|
|
2015-09-24 20:02:11 +00:00
|
|
|
std::unordered_map<std::string, std::set<std::string>> jobTags;
|
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
RunSet activeJobs;
|
|
|
|
Database* db;
|
|
|
|
Server* srv;
|
|
|
|
NodeMap nodes;
|
2018-09-28 07:36:10 +00:00
|
|
|
kj::Path homePath;
|
|
|
|
kj::Own<const kj::Directory> fsHome;
|
2015-09-13 20:25:26 +00:00
|
|
|
std::set<LaminarClient*> clients;
|
2017-08-10 05:25:20 +00:00
|
|
|
std::set<LaminarWaiter*> waiters;
|
2017-12-09 17:03:43 +00:00
|
|
|
uint numKeepRunDirs;
|
2015-09-19 15:24:20 +00:00
|
|
|
std::string archiveUrl;
|
2015-09-13 20:25:26 +00:00
|
|
|
};
|
|
|
|
|
2017-12-20 06:24:25 +00:00
|
|
|
#endif // LAMINAR_LAMINAR_H_
|