|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
import assert from 'assert'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
|
|
|
|
|
|
|
|
import { query } from '../../accessModule'; |
|
|
|
import { query } from '../../accessModule'; |
|
|
@ -11,40 +12,55 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async ( |
|
|
|
params: { anvilUuid }, |
|
|
|
params: { anvilUuid }, |
|
|
|
} = request; |
|
|
|
} = request; |
|
|
|
|
|
|
|
|
|
|
|
let rCores: null | string; |
|
|
|
let rCpus: [ |
|
|
|
let rThreads: null | string; |
|
|
|
hostUuid: string, |
|
|
|
|
|
|
|
hostName: string, |
|
|
|
|
|
|
|
cpuModel: string, |
|
|
|
|
|
|
|
cpuCores: string, |
|
|
|
|
|
|
|
cpuThreads: string, |
|
|
|
|
|
|
|
cpuMinCores: string, |
|
|
|
|
|
|
|
cpuMinThreads: string, |
|
|
|
|
|
|
|
][]; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
[[rCores = '', rThreads = '']] = await query< |
|
|
|
rCpus = await query( |
|
|
|
[[cpuCores: null | string, cpuThreads: null | string]] |
|
|
|
|
|
|
|
>( |
|
|
|
|
|
|
|
`SELECT
|
|
|
|
`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_cores) AS cores, |
|
|
|
MIN(c.scan_hardware_cpu_threads) AS threads |
|
|
|
MIN(c.scan_hardware_cpu_threads) AS threads |
|
|
|
FROM anvils AS a |
|
|
|
FROM anvils AS a |
|
|
|
JOIN hosts AS b |
|
|
|
JOIN hosts AS b |
|
|
|
ON b.host_uuid IN ( |
|
|
|
ON b.host_uuid IN ( |
|
|
|
a.anvil_node1_host_uuid, |
|
|
|
a.anvil_node1_host_uuid, |
|
|
|
a.anvil_node2_host_uuid, |
|
|
|
a.anvil_node2_host_uuid |
|
|
|
a.anvil_dr1_host_uuid |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
JOIN scan_hardware AS c |
|
|
|
JOIN scan_hardware AS c |
|
|
|
ON b.host_uuid = c.scan_hardware_host_uuid |
|
|
|
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) { |
|
|
|
} catch (error) { |
|
|
|
stderr(`Failed to get anvil ${anvilUuid} cpu info; CAUSE: ${error}`); |
|
|
|
stderr(`Failed to get anvil ${anvilUuid} cpu info; CAUSE: ${error}`); |
|
|
|
|
|
|
|
|
|
|
|
return response.status(500).send(); |
|
|
|
return response.status(500).send(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const cores = Number.parseInt(rCores); |
|
|
|
let rAllocatedRow: [cpuAllocated: string][]; |
|
|
|
const threads = Number.parseInt(rThreads); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let rAllocated: null | string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
[[rAllocated = '']] = await query<[[cpuAllocated: null | string]]>( |
|
|
|
rAllocatedRow = await query( |
|
|
|
`SELECT
|
|
|
|
`SELECT
|
|
|
|
SUM( |
|
|
|
SUM( |
|
|
|
CAST( |
|
|
|
CAST( |
|
|
@ -58,17 +74,51 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async ( |
|
|
|
ON a.server_uuid = b.server_definition_server_uuid |
|
|
|
ON a.server_uuid = b.server_definition_server_uuid |
|
|
|
WHERE a.server_anvil_uuid = '${anvilUuid}';`,
|
|
|
|
WHERE a.server_anvil_uuid = '${anvilUuid}';`,
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.ok(rAllocatedRow.length, 'No entry found'); |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`); |
|
|
|
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`); |
|
|
|
|
|
|
|
|
|
|
|
return response.status(500).send(); |
|
|
|
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({ |
|
|
|
response.status(200).send(rsBody); |
|
|
|
allocated, |
|
|
|
|
|
|
|
cores, |
|
|
|
|
|
|
|
threads, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|