Merge "Move CQ operation name from actor.aai to aai"
[policy/models.git] / models-interactions / model-actors / actor.appc / src / main / java / org / onap / policy / controlloop / actor / appc / ModifyConfigOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.appc;
22
23 import java.util.concurrent.CompletableFuture;
24 import org.onap.aai.domain.yang.GenericVnf;
25 import org.onap.policy.aai.AaiConstants;
26 import org.onap.policy.aai.AaiCqResponse;
27 import org.onap.policy.appc.Request;
28 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ModifyConfigOperation extends AppcOperation {
35     private static final Logger logger = LoggerFactory.getLogger(ModifyConfigOperation.class);
36
37     public static final String NAME = "ModifyConfig";
38
39     /**
40      * Constructs the object.
41      *
42      * @param params operation parameters
43      * @param config configuration for this operation
44      */
45     public ModifyConfigOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
46         super(params, config);
47     }
48
49     /**
50      * Ensures that A&AI customer query has been performed, and then runs the guard query.
51      */
52     @Override
53     @SuppressWarnings("unchecked")
54     protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
55         ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
56                         .operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
57
58         // run Custom Query and Guard, in parallel
59         return allOf(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::startGuardAsync);
60     }
61
62     @Override
63     protected Request makeRequest(int attempt) {
64         AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
65
66         GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID());
67         if (genvnf == null) {
68             logger.info("{}: target entity could not be found for {}", getFullName(), params.getRequestId());
69             throw new IllegalArgumentException("target vnf-id could not be found");
70         }
71
72         return makeRequest(attempt, genvnf.getVnfId());
73     }
74 }