danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * Copyright (C) 2024 Nordix Foundation |
| 4 | * ================================================================================ |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * SPDX-License-Identifier: Apache-2.0 |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 21 | import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 22 | import { |
| 23 | performPostRequest, |
| 24 | performGetRequest, |
| 25 | NCMP_BASE_URL, |
halil.cakal | fc49910 | 2024-08-28 10:19:26 +0100 | [diff] [blame] | 26 | LEGACY_BATCH_TOPIC_NAME, |
| 27 | TOTAL_CM_HANDLES, |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 28 | } from './utils.js'; |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 29 | |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 30 | export function passthroughRead(useAlternateId) { |
| 31 | const cmHandleReference = getRandomCmHandleReference(useAlternateId); |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 32 | const resourceIdentifier = 'my-resource-identifier'; |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 33 | const datastoreName = 'ncmp-datastore:passthrough-operational'; |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 34 | const includeDescendants = true; |
| 35 | const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); |
| 36 | return performGetRequest(url, 'passthroughRead'); |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 37 | } |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 38 | |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 39 | export function passthroughWrite(useAlternateId) { |
| 40 | const cmHandleReference = getRandomCmHandleReference(useAlternateId); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 41 | const resourceIdentifier = 'my-resource-identifier'; |
| 42 | const datastoreName = 'ncmp-datastore:passthrough-running'; |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 43 | const includeDescendants = false; |
| 44 | const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); |
| 45 | const payload = JSON.stringify({"neType": "BaseStation"}); |
| 46 | return performPostRequest(url, payload, 'passthroughWrite'); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 47 | } |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 48 | |
halil.cakal | fc49910 | 2024-08-28 10:19:26 +0100 | [diff] [blame] | 49 | export function legacyBatchRead(cmHandleIds) { |
| 50 | const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${LEGACY_BATCH_TOPIC_NAME}` |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 51 | const payload = JSON.stringify({ |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 52 | "operations": [ |
| 53 | { |
| 54 | "resourceIdentifier": "parent/child", |
| 55 | "targetIds": cmHandleIds, |
| 56 | "datastore": "ncmp-datastore:passthrough-operational", |
| 57 | "options": "(fields=schemas/schema)", |
| 58 | "operationId": "12", |
| 59 | "operation": "read" |
| 60 | } |
| 61 | ] |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 62 | }); |
| 63 | return performPostRequest(url, payload, 'batchRead'); |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | function getRandomCmHandleReference(useAlternateId) { |
| 67 | const prefix = useAlternateId ? 'alt' : 'ch'; |
| 68 | return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`; |
| 69 | } |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 70 | |
| 71 | function generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants) { |
| 72 | const descendantsParam = includeDescendants ? `&include-descendants=${includeDescendants}` : ''; |
| 73 | return `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}${descendantsParam}`; |
| 74 | } |