• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dedicate-project / beast / 3ba971e4-2004-46a3-b2d0-8a6d687db0d1

pending completion
3ba971e4-2004-46a3-b2d0-8a6d687db0d1

Pull #9

circleci

fairlight1337
Repaired context menu popping up
Pull Request #9: Adding pipeline applications

1225 of 1225 new or added lines in 24 files covered. (100.0%)

2850 of 3071 relevant lines covered (92.8%)

12345.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/pipeline_server.cpp
1
#include <beast/pipeline_server.hpp>
2

3
// Internal
4
#include <beast/version.hpp>
5

6
namespace beast {
7

8
PipelineServer::PipelineServer(const std::string& storage_folder)
17✔
9
    : pipeline_manager_{storage_folder} {}
17✔
10

11
crow::json::wvalue PipelineServer::serveStatus() {
1✔
12
  crow::json::wvalue value;
1✔
13
  value["version"] = getVersionString();
1✔
14
  return value;
1✔
15
}
16

17
crow::json::wvalue PipelineServer::serveNewPipeline(const crow::request& req) {
15✔
18
  crow::json::wvalue value;
15✔
19
  if (const auto req_body = crow::json::load(req.body); req_body && req_body.has("name")) {
30✔
20
    const auto name = static_cast<std::string>(req_body["name"]);
28✔
21
    try {
22
      const auto pipeline_id = pipeline_manager_.createPipeline(name);
14✔
23
      value["status"] = "success";
14✔
24
      value["id"] = pipeline_id;
14✔
25
    } catch (const std::invalid_argument& exception) {
×
26
      value["status"] = "failed";
×
27
      value["error"] = exception.what();
×
28
    }
29
  } else {
30
    value["status"] = "failed";
1✔
31
    value["error"] = "Missing 'name' in request body";
1✔
32
  }
33
  return value;
15✔
34
}
35

36
crow::json::wvalue PipelineServer::servePipelineById(uint32_t pipeline_id) {
6✔
37
  crow::json::wvalue value;
6✔
38
  value["id"] = pipeline_id;
6✔
39
  try {
40
    const auto& descriptor = pipeline_manager_.getPipelineById(pipeline_id);
6✔
41
    value["state"] =
6✔
42
        descriptor.pipeline.isRunning() ? std::string("running") : std::string("stopped");
9✔
43
    value["name"] = descriptor.name;
3✔
44
    value["metadata"] = crow::json::load(descriptor.metadata.dump());
3✔
45
    value["model"] = crow::json::load(pipeline_manager_.getJsonForPipeline(pipeline_id).dump());
3✔
46

47
    value["status"] = "success";
3✔
48
  } catch (const std::invalid_argument& exception) {
3✔
49
    value["status"] = "failed";
3✔
50
    value["error"] = exception.what();
3✔
51
  }
52
  return value;
6✔
53
}
54

55
crow::json::wvalue PipelineServer::servePipelineAction(const crow::request& req,
14✔
56
                                                       uint32_t pipeline_id,
57
                                                       const std::string_view path) {
58
  crow::json::wvalue value;
14✔
59
  value["id"] = pipeline_id;
14✔
60
  try {
61
    auto& pipeline = pipeline_manager_.getPipelineById(pipeline_id);
14✔
62
    const bool running = pipeline.pipeline.isRunning();
13✔
63
    if (path == "start") {
13✔
64
      if (running) {
4✔
65
        value["status"] = "failed";
1✔
66
        value["error"] = "already_running";
1✔
67
      } else {
68
        try {
69
          pipeline.pipeline.start();
3✔
70
          value["status"] = "success";
3✔
71
        } catch (const std::invalid_argument& exception) {
×
72
          value["status"] = "failed";
×
73
          value["error"] = exception.what();
×
74
        }
75
      }
76
    } else if (path == "stop") {
9✔
77
      if (running) {
2✔
78
        try {
79
          pipeline.pipeline.stop();
1✔
80
          value["status"] = "success";
1✔
81
        } catch (const std::invalid_argument& exception) {
×
82
          value["status"] = "failed";
×
83
          value["error"] = exception.what();
×
84
        }
85
      } else {
86
        value["status"] = "failed";
1✔
87
        value["error"] = "not_running";
1✔
88
      }
89
    } else if (path == "update") {
7✔
90
      if (req.get_header_value("Content-Type") == "application/json") {
4✔
91
        try {
92
          const auto req_body = crow::json::load(req.body);
6✔
93
          const auto action = static_cast<std::string>(req_body["action"]);
5✔
94

95
          if (action == "change_name") {
2✔
96
            const auto new_name = static_cast<std::string>(req_body["name"]);
1✔
97
            pipeline_manager_.updatePipelineName(pipeline.id, new_name);
1✔
98
            value["status"] = "success";
1✔
99
          } else if (action == "move_pipe") {
1✔
100
            auto& descriptor = pipeline_manager_.getPipelineById(pipeline.id);
×
101
            const auto pipe_name = static_cast<std::string>(req_body["name"]);
×
102
            descriptor.metadata["pipes"][pipe_name]["position"]["x"] =
×
103
                static_cast<int32_t>(req_body["x"]);
×
104
            descriptor.metadata["pipes"][pipe_name]["position"]["y"] =
×
105
                static_cast<int32_t>(req_body["y"]);
×
106
            pipeline_manager_.savePipeline(pipeline.id);
×
107
          } else {
108
            value["status"] = "failed";
1✔
109
            value["action"] = action;
1✔
110
            value["error"] = "invalid_action";
1✔
111
          }
112
        } catch (const nlohmann::detail::parse_error& exception) {
×
113
          value["status"] = "failed";
×
114
          value["error"] = exception.what();
×
115
        } catch (const std::invalid_argument& exception) {
×
116
          value["status"] = "failed";
×
117
          value["error"] = exception.what();
×
118
        } catch (const std::runtime_error& exception) {
1✔
119
          value["status"] = "failed";
1✔
120
          value["error"] = exception.what();
1✔
121
        }
122
      } else {
123
        value["status"] = "failed";
1✔
124
        value["error"] = "invalid_request";
1✔
125
      }
126
    } else if (path == "delete") {
3✔
127
      if (pipeline.pipeline.isRunning()) {
2✔
128
        pipeline.pipeline.stop();
1✔
129
      }
130
      pipeline_manager_.deletePipeline(pipeline.id);
2✔
131
      value["status"] = "success";
2✔
132
    } else {
133
      value["status"] = "failed";
1✔
134
      value["error"] = "invalid_command";
1✔
135
      value["command"] = std::string(path);
1✔
136
    }
137
  } catch (const std::invalid_argument& exception) {
1✔
138
    value["status"] = "failed";
1✔
139
    value["error"] = exception.what();
1✔
140
  }
141
  return value;
14✔
142
}
143

144
crow::json::wvalue PipelineServer::serveAllPipelines() const {
1✔
145
  crow::json::wvalue value = crow::json::wvalue::list();
1✔
146
  uint32_t idx = 0;
1✔
147
  for (const auto& pipeline : pipeline_manager_.getPipelines()) {
3✔
148
    crow::json::wvalue pipeline_item;
2✔
149
    pipeline_item["id"] = pipeline.id;
2✔
150
    pipeline_item["name"] = pipeline.name;
2✔
151
    pipeline_item["state"] =
4✔
152
        pipeline.pipeline.isRunning() ? std::string("running") : std::string("stopped");
6✔
153
    value[idx] = std::move(pipeline_item);
2✔
154
    idx++;
2✔
155
  }
156
  return value;
1✔
157
}
158

159
} // namespace beast
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc