2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022-2023 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.rest.controller.handlers;
23 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL;
24 import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ;
27 import java.util.UUID;
28 import java.util.function.Supplier;
29 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
30 import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException;
31 import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
32 import org.onap.cps.ncmp.api.impl.operations.OperationType;
33 import org.onap.cps.ncmp.api.models.DataOperationRequest;
34 import org.onap.cps.ncmp.rest.exceptions.OperationNotSupportedException;
35 import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor;
36 import org.onap.cps.ncmp.rest.util.TopicValidator;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.stereotype.Component;
41 public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestHandler {
43 private final NetworkCmProxyDataService networkCmProxyDataService;
45 private static final Object noReturn = null;
50 * @param cpsNcmpTaskExecutor @see org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor
51 * @param networkCmProxyDataService @see org.onap.cps.ncmp.api.NetworkCmProxyDataService
53 public NcmpPassthroughResourceRequestHandler(final CpsNcmpTaskExecutor cpsNcmpTaskExecutor,
54 final NetworkCmProxyDataService networkCmProxyDataService) {
55 super(cpsNcmpTaskExecutor);
56 this.networkCmProxyDataService = networkCmProxyDataService;
60 * Executes asynchronous request for group of cm handles to resource data.
62 * @param topicParamInQuery the topic param in query
63 * @param dataOperationRequest data operation request details for resource data
64 * @return the response entity
66 public ResponseEntity<Object> executeRequest(final String topicParamInQuery,
67 final DataOperationRequest
68 dataOperationRequest) {
69 validateDataOperationRequest(topicParamInQuery, dataOperationRequest);
70 if (!notificationFeatureEnabled) {
71 return ResponseEntity.ok(Map.of("status",
72 "Asynchronous request is unavailable as notification feature is currently disabled."));
74 return getRequestIdAndSendDataOperationRequestToDmiService(topicParamInQuery, dataOperationRequest);
78 protected Supplier<Object> getTaskSupplierForGetRequest(final String datastoreName,
79 final String cmHandleId,
80 final String resourceIdentifier,
81 final String optionsParamInQuery,
82 final String topicParamInQuery,
83 final String requestId,
84 final boolean includeDescendants,
85 final String authorization) {
87 return () -> networkCmProxyDataService.getResourceDataForCmHandle(
88 datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId,
92 private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService(final String topicParamInQuery,
93 final DataOperationRequest
94 dataOperationRequest) {
95 final String requestId = UUID.randomUUID().toString();
96 cpsNcmpTaskExecutor.executeTask(
97 getTaskSupplierForDataOperationRequest(topicParamInQuery, dataOperationRequest, requestId),
98 timeOutInMilliSeconds);
99 return ResponseEntity.ok(Map.of("requestId", requestId));
102 private void validateDataOperationRequest(final String topicParamInQuery,
103 final DataOperationRequest
104 dataOperationRequest) {
105 TopicValidator.validateTopicName(topicParamInQuery);
106 dataOperationRequest.getDataOperationDefinitions().forEach(dataOperationDetail -> {
107 if (OperationType.fromOperationName(dataOperationDetail.getOperation()) != READ) {
108 throw new OperationNotSupportedException(
109 dataOperationDetail.getOperation() + " operation not yet supported");
110 } else if (DatastoreType.fromDatastoreName(dataOperationDetail.getDatastore()) == OPERATIONAL) {
111 throw new InvalidDatastoreException(dataOperationDetail.getDatastore()
112 + " datastore is not supported");
117 private Supplier<Object> getTaskSupplierForDataOperationRequest(final String topicParamInQuery,
118 final DataOperationRequest dataOperationRequest,
119 final String requestId) {
121 networkCmProxyDataService.executeDataOperationForCmHandles(topicParamInQuery,
122 dataOperationRequest,