|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
import assert from 'assert'; |
|
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
|
|
|
|
|
|
import { query } from '../../accessModule'; |
|
|
|
@ -11,40 +12,55 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async ( |
|
|
|
|
params: { anvilUuid }, |
|
|
|
|
} = request; |
|
|
|
|
|
|
|
|
|
let rCores: null | string; |
|
|
|
|
let rThreads: null | string; |
|
|
|
|
let rCpus: [ |
|
|
|
|
hostUuid: string, |
|
|
|
|
hostName: string, |
|
|
|
|
cpuModel: string, |
|
|
|
|
cpuCores: string, |
|
|
|
|
cpuThreads: string, |
|
|
|
|
cpuMinCores: string, |
|
|
|
|
cpuMinThreads: string, |
|
|
|
|
][]; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
[[rCores = '', rThreads = '']] = await query< |
|
|
|
|
[[cpuCores: null | string, cpuThreads: null | string]] |
|
|
|
|
>( |
|
|
|
|
rCpus = await query( |
|
|
|
|
`SELECT
|
|
|
|
|
b.host_uuid, |
|
|
|
|
b.host_name, |
|
|
|
|
c.scan_hardware_cpu_model, |
|
|
|
|
c.scan_hardware_cpu_cores, |
|
|
|
|
c.scan_hardware_cpu_threads, |
|
|
|
|
MIN(c.scan_hardware_cpu_cores) AS cores, |
|
|
|
|
MIN(c.scan_hardware_cpu_threads) AS threads |
|
|
|
|
FROM anvils AS a |
|
|
|
|
JOIN hosts AS b |
|
|
|
|
ON b.host_uuid IN ( |
|
|
|
|
a.anvil_node1_host_uuid, |
|
|
|
|
a.anvil_node2_host_uuid, |
|
|
|
|
a.anvil_dr1_host_uuid |
|
|
|
|
a.anvil_node2_host_uuid |
|
|
|
|
) |
|
|
|
|
JOIN scan_hardware AS c |
|
|
|
|
ON b.host_uuid = c.scan_hardware_host_uuid |
|
|
|
|
WHERE a.anvil_uuid = '${anvilUuid}';`,
|
|
|
|
|
WHERE a.anvil_uuid = '${anvilUuid}' |
|
|
|
|
GROUP BY |
|
|
|
|
b.host_uuid, |
|
|
|
|
b.host_name, |
|
|
|
|
c.scan_hardware_cpu_model, |
|
|
|
|
c.scan_hardware_cpu_cores, |
|
|
|
|
c.scan_hardware_cpu_threads |
|
|
|
|
ORDER BY b.host_name;`,
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
assert.ok(rCpus.length, 'No entry found'); |
|
|
|
|
} catch (error) { |
|
|
|
|
stderr(`Failed to get anvil ${anvilUuid} cpu info; CAUSE: ${error}`); |
|
|
|
|
|
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const cores = Number.parseInt(rCores); |
|
|
|
|
const threads = Number.parseInt(rThreads); |
|
|
|
|
|
|
|
|
|
let rAllocated: null | string; |
|
|
|
|
let rAllocatedRow: [cpuAllocated: string][]; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
[[rAllocated = '']] = await query<[[cpuAllocated: null | string]]>( |
|
|
|
|
rAllocatedRow = await query( |
|
|
|
|
`SELECT
|
|
|
|
|
SUM( |
|
|
|
|
CAST( |
|
|
|
@ -58,17 +74,51 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async ( |
|
|
|
|
ON a.server_uuid = b.server_definition_server_uuid |
|
|
|
|
WHERE a.server_anvil_uuid = '${anvilUuid}';`,
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
assert.ok(rAllocatedRow.length, 'No entry found'); |
|
|
|
|
} catch (error) { |
|
|
|
|
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`); |
|
|
|
|
|
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const allocated = Number.parseInt(rAllocated); |
|
|
|
|
const { |
|
|
|
|
0: { 5: rMinCores, 6: rMinThreads }, |
|
|
|
|
} = rCpus; |
|
|
|
|
|
|
|
|
|
const minCores = Number(rMinCores); |
|
|
|
|
const minThreads = Number(rMinThreads); |
|
|
|
|
|
|
|
|
|
const [[rAllocated]] = rAllocatedRow; |
|
|
|
|
|
|
|
|
|
const allocated = Number(rAllocated); |
|
|
|
|
|
|
|
|
|
const rsBody = rCpus.reduce<AnvilDetailCpuSummary>( |
|
|
|
|
(previous, current) => { |
|
|
|
|
const { 0: uuid, 1: name, 2: model, 3: rCores, 4: rThreads } = current; |
|
|
|
|
|
|
|
|
|
const cores = Number(rCores); |
|
|
|
|
const threads = Number(rThreads); |
|
|
|
|
const vendor = model.replace(/^(\w+).*$/, '$1'); |
|
|
|
|
|
|
|
|
|
previous.hosts[uuid] = { |
|
|
|
|
cores, |
|
|
|
|
model, |
|
|
|
|
name, |
|
|
|
|
threads, |
|
|
|
|
uuid, |
|
|
|
|
vendor, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return previous; |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
allocated, |
|
|
|
|
cores: minCores, |
|
|
|
|
hosts: {}, |
|
|
|
|
threads: minThreads, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
response.status(200).send({ |
|
|
|
|
allocated, |
|
|
|
|
cores, |
|
|
|
|
threads, |
|
|
|
|
}); |
|
|
|
|
response.status(200).send(rsBody); |
|
|
|
|
}; |
|
|
|
|