2015-09-13 20:25:26 +00:00
|
|
|
///
|
2022-01-21 20:07:08 +00:00
|
|
|
/// Copyright 2015-2022 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 "run.h"
|
2019-10-05 17:06:35 +00:00
|
|
|
#include "monitorscope.h"
|
2019-12-13 08:42:22 +00:00
|
|
|
#include "context.h"
|
2015-09-13 20:25:26 +00:00
|
|
|
#include "database.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2018-09-28 07:36:10 +00:00
|
|
|
#include <kj/filesystem.h>
|
2019-10-05 17:06:35 +00:00
|
|
|
#include <kj/async-io.h>
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2019-12-13 08:42:22 +00:00
|
|
|
// Context name to context object map
|
|
|
|
typedef std::unordered_map<std::string, std::shared_ptr<Context>> ContextMap;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2020-09-25 23:33:36 +00:00
|
|
|
class Server;
|
2015-11-01 10:28:22 +00:00
|
|
|
class Json;
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2019-10-05 17:06:35 +00:00
|
|
|
class Http;
|
|
|
|
class Rpc;
|
|
|
|
|
|
|
|
struct Settings {
|
|
|
|
const char* home;
|
|
|
|
const char* bind_rpc;
|
|
|
|
const char* bind_http;
|
|
|
|
const char* archive_url;
|
|
|
|
};
|
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
// The main class implementing the application's business logic.
|
2019-10-05 17:06:35 +00:00
|
|
|
class Laminar final {
|
2015-09-13 20:25:26 +00:00
|
|
|
public:
|
2019-10-05 17:06:35 +00:00
|
|
|
Laminar(Server& server, Settings settings);
|
|
|
|
~Laminar() noexcept;
|
|
|
|
|
|
|
|
// Queues a job, returns immediately. Return value will be nullptr if
|
|
|
|
// the supplied name is not a known job.
|
2022-01-21 20:07:08 +00:00
|
|
|
std::shared_ptr<Run> queueJob(std::string name, ParamMap params = ParamMap(), bool frontOfQueue = false);
|
2019-10-05 17:06:35 +00:00
|
|
|
|
|
|
|
// Return the latest known number of the named job
|
|
|
|
uint latestRun(std::string job);
|
|
|
|
|
|
|
|
// Given a job name and number, return existence and (via reference params)
|
|
|
|
// its current log output and whether the job is ongoing
|
|
|
|
bool handleLogRequest(std::string name, uint num, std::string& output, bool& complete);
|
|
|
|
|
|
|
|
// Given a relevant scope, returns a JSON string describing the current
|
|
|
|
// server status. Content differs depending on the page viewed by the user,
|
|
|
|
// which should be provided as part of the scope.
|
|
|
|
std::string getStatus(MonitorScope scope);
|
|
|
|
|
|
|
|
// Implements the laminarc function of setting arbitrary parameters on a run,
|
|
|
|
// (typically the current run) which will be made available in the environment
|
|
|
|
// of subsequent scripts.
|
|
|
|
bool setParam(std::string job, uint buildNum, std::string param, std::string value);
|
|
|
|
|
|
|
|
// Gets the list of jobs currently waiting in the execution queue
|
|
|
|
const std::list<std::shared_ptr<Run>>& listQueuedJobs();
|
|
|
|
|
|
|
|
// Gets the list of currently executing jobs
|
|
|
|
const RunSet& listRunningJobs();
|
|
|
|
|
|
|
|
// Gets the list of known jobs - scans cfg/jobs for *.run files
|
|
|
|
std::list<std::string> listKnownJobs();
|
|
|
|
|
|
|
|
// Fetches the content of an artifact given its filename relative to
|
|
|
|
// $LAMINAR_HOME/archive. Ideally, this would instead be served by a
|
|
|
|
// proper web server which handles this url.
|
|
|
|
kj::Maybe<kj::Own<const kj::ReadableFile>> getArtefact(std::string path);
|
|
|
|
|
|
|
|
// Given the name of a job, populate the provided string reference with
|
|
|
|
// SVG content describing the last known state of the job. Returns false
|
|
|
|
// if the job is unknown.
|
|
|
|
bool handleBadgeRequest(std::string job, std::string& badge);
|
|
|
|
|
|
|
|
// Aborts a single job
|
|
|
|
bool abort(std::string job, uint buildNum);
|
|
|
|
|
|
|
|
// Abort all running jobs
|
|
|
|
void abortAll();
|
2015-09-13 20:25:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool loadConfiguration();
|
2020-03-10 17:40:14 +00:00
|
|
|
void loadCustomizations();
|
2015-09-13 20:25:26 +00:00
|
|
|
void assignNewJobs();
|
2020-11-13 00:47:02 +00:00
|
|
|
bool canQueue(const Context& ctx, const Run& run) const;
|
2018-07-20 11:15:59 +00:00
|
|
|
bool tryStartRun(std::shared_ptr<Run> run, int queueIndex);
|
2019-12-21 13:29:37 +00:00
|
|
|
void handleRunFinished(Run*);
|
2015-11-01 10:28:22 +00:00
|
|
|
// expects that Json has started an array
|
2021-03-07 09:48:49 +00:00
|
|
|
void populateArtifacts(Json& out, std::string job, uint num, kj::Path subdir = kj::Path::parse(".")) 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;
|
|
|
|
|
2019-12-13 08:42:22 +00:00
|
|
|
std::unordered_map<std::string, std::set<std::string>> jobContexts;
|
|
|
|
|
2019-12-24 20:10:16 +00:00
|
|
|
std::unordered_map<std::string, std::string> jobDescriptions;
|
|
|
|
|
2019-12-13 08:42:22 +00:00
|
|
|
std::unordered_map<std::string, std::string> jobGroups;
|
2015-09-24 20:02:11 +00:00
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
RunSet activeJobs;
|
|
|
|
Database* db;
|
2019-10-05 17:06:35 +00:00
|
|
|
Server& srv;
|
2019-12-13 08:42:22 +00:00
|
|
|
ContextMap contexts;
|
2018-09-28 07:36:10 +00:00
|
|
|
kj::Path homePath;
|
|
|
|
kj::Own<const kj::Directory> fsHome;
|
2017-12-09 17:03:43 +00:00
|
|
|
uint numKeepRunDirs;
|
2015-09-19 15:24:20 +00:00
|
|
|
std::string archiveUrl;
|
2019-10-05 17:06:35 +00:00
|
|
|
|
|
|
|
kj::Own<Http> http;
|
|
|
|
kj::Own<Rpc> rpc;
|
2015-09-13 20:25:26 +00:00
|
|
|
};
|
|
|
|
|
2017-12-20 06:24:25 +00:00
|
|
|
#endif // LAMINAR_LAMINAR_H_
|