Merge "Migrate policy-engine docs"
authorPamela Dragosh <pdragosh@research.att.com>
Mon, 24 Feb 2020 15:04:47 +0000 (15:04 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 24 Feb 2020 15:04:47 +0000 (15:04 +0000)
.gitignore
BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java
LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java
ONAP-SDK-APP/pom.xml
POLICY-SDK-APP/pom.xml
POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java
packages/docker/src/main/docker/Dockerfile

index 7df831f..dbc83af 100644 (file)
@@ -4,7 +4,12 @@
 .classpath
 .jupiter
 .pydevproject
-.idea
+
+# IntelliJ files
+.idea/
+**/*.iml
+overlays/
+
 target
 .metadata/
 ASTRAGateway/policyEngineLog.log
index 45f6585..8826d56 100644 (file)
@@ -256,8 +256,8 @@ public class BrmsPush {
             repUrlList = new ArrayList<>();
             repUrlList.add(repUrl);
         }
-        repUserName = config.getProperty("repositoryUsername");
-        repPassword = PeCryptoUtils.decrypt(config.getProperty("repositoryPassword"));
+        repUserName = getValue(config.getProperty("repositoryUsername"));
+        repPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("repositoryPassword")));
         if (repUserName == null || repPassword == null) {
             LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
                     + "repostoryUserName and respositoryPassword properties are required.");
@@ -367,6 +367,13 @@ public class BrmsPush {
 
     }
 
+    private String getValue(final String value) {
+        if (value != null && value.matches("[$][{].*[}]$")) {
+            return System.getenv(value.substring(2, value.length() - 1));
+        }
+        return value;
+    }
+
     private static void setBackupMonitor(final BackUpMonitor instance) {
         bm = instance;
     }
index f12522a..77aafdf 100644 (file)
@@ -884,11 +884,11 @@ public class ParseLog {
             setLogFileProperties(splitString);
 
             jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
-            jdbcUser = config.getProperty("JDBC_USER");
+            jdbcUser = getValue(config.getProperty("JDBC_USER"));
             jdbcDriver = config.getProperty("JDBC_DRIVER");
 
             PeCryptoUtils.initAesKey(config.getProperty(PROP_AES_KEY));
-            jdbcPassword = PeCryptoUtils.decrypt(config.getProperty("JDBC_PASSWORD"));
+            jdbcPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("JDBC_PASSWORD")));
             config.setProperty("javax.persistence.jdbc.password", jdbcPassword);
             return config;
 
@@ -902,6 +902,13 @@ public class ParseLog {
         return null;
     }
 
+    private static String getValue(final String value) {
+        if (value != null && value.matches("[$][{].*[}]$")) {
+            return System.getenv(value.substring(2, value.length() - 1));
+        }
+        return value;
+    }
+
     public static Connection getDbConnection() {
         return dbConnection(jdbcDriver, jdbcUrl, jdbcUser, jdbcPassword);
     }
index 67214ac..e694f7e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -549,6 +549,9 @@ public class PolicyDbDaoTransactionInstance implements PolicyDbDaoTransaction {
 
             IOUtils.closeQuietly(policyXmlStream);
             if (PolicyDbDao.isJunit()) {
+                if (policyDataString != null) {
+                    logger.warn("isJUnit will overwrite policyDataString");
+                }
                 // Using parentPath object to set policy data.
                 policyDataString = policy.policyAdapter.getParentPath();
             }
index 29b2440..f2f2e8d 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -618,7 +618,13 @@ public class PolicyCreation extends AbstractPolicyCreation {
         } catch (Exception e) {
             LOGGER.error("Exception Occured : " + e.getMessage(), e);
             body = ERROR;
-            response.addHeader(ERROR, e.getMessage());
+            //
+            // Because we are catching any old exception instead of a dedicated exception,
+            // its possible the e.getMessage() returns a null value. You cannot add a header
+            // to the response with a null value, it will throw an exception. This is something
+            // this is undesirable.
+            //
+            response.addHeader(ERROR, (e.getMessage() == null ? "missing exception message" : e.getMessage()));
             response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
         }
         return new ResponseEntity<>(body, status);
index 0c029b4..953fff3 100644 (file)
 
 package org.onap.policy.pap.xacml.rest.policycontroller;
 
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
-
-import com.mockrunner.mock.web.MockHttpServletRequest;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.onap.policy.pap.xacml.rest.components.PolicyDbDao;
+import org.onap.policy.pap.xacml.rest.components.PolicyDbDaoTransaction;
 import org.onap.policy.rest.adapter.PolicyRestAdapter;
 import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.PolicyDbDaoEntity;
 import org.onap.policy.rest.jpa.PolicyVersion;
+import org.powermock.reflect.Whitebox;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.http.converter.HttpMessageNotReadableException;
 import org.springframework.mock.web.MockHttpServletResponse;
+import com.mockrunner.mock.web.MockHttpServletRequest;
 
 public class PolicyCreationTest {
     @Test
@@ -57,7 +64,7 @@ public class PolicyCreationTest {
         Exception cause = new Exception("oops");
         HttpMessageNotReadableException exception = new HttpMessageNotReadableException("oops", cause);
         assertEquals(HttpStatus.BAD_REQUEST,
-            creation.messageNotReadableExceptionHandler(req, exception).getStatusCode());
+                creation.messageNotReadableExceptionHandler(req, exception).getStatusCode());
 
         HttpServletResponse response = new MockHttpServletResponse();
         PolicyRestAdapter policyData = new PolicyRestAdapter();
@@ -65,53 +72,81 @@ public class PolicyCreationTest {
         policyData.setConfigPolicyType("ClosedLoop_Fault");
         policyData.setDomainDir("domain");
         policyData.setPolicyName("policyname");
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        ResponseEntity<String> responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         version.setHigherVersion(1);
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setEditPolicy(true);
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setEditPolicy(false);
         version.setHigherVersion(0);
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setEditPolicy(true);
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         version.setHigherVersion(1);
         policyData.setConfigPolicyType("Firewall Config");
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setConfigPolicyType("BRMS_Raw");
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
+
         policyData.setConfigPolicyType("BRMS_Param");
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
+
         policyData.setConfigPolicyType("Base");
         Mockito.when(policyData.getRuleData()).thenReturn(new LinkedHashMap<>());
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+
+        SessionFactory mockSessionFactory = Mockito.mock(SessionFactory.class);
+        Session mockSession = Mockito.mock(Session.class);
+        Criteria mockCriteria = Mockito.mock(Criteria.class);
+        List<?> policyDbDaoEntityList = new LinkedList<>();
+
+        Mockito.when(mockSessionFactory.openSession()).thenReturn(mockSession);
+        Mockito.when(mockSession.createCriteria(PolicyDbDaoEntity.class)).thenReturn(mockCriteria);
+        Mockito.when(mockCriteria.list()).thenReturn(policyDbDaoEntityList);
+        Whitebox.setInternalState(PolicyDbDao.class, "sessionfactory", mockSessionFactory);
+
+        PolicyDbDao mockPolicyDbDao = Mockito.mock(PolicyDbDao.class);
+        PolicyDbDaoTransaction mockTransaction = Mockito.mock(PolicyDbDaoTransaction.class);
+        Mockito.when(mockPolicyDbDao.getNewTransaction()).thenReturn(mockTransaction);
+
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
+
         policyData.setConfigPolicyType("ClosedLoop_PM");
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
+
         policyData.setConfigPolicyType("Micro Service");
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
+
         policyData.setConfigPolicyType("Optimization");
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setPolicyType("Action");
-        List<Object> choices = new ArrayList<Object>();
+        List<Object> choices = new ArrayList<>();
         policyData.setRuleAlgorithmschoices(choices);
-        assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException();
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
 
         policyData.setPolicyType("Decision");
-        List<Object> settings = new ArrayList<Object>();
+        List<Object> settings = new ArrayList<>();
         policyData.setSettings(settings);
-        assertThatThrownBy(() -> creation.savePolicy(policyData, response))
-            .isInstanceOf(IllegalArgumentException.class);
+        responseEntity = creation.savePolicy(policyData, response);
+        assertThat(responseEntity).isNotNull();
     }
 }
index c3c595c..45d105a 100644 (file)
                     <groupId>org.onap.portal.sdk</groupId>
                     <artifactId>epsdk-core</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-expression</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
             <artifactId>commons-collections</artifactId>
             <version>3.2.2</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-aop</artifactId>
+            <version>${springframework.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-orm</artifactId>
+            <version>${springframework.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.onap.portal.sdk</groupId>
             <artifactId>epsdk-core</artifactId>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-webmvc</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-aop</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-orm</artifactId>
+                </exclusion>
                 <exclusion>
                     <groupId>xalan</groupId>
                     <artifactId>xalan</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.aspectj</groupId>
+                    <artifactId>aspectjrt</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.aspectj</groupId>
+                    <artifactId>aspectjweaver</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
         </dependency>
         <!-- Spring -->
         <!-- Added dependencies to fix issue with duplicate jars of different versions -->
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjrt</artifactId>
+            <version>1.8.14</version>
+        </dependency>
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <version>1.8.14</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-expression</artifactId>
+            <version>${springframework.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
             <version>${springframework.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-expression</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
             <version>${springframework.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-expression</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <!-- bridge to implement commons-logging using slf4j -->
         <dependency>
index 14179fa..6c66bd7 100644 (file)
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-webmvc</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-aop</artifactId>
+                </exclusion>
                 <exclusion>
                     <groupId>xalan</groupId>
                     <artifactId>xalan</artifactId>
                     <groupId>xml-apis</groupId>
                     <artifactId>xml-apis</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.hibernate</groupId>
+                    <artifactId>hibernate-core</artifactId>
+                </exclusion>
+                  <exclusion>
+                    <groupId>org.aspectj</groupId>
+                    <artifactId>aspectjrt</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.aspectj</groupId>
+                    <artifactId>aspectjweaver</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-expression</artifactId>
+             <version>${springframework.version}</version>
+        </dependency>
+              <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjrt</artifactId>
+            <version>1.8.14</version>
+        </dependency>
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <version>1.8.14</version>
+        </dependency>
         <!-- Spring -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
+            <version>${springframework.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>commons-logging</groupId>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
+            <version>${springframework.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-expression</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
+            <version>${springframework.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-expression</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
                     <groupId>xml-apis</groupId>
                     <artifactId>xml-apis</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-orm</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.springframework</groupId>
+                    <artifactId>spring-test</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>
         <dependency>
             <groupId>org.apache.poi</groupId>
             <artifactId>poi</artifactId>
-            <version>3.17</version>
+            <version>4.1.1</version>
         </dependency>
         <dependency>
             <groupId>org.apache.poi</groupId>
             <artifactId>poi-ooxml</artifactId>
-            <version>3.17</version>
+            <version>4.1.1</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.apache.xmlbeans</groupId>
index a12eac3..4831802 100644 (file)
@@ -44,9 +44,9 @@ decryption_key                                  = AGLDdG4D04BKm2IxIWEr8o==
 ##########################################################################
 #Mysql
 db.driver = org.mariadb.jdbc.Driver
-db.connectionURL = jdbc:mariadb://localhost:3306/onapsdk1707
+db.connectionURL = jdbc:mariadb://localhost:3306/onap_sdk
 db.userName = root
-db.password = 
+db.password =
 db.hib.dialect = org.hibernate.dialect.MySQLDialect
 db.min_pool_size = 5
 db.max_pool_size = 10
index b2e1b92..6c47b39 100644 (file)
@@ -69,7 +69,7 @@ import org.powermock.reflect.Whitebox;
 import org.springframework.mock.web.MockHttpServletResponse;
 
 @RunWith(PowerMockRunner.class)
-@PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "com.sun.org.apache.xalan.*"})
 public class PolicyRestControllerTest {
 
     private String clRequestString;
index d59e9d7..c257fd3 100644 (file)
@@ -13,9 +13,7 @@ RUN apt update && \
     apt-get install -y netcat && \
     apt-get install -y cron && \
     mkdir -p /tmp/policy-install ${POLICY_LOGS} && \
-    chown policy:policy /tmp/policy-install ${POLICY_LOGS} && \
-    rmdir ${POLICY_HOME}/etc/ssl && \
-    rmdir ${POLICY_HOME}/etc
+    chown policy:policy /tmp/policy-install ${POLICY_LOGS}
 
 WORKDIR /tmp/policy-install