2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Wipro Limited.
6 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2023 Nordix Foundation.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.controlloop.actor.so;
25 import jakarta.ws.rs.client.Entity;
26 import jakarta.ws.rs.core.MediaType;
27 import java.util.List;
29 import java.util.concurrent.CompletableFuture;
30 import org.onap.policy.common.endpoints.event.comm.Topic;
31 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
32 import org.onap.policy.common.utils.coder.CoderException;
33 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
34 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
37 import org.onap.policy.so.SoRequest3gpp;
39 public class ModifyNssi extends SoOperation {
40 public static final String NAME = "Modify NSSI";
42 private static final List<String> PROPERTY_NAMES = List.of(
43 OperationProperties.EVENT_PAYLOAD);
46 * Constructs the object.
48 * @param params operation parameters
49 * @param config configuration for this operation
51 public ModifyNssi(ControlLoopOperationParams params, HttpPollingConfig config) {
52 super(params, config, PROPERTY_NAMES);
56 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
58 SoRequest3gpp soRequest = makeRequest();
60 String path = getPath();
61 String url = getClient().getBaseUrl() + path;
63 String strRequest = prettyPrint(soRequest);
64 logMessage(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, url, strRequest);
66 Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
67 Map<String, Object> headers = createSimpleHeaders();
69 return handleResponse(outcome, url, callback -> getClient().put(callback, path, entity, headers));
72 protected SoRequest3gpp makeRequest() {
74 String payload = getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload");
76 return getCoder().convert(payload, SoRequest3gpp.class);
77 } catch (CoderException e) {
78 throw new IllegalArgumentException("invalid payload value: " + payload, e);