blob: 86fcef6242f3cdde8cd76bcb614c935da0c61840 [file] [log] [blame]
danielhanrahanf66694a2024-06-10 21:32:12 +01001/*
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
danielhanrahanf2e1e252024-08-25 21:35:19 +010021import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
sourabh_sourabh175d12d2024-08-30 16:25:04 +010022import {
23 performPostRequest,
24 performGetRequest,
25 NCMP_BASE_URL,
halil.cakalfc499102024-08-28 10:19:26 +010026 LEGACY_BATCH_TOPIC_NAME,
27 TOTAL_CM_HANDLES,
sourabh_sourabh175d12d2024-08-30 16:25:04 +010028} from './utils.js';
danielhanrahanf66694a2024-06-10 21:32:12 +010029
danielhanrahanf2e1e252024-08-25 21:35:19 +010030export function passthroughRead(useAlternateId) {
31 const cmHandleReference = getRandomCmHandleReference(useAlternateId);
danielhanrahanf66694a2024-06-10 21:32:12 +010032 const resourceIdentifier = 'my-resource-identifier';
danielhanrahanf66694a2024-06-10 21:32:12 +010033 const datastoreName = 'ncmp-datastore:passthrough-operational';
sourabh_sourabh175d12d2024-08-30 16:25:04 +010034 const includeDescendants = true;
35 const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants);
36 return performGetRequest(url, 'passthroughRead');
danielhanrahanf66694a2024-06-10 21:32:12 +010037}
halil.cakalfcc81ee2024-07-11 14:54:57 +010038
danielhanrahanf2e1e252024-08-25 21:35:19 +010039export function passthroughWrite(useAlternateId) {
40 const cmHandleReference = getRandomCmHandleReference(useAlternateId);
halil.cakalfcc81ee2024-07-11 14:54:57 +010041 const resourceIdentifier = 'my-resource-identifier';
42 const datastoreName = 'ncmp-datastore:passthrough-running';
sourabh_sourabh175d12d2024-08-30 16:25:04 +010043 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.cakalfcc81ee2024-07-11 14:54:57 +010047}
halil.cakal65b870b2024-07-25 11:12:29 +010048
halil.cakalfc499102024-08-28 10:19:26 +010049export function legacyBatchRead(cmHandleIds) {
50 const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${LEGACY_BATCH_TOPIC_NAME}`
sourabh_sourabh175d12d2024-08-30 16:25:04 +010051 const payload = JSON.stringify({
halil.cakal65b870b2024-07-25 11:12:29 +010052 "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_sourabh175d12d2024-08-30 16:25:04 +010062 });
63 return performPostRequest(url, payload, 'batchRead');
danielhanrahanf2e1e252024-08-25 21:35:19 +010064}
65
66function getRandomCmHandleReference(useAlternateId) {
67 const prefix = useAlternateId ? 'alt' : 'ch';
68 return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`;
69}
sourabh_sourabh175d12d2024-08-30 16:25:04 +010070
71function 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}