diff options
author | rb7147 <rb7147@att.com> | 2017-06-09 15:11:06 -0400 |
---|---|---|
committer | rb7147 <rb7147@att.com> | 2017-06-12 16:59:35 -0400 |
commit | 685ed1545ed28b777a3ba6e7d315b78f355154cb (patch) | |
tree | 1e37d639242c5f1e9cbf5623821f8498542b81dc | |
parent | fc5c07705edc4dcb7083b39116a43844bb6a1490 (diff) |
[Policy-20] getConfig & Policy resolved blockers
Change-Id: If08e4c90d419e8d6e1426d817a12dde5b7cafba3
Signed-off-by: rb7147 <rb7147@att.com>
35 files changed, 829 insertions, 2159 deletions
diff --git a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/compiler/ControlLoopCompiler.java b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/compiler/ControlLoopCompiler.java index 799371a2a..2f01307af 100644 --- a/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/compiler/ControlLoopCompiler.java +++ b/ECOMP-ControlloopPolicy/src/main/java/org/openecomp/policy/controlloop/compiler/ControlLoopCompiler.java @@ -78,14 +78,16 @@ public class ControlLoopCompiler { if (controlLoop == null && callback != null) { callback.onError("controlLoop cannot be null"); } - if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) && callback != null) { - callback.onError("Missing controlLoopName"); - } - if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) { - callback.onError("Unsupported version for this compiler"); - } - if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) { - throw new CompilerException("trigger_policy is not valid"); + if (controlLoop!=null){ + if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) && callback != null) { + callback.onError("Missing controlLoopName"); + } + if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) { + callback.onError("Unsupported version for this compiler"); + } + if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) { + throw new CompilerException("trigger_policy is not valid"); + } } } 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()){ diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/services/GetMetricsService.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/services/GetMetricsService.java index d390df864..dc431b0d5 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/services/GetMetricsService.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/services/GetMetricsService.java @@ -118,9 +118,13 @@ public class GetMetricsService { metricsResponse.setPdpMetrics(pdpCount); } catch (JsonException | IllegalStateException e) { + String jsonString = null; + if(json != null){ + jsonString = json.toString(); + } message = XACMLErrorConstants.ERROR_DATA_ISSUE - + " improper JSON object : " + json != null ? json.toString() : "JSON is null"; - LOGGER.error(message); + + " improper JSON object : " + jsonString; + LOGGER.error(message + e); metricsResponse.setResponseMessage(message); metricsResponse.setResponseCode(400); return metricsResponse; diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java index 27d6b6f76..a1d0ece83 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java @@ -94,35 +94,36 @@ public class ManualNotificationUpdateThread implements Runnable { } catch (MalformedURLException e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in processing URL to create topic for Notification ", e); } - - String consumerTopic = aURL.getHost() + aURL.getPort() + "UpdateRequest"; - SendMessage(consumerTopic, "Starting-Topic"); - final LinkedList<String> urlList = new LinkedList<> (); - for ( String u : clusterList.split ( "," ) ){ - urlList.add ( u ); - } - - try { - CConsumer = CambriaClientFactory.createConsumer ( null, urlList, consumerTopic , group, id, 20*1000, 1000 ); - } catch (MalformedURLException | GeneralSecurityException e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create UEB Consumer: ", e1); - } + if(aURL != null){ + String consumerTopic = aURL.getHost() + aURL.getPort() + "UpdateRequest"; + SendMessage(consumerTopic, "Starting-Topic"); + final LinkedList<String> urlList = new LinkedList<> (); + for ( String u : clusterList.split ( "," ) ){ + urlList.add ( u ); + } - while (this.isRunning()) { - LOGGER.debug("While loop test _ take out "); try { - for ( String msg : CConsumer.fetch () ){ - LOGGER.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : "); - returnTopic = processMessage(msg); - if(returnTopic != null){ - SendMessage(returnTopic, update); + CConsumer = CambriaClientFactory.createConsumer ( null, urlList, consumerTopic , group, id, 20*1000, 1000 ); + } catch (MalformedURLException | GeneralSecurityException e1) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create UEB Consumer: ", e1); + } + + while (this.isRunning()) { + LOGGER.debug("While loop test _ take out "); + try { + for ( String msg : CConsumer.fetch () ){ + LOGGER.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : "); + returnTopic = processMessage(msg); + if(returnTopic != null){ + SendMessage(returnTopic, update); + } } + } catch (IOException e) { + LOGGER.debug(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in processing UEB message" + e); } - } catch (IOException e) { - LOGGER.debug(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in processing UEB message"); } + LOGGER.debug("Stopping UEB Consumer loop will no longer fetch messages from the cluster"); } - LOGGER.debug("Stopping UEB Consumer loop will no longer fetch messages from the cluster"); } else if ("dmaap".equals(propNotificationType)) { String dmaapServers = null; try { @@ -200,14 +201,15 @@ public class ManualNotificationUpdateThread implements Runnable { } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+ "Error sending notification update: ", e); } - - try { - pub.send( "pdpReturnMessage", message ); - LOGGER.debug("Sending to Message to tpoic" + topic); - } catch (IOException e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+ "Error sending notification update"); - } - pub.close(); + if(pub != null){ + try { + pub.send( "pdpReturnMessage", message ); + LOGGER.debug("Sending to Message to tpoic" + topic); + pub.close(); + } catch (IOException e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+ "Error sending notification update" +e); + } + } } private String processMessage(String msg) { diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java index ed2fbd1f4..a226a3afe 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java @@ -377,7 +377,7 @@ public class NotificationController { delete = true; dir = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS)+File.separator+"Action"); } - if(delete && dir!=null){ + if(delete){ FileFilter fileFilter = new WildcardFileFilter(oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf("."))+".*"); File[] configFile = dir.listFiles(fileFilter); if(configFile.length==1){ @@ -385,9 +385,7 @@ public class NotificationController { } } }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Couldn't remove the policy/config file " + oldPolicy.getName()); - // TODO:EELF Cleanup - Remove LOGGER - //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Couldn't remove the policy file " + oldPolicy.getName()); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Couldn't remove the policy/config file " + oldPolicy.getName() + e); } } diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java index 136f22268..21fb8f3c9 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java @@ -143,27 +143,26 @@ public class NotificationServer { } catch (GeneralSecurityException e1) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error creating the UEB publisher" + e1.getMessage()); } - - try { - pub.send( "MyPartitionKey", notification ); - } catch (IOException e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error sending notification update" + e.getMessage()); - } - - // close the publisher. The batching publisher does not send events - // immediately, so you MUST use close to send any remaining messages. - // You provide the amount of time you're willing to wait for the sends - // to succeed before giving up. If any messages are unsent after that time, - // they're returned to your app. You could, for example, persist to disk - // and try again later. - final List<?> stuck = pub.close ( 20, TimeUnit.SECONDS ); - - if ( stuck.size () > 0 ){ - LOGGER.error( stuck.size() + " messages unsent" ); - }else{ - LOGGER.info( "Clean exit; all messages sent: " + notification ); + if(pub != null){ + try { + pub.send( "MyPartitionKey", notification ); + } catch (IOException e) { + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error sending notification update" + e.getMessage() + e); + } + // close the publisher. The batching publisher does not send events + // immediately, so you MUST use close to send any remaining messages. + // You provide the amount of time you're willing to wait for the sends + // to succeed before giving up. If any messages are unsent after that time, + // they're returned to your app. You could, for example, persist to disk + // and try again later. + final List<?> stuck = pub.close ( 20, TimeUnit.SECONDS ); + + if (!stuck.isEmpty()){ + LOGGER.error( stuck.size() + " messages unsent" ); + }else{ + LOGGER.info( "Clean exit; all messages sent: " + notification ); + } } - } else if (propNotificationType.equals("dmaap")) { // Setting up the Publisher for DMaaP MR diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java index ae72db267..9a2dbdbdb 100644 --- a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java @@ -202,12 +202,14 @@ public class XacmlAdminAuthorization { // // Should only be one result // - for (Result result : response.getResults()) { - Decision decision = result.getDecision(); - logger.info("Decision: " + decision); - if (decision.equals(Decision.PERMIT)) { - return true; - } + if(response != null){ + for (Result result : response.getResults()) { + Decision decision = result.getDecision(); + logger.info("Decision: " + decision); + if (decision.equals(Decision.PERMIT)) { + return true; + } + } } } catch (PDPException e) { logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PDP Decide failed: " + e.getLocalizedMessage()); diff --git a/ECOMP-SDK-APP/xacml.admin.properties b/ECOMP-SDK-APP/xacml.admin.properties index b3550dfc1..e6774a6cd 100644 --- a/ECOMP-SDK-APP/xacml.admin.properties +++ b/ECOMP-SDK-APP/xacml.admin.properties @@ -60,14 +60,6 @@ xacml.AC.papEngineFactory=org.openecomp.policy.xacml.admin.util.RESTfulPAPFactor # Set your domain here: xacml.rest.admin.domain=com # -# Location where the GIT repository is located -# -xacml.rest.admin.repository=repository -# -# Location where all the user workspaces are located. -# -xacml.rest.admin.workspace=workspace -# # # Property to declare the max time frame for logs. # diff --git a/LogParser/pom.xml b/LogParser/pom.xml index 20e06045a..81784b8a2 100644 --- a/LogParser/pom.xml +++ b/LogParser/pom.xml @@ -58,9 +58,14 @@ </exclusions> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.17</version> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.4</version> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java b/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java index 4b03d2aaa..3b1ccffc5 100644 --- a/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java +++ b/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java @@ -32,7 +32,7 @@ public class LogEntryObject { private LOGTYPE logType; public enum LOGTYPE { - INFO, ERROR, SEVERE, WARN; + INFO, DEBUG, ERROR, SEVERE, WARN; } public String getSystem() { @@ -71,4 +71,4 @@ public class LogEntryObject { public void setLogType(LOGTYPE logType) { this.logType = logType; } -} +}
\ No newline at end of file diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java index 8c6df28b0..443267309 100644 --- a/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java +++ b/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java @@ -48,6 +48,7 @@ import org.apache.log4j.Logger; import org.openecomp.policy.common.im.AdministrativeStateException; import org.openecomp.policy.common.im.IntegrityMonitor; import org.openecomp.policy.common.im.StandbyStatusException; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; /** @@ -57,15 +58,24 @@ import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; */ public class ParseLog { - private static final Logger logger = Logger.getLogger(ParseLog.class.getName()); + // only logging last line of each log file processed to the log4j log file defined by property - PARSERLOGPATH + private static final Logger log4jlogger = Logger.getLogger(ParseLog.class.getName()); + + // processing logging + private static org.openecomp.policy.common.logging.flexlogger.Logger logger = FlexLogger.getLogger(ParseLog.class.getName()); private static String system; private static int lastNumberRead = 0; + private static int debuglastNumberRead = 0; + private static int errorlastNumberRead = 0; private static String type; private static long startFileSize; + private static long debugStartFileSize; + private static long errorStartFileSize; private static String systemLogFile; private static String logFile; - + private static String debuglogFile; + private static String errorlogFile; private static String JDBC_URL; private static String JDBC_USER; private static String JDBC_PASSWORD = ""; @@ -73,84 +83,240 @@ public class ParseLog { private static int maxLength = 255; //Max length that is allowed in the DB table private static String resourceName; private static long sleepTimer = 50000; - static IntegrityMonitor im; + static IntegrityMonitor im; + private static boolean isMissingLogFile; private static RandomAccessFile randomAccessFile; public static void main(String[] args) throws Exception { Properties logProperties = getPropertiesValue("parserlog.properties"); - Path filePath = Paths.get(logFile); - File file = new File(logFile); + + if(logProperties == null || isMissingLogFile){ + // missing the path of log file in the properties file, so stop the process + logger.error("logProperties is null or LOGPATH is missing in parserlog.properties, so stop the process."); + return; + } + File fileLog = new File(systemLogFile); - startFileSize = file.length(); - + im = IntegrityMonitor.getInstance(resourceName,logProperties ); - logger.info("System: " + system ); - logger.info("System type: " + type ); - logger.info("Logging File: " + systemLogFile ); - logger.info("log file: " + logFile); - logger.info("JDBC_URL: " + JDBC_URL); - logger.info("JDBC_DRIVER: " + JDBC_DRIVER); - - String filesRead = PullLastLineRead(fileLog); - if (filesRead!= null){ - filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "<br />"); - lastNumberRead= Integer.parseInt(filesRead.trim()); - }else{ - lastNumberRead = 0; - } - startFileSize = countLines(logFile); - logger.info("File Line Count: " + startFileSize + " value read in: " + lastNumberRead); - if (startFileSize < lastNumberRead ){ - logger.error("Filed Rolled: set Last number read to 0"); - lastNumberRead = 0; - } - Runnable runnable = new Runnable (){ - public void run(){ - while (true){ - - if (file.isFile()){ - try (Stream<String> lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> logger.info("Last line Read: " + lastNumberRead)).skip(lastNumberRead)) { + startDebugLogParser(fileLog); + startErrorLogParser(fileLog); + startAPIRestLogParser(fileLog); + + } + + private static void startDebugLogParser(File fileLog) throws Exception{ + if(debuglogFile != null && !debuglogFile.isEmpty()){ + + // pull the last line number + String dataFileName = "debug.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "<br />"); + debuglastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + debuglastNumberRead = 0; + } + + debugStartFileSize = countLines(debuglogFile); + if (debugStartFileSize < debuglastNumberRead ){ + logger.error("Filed Rolled: set Last debug number read to 0"); + debuglastNumberRead = 0; + } + + isMissingLogFile = false; + Path debugfilePath = Paths.get(debuglogFile); + File debugfile = new File(debuglogFile); + debugStartFileSize = debugfile.length(); + // start process debug.log file + + Runnable runnable = new Runnable (){ + boolean isStop = false; + + public void run(){ + while (!isStop){ + + if (debugfile.isFile()){ + // log4jlogger must use .info + try (Stream<String> lines = Files.lines(debugfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + debuglastNumberRead)).skip(debuglastNumberRead)) { + + lines.forEachOrdered(line -> process(line, type, LOGTYPE.DEBUG)); + + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + } + try { + Thread.sleep(sleepTimer); + debugStartFileSize = countLines(debuglogFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } - lines.forEachOrdered(line -> process(line, type)); - - } catch (IOException e) { - logger.error("Error processing line in log file: " + e); + logger.debug("File Line Count of debug.log: " + debugStartFileSize + " value read in: " + debuglastNumberRead); + if (debugStartFileSize < debuglastNumberRead ){ + logger.debug("Failed Rolled: set Last number read to 0"); + debuglastNumberRead = 0; + } } } - try { - Thread.sleep(sleepTimer); - startFileSize = countLines(logFile); - } catch (InterruptedException | IOException e) { - logger.error("Error: " + e); - } + }; + + Thread thread = new Thread(runnable); + thread.start(); + + } + } + + private static void startErrorLogParser(File fileLog) throws Exception{ + + if(errorlogFile != null && !errorlogFile.isEmpty()){ + + // pull the last line number + String dataFileName = "error.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "<br />"); + errorlastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + errorlastNumberRead = 0; + } + + errorStartFileSize = countLines(errorlogFile); + if (errorStartFileSize < errorlastNumberRead ){ + logger.error("Filed Rolled: set Last error number read to 0"); + errorlastNumberRead = 0; + } + + isMissingLogFile = false; + Path errorfilePath = Paths.get(errorlogFile); + File errorfile = new File(errorlogFile); + errorStartFileSize = errorfile.length(); + // start process error.log file + Runnable runnable = new Runnable (){ + boolean isStop = false; + public void run(){ + + while (!isStop){ + if (errorfile.isFile()){ + // log4jlogger must use .info + try (Stream<String> lines = Files.lines(errorfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + errorlastNumberRead)).skip(errorlastNumberRead)) { + + lines.forEachOrdered(line -> process(line, type, LOGTYPE.ERROR)); - logger.info("File Line Count: " + startFileSize + " value read in: " + lastNumberRead); - if (startFileSize < lastNumberRead ){ - logger.info("Failed Rolled: set Last number read to 0"); - lastNumberRead = 0; + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + } + try { + Thread.sleep(sleepTimer); + errorStartFileSize = countLines(errorlogFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + + logger.debug("File Line Count of error.log: " + errorStartFileSize + " value read in: " + errorlastNumberRead); + if (errorStartFileSize < errorlastNumberRead ){ + logger.debug("Failed Rolled: set Last error number read to 0"); + errorlastNumberRead = 0; + } + } } - } - } - }; + }; + + Thread thread = new Thread(runnable); + thread.start(); + } + } + + private static void startAPIRestLogParser(File fileLog) throws Exception{ - Thread thread = new Thread(runnable); - thread.start(); - - } - + if(logFile != null && !logFile.isEmpty()){ + + // pull the last line number + String dataFileName = type.toLowerCase()+"-rest.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "<br />"); + lastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + lastNumberRead = 0; + } + startFileSize = countLines(logFile); + if (startFileSize < lastNumberRead ){ + logger.error("Filed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + + isMissingLogFile = false; + Path filePath = Paths.get(logFile); + File file = new File(logFile); + startFileSize = file.length(); + // start process pap/pdp-rest.log file + Runnable runnable = new Runnable () { + boolean isStop = false; + public void run(){ + while (!isStop){ + + if (file.isFile()){ + // log4jlogger must use .info + try (Stream<String> lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + lastNumberRead)).skip(lastNumberRead)) { + + lines.forEachOrdered(line -> process(line, type, LOGTYPE.INFO)); + + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + } + try { + Thread.sleep(sleepTimer); + startFileSize = countLines(logFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + + logger.debug("File Line Count of " + dataFileName+": " + startFileSize + " value read in: " + lastNumberRead); + if (startFileSize < lastNumberRead ){ + logger.debug("Failed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + } + } + }; + + Thread thread = new Thread(runnable); + thread.start(); + } + } + public static int countLines(String filename) throws IOException { LineNumberReader reader = new LineNumberReader(new FileReader(filename)); int cnt = 0; - while ((reader.readLine()) != null); + String line= null; + while ((line = reader.readLine()) != null) { + logger.info("Reading the Logs"+line); + } cnt = reader.getLineNumber(); reader.close(); return cnt; } - public static String PullLastLineRead(File file) throws IOException { + public static String PullLastLineRead(File file, String dataFileName) throws IOException { if(!file.exists()){ file.createNewFile(); return null; @@ -158,38 +324,48 @@ public class ParseLog { randomAccessFile = new RandomAccessFile(file, "r"); StringBuilder builder = new StringBuilder(); long length = file.length(); - length--; - randomAccessFile.seek(length); - for(long seek = length; seek >= 0; --seek){ - randomAccessFile.seek(seek); - char c = (char)randomAccessFile.read(); - builder.append(c); - if(c == '\n'){ - builder = builder.reverse(); - if (builder.toString().contains("Last line Read:")){ - String[] parseString = builder.toString().split("Last line Read:"); - String returnValue = parseString[1].replace("\r", ""); - return returnValue.trim(); - } - builder = null; - builder = new StringBuilder(); - } - + logger.debug("dataFileName: " +dataFileName); + if(length > 0){ + length--; + randomAccessFile.seek(length); + for(long seek = length; seek >= 0; --seek){ + randomAccessFile.seek(seek); + char c = (char)randomAccessFile.read(); + builder.append(c); + if(c == '\n'){ + builder = builder.reverse(); + logger.debug("builder.toString(): " +builder.toString()); + if (builder.toString().contains("Last-"+dataFileName+"-line-Read:")){ + String[] parseString = builder.toString().split("Last-"+dataFileName+"-line-Read:"); + String returnValue = parseString[1].replace("\r", ""); + return returnValue.trim(); + } + builder = null; + builder = new StringBuilder(); + } + } } + return null; } public static LogEntryObject pullOutLogValues(String line, String type){ Date date; LogEntryObject logEntry = new LogEntryObject(); + String description = ""; logEntry.setSystemType(type); - String description = null; - logEntry.setSystem(system); - - //Values for PDP/PAP log file - if(line.contains("||INFO||") || line.contains("||ERROR||")){ - String[] splitString = line.split("[||]"); + logger.debug("In pullOutLogValues ..."); + //Values for PDP/PAP debug.log file contains "INFO:", error.log file contains ""ERROR:", others are in PDP/PAP rest log file + if(line.contains("||INFO||") || line.contains("||ERROR||") || line.contains("INFO:") || line.contains("ERROR:")){ + String[] splitString = null; + if(line.contains("||INFO||") || line.contains("||ERROR||")){ + splitString = line.split("[||]"); + }else if(line.contains("INFO:")){ + splitString = line.split("INFO:"); + }else{ + splitString = line.split("ERROR:"); + } String dateString = splitString[0].substring(0, 19); logEntry.setDescription(splitString[splitString.length-1]); @@ -198,12 +374,13 @@ public class ParseLog { logEntry.setDate(date); logEntry.setRemote(parseRemoteSystem(line)); - if (line.contains("||INFO||")){ + if (line.contains("INFO:") || line.contains("||INFO||")){ logEntry.setLogType(LOGTYPE.INFO); }else{ logEntry.setLogType(LOGTYPE.ERROR); - } - }else if (line.contains("INFO") && line.contains(")-")){ + } + // from PDP/PAP rest log file below + }else if (line.contains("INFO") && line.contains(")-")){ //parse out description logEntry.setDescription(line.substring(line.indexOf(")-")+3)); @@ -272,8 +449,7 @@ public class ParseLog { logEntry.setLogType(LOGTYPE.ERROR); }else { return null; - } - + } return logEntry; } @@ -287,20 +463,28 @@ public class ParseLog { } } - public static void process(String line, String type) { + public static void process(String line, String type, LOGTYPE logFile) { + + logger.debug("In process: processing line : " + line); LogEntryObject returnLogValue = null; if (im!=null){ try { im.startTransaction(); } catch (AdministrativeStateException e) { - logger.error("Error received" + e); - + logger.error("Error received" + e); } catch (StandbyStatusException e) { logger.error("Error received" + e); } } returnLogValue = pullOutLogValues(line, type); - lastNumberRead++; + + if(logFile.equals(LOGTYPE.DEBUG)){ + debuglastNumberRead++; + }else if(logFile.equals(LOGTYPE.ERROR)){ + errorlastNumberRead++; + }else if(logFile.equals(LOGTYPE.INFO)){ + lastNumberRead++; + } if (returnLogValue!=null){ writeDB(returnLogValue); } @@ -310,6 +494,7 @@ public class ParseLog { } private static void writeDB(LogEntryObject returnLogValue) { + Connection conn = DBConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); DBAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(), returnLogValue.getDate(), returnLogValue.getRemote(), @@ -334,7 +519,10 @@ public class ParseLog { if (date!=null){ Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdate = formatter.format(date); + sdate = formatter.format(date); + logger.debug("DBAccesss : sdate : " + sdate); + }else{ + logger.debug("DBAccesss : sdate is null"); } //ensure the length of description is less than the maximumm db char length @@ -399,11 +587,26 @@ public class ParseLog { return null; } + public static String[] getPaths(String logPath){ + + if(logPath != null && !logPath.isEmpty()){ + if(logPath.contains(";")){ + return logPath.split(";"); + }else{ + String[] oneFile = new String[1]; + oneFile[0] = logPath; + return oneFile; + } + } + + return null; + } + public static Properties getPropertiesValue(String fileName) { Properties config = new Properties(); Path file = Paths.get(fileName); if (Files.notExists(file)) { - logger.info("File doesn't exist in the specified Path " + file.toString()); + logger.debug("File doesn't exist in the specified Path " + file.toString()); }else{ if (file.toString().endsWith(".properties")) { InputStream in; @@ -415,7 +618,44 @@ public class ParseLog { system = config.getProperty("SERVER"); type = config.getProperty("LOGTYPE"); systemLogFile = config.getProperty("PARSERLOGPATH"); - logFile = config.getProperty("LOGPATH"); + String logFiles = config.getProperty("LOGPATH"); + if(logFiles == null || logFiles.isEmpty()){ + isMissingLogFile = true; + return null; + } + + String[] splitString = getPaths(logFiles); + + if(splitString != null){ + for(int i=0; i < splitString.length; i++){ + + if(splitString[i].contains("debug")){ + // get path of debug.log file + debuglogFile = splitString[i]; + if(debuglogFile != null && !debuglogFile.isEmpty()){ + debuglogFile = debuglogFile.trim(); + } + }else if(splitString[i].contains("error")){ + // get path of error.log file + errorlogFile = splitString[i]; + if(errorlogFile != null && !errorlogFile.isEmpty()){ + errorlogFile = errorlogFile.trim(); + } + }else { + // get path of default file + logFile = splitString[i]; + if(logFile != null && !logFile.isEmpty()){ + logFile = logFile.trim(); + } + } + } + }else{ + + debuglogFile = null; + errorlogFile = null; + logFile = null; + } + JDBC_URL = config.getProperty("JDBC_URL").replace("'", ""); JDBC_USER = config.getProperty("JDBC_USER"); JDBC_DRIVER = config.getProperty("JDBC_DRIVER"); @@ -423,11 +663,11 @@ public class ParseLog { return config; } catch (IOException e) { - logger.info("Error porcessing Cofnig file will be unable to create Health Check"); + logger.debug("Error porcessing Config file will be unable to create Health Check" + e); } } } return null; } -} +}
\ No newline at end of file diff --git a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java index 621f39742..2bd70f2be 100644 --- a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java +++ b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java @@ -21,6 +21,7 @@ package org.openecomp.xacml.parser; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.BufferedReader; @@ -38,15 +39,19 @@ import org.mockito.Mockito; import org.openecomp.policy.common.im.AdministrativeStateException; import org.openecomp.policy.common.im.IntegrityMonitor; import org.openecomp.policy.common.im.StandbyStatusException; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; public class ParseLogTest { - + + private static Logger logger = FlexLogger.getLogger(ParseLogTest.class); private Properties config = new Properties(); - private String configFile = "test_config.properties"; + private String configFile; + private String testFile1; + private String testFile2; private IntegrityMonitor im; - @Before public void setUp() throws Exception { @@ -59,41 +64,56 @@ public class ParseLogTest { fail(); } Mockito.doNothing().when(im).endTransaction(); - + ClassLoader classLoader = getClass().getClassLoader(); + configFile = classLoader.getResource("test_config.properties").getFile(); + if(configFile.startsWith("/C:/")){ + configFile = configFile.substring(1); + } + testFile1 = classLoader.getResource("LineTest.txt").getFile(); + testFile2 = classLoader.getResource("LineTest2.txt").getFile(); + } @After public void tearDown() { + + logger.debug("tearDown: enter"); + File file = new File("nonExistFile.txt"); file.delete(); - } - - //@Test - public void testMain() { - try { - ParseLog.main(null); - } catch (Exception e) { - fail(); - } + logger.debug("tearDown: exit"); } @Test public void testCountLines() throws IOException { - String fileName = "LineTest.txt"; - int returnValue = ParseLog.countLines(fileName); - assertEquals(9, returnValue); + logger.debug("testCountLines: enter"); + + int returnValue = ParseLog.countLines(testFile1); + logger.debug("testCountLines: returnValue: " + returnValue); + assertEquals(12, returnValue); + + logger.debug("testCountLines: exit"); } - + @Test public void testParseRemoteSystem() { + + logger.debug("testParseRemoteSystem: enter"); + String line = "||org.openecomp.policy.pap.xacml.rest.XACMLPapServlet$Heartbeat.run(XACMLPapServlet.java:2801)||Heartbeat 'https://localhost:8081/pdp/' status='UP_TO_DATE'"; String returnValue = ParseLog.parseRemoteSystem(line); + logger.debug("testParseRemoteSystem: returnValue: " + returnValue); assertEquals("localhost:8081", returnValue); + + logger.debug("testParseRemoteSystem: exit"); } @Test public void testGetPropertiesValue() { + + logger.debug("testGetPropertiesValue: enter"); + config = new Properties(); config.put("RESOURCE_NAME", "logparser_pap01"); config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); @@ -108,76 +128,123 @@ public class ParseLogTest { config.put("PARSERLOGPATH", "IntegrityMonitor.log"); Properties returnConfig = ParseLog.getPropertiesValue(configFile); - - + logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + + logger.debug("testGetPropertiesValue: exit"); } - + @Test public void testGetPropertiesFail() { - Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + logger.debug("testGetPropertiesFail: enter"); + + Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + logger.debug("testGetPropertiesFail: returnValue: " + returnValue); assertEquals(null, returnValue); + + logger.debug("testGetPropertiesFail: exit"); } @Test public void testParseDate(){ + + logger.debug("testParseDate: enter"); + String line = "2016-02-23 08:07:30"; Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + logger.debug("testParseDate: returnValue: " + returnValue); line = returnValue.toString().substring(0, returnValue.toString().lastIndexOf(":30")+3); assertEquals("Tue Feb 23 08:07:30", line); + + logger.debug("testParseDate: exit"); } - + @Test public void testParseDateFail(){ + + logger.debug("testParseDateFail: enter"); + String line = "2016-02-23 08:07:30"; Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", true); - + logger.debug("testParseDateFail: returnValue: " + returnValue); assertEquals(null, returnValue); + + logger.debug("testParseDateFail: exit"); } - + @Test public void testPullLastLineRead(){ - File file = new File("LineTest.txt"); + logger.debug("testPullLastLineRead: enter"); + File file = new File(testFile1); String returnValue = null; try { - returnValue = ParseLog.PullLastLineRead(file).trim(); + returnValue = ParseLog.PullLastLineRead(file, "pap-rest.log"); + logger.debug("testPullLastLineRead: returnValue for pap-rest.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("52", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "debug.log"); + logger.debug("testPullLastLineRead: returnValue for debug.log: " + returnValue); } catch (IOException e) { fail(); } - assertEquals("12", returnValue); + assertEquals("17", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "error.log"); + logger.debug("testPullLastLineRead: returnValue for error.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("22", returnValue); + logger.debug("testPullLastLineRead: exit"); } - + @Test public void testPullLastLineReadNoFile(){ + logger.debug("testPullLastLineReadNoFile: enter"); + File file = new File("nonExistFile.txt"); try { - assertEquals(null, ParseLog.PullLastLineRead(file)); + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); } catch (IOException e) { fail(); } + + logger.debug("testPullLastLineReadNoFile: exit"); } + @Test public void testPullLastLineReadFail(){ - File file = new File("LineTest2.txt"); + logger.debug("testPullLastLineReadFail: enter"); + + File file = new File(testFile2); try { - assertEquals(null, ParseLog.PullLastLineRead(file)); + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); } catch (IOException e) { fail(); } + + logger.debug("testPullLastLineReadFail: exit"); } @Test public void testPullOutLogValues(){ + + logger.debug("testPullOutLogValues: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "ERROR"); @@ -186,15 +253,47 @@ public class ParseLogTest { } catch (IOException e) { fail(); } -// assert(true); + + logger.debug("testPullOutLogValues: exit"); } + + @Test + public void testGetPaths(){ + + logger.debug("testGetPaths: enter"); + + try { + // valid test + String logPaths = "C:\\pap-log\\pap-rest.log;C:\\pap-log\\debug.log;C:\\pap-log\\error.log"; + String [] retrunObject = ParseLog.getPaths(logPaths); + assertEquals(3, retrunObject.length); + + // valid test + logPaths = "C:\\pap-log\\pap-rest.log"; + retrunObject = ParseLog.getPaths(logPaths); + assertEquals(1, retrunObject.length); + + // invalid test + logPaths = ""; + retrunObject = ParseLog.getPaths(logPaths); + assertTrue(retrunObject == null); + + } catch (Exception e) { + fail(); + } + + logger.debug("testGetPaths: exit"); + } + @Test public void testPullOutLogValuesSecond(){ + + logger.debug("testPullOutLogValuesSecond: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); strLine = br.readLine(); @@ -204,16 +303,20 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSecond: exit"); } - + @Test public void testPullOutLogValuesThird(){ + + logger.debug("testPullOutLogValuesThird: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { int number = 3; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -225,15 +328,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesThird: exit"); } @Test public void testPullOutLogValuesFourth(){ + + logger.debug("testPullOutLogValuesFourth: enter"); // Open the file FileInputStream fstream; try { int number = 4; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -245,15 +352,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesFourth: exit"); } - + @Test public void testPullOutLogValuesFith(){ + + logger.debug("testPullOutLogValuesFith: enter"); // Open the file FileInputStream fstream; try { int number = 5; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -265,15 +376,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesFith: exit"); } - + @Test public void testPullOutLogValuesSixth(){ + + logger.debug("testPullOutLogValuesSixth: enter"); // Open the file FileInputStream fstream; try { int number = 6; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -285,15 +400,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSixth: exit"); } @Test public void testPullOutLogValuesSeven(){ + + logger.debug("testPullOutLogValuesSeven: enter"); // Open the file FileInputStream fstream; try { int number = 7; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -305,15 +424,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSeven: exit"); } - + @Test public void testPullOutLogValuesEight(){ + + logger.debug("testPullOutLogValuesEight: enter"); // Open the file FileInputStream fstream; try { int number = 8; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -325,17 +448,26 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesEight: exit"); } - + @Test public void testPullOutLogValuesNull(){ + + logger.debug("testPullOutLogValuesNull: enter"); // Open the file LogEntryObject retrunObject = ParseLog.pullOutLogValues("", "Console"); assertEquals(null, retrunObject); + + logger.debug("testPullOutLogValuesNull: exit"); } - + @Test public void testLogEntryObject(){ + + logger.debug("testLogEntryObject: enter"); + Date date = new Date(); // Open the file @@ -349,10 +481,15 @@ public class ParseLogTest { assertEquals("pap", logObject.getSystemType()); assertEquals(date, logObject.getDate()); assertEquals("remote", logObject.getRemote()); + + logger.debug("testLogEntryObject: exit"); } @Test public void testProcess(){ + + logger.debug("testProcess: enter"); + String line = "2015-04-01 09:13:44.947 DEBUG 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved "; im = Mockito.mock(IntegrityMonitor.class); @@ -362,6 +499,8 @@ public class ParseLogTest { fail(); } Mockito.doNothing().when(im).endTransaction(); - ParseLog.process(line, "pap"); + ParseLog.process(line, "pap", LOGTYPE.INFO); + + logger.debug("testProcess: exit"); } }
\ No newline at end of file diff --git a/LogParser/LineTest.txt b/LogParser/src/test/resources/LineTest.txt index 449644219..32ec6cb0e 100644 --- a/LogParser/LineTest.txt +++ b/LogParser/src/test/resources/LineTest.txt @@ -6,4 +6,7 @@ 08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. service Catalina08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. 06-Mar-2015 11:50:06.243 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use 2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.openecomp.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! -2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore
\ No newline at end of file +2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-4||||INFO|||||org.openecomp.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:136)||Last-debug.log-line-Read:17 +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-5||||INFO|||||org.openecomp.xacml.parser.ParseLog$2.lambda$0(ParseLog.java:194)||Last-error.log-line-Read:22 +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-6||||INFO|||||org.openecomp.xacml.parser.ParseLog$3.lambda$0(ParseLog.java:250)||Last-pap-rest.log-line-Read:52
\ No newline at end of file diff --git a/LogParser/LineTest2.txt b/LogParser/src/test/resources/LineTest2.txt index 2243960df..2243960df 100644 --- a/LogParser/LineTest2.txt +++ b/LogParser/src/test/resources/LineTest2.txt diff --git a/LogParser/test_config.properties b/LogParser/src/test/resources/test_config.properties index 5a6a460ba..6512184c8 100644 --- a/LogParser/test_config.properties +++ b/LogParser/src/test/resources/test_config.properties @@ -27,5 +27,5 @@ JDBC_PASSWORD=password jmx_url=service:jmx:rmi:///jndi/rmi://localhost:9996/jmxrmi SERVER=https://localhost:9091/pap/ LOGTYPE=PAP -LOGPATH=C:\\Workspaces\\HealthCheck\\pap-rest.log +LOGPATH=/Workspaces/HealthCheck/pap-rest.log PARSERLOGPATH=IntegrityMonitor.log diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java index b67cb261d..5b4fdeb02 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java @@ -27,8 +27,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -37,6 +37,23 @@ import java.util.Map; import javax.xml.bind.JAXBElement; +import org.apache.commons.io.FilenameUtils; +import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; +import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; + import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; @@ -55,24 +72,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; -import org.apache.commons.io.FilenameUtils; -import org.json.JSONObject; -import org.openecomp.policy.controller.PolicyController; -import org.openecomp.policy.rest.jpa.FunctionDefinition; -import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; - -import com.att.research.xacml.api.AttributeValue; -import org.openecomp.policy.xacml.api.XACMLErrorConstants; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeValue; -import org.openecomp.policy.xacml.util.XACMLPolicyScanner; -import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; -import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; - -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - public class HumanPolicyComponent{ @@ -147,7 +146,7 @@ public class HumanPolicyComponent{ HumanPolicyComponent.htmlProcessor = new HtmlProcessor(HumanPolicyComponent.policyFile, policy); - Path policyPath = FileSystems.getDefault().getPath(policyFile.getAbsolutePath()); + Path policyPath = Paths.get(policyFile.getAbsolutePath()); XACMLPolicyScanner xacmlScanner = new XACMLPolicyScanner(policyPath, htmlProcessor); xacmlScanner.scan(); String html = htmlProcessor.html(); @@ -734,35 +733,36 @@ class HtmlProcessor extends SimpleCallback { } String functionName = getHumanFunction(match.getMatchId()); - - String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + - ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); - AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), - attributeDataType, - attribute.getAttributeId().stringValue()); - this.attributeIdentifiersMap.put(succintIdentifier,ai); - - targetInHuman += "<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "; - - int numAttributes = attribute.getValues().size(); - int count = 0; - for (AttributeValue<?> v: attribute.getValues()) { - count++; - if (v.getValue() instanceof Collection<?>) { - Collection<?> value_s = (Collection<?>) v.getValue(); - int numValues = value_s.size(); - int countValues = 0; - for (Object o : value_s) { - countValues++; - targetInHuman += " <I>" + o + "</I>"; - if (countValues < numValues) { - targetInHuman += ", or"; + if(attribute != null){ + String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); + AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), + attributeDataType, + attribute.getAttributeId().stringValue()); + this.attributeIdentifiersMap.put(succintIdentifier,ai); + + targetInHuman += "<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "; + + int numAttributes = attribute.getValues().size(); + int count = 0; + for (AttributeValue<?> v: attribute.getValues()) { + count++; + if (v.getValue() instanceof Collection<?>) { + Collection<?> value_s = (Collection<?>) v.getValue(); + int numValues = value_s.size(); + int countValues = 0; + for (Object o : value_s) { + countValues++; + targetInHuman += " <I>" + o + "</I>"; + if (countValues < numValues) { + targetInHuman += ", or"; + } + } + } else { + targetInHuman += " <I>" + v.getValue() + "</I>"; + if (count < numAttributes) { + targetInHuman += ", or "; } - } - } else { - targetInHuman += " <I>" + v.getValue() + "</I>"; - if (count < numAttributes) { - targetInHuman += ", or "; } } } diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java deleted file mode 100644 index f5cc5d0fa..000000000 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * 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.components; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Set; - -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.io.IOUtils; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.xacml.api.XACMLErrorConstants; - - - -public class PolicyImportWindow{ - - private static final Logger LOGGER = FlexLogger.getLogger(PolicyImportWindow.class); - private Path newfile = null; - private boolean succeeded = false; - private Boolean superadmin = false; - private ArrayList<String> xacmlFiles = new ArrayList<String>(); - private static FileOutputStream outputFile; - /** - * The constructor should first build the main layout, set the - * composition root and then do any custom initialization. - * - * The constructor will not be automatically regenerated by the - * visual editor. - */ - - public OutputStream receiveUpload(String filename, String mimeType) { - - // - // Create its new full path - // - this.newfile = null; - // - // Does it already exist? - // - if (Files.exists(this.newfile)) { - return null; - } - // - // Try to create the output stream - // - try { - return new FileOutputStream(this.newfile.toFile()); - } catch (FileNotFoundException e) { - LOGGER.error("Failed to create uploaded file", e); - } - return null; - } - - public void Upload(){ - TarArchiveEntry entry = null; - TarArchiveInputStream extractFile = null; - try { - extractFile = new TarArchiveInputStream (new FileInputStream(this.newfile.toFile())); - } catch (FileNotFoundException e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception while Importing Polcies"+e1); - } - //Create a loop to read every single entry in TAR file - try { - while (extractFile!=null && (entry = extractFile.getNextTarEntry()) != null) { - this.superadmin = true; - try{ - copyFileToLocation(extractFile, entry, xacmlFiles, null, superadmin); - }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception while Importing Polcies"+e); - } - } - } catch (IOException e) { - LOGGER.error("Exception Occured"+e); - }finally{ - try { - if(extractFile != null){ - extractFile.close(); - } - } catch (IOException e) { - LOGGER.error("Exception Occured"+e); - } - } - - } - - //Copy files to Directorys - public static void copyFileToLocation(TarArchiveInputStream extractFile, TarArchiveEntry entry, ArrayList<String> xacmlFiles, Set<String> finalScopes, Boolean superadminValue ) throws IOException{ - String individualFiles = ""; - int offset = 0; - outputFile = null; - // Get the name of the file - if(superadminValue){ - individualFiles = entry.getName(); - }else{ - for(int i =0; i< finalScopes.size(); i++){ - if(entry.getName().startsWith(finalScopes.toArray()[i].toString())){ - individualFiles = entry.getName(); - } - } - } - - if(individualFiles.endsWith(".xls")){ - if(individualFiles.contains("\\")){ - individualFiles = individualFiles.replace("\\", File.separator); - }else if(individualFiles.contains("/")){ - individualFiles = individualFiles.replace("/", File.separator); - } - return; - } - - individualFiles = individualFiles.replace("/", File.separator); - individualFiles = individualFiles.replace("\\", File.separator); - - //Create the path with the entry name - - - - // Get Size of the file and create a byte array for the size - byte[] content = new byte[(int) entry.getSize()]; - - offset=0; - LOGGER.info("Size of the File is: " + entry.getSize()); - // Read file from the archive into byte array - extractFile.read(content, offset, content.length - offset); - - // Use IOUtiles to write content of byte array to physical file - IOUtils.write(content,outputFile); - - // Close Output Stream - try { - if(outputFile != null){ - outputFile.close(); - } - } catch (IOException e) { - LOGGER.info("IOException:" +e); - LOGGER.error("Exception Occured"+e); - } - } - - - public Path getUploadedFile() { - if (this.succeeded) { - return this.newfile; - } - return null; - } - -} diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java index bb138d415..ed47fd949 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java @@ -22,7 +22,6 @@ package org.openecomp.policy.controller; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringReader; @@ -42,7 +41,6 @@ import javax.json.Json; import javax.json.JsonReader; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -65,7 +63,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -419,12 +416,6 @@ public class PolicyValidationController extends RestrictedBaseController { } } } - //for continue testing for Dkat, just blocked this validation until fixing it. gw1218 on 3/30/17 - //if (!checkAttributeValues()){ - //responseString.append("<b>Micro Service</b>:<i> Attribute Values Missing" + "</i><br>"); - //valid = false; - //} - }else{ responseString.append("<b>Micro Service</b>:<i> Micro Service is required" + "</i><br>"); valid = false; @@ -576,7 +567,7 @@ public class PolicyValidationController extends RestrictedBaseController { if (!spData.isEmpty()){ SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) spData.get(0); safePolicyWarningData.getMessage(); - value = "Messaage:" + safePolicyWarningData.getMessage(); + value = "Message:" + safePolicyWarningData.getMessage(); } responseString.append("success" + "@#"+ value); } @@ -698,14 +689,19 @@ public class PolicyValidationController extends RestrictedBaseController { // Validation for json. protected static boolean isJSONValid(String data) { + JsonReader jsonReader = null; try { new JSONObject(data); InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); - JsonReader jsonReader = Json.createReader(stream); - System.out.println("Json Value is: " + jsonReader.read().toString() ); + jsonReader = Json.createReader(stream); + LOGGER.info("Json Value is: " + jsonReader.read().toString() ); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Exception Occured While Validating"+e); return false; + }finally{ + if(jsonReader != null){ + jsonReader.close(); + } } return true; } @@ -720,11 +716,8 @@ public class PolicyValidationController extends RestrictedBaseController { XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new XMLErrorHandler()); reader.parse(new InputSource(new StringReader(data))); - } catch (ParserConfigurationException e) { - return false; - } catch (SAXException e) { - return false; - } catch (IOException e) { + } catch (Exception e) { + LOGGER.error("Exception Occured While Validating"+e); return false; } return true; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html index 776663595..070cafc8b 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html @@ -27,9 +27,10 @@ /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html index 4e3a9746f..2eaf98cd9 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html index 4c77cf528..613eb6d4c 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html index 6df44bc24..2c112477d 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java index 287e5c851..85d5659e8 100644 --- a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java @@ -95,14 +95,14 @@ public class ManualClientEndUEB { final JSONObject msg1 = new JSONObject (); msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID); - - try { - pub.send ( "MyPartitionKey", msg1.toString () ); - } catch (IOException e) { - logger.error("Exception Occured"+e); - } - pub.close (); - + if(pub != null){ + try { + pub.send ( "MyPartitionKey", msg1.toString () ); + pub.close (); + } catch (IOException e) { + logger.error("Exception Occured"+e); + } + } } public static void createTopic (String url, String uniquID, List<String> uebURLList){ diff --git a/packages/install/src/files/elk.conf b/packages/install/src/files/elk.conf index 938954ce6..030c162c5 100644 --- a/packages/install/src/files/elk.conf +++ b/packages/install/src/files/elk.conf @@ -1,3 +1,7 @@ # elasticsearch -ELK_JMX_PORT=9995
\ No newline at end of file +ELK_JMX_PORT=9995 + +#Add Numeric IP address below. If elastic search needs to be accessed from other servers. +#The property is used to set for network.hosts in elasticsearch.yml file. +ELK_NETWORK_HOST=127.0.0.1
\ No newline at end of file |