MCPcopy
hub / github.com/scality/cloudserver / initManagement

Function initManagement

lib/management/index.js:77–133  ·  view source on GitHub ↗

* Initializes Orbit-based management by: * - creating the management database in metadata * - generating a key pair for credentials encryption * - generating an instance-unique ID * - getting an authentication token for the API * - loading and applying the latest cached overlay configuration *

(log, callback)

Source from the content-addressed store, hash-verified

75 * @returns {undefined}
76 */
77function initManagement(log, callback) {
78 if ((process.env.REMOTE_MANAGEMENT_DISABLE &&
79 process.env.REMOTE_MANAGEMENT_DISABLE !== '0')
80 || process.env.S3BACKEND === 'mem') {
81 log.info('remote management disabled');
82 return;
83 }
84
85 /* Temporary check before to fully move to the process management agent. */
86 if (isManagementAgentUsed() ^ typeof callback === 'function') {
87 let msg = 'misuse of initManagement function: ';
88 msg += `MANAGEMENT_USE_AGENT: ${process.env.MANAGEMENT_USE_AGENT}`;
89 msg += `, callback type: ${typeof callback}`;
90 throw new Error(msg);
91 }
92
93 async.waterfall([
94 // eslint-disable-next-line arrow-body-style
95 cb => { return isManagementAgentUsed() ? metadata.setup(cb) : cb(); },
96 cb => initManagementDatabase(log, cb),
97 cb => metadata.getUUID(log, cb),
98 (instanceId, cb) => initManagementCredentials(
99 managementEndpoint, instanceId, log, cb),
100 (instanceId, token, cb) => {
101 if (!isManagementAgentUsed()) {
102 cb(null, instanceId, token, {});
103 return;
104 }
105 loadCachedOverlay(log, (err, overlay) => cb(err, instanceId,
106 token, overlay));
107 },
108 (instanceId, token, overlay, cb) => {
109 if (!isManagementAgentUsed()) {
110 cb(null, instanceId, token, overlay);
111 return;
112 }
113 patchConfiguration(overlay, log,
114 err => cb(err, instanceId, token, overlay));
115 },
116 ], (error, instanceId, token, overlay) => {
117 if (error) {
118 log.error('could not initialize remote management, retrying later',
119 { error: reshapeExceptionError(error),
120 method: 'initManagement' });
121 setTimeout(initManagement,
122 initRemoteManagementRetryDelay,
123 logger.newRequestLogger());
124 } else {
125 log.info(`this deployment's Instance ID is ${instanceId}`);
126 log.end('management init done');
127 startManagementListeners(instanceId, token);
128 if (callback) {
129 callback(overlay);
130 }
131 }
132 });
133}
134

Callers 2

startMethod · 0.85
initiateStartupMethod · 0.85

Calls 10

isManagementAgentUsedFunction · 0.85
initManagementDatabaseFunction · 0.85
loadCachedOverlayFunction · 0.85
patchConfigurationFunction · 0.85
startManagementListenersFunction · 0.85
infoMethod · 0.80
setupMethod · 0.80
errorMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected