extend vnf properties model for cds actors
[policy/models.git] / models-interactions / model-actors / actor.cds / src / main / java / org / onap / policy / controlloop / actor / cds / properties / GrpcOperationProperties.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.controlloop.actor.cds.properties;
20
21 import java.util.List;
22 import java.util.Map;
23 import lombok.Data;
24 import org.onap.policy.controlloop.actor.cds.GrpcOperation;
25 import org.onap.policy.controlloop.actorserviceprovider.TargetType;
26 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.util.CollectionUtils;
30
31 /**
32  * GRPC Operation Base Class.
33  */
34 @Data
35 public abstract class GrpcOperationProperties {
36     protected static final String AAI_PNF_PREFIX = "pnf.";
37
38     /**
39      * AAI VNF Identifier.
40      */
41     public static final String AAI_VNF_ID_KEY = "generic-vnf.vnf-id";
42
43     /**
44      * AAI Service Instance Identifier.
45      */
46     public static final String AAI_SERVICE_INSTANCE_ID_KEY = "service-instance.service-instance-id";
47
48     private static final Logger logger = LoggerFactory.getLogger(GrpcOperationProperties.class);
49
50     /**
51      * Build the appropriate GrpcOperation object depending on the target type.
52      */
53     public static GrpcOperationProperties build(ControlLoopOperationParams params) {
54         if (TargetType.PNF.equals(params.getTargetType())) {
55             return new GrpcOperationPnfProperties();
56         }
57
58         // assume VNF processing for backwards compatibility with istanbul
59
60         if (!TargetType.VNF.equals(params.getTargetType())) {
61             logger.warn("Unexpected target type, build VNF-like operation properties");
62         }
63
64         return CollectionUtils.isEmpty(params.getTargetEntityIds())
65                 ? new GrpcOperationTargetVnfProperties()
66                 : new GrcpOperationResourceVnfProperties();
67     }
68
69     /**
70      * Get the property names.
71      */
72     public abstract List<String> getPropertyNames();
73
74     /**
75      * Convert to the AAI properties.
76      */
77     public abstract Map<String, String> convertToAaiProperties(GrpcOperation operation);
78 }