forked from infinispan/infinispan-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleServices.ts
More file actions
161 lines (138 loc) · 5.1 KB
/
ConsoleServices.ts
File metadata and controls
161 lines (138 loc) · 5.1 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
import { AuthenticationService } from '@services/authService';
import { FetchCaller } from '@services/fetchCaller';
import { ProtobufService } from '@services/protobufService';
import { TasksService } from '@services/tasksService';
import { ServerService } from '@services/serverService';
import { CountersService } from '@services/countersService';
import { CrossSiteReplicationService } from '@services/crossSiteReplicationService';
import { CacheService } from '@services/cacheService';
import { ContainerService } from '@services/dataContainerService';
import { SecurityService } from '@services/securityService';
import { SearchService } from '@services/searchService';
import { ClusterService } from '@services/clusterService';
/**
* Infinispan Console Services
*/
export class ConsoleServices {
private initialized = false;
private static instance: ConsoleServices = new ConsoleServices();
private fetchCaller;
private authenticationService;
private countersService;
private serverService;
private taskService;
private protobufService;
private xsiteReplicationService;
private cacheService;
private dataContainerService;
private userService;
private searchService;
private clusterService;
private constructor() {
this.initialized = false;
}
public static get Instance(): ConsoleServices {
return this.instance;
}
public static isDevMode(): boolean {
return !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
}
public static endpoint(): string {
if (ConsoleServices.isDevMode()) {
if (!process.env.INFINISPAN_SERVER_URL) {
return 'http://localhost:11222/rest/v2';
} else {
return process.env.INFINISPAN_SERVER_URL + '/rest/v2';
}
} else {
const x = window as any;
return window.location.origin.toString() + (x.INFINISPAN_CONFIG?.restContextPath || '/rest') + '/v2';
}
}
public static landing(): string {
if (ConsoleServices.isDevMode()) {
return 'http://localhost:9000/console/';
} else {
return window.location.origin.toString() + '/console';
}
}
public static isWelcomePage(): boolean {
return location.pathname == '/console/welcome' || location.pathname == '/console/welcome/';
}
public static init(user?: string, password?: string) {
if (!this.instance.initialized) {
console.info('Init Console Services');
this.instance.authenticationService = new AuthenticationService(ConsoleServices.endpoint());
this.instance.fetchCaller = new FetchCaller(this.instance.authenticationService, user, password);
this.instance.protobufService = new ProtobufService(
ConsoleServices.endpoint() + '/schemas',
this.instance.fetchCaller
);
this.instance.taskService = new TasksService(ConsoleServices.endpoint() + '/tasks', this.instance.fetchCaller);
this.instance.serverService = new ServerService(
ConsoleServices.endpoint() + '/server',
this.instance.fetchCaller
);
this.instance.countersService = new CountersService(
ConsoleServices.endpoint() + '/counters',
this.instance.fetchCaller
);
this.instance.xsiteReplicationService = new CrossSiteReplicationService(
ConsoleServices.endpoint(),
this.instance.fetchCaller
);
this.instance.cacheService = new CacheService(ConsoleServices.endpoint(), this.instance.fetchCaller);
this.instance.dataContainerService = new ContainerService(ConsoleServices.endpoint(), this.instance.fetchCaller);
this.instance.userService = new SecurityService(
ConsoleServices.endpoint() + '/security',
this.instance.fetchCaller,
this.instance.authenticationService
);
this.instance.searchService = new SearchService(
ConsoleServices.endpoint() + '/caches/',
this.instance.fetchCaller
);
this.instance.clusterService = new ClusterService(
ConsoleServices.endpoint() + '/cluster',
this.instance.fetchCaller
);
this.instance.initialized = true;
}
}
public static server(): ServerService {
return this.instance.serverService;
}
public static dataContainer(): ContainerService {
return this.instance.dataContainerService;
}
public static caches(): CacheService {
return this.instance.cacheService;
}
public static protobuf(): ProtobufService {
return this.instance.protobufService;
}
public static xsite(): CrossSiteReplicationService {
return this.instance.xsiteReplicationService;
}
public static counters(): CountersService {
return this.instance.countersService;
}
public static tasks(): TasksService {
return this.instance.taskService;
}
public static authentication(): AuthenticationService {
return this.instance.authenticationService;
}
public static security(): SecurityService {
return this.instance.userService;
}
public static search(): SearchService {
return this.instance.searchService;
}
public static cluster(): ClusterService {
return this.instance.clusterService;
}
public isInitialized(): boolean {
return ConsoleServices.Instance.initialized;
}
}