-
Notifications
You must be signed in to change notification settings - Fork 6
/
AdminService.ts
111 lines (99 loc) · 3.63 KB
/
AdminService.ts
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
/*
* Copyright (C) 2023 Thirty Meter Telescope International Observatory
* SPDX-License-Identifier: Apache-2.0
*/
import { GATEWAY_CONNECTION } from '../../config/Connections'
import type {
ComponentId,
ContainerLifecycleState,
Done,
Prefix,
SupervisorLifecycleState,
AuthData
} from '../../models'
import { HttpTransport } from '../../utils/HttpTransport'
import { extractHostPort, getPostEndPoint } from '../../utils/Utils'
import type { Location } from '../location'
import { resolve } from '../location/LocationUtils'
import type { Level, LogMetadata } from '../logger'
import { AdminServiceImpl } from './AdminServiceImpl'
/**
* Admin service provides admin related APIs which includes logging APIs
* @interface
* @category Service
*/
export interface AdminService {
/**
* Restarts the given component(HCD, Assembly or Container)
*
* @param componentId The component id of the component.
* @return Done as promise
*/
restart(componentId: ComponentId): Promise<Done>
/**
* Sets the current Lifecycle state of the given component(HCD, Assembly or Container) to Offline
*
* @param componentId the component id of the component which needs to be offline
* @return Done as promise
*/
goOffline(componentId: ComponentId): Promise<Done>
/**
* Sets the current Lifecycle state of the given component(HCD, Assembly or Container) to Online
*
* @param componentId the component id of the component which needs to be offline
* @return Done as promise
*/
goOnline(componentId: ComponentId): Promise<Done>
/**
* Fetches the current Lifecycle state of the given container
*
* @param prefix the prefix of the container whose lifecycle state needs to be fetched
* @return ContainerLifecycleState as promise
*/
getContainerLifecycleState(prefix: Prefix): Promise<ContainerLifecycleState>
/**
* Fetches the current Lifecycle state of the given Assembly or HCD
*
* @param componentId the component id of the component whose lifecycle state needs to be fetched
* @return SupervisorLifecycleState as promise
*/
getComponentLifecycleState(componentId: ComponentId): Promise<SupervisorLifecycleState>
/**
* Shuts down the given component(HCD, Assembly or Container)
*
* @param componentId The component id of the component.
* @return Done as promise
*/
shutdown(componentId: ComponentId): Promise<Done>
/**
* Get basic logging configuration values of the component.
*
* @param componentId The component id of the component.
* @return LogMetadata as promise
*/
getLogMetadata(componentId: ComponentId): Promise<LogMetadata>
/**
* Set new log level of a component.
*
* @param componentId The component id of the component
* @param level Expected Log level for the component.
* @return Done as promise
*/
setLogLevel(componentId: ComponentId, level: Level): Promise<Done>
}
/**
* Instantiate Admin service.
*
* @param authData A record which contains tokenFactory and username
* @return AdminService as Promise
* @constructor
*/
export const AdminService = async (authData?: AuthData): Promise<AdminService> => {
const location = await resolve(GATEWAY_CONNECTION)
return createAdminService(location, authData)
}
export const createAdminService = (location: Location, authData?: AuthData): AdminService => {
const { host, port } = extractHostPort(location.uri)
const postEndpoint = getPostEndPoint({ host, port })
return new AdminServiceImpl(new HttpTransport(postEndpoint, authData))
}