Browse Source

rearrange a bit

dhasenan 6 years ago
parent
commit
9be4f00c96

+ 1
- 1
source/stratos/app.d View File

@@ -2,7 +2,7 @@ module stratos.app;
2 2
 
3 3
 import std.stdio;
4 4
 import stratos.api.internal.Raft;
5
-import stratos.raft;
5
+import stratos.cluster.raft;
6 6
 //import stratos.upnp;
7 7
 import vibe.d;
8 8
 import vibethrift.server;

+ 1
- 0
source/stratos/cluster/consensus.d View File

@@ -0,0 +1 @@
1
+module stratos.cluster.consensus;

source/stratos/raft.d → source/stratos/cluster/raft.d View File

@@ -1,4 +1,4 @@
1
-module stratos.raft;
1
+module stratos.cluster.raft;
2 2
 
3 3
 import d2sqlite3;
4 4
 

source/stratos/upnp.d → source/stratos/cluster/upnp.d View File

@@ -1,4 +1,4 @@
1
-module stratos.upnp;
1
+module stratos.cluster.upnp;
2 2
 
3 3
 import vibe.core.log;
4 4
 
@@ -110,19 +110,14 @@ class UPnP
110 110
         import std.socket : Socket;
111 111
         import std.string : replace;
112 112
         import std.uuid : randomUUID;
113
-        import stratos.osinfo;
113
+        import stratos.util.osinfo;
114
+        import stratos.versionid;
114 115
 
115 116
         if (myIPs.length == 0) return;
116 117
 
117 118
         auto name = Socket.hostName;
118 119
         auto configID = 1;
119 120
         auto msgNumber = 1;
120
-        // So, this is an interesting problem.
121
-        // How do we detect the OS version? And what part of the OS?
122
-        // For instance, you might have code that should only run on Linux with kernel 2.6 or higher.
123
-        // We want the kernel name. Or maybe the GLIBC version is the issue. Or maybe you want it
124
-        // to run on Ubuntu 16.04 or higher, or SLES 11.x, or something like that.
125
-        enum stratosVersion = "0.0.1";
126 121
         auto os = osInfo;
127 122
 
