-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathboot.ex
More file actions
353 lines (330 loc) · 15.8 KB
/
Copy pathboot.ex
File metadata and controls
353 lines (330 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
defmodule EXO.Boot do
require EXO
require Logger
def clients() do
case :kvs.all(~c"/exo/clients") do
[] ->
date = :calendar.now_to_datetime(:erlang.timestamp())
ids = :lists.map(fn _ -> :timer.sleep(1) ; :kvs.seq([],[]) end, :lists.seq(1,6))
sample = [
EXO.client(
id: :lists.nth(1,ids),
names: "Максим",
phone: "1",
surnames: "Сохацький",
type: :admin,
status: :online,
date: date
),
EXO.client(
id: :lists.nth(2,ids),
names: "Антон",
phone: "2",
surnames: "Волошко",
type: :admin,
status: :online,
date: date
),
EXO.client(
id: :lists.nth(3,ids),
names: "МВС",
phone: "3",
surnames: "",
type: :consumer,
status: :online,
date: date
),
EXO.client(
id: :lists.nth(4,ids),
names: "ГСЦ",
phone: "4",
surnames: "",
type: :consumer,
status: :online,
date: date
),
EXO.client(
id: :lists.nth(5,ids),
names: "ЦІТ",
phone: "5",
surnames: "",
type: :consumer,
status: :online,
date: date
),
EXO.client(
id: :lists.nth(6,ids),
names: "ДНДІ",
phone: "6",
surnames: "",
type: :consumer,
status: :online,
date: date
)
]
:lists.map(fn x -> :kvs.append(x, ~c"/exo/clients") end, sample)
_ ->
:ok
end
end
def programs() do
current_programs = :kvs.all(~c"/exo/tariffs")
has_gas_or_oil = Enum.any?(current_programs, fn p -> EXO.program(p, :type) in [:gas, :oil] end)
if current_programs == [] or has_gas_or_oil do
if current_programs != [] do
Enum.each(current_programs, fn p -> :kvs.delete(~c"/exo/tariffs", EXO.program(p, :id)) end)
:kvs.delete(:writer, ~c"/exo/tariffs")
end
date = :calendar.now_to_datetime(:erlang.timestamp())
ids = :lists.map(fn _ -> :timer.sleep(1) ; :kvs.seq([],[]) end, :lists.seq(1,12))
sample = [
EXO.program(id: :lists.nth(1, ids), name: "БАЗОВИЙ", type: :internet, date: date),
EXO.program(id: :lists.nth(2, ids), name: "СТАНДАРТ", type: :internet, date: date),
EXO.program(id: :lists.nth(3, ids), name: "БАЗОВИЙ", type: :electricity, date: date),
EXO.program(id: :lists.nth(4, ids), name: "СТАНДАРТ", type: :electricity, date: date),
EXO.program(id: :lists.nth(5, ids), name: "БАЗОВИЙ", type: :bankruptcy, date: date),
EXO.program(id: :lists.nth(6, ids), name: "СТАНДАРТ", type: :bankruptcy, date: date),
EXO.program(id: :lists.nth(7, ids), name: "БАЗОВИЙ", type: :court_decisions_images, date: date),
EXO.program(id: :lists.nth(8, ids), name: "СТАНДАРТ", type: :court_decisions_images, date: date),
EXO.program(id: :lists.nth(9, ids), name: "БАЗОВИЙ", type: :court_cases_scheduled, date: date),
EXO.program(id: :lists.nth(10, ids), name: "СТАНДАРТ", type: :court_cases_scheduled, date: date),
EXO.program(id: :lists.nth(11, ids), name: "БАЗОВИЙ", type: :court_decisions_hyperlinks, date: date),
EXO.program(id: :lists.nth(12, ids), name: "СТАНДАРТ", type: :court_decisions_hyperlinks, date: date)
]
:lists.map(fn x -> :kvs.append(x, ~c"/exo/tariffs") end, sample)
:ok
else
:ok
end
end
def accounts() do
case :kvs.all(~c"/exo/accounts") do
[] ->
date = :calendar.now_to_datetime(:erlang.timestamp())
clients = :kvs.all(~c"/exo/clients")
programs = :kvs.all(~c"/exo/tariffs")
internet_prog = Enum.find(programs, fn p -> EXO.program(p, :type) == :internet end)
Enum.each(clients, fn client ->
phone = EXO.client(client, :phone)
if phone in ["3", "5", "6"] do
client_id = EXO.client(client, :id)
acc_id = :kvs.seq([], [])
acc = EXO.account(
id: acc_id,
client: client_id,
type: :internet,
iban: "UA" <> to_string(:rand.uniform(10_000_000_000_000_000_000_000)),
program: if(internet_prog, do: EXO.program(internet_prog, :id), else: []),
amount: 5000,
state: :open,
date: date
)
:kvs.append(acc, ~c"/exo/accounts")
Logger.info("Seeded account for client phone #{phone} (id: #{client_id}) with balance 5000 UAH")
end
end)
_ ->
:ok
end
end
def itsm() do
current_services = :kvs.all(~c"/itsm/services")
has_bankruptcy = Enum.any?(current_services, fn s -> EXO.itsm_service(s, :id) == "bankruptcy" end)
has_gas_or_oil = Enum.any?(current_services, fn s -> EXO.itsm_service(s, :id) in ["gas", "oil"] end)
if current_services == [] or not has_bankruptcy or has_gas_or_oil do
if current_services != [] do
Enum.each(current_services, fn s -> :kvs.delete(~c"/itsm/services", EXO.itsm_service(s, :id)) end)
:kvs.delete(:writer, ~c"/itsm/services")
end
sample_services = [
EXO.itsm_service(id: "internet", name: "Інтернет", description: "Широкосмуговий доступ до мережі Інтернет", owner: "ІСС Мережі", status: :active),
EXO.itsm_service(id: "electricity", name: "Електропостачання", description: "Постачання електроенергії", owner: "Київські Енергомережі", status: :active),
EXO.itsm_service(
id: "bankruptcy",
name: "Інформаційно-довідкова система \"Банкрутство\"",
description: "Послуги з надання інформації про підприємства щодо яких порушено справу про банкрутство та стан проходження цих справ.",
owner: "ДП «Інформаційні судові системи»",
status: :active
),
EXO.itsm_service(
id: "court_decisions_images",
name: "Сервіс систематизації образів судових рішень",
description: "Послуга з систематизації за обраними критеріями образів автоматично створених електронних копій судових рішень або інших документів, які містяться в Єдиному державному реєстрі судових рішень.",
owner: "ДП «Інформаційні судові системи»",
status: :active
),
EXO.itsm_service(
id: "court_cases_scheduled",
name: "Сервіс систематизації переліку судових справ, призначених до розгляду",
description: "Послуга з отримання переліку судових справ, призначених до розгляду.",
owner: "ДП «Інформаційні судові системи»",
status: :active
),
EXO.itsm_service(
id: "court_decisions_hyperlinks",
name: "Сервіс зі створення гіпертекстових посилань в текстах судових рішень",
description: "Мета послуги - підвищення інформативності документів, які містяться в Єдиному державному реєстрі судових рішень, за рахунок створення гіпертекстових посилань на первинні нормативні документи, згадувані в текстах рішень та розміщені в інформаційно-правових системах користувача.",
owner: "ДП «Інформаційні судові системи»",
status: :active
)
]
:lists.map(fn x -> :kvs.append(x, ~c"/itsm/services") end, sample_services)
end
if :kvs.all(~c"/itsm/slas") == [] do
ids = :lists.map(fn _ -> :timer.sleep(1) ; :kvs.seq([],[]) end, :lists.seq(1,2))
sample_slas = [
EXO.itsm_sla(id: :lists.nth(1, ids), service: "internet", priority: :low, response_time: 120, resolution_time: 480, status: :active),
EXO.itsm_sla(id: :lists.nth(2, ids), service: "electricity", priority: :critical, response_time: 15, resolution_time: 60, status: :active)
]
:lists.map(fn x -> :kvs.append(x, ~c"/itsm/slas") end, sample_slas)
end
if :kvs.all(~c"/itsm/cis") == [] do
ids = :lists.map(fn _ -> :timer.sleep(1) ; :kvs.seq([],[]) end, :lists.seq(1,2))
sample_cis = [
EXO.itsm_ci(id: :lists.nth(1, ids), name: "Магістральний оптоволоконний кабель", type: :hardware, status: :active, dependencies: [], serial_number: "FIB-MAG-01", owner: "ІСС Мережі"),
EXO.itsm_ci(id: :lists.nth(2, ids), name: "Трансформаторна підстанція ТП-402", type: :hardware, status: :active, dependencies: [], serial_number: "SUB-EL-402", owner: "Київські Енергомережі")
]
:lists.map(fn x -> :kvs.append(x, ~c"/itsm/cis") end, sample_cis)
end
# ── Step 1: ensure req exists and get its id ─────────────────────────────
req_id =
case :kvs.all(~c"/itsm/reqs") do
[] ->
:timer.sleep(1)
rid = :kvs.seq([], [])
date = :calendar.now_to_datetime(:erlang.timestamp())
req = EXO.itsm_req(
id: rid,
initiator: "3",
service: "internet",
title: "Проблеми зі зв'язком в офісі МВС",
description: "Не працює VPN-з'єднання з центральним сервером. Зачіпає 40 робочих місць.",
status: :in_progress,
created_at: date,
closed_at: []
)
:kvs.append(req, ~c"/itsm/reqs")
# BPE workflow for this req
case :bpe.start(BPE.Incident.def(), [req]) do
{:ok, proc_id} ->
:bpe.next(proc_id) # New -> Triaje
:bpe.next(proc_id) # Triaje -> Work
Logger.info("Seeded BPE incident workflow #{proc_id} in Work state for req #{rid}")
err ->
Logger.warning("Failed to start BPE workflow in boot: #{inspect(err)}")
end
rid
[existing | _] ->
EXO.itsm_req(existing, :id)
end
# ── Step 2: seed 6 incidents; first one links to req ─────────────────────
# Re-seed whenever count < 6 (wipe old first to avoid list corruption)
current_incidents = :kvs.all(~c"/itsm/incidents")
if length(current_incidents) < 6 do
Enum.each(current_incidents, fn i ->
:kvs.delete(~c"/itsm/incidents", EXO.itsm_incident(i, :id))
end)
if current_incidents != [] do
:kvs.delete(:writer, ~c"/itsm/incidents")
end
inc_ids = :lists.map(fn _ -> :timer.sleep(1); :kvs.seq([], []) end, :lists.seq(1, 6))
# NOTE: req_id goes directly into incident #1 — no post-hoc patching
sample_incidents = [
EXO.itsm_incident(
id: :lists.nth(1, inc_ids),
req: req_id,
service: "internet",
priority: :high,
status: :in_progress,
assignee: "Іваненко О.П.",
description: "Падіння швидкості та обриви зв'язку через аварію на магістральній лінії.",
resolution: "",
slm_deadline: []
),
EXO.itsm_incident(
id: :lists.nth(2, inc_ids),
req: [],
service: "electricity",
priority: :critical,
status: :new,
assignee: "Петренко В.М.",
description: "Повне відключення живлення у серверній кімнаті корпусу А.",
resolution: "",
slm_deadline: []
),
EXO.itsm_incident(
id: :lists.nth(3, inc_ids),
req: [],
service: "bankruptcy",
priority: :medium,
status: :accepted,
assignee: "Коваленко С.Г.",
description: "API повертає помилку 500 при запиті переліку справ за датою.",
resolution: "",
slm_deadline: []
),
EXO.itsm_incident(
id: :lists.nth(4, inc_ids),
req: [],
service: "court_decisions_images",
priority: :low,
status: :resolved,
assignee: "Бойко Д.Р.",
description: "Затримка у формуванні образів рішень понад 2 хвилини.",
resolution: "Збільшено потужність черги обробки зображень. Затримки усунуто.",
slm_deadline: []
),
EXO.itsm_incident(
id: :lists.nth(5, inc_ids),
req: [],
service: "court_cases_scheduled",
priority: :medium,
status: :escalated,
assignee: "Мороз Л.В.",
description: "Відсутні дані про призначені справи за 01.06.2026 у відповіді API.",
resolution: "",
slm_deadline: []
),
EXO.itsm_incident(
id: :lists.nth(6, inc_ids),
req: [],
service: "court_decisions_hyperlinks",
priority: :high,
status: :in_progress,
assignee: "Лисенко А.Ю.",
description: "Гіперпосилання в рішеннях ЄДРСР ведуть на застарілі URL нормативних актів.",
resolution: "",
slm_deadline: []
)
]
:lists.map(fn x -> :kvs.append(x, ~c"/itsm/incidents") end, sample_incidents)
Logger.info("Seeded #{length(sample_incidents)} incidents into /itsm/incidents")
end
# ── Step 3: seed change request ───────────────────────────────────────────
if :kvs.all(~c"/itsm/changes") == [] do
:timer.sleep(1)
chg_id = :kvs.seq([], [])
chg = EXO.itsm_change(
id: chg_id,
req: req_id,
service: "internet",
title: "Модернізація магістрального кабелю",
description: "Заміна пошкодженої ділянки оптоволокна для відновлення стабільного з'єднання.",
risk_level: :medium,
impact: :medium,
status: :in_progress,
change_manager: "Адміністратор",
backout_plan: "Переключення на резервний мідний кабель"
)
:kvs.append(chg, ~c"/itsm/changes")
case :bpe.start(BPE.Change.def(), [chg]) do
{:ok, chg_proc_id} ->
:bpe.next(chg_proc_id) # New -> Analyze
Logger.info("Seeded BPE change workflow #{chg_proc_id} in Analyze state for change #{chg_id}")
err ->
Logger.warning("Failed to start BPE Change workflow in boot: #{inspect(err)}")
end
end
:ok
end
end