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