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 | |
| 21 | import http from 'k6/http'; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 22 | import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; |
| 23 | import { TOTAL_CM_HANDLES, CONTENT_TYPE_JSON_PARAM, NCMP_BASE_URL, TOPIC_DATA_OPERATIONS_BATCH_READ } from './utils.js'; |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 24 | |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 25 | export function passthroughRead(useAlternateId) { |
| 26 | const cmHandleReference = getRandomCmHandleReference(useAlternateId); |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 27 | const resourceIdentifier = 'my-resource-identifier'; |
| 28 | const includeDescendants = true; |
| 29 | const datastoreName = 'ncmp-datastore:passthrough-operational'; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 30 | const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}` |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 31 | const response = http.get(url); |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 32 | return response; |
| 33 | } |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 34 | |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 35 | export function passthroughWrite(useAlternateId) { |
| 36 | const cmHandleReference = getRandomCmHandleReference(useAlternateId); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 37 | const resourceIdentifier = 'my-resource-identifier'; |
| 38 | const datastoreName = 'ncmp-datastore:passthrough-running'; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 39 | const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}` |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 40 | const body = `{"neType": "BaseStation"}` |
| 41 | const response = http.post(url, JSON.stringify(body), CONTENT_TYPE_JSON_PARAM); |
| 42 | return response; |
| 43 | } |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 44 | |
| 45 | export function batchRead(cmHandleIds) { |
| 46 | const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}` |
| 47 | const payload = { |
| 48 | "operations": [ |
| 49 | { |
| 50 | "resourceIdentifier": "parent/child", |
| 51 | "targetIds": cmHandleIds, |
| 52 | "datastore": "ncmp-datastore:passthrough-operational", |
| 53 | "options": "(fields=schemas/schema)", |
| 54 | "operationId": "12", |
| 55 | "operation": "read" |
| 56 | } |
| 57 | ] |
| 58 | }; |
| 59 | const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM); |
| 60 | return response; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | function getRandomCmHandleReference(useAlternateId) { |
| 64 | const prefix = useAlternateId ? 'alt' : 'ch'; |
| 65 | return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`; |
| 66 | } |