Alter PDP_UPDATE message to store lists of delpoyed/undeployed policies
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / concepts / PdpUpdate.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
5  *  Modifications Copyright (C) 2021 Nordix Foundation.
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.pdp.concepts;
24
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.stream.Collectors;
28 import lombok.Getter;
29 import lombok.Setter;
30 import lombok.ToString;
31 import org.onap.policy.models.pdp.enums.PdpMessageType;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
34
35 /**
36  * Class to represent the PDP_UPDATE message that PAP will send to a PDP. When a PDP
37  * receives this message, it should save the group and subgroup and pass them to
38  * {@link #appliesTo(String, String, String)} of subsequent messages that it receives.
39  *
40  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41  */
42 @Getter
43 @Setter
44 @ToString(callSuper = true)
45 public class PdpUpdate extends PdpMessage {
46
47     /**
48      * Description of the PDP group.
49      */
50     private String description;
51
52     private Long pdpHeartbeatIntervalMs;
53
54     /**
55      * Policies that the PDP should deploy. This is a complete list, so PDPs should be
56      * prepared to deploy new policies listed and undeploy policies that are no longer
57      * listed. Note: this list may be empty, as a PDP may remain attached to a subgroup
58      * even if all of the policies are removed from the subgroup.
59      */
60     private List<ToscaPolicy> policies = new LinkedList<>();
61
62     /**
63      * Policies that the PDP should deploy.
64      */
65     private List<ToscaPolicy> policiesToBeDeployed = new LinkedList<>();
66
67     /**
68      * Policies that the PDP should undeploy.
69      */
70     private List<ToscaConceptIdentifier> policiesToBeUndeployed = new LinkedList<>();
71
72     /**
73      * Constructor for instantiating PdpUpdate class with message name.
74      *
75      */
76     public PdpUpdate() {
77         super(PdpMessageType.PDP_UPDATE);
78     }
79
80     /**
81      * Constructs the object, making a deep copy.
82      *
83      * @param source source from which to copy
84      */
85     public PdpUpdate(PdpUpdate source) {
86         super(source);
87
88         this.description = source.description;
89         this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs;
90         this.policies = (source.policies == null ? null
91                         : source.policies.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
92     }
93 }