IceFlow NDN-based stream processing library written in C++
Loading...
Searching...
No Matches
dag-parser.hpp
1/*
2 * Copyright 2024 The IceFlow Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19#ifndef DAGPARSER_HPP
20#define DAGPARSER_HPP
21
22#include <fstream>
23#include <iostream>
24#include <nlohmann/json.hpp>
25#include <optional>
26#include <stdexcept>
27#include <string>
28#include <vector>
29
30using json = nlohmann::json;
31
32namespace iceflow {
33
34// Structs for resources, container, scaling parameters, and communication task
35struct Resources {
36 uint32_t cpu;
37 uint32_t memory;
38};
39
40struct Container {
41 std::string image;
42 std::string tag;
43 std::map<std::string, std::string> envs;
44 std::map<std::string, std::string> mounts;
45 Resources resources;
46};
47
49 uint32_t taskComplexity;
50};
51
52struct Edge {
53 std::string id;
54 std::string target;
55 uint32_t maxPartitions;
56 nlohmann::json::object_t applicationConfiguration;
57};
58
62struct Node {
63 std::string task;
64 std::string name;
65 std::string description;
66 std::string executor;
67 Container container;
68 ScalingParameters scalingParameters;
69 std::vector<Edge> downstream;
70 nlohmann::json::object_t applicationConfiguration;
71};
72
76class DAGParser {
77public:
78 DAGParser(const std::string &appName, std::vector<Node> &&nodes);
79
80 DAGParser(const std::string &appName, std::vector<Node> &&nodeList,
81 std::optional<nlohmann::json> json);
82
83 static DAGParser parseFromFile(const std::string &filename);
84
85 static DAGParser fromJson(nlohmann::json json);
86
87 const std::vector<Node> &getNodes();
88
89 const std::string &getApplicationName();
90
91 const Node &findNodeByName(const std::string &nodeName);
92
93 const Edge &findEdgeByName(const std::string &edgeId);
94
95 std::vector<std::pair<const Node &, const Edge &>>
96 findUpstreamEdges(const std::string &taskId);
97
98 std::vector<std::pair<const Node &, const Edge &>>
99 findUpstreamEdges(const Node &node);
100
101 std::optional<nlohmann::json> getRawDag();
102
103private:
104 std::string m_applicationName;
105 std::vector<Node> m_nodes;
106
107 std::optional<nlohmann::json> m_json;
108};
109
110} // namespace iceflow
111
112#endif // DAGPARSER_HPP
Definition dag-parser.hpp:76
Definition dag-parser.hpp:40
Definition dag-parser.hpp:52
Definition dag-parser.hpp:62
Definition dag-parser.hpp:35
Definition dag-parser.hpp:48