pmcf 6.64.1 → 6.64.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "6.64.1",
3
+ "version": "6.64.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/cluster.mjs CHANGED
@@ -1,22 +1,25 @@
1
- import { duration_attribute_writable} from "pacc";
2
- import { host } from "./host.mjs";
3
-
1
+ import {
2
+ duration_attribute_writable,
3
+ default_collection_attribute_writable
4
+ } from "pacc";
4
5
  import { addType } from "./type.mjs";
5
- import { networkInterfaces_attribute } from "./common-attributes.mjs";
6
+ import { owner_attribute } from "./common-attributes.mjs";
7
+ import { host } from "./host.mjs";
6
8
 
7
9
  export class cluster extends host {
8
10
  static priority = 1.5;
9
11
  static attributes = {
10
12
  members: {
11
- ...networkInterfaces_attribute,
13
+ ...default_collection_attribute_writable,
14
+ type: "core",
15
+ backpointer: owner_attribute,
12
16
  name: "members"
13
17
  },
14
- checkInterval: {
15
- ...duration_attribute_writable,
16
- name: "checkInterval",
17
- default: 60
18
- },
19
-
18
+ checkInterval: {
19
+ ...duration_attribute_writable,
20
+ name: "checkInterval",
21
+ default: 60
22
+ }
20
23
  };
21
24
 
22
25
  static {
@@ -6,13 +6,18 @@ import {
6
6
  } from "pacc";
7
7
  import { FAMILY_IPV4 } from "ip-utilties";
8
8
  import { addType } from "../type.mjs";
9
+ import { PROTOCOL_TCP } from "../constants.mjs";
9
10
  import { core } from "../core.mjs";
10
11
  import { credential } from "../credential.mjs";
11
12
  import { CoreService, serviceEndpoints } from "../core-service.mjs";
12
- import { PROTOCOL_TCP } from "../constants.mjs";
13
13
 
14
14
  import { writeLines } from "../utils.mjs";
15
15
 
16
+ const ROLE_PRIORITIES = {
17
+ master: 10,
18
+ backup: 0
19
+ };
20
+
16
21
  export class keepalive_cluster_member extends core {
17
22
  static attributes = {
18
23
  cluster: {
@@ -23,7 +28,7 @@ export class keepalive_cluster_member extends core {
23
28
  role: {
24
29
  ...enum_string_attribute_writable,
25
30
  name: "role",
26
- values: new Set(["master", "backup"])
31
+ values: new Set(Object.keys(ROLE_PRIORITIES))
27
32
  }
28
33
  };
29
34
  static key = "cluster";
@@ -51,6 +56,10 @@ export class keepalive_cluster_member extends core {
51
56
  get address() {
52
57
  return this.owner.owner.address;
53
58
  }
59
+
60
+ get priority() {
61
+ return this.owner.priority + ROLE_PRIORITIES[this.role];
62
+ }
54
63
  }
55
64
 
56
65
  export class keepalived extends CoreService {
@@ -67,39 +76,37 @@ export class keepalived extends CoreService {
67
76
  addType(this);
68
77
  }
69
78
 
70
- clusters = new Map();
71
- checkInterval = 60;
79
+ clusters = new Set();
72
80
 
73
81
  async *preparePackages(dir) {
74
82
  const packageData = await this.preparePackage(dir);
75
83
 
76
- for (const clusterMember of this.clusters.values()) {
77
- const cluster = clusterMember.cluster;
78
- const host = cluster.host;
79
-
80
- const extra = [];
84
+ const extra = [];
81
85
 
82
- const smtp = this.smtp;
86
+ const smtp = this.smtp;
83
87
 
84
- if (smtp) {
85
- extra.push(` smtp_server ${smtp.address()}`);
86
- }
88
+ if (smtp) {
89
+ extra.push(` smtp_server ${smtp.address()}`);
90
+ }
87
91
 
88
- const cfg = [
89
- "global_defs {",
90
- " notification_email {",
91
- " " + this.administratorEmail,
92
- " }",
93
- ...extra,
94
- ` notification_email_from keepalived@${host.domainName}`,
95
- " enable_script_security",
96
- " script_user root",
97
- " max_auto_priority 20",
98
- "}",
99
- ""
100
- ];
92
+ const cfg = [
93
+ "global_defs {",
94
+ " notification_email {",
95
+ " " + this.administratorEmail,
96
+ " }",
97
+ ...extra,
98
+ ` notification_email_from keepalived@${this.domainName}`,
99
+ " enable_script_security",
100
+ " script_user root",
101
+ " max_auto_priority 20",
102
+ "}",
103
+ ""
104
+ ];
101
105
 
106
+ for (const clusterMember of this.clusters.values()) {
107
+ const cluster = clusterMember.cluster;
102
108
  const clusterName = cluster.name;
109
+
103
110
  cfg.push(`vrrp_instance ${clusterName} {`);
104
111
  cfg.push(` state ${clusterMember.role.toUpperCase()}`);
105
112
 
@@ -123,20 +130,13 @@ export class keepalived extends CoreService {
123
130
 
124
131
  cfg.push(` virtual_router_id ${cluster.id}`);
125
132
 
126
- let reducedPrio = 0;
127
- /*
128
- let reducedPrio = cluster.masters.indexOf(ni);
129
- if (reducedPrio < 0) {
130
- reducedPrio = cluster.backups.indexOf(ni) + 5;
131
- }
132
- */
133
133
  const cred = new credential(this);
134
134
  cred.name = `keepalived.${clusterName}.password`;
135
135
  cred.localName = clusterName.toUpperCase() + "_PASSWORD";
136
136
  cred._tags.add("keepalived.service");
137
137
  this.credentials.set(cred.name, cred);
138
138
 
139
- cfg.push(` priority ${host.priority - reducedPrio}`);
139
+ cfg.push(` priority ${clusterMember.priority}`);
140
140
  cfg.push(" smtp_alert");
141
141
  cfg.push(" advert_int 5");
142
142
  cfg.push(" authentication {");
@@ -170,7 +170,7 @@ export class keepalived extends CoreService {
170
170
  `services[types[${endpoint.type}]][0]`
171
171
  );
172
172
 
173
- console.log(member.fullName, endpoint.type, memberService?.fullName);
173
+ //console.log(member.fullName, endpoint.type, memberService?.fullName);
174
174
  cfg.push(` real_server ${member.address} ${memberService.port} {`);
175
175
  cfg.push(` weight ${memberService.weight}`);
176
176