@nsshunt/stsdatamanagement 1.18.98 → 1.18.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,356 +28,6 @@ ALTER SEQUENCE public.stsresource_oid_seq
28
28
  OWNER TO postgres;
29
29
 
30
30
 
31
- CREATE SEQUENCE public.stsmonitor_oid_seq
32
- AS BIGINT
33
- INCREMENT 1
34
- START 1
35
- MINVALUE 1
36
- CACHE 1;
37
-
38
- ALTER SEQUENCE public.stsmonitor_oid_seq
39
- OWNER TO postgres;
40
-
41
-
42
- -----[ stsmonitor ]--------------------------------
43
-
44
- CREATE TABLE public.stsmonitor
45
- (
46
- oid bigint NOT NULL DEFAULT nextval('stsmonitor_oid_seq'::regclass),
47
-
48
- -- main graph key
49
- context character varying COLLATE pg_catalog."default" NOT NULL,
50
-
51
- -- Tree level attributes (context)
52
- servicetype character varying COLLATE pg_catalog."default" NOT NULL,
53
- serviceid character varying COLLATE pg_catalog."default" NOT NULL,
54
- serviceinstanceid character varying COLLATE pg_catalog."default" NOT NULL,
55
- serviceidhostname character varying COLLATE pg_catalog."default" NOT NULL,
56
-
57
- serviceinstanceprocessid character varying COLLATE pg_catalog."default" NOT NULL,
58
- pid integer NOT NULL,
59
- ppid integer NOT NULL,
60
- ismaster boolean NOT NULL,
61
- isworker boolean NOT NULL,
62
- servicename character varying COLLATE pg_catalog."default" NOT NULL,
63
- serviceversion character varying COLLATE pg_catalog."default" NOT NULL,
64
-
65
- -- Leaf level attributes
66
- -- Count based (summed in summary views)
67
- request_count_gauge integer NULL,
68
- error_count_gauge integer NULL,
69
- retry_count_gauge integer NULL,
70
- authentication_count_gauge integer NULL,
71
- velocity_gauge integer NULL,
72
- cpu_load_gauge numeric NULL,
73
- active_request_gauge integer NULL,
74
- connection_count_gauge integer NULL,
75
- connection_pool_total_gauge integer NULL,
76
- connection_pool_idle_gauge integer NULL,
77
- connection_pool_waiting_gauge integer NULL,
78
- core_count_gauge integer NULL,
79
-
80
- -- Define the gauges that provide a point in time value that conveys meaning at that point in time.
81
- -- These values will not be aggregated (summed) in summary views.
82
- timer_gauge numeric NULL,
83
-
84
- -- average gauges
85
- duration_gauge numeric NULL,
86
- latency_gauge numeric NULL,
87
-
88
- -- Define the histogram gauges
89
- duration_histogram_gauge integer ARRAY NULL,
90
- latency_histogram_gauge integer ARRAY NULL,
91
-
92
- -- Define logger based gauges
93
- logger character varying COLLATE pg_catalog."default",
94
-
95
- -- Standard STS attributes
96
- validfrom timestamp with time zone NOT NULL,
97
- validto timestamp with time zone,
98
- vnum bigint NOT NULL,
99
- dbaction smallint NOT NULL,
100
- dbactionuser character varying COLLATE pg_catalog."default" NOT NULL,
101
- CONSTRAINT stsmonitor_pkey PRIMARY KEY (oid)
102
- )
103
-
104
- TABLESPACE pg_default;
105
-
106
- ALTER TABLE public.stsmonitor
107
- OWNER to postgres;
108
- -- Index: stsresource_resname_vnum;
109
-
110
- -- DROP INDEX public.stsresource_resname_vnum;
111
-
112
- CREATE UNIQUE INDEX stsmonitor_prim_index
113
- ON public.stsmonitor USING btree
114
- (context COLLATE pg_catalog."default" ASC NULLS LAST,
115
- servicetype COLLATE pg_catalog."default" ASC NULLS LAST,
116
- serviceid COLLATE pg_catalog."default" ASC NULLS LAST,
117
- serviceinstanceid COLLATE pg_catalog."default" ASC NULLS LAST,
118
- serviceidhostname COLLATE pg_catalog."default" ASC NULLS LAST)
119
- TABLESPACE pg_default;
120
-
121
-
122
- CREATE OR REPLACE FUNCTION public.create_stsmonitor(
123
- _dbactionuser character varying, -- 1
124
-
125
- _context character varying, -- 2
126
-
127
- _servicetype character varying, -- 3
128
- _serviceid character varying, -- 4
129
- _serviceinstanceid character varying, -- 5
130
- _serviceidhostname character varying, -- 6
131
-
132
- _serviceinstanceprocessid character varying, -- 7
133
- _pid integer, -- 8
134
- _ppid integer, -- 9
135
- _ismaster boolean, -- 10
136
- _isworker boolean, -- 11
137
- _servicename character varying, -- 12
138
- _serviceversion character varying, -- 13
139
-
140
- -- Leaf level attributes
141
- -- Count based (summed in summary views)
142
- _request_count_gauge integer, -- 14
143
- _error_count_gauge integer, -- 15
144
- _retry_count_gauge integer, -- 16
145
- _authentication_count_gauge integer, -- 17
146
- _velocity_gauge numeric, -- 18
147
- _cpu_load_gauge numeric , -- 19
148
- _active_request_gauge integer, -- 20
149
- _connection_count_gauge integer, -- 21
150
- _connection_pool_total_gauge integer, -- 22
151
- _connection_pool_idle_gauge integer, -- 23
152
- _connection_pool_waiting_gauge integer, -- 24
153
- _core_count_gauge integer, -- 25
154
-
155
- -- Define the gauges that provide a point in time value that conveys meaning at that point in time.
156
- -- These values will not be aggregated (summed) in summary views.
157
- _timer_gauge numeric, -- 26
158
-
159
- -- average gauges
160
- _duration_gauge numeric, -- 27
161
- _latency_gauge numeric, -- 28
162
-
163
- -- Define the histogram gauges
164
- _duration_histogram_gauge integer ARRAY, -- 29
165
- _latency_histogram_gauge integer ARRAY -- 30
166
- )
167
- RETURNS SETOF stsmonitor
168
- LANGUAGE 'plpgsql'
169
-
170
- COST 100
171
- VOLATILE
172
- ROWS 1000
173
-
174
- AS $BODY$
175
- DECLARE
176
- __now timestamp without time zone := now();
177
- __resoid bigint;
178
- __vnum bigint;
179
- __dbaction smallint;
180
- __inserted_oid bigint;
181
- BEGIN
182
- begin
183
- select oid, vnum, dbaction into __resoid, __vnum, __dbaction from stsmonitor m where m.context = _context and m.validto is null;
184
- -- Too many records exists using the supplied data, the database is in an invalid state for this resource
185
- exception
186
- when sqlstate '21000' then
187
- raise exception 'Too many stsmonitor records for current version using stsmonitor %', _context USING ERRCODE = 'cardinality_violation';
188
- end;
189
-
190
- if __resoid is not null then
191
- -- We have an existing resource
192
- if __dbaction = 1 or __dbaction = 2 or __dbaction = 3 then
193
- -- The existing resource is deleted, update the current version
194
- update stsmonitor
195
-
196
- set dbactionuser = _dbactionuser, -- 1
197
- context = _context, -- 2
198
- servicetype = _servicetype, -- 3
199
- serviceid = _serviceid, -- 4
200
- serviceinstanceid = _serviceinstanceid, -- 5
201
- serviceidhostname = _serviceidhostname, -- 6
202
-
203
- serviceinstanceprocessid = _serviceinstanceprocessid, -- 7
204
- pid = _pid, -- 8
205
- ppid = _ppid, -- 9
206
- ismaster = _ismaster, -- 10
207
- isworker = _isworker, -- 11
208
- servicename = _servicename, -- 12
209
- serviceversion = _serviceversion, -- 13
210
-
211
- request_count_gauge = _request_count_gauge, -- 14
212
- error_count_gauge = _error_count_gauge, -- 15
213
- retry_count_gauge = _retry_count_gauge, -- 16
214
- authentication_count_gauge = _authentication_count_gauge, -- 17
215
- velocity_gauge = _velocity_gauge, -- 18
216
- cpu_load_gauge = _cpu_load_gauge, -- 19
217
- active_request_gauge = _active_request_gauge, -- 20
218
- connection_count_gauge = _connection_count_gauge, -- 21
219
- connection_pool_total_gauge = _connection_pool_total_gauge, -- 22
220
- connection_pool_idle_gauge = _connection_pool_idle_gauge, -- 23
221
- connection_pool_waiting_gauge = _connection_pool_waiting_gauge, -- 24
222
- core_count_gauge = _core_count_gauge, -- 25
223
-
224
- timer_gauge = _timer_gauge, -- 26
225
-
226
- duration_gauge = _duration_gauge, -- 27
227
- latency_gauge = _latency_gauge, -- 28
228
-
229
- duration_histogram_gauge = _duration_histogram_gauge, -- 29
230
- latency_histogram_gauge = _latency_histogram_gauge, -- 30
231
-
232
- validfrom = __now,
233
- dbaction = 2 -- updated
234
-
235
- where oid = __resoid;
236
-
237
- return query
238
- select * from stsmonitor where oid = __resoid;
239
- else
240
- -- The current version is in an active state, raise unique violate condition
241
- RAISE 'Duplicate context within stsmonitor: %', _context USING ERRCODE = 'unique_violation';
242
- end if;
243
- else
244
- /*
245
- For some unknown reason, the below works in pg outside and inside a docker container
246
- but does NOT work inside a docker swarm or a K3 cluster.
247
- -- No current version exists, create a new record
248
- return query
249
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
250
- values (_resname, _resdesc, 1, 1, _dbactionuser, __now)
251
- returning *;
252
- */
253
-
254
- insert into stsmonitor(
255
- context,
256
- servicetype,
257
- serviceid,
258
- serviceinstanceid,
259
- serviceidhostname,
260
-
261
- serviceinstanceprocessid,
262
- pid,
263
- ppid,
264
- ismaster,
265
- isworker,
266
- servicename,
267
- serviceversion,
268
-
269
- request_count_gauge,
270
- error_count_gauge,
271
- retry_count_gauge,
272
- authentication_count_gauge,
273
- velocity_gauge,
274
- cpu_load_gauge,
275
- active_request_gauge,
276
- connection_count_gauge,
277
- connection_pool_total_gauge,
278
- connection_pool_idle_gauge,
279
- connection_pool_waiting_gauge,
280
- core_count_gauge,
281
-
282
- timer_gauge,
283
-
284
- duration_gauge,
285
- latency_gauge,
286
-
287
- duration_histogram_gauge,
288
- latency_histogram_gauge,
289
-
290
- vnum, dbaction, dbactionuser, validfrom)
291
- values (
292
- _context,
293
- _servicetype,
294
- _serviceid,
295
- _serviceinstanceid,
296
- _serviceidhostname,
297
-
298
- _serviceinstanceprocessid,
299
- _pid,
300
- _ppid,
301
- _ismaster,
302
- _isworker,
303
- _servicename,
304
- _serviceversion,
305
-
306
- _request_count_gauge,
307
- _error_count_gauge,
308
- _retry_count_gauge,
309
- _authentication_count_gauge,
310
- _velocity_gauge,
311
- _cpu_load_gauge,
312
- _active_request_gauge,
313
- _connection_count_gauge,
314
- _connection_pool_total_gauge,
315
- _connection_pool_idle_gauge,
316
- _connection_pool_waiting_gauge,
317
- _core_count_gauge,
318
-
319
- _timer_gauge,
320
-
321
- _duration_gauge,
322
- _latency_gauge,
323
-
324
- _duration_histogram_gauge,
325
- _latency_histogram_gauge,
326
-
327
- 1, 1, _dbactionuser, __now)
328
- returning oid into __inserted_oid;
329
-
330
- return query
331
- select * from stsmonitor where oid = __inserted_oid;
332
- end if;
333
- END;
334
- $BODY$;
335
-
336
- ALTER FUNCTION public.create_stsmonitor(
337
- character varying, -- 1 userid
338
-
339
- character varying, -- 2 context
340
-
341
- character varying, -- 3
342
- character varying, -- 4
343
- character varying, -- 5
344
- character varying, -- 6
345
-
346
- character varying, -- 7
347
- integer, -- 8
348
- integer, -- 9
349
- boolean, -- 10
350
- boolean, -- 11
351
- character varying, -- 12
352
- character varying, -- 13
353
-
354
- integer, -- 14
355
- integer, -- 15
356
- integer, -- 16
357
- integer, -- 17
358
- numeric, -- 18 velocity
359
- numeric, -- 19 cpu
360
- integer, -- 20
361
- integer, -- 21
362
- integer, -- 22
363
- integer, -- 23
364
- integer, -- 24
365
- integer, -- 25
366
-
367
- numeric, -- 26 timer
368
-
369
- numeric, -- 27
370
- numeric, -- 28
371
-
372
- integer ARRAY, -- 29
373
- integer ARRAY -- 30
374
- )
375
- OWNER TO postgres;
376
-
377
-
378
-
379
-
380
-
381
31
  -- [ Table: public.stsresource ] ------------------------------------------------------------------------
