2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.xacml.std.pap;
23 import com.att.research.xacml.api.pap.PAPException;
24 import com.att.research.xacml.api.pap.PDP;
25 import com.att.research.xacml.api.pap.PDPGroupStatus;
26 import com.att.research.xacml.api.pap.PDPGroupStatus.Status;
27 import com.att.research.xacml.api.pap.PDPPIPConfig;
28 import com.att.research.xacml.api.pap.PDPPolicy;
29 import com.att.research.xacml.util.XACMLProperties;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31 import com.google.common.base.Joiner;
32 import com.google.common.base.Splitter;
33 import com.google.common.io.ByteStreams;
35 import java.io.FileInputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.io.OutputStream;
39 import java.io.Serializable;
40 import java.nio.file.Files;
41 import java.nio.file.Path;
42 import java.nio.file.Paths;
43 import java.util.ArrayList;
44 import java.util.Collections;
45 import java.util.Enumeration;
46 import java.util.HashSet;
47 import java.util.List;
48 import java.util.Properties;
50 import java.util.TreeSet;
51 import lombok.EqualsAndHashCode;
52 import lombok.ToString;
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55 import org.onap.policy.common.logging.eelf.MessageCodes;
56 import org.onap.policy.common.logging.eelf.PolicyLogger;
57 import org.onap.policy.xacml.api.XACMLErrorConstants;
58 import org.onap.policy.xacml.api.pap.OnapPDP;
59 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
60 import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
62 @EqualsAndHashCode(callSuper=false)
64 public class StdPDPGroup extends StdPDPItemSetChangeNotifier
65 implements OnapPDPGroup, StdItemSetChangeListener, Comparable<Object>, Serializable {
67 private static final long serialVersionUID = 1L;
68 private static final String groupNotExist = "Group directory does NOT exist";
69 private static Log logger = LogFactory.getLog(StdPDPGroup.class);
73 private boolean isDefault = false;
77 private String description;
79 private transient StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN);
81 private transient Set<OnapPDP> pdps = new HashSet<>();
83 private transient Set<PDPPolicy> policies = new HashSet<>();
85 private transient Set<PDPPolicy> selectedPolicies = new HashSet<>();
87 private transient Set<PDPPIPConfig> pipConfigs = new HashSet<>();
89 private String operation;
92 private transient Path directory;
95 private Integer jmxport;
97 public StdPDPGroup() {
99 // Methods needed for JSON deserialization
104 * StdPDPGroup constructor.
106 * @param group OnapPDPGroup
108 public StdPDPGroup(OnapPDPGroup group) {
109 this.id = group.getId();
110 this.name = group.getName();
111 this.description = group.getDescription();
112 this.isDefault = group.isDefaultGroup();
113 this.pdps = group.getOnapPdps();
114 this.policies = group.getPolicies();
115 this.pipConfigs = group.getPipConfigs();
118 public StdPDPGroup(String id, Path directory) {
120 this.directory = directory;
123 public StdPDPGroup(String id, boolean isDefault, Path directory) {
125 this.isDefault = isDefault;
132 * @param isDefault boolean
134 * @param description String
135 * @param directory Path
137 public StdPDPGroup(String id, boolean isDefault, String name, String description, Path directory) {
138 this(id, isDefault, directory);
140 // force all policies to have a name
144 this.description = description;
147 public StdPDPGroup(String id, String name, String description, Path directory) {
148 this(id, false, name, description, directory);
156 * @param isDefault boolean
157 * @param properties Properties
158 * @param directory Path
159 * @throws PAPException PAPException
161 public StdPDPGroup(String id, boolean isDefault, Properties properties, Path directory) throws PAPException {
162 this(id, isDefault, directory);
163 this.initialize(properties, directory);
167 private void initialize(Properties properties, Path directory) throws PAPException {
168 if (this.id == null || this.id.length() == 0) {
169 logger.warn("Cannot initialize with a null or zero length id");
173 // Pull the group's properties
175 for (Object key : properties.keySet()) {
176 if (key.toString().startsWith(this.id + ".")) {
177 if (key.toString().endsWith(".name")) {
178 this.name = properties.getProperty(key.toString());
179 } else if (key.toString().endsWith(".description")) {
180 this.description = properties.getProperty(key.toString());
181 } else if (key.toString().endsWith(".pdps")) {
182 String pdpList = properties.getProperty(key.toString());
183 if (pdpList != null && pdpList.length() > 0) {
184 for (String pdpId : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) {
185 StdPDP pdp = new StdPDP(pdpId, properties);
186 pdp.addItemSetChangeListener(this);
192 // force all policies to have a name
193 if (this.name == null) {
198 // Validate our directory
200 if (Files.notExists(directory)) {
201 logger.warn("Group directory does NOT exist: " + directory.toString());
203 Files.createDirectory(directory);
204 this.status.addLoadWarning(groupNotExist);
205 } catch (IOException e) {
206 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", groupNotExist);
207 this.status.addLoadError(groupNotExist);
208 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
214 this.loadPolicies(Paths.get(directory.toString(), "xacml.policy.properties"));
218 this.loadPIPConfig(Paths.get(directory.toString(), "xacml.pip.properties"));
225 * @throws PAPException PAPException
227 public void loadPolicies(Path file) throws PAPException {
229 // Read the Groups Policies
231 Properties policyProperties = new Properties();
232 if (!file.toFile().exists()) {
233 // need to create the properties file with default values
234 policyProperties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "");
235 policyProperties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
236 // save properties to file
237 try (OutputStream os = Files.newOutputStream(file)) {
238 policyProperties.store(os, "");
239 } catch (Exception e) {
240 throw new PAPException("Failed to create new default policy properties file '" + file + "'", e);
243 // load previously existing file
246 // Load the properties
248 try (InputStream is = Files.newInputStream(file)) {
249 policyProperties.load(is);
252 // Parse the policies
254 this.readPolicyProperties(directory, policyProperties);
255 } catch (IOException e) {
256 logger.warn("Failed to load group policy properties file: " + file, e);
257 this.status.addLoadError("Not policy properties defined");
258 this.status.setStatus(Status.LOAD_ERRORS);
259 throw new PAPException("Failed to load group policy properties file: " + file);
268 * @throws PAPException PAPException
270 public void loadPIPConfig(Path file) throws PAPException {
272 // Read the Groups' PIP configuration
274 Properties pipProperties = new Properties();
275 if (!file.toFile().exists()) {
276 // need to create the properties file with no values
277 pipProperties = setPipProperties(pipProperties);
278 // save properties to file
280 try (OutputStream os = Files.newOutputStream(file)) {
281 pipProperties.store(os, "");
283 } catch (Exception e) {
284 throw new PAPException("Failed to create new default pip properties file '" + file + "'", e);
286 // Even if we create a new pip file, we still need to parse and load the properties
288 this.readPipProperties(pipProperties);
289 } catch (Exception e) {
290 throw new PAPException("Failed to load the new pip properties file", e);
295 // Load the properties
297 try (InputStream is = Files.newInputStream(file)) {
298 pipProperties.load(is);
300 // For all old PIP config's modify to the new PIP Configuration.
301 // If PIP is empty add the new values and save it.
302 if ("".equals(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim())) {
303 pipProperties = setPipProperties(pipProperties);
304 try (OutputStream os = Files.newOutputStream(file)) {
305 pipProperties.store(os, "");
311 this.readPipProperties(pipProperties);
312 } catch (IOException e) {
313 logger.warn("Failed to open group PIP Config properties file: " + file, e);
314 this.status.addLoadError("Not PIP config properties defined");
315 this.status.setStatus(Status.LOAD_ERRORS);
316 throw new PAPException("Failed to load group policy properties file: " + file);
325 public void resetStatus() {
327 // Reset our status object
331 // Determine our status
333 for (PDP pdp : this.pdps) {
334 switch (pdp.getStatus().getStatus()) {
336 this.status.addOutOfSynchPDP(pdp);
338 case LAST_UPDATE_FAILED:
339 this.status.addLastUpdateFailedPDP(pdp);
342 this.status.addFailedPDP(pdp);
344 case UPDATING_CONFIGURATION:
345 this.status.addUpdatingPDP(pdp);
348 this.status.addInSynchPDP(pdp);
354 this.status.addUnknownPDP(pdp);
359 // priority is worst-cast to best case
360 if (!this.status.getUnknownPDPs().isEmpty()) {
361 this.status.setStatus(Status.UNKNOWN);
362 } else if (!this.status.getFailedPDPs().isEmpty() || !this.status.getLastUpdateFailedPDPs().isEmpty()) {
363 this.status.setStatus(Status.LOAD_ERRORS);
364 } else if (!this.status.getOutOfSynchPDPs().isEmpty()) {
365 this.status.setStatus(Status.OUT_OF_SYNCH);
366 } else if (!this.status.getUpdatingPDPs().isEmpty()) {
367 this.status.setStatus(Status.UPDATING_CONFIGURATION);
369 this.status.setStatus(Status.OK);
374 public String getId() {
378 public void setId(String id) {
383 public boolean isDefaultGroup() {
384 return this.isDefault;
390 * @param isDefault boolean
392 public void setDefaultGroup(boolean isDefault) {
393 this.isDefault = isDefault;
395 // Cannot fire this because 2 operations have
396 // to occur: 1) old default=false (don't want to fire) and
397 // then 2) new default=true (yes fire - but we'll have to do that
402 public String getName() {
407 public void setName(String groupName) {
408 this.name = groupName;
409 this.firePDPGroupChanged(this);
413 public String getDescription() {
414 return this.description;
418 public void setDescription(String groupDescription) {
419 this.description = groupDescription;
420 this.firePDPGroupChanged(this);
423 public Path getDirectory() {
424 return this.directory;
427 public void setDirectory(Path groupDirectory) {
428 this.directory = groupDirectory;
429 // this is used only for transmission on the RESTful interface, so no need to fire group changed?
433 public PDPGroupStatus getStatus() {
438 public Set<PDPPolicy> getSelectedPolicies() {
439 return this.selectedPolicies;
443 public String getOperation() {
444 return this.operation;
448 public Set<PDP> getPdps() {
449 return Collections.unmodifiableSet(pdps);
452 public void setOnapPdps(Set<OnapPDP> pdps) {
457 public Set<OnapPDP> getOnapPdps() {
458 return Collections.unmodifiableSet(pdps);
461 public boolean addPDP(OnapPDP pdp) {
462 return this.pdps.add(pdp);
465 public boolean removePDP(PDP pdp) {
466 return this.pdps.remove(pdp);
470 public Set<PDPPolicy> getPolicies() {
471 return Collections.unmodifiableSet(this.policies);
475 public PDPPolicy getPolicy(String id) {
476 for (PDPPolicy policy : this.policies) {
477 if (policy.getId().equals(id)) {
485 public Properties getPolicyProperties() {
486 Properties properties = new Properties() {
487 private static final long serialVersionUID = 1L;
489 // For Debugging it is helpful for the file to be in a sorted order,
490 // any by returning the keys in the natural Alpha order for strings we get close enough.
491 // TreeSet is sorted, and this just overrides the normal Properties method to get the keys.
493 public synchronized Enumeration<Object> keys() {
494 return Collections.enumeration(new TreeSet<Object>(super.keySet()));
497 List<String> roots = new ArrayList<>();
498 List<String> refs = new ArrayList<>();
500 for (PDPPolicy policy : this.policies) {
501 // for all policies need to tell PDP the "name", which is the base name for the file id
502 if (policy.getName() != null) {
503 properties.setProperty(policy.getId() + ".name", policy.getName());
505 // put the policy on the correct list
506 if (policy.isRoot()) {
507 roots.add(policy.getId());
509 refs.add(policy.getId());
513 properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, Joiner.on(',').join(roots));
514 properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, Joiner.on(',').join(refs));
524 * @param isRoot boolean
525 * @param policy InputStream
527 * @throws PAPException PAPException
529 public PDPPolicy publishPolicy(String id, String name, boolean isRoot, InputStream policy) throws PAPException {
531 // Does it exist already?
533 if (this.getPolicy(id) != null) {
534 throw new PAPException("Policy with id " + id + " already exists - unpublish it first.");
536 Path tempFile = null;
539 // Copy the policy over
541 tempFile = Files.createFile(Paths.get(this.directory.toAbsolutePath().toString(), id));
543 try (OutputStream os = Files.newOutputStream(tempFile)) {
544 num = ByteStreams.copy(policy, os);
546 logger.info("Copied " + num + " bytes for policy " + name);
548 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri());
549 if (!tempRootPolicy.isValid()) {
551 Files.delete(tempFile);
552 } catch (Exception ee) {
553 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup",
554 "Policy was invalid, could NOT delete it.");
556 throw new PAPException("Policy is invalid");
561 this.policies.add(tempRootPolicy);
565 this.firePDPGroupChanged(this);
567 // Return our new object.
569 return tempRootPolicy;
570 } catch (IOException e) {
571 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Failed to publishPolicy");
577 * Copy one policy file into the Group's directory but do not change the configuration.
578 * This is one part of a multi-step process of publishing policies.
579 * There may be multiple changes in the group (adding multiple policies, deleting policies, changine
581 * that must be done all at once, so we just copy the file in preparation for a later "update whole group"
585 * @param policy InputStream
586 * @throws PAPException PAPException
588 public void copyPolicyToFile(String id, InputStream policy) throws PAPException {
591 // Copy the policy over
594 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
597 if (Files.exists(policyFilePath)) {
598 policyFile = policyFilePath;
600 policyFile = Files.createFile(policyFilePath);
603 try (OutputStream os = Files.newOutputStream(policyFile)) {
604 num = ByteStreams.copy(policy, os);
607 logger.info("Copied " + num + " bytes for policy " + name);
609 for (PDPPolicy p : policies) {
610 if (p.getId().equals(id)) {
611 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this
613 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
618 // policy is new to this group
619 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
620 if (!tempRootPolicy.isValid()) {
622 Files.delete(policyFile);
623 } catch (Exception ee) {
624 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup",
625 "Policy was invalid, could NOT delete it.");
627 throw new PAPException("Policy is invalid");
632 this.policies.add(tempRootPolicy);
636 this.firePDPGroupChanged(this);
637 } catch (IOException e) {
638 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
639 throw new PAPException("Failed to copy policy to file: " + e);
644 * Policy Engine API Copy one policy file into the Group's directory but do not change the configuration.
648 * @param policy InputStream
649 * @throws PAPException PAPException
651 public void copyPolicyToFile(String id, String name, InputStream policy) throws PAPException {
654 // Copy the policy over
657 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
660 if (Files.exists(policyFilePath)) {
661 policyFile = policyFilePath;
663 policyFile = Files.createFile(policyFilePath);
666 try (OutputStream os = Files.newOutputStream(policyFile)) {
667 num = ByteStreams.copy(policy, os);
670 logger.info("Copied " + num + " bytes for policy " + name);
671 for (PDPPolicy p : policies) {
672 if (p.getId().equals(id)) {
673 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this
675 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
680 // policy is new to this group
681 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
682 if (!tempRootPolicy.isValid()) {
684 Files.delete(policyFile);
685 } catch (Exception ee) {
686 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup",
687 "Policy was invalid, could NOT delete it.");
689 throw new PAPException("Policy is invalid");
694 this.policies.add(tempRootPolicy);
698 this.firePDPGroupChanged(this);
700 } catch (IOException e) {
701 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
702 throw new PAPException("Failed to copy policy to file: " + e);
707 * removePolicyFromGroup.
709 * @param policy PDPPolicy
712 public boolean removePolicyFromGroup(PDPPolicy policy) {
713 PolicyLogger.info("policy: " + policy.getId());
714 PolicyLogger.info("Policy ID:" + policy.getPolicyId());
715 PolicyLogger.info("Policy Version: " + policy.getVersion());
716 PolicyLogger.info("StdPDPPolicy Class cast: " + this.getPolicy(policy.getId()).toString());
717 StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId());
718 if (currentPolicy == null) {
719 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
724 // Remove it from our list
726 this.policies.remove(currentPolicy);
730 this.firePDPGroupChanged(this);
732 } catch (Exception e) {
733 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy");
741 * @param policy PDPPolicy
744 public boolean removePolicy(PDPPolicy policy) {
745 PDPPolicy currentPolicy = this.getPolicy(policy.getId());
746 if (currentPolicy == null) {
747 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
754 Files.delete(Paths.get(currentPolicy.getLocation()));
756 // Remove it from our list
758 this.policies.remove(currentPolicy);
762 this.firePDPGroupChanged(this);
764 } catch (Exception e) {
765 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy " + policy);
771 public Set<PDPPIPConfig> getPipConfigs() {
772 return Collections.unmodifiableSet(this.pipConfigs);
776 public PDPPIPConfig getPipConfig(String id) {
777 for (PDPPIPConfig config : this.pipConfigs) {
778 if (config.getId().equals(id)) {
785 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
786 this.pipConfigs = pipConfigs;
787 this.firePDPGroupChanged(this);
790 public void removeAllPIPConfigs() {
791 this.pipConfigs.clear();
792 this.firePDPGroupChanged(this);
796 public Properties getPipConfigProperties() {
797 Properties properties = new Properties();
798 List<String> configs = new ArrayList<>();
800 for (PDPPIPConfig config : this.pipConfigs) {
801 configs.add(config.getId());
802 properties.putAll(config.getConfiguration());
805 properties.setProperty(XACMLProperties.PROP_PIP_ENGINES, Joiner.on(',').join(configs));
811 public void repair() {
813 // Reset the status object
817 // Validate our directory
819 boolean fire = false;
820 if (Files.notExists(directory)) {
821 logger.warn("Group directory does NOT exist: " + directory.toString());
823 Files.createDirectory(directory);
825 this.status.addLoadWarning("Created missing group directory");
826 } catch (IOException e) {
827 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup",
828 "Failed to create missing Group directory.");
829 this.status.addLoadError("Failed to create missing Group directory.");
830 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
834 // Validate our PIP config file
836 Path pipPropertiesFile = Paths.get(directory.toString(), "xacml.pip.properties");
837 if (Files.notExists(pipPropertiesFile)) {
839 Files.createFile(pipPropertiesFile);
841 this.status.addLoadWarning("Created missing PIP properties file");
842 } catch (IOException e) {
843 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup",
844 "Failed to create missing PIP properties file");
845 this.status.addLoadError("Failed to create missing PIP properties file");
846 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
850 // Valid our policy properties file
852 Path policyPropertiesFile = Paths.get(directory.toString(), "xacml.policy.properties");
853 if (Files.notExists(policyPropertiesFile)) {
855 Files.createFile(policyPropertiesFile);
857 this.status.addLoadWarning("Created missing Policy properties file");
858 } catch (IOException e) {
859 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup",
860 "Failed to create missing Policy properties file");
861 this.status.addLoadError("Failed to create missing Policy properties file");
862 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
871 private void readPolicyProperties(Path directory, Properties properties) {
873 // There are 2 property values that hold policies, root and referenced
875 String[] lists = new String[2];
876 lists[0] = properties.getProperty(XACMLProperties.PROP_ROOTPOLICIES);
877 lists[1] = properties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
879 // Iterate each policy list
881 boolean isRoot = true;
882 for (String list : lists) {
884 // Was there actually a property?
886 if (list == null || list.length() == 0) {
893 Iterable<String> policyList = Splitter.on(',').trimResults().omitEmptyStrings().split(list);
895 // Was there actually a list
897 if (policyList == null) {
901 for (String policyId : policyList) {
903 // Construct the policy filename
905 Path policyPath = Paths.get(directory.toString(), policyId);
907 // Create the Policy Object
911 policy = new StdPDPPolicy(id, isRoot, policyPath.toUri(), properties);
912 } catch (IOException e) {
913 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup",
914 "Failed to create policy object");
920 if (policy != null && policy.isValid()) {
921 this.policies.add(policy);
922 this.status.addLoadedPolicy(policy);
924 this.status.addFailedPolicy(policy);
925 this.status.setStatus(Status.LOAD_ERRORS);
927 // force all policies to have a name
928 if (policy != null && policy.getName() == null) {
929 policy.setName(policy.getId());
936 private void readPipProperties(Properties properties) {
937 String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES);
938 if (list == null || list.length() == 0) {
941 for (String pipId : list.split("[,]")) {
942 StdPDPPIPConfig config = new StdPDPPIPConfig(pipId, properties);
943 if (config.isConfigured()) {
944 this.pipConfigs.add(config);
945 this.status.addLoadedPipConfig(config);
947 this.status.addFailedPipConfig(config);
948 this.status.setStatus(Status.LOAD_ERRORS);
954 public void changed() {
956 // save the (changed) properties
958 saveGroupConfiguration();
959 } catch (PAPException | IOException e) {
960 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup",
961 "Unable to save group configuration change");
962 // don't notify other things of change if we cannot save it???
966 this.firePDPGroupChanged(this);
971 public void groupChanged(OnapPDPGroup group) {
976 public void pdpChanged(OnapPDP pdp) {
978 // If one of the group's PDP's changed, then the group changed
983 public boolean isDefault() {
987 public void setDefault(boolean isDefault) {
988 this.isDefault = isDefault;
991 public void setStatus(PDPGroupStatus status) {
992 this.status = new StdPDPGroupStatus(status);
995 public void setPolicies(Set<PDPPolicy> policies) {
996 this.policies = policies;
999 public void setSelectedPolicies(Set<PDPPolicy> selectedPolicies) {
1000 this.selectedPolicies = selectedPolicies;
1003 public void setOperation(String operation) {
1004 this.operation = operation;
1008 * saveGroupConfiguration.
1010 * @throws PAPException PAPException
1011 * @throws IOException IOException
1013 public void saveGroupConfiguration() throws PAPException, IOException {
1015 // First save the Policy properties
1017 // save the lists of policies
1018 Properties policyProperties = this.getPolicyProperties();
1020 // save info about each policy
1021 for (PDPPolicy policy : this.policies) {
1022 policyProperties.put(policy.getId() + ".name", policy.getName());
1026 // Now we can save the file
1028 Path file = Paths.get(this.directory.toString(), "xacml.policy.properties");
1029 try (OutputStream os = Files.newOutputStream(file)) {
1030 policyProperties.store(os, "");
1031 } catch (Exception e) {
1032 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "STdPDPGroup", "Group Policies Config save failed");
1033 throw new PAPException("Failed to save policy properties file '" + file + "'");
1036 // Now save the PIP Config properties
1037 Properties pipProperties = this.getPipConfigProperties();
1040 // Now we can save the file
1042 file = Paths.get(this.directory.toString(), "xacml.pip.properties");
1043 try (OutputStream os = Files.newOutputStream(file)) {
1044 pipProperties.store(os, "");
1045 } catch (Exception e) {
1046 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group PIP Config save failed");
1047 throw new PAPException("Failed to save pip properties file '" + file + "'");
1052 // Comparable Interface
1055 public int compareTo(Object arg0) {
1059 if (!(arg0 instanceof StdPDPGroup)) {
1062 if (((StdPDPGroup) arg0).name == null) {
1069 return name.compareTo(((StdPDPGroup) arg0).name);
1072 // Adding Default PIP engine(s) while Loading initially. We don't want
1073 // Programmer intervention with the PIP engines.
1074 private Properties setPipProperties(Properties props) {
1075 props.setProperty("AAF.name", "AAFEngine");
1076 props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions");
1077 props.setProperty("AAF.classname", "org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine");
1078 props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF");
1079 // read from PIP properties file.
1080 Path file = Paths.get(StdEngine.pipPropertyFile);
1081 if (!Files.notExists(file)) {
1083 Properties prop = new Properties();
1085 in = new FileInputStream(file.toFile());
1087 } catch (IOException e) {
1089 XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" + e);