2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.pdp.concepts;
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import java.util.List;
29 import lombok.NoArgsConstructor;
30 import lombok.NonNull;
31 import org.onap.policy.common.parameters.BeanValidationResult;
32 import org.onap.policy.common.parameters.ValidationResult;
33 import org.onap.policy.common.parameters.ValidationStatus;
34 import org.onap.policy.models.base.PfUtils;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
38 * Class to represent a group of all PDP's of the same pdp type running for a particular
41 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
45 public class PdpSubGroup {
46 private String pdpType;
47 private List<ToscaConceptIdentifier> supportedPolicyTypes;
48 private List<ToscaConceptIdentifier> policies;
49 private int currentInstanceCount;
50 private int desiredInstanceCount;
51 private Map<String, String> properties;
52 private List<Pdp> pdpInstances;
55 * Constructs the object, making a deep copy from the source.
57 * @param source source from which to copy fields
59 public PdpSubGroup(@NonNull final PdpSubGroup source) {
60 this.pdpType = source.pdpType;
61 this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaConceptIdentifier::new,
63 this.policies = PfUtils.mapList(source.policies, ToscaConceptIdentifier::new, new ArrayList<>(0));
64 this.currentInstanceCount = source.currentInstanceCount;
65 this.desiredInstanceCount = source.desiredInstanceCount;
66 this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
67 this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new, new ArrayList<>(0));
71 * Validates that appropriate fields are populated for an incoming call to the PAP
74 * @param updateGroupFlow if the operation is pdp group update
75 * @return the validation result
77 public ValidationResult validatePapRest(boolean updateGroupFlow) {
78 var result = new BeanValidationResult("group", this);
80 result.validateNotNull("pdpType", pdpType);
81 // When doing PdpGroup Update operation, supported policy types and policies doesn't have to be validated.
82 if (!updateGroupFlow) {
83 result.validateNotNullList("policies", policies, ToscaConceptIdentifier::validatePapRest);
84 result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
85 ToscaConceptIdentifier::validatePapRest);
87 if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
88 result.addResult("supportedPolicyTypes", supportedPolicyTypes, ValidationStatus.INVALID, "empty list");
92 if (desiredInstanceCount <= 0) {
93 result.addResult("desiredInstanceCount", desiredInstanceCount, ValidationStatus.INVALID, "non-positive");