382
32
 
383
33
  -- DROP TABLE public.stsresource;
@@ -387,6 +37,7 @@ CREATE TABLE public.stsresource
387
37
  oid bigint NOT NULL DEFAULT nextval('stsresource_oid_seq'::regclass),
388
38
  resname character varying(128) COLLATE pg_catalog."default" NOT NULL,
389
39
  resdesc character varying(32768) COLLATE pg_catalog."default",
40
+ resdesc_jsonb jsonb,
390
41
  vnum bigint NOT NULL,
391
42
  validfrom timestamp with time zone NOT NULL,
392
43
  validto timestamp with time zone,
@@ -394,7 +45,6 @@ CREATE TABLE public.stsresource
394
45
  dbactionuser character varying(64) COLLATE pg_catalog."default" NOT NULL,
395
46
  CONSTRAINT stsresource_pkey PRIMARY KEY (oid)
396
47
  )
397
-
398
48
  TABLESPACE pg_default;
399
49
 
400
50
  ALTER TABLE public.stsresource
@@ -418,147 +68,6 @@ CREATE INDEX stsresource_resname_validto
418
68
  TABLESPACE pg_default;
419
69
 
420
70
 
421
-
422
- -- Table: public.stsentity
423
-
424
- -- DROP TABLE public.stsentity;
425
-
426
- CREATE TABLE public.stsentity
427
- (
428
- oid bigint NOT NULL DEFAULT nextval('stsentity_oid_seq'::regclass),
429
- resourceoid integer NOT NULL,
430
- entname character varying(128) COLLATE pg_catalog."default" NOT NULL,
431
- entvalue character varying(32768) COLLATE pg_catalog."default",
432
- vnum bigint NOT NULL,
433
- validfrom timestamp without time zone NOT NULL,
434
- validto timestamp without time zone,
435
- dbaction smallint NOT NULL,
436
- dbactionuser character varying(64) COLLATE pg_catalog."default" NOT NULL,
437
- CONSTRAINT stsentity_pkey PRIMARY KEY (oid),
438
- CONSTRAINT fk_stsresource FOREIGN KEY (resourceoid)
439
- REFERENCES public.stsresource (oid) MATCH SIMPLE
440
- ON UPDATE NO ACTION
441
- ON DELETE CASCADE
442
- )
443
-
444
- TABLESPACE pg_default;
445
-
446
- ALTER TABLE public.stsentity
447
- OWNER to postgres;
448
-
449
- -- Index: stsentity_resourceoid_entname_vnum
450
-
451
- -- DROP INDEX public.stsentity_resourceoid_entname_vnum;
452
-
453
- CREATE UNIQUE INDEX stsentity_resourceoid_entname_vnum
454
- ON public.stsentity USING btree
455
- (resourceoid ASC NULLS LAST, entname COLLATE pg_catalog."default" ASC NULLS LAST, vnum ASC NULLS LAST)
456
- TABLESPACE pg_default;
457
-
458
- -- Index: stsentity_resourceoid_entname_validto
459
-
460
- -- DROP INDEX public.stsentity_resourceoid_entname_validto;
461
-
462
- CREATE INDEX stsentity_resourceoid_entname_validto
463
- ON public.stsentity USING btree
464
- (resourceoid ASC NULLS LAST, entname COLLATE pg_catalog."default" ASC NULLS LAST, validto DESC NULLS LAST)
465
- TABLESPACE pg_default;
466
-
467
-
468
- -- FUNCTION: public.create_stsentity(character varying, character varying, integer, character varying, character varying)
469
-
470
- -- DROP FUNCTION public.create_stsentity(character varying, character varying, integer, character varying, character varying);
471
-
472
- CREATE OR REPLACE FUNCTION public.create_stsentity(
473
- _dbactionuser character varying,
474
- _resname character varying,
475
- _resvnum integer,
476
- _entname character varying,
477
- _entvalue character varying)
478
- RETURNS SETOF stsentity
479
- LANGUAGE 'plpgsql'
480
-
481
- COST 100
482
- VOLATILE
483
- ROWS 1000
484
-
485
- AS $BODY$
486
- declare
487
- resoid bigint;
488
- __inserted_oid bigint;
489
- BEGIN
490
- -- Ensure we get the current non-deleted resource.
491
- resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
492
- if resoid is null then
493
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
494
- RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
495
- end if;
496
- if (select count(*) from stsentity e
497
- where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3) > 0 then
498
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
499
- -- RAISE EXCEPTION 'resname already exists within stsresource %', now();
500
- RAISE 'Duplicate entname within stsresource: %', _resname USING ERRCODE = 'unique_violation';
501
- else
502
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
503
- values (resoid, _entname, _entvalue, 1, 1, _dbactionuser, now())
504
- returning oid into __inserted_oid;
505
-
506
- return query
507
- select * from stsentity where oid = __inserted_oid;
508
- END IF;
509
- END;
510
- $BODY$;
511
-
512
- ALTER FUNCTION public.create_stsentity(character varying, character varying, integer, character varying, character varying)
513
- OWNER TO postgres;
514
-
515
-
516
-
517
-
518
- CREATE OR REPLACE FUNCTION public.create_stsentity_latest(
519
- _dbactionuser character varying,
520
- _resname character varying,
521
- _entname character varying,
522
- _entvalue character varying)
523
- RETURNS SETOF stsentity
524
- LANGUAGE 'plpgsql'
525
-
526
- COST 100
527
- VOLATILE
528
- ROWS 1000
529
-
530
- AS $BODY$
531
- declare
532
- resoid bigint;
533
- __inserted_oid bigint;
534
- BEGIN
535
- -- Ensure we get the current non-deleted resource.
536
- resoid := (select oid from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
537
- if resoid is null then
538
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
539
- RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
540
- end if;
541
- if (select count(*) from stsentity e
542
- where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3) > 0 then
543
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
544
- -- RAISE EXCEPTION 'resname already exists within stsresource %', now();
545
- RAISE 'Duplicate entname within stsresource: %', _resname USING ERRCODE = 'unique_violation';
546
- else
547
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
548
- values (resoid, _entname, _entvalue, 1, 1, _dbactionuser, now())
549
- returning oid into __inserted_oid;
550
-
551
- return query
552
- select * from stsentity where oid = __inserted_oid;
553
- END IF;
554
- END;
555
- $BODY$;
556
-
557
- ALTER FUNCTION public.create_stsentity_latest(character varying, character varying, character varying, character varying)
558
- OWNER TO postgres;
559
-
560
-
561
-
562
71
  -- FUNCTION: public.create_stsresource(character varying, character varying, character varying)
563
72
 
564
73
  -- DROP FUNCTION public.create_stsresource(character varying, character varying, character varying);
@@ -581,7 +90,15 @@ DECLARE
581
90
  __vnum bigint;
582
91
  __dbaction smallint;
583
92
  __inserted_oid bigint;
93
+ _resdesc_jsonb JSONB;
584
94
  BEGIN
95
+ begin
96
+ _resdesc_jsonb := _resdesc::jsonb;
97
+ exception
98
+ when others then
99
+ raise exception 'Invalid JSON string: %', _resdesc;
100
+ end;
101
+
585
102
  begin
586
103
  select oid, vnum, dbaction into __resoid, __vnum, __dbaction from stsresource r where r.resname = _resname and r.validto is null;
587
104
  -- Too many records exists using the supplied data, the database is in an invalid state for this resource
@@ -597,8 +114,8 @@ BEGIN
597
114
  update stsresource set validto = __now where oid = __resoid;
598
115
 
599
116
  -- Create a new record
600
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
601
- values (_resname, _resdesc, __vnum+1, 1, _dbactionuser, __now)
117
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
118
+ values (_resname, _resdesc, _resdesc_jsonb, __vnum+1, 1, _dbactionuser, __now)
602
119
  returning oid into __inserted_oid;
603
120
 
604
121
  return query
@@ -618,8 +135,8 @@ BEGIN
618
135
  returning *;
619
136
  */
620
137
 
621
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
622
- values (_resname, _resdesc, 1, 1, _dbactionuser, __now)
138
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
139
+ values (_resname, _resdesc, _resdesc_jsonb, 1, 1, _dbactionuser, __now)
623
140
  returning oid into __inserted_oid;
624
141
 
625
142
  return query
@@ -632,17 +149,16 @@ ALTER FUNCTION public.create_stsresource(character varying, character varying, c
632
149
  OWNER TO postgres;
633
150
 
634
151
 
635
- -- FUNCTION: public.delete_stsentity(character varying, character varying, integer, character varying, integer)
636
152
 
637
- -- DROP FUNCTION public.delete_stsentity(character varying, character varying, integer, character varying, integer);
638
153
 
639
- CREATE OR REPLACE FUNCTION public.delete_stsentity(
154
+
155
+
156
+ CREATE OR REPLACE FUNCTION public.update_stsresource(
640
157
  _dbactionuser character varying,
641
158
  _resname character varying,
642
159
  _resvnum integer,
643
- _entname character varying,
644
- _entvnum integer)
645
- RETURNS SETOF stsentity
160
+ _resdesc character varying)
161
+ RETURNS SETOF stsresource
646
162
  LANGUAGE 'plpgsql'
647
163
 
648
164
  COST 100
@@ -653,59 +169,121 @@ AS $BODY$
653
169
  declare
654
170
  _now timestamp without time zone := now();
655
171
  resoid bigint;
656
- entoid bigint;
657
- __inserted_oid bigint;
172
+ newresoid stsresource.oid%TYPE;
173
+ _resdesc_jsonb JSONB;
658
174
  BEGIN
659
- BEGIN
660
- -- Ensure we get the current non-deleted resource.
175
+ begin
176
+ _resdesc_jsonb := _resdesc::jsonb;
177
+ exception
178
+ when others then
179
+ raise exception 'Invalid JSON string: %', _resdesc;
180
+ end;
181
+
182
+ begin
661
183
  resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
662
184
  exception
663
185
  when sqlstate '21000' then
664
186
  raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
665
- END;
187
+ end;
188
+
666
189
  if resoid is null then
667
190
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
668
191
  RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
669
192
  end if;
670
193
 
671
- -- Ensure we get the current non-deleted entity for this resource.
194
+ update stsresource set validto = _now where oid = resoid;
195
+
196
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
197
+ values (_resname, _resdesc, _resdesc_jsonb, _resvnum+1, 2, _dbactionuser, _now)
198
+ RETURNING oid INTO newresoid;
199
+
200
+ update stsentity set resourceoid = newresoid where resourceoid = resoid;
201
+
202
+ return query
203
+ select * from stsresource where oid = newresoid;
204
+ END;
205
+ $BODY$;
206
+
207
+ ALTER FUNCTION public.update_stsresource(character varying, character varying, integer, character varying)
208
+ OWNER TO postgres;
209
+
210
+
211
+ -- FUNCTION: public.update_stsresource(character varying, character varying, integer, character varying)
212
+
213
+ -- DROP FUNCTION public.update_stsresource(character varying, character varying, integer, character varying);
214
+
215
+ CREATE OR REPLACE FUNCTION public.update_stsresource_latest(
216
+ _dbactionuser character varying,
217
+ _resname character varying,
218
+ _resdesc character varying)
219
+ RETURNS SETOF stsresource
220
+ LANGUAGE 'plpgsql'
221
+
222
+ COST 100
223
+ VOLATILE
224
+ ROWS 1000
225
+
226
+ AS $BODY$
227
+ declare
228
+ _now timestamp without time zone := now();
229
+ resoid bigint;
230
+ newresoid stsresource.oid%TYPE;
231
+ _resvnum integer;
232
+ _resdesc_jsonb JSONB;
233
+ BEGIN
672
234
  begin
673
- entoid = (select oid from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.vnum = _entvnum and e.validto is null and e.dbaction != 3);
235
+ _resdesc_jsonb := _resdesc::jsonb;
236
+ exception
237
+ when others then
238
+ raise exception 'Invalid JSON string: %', _resdesc;
239
+ end;
240
+
241
+ begin
242
+ _resvnum := (select vnum from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
674
243
  exception
675
244
  when sqlstate '21000' then
676
- raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
245
+ raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
677
246
  end;
678
247
 
679
- if entoid is null then
248
+ begin
249
+ resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
250
+ exception
251
+ when sqlstate '21000' then
252
+ raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
253
+ end;
254
+
255
+ if resoid is null then
680
256
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
681
- RAISE 'entname and version not found or not current version (not deleted) within stsentity %', _entname USING ERRCODE = 'no_data_found';
257
+ RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
682
258
  end if;
683
259
 
684
- update stsentity set validto = _now where oid = entoid;
685
-
686
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
687
- (select resoid, e.entname, e.entvalue, _entvnum+1, 3, _dbactionuser, _now
688
- from stsentity e where e.oid = entoid)
689
- returning oid into __inserted_oid;
260
+ update stsresource set validto = _now where oid = resoid;
690
261
 
262
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
263
+ values (_resname, _resdesc, _resdesc_jsonb, _resvnum+1, 2, _dbactionuser, _now)
264
+ RETURNING oid INTO newresoid;
265
+
266
+ update stsentity set resourceoid = newresoid where resourceoid = resoid;
267
+
691
268
  return query
692
- select * from stsentity where oid = __inserted_oid;
269
+ select * from stsresource where oid = newresoid;
693
270
  END;
694
271
  $BODY$;
695
272
 
696
- ALTER FUNCTION public.delete_stsentity(character varying, character varying, integer, character varying, integer)
273
+ ALTER FUNCTION public.update_stsresource_latest(character varying, character varying, character varying)
697
274
  OWNER TO postgres;
698
275
 
699
276
 
700
277
 
278
+ -- FUNCTION: public.delete_stsresource(character varying, character varying, integer)
701
279
 
280
+ -- DROP FUNCTION public.delete_stsresource(character varying, character varying, integer);
702
281
 
703
-
704
- CREATE OR REPLACE FUNCTION public.delete_stsentity_latest(
282
+ CREATE OR REPLACE FUNCTION public.delete_stsresource(
705
283
  _dbactionuser character varying,
706
284
  _resname character varying,
707
- _entname character varying)
708
- RETURNS SETOF stsentity
285
+ _resvnum integer)
286
+ RETURNS SETOF stsresource
709
287
  LANGUAGE 'plpgsql'
710
288
 
711
289
  COST 100
@@ -716,66 +294,150 @@ AS $BODY$
716
294
  declare
717
295
  _now timestamp without time zone := now();
718
296
  resoid bigint;
719
- entoid bigint;
720
- __inserted_oid bigint;
721
- _entvnum integer;
297
+ newresoid stsresource.oid%TYPE;
722
298
  BEGIN
723
- BEGIN
724
- -- Ensure we get the current non-deleted resource.
725
- resoid := (select oid from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
299
+ begin
300
+ resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
726
301
  exception
727
302
  when sqlstate '21000' then
728
303
  raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
729
- END;
304
+ end;
305
+
730
306
  if resoid is null then
731
307
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
732
- RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
308
+ RAISE 'resname and version not found or not current version within stsresource %', _resname USING ERRCODE = 'no_data_found';
733
309
  end if;
734
310
 
311
+ update stsresource set validto = _now where oid = resoid;
312
+
313
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
314
+ select r.resname, r.resdesc, r.resdesc::jsonb, _resvnum+1, 3, _dbactionuser, _now
315
+ from stsresource r where r.oid = resoid
316
+ RETURNING oid INTO newresoid;
317
+
318
+ update stsentity set resourceoid = newresoid where resourceoid = resoid;
319
+
320
+ return query
321
+ select * from stsresource where oid = newresoid;
322
+ END;
323
+ $BODY$;
324
+
325
+ ALTER FUNCTION public.delete_stsresource(character varying, character varying, integer)
326
+ OWNER TO postgres;
327
+
328
+
329
+
330
+ CREATE OR REPLACE FUNCTION public.delete_stsresource_latest(
331
+ _dbactionuser character varying,
332
+ _resname character varying)
333
+ RETURNS SETOF stsresource
334
+ LANGUAGE 'plpgsql'
335
+
336
+ COST 100
337
+ VOLATILE
338
+ ROWS 1000
339
+
340
+ AS $BODY$
341
+ declare
342
+ _now timestamp without time zone := now();
343
+ resoid bigint;
344
+ newresoid stsresource.oid%TYPE;
345
+ _resvnum integer;
346
+ BEGIN
735
347
  begin
736
- _entvnum = (select vnum from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3);
348
+ _resvnum := (select vnum from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
737
349
  exception
738
350
  when sqlstate '21000' then
739
- raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
351
+ raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
740
352
  end;
741
353
 
742
- -- Ensure we get the current non-deleted entity for this resource.
743
354
  begin
744
- entoid = (select oid from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.vnum = _entvnum and e.validto is null and e.dbaction != 3);
355
+ resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
745
356
  exception
746
357
  when sqlstate '21000' then
747
- raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
358
+ raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
748
359
  end;
749
360
 
750
- if entoid is null then
361
+ if resoid is null then
751
362
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
752
- RAISE 'entname and version not found or not current version (not deleted) within stsentity %', _entname USING ERRCODE = 'no_data_found';
363
+ RAISE 'resname and version not found or not current version within stsresource %', _resname USING ERRCODE = 'no_data_found';
753
364
  end if;
754
365
 
755
- update stsentity set validto = _now where oid = entoid;
756
-
757
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
758
- (select resoid, e.entname, e.entvalue, _entvnum+1, 3, _dbactionuser, _now
759
- from stsentity e where e.oid = entoid)
760
- returning oid into __inserted_oid;
366
+ update stsresource set validto = _now where oid = resoid;
367
+
368
+ insert into stsresource(resname, resdesc, resdesc_jsonb, vnum, dbaction, dbactionuser, validfrom)
369
+ select r.resname, r.resdesc, r.resdesc::jsonb, _resvnum+1, 3, _dbactionuser, _now
370
+ from stsresource r where r.oid = resoid
371
+ RETURNING oid INTO newresoid;
372
+
373
+ update stsentity set resourceoid = newresoid where resourceoid = resoid;
374
+
375
+ return query
376
+ select * from stsresource where oid = newresoid;
377
+ END;
378
+ $BODY$;
379
+
380
+ ALTER FUNCTION public.delete_stsresource_latest(character varying, character varying)
381
+ OWNER TO postgres;
382
+
383
+
384
+ -- Table: public.stsentity
385
+
386
+ -- DROP TABLE public.stsentity;
387
+
388
+ CREATE TABLE public.stsentity
389
+ (
390
+ oid bigint NOT NULL DEFAULT nextval('stsentity_oid_seq'::regclass),
391
+ resourceoid integer NOT NULL,
392
+ entname character varying(128) COLLATE pg_catalog."default" NOT NULL,
393
+ entvalue character varying(32768) COLLATE pg_catalog."default",
394
+ envalue_jsonb jsonb,
395
+ vnum bigint NOT NULL,
396
+ validfrom timestamp without time zone NOT NULL,
397
+ validto timestamp without time zone,
398
+ dbaction smallint NOT NULL,
399
+ dbactionuser character varying(64) COLLATE pg_catalog."default" NOT NULL,
400
+ CONSTRAINT stsentity_pkey PRIMARY KEY (oid),
401
+ CONSTRAINT fk_stsresource FOREIGN KEY (resourceoid)
402
+ REFERENCES public.stsresource (oid) MATCH SIMPLE
403
+ ON UPDATE NO ACTION
404
+ ON DELETE CASCADE
405
+ )
406
+ TABLESPACE pg_default;
407
+
408
+ ALTER TABLE public.stsentity
409
+ OWNER to postgres;
410
+
411
+ -- Index: stsentity_resourceoid_entname_vnum
761
412
 
762
- return query
763
- select * from stsentity where oid = __inserted_oid;
764
- END;
765
- $BODY$;
413
+ -- DROP INDEX public.stsentity_resourceoid_entname_vnum;
766
414
 
767
- ALTER FUNCTION public.delete_stsentity_latest(character varying, character varying, character varying)
768
- OWNER TO postgres;
415
+ CREATE UNIQUE INDEX stsentity_resourceoid_entname_vnum
416
+ ON public.stsentity USING btree
417
+ (resourceoid ASC NULLS LAST, entname COLLATE pg_catalog."default" ASC NULLS LAST, vnum ASC NULLS LAST)
418
+ TABLESPACE pg_default;
419
+
420
+ -- Index: stsentity_resourceoid_entname_validto
769
421
 
422
+ -- DROP INDEX public.stsentity_resourceoid_entname_validto;
770
423
 
424
+ CREATE INDEX stsentity_resourceoid_entname_validto
425
+ ON public.stsentity USING btree
426
+ (resourceoid ASC NULLS LAST, entname COLLATE pg_catalog."default" ASC NULLS LAST, validto DESC NULLS LAST)
427
+ TABLESPACE pg_default;
771
428
 
772
429
 
430
+ -- FUNCTION: public.create_stsentity(character varying, character varying, integer, character varying, character varying)
773
431
 
432
+ -- DROP FUNCTION public.create_stsentity(character varying, character varying, integer, character varying, character varying);
774
433
 
775
- CREATE OR REPLACE FUNCTION public.delete_stsresource_latest(
434
+ CREATE OR REPLACE FUNCTION public.create_stsentity(
776
435
  _dbactionuser character varying,
777
- _resname character varying)
778
- RETURNS SETOF stsresource
436
+ _resname character varying,
437
+ _resvnum integer,
438
+ _entname character varying,
439
+ _entvalue character varying)
440
+ RETURNS SETOF stsentity
779
441
  LANGUAGE 'plpgsql'
780
442
 
781
443
  COST 100
@@ -783,59 +445,52 @@ CREATE OR REPLACE FUNCTION public.delete_stsresource_latest(
783
445
  ROWS 1000
784
446
 
785
447
  AS $BODY$
786
- declare
787
- _now timestamp without time zone := now();
448
+ declare
788
449
  resoid bigint;
789
- newresoid stsresource.oid%TYPE;
790
- _resvnum integer;
450
+ __inserted_oid bigint;
451
+ _envalue_jsonb JSONB;
791
452
  BEGIN
792
453
  begin
793
- _resvnum := (select vnum from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
794
- exception
795
- when sqlstate '21000' then
796
- raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
797
- end;
798
-
799
- begin
800
- resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
454
+ _envalue_jsonb := _entvalue::jsonb;
801
455
  exception
802
- when sqlstate '21000' then
803
- raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
456
+ when others then
457
+ raise exception 'Invalid JSON string: %', _entvalue;
804
458
  end;
805
459
 
460
+ -- Ensure we get the current non-deleted resource.
461
+ resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
806
462
  if resoid is null then
807
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
808
- RAISE 'resname and version not found or not current version within stsresource %', _resname USING ERRCODE = 'no_data_found';
463
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
464
+ RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
809
465
  end if;
466
+ if (select count(*) from stsentity e
467
+ where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3) > 0 then
468
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
469
+ -- RAISE EXCEPTION 'resname already exists within stsresource %', now();
470
+ RAISE 'Duplicate entname within stsresource: %', _resname USING ERRCODE = 'unique_violation';
471
+ else
472
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
473
+ values (resoid, _entname, _entvalue, _envalue_jsonb, 1, 1, _dbactionuser, now())
474
+ returning oid into __inserted_oid;
810
475
 
811
- update stsresource set validto = _now where oid = resoid;
812
-
813
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
814
- select r.resname, r.resdesc, _resvnum+1, 3, _dbactionuser, _now
815
- from stsresource r where r.oid = resoid
816
- RETURNING oid INTO newresoid;
817
-
818
- update stsentity set resourceoid = newresoid where resourceoid = resoid;
819
-
820
- return query
821
- select * from stsresource where oid = newresoid;
476
+ return query
477
+ select * from stsentity where oid = __inserted_oid;
478
+ END IF;
822
479
  END;
823
480
  $BODY$;
824
481
 
825
- ALTER FUNCTION public.delete_stsresource_latest(character varying, character varying)
482
+ ALTER FUNCTION public.create_stsentity(character varying, character varying, integer, character varying, character varying)
826
483
  OWNER TO postgres;
827
484
 
828
485
 
829
486
 
830
- -- FUNCTION: public.delete_stsresource(character varying, character varying, integer)
831
-
832
- -- DROP FUNCTION public.delete_stsresource(character varying, character varying, integer);
833
487
 
834
- CREATE OR REPLACE FUNCTION public.delete_stsresource(
488
+ CREATE OR REPLACE FUNCTION public.create_stsentity_latest(
835
489
  _dbactionuser character varying,
836
490
  _resname character varying,
837
- _resvnum integer)
838
- RETURNS SETOF stsresource
491
+ _entname character varying,
492
+ _entvalue character varying)
493
+ RETURNS SETOF stsentity
839
494
  LANGUAGE 'plpgsql'
840
495
 
841
496
  COST 100
@@ -843,41 +498,45 @@ CREATE OR REPLACE FUNCTION public.delete_stsresource(
843
498
  ROWS 1000
844
499
 
845
500
  AS $BODY$
846
- declare
847
- _now timestamp without time zone := now();
501
+ declare
848
502
  resoid bigint;
849
- newresoid stsresource.oid%TYPE;
503
+ __inserted_oid bigint;
504
+ _envalue_jsonb JSONB;
850
505
  BEGIN
851
506
  begin
852
- resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
507
+ _envalue_jsonb := _entvalue::jsonb;
853
508
  exception
854
- when sqlstate '21000' then
855
- raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
509
+ when others then
510
+ raise exception 'Invalid JSON string: %', _entvalue;
856
511
  end;
857
512
 
513
+ -- Ensure we get the current non-deleted resource.
514
+ resoid := (select oid from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
858
515
  if resoid is null then
859
- -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
860
- RAISE 'resname and version not found or not current version within stsresource %', _resname USING ERRCODE = 'no_data_found';
516
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
517
+ RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
861
518
  end if;
519
+ if (select count(*) from stsentity e
520
+ where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3) > 0 then
521
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
522
+ -- RAISE EXCEPTION 'resname already exists within stsresource %', now();
523
+ RAISE 'Duplicate entname within stsresource: %', _resname USING ERRCODE = 'unique_violation';
524
+ else
525
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
526
+ values (resoid, _entname, _entvalue, _envalue_jsonb, 1, 1, _dbactionuser, now())
527
+ returning oid into __inserted_oid;
862
528
 
863
- update stsresource set validto = _now where oid = resoid;
864
-
865
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
866
- select r.resname, r.resdesc, _resvnum+1, 3, _dbactionuser, _now
867
- from stsresource r where r.oid = resoid
868
- RETURNING oid INTO newresoid;
869
-
870
- update stsentity set resourceoid = newresoid where resourceoid = resoid;
871
-
872
- return query
873
- select * from stsresource where oid = newresoid;
529
+ return query
530
+ select * from stsentity where oid = __inserted_oid;
531
+ END IF;
874
532
  END;
875
533
  $BODY$;
876
534
 
877
- ALTER FUNCTION public.delete_stsresource(character varying, character varying, integer)
535
+ ALTER FUNCTION public.create_stsentity_latest(character varying, character varying, character varying, character varying)
878
536
  OWNER TO postgres;
879
537
 
880
538
 
539
+
881
540
  -- FUNCTION: public.update_stsentity(character varying, character varying, integer, character varying, integer, character varying)
882
541
 
883
542
  -- DROP FUNCTION public.update_stsentity(character varying, character varying, integer, character varying, integer, character varying);
@@ -902,7 +561,15 @@ declare
902
561
  resoid bigint;
903
562
  entoid bigint;
904
563
  __inserted_oid bigint;
564
+ _envalue_jsonb JSONB;
905
565
  BEGIN
566
+ begin
567
+ _envalue_jsonb := _entvalue::jsonb;
568
+ exception
569
+ when others then
570
+ raise exception 'Invalid JSON string: %', _entvalue;
571
+ end;
572
+
906
573
  BEGIN
907
574
  -- Ensure we get the current non-deleted resource.
908
575
  resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
@@ -930,8 +597,8 @@ BEGIN
930
597
 
931
598
  update stsentity set validto = _now where oid = entoid;
932
599
 
933
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
934
- values (resoid, _entname, _entvalue, _entvnum+1, 2, _dbactionuser, _now)
600
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
601
+ values (resoid, _entname, _entvalue, _envalue_jsonb, _entvnum+1, 2, _dbactionuser, _now)
935
602
  returning oid into __inserted_oid;
936
603
 
937
604
  return query
@@ -965,7 +632,15 @@ declare
965
632
  entoid bigint;
966
633
  __inserted_oid bigint;
967
634
  _entvnum integer;
635
+ _envalue_jsonb JSONB;
968
636
  BEGIN
637
+ begin
638
+ _envalue_jsonb := _entvalue::jsonb;
639
+ exception
640
+ when others then
641
+ raise exception 'Invalid JSON string: %', _entvalue;
642
+ end;
643
+
969
644
  BEGIN
970
645
  -- Ensure we get the current non-deleted resource.
971
646
  resoid := (select oid from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
@@ -1000,8 +675,8 @@ BEGIN
1000
675
 
1001
676
  update stsentity set validto = _now where oid = entoid;
1002
677
 
1003
- insert into stsentity(resourceoid, entname, entvalue, vnum, dbaction, dbactionuser, validfrom)
1004
- values (resoid, _entname, _entvalue, _entvnum+1, 2, _dbactionuser, _now)
678
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
679
+ values (resoid, _entname, _entvalue, _envalue_jsonb, _entvnum+1, 2, _dbactionuser, _now)
1005
680
  returning oid into __inserted_oid;
1006
681
 
1007
682
  return query
@@ -1013,16 +688,17 @@ ALTER FUNCTION public.update_stsentity_latest(character varying, character varyi
1013
688
  OWNER TO postgres;
1014
689
 
1015
690
 
691
+ -- FUNCTION: public.delete_stsentity(character varying, character varying, integer, character varying, integer)
1016
692
 
1017
- -- FUNCTION: public.update_stsresource(character varying, character varying, integer, character varying)
1018
-
1019
- -- DROP FUNCTION public.update_stsresource(character varying, character varying, integer, character varying);
693
+ -- DROP FUNCTION public.delete_stsentity(character varying, character varying, integer, character varying, integer);
1020
694
 
1021
- CREATE OR REPLACE FUNCTION public.update_stsresource_latest(
695
+ CREATE OR REPLACE FUNCTION public.delete_stsentity(
1022
696
  _dbactionuser character varying,
1023
697
  _resname character varying,
1024
- _resdesc character varying)
1025
- RETURNS SETOF stsresource
698
+ _resvnum integer,
699
+ _entname character varying,
700
+ _entvnum integer)
701
+ RETURNS SETOF stsentity
1026
702
  LANGUAGE 'plpgsql'
1027
703
 
1028
704
  COST 100
@@ -1033,53 +709,59 @@ AS $BODY$
1033
709
  declare
1034
710
  _now timestamp without time zone := now();
1035
711
  resoid bigint;
1036
- newresoid stsresource.oid%TYPE;
1037
- _resvnum integer;
712
+ entoid bigint;
713
+ __inserted_oid bigint;
1038
714
  BEGIN
1039
- begin
1040
- _resvnum := (select vnum from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
715
+ BEGIN
716
+ -- Ensure we get the current non-deleted resource.
717
+ resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
1041
718
  exception
1042
719
  when sqlstate '21000' then
1043
720
  raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
1044
- end;
721
+ END;
722
+ if resoid is null then
723
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
724
+ RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
725
+ end if;
1045
726
 
727
+ -- Ensure we get the current non-deleted entity for this resource.
1046
728
  begin
1047
- resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
729
+ entoid = (select oid from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.vnum = _entvnum and e.validto is null and e.dbaction != 3);
1048
730
  exception
1049
731
  when sqlstate '21000' then
1050
- raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
732
+ raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
1051
733
  end;
1052
734
 
1053
- if resoid is null then
735
+ if entoid is null then
1054
736
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
1055
- RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
737
+ RAISE 'entname and version not found or not current version (not deleted) within stsentity %', _entname USING ERRCODE = 'no_data_found';
1056
738
  end if;
1057
739
 
1058
- update stsresource set validto = _now where oid = resoid;
740
+ update stsentity set validto = _now where oid = entoid;
741
+
742
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
743
+ (select resoid, e.entname, e.entvalue, e.entvalue::jsonb, _entvnum+1, 3, _dbactionuser, _now
744
+ from stsentity e where e.oid = entoid)
745
+ returning oid into __inserted_oid;
1059
746
 
1060
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
1061
- values (_resname, _resdesc, _resvnum+1, 2, _dbactionuser, _now)
1062
- RETURNING oid INTO newresoid;
1063
-
1064
- update stsentity set resourceoid = newresoid where resourceoid = resoid;
1065
-
1066
747
  return query
1067
- select * from stsresource where oid = newresoid;
748
+ select * from stsentity where oid = __inserted_oid;
1068
749
  END;
1069
750
  $BODY$;
1070
751
 
1071
- ALTER FUNCTION public.update_stsresource_latest(character varying, character varying, character varying)
752
+ ALTER FUNCTION public.delete_stsentity(character varying, character varying, integer, character varying, integer)
1072
753
  OWNER TO postgres;
1073
754
 
1074
755
 
1075
756
 
1076
757
 
1077
- CREATE OR REPLACE FUNCTION public.update_stsresource(
758
+
759
+
760
+ CREATE OR REPLACE FUNCTION public.delete_stsentity_latest(
1078
761
  _dbactionuser character varying,
1079
762
  _resname character varying,
1080
- _resvnum integer,
1081
- _resdesc character varying)
1082
- RETURNS SETOF stsresource
763
+ _entname character varying)
764
+ RETURNS SETOF stsentity
1083
765
  LANGUAGE 'plpgsql'
1084
766
 
1085
767
  COST 100
@@ -1090,397 +772,55 @@ AS $BODY$
1090
772
  declare
1091
773
  _now timestamp without time zone := now();
1092
774
  resoid bigint;
1093
- newresoid stsresource.oid%TYPE;
775
+ entoid bigint;
776
+ __inserted_oid bigint;
777
+ _entvnum integer;
1094
778
  BEGIN
1095
- begin
1096
- resoid := (select oid from stsresource r where r.resname = _resname and r.vnum = _resvnum and r.validto is null and r.dbaction != 3);
779
+ BEGIN
780
+ -- Ensure we get the current non-deleted resource.
781
+ resoid := (select oid from stsresource r where r.resname = _resname and r.validto is null and r.dbaction != 3);
1097
782
  exception
1098
783
  when sqlstate '21000' then
1099
784
  raise exception 'Too many stsresource records for current version using stsresource %', _resname USING ERRCODE = 'cardinality_violation';
1100
- end;
1101
-
785
+ END;
1102
786
  if resoid is null then
1103
787
  -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
1104
788
  RAISE 'resname and version not found or not current version (not deleted) within stsresource %', _resname USING ERRCODE = 'no_data_found';
1105
789
  end if;
1106
790
 
1107
- update stsresource set validto = _now where oid = resoid;
1108
-
1109
- insert into stsresource(resname, resdesc, vnum, dbaction, dbactionuser, validfrom)
1110
- values (_resname, _resdesc, _resvnum+1, 2, _dbactionuser, _now)
1111
- RETURNING oid INTO newresoid;
1112
-
1113
- update stsentity set resourceoid = newresoid where resourceoid = resoid;
1114
-
1115
- return query
1116
- select * from stsresource where oid = newresoid;
1117
- END;
1118
- $BODY$;
1119
-
1120
- ALTER FUNCTION public.update_stsresource(character varying, character varying, integer, character varying)
1121
- OWNER TO postgres;
1122
-
1123
-
1124
- --- [ Queries ] ------------------------------------------------------------------------------------
1125
-
1126
- -- DROP FUNCTION get_monitor_summary()
1127
- -- select * from get_monitor_summary()
1128
- -- Shows all services currently running
1129
- CREATE OR REPLACE FUNCTION public.get_monitor_summary()
1130
- RETURNS TABLE
1131
- (serviceid character varying,
1132
- request_count_gauge integer,
1133
- error_count_gauge integer,
1134
- retry_count_gauge integer,
1135
- authentication_count_gauge integer,
1136
- velocity_gauge numeric,
1137
- cpu_load_gauge numeric,
1138
- active_request_gauge integer,
1139
- connection_count_gauge integer,
1140
- connection_pool_total_gauge integer,
1141
- connection_pool_idle_gauge integer,
1142
- connection_pool_waiting_gauge integer,
1143
- core_count_gauge integer,
1144
- timer_gauge numeric,
1145
- duration_gauge numeric,
1146
- latency_gauge numeric,
1147
- duration_histogram_gauge_1 integer,
1148
- duration_histogram_gauge_2 integer,
1149
- duration_histogram_gauge_3 integer,
1150
- duration_histogram_gauge_4 integer,
1151
- duration_histogram_gauge_5 integer,
1152
- duration_histogram_gauge_6 integer,
1153
- duration_histogram_gauge_7 integer,
1154
- latency_histogram_gauge_1 integer,
1155
- latency_histogram_gauge_2 integer,
1156
- latency_histogram_gauge_3 integer,
1157
- latency_histogram_gauge_4 integer,
1158
- latency_histogram_gauge_5 integer,
1159
- latency_histogram_gauge_6 integer,
1160
- latency_histogram_gauge_7 integer)
1161
- LANGUAGE 'plpgsql'
1162
- AS $$
1163
- BEGIN
1164
- -- Show all services
1165
- -- Top level query
1166
- RETURN QUERY
1167
- select
1168
- '_'::character varying as serviceid,
1169
- sum(m.request_count_gauge)::integer as request_count_gauge,
1170
- sum(m.error_count_gauge)::integer as error_count_gauge,
1171
- sum(m.retry_count_gauge)::integer as retry_count_gauge,
1172
- sum(m.authentication_count_gauge)::integer as authentication_count_gauge,
1173
- sum(m.velocity_gauge)::numeric as velocity_gauge,
1174
- sum(m.cpu_load_gauge)::numeric as cpu_load_gauge,
1175
- sum(m.active_request_gauge)::integer as active_request_gauge,
1176
- sum(m.connection_count_gauge)::integer as connection_count_gauge,
1177
- sum(m.connection_pool_total_gauge)::integer as connection_pool_total_gauge,
1178
- sum(m.connection_pool_idle_gauge)::integer as connection_pool_idle_gauge,
1179
- sum(m.connection_pool_waiting_gauge)::integer as connection_pool_waiting_gauge,
1180
- sum(m.core_count_gauge)::integer as core_count_gauge,
1181
- avg(m.timer_gauge)::numeric as timer_gauge, -- needs to be raw
1182
- avg(m.duration_gauge)::numeric as duration_gauge,
1183
- avg(m.latency_gauge)::numeric as latency_gauge,
1184
- sum(m.duration_histogram_gauge[1])::integer as duration_histogram_gauge_1,
1185
- sum(m.duration_histogram_gauge[2])::integer as duration_histogram_gauge_2,
1186
- sum(m.duration_histogram_gauge[3])::integer as duration_histogram_gauge_3,
1187
- sum(m.duration_histogram_gauge[4])::integer as duration_histogram_gauge_4,
1188
- sum(m.duration_histogram_gauge[5])::integer as duration_histogram_gauge_5,
1189
- sum(m.duration_histogram_gauge[6])::integer as duration_histogram_gauge_6,
1190
- sum(m.duration_histogram_gauge[7])::integer as duration_histogram_gauge_7,
1191
- sum(m.latency_histogram_gauge[1])::integer as latency_histogram_gauge_1,
1192
- sum(m.latency_histogram_gauge[2])::integer as latency_histogram_gauge_2,
1193
- sum(m.latency_histogram_gauge[3])::integer as latency_histogram_gauge_3,
1194
- sum(m.latency_histogram_gauge[4])::integer as latency_histogram_gauge_4,
1195
- sum(m.latency_histogram_gauge[5])::integer as latency_histogram_gauge_5,
1196
- sum(m.latency_histogram_gauge[6])::integer as latency_histogram_gauge_6,
1197
- sum(m.latency_histogram_gauge[7])::integer as latency_histogram_gauge_7
1198
- from stsmonitor m;
1199
- END
1200
- $$;
1201
-
1202
- ALTER FUNCTION public.get_monitor_summary()
1203
- OWNER TO postgres;
1204
-
791
+ begin
792
+ _entvnum = (select vnum from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.validto is null and e.dbaction != 3);
793
+ exception
794
+ when sqlstate '21000' then
795
+ raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
796
+ end;
1205
797
 
1206
- -- DROP FUNCTION get_monitor_summary()
1207
- -- select * from get_monitor_summary()
1208
- -- Shows all services currently running
1209
- CREATE OR REPLACE FUNCTION public.get_monitor_service_summary()
1210
- RETURNS TABLE
1211
- (serviceid character varying,
1212
- request_count_gauge integer,
1213
- error_count_gauge integer,
1214
- retry_count_gauge integer,
1215
- authentication_count_gauge integer,
1216
- velocity_gauge numeric,
1217
- cpu_load_gauge numeric,
1218
- active_request_gauge integer,
1219
- connection_count_gauge integer,
1220
- connection_pool_total_gauge integer,
1221
- connection_pool_idle_gauge integer,
1222
- connection_pool_waiting_gauge integer,
1223
- core_count_gauge integer,
1224
- timer_gauge numeric,
1225
- duration_gauge numeric,
1226
- latency_gauge numeric,
1227
- duration_histogram_gauge_1 integer,
1228
- duration_histogram_gauge_2 integer,
1229
- duration_histogram_gauge_3 integer,
1230
- duration_histogram_gauge_4 integer,
1231
- duration_histogram_gauge_5 integer,
1232
- duration_histogram_gauge_6 integer,
1233
- duration_histogram_gauge_7 integer,
1234
- latency_histogram_gauge_1 integer,
1235
- latency_histogram_gauge_2 integer,
1236
- latency_histogram_gauge_3 integer,
1237
- latency_histogram_gauge_4 integer,
1238
- latency_histogram_gauge_5 integer,
1239
- latency_histogram_gauge_6 integer,
1240
- latency_histogram_gauge_7 integer)
1241
- LANGUAGE 'plpgsql'
1242
- AS $$
1243
- BEGIN
1244
- -- Show all services
1245
- -- Top level query
1246
- RETURN QUERY
1247
- select
1248
- m.serviceid,
1249
- sum(m.request_count_gauge)::integer as request_count_gauge,
1250
- sum(m.error_count_gauge)::integer as error_count_gauge,
1251
- sum(m.retry_count_gauge)::integer as retry_count_gauge,
1252
- sum(m.authentication_count_gauge)::integer as authentication_count_gauge,
1253
- sum(m.velocity_gauge)::numeric as velocity_gauge,
1254
- sum(m.cpu_load_gauge)::numeric as cpu_load_gauge,
1255
- sum(m.active_request_gauge)::integer as active_request_gauge,
1256
- sum(m.connection_count_gauge)::integer as connection_count_gauge,
1257
- sum(m.connection_pool_total_gauge)::integer as connection_pool_total_gauge,
1258
- sum(m.connection_pool_idle_gauge)::integer as connection_pool_idle_gauge,
1259
- sum(m.connection_pool_waiting_gauge)::integer as connection_pool_waiting_gauge,
1260
- sum(m.core_count_gauge)::integer as core_count_gauge,
1261
- avg(m.timer_gauge)::numeric as timer_gauge, -- needs to be raw
1262
- avg(m.duration_gauge)::numeric as duration_gauge,
1263
- avg(m.latency_gauge)::numeric as latency_gauge,
1264
- sum(m.duration_histogram_gauge[1])::integer as duration_histogram_gauge_1,
1265
- sum(m.duration_histogram_gauge[2])::integer as duration_histogram_gauge_2,
1266
- sum(m.duration_histogram_gauge[3])::integer as duration_histogram_gauge_3,
1267
- sum(m.duration_histogram_gauge[4])::integer as duration_histogram_gauge_4,
1268
- sum(m.duration_histogram_gauge[5])::integer as duration_histogram_gauge_5,
1269
- sum(m.duration_histogram_gauge[6])::integer as duration_histogram_gauge_6,
1270
- sum(m.duration_histogram_gauge[7])::integer as duration_histogram_gauge_7,
1271
- sum(m.latency_histogram_gauge[1])::integer as latency_histogram_gauge_1,
1272
- sum(m.latency_histogram_gauge[2])::integer as latency_histogram_gauge_2,
1273
- sum(m.latency_histogram_gauge[3])::integer as latency_histogram_gauge_3,
1274
- sum(m.latency_histogram_gauge[4])::integer as latency_histogram_gauge_4,
1275
- sum(m.latency_histogram_gauge[5])::integer as latency_histogram_gauge_5,
1276
- sum(m.latency_histogram_gauge[6])::integer as latency_histogram_gauge_6,
1277
- sum(m.latency_histogram_gauge[7])::integer as latency_histogram_gauge_7
1278
- from stsmonitor m
1279
- group by m.serviceid
1280
- order by m.serviceid;
1281
- END
1282
- $$;
1283
-
1284
- ALTER FUNCTION public.get_monitor_service_summary()
1285
- OWNER TO postgres;
798
+ -- Ensure we get the current non-deleted entity for this resource.
799
+ begin
800
+ entoid = (select oid from stsentity e where e.resourceoid = resoid and e.entname = _entname and e.vnum = _entvnum and e.validto is null and e.dbaction != 3);
801
+ exception
802
+ when sqlstate '21000' then
803
+ raise exception 'Too many stsentity records for current version using stsentity %', _entname USING ERRCODE = 'cardinality_violation';
804
+ end;
1286
805
 
806
+ if entoid is null then
807
+ -- Exception Codes: https://www.postgresql.org/docs/10/errcodes-appendix.html
808
+ RAISE 'entname and version not found or not current version (not deleted) within stsentity %', _entname USING ERRCODE = 'no_data_found';
809
+ end if;
1287
810
 
1288
- -- DROP FUNCTION get_monitor_summary_by_serviceid()
1289
- -- select * from get_monitor_summary()
1290
- -- select * from get_monitor_summary_by_serviceid('STSAuth@1.0.0')
1291
- -- Shows all instances for this serviceid
1292
- CREATE OR REPLACE FUNCTION public.get_monitor_summary_by_serviceid(
1293
- _serviceid character varying)
1294
- RETURNS TABLE
1295
- (serviceid character varying,
1296
- serviceinstanceid character varying,
1297
- request_count_gauge integer,
1298
- error_count_gauge integer,
1299
- retry_count_gauge integer,
1300
- authentication_count_gauge integer,
1301
- velocity_gauge numeric,
1302
- cpu_load_gauge numeric,
1303
- active_request_gauge integer,
1304
- connection_count_gauge integer,
1305
- connection_pool_total_gauge integer,
1306
- connection_pool_idle_gauge integer,
1307
- connection_pool_waiting_gauge integer,
1308
- core_count_gauge integer,
1309
- timer_gauge numeric,
1310
- duration_gauge numeric,
1311
- latency_gauge numeric,
1312
- duration_histogram_gauge_1 integer,
1313
- duration_histogram_gauge_2 integer,
1314
- duration_histogram_gauge_3 integer,
1315
- duration_histogram_gauge_4 integer,
1316
- duration_histogram_gauge_5 integer,
1317
- duration_histogram_gauge_6 integer,
1318
- duration_histogram_gauge_7 integer,
1319
- latency_histogram_gauge_1 integer,
1320
- latency_histogram_gauge_2 integer,
1321
- latency_histogram_gauge_3 integer,
1322
- latency_histogram_gauge_4 integer,
1323
- latency_histogram_gauge_5 integer,
1324
- latency_histogram_gauge_6 integer,
1325
- latency_histogram_gauge_7 integer)
1326
- LANGUAGE 'plpgsql'
1327
- AS $$
1328
- BEGIN
1329
- -- Show all services
1330
- -- Top level query
1331
- RETURN QUERY
1332
- select
1333
- m.serviceid,
1334
- m.serviceinstanceid,
1335
- sum(m.request_count_gauge)::integer as request_count_gauge,
1336
- sum(m.error_count_gauge)::integer as error_count_gauge,
1337
- sum(m.retry_count_gauge)::integer as retry_count_gauge,
1338
- sum(m.authentication_count_gauge)::integer as authentication_count_gauge,
1339
- sum(m.velocity_gauge)::numeric as velocity_gauge,
1340
- sum(m.cpu_load_gauge)::numeric as cpu_load_gauge,
1341
- sum(m.active_request_gauge)::integer as active_request_gauge,
1342
- sum(m.connection_count_gauge)::integer as connection_count_gauge,
1343
- sum(m.connection_pool_total_gauge)::integer as connection_pool_total_gauge,
1344
- sum(m.connection_pool_idle_gauge)::integer as connection_pool_idle_gauge,
1345
- sum(m.connection_pool_waiting_gauge)::integer as connection_pool_waiting_gauge,
1346
- sum(m.core_count_gauge)::integer as core_count_gauge,
1347
- avg(m.timer_gauge)::numeric as timer_gauge, -- needs to be raw
1348
- avg(m.duration_gauge)::numeric as duration_gauge,
1349
- avg(m.latency_gauge)::numeric as latency_gauge,
1350
- sum(m.duration_histogram_gauge[1])::integer as duration_histogram_gauge_1,
1351
- sum(m.duration_histogram_gauge[2])::integer as duration_histogram_gauge_2,
1352
- sum(m.duration_histogram_gauge[3])::integer as duration_histogram_gauge_3,
1353
- sum(m.duration_histogram_gauge[4])::integer as duration_histogram_gauge_4,
1354
- sum(m.duration_histogram_gauge[5])::integer as duration_histogram_gauge_5,
1355
- sum(m.duration_histogram_gauge[6])::integer as duration_histogram_gauge_6,
1356
- sum(m.duration_histogram_gauge[7])::integer as duration_histogram_gauge_7,
1357
- sum(m.latency_histogram_gauge[1])::integer as latency_histogram_gauge_1,
1358
- sum(m.latency_histogram_gauge[2])::integer as latency_histogram_gauge_2,
1359
- sum(m.latency_histogram_gauge[3])::integer as latency_histogram_gauge_3,
1360
- sum(m.latency_histogram_gauge[4])::integer as latency_histogram_gauge_4,
1361
- sum(m.latency_histogram_gauge[5])::integer as latency_histogram_gauge_5,
1362
- sum(m.latency_histogram_gauge[6])::integer as latency_histogram_gauge_6,
1363
- sum(m.latency_histogram_gauge[7])::integer as latency_histogram_gauge_7
1364
- from stsmonitor m
1365
- group by m.serviceid, m.serviceinstanceid
1366
- having m.serviceid = _serviceid
1367
- order by m.serviceid, m.serviceinstanceid;
1368
- END
1369
- $$;
1370
-
1371
- ALTER FUNCTION public.get_monitor_summary_by_serviceid(character varying)
1372
- OWNER TO postgres;
811
+ update stsentity set validto = _now where oid = entoid;
812
+
813
+ insert into stsentity(resourceoid, entname, entvalue, envalue_jsonb, vnum, dbaction, dbactionuser, validfrom)
814
+ (select resoid, e.entname, e.entvalue, e.entvalue::jsonb, _entvnum+1, 3, _dbactionuser, _now
815
+ from stsentity e where e.oid = entoid)
816
+ returning oid into __inserted_oid;
1373
817
 
818
+ return query
819
+ select * from stsentity where oid = __inserted_oid;
820
+ END;
821
+ $BODY$;
1374
822
 
1375
- -- select * from stsmonitor where serviceinstanceid = 'e2a83340-7b0b-4283-be67-d43ff110bfd3@12900k-14-91'
1376
- -- DROP FUNCTION get_monitor_summary_by_serviceinstanceid
1377
- -- select * from get_monitor_summary()
1378
- -- select * from get_monitor_summary_by_serviceid('STSAuth@1.0.0')
1379
- -- select * from get_monitor_summary_by_serviceinstanceid('e2a83340-7b0b-4283-be67-d43ff110bfd3@12900k-14-91')
1380
- -- Shows all threads for this service instance id
1381
- CREATE OR REPLACE FUNCTION public.get_monitor_summary_by_serviceinstanceid(
1382
- _serviceinstanceid character varying)
1383
- RETURNS TABLE
1384
- (serviceid character varying,
1385
- serviceinstanceid character varying,
1386
- pid integer,
1387
- ppid integer,
1388
- request_count_gauge integer,
1389
- error_count_gauge integer,
1390
- retry_count_gauge integer,
1391
- authentication_count_gauge integer,
1392
- velocity_gauge numeric,
1393
- cpu_load_gauge numeric,
1394
- active_request_gauge integer,
1395
- connection_count_gauge integer,
1396
- connection_pool_total_gauge integer,
1397
- connection_pool_idle_gauge integer,
1398
- connection_pool_waiting_gauge integer,
1399
- core_count_gauge integer,
1400
- timer_gauge numeric,
1401
- duration_gauge numeric,
1402
- latency_gauge numeric,
1403
- duration_histogram_gauge_1 integer,
1404
- duration_histogram_gauge_2 integer,
1405
- duration_histogram_gauge_3 integer,
1406
- duration_histogram_gauge_4 integer,
1407
- duration_histogram_gauge_5 integer,
1408
- duration_histogram_gauge_6 integer,
1409
- duration_histogram_gauge_7 integer,
1410
- latency_histogram_gauge_1 integer,
1411
- latency_histogram_gauge_2 integer,
1412
- latency_histogram_gauge_3 integer,
1413
- latency_histogram_gauge_4 integer,
1414
- latency_histogram_gauge_5 integer,
1415
- latency_histogram_gauge_6 integer,
1416
- latency_histogram_gauge_7 integer)
1417
- LANGUAGE 'plpgsql'
1418
- AS $$
1419
- BEGIN
1420
- -- Show all services
1421
- -- Top level query
1422
- RETURN QUERY
1423
- select
1424
- m.serviceid,
1425
- m.serviceinstanceid,
1426
- m.pid,
1427
- m.ppid,
1428
- sum(m.request_count_gauge)::integer as request_count_gauge,
1429
- sum(m.error_count_gauge)::integer as error_count_gauge,
1430
- sum(m.retry_count_gauge)::integer as retry_count_gauge,
1431
- sum(m.authentication_count_gauge)::integer as authentication_count_gauge,
1432
- sum(m.velocity_gauge)::numeric as velocity_gauge,
1433
- sum(m.cpu_load_gauge)::numeric as cpu_load_gauge,
1434
- sum(m.active_request_gauge)::integer as active_request_gauge,
1435
- sum(m.connection_count_gauge)::integer as connection_count_gauge,
1436
- sum(m.connection_pool_total_gauge)::integer as connection_pool_total_gauge,
1437
- sum(m.connection_pool_idle_gauge)::integer as connection_pool_idle_gauge,
1438
- sum(m.connection_pool_waiting_gauge)::integer as connection_pool_waiting_gauge,
1439
- sum(m.core_count_gauge)::integer as core_count_gauge,
1440
- avg(m.timer_gauge)::numeric as timer_gauge, -- needs to be raw
1441
- avg(m.duration_gauge)::numeric as duration_gauge,
1442
- avg(m.latency_gauge)::numeric as latency_gauge,
1443
- sum(m.duration_histogram_gauge[1])::integer as duration_histogram_gauge_1,
1444
- sum(m.duration_histogram_gauge[2])::integer as duration_histogram_gauge_2,
1445
- sum(m.duration_histogram_gauge[3])::integer as duration_histogram_gauge_3,
1446
- sum(m.duration_histogram_gauge[4])::integer as duration_histogram_gauge_4,
1447
- sum(m.duration_histogram_gauge[5])::integer as duration_histogram_gauge_5,
1448
- sum(m.duration_histogram_gauge[6])::integer as duration_histogram_gauge_6,
1449
- sum(m.duration_histogram_gauge[7])::integer as duration_histogram_gauge_7,
1450
- sum(m.latency_histogram_gauge[1])::integer as latency_histogram_gauge_1,
1451
- sum(m.latency_histogram_gauge[2])::integer as latency_histogram_gauge_2,
1452
- sum(m.latency_histogram_gauge[3])::integer as latency_histogram_gauge_3,
1453
- sum(m.latency_histogram_gauge[4])::integer as latency_histogram_gauge_4,
1454
- sum(m.latency_histogram_gauge[5])::integer as latency_histogram_gauge_5,
1455
- sum(m.latency_histogram_gauge[6])::integer as latency_histogram_gauge_6,
1456
- sum(m.latency_histogram_gauge[7])::integer as latency_histogram_gauge_7
1457
- from stsmonitor m
1458
- group by m.serviceid, m.serviceinstanceid, m.pid, m.ppid
1459
- having m.serviceinstanceid = _serviceinstanceid
1460
- order by m.serviceid, m.serviceinstanceid, m.pid, m.ppid;
1461
- END
1462
- $$;
1463
-
1464
- ALTER FUNCTION public.get_monitor_summary_by_serviceinstanceid(character varying)
823
+ ALTER FUNCTION public.delete_stsentity_latest(character varying, character varying, character varying)
1465
824
  OWNER TO postgres;
1466
825
 
1467
826
 
1468
- -- DROP FUNCTION purge_old_monitor_data(integer)
1469
- -- select * from purge_old_monitor_data(3) as rowsdel
1470
- CREATE OR REPLACE FUNCTION public.purge_old_monitor_data(
1471
- _keep_age_seconds integer)
1472
- RETURNS INTEGER
1473
- LANGUAGE 'plpgsql'
1474
- AS $$
1475
- DECLARE
1476
- rows_deleted INTEGER;
1477
- BEGIN
1478
- delete from stsmonitor m
1479
- where EXTRACT(EPOCH FROM (now() - m.validfrom)) > _keep_age_seconds;
1480
- GET DIAGNOSTICS rows_deleted = ROW_COUNT;
1481
- RETURN rows_deleted;
1482
- END
1483
- $$;
1484
-
1485
- ALTER FUNCTION public.purge_old_monitor_data(integer)
1486
- OWNER TO postgres;