128 123
         auto packet = mixin(interp!`NOTIFY * HTTP/1.1
@@ -165,7 +160,7 @@ private void readHeader(ref UPnP.SSDPService service, string line)
165 160
     import std.array : array;
166 161
     import std.conv : to;
167 162
     import std.string : strip;
168
-    import stratos.util : splitOnce;
163
+    import stratos.util.util : splitOnce;
169 164
 
170 165
     auto tag = line.splitter(":").front;
171 166
     auto value = line[tag.length + 1 .. $].strip;

+ 0
- 1
source/stratos/consensus.d View File

@@ -1 +0,0 @@
1
-module stratos.consensus;

+ 0
- 134
source/stratos/job.d View File

@@ -1,134 +0,0 @@
1
-module stratos.job;
2
-
3
-import core.time, std.datetime;
4
-
5
-/// The definition of a job.
6
-class JobDef
7
-{
8
-    /// The friendly name of the job.
9
-    string name;
10
-
11
-    /**
12
-     * The version number for this job.
13
-     *
14
-     * Multiple jobs with the same name are considered versions of the same job.
15
-     * The newest job wins, replacing previous ones.
16
-     */
17
-    size_t versionNumber;
18
-
19
-    /// Which ports it needs to run on. We'll use network trickery to make sure it always works.
20
-    ushort[] ports;
21
-    
22
-    /// How often to run it, how many instances, etc.
23
-    Schedule schedule;
24
-    
25
-    /// How to determine if it's healthy.
26
-    HealthCheck healthcheck;
27
-
28
-    /**
29
-     * How long it takes to drain instances of this service.
30
-     *
31
-     * When you gracefully terminate a task, its DNS records are removed. Once the DNS cache gets flushed, we
32
-     * wait this long for the last requests to be finished before stopping the task.
33
-     *
34
-     * When you restart a task, update a job, etc, we bring up the new task first, wait for it to become healthy,
35
-     * then undertake the process described.
36
-     */
37
-    Duration drainTime = 30.seconds;
38
-}
39
-
40
-/**
41
- * How and when to run a job.
42
- * This is a little combinatorial, but some options:
43
- *
44
- * {instances=1, restart=always, period=0}
45
- *   Run this continually, but only once instance.
46
- *
47
- * {instances=2, restart=never, period=0}
48
- *   Run this right now, two copies; don't restart. One-off job.
49
- *
50
- * {instances=1, restart=never, period=8h}
51
- *   Start this every eight hours; don't restart.
52
- *
53
- * {instances=1, restart=onerror, period=1h}
54
- *   Start this every hour. If it fails early with an error, rerun it.
55
- *   This will not run the job multiple overlapping times.
56
- */
57
-class Schedule
58
-{
59
-    /// How to handle restarts.
60
-    enum Restart
61
-    {
62
-        /// Restart this thing if it exits, cleanly or otherwise.
63
-        Always,
64
-        /// Don't restart this thing, no matter why it fails.
65
-        Never,
66
-        /// Restart this thing if it fails, not if it exits cleanly.
67
-        OnError,
68
-    }
69
-
70
-    /// How many instances should be run at once.
71
-    size_t instances = 1;
72
-    /// Whether to restart if a task ends.
73
-    Restart restart = Restart.Always;
74
-    /// How frequently to run this task.
75
-    Duration period = Duration.zero;
76
-}
77
-
78
-struct JobID
79
-{
80
-    string name;
81
-    size_t revision;
82
-}
83
-
84
-/// A Task is a process run for a job.
85
-class Task
86
-{
87
-    /// The corresponding job.
88
-    JobDef job;
89
-    /// When this started running.
90
-    SysTime start;
91
-    /// When this stopped running. SysTime.min if it's still ongoing.
92
-    SysTime end;
93
-    /// If this process has exited, this is its exit code.
94
-    int exitCode;
95
-    /// The name of the instance that is running / ran this job.
96
-    string runningInstance;
97
-    /// The path at which ith sshould have run.
98
-    string logPath;
99
-}
100
-
101
-/// A HealthCheck is how we determine service health.
102
-class HealthCheck
103
-{
104
-    /// What type of healthcheck to perform.
105
-    enum Type
106
-    {
107
-        /// Perform an HTTP(S) GET request, using the status code to determine health.
108
-        HTTP,
109
-        /// Connect to a socket. Successful connection means healthy.
110
-        Socket
111
-    }
112
-
113
-    /// This healthcheck's type.
114
-    Type type;
115
-    /// If HTTP, request the given path.
116
-    string httpPath = "/";
117
-    /// Whether to make an SSL request.
118
-    bool ssl = false;
119
-    /// What port to request. If not specified, HTTPS gets port 443, HTTP gets port 80.
120
-    // TODO is this necessary? Jobs will specify which ports they get.
121
-    ushort port = 0;
122
-
123
-    /// How frequently to check job health.
124
-    Duration interval = seconds(30);
125
-    /// Services might take extra time to warm up. This is how much extra time to give.
126
-    Duration startupGracePeriod = seconds(60);
127
-
128
-    /// How many checks in a row to succeed before calling this healthy.
129
-    ushort healthyCount = 2;
130
-    /// How many checks in a row to fail before calling this unhealthy (and then we'll stop routing traffic).
131
-    ushort unhealthyCount = 1;
132
-    /// How many checks in a row to fail before calling this unhealthy (and then we'll restart the task).
133
-    ushort respawnCount = 5;
134
-}

source/stratos/osinfo.d → source/stratos/util/osinfo.d View File

@@ -1,4 +1,4 @@
1
-module stratos.osinfo;
1
+module stratos.util.osinfo;
2 2
 
3 3
 struct OS
4 4
 {

source/stratos/serialize.d → source/stratos/util/serialize.d View File

@@ -1,4 +1,4 @@
1
-module stratos.serialize;
1
+module stratos.util.serialize;
2 2
 
3 3
 import core.time;
4 4
 import datetimeformat;

source/stratos/util.d → source/stratos/util/util.d View File

@@ -1,4 +1,4 @@
1
-module stratos.util;
1
+module stratos.util.util;
2 2
 
3 3
 import std.range.primitives : isInputRange, ElementType;
4 4