From 0873cc0b67a5e3103f1efea8f3b6a18b116b0751 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 31 Mar 2019 13:50:50 +0000 Subject: [server/registration] Performance improvements & add automatic registration with custom name Manual registration now sends the client as json idoit: Add server bug fixes shell: Fix building pcbios ipxe version eslint fixes --- server/lib/external-backends/backendhelper.js | 21 ++++++++++----- .../external-backends/backends/idoit-backend.js | 30 ++++++---------------- 2 files changed, 22 insertions(+), 29 deletions(-) (limited to 'server/lib/external-backends') diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js index 6892f7c..a088074 100644 --- a/server/lib/external-backends/backendhelper.js +++ b/server/lib/external-backends/backendhelper.js @@ -8,18 +8,18 @@ module.exports = { addClient, updateClient, deleteClients, uploadFiles } async function addClient (client) { // Get all backends and call addClient for each instance. - var backends = await db.backend.findAll({ include: ['mappedGroups', 'mappedClients'] }) + const backends = await db.backend.findAll({ include: [{ association: 'mappedGroups', where: { id: client.parents }, required: false }] }) var result = [] - for (var b in backends) { - var backend = backends[b] + for (let b in backends) { + const backend = backends[b] const ba = new ExternalBackends() const instance = ba.getInstance(backend.type) var tmpClient = JSON.parse(JSON.stringify(client)) // Convert the parent group ids to the external backend parentIds. If multiple -> conflict if (client.parents) { - const elements = backend.mappedGroups.filter(x => client.parents.includes(x.id)) + const elements = backend.mappedGroups if (elements.length > 1) { // Conflict occured! const conflict = await db.conflict.create({ description: 'Multiple parents found' }) @@ -35,12 +35,14 @@ async function addClient (client) { } let addClient = await instance.addClient(backend.credentials, tmpClient) + addClient.backendId = backend.id if (addClient.succes) { // If the object was created we need to make the objectid / external id mapping. const clientDb = await db.client.findOne({ where: { id: client.id } }) backend.addMappedClients(clientDb, { through: { externalId: addClient.id, externalType: addClient.type } }) } + if (addClient.error && addClient.error !== 'NOT_IMPLEMENTED_EXCEPTION') log({ category: 'BACKEND_ERROR', description: `[${addClient.backendId}] ${addClient.error}: ${addClient.message}`, clientId: client.id }) result.push(addClient) } @@ -49,7 +51,12 @@ async function addClient (client) { async function updateClient (client) { // Get all backends and call addClient for each instance. - const backends = await db.backend.findAll({ include: ['mappedGroups', 'mappedClients'] }) + const backends = await db.backend.findAll({ + include: [ + { association: 'mappedGroups', where: { id: client.parents }, required: false }, + { association: 'mappedClients', where: { id: client.id }, required: false } + ] + }) let result = [] for (let b in backends) { @@ -59,12 +66,12 @@ async function updateClient (client) { var tmpClient = JSON.parse(JSON.stringify(client)) // Get the external clientid. - var exid = backend.mappedClients.find(y => y.id === parseInt(client.id)) + const exid = backend.mappedClients[0] if (exid) tmpClient.id = exid.backend_x_client.externalId // Convert the parent group ids to the external backend parentIds. If multiple -> conflict if (client.parents) { - const elements = backend.mappedGroups.filter(x => client.parents.includes(x.id)) + const elements = backend.mappedGroups if (elements.length > 1) { // Conflict occured! const conflict = await db.conflict.create({ description: 'Multiple parents found' }) diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js index c76b6bf..601c9f9 100644 --- a/server/lib/external-backends/backends/idoit-backend.js +++ b/server/lib/external-backends/backends/idoit-backend.js @@ -185,7 +185,7 @@ class IdoitBackend extends ExternalBackends { if (client.formfactor) params.categories.C__CATG__FORMFACTOR = { 'data': { 'formfactor': client.formfactor, 'rackunits': client.formfactor.rackunits } } // Rack segmentation - if (client.location.bay) { + if (client.location.bay !== undefined && client.location.bay !== null) { // Get all assigned objects of the rack (parentid) to check for existing rack segments at slot position. const rackobjectsBody = this.getBody('cmdb.category.read', { 'apikey': c.apikey, 'object': client.parentId, 'objID': client.parentId, 'category': 'C__CATG__OBJECT' }, 'get_rack_objects') const rackobjects = await this.axiosRequest(c.url, [rackobjectsBody], headers) @@ -218,8 +218,8 @@ class IdoitBackend extends ExternalBackends { 'categories': { 'C__CATS__CHASSIS': { 'data': { - 'front_x': 4, - 'front_y': 2, + 'front_x': 2, + 'front_y': 1, 'rear_x': 0, 'rear_y': 0 } @@ -231,7 +231,7 @@ class IdoitBackend extends ExternalBackends { 'from_x': 0, 'to_x': 0, 'from_y': 0, - 'to_y': 1 + 'to_y': 0 }, { 'title': 'Bay 2', @@ -239,23 +239,7 @@ class IdoitBackend extends ExternalBackends { 'from_x': 1, 'to_x': 1, 'from_y': 0, - 'to_y': 1 - }, - { - 'title': 'Bay 3', - 'insertion': 'front', - 'from_x': 2, - 'to_x': 2, - 'from_y': 0, - 'to_y': 1 - }, - { - 'title': 'Bay 4', - 'insertion': 'front', - 'from_x': 3, - 'to_x': 3, - 'from_y': 0, - 'to_y': 1 + 'to_y': 0 } ], 'C__CATG__LOCATION': { @@ -273,6 +257,7 @@ class IdoitBackend extends ExternalBackends { const createSegment = await this.axiosRequest(c.url, [createSegmentParam], headers) chassisId = createSegment[0].result.id + /* // Set the new rack units height. (Needs an extra request, why? I DONT KNOW... idoit...) const setSegmentSizeParams = this.getBody('cmdb.category.save', { 'apikey': c.apikey, 'object': chassisId, @@ -280,6 +265,7 @@ class IdoitBackend extends ExternalBackends { 'category': 'C__CATG__FORMFACTOR', 'data': { 'rackunits': client.formfactor.rackunits } }, 'set_segment_size') await this.axiosRequest(c.url, [setSegmentSizeParams], headers) + */ } } } @@ -331,7 +317,7 @@ class IdoitBackend extends ExternalBackends { // If chassis id is set, assign the object to the chassis bay if (chassisId) { - const bay = client.location.bay + '' + const bay = client.location.bay + 1 + '' const assignToSlotBody = this.getBody('cmdb.category.save', { 'apikey': c.apikey, 'objID': chassisId, 'object': chassisId, -- cgit v1.2.3-55-g7522