import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
-
import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static boolean needsInit = true;
private static ServiceLoader<XacmlApplicationServiceProvider> applicationLoader;
private static Map<String, XacmlApplicationServiceProvider> providerActionMap = new HashMap<>();
+ private static List<ToscaPolicyTypeIdentifier> toscaPolicyTypeIdents = new ArrayList<>();
private XacmlPdpApplicationManager() {
super();
// Load service
//
applicationLoader = ServiceLoader.load(XacmlApplicationServiceProvider.class);
+
//
- // Iterate through them
+ // Iterate through them the applications for actions and supported policy types
//
- Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator();
- while (iterator.hasNext()) {
- //
- // Get the application
- //
- XacmlApplicationServiceProvider application = iterator.next();
+ for (XacmlApplicationServiceProvider application : applicationLoader) {
+
LOGGER.info("Application {} supports {}", application.applicationName(),
application.supportedPolicyTypes());
+
//
- // Iterate each application
+ // Iterate through the actions and save in the providerActionMap
//
int pathCount = 1;
for (String action : application.actionDecisionsSupported()) {
// May need to scan this name to remove unsafe characters etc.
// But for debugging purposes, its good to use the application name
//
- //
Path path = Paths.get(applicationPath.toAbsolutePath().toString(),
application.applicationName(), Integer.toString(pathCount++));
//
//
application.initialize(path);
}
+
+ // Get string list of supportedPolicyTypes
+ List<String> supportedPolicyTypes = application.supportedPolicyTypes();
+
+ // Iterate through the supportedPolicyTypes to set the toscaPolicyTypeIdents
+ for (String name : supportedPolicyTypes) {
+ ToscaPolicyTypeIdentifier ident = new ToscaPolicyTypeIdentifier(name, "1.0.0");
+ toscaPolicyTypeIdents.add(ident);
+ }
}
//
// we have initialized
return providerActionMap.get(request.getAction());
}
+ public static List<ToscaPolicyTypeIdentifier> getToscaPolicyTypeIdents() {
+ return toscaPolicyTypeIdents;
+ }
+
/**
* Returns the current count of policy types supported. This could be misleading a bit
* as some applications can support wildcard of policy types. Eg. onap.Monitoring.* as
* @return Total count added from all applications
*/
public static long getPolicyTypeCount() {
- Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator();
long types = 0;
- while (iterator.hasNext()) {
- XacmlApplicationServiceProvider application = iterator.next();
+ for (XacmlApplicationServiceProvider application : applicationLoader) {
types += application.supportedPolicyTypes().size();
}
return types;