2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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=========================================================
20 package org.onap.policy.xacml.std.pap;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.io.Serializable;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Enumeration;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Properties;
37 import java.util.TreeSet;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import org.onap.policy.common.logging.eelf.MessageCodes;
42 import org.onap.policy.common.logging.eelf.PolicyLogger;
43 import org.onap.policy.xacml.api.XACMLErrorConstants;
44 import org.onap.policy.xacml.api.pap.OnapPDP;
45 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
46 import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
48 import com.att.research.xacml.api.pap.PAPException;
49 import com.att.research.xacml.api.pap.PDP;
50 import com.att.research.xacml.api.pap.PDPGroupStatus;
51 import com.att.research.xacml.api.pap.PDPGroupStatus.Status;
52 import com.att.research.xacml.api.pap.PDPPIPConfig;
53 import com.att.research.xacml.api.pap.PDPPolicy;
54 import com.att.research.xacml.util.XACMLProperties;
55 import com.fasterxml.jackson.annotation.JsonIgnore;
56 import com.google.common.base.Joiner;
57 import com.google.common.base.Splitter;
58 import com.google.common.io.ByteStreams;
60 public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPGroup, StdItemSetChangeListener, Comparable<Object>, Serializable {
62 private static final long serialVersionUID = 1L;
63 private static final String groupNotExist= "Group directory does NOT exist";
64 private static Log logger = LogFactory.getLog(StdPDPGroup.class);
68 private boolean isDefault = false;
72 private String description;
74 private transient StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN);
76 private transient Set<OnapPDP> pdps = new HashSet<>();
78 private transient Set<PDPPolicy> policies = new HashSet<>();
80 private transient Set<PDPPolicy> selectedPolicies = new HashSet<>();
82 private transient Set<PDPPIPConfig> pipConfigs = new HashSet<>();
84 private String operation;
87 private transient Path directory;
90 private Integer jmxport;
92 public StdPDPGroup() {
94 // Methods needed for JSON deserialization
98 public StdPDPGroup(OnapPDPGroup group) {
99 this.id = group.getId();
100 this.name = group.getName();
101 this.description = group.getDescription();
102 this.isDefault = group.isDefaultGroup();
103 this.pdps = group.getOnapPdps();
104 this.policies = group.getPolicies();
105 this.pipConfigs = group.getPipConfigs();
108 public StdPDPGroup(String id, Path directory) {
110 this.directory = directory;
113 public StdPDPGroup(String id, boolean isDefault, Path directory) {
115 this.isDefault = isDefault;
118 public StdPDPGroup(String id, boolean isDefault, String name, String description, Path directory) {
119 this(id, isDefault, directory);
121 // force all policies to have a name
125 this.description = description;
128 public StdPDPGroup(String id, String name, String description, Path directory) {
129 this(id, false, name, description, directory);
133 public StdPDPGroup(String id, boolean isDefault, Properties properties, Path directory) throws PAPException {
134 this(id, isDefault, directory);
135 this.initialize(properties, directory);
139 private void initialize(Properties properties, Path directory) throws PAPException {
140 if (this.id == null || this.id.length() == 0) {
141 logger.warn("Cannot initialize with a null or zero length id");
145 // Pull the group's properties
147 for (Object key : properties.keySet()) {
148 if (key.toString().startsWith(this.id + ".")) {
149 if (key.toString().endsWith(".name")) {
150 this.name = properties.getProperty(key.toString());
151 } else if (key.toString().endsWith(".description")) {
152 this.description = properties.getProperty(key.toString());
153 } else if (key.toString().endsWith(".pdps")) {
154 String pdpList = properties.getProperty(key.toString());
155 if (pdpList != null && pdpList.length() > 0) {
156 for (String pdpId : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) {
157 StdPDP pdp = new StdPDP(pdpId, properties);
158 pdp.addItemSetChangeListener(this);
164 // force all policies to have a name
165 if (this.name == null) {
170 // Validate our directory
172 if (Files.notExists(directory)) {
173 logger.warn("Group directory does NOT exist: " + directory.toString());
175 Files.createDirectory(directory);
176 this.status.addLoadWarning(groupNotExist);
177 } catch (IOException e) {
178 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", groupNotExist);
179 this.status.addLoadError(groupNotExist);
180 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
186 this.loadPolicies(Paths.get(directory.toString(), "xacml.policy.properties"));
190 this.loadPIPConfig(Paths.get(directory.toString(), "xacml.pip.properties"));
193 public void loadPolicies(Path file) throws PAPException {
195 // Read the Groups Policies
197 Properties policyProperties = new Properties();
198 if ( ! file.toFile().exists()) {
199 // need to create the properties file with default values
200 policyProperties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "");
201 policyProperties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
202 // save properties to file
203 try (OutputStream os = Files.newOutputStream(file)) {
204 policyProperties.store(os, "");
205 } catch (Exception e) {
206 throw new PAPException("Failed to create new default policy properties file '" + file +"'", e);
209 // load previously existing file
212 // Load the properties
214 try (InputStream is = Files.newInputStream(file)) {
215 policyProperties.load(is);
218 // Parse the policies
220 this.readPolicyProperties(directory, policyProperties);
221 } catch (IOException e) {
222 logger.warn("Failed to load group policy properties file: " + file, e);
223 this.status.addLoadError("Not policy properties defined");
224 this.status.setStatus(Status.LOAD_ERRORS);
225 throw new PAPException("Failed to load group policy properties file: " + file);
230 public void loadPIPConfig(Path file) throws PAPException {
232 // Read the Groups' PIP configuration
234 Properties pipProperties = new Properties();
235 if ( ! file.toFile().exists()) {
236 // need to create the properties file with no values
237 pipProperties = setPIPProperties(pipProperties);
238 // save properties to file
240 try (OutputStream os = Files.newOutputStream(file)) {
241 pipProperties.store(os, "");
243 } catch (Exception e) {
244 throw new PAPException("Failed to create new default pip properties file '" + file +"'", e);
246 //Even if we create a new pip file, we still need to parse and load the properties
248 this.readPIPProperties(pipProperties);
250 throw new PAPException("Failed to load the new pip properties file", e);
255 // Load the properties
257 try (InputStream is = Files.newInputStream(file)) {
258 pipProperties.load(is);
260 // For all old PIP config's modify to the new PIP Configuration.
261 // If PIP is empty add the new values and save it.
262 if("".equals(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim())){
263 pipProperties = setPIPProperties(pipProperties);
264 try (OutputStream os = Files.newOutputStream(file)) {
265 pipProperties.store(os, "");
271 this.readPIPProperties(pipProperties);
272 } catch (IOException e) {
273 logger.warn("Failed to open group PIP Config properties file: " + file, e);
274 this.status.addLoadError("Not PIP config properties defined");
275 this.status.setStatus(Status.LOAD_ERRORS);
276 throw new PAPException("Failed to load group policy properties file: " + file);
282 public void resetStatus() {
284 // Reset our status object
288 // Determine our status
290 for (PDP pdp : this.pdps) {
291 switch (pdp.getStatus().getStatus()) {
293 this.status.addOutOfSynchPDP(pdp);
295 case LAST_UPDATE_FAILED:
296 this.status.addLastUpdateFailedPDP(pdp);
299 this.status.addFailedPDP(pdp);
301 case UPDATING_CONFIGURATION:
302 this.status.addUpdatingPDP(pdp);
305 this.status.addInSynchPDP(pdp);
311 this.status.addUnknownPDP(pdp);
316 // priority is worst-cast to best case
317 if (!this.status.getUnknownPDPs().isEmpty()) {
318 this.status.setStatus(Status.UNKNOWN);
319 } else if (!this.status.getFailedPDPs().isEmpty() || !this.status.getLastUpdateFailedPDPs().isEmpty()) {
320 this.status.setStatus(Status.LOAD_ERRORS);
321 } else if (!this.status.getOutOfSynchPDPs().isEmpty()) {
322 this.status.setStatus(Status.OUT_OF_SYNCH);
323 } else if (!this.status.getUpdatingPDPs().isEmpty()) {
324 this.status.setStatus(Status.UPDATING_CONFIGURATION);
326 this.status.setStatus(Status.OK);
331 public String getId() {
335 public void setId(String id) {
340 public boolean isDefaultGroup() {
341 return this.isDefault;
344 public void setDefaultGroup(boolean isDefault) {
345 this.isDefault = isDefault;
347 // Cannot fire this because 2 operations have
348 // to occur: 1) old default=false (don't want to fire) and
349 // then 2) new default=true (yes fire - but we'll have to do that
354 public String getName() {
359 public void setName(String groupName) {
360 this.name = groupName;
361 this.firePDPGroupChanged(this);
365 public String getDescription() {
366 return this.description;
370 public void setDescription(String groupDescription) {
371 this.description = groupDescription;
372 this.firePDPGroupChanged(this);
375 public Path getDirectory() {
376 return this.directory;
379 public void setDirectory(Path groupDirectory) {
380 this.directory = groupDirectory;
381 // this is used only for transmission on the RESTful interface, so no need to fire group changed?
385 public PDPGroupStatus getStatus(){
390 public Set<PDPPolicy> getSelectedPolicies() {
391 return this.selectedPolicies;
395 public String getOperation() {
396 return this.operation;
400 public Set<PDP> getPdps() {
401 return Collections.unmodifiableSet(pdps);
404 public void setOnapPdps(Set<OnapPDP> pdps) {
409 public Set<OnapPDP> getOnapPdps(){
410 return Collections.unmodifiableSet(pdps);
413 public boolean addPDP(OnapPDP pdp) {
414 return this.pdps.add(pdp);
417 public boolean removePDP(PDP pdp) {
418 return this.pdps.remove(pdp);
422 public Set<PDPPolicy> getPolicies() {
423 return Collections.unmodifiableSet(this.policies);
427 public PDPPolicy getPolicy(String id) {
428 for (PDPPolicy policy : this.policies) {
429 if (policy.getId().equals(id)) {
437 public Properties getPolicyProperties()
439 Properties properties = new Properties(){
440 private static final long serialVersionUID = 1L;
441 // For Debugging it is helpful for the file to be in a sorted order,
442 // any by returning the keys in the natural Alpha order for strings we get close enough.
443 // TreeSet is sorted, and this just overrides the normal Properties method to get the keys.
445 public synchronized Enumeration<Object> keys() {
446 return Collections.enumeration(new TreeSet<Object>(super.keySet()));
449 List<String> roots = new ArrayList<>();
450 List<String> refs = new ArrayList<>();
452 for (PDPPolicy policy : this.policies) {
453 // for all policies need to tell PDP the "name", which is the base name for the file id
454 if (policy.getName() != null) {
455 properties.setProperty(policy.getId() + ".name", policy.getName());
457 // put the policy on the correct list
458 if (policy.isRoot()) {
459 roots.add(policy.getId());
461 refs.add(policy.getId());
465 properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, Joiner.on(',').join(roots));
466 properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, Joiner.on(',').join(refs));
471 public PDPPolicy publishPolicy(String id, String name, boolean isRoot, InputStream policy) throws PAPException {
473 // Does it exist already?
475 if (this.getPolicy(id) != null) {
476 throw new PAPException("Policy with id " + id + " already exists - unpublish it first.");
478 Path tempFile = null;
481 // Copy the policy over
483 tempFile = Files.createFile(Paths.get(this.directory.toAbsolutePath().toString(), id));
485 try (OutputStream os = Files.newOutputStream(tempFile)) {
486 num = ByteStreams.copy(policy, os);
488 logger.info("Copied " + num + " bytes for policy " + name);
490 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri());
491 if (!tempRootPolicy.isValid()) {
493 Files.delete(tempFile);
494 } catch(Exception ee) {
495 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
497 throw new PAPException("Policy is invalid");
502 this.policies.add(tempRootPolicy);
506 this.firePDPGroupChanged(this);
508 // Return our new object.
510 return tempRootPolicy;
511 } catch (IOException e) {
512 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Failed to publishPolicy");
518 * Copy one policy file into the Group's directory but do not change the configuration.
519 * This is one part of a multi-step process of publishing policies.
520 * There may be multiple changes in the group (adding multiple policies, deleting policies, changine root<->referenced)
521 * that must be done all at once, so we just copy the file in preparation for a later "update whole group" operation.
528 * @throws PAPException
530 public void copyPolicyToFile(String id, InputStream policy) throws PAPException {
533 // Copy the policy over
536 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
539 if (Files.exists(policyFilePath)) {
540 policyFile = policyFilePath;
542 policyFile = Files.createFile(policyFilePath);
545 try (OutputStream os = Files.newOutputStream(policyFile)) {
546 num = ByteStreams.copy(policy, os);
549 logger.info("Copied " + num + " bytes for policy " + name);
551 for (PDPPolicy p : policies) {
552 if (p.getId().equals(id)) {
553 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
554 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
559 // policy is new to this group
560 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
561 if (!tempRootPolicy.isValid()) {
563 Files.delete(policyFile);
564 } catch(Exception ee) {
565 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
567 throw new PAPException("Policy is invalid");
572 this.policies.add(tempRootPolicy);
576 this.firePDPGroupChanged(this);
577 } catch (IOException e) {
578 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
579 throw new PAPException("Failed to copy policy to file: " + e);
585 * Policy Engine API Copy one policy file into the Group's directory but do not change the configuration.
591 * @throws PAPException
593 public void copyPolicyToFile(String id, String name, InputStream policy) throws PAPException {
596 // Copy the policy over
599 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
602 if (Files.exists(policyFilePath)) {
603 policyFile = policyFilePath;
605 policyFile = Files.createFile(policyFilePath);
608 try (OutputStream os = Files.newOutputStream(policyFile)) {
609 num = ByteStreams.copy(policy, os);
612 logger.info("Copied " + num + " bytes for policy " + name);
613 for (PDPPolicy p : policies) {
614 if (p.getId().equals(id)) {
615 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
616 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
621 // policy is new to this group
622 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
623 if (!tempRootPolicy.isValid()) {
625 Files.delete(policyFile);
626 } catch(Exception ee) {
627 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
629 throw new PAPException("Policy is invalid");
634 this.policies.add(tempRootPolicy);
638 this.firePDPGroupChanged(this);
640 } catch (IOException e) {
641 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
642 throw new PAPException("Failed to copy policy to file: " + e);
647 public boolean removePolicyFromGroup(PDPPolicy policy) {
648 PolicyLogger.info("policy: " + policy.getId());
649 PolicyLogger.info("Policy ID:" + policy.getPolicyId());
650 PolicyLogger.info("Policy Version: " + policy.getVersion());
651 PolicyLogger.info("StdPDPPolicy Class cast: " + this.getPolicy(policy.getId()).toString());
652 StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId());
653 if (currentPolicy == null) {
654 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
659 // Remove it from our list
661 this.policies.remove(currentPolicy);
665 this.firePDPGroupChanged(this);
667 } catch (Exception e) {
668 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy");
673 public boolean removePolicy(PDPPolicy policy) {
674 PDPPolicy currentPolicy = this.getPolicy(policy.getId());
675 if (currentPolicy == null) {
676 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
683 Files.delete(Paths.get(currentPolicy.getLocation()));
685 // Remove it from our list
687 this.policies.remove(currentPolicy);
691 this.firePDPGroupChanged(this);
693 } catch (Exception e) {
694 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy " + policy);
700 public Set<PDPPIPConfig> getPipConfigs() {
701 return Collections.unmodifiableSet(this.pipConfigs);
705 public PDPPIPConfig getPipConfig(String id) {
706 for (PDPPIPConfig config : this.pipConfigs) {
707 if (config.getId().equals(id)) {
714 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
715 this.pipConfigs = pipConfigs;
716 this.firePDPGroupChanged(this);
719 public void removeAllPIPConfigs() {
720 this.pipConfigs.clear();
721 this.firePDPGroupChanged(this);
725 public Properties getPipConfigProperties() {
726 Properties properties = new Properties();
727 List<String> configs = new ArrayList<>();
729 for (PDPPIPConfig config : this.pipConfigs) {
730 configs.add(config.getId());
731 properties.putAll(config.getConfiguration());
734 properties.setProperty(XACMLProperties.PROP_PIP_ENGINES, Joiner.on(',').join(configs));
740 public void repair() {
742 // Reset the status object
746 // Validate our directory
748 boolean fire = false;
749 if (Files.notExists(directory)) {
750 logger.warn("Group directory does NOT exist: " + directory.toString());
752 Files.createDirectory(directory);
754 this.status.addLoadWarning("Created missing group directory");
755 } catch (IOException e) {
756 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Group directory.");
757 this.status.addLoadError("Failed to create missing Group directory.");
758 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
762 // Validate our PIP config file
764 Path pipPropertiesFile = Paths.get(directory.toString(), "xacml.pip.properties");
765 if (Files.notExists(pipPropertiesFile)) {
767 Files.createFile(pipPropertiesFile);
769 this.status.addLoadWarning("Created missing PIP properties file");
770 } catch (IOException e) {
771 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing PIP properties file");
772 this.status.addLoadError("Failed to create missing PIP properties file");
773 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
777 // Valid our policy properties file
779 Path policyPropertiesFile = Paths.get(directory.toString(), "xacml.policy.properties");
780 if (Files.notExists(policyPropertiesFile)) {
782 Files.createFile(policyPropertiesFile);
784 this.status.addLoadWarning("Created missing Policy properties file");
785 } catch (IOException e) {
786 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Policy properties file");
787 this.status.addLoadError("Failed to create missing Policy properties file");
788 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
797 private void readPolicyProperties(Path directory, Properties properties) {
799 // There are 2 property values that hold policies, root and referenced
801 String[] lists = new String[2];
802 lists[0] = properties.getProperty(XACMLProperties.PROP_ROOTPOLICIES);
803 lists[1] = properties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
805 // Iterate each policy list
807 boolean isRoot = true;
808 for (String list : lists) {
810 // Was there actually a property?
812 if (list == null || list.length() == 0) {
819 Iterable<String> policyList = Splitter.on(',').trimResults().omitEmptyStrings().split(list);
821 // Was there actually a list
823 if (policyList == null) {
827 for (String policyId : policyList) {
829 // Construct the policy filename
831 Path policyPath = Paths.get(directory.toString(), policyId );
833 // Create the Policy Object
837 policy = new StdPDPPolicy(id, isRoot, policyPath.toUri(), properties);
838 } catch (IOException e) {
839 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create policy object");
845 if (policy != null && policy.isValid()) {
846 this.policies.add(policy);
847 this.status.addLoadedPolicy(policy);
849 this.status.addFailedPolicy(policy);
850 this.status.setStatus(Status.LOAD_ERRORS);
852 // force all policies to have a name
853 if (policy!=null && policy.getName() == null) {
854 policy.setName(policy.getId());
861 private void readPIPProperties(Properties properties) {
862 String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES);
863 if (list == null || list.length() == 0) {
866 for (String pipId : list.split("[,]")) {
867 StdPDPPIPConfig config = new StdPDPPIPConfig(pipId, properties);
868 if (config.isConfigured()) {
869 this.pipConfigs.add(config);
870 this.status.addLoadedPipConfig(config);
872 this.status.addFailedPipConfig(config);
873 this.status.setStatus(Status.LOAD_ERRORS);
879 public int hashCode() {
880 final int prime = 31;
882 result = prime * result + ((id == null) ? 0 : id.hashCode());
887 public boolean equals(Object obj) {
892 if (getClass() != obj.getClass())
894 StdPDPGroup other = (StdPDPGroup) obj;
896 if (other.id != null)
898 } else if (!id.equals(other.id))
904 public String toString() {
905 return "StdPDPGroup [id=" + id + ", isDefault=" + isDefault + ", name="
906 + name + ", description=" + description + ", status=" + status
907 + ", pdps=" + pdps + ", policies=" + policies + ", pipConfigs="
908 + pipConfigs + ", directory=" + directory + ",selectedPolicies="
909 + selectedPolicies + ",operation=" + operation + "]";
913 public void changed() {
915 // save the (changed) properties
917 saveGroupConfiguration();
918 } catch (PAPException | IOException e) {
919 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Unable to save group configuration change");
920 // don't notify other things of change if we cannot save it???
924 this.firePDPGroupChanged(this);
929 public void groupChanged(OnapPDPGroup group) {
934 public void pdpChanged(OnapPDP pdp) {
936 // If one of the group's PDP's changed, then the group changed
941 public boolean isDefault() {
944 public void setDefault(boolean isDefault) {
945 this.isDefault = isDefault;
947 public void setStatus(PDPGroupStatus status) {
948 this.status = new StdPDPGroupStatus(status);
950 public void setPolicies(Set<PDPPolicy> policies) {
951 this.policies = policies;
953 public void setSelectedPolicies(Set<PDPPolicy> selectedPolicies) {
954 this.selectedPolicies = selectedPolicies;
956 public void setOperation(String operation) {
957 this.operation = operation;
960 public void saveGroupConfiguration() throws PAPException, IOException {
962 // First save the Policy properties
964 // save the lists of policies
965 Properties policyProperties = this.getPolicyProperties();
967 // save info about each policy
968 for (PDPPolicy policy : this.policies){
969 policyProperties.put(policy.getId() + ".name", policy.getName());
973 // Now we can save the file
975 Path file = Paths.get(this.directory.toString(), "xacml.policy.properties");
976 try (OutputStream os = Files.newOutputStream(file)) {
977 policyProperties.store(os, "");
978 } catch (Exception e) {
979 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "STdPDPGroup", "Group Policies Config save failed");
980 throw new PAPException("Failed to save policy properties file '" + file +"'");
984 // Now save the PIP Config properties
985 Properties pipProperties = this.getPipConfigProperties();
988 // Now we can save the file
990 file = Paths.get(this.directory.toString(), "xacml.pip.properties");
991 try (OutputStream os = Files.newOutputStream(file)) {
992 pipProperties.store(os, "");
993 } catch (Exception e) {
994 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group PIP Config save failed");
995 throw new PAPException("Failed to save pip properties file '" + file +"'");
1000 // Comparable Interface
1003 public int compareTo(Object arg0) {
1007 if ( ! (arg0 instanceof StdPDPGroup)) {
1010 if (((StdPDPGroup)arg0).name == null) {
1017 return name.compareTo(((StdPDPGroup)arg0).name);
1020 //Adding Default PIP engine(s) while Loading initially. We don't want
1021 // Programmer intervention with the PIP engines.
1022 private Properties setPIPProperties(Properties props){
1023 props.setProperty("AAF.name", "AAFEngine");
1024 props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions");
1025 props.setProperty("AAF.classname","org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine");
1026 props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF");
1027 // read from PIP properties file.
1028 Path file = Paths.get(StdEngine.pipPropertyFile);
1029 if (!Files.notExists(file)) {
1031 Properties prop = new Properties();
1033 in = new FileInputStream(file.toFile());
1035 } catch (IOException e) {
1036 PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e);