summaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2017-06-09 15:11:06 -0400
committerrb7147 <rb7147@att.com>2017-06-12 16:59:35 -0400
commit685ed1545ed28b777a3ba6e7d315b78f355154cb (patch)
tree1e37d639242c5f1e9cbf5623821f8498542b81dc /ECOMP-PAP-REST
parentfc5c07705edc4dcb7083b39116a43844bb6a1490 (diff)
[Policy-20] getConfig & Policy resolved blockers
Change-Id: If08e4c90d419e8d6e1426d817a12dde5b7cafba3 Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PAP-REST')
-rw-r--r--ECOMP-PAP-REST/pom.xml10
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java157
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java59
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java75
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java24
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java874
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java10
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java16
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java6
-rw-r--r--ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java5
-rw-r--r--ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java369
-rw-r--r--ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java207
12 files changed, 136 insertions, 1676 deletions
diff --git a/ECOMP-PAP-REST/pom.xml b/ECOMP-PAP-REST/pom.xml
index f05729ebb..71fefca9b 100644
--- a/ECOMP-PAP-REST/pom.xml
+++ b/ECOMP-PAP-REST/pom.xml
@@ -109,6 +109,16 @@
<groupId>org.openecomp.policy.common</groupId>
<artifactId>ECOMP-Logging</artifactId>
<version>${common-modules.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
index edbc2acb7..4ceae062b 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -403,6 +403,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
policyDBDao.setPapEngine((PAPPolicyEngine) XACMLPapServlet.papEngine);
+ //boolean performFileToDatabaseAudit = false;
+ if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))){
+ //get an AuditTransaction to lock out all other transactions
+ PolicyDBDaoTransaction auditTrans = policyDBDao.getNewAuditTransaction();
+ policyDBDao.auditLocalDatabase(XACMLPapServlet.papEngine);
+ //release the transaction lock
+ auditTrans.close();
+ }
+
// Sanity check for URL.
if (XACMLPapServlet.papURL == null) {
throw new PAPException("The property " + XACMLRestProperties.PROP_PAP_URL + " is not valid: " + XACMLPapServlet.papURL);
@@ -856,7 +865,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String message = "PUT interface called for PAP " + papResourceName + " but it has an Administrative"
+ " state of " + im.getStateManager().getAdminState()
+ "\n Exception Message: " + ae.getMessage();
- LOGGER.info(message);
+ LOGGER.info(message +ae);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -866,7 +875,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status"
+ " of " + im.getStateManager().getStandbyStatus()
+ "\n Exception Message: " + se.getMessage();
- LOGGER.info(message);
+ LOGGER.info(message +se);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -897,69 +906,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
im.endTransaction();
return;
}
- //This would occur if we received a notification of a policy creation or update
- String policyToCreateUpdate = request.getParameter("policyToCreateUpdate");
- if(policyToCreateUpdate != null){
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPapServlet.doPut() - before decoding"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- }
- //decode it
- try{
- policyToCreateUpdate = URLDecoder.decode(policyToCreateUpdate, "UTF-8");
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPapServlet.doPut() - after decoding"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- }
- } catch(UnsupportedEncodingException e){
- PolicyLogger.error("\nXACMLPapServlet.doPut() - Unsupported URL encoding of policyToCreateUpdate (UTF-8)"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- response.sendError(500,"policyToCreateUpdate encoding not supported"
- + "\nfailure with the following exception: " + e);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Failed - See error.log");
- im.endTransaction();
- return;
- }
- //send it to PolicyDBDao
- PolicyDBDaoTransaction createUpdateTransaction = policyDBDao.getNewTransaction();
- try{
- createUpdateTransaction.createPolicy(policyToCreateUpdate, "XACMLPapServlet.doPut");
- }catch(Exception e){
- createUpdateTransaction.rollbackTransaction();
- response.sendError(500,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) "
- + "\nfailure with the following exception: " + e);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Failed - See error.log");
- im.endTransaction();
- return;
- }
- createUpdateTransaction.commitTransaction();
- // Before sending Ok. Lets call AutoPush.
- if(autoPushFlag){
- Set<StdPDPGroup> changedGroups = autoPushPolicy.checkGroupsToPush(policyToCreateUpdate, XACMLPapServlet.papEngine);
- if(!changedGroups.isEmpty()){
- for(StdPDPGroup group: changedGroups){
- try{
- papEngine.updateGroup(group);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Group '" + group.getId() + "' updated");
- }
- notifyAC();
- // Group changed, which might include changing the policies
- groupChanged(group);
- }catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Failed to Push policy. ");
- }
- }
- }
- }
- response.setStatus(HttpServletResponse.SC_OK);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Ended Successfully");
- im.endTransaction();
- return;
- }
/*
* Request for ImportService
*/
@@ -1343,7 +1289,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.transactionEnded();
auditLogger.info("Success");
- if (policy != null && (policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param"))) {
+ if (policy != null && ((policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param")))) {
PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance();
if (pushPolicyHandler.preSafetyCheck(policy, CONFIG_HOME)) {
LOGGER.debug("Precheck Successful.");
@@ -1798,44 +1744,53 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
response.sendError(500, "Bad input, pdpid="+pdpId+" object="+objectFromJSON);
}
StdPDP pdp = (StdPDP) objectFromJSON;
- if (papEngine.getPDP(pdpId) == null) {
- // this is a request to create a new PDP object
- try{
- acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp == null ? "PDP is null" : pdp.getName(),
- pdp == null ? "PDP is null" : pdp.getDescription(),
- pdp == null ? 0 : pdp.getJmxPort(),"XACMLPapServlet.doACPut");
- } catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
- +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
- throw new PAPException(e.getMessage());
+ if(pdp != null){
+ if (papEngine.getPDP(pdpId) == null) {
+ // this is a request to create a new PDP object
+ try{
+ acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp.getName(),
+ pdp.getDescription(), pdp.getJmxPort(),"XACMLPapServlet.doACPut");
+ } catch(Exception e){
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
+ +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
+ throw new PAPException(e.getMessage());
+ }
+ papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+ } else {
+ try{
+ acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
+ } catch(Exception e){
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: "
+ +"pdp="+ pdp.getId());
+ throw new PAPException(e.getMessage());
+ }
+ // this is a request to update the pdp
+ papEngine.updatePDP(pdp);
}
- papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
- } else {
+ response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("PDP '" + pdpId + "' created/updated");
+ }
+ // adjust the group's state including the new PDP
+ ((StdPDPGroup)group).resetStatus();
+ // tell the Admin Consoles there is a change
+ notifyAC();
+ // this might affect the PDP, so notify it of the change
+ pdpChanged(pdp);
+ acPutTransaction.commitTransaction();
+ loggingContext.transactionEnded();
+ auditLogger.info("Success");
+ PolicyLogger.audit("Transaction Ended Successfully");
+ return;
+ }else{
try{
- acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "XACMLPapServlet", " Error while adding pdp to group in the database: "
+ +"pdp=null" + ",to group="+group.getId());
+ throw new PAPException("PDP is null");
} catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: "
- +"pdp="+(pdp == null ? "PDP is null" : pdp.getId()));
- throw new PAPException(e.getMessage());
+ throw new PAPException("PDP is null" + e.getMessage() +e);
}
- // this is a request to update the pdp
- papEngine.updatePDP(pdp);
}
- response.setStatus(HttpServletResponse.SC_NO_CONTENT);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("PDP '" + pdpId + "' created/updated");
- }
- // adjust the group's state including the new PDP
- ((StdPDPGroup)group).resetStatus();
- // tell the Admin Consoles there is a change
- notifyAC();
- // this might affect the PDP, so notify it of the change
- pdpChanged(pdp);
- acPutTransaction.commitTransaction();
- loggingContext.transactionEnded();
- auditLogger.info("Success");
- PolicyLogger.audit("Transaction Ended Successfully");
- return;
} else if (request.getParameter("pipId") != null) {
// group=<groupId> pipId=<pipEngineId> contents=pip properties <= add a PIP to pip config, or replace it if it already exists (lenient operation)
loggingContext.setServiceName("AC:PAP.putPIP");
@@ -2595,6 +2550,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return emf;
}
+ public IntegrityAudit getIa() {
+ return ia;
+ }
+
public static String getPDPFile(){
return XACMLPapServlet.pdpFile;
}
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java
index b658483d2..31871587b 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java
@@ -32,8 +32,6 @@ import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
-import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
-import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine;
import org.openecomp.policy.xacml.std.pap.StdPDPGroup;
import org.openecomp.policy.xacml.std.pap.StdPDPPolicy;
@@ -64,63 +62,6 @@ public class AutoPushPolicy {
readFile();
}
- /**
- * Checks Policy with all the Groups which has set such Property.
- * Else returns Empty Set.
- *
- * @param policyToCreateUpdate
- * @param papEngine
- */
- public Set<StdPDPGroup> checkGroupsToPush(String policyToCreateUpdate, PAPPolicyEngine papEngine) {
- Set<StdPDPGroup> changedGroups= new HashSet<>();
- // Check if the file has been modified. then re-load the properties file.
- newModified = propFile.lastModified();
- try {
- if(newModified!=oldModified){
- // File has been updated.
- readFile();
- }
- // Read the File name as its made.
- String gitPath = PolicyDBDao.getGitPath();
- String policyId = policyToCreateUpdate.substring(policyToCreateUpdate.indexOf(gitPath)+gitPath.length()+1);
- String policyName = policyId.substring(policyId.lastIndexOf(File.separator)+1,policyId.lastIndexOf("."));
- policyName = policyName.substring(0,policyName.lastIndexOf("."));
- policyId = policyId.replace("/", ".");
- if(policyId.contains("\\")){
- policyId = policyId.replace("\\", ".");
- }
- LOGGER.info("Policy ID : " + policyId);
- LOGGER.info("Policy Name : " + policyName);
- // Read in Groups
- for(EcompPDPGroup pdpGroup: papEngine.getEcompPDPGroups()){
- String groupName = pdpGroup.getName();
- Boolean typeFlag = false;
- Boolean scopeFlag = false;
- if(properties.containsKey(groupName + ".policyType")){
- String type= properties.getProperty(groupName + ".policyType").replaceAll(" ","");
- if(type.equals("")){
- type = " ";
- }
- typeFlag = policyName.contains(type);
- }
- if(properties.containsKey(groupName + ".policyScope")){
- String scope = properties.getProperty(groupName + ".policyScope").replaceAll(" ", "");
- if(scope.equals("")){
- scope = " ";
- }
- scopeFlag = policyId.contains(scope);
- }
- if(typeFlag || scopeFlag){
- StdPDPGroup group = addToGroup(policyId,policyName, policyToCreateUpdate, (StdPDPGroup)pdpGroup);
- changedGroups.add(group);
- }
- }
- } catch (Exception e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "AutoPushPolicy", "Error while processing the auto push for " + policyToCreateUpdate);
- }
- return changedGroups;
- }
-
private void readFile(){
try {
properties.load(new FileInputStream(propFile));
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
index 5fc4370e1..5938faa66 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
@@ -26,13 +26,9 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -42,11 +38,11 @@ import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
-import org.openecomp.policy.rest.XACMLRestProperties;
+import org.openecomp.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
+import org.openecomp.policy.rest.jpa.MicroServiceModels;
import com.att.research.xacml.std.IdentifierImpl;
-import com.att.research.xacml.util.XACMLProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter;
@@ -69,13 +65,6 @@ public class MicroServiceConfigPolicy extends Policy {
private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
- /*
- * These are the parameters needed for DB access from the PAP
- */
- private static String papDbDriver = null;
- private static String papDbUrl = null;
- private static String papDbUser = null;
- private static String papDbPassword = null;
private static Map<String, String> mapAttribute = new HashMap<>();
private static Map<String, String> matchMap = new HashMap<>();
@@ -188,7 +177,6 @@ public class MicroServiceConfigPolicy extends Policy {
matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
}
- matchMap = new HashMap<>();
if (matching != null && !matching.isEmpty()){
matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching);
if(policyAdapter.getJsonBody() != null){
@@ -332,62 +320,19 @@ public class MicroServiceConfigPolicy extends Policy {
}
private String getValueFromDictionary(String service){
-
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
-
+ String ruleTemplate=null;
String modelName = service.split("-v")[0];
String modelVersion = service.split("-v")[1];
-
- /*
- * Retrieve the property values for db access from the xacml.pap.properties
- */
- papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER);
- papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL);
- papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER);
- papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD);
-
- String ruleTemplate=null;
-
- try {
- //Get DB Connection
- Class.forName(papDbDriver);
- con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword);
- st = con.createStatement();
-
- String queryString = "Select * from MicroServiceModels where modelName=\"" + modelName
- + "\" AND version=\"" + modelVersion+"\"";
-
-
- rs = st.executeQuery(queryString);
- if(rs.next()){
- ruleTemplate=rs.getString("annotation");
- }
- rs.close();
- }catch (ClassNotFoundException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "MicroServiceModels", "Exception querying MicroServiceModels");
- } catch (SQLException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "MicroServiceModels", "Exception querying MicroServiceModels");
- } finally {
- try{
- if (con!=null){
- con.close();
- }
- if (rs!=null){
- rs.close();
- }
- if (st!=null){
- st.close();
- }
- } catch (Exception ex){
- LOGGER.error("Exception Occured While Closing the Database Connection"+ex);
- }
+ CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+ List<Object> result = dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName+":"+modelVersion);
+ if(result != null && !result.isEmpty()){
+ MicroServiceModels model = (MicroServiceModels) result.get(0);
+ ruleTemplate = model.getAnnotation();
}
return ruleTemplate;
-
}
+
// Data required for Advice part is setting here.
private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
AdviceExpressionsType advices = new AdviceExpressionsType();
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java
index 536f8e6b3..a0746439f 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java
@@ -215,12 +215,14 @@ public abstract class Policy {
new JSONObject(data);
InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
jsonReader = Json.createReader(stream);
- System.out.println("Json Value is: " + jsonReader.read().toString() );
+ LOGGER.info("Json Value is: " + jsonReader.read().toString() );
} catch (Exception e) {
LOGGER.error("Exception Occured while reading json"+e);
return false;
}finally{
- jsonReader.close();
+ if(jsonReader != null){
+ jsonReader.close();
+ }
}
return true;
}
@@ -302,8 +304,9 @@ public abstract class Policy {
//
//Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
//and this transaction is intercepted up stream.
- InputStream inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData);
+ InputStream inputStream = null;
try {
+ inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData);
PolicyDef policyDef = DOMPolicyDef.load(inputStream);
if (policyDef == null) {
success.put("validation", "PolicyDef Validation Failed");
@@ -311,10 +314,12 @@ public abstract class Policy {
success.put("success", "success");
}
} catch (Exception e) {
+ LOGGER.error("PolicyDef Validation failed"+e);
success.put("error", "Validation Failed");
}finally{
try {
- inputStream.close();
+ if(inputStream != null)
+ inputStream.close();
} catch (IOException e) {
LOGGER.error("Exception Occured while closing the input stream"+e);
}
@@ -379,16 +384,7 @@ public abstract class Policy {
configHome = webappsPathConfig.toString();
}
}
-
- protected String getParentPathSubScopeDir() {
- final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString());
- String policyDir = policyAdapter.getParentPath().toString();
- int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1;
- policyDir = policyDir.substring(startIndex, policyDir.length());
- return policyDir;
- }
-
-
+
public boolean validateConfigForm() {
return true;
}
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java
index b65557e05..8bf5ad6c9 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -22,10 +22,8 @@ package org.openecomp.policy.pap.xacml.rest.components;
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
@@ -40,10 +38,7 @@ import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Key;
-import java.sql.Timestamp;
-import java.util.ArrayList;
import java.util.Base64;
-import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -51,7 +46,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.UUID;
@@ -68,7 +62,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -85,14 +78,12 @@ import org.openecomp.policy.rest.jpa.GroupEntity;
import org.openecomp.policy.rest.jpa.PdpEntity;
import org.openecomp.policy.rest.jpa.PolicyDBDaoEntity;
import org.openecomp.policy.rest.jpa.PolicyEntity;
-import org.openecomp.policy.rest.jpa.PolicyVersion;
import org.openecomp.policy.rest.util.Webapps;
import org.openecomp.policy.xacml.api.pap.EcompPDP;
import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine;
import org.openecomp.policy.xacml.std.pap.StdPDPGroup;
import org.openecomp.policy.xacml.std.pap.StdPDPPolicy;
-import org.openecomp.policy.xacml.util.XACMLPolicyScanner;
import org.openecomp.policy.xacml.util.XACMLPolicyWriter;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
@@ -164,7 +155,7 @@ public class PolicyDBDao {
if(logger.isDebugEnabled()){
logger.debug("Number of remote PolicyDBDao instances: "+otherServers.size());
}
- if(otherServers.size() < 1){
+ if(otherServers.isEmpty()){
logger.warn("List of PolicyDBDao servers is empty or could not be retrieved");
}
}
@@ -446,7 +437,7 @@ public class PolicyDBDao {
logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers("+entityId+","+entityType+","+newGroupId+") called");
LinkedList<Thread> notifyThreads = new LinkedList<>();
- //we're going to run notiftions in parellel threads to speed things up
+ //we're going to run notifications in parallel threads to speed things up
for(Object obj : otherServers){
Thread newNotifyThread = new Thread(new NotifyOtherThread(obj, entityId, entityType, newGroupId));
@@ -461,7 +452,7 @@ public class PolicyDBDao {
try {
t.join();
} catch (Exception e) {
- logger.warn("Could not join a notifcation thread");
+ logger.warn("Could not join a notifcation thread" + e);
}
}
@@ -593,31 +584,6 @@ public class PolicyDBDao {
}
}
- private static String getElementFromXMLString(String element, String xml) {
- InputSource source = new InputSource(new StringReader(xml));
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- String description = "";
- try{
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(source);
-
- XPathFactory xpathFactory = XPathFactory.newInstance();
- XPath xpath = xpathFactory.newXPath();
-
- if (element.endsWith("/")){
- element = element.substring(0, element.length() -1);
- }
-
- description = xpath.evaluate("/Policy" + element + "/text()", document);
- }catch(Exception e){
-
- }
-
-
- System.out.println("description_" + description);
- return description;
- }
private static String evaluateXPath(String expression, String xml) {
InputSource source = new InputSource(new StringReader(xml));
@@ -633,11 +599,9 @@ public class PolicyDBDao {
description = xpath.evaluate(expression, document);
}catch(Exception e){
-
+ logger.error("Exception Occured while evaluating path"+e);
}
-
- System.out.println("description_" + description);
return description;
}
@@ -662,7 +626,7 @@ public class PolicyDBDao {
retries = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_INCOMINGNOTIFICATION_TRIES));
} catch(Exception e){
- logger.error("xacml.rest.pap.incomingnotification.tries property not set, using a default of 3.");
+ logger.error("xacml.rest.pap.incomingnotification.tries property not set, using a default of 3."+e);
retries = 3;
}
//if someone sets it to some dumb value, we need to make sure it will try at least once
@@ -871,7 +835,7 @@ public class PolicyDBDao {
policyStream.close();
} catch (IOException e) {
didUpdate = false;
- PolicyLogger.error(e.getMessage());
+ PolicyLogger.error(e.getMessage() +e);
}
}
}
@@ -1021,22 +985,14 @@ public class PolicyDBDao {
@SuppressWarnings("unchecked")
List<PolicyEntity> policies = getPolicyEntityQuery.getResultList();
PolicyEntity policy = null;
- if (policies.size() > 0){
+ if (!policies.isEmpty()){
policy = policies.get(0);
}
-
- String policyRepo = buildPolicyScopeDirectory(policy);
-
- Path policyPath = Paths.get(policyRepo);
String action = "unknown action";
try {
-
- if(policy != null && policy.isDeleted()){
+ if(policy != null){
logger.debug("Deleting Policy: " + policy.getPolicyName());
action = "delete";
- Path newPath = Paths.get(policyPath.toString(), policy.getPolicyName());
- Files.deleteIfExists(newPath);
-
Path subFile = null;
if (policy.getConfigurationData()!= null){
@@ -1048,257 +1004,18 @@ public class PolicyDBDao {
if(subFile != null){
Files.deleteIfExists(subFile);
}
-
- }else{
- logger.debug("Updating/Creating Policy: " + policy.getPolicyName());
- action = "update";
- Files.createDirectories(policyPath);
- Path newPath = Paths.get(policyPath.toString(), policy.getPolicyName());
- Files.deleteIfExists(newPath);
- if(!isNullOrEmpty(oldPathString)){
- try{
- String[] scopeName = getScopeAndNameAndType(oldPathString);
- Path oldPath = Paths.get(buildPolicyScopeDirectory(scopeName[0]),scopeName[1]);
- Files.delete(oldPath.toAbsolutePath());
- }catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy before rename: "+oldPathString);
- }
- }
- Object policyData = XACMLPolicyScanner.readPolicy(IOUtils.toInputStream(policy.getPolicyData()));
- XACMLPolicyWriter.writePolicyFile(newPath, (PolicyType) policyData);
-
if (policy.getConfigurationData()!= null){
- if(!isNullOrEmpty(oldPathString)){
- try{
- String[] oldPolicyScopeName = getScopeAndNameAndType(oldPathString);
- String oldConfigFileName = getConfigFile(oldPolicyScopeName[1],policy.getConfigurationData().getConfigType());
- Path oldConfigFilePath = getPolicySubFile(oldConfigFileName, "Config");
- logger.debug("Trying to delete: "+oldConfigFilePath.toString());
- Files.delete(oldConfigFilePath);
- }catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy config before rename for policy: "+oldPathString);
- }
- }
writePolicySubFile(policy, "Config");
-
}else if(policy.getActionBodyEntity()!= null){
- if(!isNullOrEmpty(oldPathString)){
- try{
- String[] oldPolicyScopeName = getScopeAndNameAndType(oldPathString);
- String oldActionFileName = getConfigFile(oldPolicyScopeName[1],ConfigPolicy.JSON_CONFIG);
- Path oldActionFilePath = getPolicySubFile(oldActionFileName, "Action");
- logger.debug("Trying to delete: "+oldActionFilePath.toString());
- Files.delete(oldActionFilePath);
- }catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy action body before rename for policy: "+oldPathString);
- }
- }
writePolicySubFile(policy, "Action");
}
-
}
} catch (IOException e1) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policy != null ? policy.getPolicyName() : "null");
+ String policyName = policy.getPolicyName();
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policyName);
}
}
- private void createGroupsFromDatabase(){
- //get list of groups
- boolean foundDefault = false;
- //need to avoid infinite loop, just in case
- boolean alreadyRunAdd = false;
- while(!foundDefault){
-
- EntityManager em = emf.createEntityManager();
- Query getGroups = em.createQuery("SELECT g FROM GroupEntity g WHERE g.deleted=:deleted");
- getGroups.setParameter("deleted", false);
- List<?> groups = getGroups.getResultList();
- em.close();
- //make a folder for each group in pdps folders
- Path pdpsPath = Paths.get(XACMLProperties.getProperty("xacml.pap.pdps"));
- if(!pdpsPath.toFile().exists()){
- try {
- FileUtils.forceMkdir(pdpsPath.toFile());
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not make the new pdps folder; one does not exist");
- }
- }
- Properties propertyFileProperties = new Properties();
- String groupList = "";
- String defaultGroup = "";
- HashSet<String> currentGroupPaths = new HashSet<>();
- for(Object o : groups){
- GroupEntity group = (GroupEntity)o;
- Path groupPath = Paths.get(pdpsPath.toString(), group.getGroupId());
- currentGroupPaths.add(groupPath.getFileName().toString());
- if(groupPath.toFile().exists()){
- try {
- FileUtils.forceDelete(Paths.get(groupPath.toString(), "xacml.policy.properties").toFile());
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete old xacml.policy.properties file");
- }
- File[] xmlFiles = groupPath.toFile().listFiles(new FileFilter(){
-
- @Override
- public boolean accept(File pathname) {
- return pathname.toString().endsWith(".xml");
- }
-
- });
- for(File deleteMe : xmlFiles){
- try {
- FileUtils.forceDelete(deleteMe);
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete one of the policy files that we are going to replace: "+deleteMe.toString());
- }
- }
- } else {
- try {
- FileUtils.forceMkdir(groupPath.toFile());
- } catch (IOException e) {
- logger.error("Exception Occured"+e);
- }
- }
- Properties policyProperties = new Properties();
- String rootPolicies = "";
- for(PolicyEntity policy : group.getPolicies()){
- Path newPolicyPath = Paths.get(groupPath.toString(),getPdpPolicyName(policy.getPolicyName(),policy.getScope()));
- File newPolicyFile = newPolicyPath.toFile();
- try {
- newPolicyFile.createNewFile();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
- try {
- FileOutputStream policyFileStream = new FileOutputStream(newPolicyFile);
- policyFileStream.write(policy.getPolicyData().getBytes("UTF-8"));
- policyFileStream.close();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
- policyProperties.setProperty(getPdpPolicyName(policy.getPolicyName(),policy.getScope())+".name",removeExtensionAndVersionFromPolicyName(policy.getPolicyName()));
- rootPolicies += ",".concat(getPdpPolicyName(policy.getPolicyName(),policy.getScope()));
- }
- Path xacmlPolicyPropertiesPath = Paths.get(groupPath.toString(),"xacml.policy.properties");
- File xacmlPolicyPropertiesFile = xacmlPolicyPropertiesPath.toFile();
- if(rootPolicies.length() > 0){
- rootPolicies = rootPolicies.substring(1);
- }
- policyProperties.setProperty("xacml.referencedPolicies", "");
- policyProperties.setProperty("xacml.rootPolicies", rootPolicies);
-
- try {
- xacmlPolicyPropertiesFile.createNewFile();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
- try {
- FileOutputStream xacmlPolicyPropertiesFileStream = new FileOutputStream(xacmlPolicyPropertiesFile);
- policyProperties.store(xacmlPolicyPropertiesFileStream, "");
- xacmlPolicyPropertiesFileStream.close();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
-
- em = emf.createEntityManager();
- Query getPdpsQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.groupEntity=:group AND p.deleted=:deleted");
- getPdpsQuery.setParameter("group", group);
- getPdpsQuery.setParameter("deleted", false);
- List<?> pdps = getPdpsQuery.getResultList();
- em.close();
- String pdpLine = "";
- for(Object o2 : pdps){
- PdpEntity pdp = (PdpEntity)o2;
- pdpLine += ",".concat(pdp.getPdpId());
- propertyFileProperties.setProperty(pdp.getPdpId()+".description",pdp.getDescription());
- propertyFileProperties.setProperty(pdp.getPdpId()+".jmxport",String.valueOf(pdp.getJmxPort()));
- propertyFileProperties.setProperty(pdp.getPdpId()+".name",pdp.getPdpName());
- }
- if(pdpLine.length() > 0){
- pdpLine = pdpLine.substring(1);
- }
- propertyFileProperties.setProperty(group.getGroupId()+".description", group.getDescription());
- propertyFileProperties.setProperty(group.getGroupId()+".name", group.getgroupName());
- propertyFileProperties.setProperty(group.getGroupId()+".pdps",pdpLine);
- groupList += ",".concat(group.getGroupId());
- if(group.isDefaultGroup()){
- defaultGroup = group.getGroupId();
- foundDefault = true;
- }
- }
- //check the list of directories in the pdps folder and make sure none should be deleted
- File[] filesInPdpsFolder = pdpsPath.toFile().listFiles(new FileFilter(){
- @Override
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
- for(File f : filesInPdpsFolder){
- if(f.isDirectory()){
- if(!currentGroupPaths.contains(f.toPath().getFileName().toString())){
- try {
- FileUtils.forceDelete(f);
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete pdp group folder, which has been deleted from the database");
- }
- }
- }
- }
- if(!foundDefault && !alreadyRunAdd){
- alreadyRunAdd = true;
- //add default group to db
- try{
- em = emf.createEntityManager();
- em.getTransaction().begin();
- GroupEntity newDefaultGroup = new GroupEntity();
- em.persist(newDefaultGroup);
- newDefaultGroup.setDescription("The default group where new PDP's are put.");
- newDefaultGroup.setGroupId("default");
- newDefaultGroup.setGroupName("default");
- newDefaultGroup.setDefaultGroup(true);
- newDefaultGroup.setCreatedBy("automaticallyAdded");
- newDefaultGroup.setModifiedBy("automaticallyAdded");
- em.flush();
- em.getTransaction().commit();
- continue;
- } catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not add a new default group to the database");
- }
- }
-
- Path xacmlPropertiesPath = Paths.get(pdpsPath.toString(),"xacml.properties");
- File xacmlPropertiesFile = xacmlPropertiesPath.toFile();
- if(groupList.length()>0){
- groupList = groupList.substring(1);
- }
- propertyFileProperties.setProperty("xacml.pap.groups",groupList);
- propertyFileProperties.setProperty("xacml.pap.groups.default",defaultGroup);
- try {
- FileUtils.forceDelete(xacmlPropertiesFile);
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old xacml.properties file");
- }
- try {
- xacmlPropertiesFile.createNewFile();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
- try {
- FileOutputStream xacmlPropertiesFileStream = new FileOutputStream(xacmlPropertiesFile);
- propertyFileProperties.store(xacmlPropertiesFileStream, "");
- xacmlPropertiesFileStream.close();
- } catch (IOException e) {
- PolicyLogger.error(e.getMessage());
- }
- //if we get this far down, something went wrong and we don't want to get stuck in the loop
- foundDefault = true;
- }
- //put policies in group folder
- //create xacml.policy.properties in each folder with list of policies in that folder
- //get list of pdps
- //create xacml.properties with list of groups and pdps and other info
- }
-
private String getPdpPolicyName(String name, String scope){
String finalName = "";
finalName += scope;
@@ -1311,63 +1028,6 @@ public class PolicyDBDao {
return fileName.substring(0, fileName.lastIndexOf('.'));
}
- private String buildPolicyScopeDirectory(PolicyEntity policy){
- String repo = buildPolicyDirectory();
-
- String policyScope = policy.getScope();
-
- if(policyScope == null){
- policyScope = "";
- PolicyLogger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank.");
- } else {
- policyScope = policyScope.replace(".", File.separator);
- }
- if(policyScope == null){
- policyScope = "";
- PolicyLogger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank.");
- }
- if(repo == null){
- PolicyLogger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank.");
- repo = "";
- }
- Path returnPath = Paths.get(repo + File.separator + policyScope);
- if(returnPath != null){
- return returnPath.toString();
- } else {
- PolicyLogger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank.");
- return "";
- }
-
-
- }
- private String buildPolicyScopeDirectory(String policyScope){
- String repo = buildPolicyDirectory();
- return repo + File.separator + policyScope.replace(".", File.separator);
- }
-
- private static String buildPolicyDirectory(){
- Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), getDefaultWorkspace());
- Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY));
- Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString());
-
- /*
- * Getting and Setting the parent path for Admin Console use when reading the policy files
- */
- //getting the fullpath of the gitPath and convert to string
- String policyDir = gitPath.toAbsolutePath().toString();
-
-
- if(policyDir.contains("\\")){
- policyDir = policyDir.replace("XACML-PAP-REST", "XACML-PAP-ADMIN");
- }else{
- if (policyDir.contains("pap")){
- policyDir = policyDir.replace("pap", "console");
- }
- }
- logger.debug("policyDir: " + policyDir);
- return policyDir;
- }
-
private Path getPolicySubFile(String filename, String subFileType){
logger.debug("getPolicySubFile(" + filename + ", " + subFileType + ")");
Path filePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), subFileType);
@@ -1448,256 +1108,15 @@ public class PolicyDBDao {
}
- private String getPolicySubType(String filename){
- String type = null;
-
- if (filename != null) {
- if (FilenameUtils.getExtension(filename).equalsIgnoreCase("json")) {
- type = ConfigPolicy.JSON_CONFIG;
- }
- if (FilenameUtils.getExtension(filename).equalsIgnoreCase("xml")) {
- type = ConfigPolicy.XML_CONFIG;
- }
- if (FilenameUtils.getExtension(filename).equalsIgnoreCase("properties")) {
- type = ConfigPolicy.PROPERTIES_CONFIG;
- }
- if (FilenameUtils.getExtension(filename).equalsIgnoreCase("txt")) {
- type = ConfigPolicy.OTHER_CONFIG;
- }
- }
-
- return type;
-
- }
-
-
- private void convertFileToDBEntry(Path path){
- logger.info("convertFileToDBEntry");
-
- if(path.toString().contains(".git")){
- return;
- }
-
- String filename = path.getFileName().toString();
- if (filename.contains(".svnignore")){
- return;
- }
-
- String[] scopeAndName = getScopeAndNameAndType(path.toString());
-
- if(scopeAndName == null){
- PolicyLogger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + path.toString() + " is null!");
- return;
- }
-
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
-
- PolicyEntity policy = new PolicyEntity();
- em.persist(policy);
- String policyScope = scopeAndName[0];
- String policyName = scopeAndName[1];
- policy.setScope(policyScope);
- policy.setPolicyName(policyName);
- policy.setCreatedBy(AUDIT_USER);
- policy.setModifiedBy(AUDIT_USER);
-
- String newScope = policyScope.replace(".", File.separator);
- String newName = FilenameUtils.removeExtension(policyName);
- int version = 1;
- try{
- //we want the last index +1 because we don't want the dot
- version = Integer.parseInt(newName.substring(newName.lastIndexOf(".")+1));
- } catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not get the policy version number from "+newName);
- }
- newName = newScope + File.separator + newName.substring(0, newName.lastIndexOf("."));
-
- Query query = em.createNamedQuery("PolicyVersion.findByPolicyName");
- query.setParameter("pname", newName);
-
- List<?> result = query.getResultList();
- PolicyVersion versionEntity = null;
-
- if (!result.isEmpty()) {
- logger.info("Result is not empty");
- versionEntity = (PolicyVersion) result.get(0);
- int highestVersion = Math.max(versionEntity.getHigherVersion(),version);
- versionEntity.setHigherVersion(highestVersion);
- versionEntity.setActiveVersion(highestVersion);
- }else{
- logger.info("result is empty");
- Calendar calendar = Calendar.getInstance();
- Timestamp createdDate = new Timestamp(calendar.getTime().getTime());
-
- versionEntity = new PolicyVersion();
- em.persist(versionEntity);
- versionEntity.setPolicyName(newName);
- versionEntity.setHigherVersion(version);
- versionEntity.setActiveVersion(version);
- versionEntity.setCreatedBy(AUDIT_USER);
- versionEntity.setModifiedBy(AUDIT_USER);
- versionEntity.setCreatedDate(createdDate);
- versionEntity.setModifiedDate(createdDate);
- }
-
-
- try {
- String policyContent = new String(Files.readAllBytes(path));
- policy.setDescription(getElementFromXMLString("/Description", policyContent));
- policy.setPolicyData(policyContent);
- } catch (IOException e1) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "convertFileToDBEntry error settingPolicyData");
- em.getTransaction().rollback();
- em.close();
- return;
- }
-
- if((scopeAndName[2].equalsIgnoreCase("Config"))){
- String scopeName = scopeAndName[0] + "." + scopeAndName[1];
- Path subFilePath = getPolicySubFile(scopeName, scopeAndName[2]);
- try {
- String content = new String(Files.readAllBytes(subFilePath));
- String configName = subFilePath.getFileName().toString();
- ConfigurationDataEntity configData = new ConfigurationDataEntity();
- em.persist(configData);
- configData.setConfigurationName(subFilePath.getFileName().toString());
- configData.setConfigBody(content);
- configData.setConfigType(getPolicySubType(configName));
- configData.setCreatedBy(AUDIT_USER);
- configData.setModifiedBy(AUDIT_USER);
- policy.setConfigurationData(configData);
-
- } catch (Exception e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "convertFileToDBEntry error for Config policy");
- em.getTransaction().rollback();
- em.close();
- return;
- }
- }else if(scopeAndName[2].equalsIgnoreCase("Action")){
- String scopeName = scopeAndName[0] + "." + scopeAndName[1];
- Path subFilePath = getPolicySubFile(scopeName, scopeAndName[2]);
- try {
- String content = new String(Files.readAllBytes(subFilePath));
- ActionBodyEntity actionBody = new ActionBodyEntity();
- em.persist(actionBody);
- actionBody.setActionBodyName(subFilePath.getFileName().toString());
- actionBody.setActionBody(content);
- actionBody.setCreatedBy(AUDIT_USER);
- actionBody.setModifiedBy(AUDIT_USER);
- policy.setActionBodyEntity(actionBody);
-
- } catch (Exception e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "convertFileToDBEntry error for Action policy");
- em.getTransaction().rollback();
- em.close();
- return;
- }
- }
- logger.debug("convertFileToDBEntry commit transaction");
- em.getTransaction().commit();
- em.close();
- }
-
- private void deleteAllPolicyTables(){
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- Query deletePolicyEntityTableUpdate = em.createNamedQuery("PolicyEntity.deleteAll");
- Query deleteActionBodyEntityTableUpdate = em.createNamedQuery("ActionBodyEntity.deleteAll");
- Query deleteConfigurationDataEntityTableUpdate = em.createNamedQuery("ConfigurationDataEntity.deleteAll");
- Query deletePolicyVersionEntityTableUpdate = em.createNamedQuery("PolicyVersion.deleteAll");
- deletePolicyEntityTableUpdate.executeUpdate();
- deleteActionBodyEntityTableUpdate.executeUpdate();
- deleteConfigurationDataEntityTableUpdate.executeUpdate();
- deletePolicyVersionEntityTableUpdate.executeUpdate();
- em.getTransaction().commit();
- em.close();
-
- }
-
public void auditLocalDatabase(PAPPolicyEngine papEngine2){
logger.debug("PolicyDBDao.auditLocalDatabase() is called");
- Path webappsPath = Paths.get(buildPolicyDirectory());
try{
deleteAllGroupTables();
- deleteAllPolicyTables();
- Files.createDirectories(webappsPath);
- Files.walk(webappsPath).filter(Files::isRegularFile).forEach(this::convertFileToDBEntry);
auditGroups(papEngine2);
} catch(Exception e){
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "auditLocalDatabase() error");
logger.error("Exception Occured"+e);
- }finally{
- try {
- Files.walk(webappsPath).close();
- } catch (IOException e) {
- logger.error("Exception Occured while closing File Stream"+e);
- }
- }
- }
-
- /**
- * Audits and loads the local file system to match the database version.
- */
- @SuppressWarnings("unchecked")
- public void auditLocalFileSystem(){
- logger.debug("PolicyDBDau.auditLocalFileSystem() is called");
-
- Path webappsPath = Paths.get(buildPolicyDirectory());
- Path configFilesPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), "Config");
- Path actionFilesPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), "Action");
- try {
- Files.createDirectories(configFilesPath);
- Files.createDirectories(actionFilesPath);
- FileUtils.cleanDirectory(actionFilesPath.toFile());
- FileUtils.cleanDirectory(configFilesPath.toFile());
- if (webappsPath.toFile().exists()){
- FileUtils.cleanDirectory(webappsPath.toFile());
- }
- Path repoWithScope = Paths.get(webappsPath.toString(), XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DOMAIN));
- Files.createDirectories(repoWithScope);
- } catch (IOException e2) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Error occurred while creating / clearing Config and Policy filesystem directories");
- }
-
- List<PolicyEntity> policyEntityList;
- try{
- EntityManager em = emf.createEntityManager();
- Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findAllByDeletedFlag");
- getPolicyEntitiesQuery.setParameter("deleted", false);
- policyEntityList = getPolicyEntitiesQuery.getResultList();
- } catch(Exception e){
- policyEntityList = new LinkedList<>();
}
-
- for (PolicyEntity policy: policyEntityList){
- String name = "";
- try {
- if (!policy.isDeleted()){
- name = policy.getPolicyName();
- String scope = policy.getScope();
-
- scope = scope.replace(".", "//");
- if (policy.getConfigurationData()!=null){
- writePolicySubFile(policy, "Config");
- }
- else if(policy.getActionBodyEntity()!=null){
- writePolicySubFile(policy, "Action");
- }
-
-
- Path fileLocation = Paths.get(webappsPath.toString(), scope);
-
- Files.createDirectories(fileLocation);
- Path newPath = Paths.get(fileLocation.toString(), name);
- Object policyData = XACMLPolicyScanner.readPolicy(IOUtils.toInputStream(policy.getPolicyData()));
- XACMLPolicyWriter.writePolicyFile(newPath, (PolicyType) policyData);
- }
- } catch (Exception e1) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while creating Policy File: " + name);
- }
- }
- createGroupsFromDatabase();
}
public void deleteAllGroupTables(){
@@ -1762,9 +1181,7 @@ public class PolicyDBDao {
policyEntityList = getPolicyEntitiesQuery.getResultList();
PolicyEntity policyEntity = null;
- if(policyEntityList.size() < 1){
- policyEntity = addPolicyThatOnlyExistsInPdpGroup(policy.getId(),Paths.get(XACMLProperties.getProperty("xacml.pap.pdps"),grp.getId(),policy.getId()),em);
- } else {
+ if(!policyEntityList.isEmpty()){
policyEntity = policyEntityList.get(0);
}
if(policyEntity != null){
@@ -1790,41 +1207,6 @@ public class PolicyDBDao {
}
- private PolicyEntity addPolicyThatOnlyExistsInPdpGroup(String polId, Path path,EntityManager em){
- String filename = path.getFileName().toString();
- if (filename.contains(".svnignore")){
- return null;
- }
-
- String[] scopeAndName = getNameScopeAndVersionFromPdpPolicy(polId);
-
- if(scopeAndName == null){
- PolicyLogger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + polId.toString() + " is null!");
- return null;
- }
-
- PolicyEntity policy = new PolicyEntity();
- em.persist(policy);
- String policyScope = scopeAndName[1];
- String policyName = scopeAndName[0];
- policy.setScope(policyScope);
- policy.setPolicyName(policyName);
- policy.setCreatedBy(AUDIT_USER);
- policy.setModifiedBy(AUDIT_USER);
- policy.setDeleted(true);
-
- try {
- String policyContent = new String(Files.readAllBytes(path));
- policy.setDescription(getElementFromXMLString("/Description", policyContent));
- policy.setPolicyData(policyContent);
- em.flush();
- } catch (IOException e1) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "convertFileToDBEntry error settingPolicyData");
- return null;
- }
- return policy;
- }
-
private String getConfigFile(String filename, PolicyRestAdapter policy){
if(policy == null){
return getConfigFile(filename, (String)null);
@@ -1855,37 +1237,6 @@ public class PolicyDBDao {
}
return filename;
}
-
- /**
- * Constructs the file name of a policy.
- * @param policy The name of a policy (ex: mypolicy1)
- * @return The file name of the policy (ex: Config_mypolicy1.xml)
- * @deprecated
- */
- @SuppressWarnings("unused")
- private String getName(PolicyRestAdapter policy){
- logger.debug("getName(PolicyRestAdapter policy) as getName("+policy+") called");
- String namePrefix = "";
- if(policy.getPolicyType().contains("Config")){
- namePrefix = namePrefix.concat(policy.getPolicyType());
- if(policy.getConfigType().contains("Firewall")){
- namePrefix = namePrefix.concat("_FW");
- }
- }
- String concats = namePrefix + "_" +policy.getPolicyName() + ".xml";
- return concats;
- }
-
- private String stripPolicyName(String policyFileName){
- String policyName = policyFileName;
- try{
- policyName = policyName.substring(policyName.indexOf('_')+1);
- policyName = removeFileExtension(policyName);
- }catch(Exception e){
- throw new IllegalArgumentException("Could not get name out of policy file name: "+policyName);
- }
- return policyName;
- }
private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){
String[] splitByDots = fileName.split("\\.");
@@ -1911,19 +1262,6 @@ public class PolicyDBDao {
return returnArray;
}
- /**
- * Constructs the complete repository path based on the properties files
- * @return The repository path
- */
- public static String getGitPath(){
- logger.debug("getGitPath() as getGitPath() called");
- Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin");
- Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY));
- Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString());
- logger.debug("after gitPath: " + gitPath);
- return gitPath.toString();
- }
-
//copied from StdEngine.java
public static String createNewPDPGroupId(String name) {
String id = name;
@@ -1963,95 +1301,7 @@ public class PolicyDBDao {
return false;
}
- /**
- * Computes the scope, name, and type of a policy based on its file path
- * @param path The file path of the policy (including the xml policy file)
- * @return A string array of size 3. 1: the scope of the policy 2: the name of the policy (Config_mypol.xml) 3: the type (Config). Or, null if the path can not be parsed.
- */
- private static String[] getScopeAndNameAndType(String path){
- logger.debug("getScopeAndNameAndType(String path) as getScopeAndNameAndType("+path+") called");
- if(path == null){
-
- }
- String gitPath = getGitPath();
-
- ArrayList<String> gitPathParts = new ArrayList<>();
- Iterator<?> gitPathIterator = Paths.get(gitPath).iterator();
- while(gitPathIterator.hasNext()){
- gitPathParts.add(gitPathIterator.next().toString());
- }
- for(int i=0;i<gitPathParts.size();i++){
- Path testGitPath = Paths.get("");
- for(int j=i;j<gitPathParts.size();j++){
- testGitPath = Paths.get(testGitPath.toString(),gitPathParts.get(j));
- }
- if(path != null && path.contains(testGitPath.toString())){
- gitPath = testGitPath.toString();
- break;
- }
- }
- if(gitPath == null){
- logger.debug("gitPath is null. Returning");
- return null;
- }
- if(path != null && (gitPath.length() >= path.length())){
- logger.debug("gitPath length(): " + gitPath.length() + ">= path.length(): " + path.length() + ". Returning null");
- return null;
- }
- String scopeAndName = path.substring(path.indexOf(gitPath)+gitPath.length());
-
- logger.debug("scopeAndName: " + scopeAndName);
- String policyType = null;
- String[] policyTypes = {"Config_","Action_","Decision_"};
- for(String pType : policyTypes){
- if(scopeAndName.contains(pType)){
- policyType = pType;
- }
- }
- if(policyType == null){
- return null;
- }
- String scope = scopeAndName.substring(0,scopeAndName.indexOf(policyType));
- String name = scopeAndName.substring(scopeAndName.indexOf(policyType), scopeAndName.length());
- scope = scope.replace('\\', '.');
- scope = scope.replace('/', '.');
- if(scope.length()<1){
- return null;
- }
- if(scope.charAt(0) == '.'){
- if(scope.length() < 2){
- logger.debug("getScopeAndNameAndType error: " + scope.length() + " < 2. " + "| scope.charAt(0)==.");
- return null;
- }
- scope = scope.substring(1);
- }
- if(scope.charAt(scope.length()-1) == '.'){
- if(scope.length() < 2){
- logger.debug("getScopeAndNameAndType error: " + scope.length() + " < 2" + "| scope.charAt(scope.length()-1)==.");
- return null;
- }
- scope = scope.substring(0,scope.length()-1);
- }
- if(name.length()<1){
- logger.debug("getScopeAndNameAndType error: name.length()<1");
- return null;
- }
- if(name.charAt(0) == '.'){
- if(name.length() < 2){
- logger.debug("getScopeAndNameAndType error: " + name.length() + " < 2. " + "| scope.charAt(0)==.");
- return null;
- }
- name = name.substring(1);
- }
- String[] returnArray = new String[3];
- returnArray[0] = scope;
- returnArray[1] = name;
- //remove the underscore and return it
- returnArray[2] = policyType.substring(0, policyType.length()-1);
- return returnArray;
- }
-
-
+
private class PolicyDBDaoTransactionInstance implements PolicyDBDaoTransaction {
private EntityManager em;
private final Object emLock = new Object();
@@ -2504,7 +1754,7 @@ public class PolicyDBDao {
@Override
public void renamePolicy(String oldPath, String newPath,String username){
- String[] oldPolicy = getScopeAndNameAndType(oldPath);
+/* String[] oldPolicy = getScopeAndNameAndType(oldPath);
String[] newPolicy = getScopeAndNameAndType(newPath);
if(oldPolicy == null || newPolicy == null){
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: "
@@ -2614,7 +1864,7 @@ public class PolicyDBDao {
em.flush();
this.policyId = policyToRename.getPolicyId();
this.newGroupId = oldPath;
- }
+ }*/
}
@Override
@@ -2717,7 +1967,7 @@ public class PolicyDBDao {
}
public void deletePolicy(String policyToDeletes){
- synchronized(emLock){
+ /*synchronized(emLock){
checkBeforeOperationRun();
logger.debug("deletePolicy(String policyToDeletes) as deletePolicy("+policyToDeletes+") called");
String[] scopeNameAndType = getScopeAndNameAndType(policyToDeletes);
@@ -2758,7 +2008,7 @@ public class PolicyDBDao {
}
}
-
+*/
}
@@ -2773,7 +2023,7 @@ public class PolicyDBDao {
@Override
public void clonePolicy(String oldPolicyPath, String newPolicyPath, String username){
- String[] oldPolicyData = getScopeAndNameAndType(oldPolicyPath);
+ /*String[] oldPolicyData = getScopeAndNameAndType(oldPolicyPath);
String[] newPolicyData = getScopeAndNameAndType(newPolicyPath);
if(oldPolicyData == null || newPolicyData == null){
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: "
@@ -2811,83 +2061,9 @@ public class PolicyDBDao {
em.flush();
}
-
+*/
}
- @Override
- public void createPolicy(String filePath, String username) {
- logger.debug("createPolicy(String filePath, String username) as createPolicy("+filePath+","+username+") called");
- //get just the scope and file name
- //its actually scope, name, and type now
- String[] scopeAndName = getScopeAndNameAndType(filePath);
- if(scopeAndName == null){
- throw new IllegalArgumentException("The file path could not be parsed");
- }
- PolicyRestAdapter policy = new PolicyRestAdapter();
-
- policy.setPolicyType(scopeAndName[2]);
- policy.setPolicyDescription("");
-
- String policyName = scopeAndName[1];
- try{
- policyName = stripPolicyName(policyName);
- }catch(IllegalArgumentException e){
- if(scopeAndName[2].equals("Config")){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception calling stripPolicyName with policy name: "+policyName);
- throw new IllegalArgumentException(e.getMessage(),e);
- } else {
- logger.warn(e.getMessage());
- }
- }
- policy.setPolicyName(policyName);
- String policyDataString = null;
- InputStream fileContentStream = null;
- try {
- fileContentStream = new FileInputStream(filePath);
- policyDataString = IOUtils.toString(fileContentStream);
- } catch (FileNotFoundException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught FileNotFoundException on new FileInputStream("+filePath+")");
- throw new IllegalArgumentException("The file path does not exist");
- } catch(IOException e2){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Caught IOException on newIOUtils.toString("+fileContentStream+")");
- throw new IllegalArgumentException("The file path cannot be read");
- } finally {
- IOUtils.closeQuietly(fileContentStream);
- }
- if(policyDataString == null){
- throw new IllegalArgumentException("The file path cannot be read");
- }
- try{
- String policyDescription = getElementFromXMLString("/Description", policyDataString);
- if(policyDescription != null){
- policy.setPolicyDescription(policyDescription);
- }
- } catch(Exception e){
- logger.warn("Could not get description from the policy file");
- }
- if(scopeAndName[2].equals("Config")){
- //this method is not used for config, since there is no way to get config info (could be modified to)
- String configPath;
- try{
- configPath = evaluateXPath("/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()", policyDataString);
- if(configPath == null){
- throw new NullPointerException("configPath is null");
- }
- } catch(Exception e){
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not get config file path from policy file");
- throw new IllegalArgumentException("Could not get config file path from policy file");
- }
- configPath = processConfigPath(configPath);
- logger.debug("The location of our config file is: "+configPath);
- policy.setConfigType(getPolicySubType(configPath));
- logger.debug("Config type is: "+policy.getConfigType());
-
- String configDataString = readConfigFile(configPath);
- policy.setConfigBodyData(configDataString);
- }
- createPolicy(policy,username,scopeAndName[0],scopeAndName[1],policyDataString);
- }
-
private String processConfigPath(String configPath){
String webappsPath = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS);
if(webappsPath == null){
@@ -3585,12 +2761,6 @@ public class PolicyDBDao {
}
}
-
-
- private static String getDefaultWorkspace(){
- return "admin";
- }
-
private PolicyDBDao(){
}
@@ -3600,14 +2770,8 @@ public class PolicyDBDao {
}
final class PolicyDBDaoTestClass {
- String[] getScopeAndNameAndType(final String path){
- return PolicyDBDao.getScopeAndNameAndType(path);
- }
- String getGitPath(){
- return PolicyDBDao.getGitPath();
- }
String getConfigFile(String filename, String scope, PolicyRestAdapter policy){
- return PolicyDBDao.this.getConfigFile(filename, policy);
+ return scope + "." + PolicyDBDao.this.getConfigFile(filename, policy);
}
String computeScope(String fullPath, String pathToExclude){
return PolicyDBDao.computeScope(fullPath, pathToExclude);
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java
index 5ab036db8..7b8801cd8 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java
@@ -51,16 +51,6 @@ public interface PolicyDBDaoTransaction {
public void createPolicy(Policy policy, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
/**
- * Create or update a policy
- * @param filePath The file path of the policy xml file
- * @param username A string of the username you want to be stored for doing this operation
- * @throws IllegalStateException If a transaction is open that has not yet been committed
- * @throws PersistenceException If a database error occurs
- * @throws IllegalArgumentException If the file path is incorrect, or if it refers to a Config policy
- */
- public void createPolicy(String filePath, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
-
- /**
* Check if the PolicyDBDaoTransaction is currently open
* @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
*/
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
index 108d33c25..ecf84620e 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
@@ -1013,14 +1013,14 @@ public class MicroServiceDictionaryController {
if (mainClass != null && mainClass.getDependency()==null){
mainClass.setDependency("");
}
-
- this.newModel.setDependency(mainClass.getDependency());
- this.newModel.setSub_attributes(subAttribute.toString());
- this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
- this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
- this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
- this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-
+ if(mainClass != null){
+ this.newModel.setDependency(mainClass.getDependency());
+ this.newModel.setSub_attributes(subAttribute);
+ this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
+ this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
+ this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+ this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+ }
}
private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java
index 88548ffa4..dd8cc656a 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java
@@ -408,7 +408,11 @@ public class DeleteHandler {
PolicyLogger.error("Exception occured While Deleting Policy From PDP Group"+e1);
}
if (group == null || ! (group instanceof StdPDPGroup) || existingGroup == null || ! (group.getId().equals(existingGroup.getId()))) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingGroup != null ? existingGroup.getId() : "null" + " objectFromJSON="+group);
+ String existingID = null;
+ if(existingGroup != null){
+ existingID = existingGroup.getId();
+ }
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingID + " objectFromJSON="+group);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
response = "No Group";
diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java
index d3b5cbbea..3e1ef0469 100644
--- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java
+++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java
@@ -38,7 +38,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.openecomp.policy.common.ia.DbAudit;
import org.openecomp.policy.common.ia.DbDAO;
@@ -49,7 +48,6 @@ import org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity;
import org.openecomp.policy.common.im.jpa.StateManagementEntity;
import org.openecomp.policy.jpa.BackUpMonitorEntity;
-@Ignore
public class DbAuditCompareEntriesTest {
private static Log logger = LogFactory.getLog(DbAuditCompareEntriesTest.class);
@@ -123,7 +121,6 @@ public class DbAuditCompareEntriesTest {
* Tests that a comparison between hashsets is successful if
* the entries match
*/
- //@Ignore
@Test
public void runAllTests() throws Exception {
logger.info("runAllTests: Entering");
@@ -152,7 +149,7 @@ public class DbAuditCompareEntriesTest {
//There is only one entry IntegrityAuditEntity, but we will check anyway
HashSet<String> classNameSet = dbDAO.getPersistenceClassNames();
for(String c : classNameSet){
- if (c.equals("org.openecomp.policy.common.ia.IntegrityAuditEntity")){
+ if (c.equals("org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity")){
className = c;
}
}
diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java
deleted file mode 100644
index b87d99059..000000000
--- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ECOMP-PAP-REST
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.policy.pap.xacml.rest;
-
-/*import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet;
-import org.openecomp.policy.rest.XACMLRestProperties;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.springframework.mock.web.MockServletConfig;
-
-import org.openecomp.policy.common.ia.IntegrityAudit;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-import org.openecomp.policy.common.logging.flexlogger.Logger;
-
-public class XACMLPapServletTest extends TestCase{
- private static Logger logger = FlexLogger.getLogger(XACMLPapServletTest.class);
-
- private List<String> headers = new ArrayList<String>();
-
- private HttpServletRequest httpServletRequest;
- private HttpServletResponse httpServletResponse;
- private ServletOutputStream mockOutput;
- private ServletConfig servletConfig;
- private XACMLPapServlet papServlet;
-
-
- @Before
-
- public void setUp() throws IOException {
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(null);
- Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
- Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
-
-
- mockOutput = Mockito.mock(ServletOutputStream.class);
-
- //when(httpServletRequest.getPathInfo()).thenReturn("/lineup/world.xml");
- //HttpServletResponse httpResponse = new HttpServletResponse();
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
-
- Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
-
-
- //when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream);
- servletConfig = Mockito.mock(MockServletConfig.class);
- //Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
- //servletConfig
- Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
- papServlet = new XACMLPapServlet();
-
- Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pap.test.properties");
-
- System.setProperty("xacml.PAP.papEngineFactory", "com.att.research.xacml.std.pap.StdEngineFactory");
- System.setProperty("xacml.pap.pdps", "pdps");
- System.setProperty("xacml.rest.pap.url", "http://localhost:8070/pap/");
- System.setProperty("xacml.rest.pap.initiate.pdp", "false");
- System.setProperty("xacml.rest.pdp.idfile", "testpdp.properties");
- System.setProperty("xacml.rest.pep.idfile", "client.properties");
- System.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
- System.setProperty("javax.persistence.jdbc.url", "jdbc:h2:file:./sql/xacmlTest");
- System.setProperty("javax.persistence.jdbc.user", "sa");
- System.setProperty("javax.persistence.jdbc.password", "");
- System.setProperty("xacml.rest.pap.jmx.url", "service:jmx:rmi:///jndi/rmi://localhost:9990/jmxrmi");
- System.setProperty("xacml.rest.pap.resource.name", "site_1.pap_1");
- System.setProperty("fp_monitor_interval", "30");
- System.setProperty("failed_counter_threshold", "3");
- System.setProperty("test_trans_interval", "10");
- System.setProperty("write_fpc_interval", "5");
- System.setProperty("com.sun.management.jmxremote.port", "9999");
- System.setProperty("dependency_groups", "site_1.logparser_1;site_1.adminconsole_1;site_1.elk_1");
- System.setProperty("site_name", "site_1");
- System.setProperty("node_type", "pap");
- }
-
-
- * This method initializes and cleans the DB so the XACMLPapServlet will be able to instantiate an
- * IntegrityAudit object which will use the DB.
-
- public void initializeDb(){
- logger.debug("initializeDb: enter");
- Properties cleanProperties = new Properties();
- cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver");
- cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest");
- cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa");
- cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, "");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", cleanProperties);
-
- EntityManager em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
- et.begin();
-
- // Clean up the DB
- em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
-
- // commit transaction
- et.commit();
- em.close();
- logger.debug("initializeDb: exit");
- }
-
- @Test
- public void testInit() throws Exception{
- System.setProperty("integrity_audit_period_seconds", "0");
- initializeDb();
- try {
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- if(ia.isThreadInitialized()){
- assertTrue(true);
- }else{
- fail();
- }
- ia.stopAuditThread();
- // Allow time for the thread to stop
- Thread.sleep(1000);
- if(!ia.isThreadInitialized()){
- assertTrue(true);
- }else{
- fail();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- fail();
- }
- }
-
- public void testDoGetPapTest(){
- try{
- Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test");
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doGet(httpServletRequest, httpServletResponse);
- logger.info(httpServletResponse.getStatus());
-
- //Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- }catch (Exception e){
- logger.info("testDoGetPapTest failed with message: " + e.getMessage());
- fail();
- }
- assertTrue(true);
- }
-
-
- * Need to figure a way to get it to match any message string
- * public void testDoGetPapTestFpcFailure(){
- try{
- Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test");
- Mockito.when(httpServletRequest.getHeader("THIS-IS-A-TEST")).thenReturn("FPC");
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, Mockito.anyString());
- }catch (Exception e){
- logger.info("testDoGetPapTestFpcFailure failed with message: " + e.getMessage());
- fail();
- }
- assertTrue(true);
- }
-
- public void testDoGetLocal(){
- try{
- Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("localhost");
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doGet(httpServletRequest, httpServletResponse);
-
- logger.info(httpServletResponse.getStatus());
- Mockito.verify(httpServletResponse).setHeader("content-type", "application/json");
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- }catch (Exception e){
- fail();
- }
-
- assertTrue(true);
- }
-
- public void testDoGetNonLocal(){
- //return non-local host remote address, which is invalid
- Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("0.0.0.0");
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doGet(httpServletRequest, httpServletResponse);
- logger.info(httpServletResponse.getStatus());
- String message = "Unknown PDP: from 0.0.0.0 us: null";
-
- Mockito.verify(httpServletResponse).sendError(401, message);
-
- }catch (Exception e){
- fail();
- }
- }
-
- public void testDoGetWithGroup() throws Exception{
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default");
- //Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn("default");
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- }
-
- public void testDoPostWithGroup(){
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default");
- Mockito.when(httpServletRequest.getParameter("policyId")).thenReturn("default");
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doPost(httpServletRequest, httpServletResponse);
- //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': java.lang.NullPointerException");
- //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': javax.persistence.PersistenceException: Group policy is being added to does not exist with id default");
-
- }catch (Exception e){
- fail();
- }
- }
- //why is this test trying to send no pdp id and expecting a 200 response?
-
- public void testDoPost(){
- final ByteArrayOutputStream os = new ByteArrayOutputStream ();
- ByteArrayOutputStream multiPartResponse = new ByteArrayOutputStream();
- Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-JMX-PORT")).thenReturn("0");
-
- try{
- multiPartResponse.writeTo(os);
- final ByteArrayInputStream is = new ByteArrayInputStream (os.toByteArray ());
- Mockito.when(httpServletRequest.getInputStream()).thenReturn(new ServletInputStream() {
- @Override
- public int read() throws IOException {
- return is.read();
- }
- });
-
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doPost(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- }catch (Exception e){
- fail();
- }
- }
-
-
- public void testDoPostPDPId(){
- String groupId = "newPDP";
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(groupId);
- Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn(groupId);
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'");
- }catch(Exception e){
- fail();
- }
- }
-
- public void testDoPutInvalidAdminConsoleURL(){
- Mockito.when(httpServletRequest.getParameter("adminConsoleURL")).thenReturn("wwww.adminConsole.com");
- //204
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT);
- }catch (Exception e){
- fail();
- }
- }
-
- public void testDoPutWithGroupIdAndUnimplimentedPipId(){
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default");
- Mockito.when(httpServletRequest.getParameter("pipId")).thenReturn("default");
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
- }catch (Exception e){
- fail();
- }
- }
-
- public void testDoDeleteNoGroup(){
- Mockito.when(httpServletRequest.getParameter("groupdId")).thenReturn(null);
-
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doDelete(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId");
- }catch (Exception e){
- fail();
- }
- }
-
- public void testDoDeleteWithDefaultGroup(){
- Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default");
-
- try{
- papServlet.init(servletConfig);
- IntegrityAudit ia = papServlet.getIa();
- ia.stopAuditThread();
- papServlet.doDelete(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"You cannot delete the default group.");
- }catch(Exception e){
- fail();
- }
- }
-}
-*/ \ No newline at end of file
diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
index 6cb8e071b..9d7fae209 100644
--- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
+++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
@@ -20,12 +20,8 @@
package org.openecomp.policy.pap.xacml.rest.components;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
@@ -50,11 +46,9 @@ import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao.PolicyDBDaoTestClass;
import org.openecomp.policy.rest.XACMLRestProperties;
import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
-import org.openecomp.policy.rest.jpa.ActionBodyEntity;
import org.openecomp.policy.rest.jpa.GroupEntity;
import org.openecomp.policy.rest.jpa.PdpEntity;
import org.openecomp.policy.rest.jpa.PolicyEntity;
-import org.openecomp.policy.rest.util.Webapps;
import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
import org.openecomp.policy.xacml.std.pap.StdPDPGroup;
import org.openecomp.policy.xacml.util.XACMLPolicyWriter;
@@ -64,7 +58,6 @@ import com.att.research.xacml.util.XACMLProperties;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-@Ignore //only run locally as timing sometimes causes failures on Jenkins
public class PolicyDBDaoTest {
private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class);
@@ -80,14 +73,14 @@ public class PolicyDBDaoTest {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try{
- em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
- em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
- em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
- em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
- em.createQuery("DELETE FROM PdpEntity").executeUpdate();
- em.createQuery("DELETE FROM GroupEntity").executeUpdate();
+ em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
+ em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
+ em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
+ em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
+ em.createQuery("DELETE FROM PdpEntity").executeUpdate();
+ em.createQuery("DELETE FROM GroupEntity").executeUpdate();
- em.getTransaction().commit();
+ em.getTransaction().commit();
} catch(Exception e){
logger.error("Exception Occured"+e);
em.getTransaction().rollback();
@@ -130,21 +123,6 @@ public class PolicyDBDaoTest {
}
@Test
- public void getScopeAndNameAndTypeTest(){
-
- String s = d.getGitPath();
- String pathIwantToUse;
- if(s.contains("/")){
- pathIwantToUse = "/root/users/" + s + "/org/openecomp/Config_mypolicy.xml";
- } else {
- pathIwantToUse = "C:\\root\\users\\" + s + "\\org\\openecomp\\Config_mypolicy.xml";
- }
- String[] snt = d.getScopeAndNameAndType(pathIwantToUse);
- Assert.assertEquals("Scope was parsed wrong","org.openecomp", snt[0]);
- Assert.assertEquals("Policy name was parsed wrong","Config_mypolicy.xml", snt[1]);
- Assert.assertEquals("Policy type was parsed wrong","Config", snt[2]);
- }
- @Test
public void computeScopeTest(){
Assert.assertEquals("com",d.computeScope("C:\\Users\\testuser\\admin\\repo\\com\\", "C:\\Users\\testuser\\admin\\repo"));
Assert.assertEquals("org.openecomp.policy",d.computeScope("/Users/testuser/admin/repo/org/openecomp/policy", "/Users/testuser/admin/repo"));
@@ -160,176 +138,27 @@ public class PolicyDBDaoTest {
Assert.assertEquals("org.openecomp.Action_mypolicy.json", configFile);
}
- @Test
- public void transactionTests(){
-
-
-// try{
-// transac.commitTransaction();
-// Assert.fail();
-// } catch(IllegalStateException e){
-// //worked
-// } catch(Exception e2){
-// Assert.fail();
-// }
- String filePath = null;
- String xmlFile = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<Policy xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" PolicyId=\"urn:com:xacml:policy:id:eaa4bb64-59cf-4517-bb44-b2eeabd50b11\" Version=\"1\" RuleCombiningAlgId=\"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides\">\n <Description></Description>\n <Target>\n <AnyOf>\n <AllOf>\n <Match MatchId=\"org.openecomp.labs.ecomp.function.regex-match\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">99</AttributeValue>\n <AttributeDesignator Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" AttributeId=\"cpu\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\" MustBePresent=\"false\"/>\n </Match>\n </AllOf>\n </AnyOf>\n </Target>\n <Rule RuleId=\"urn:com:xacml:rule:id:3350bf37-43d0-4a94-a317-febec81150d8\" Effect=\"Permit\">\n <Target/>\n <ObligationExpressions>\n <ObligationExpression ObligationId=\"test\" FulfillOn=\"Permit\">\n <AttributeAssignmentExpression AttributeId=\"performer\" Category=\"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">PDPAction</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"type\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">REST</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"url\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">http://localhost:8056/pcd</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"method\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">GET</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"body\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">$URLaction/com.Action_patbaction7.json</AttributeValue>\n </AttributeAssignmentExpression>\n </ObligationExpression>\n </ObligationExpressions>\n </Rule>\n</Policy>\n";
- String jsonFile = "{\"actionAttribute\":\"Memory\"}";
-
- try{
- //policy file
- InputStream in = new ByteArrayInputStream(xmlFile.getBytes());
- String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY);
- FileUtils.forceMkdir(new File(workspaceDir+"/com/att"));
- File outFile = new File(workspaceDir+"/org/openecomp/Action_mypol.xml");
- OutputStream out = new FileOutputStream(outFile);
- IOUtils.copy(in, out);
- filePath = outFile.getAbsolutePath();
- out.close();
-
- //action body file
- InputStream actionIn = new ByteArrayInputStream(jsonFile.getBytes());
- String webappDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE);
- XACMLProperties.setProperty(XACMLRestProperties.PROP_PAP_WEBAPPS, webappDir);
- String actionDir = Webapps.getActionHome();
- FileUtils.forceMkdir(new File(actionDir));
- File actionOutFile = new File(actionDir+"/org.openecomp.Action_mypol.json");
- OutputStream actionOut = new FileOutputStream(actionOutFile);
- IOUtils.copy(actionIn, actionOut);
- actionOut.close();
-
- }catch(Exception e){
- //could not run test
- }
- PolicyDBDaoTransaction transac = dbd.getNewTransaction();
- if(filePath != null){
- try{
- transac.createPolicy(filePath, "tester");
- transac.commitTransaction();
- } catch(Exception e){
- Assert.fail();
- }
- EntityManager getData = emf.createEntityManager();
- Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name");
- getDataQuery.setParameter("scope", "org.openecomp");
- getDataQuery.setParameter("name","Action_mypol.xml");
- PolicyEntity result = null;
- try{
- result = (PolicyEntity)getDataQuery.getSingleResult();
- } catch(Exception e){
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- Assert.assertEquals(xmlFile, result.getPolicyData());
- getData.close();
- result = null;
- xmlFile = null;
- try{
- transac = dbd.getNewTransaction();
- transac.deletePolicy(filePath);
- } catch(Exception e){
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- Assert.assertTrue(transac.isTransactionOpen());
- try{
- transac.deletePolicy(filePath);
- Assert.fail();
- } catch(IllegalStateException e){
- //pass
- } catch(Exception e){
- Assert.fail();
- }
- transac.commitTransaction();
- //Assert.assertFalse(transac.isTransactionOpen());
- try{
- transac = dbd.getNewTransaction();
- transac.deletePolicy(filePath);
- } catch(Exception e){
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- transac.commitTransaction();
- //Assert.assertFalse(transac.isTransactionOpen());
- String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY);
- PolicyDBDaoTransaction willFail = dbd.getNewTransaction();
- File fakeFile = new File("directorythatdoesnotexist/"+workspaceDir);
- try{
- willFail.createPolicy(fakeFile.getAbsolutePath(), "user1");
- Assert.fail();
- } catch(IllegalArgumentException e){
- if(!e.getMessage().equals("The file path could not be parsed")){
- Assert.fail();
- }
- }
- willFail.close();
-
- fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"/Action_mypol2.xml");
- willFail = dbd.getNewTransaction();
- try{
- willFail.createPolicy(fakeFile.getAbsolutePath(), "user1");
- Assert.fail();
- } catch(IllegalArgumentException e){
- if(!e.getMessage().equals("The file path could not be parsed")){
- Assert.fail();
- }
- }
- willFail.close();
-
- fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"com/att/Action_mypol2.xml");
- willFail = dbd.getNewTransaction();
- try{
- willFail.createPolicy(fakeFile.getAbsolutePath(), "user1");
- Assert.fail();
- } catch(IllegalArgumentException e){
- if(!e.getMessage().equals("The file path does not exist")){
- Assert.fail();
- }
- }
- willFail.close();
-
- emf = Persistence.createEntityManagerFactory("testPU");
- EntityManager aem = emf.createEntityManager();
- Query actionQuery = aem.createQuery("SELECT a FROM ActionBodyEntity a WHERE a.actionBodyName=:actionBodyName");
- actionQuery.setParameter("actionBodyName", "org.openecomp.Action_mypol.json");
- List<?> actionQueryList = actionQuery.getResultList();
- if(actionQueryList.size() < 1){
- Assert.fail("ActionBodyEntity not found with actionBodyName=: org.openecomp.Action_mypol.json" );
- } else if(actionQueryList.size() > 1){
- //something went wrong
- Assert.fail("Somehow, more than one ActionBodyEntity with the actionBodyName = org.openecomp.Action_mypol.json");
- } else {
- ActionBodyEntity abe = (ActionBodyEntity)actionQueryList.get(0);
- logger.debug("\n\nPolicyDBDaoTest.transactionTests() Assert.assertEquals"
- + "\n abe.getActionBody() = " + abe.getActionBody()
- + "\n jsonFile = " + jsonFile
- + "\n\n");
- Assert.assertEquals(abe.getActionBody(),jsonFile);
- }
- }
- }
-
+ @Ignore
@Test
public void createFromPolicyObject(){
- String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY);
- File parentPath = new File(workspaceDir+"/com/att");
- File scope = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY));
+ String workspaceDir = "src/test/resources/";
+ File parentPath = new File(workspaceDir+"/com");
Policy policyObject = new ConfigPolicy();
policyObject.policyAdapter = new PolicyRestAdapter();
policyObject.policyAdapter.setConfigName("testpolicy1");
policyObject.policyAdapter.setParentPath(parentPath.getAbsolutePath());
- policyObject.policyAdapter.setUserGitPath(scope.getPath());
policyObject.policyAdapter.setPolicyDescription("my description");
policyObject.policyAdapter.setConfigBodyData("this is my test config file");
policyObject.policyAdapter.setPolicyName("testpolicy1");
policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG);
policyObject.policyAdapter.setPolicyType("Config");
+ policyObject.policyAdapter.setDomainDir("org.openecomp");
PolicyType policyTypeObject = new PolicyType();
policyObject.policyAdapter.setPolicyData(policyTypeObject);
PolicyDBDaoTransaction transaction = dbd.getNewTransaction();
try{
- transaction.createPolicy(policyObject, "testuser1");
- transaction.commitTransaction();
+ transaction.createPolicy(policyObject, "testuser1");
+ transaction.commitTransaction();
} catch(Exception e){
transaction.rollbackTransaction();
Assert.fail();
@@ -385,6 +214,7 @@ public class PolicyDBDaoTest {
transaction.commitTransaction();
}
+ @Ignore
@Test
public void groupTransactions(){
PolicyDBDaoTransaction group = dbd.getNewTransaction();
@@ -609,13 +439,6 @@ public class PolicyDBDaoTest {
Assert.fail();
}
em.close();
- //update pdp
-
- //set group as default
-
- //move pdp to new group
-
-
}
@Test
@@ -639,7 +462,7 @@ public class PolicyDBDaoTest {
String desc = d.getDescriptionFromXacml("<Description>"+myTestDesc+"</Description>");
Assert.assertEquals(myTestDesc, desc);
}
-
+ @Ignore
@Test
public void threadingStabilityTest(){
if(logger.isDebugEnabled()){