Move credential information out of persistence.xml 71/12271/4
authorTemoc Rodriguez <cr056n@att.com>
Wed, 13 Sep 2017 19:23:46 +0000 (12:23 -0700)
committerTemoc Rodriguez <cr056n@att.com>
Thu, 14 Sep 2017 19:31:34 +0000 (12:31 -0700)
Move credential information out of persistence.xml. Define properties
file which will contain the credentials instead. Access db using new
properties file.

Issue-ID: POLICY-55
Change-Id: I01ad0611c053ad4285de2a225fca7920a3b1bc8f
Signed-off-by: Temoc Rodriguez <cr056n@att.com>
controlloop/common/eventmanager/pom.xml
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java
controlloop/common/guard/src/main/resources/operation_history.properties [new file with mode: 0644]

index a3227cb..93ff56c 100644 (file)
                        <version>2.5</version>
                        <scope>provided</scope>
                </dependency>
+               <dependency>
+                       <groupId>com.att.research.xacml</groupId>
+                       <artifactId>xacml</artifactId>
+                       <version>1.0.0</version>
+                       <scope>provided</scope>
+               </dependency>
                <dependency>
                        <groupId>org.onap.policy.drools-applications</groupId>
                        <artifactId>actorServiceProvider</artifactId>
index 7751a41..503a6fb 100644 (file)
 
 package org.onap.policy.controlloop.eventmanager;
 
+import java.io.InputStream;
 import java.io.Serializable;
 import java.sql.Timestamp;
 import java.time.Instant;
 import java.util.AbstractMap;
 import java.util.LinkedList;
+import java.util.Properties;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Persistence;
@@ -37,6 +39,7 @@ import org.onap.policy.controlloop.ControlLoopException;
 import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
+import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
 import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider;
 import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.controlloop.policy.PolicyResult;
@@ -44,7 +47,6 @@ import org.onap.policy.controlloop.actor.so.SOActorServiceProvider;
 import org.onap.policy.so.SOResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
 
 public class ControlLoopOperationManager implements Serializable {
 
@@ -216,10 +218,10 @@ public class ControlLoopOperationManager implements Serializable {
                case "SO":
                        SOActorServiceProvider SOAsp = new SOActorServiceProvider();
                        this.operationRequest = SOAsp.constructRequest((VirtualControlLoopEvent)onset, operation.operation, this.policy);
-                       
+
                        // Save the operation
                        this.currentOperation = operation;
-                       
+
                        return operationRequest;
                case "VFC":
                         this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy);
@@ -364,9 +366,9 @@ public class ControlLoopOperationManager implements Serializable {
                                }
                                return PolicyResult.FAILURE;
                        }
-                       
+
                }
-               
+
                return null;
        }
 
@@ -512,13 +514,24 @@ public class ControlLoopOperationManager implements Serializable {
 
        private void    storeOperationInDataBase(){
 
+               // DB Properties
+               Properties props = new Properties();
+               try (InputStream is = org.onap.policy.guard.PIPEngineGetHistory.class.getResourceAsStream(org.onap.policy.guard.PIPEngineGetHistory.OPS_HIST_PROPS_LOC)){
+                       props.load(is);
+               } catch (Exception ex) {
+                       logger.error("getCountFromDB threw: ", ex);
+                       return;
+               }
                String OpsHistPU = System.getProperty("OperationsHistoryPU");
                if(OpsHistPU == null || !OpsHistPU.equals("TestOperationsHistoryPU")){
                        OpsHistPU = "OperationsHistoryPU";
                }
+               else{
+                       props.clear();
+               }
                EntityManager em;
                try{
-                       em = Persistence.createEntityManagerFactory(OpsHistPU).createEntityManager();
+                       em = Persistence.createEntityManagerFactory(OpsHistPU, props).createEntityManager();
                }catch(Exception e){
                        logger.error("storeOperationInDataBase threw: ", e);
                        return;
index 27c64b6..827e256 100644 (file)
                <properties>
                        <property name="eclipselink.ddl-generation" value="create-tables" />
                        <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
-                       <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
-                       <property name="javax.persistence.jdbc.user" value="root" />
-                       <property name="javax.persistence.jdbc.password" value="aaaa" />
                        <property name="eclipselink.logging.level" value="WARNING" />
+                       <!-- Credential and URL properties located in /guard/src/main/resources/operation_history.properties -->
                </properties>
        </persistence-unit>
-
-       
 </persistence>
index 3e93bd7..6be59d6 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.policy.guard;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.sql.Timestamp;
 import java.util.Collection;
@@ -64,7 +66,8 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
 
        private static final Logger logger = LoggerFactory.getLogger(PIPEngineGetHistory.class);
 
-       public static final String DEFAULT_DESCRIPTION          = "PIP for retrieving Operations History from DB";
+       public static final String DEFAULT_DESCRIPTION  = "PIP for retrieving Operations History from DB";
+       public static final String OPS_HIST_PROPS_LOC   = "/operation_history.properties";
 
        //
        // Base issuer string. The issuer in the policy will also contain time window information
@@ -305,13 +308,25 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{
 
        private static int getCountFromDB(String actor, String operation, String target, String timeWindow){
 
+               // DB Properties
+               Properties props = new Properties();
+               try (InputStream is = org.onap.policy.guard.PIPEngineGetHistory.class.getResourceAsStream(OPS_HIST_PROPS_LOC)){
+                       props.load(is);
+               } catch (IOException ex) {
+                       logger.error("getCountFromDB threw: ", ex);
+                       return -1;
+               }
+
                EntityManager em = null;
                String OpsHistPU = System.getProperty("OperationsHistoryPU");
                if(OpsHistPU == null || !OpsHistPU.equals("TestOperationsHistoryPU")){
                        OpsHistPU = "OperationsHistoryPU";
                }
+               else{
+                       props.clear();
+               }
                try{
-                       em = Persistence.createEntityManagerFactory(OpsHistPU).createEntityManager();
+                       em = Persistence.createEntityManagerFactory(OpsHistPU, props).createEntityManager();
                }catch(Exception ex){
                        logger.error("PIP thread got Exception. Can't connect to Operations History DB -- {}", OpsHistPU);
                        logger.error("getCountFromDB threw: ", ex);
diff --git a/controlloop/common/guard/src/main/resources/operation_history.properties b/controlloop/common/guard/src/main/resources/operation_history.properties
new file mode 100644 (file)
index 0000000..8c374a8
--- /dev/null
@@ -0,0 +1,26 @@
+#/*-
+# * ============LICENSE_START=======================================================
+# * guard
+# * ================================================================================
+# * 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=========================================================
+# */
+
+#
+# Maria DB Operation History Credentials
+#
+javax.persistence.jdbc.user=root
+javax.persistence.jdbc.password=aaaa
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/policy