More actor clean-up
[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.actor.aai.AaiCustomQueryOperation;
29 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class ModifyConfigOperation extends AppcOperation {
36     private static final Logger logger = LoggerFactory.getLogger(ModifyConfigOperation.class);
37
38     public static final String NAME = "ModifyConfig";
39
40     /**
41      * Constructs the object.
42      *
43      * @param params operation parameters
44      * @param config configuration for this operation
45      */
46     public ModifyConfigOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
47         super(params, config);
48     }
49
50     /**
51      * Ensures that A&AI customer query has been performed, and then runs the guard query.
52      */
53     @Override
54     @SuppressWarnings("unchecked")
55     protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
56         ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
57                         .operation(AaiCustomQueryOperation.NAME).payload(null).retry(null).timeoutSec(null).build();
58
59         // run Custom Query and Guard, in parallel
60         return allOf(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::startGuardAsync);
61     }
62
63     @Override
64     protected Request makeRequest(int attempt) {
65         AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
66
67         GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID());
68         if (genvnf == null) {
69             logger.info("{}: target entity could not be found for {}", getFullName(), params.getRequestId());
70             throw new IllegalArgumentException("target vnf-id could not be found");
71         }
72
73         return makeRequest(attempt, genvnf.getVnfId());
74     }
75 }