Rework config 05/34505/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Wed, 7 Mar 2018 12:07:47 +0000 (13:07 +0100)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Wed, 7 Mar 2018 12:07:47 +0000 (13:07 +0100)
Rework the clds-user json and clds-controller json config

Issue-ID: CLAMP-136
Change-Id: I5393394d7d878001dd9b5773051f38e927173d5d
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
extra/docker/clamp/clamp.env
src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java
src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java
src/main/java/org/onap/clamp/clds/service/CldsService.java
src/main/resources/application.properties
src/test/resources/application.properties

index 8c4375b..729941a 100644 (file)
@@ -1,2 +1,2 @@
 ### Be careful, this must be in one line only ###
-SPRING_APPLICATION_JSON={"spring.datasource.cldsdb.url":"jdbc:mariadb:sequential://db:3306/cldsdb4?autoReconnect=true&connectTimeout=10000&socketTimeout=10000&retriesAllDown=3","org.onap.clamp.config.files.cldsPolicyConfig":"classpath:/clds/clds-policy-config.properties","org.onap.clamp.config.files.sdcController":"classpath:/clds/sdc-controllers-config.json"}
\ No newline at end of file
+SPRING_APPLICATION_JSON={"spring.datasource.cldsdb.url":"jdbc:mariadb:sequential://db:3306/cldsdb4?autoReconnect=true&connectTimeout=10000&socketTimeout=10000&retriesAllDown=3","clamp.config.files.sdcController":"classpath:/clds/sdc-controllers-config.json","clamp.config.files.cldsPolicyConfig":"classpath:/clds/clds-policy-config.properties"}
\ No newline at end of file
index 5160d04..144a48c 100644 (file)
@@ -71,7 +71,7 @@ public class PolicyClient {
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
     protected static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
     protected static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
-    @Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
+    @Value("${clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
     protected String cldsPolicyConfigFile;
     @Autowired
     protected ApplicationContext appContext;
index 15d06b9..bb1b9d1 100644 (file)
@@ -27,11 +27,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.io.IOUtils;
 import org.onap.clamp.clds.exception.CldsUsersException;
 import org.onap.clamp.clds.service.CldsUser;
 
 public class CldsUserJsonDecoder {
+
     /**
      * This method decodes the JSON file provided to a CldsUser Array. The
      * stream is closed after this call, this is not possible to reuse it.
@@ -42,10 +45,18 @@ public class CldsUserJsonDecoder {
      *         JSON file
      */
     public static CldsUser[] decodeJson(InputStream cldsUsersFile) {
+        try {
+            return decodeJson(IOUtils.toString(cldsUsersFile, StandardCharsets.UTF_8.name()));
+        } catch (IOException e) {
+            throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e);
+        }
+    }
+
+    public static CldsUser[] decodeJson(String cldsUsersString) {
         try {
             // the ObjectMapper readValue method closes the stream no need to do
             // it
-            return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class);
+            return new ObjectMapper().readValue(cldsUsersString, CldsUser[].class);
         } catch (IOException e) {
             throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e);
         }
index c99dd21..5b54904 100644 (file)
@@ -56,7 +56,7 @@ public class SdcControllersConfiguration {
     /**
      * The file name that will be loaded by Spring.
      */
-    @Value("${org.onap.clamp.config.files.sdcController:'classpath:/clds/sdc-controllers-config.json'}")
+    @Value("${clamp.config.files.sdcController:'classpath:/clds/sdc-controllers-config.json'}")
     protected String sdcControllerFile;
     /**
      * The root of the JSON.
index 51bd695..d9e5ef2 100644 (file)
@@ -28,12 +28,12 @@ import com.att.eelf.configuration.EELFManager;
 
 import java.io.IOException;
 
+import org.onap.clamp.clds.config.ClampProperties;
 import org.onap.clamp.clds.config.CldsUserJsonDecoder;
 import org.onap.clamp.clds.exception.CldsUsersException;
 import org.onap.clamp.clds.service.CldsUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -44,7 +44,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
 /**
  * This class is used to enable the HTTP authentication to login. It requires a
  * specific JSON file containing the user definition
- * (classpath:etc/config/clds/clds-users.json).
+ * (classpath:clds/clds-users.json).
  */
 @Configuration
 @EnableWebSecurity
@@ -54,9 +54,7 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSecurityConfigUsers.class);
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
     @Autowired
-    private ApplicationContext appContext;
-    @Value("${org.onap.clamp.config.files.cldsUsers:'classpath:etc/config/clds/clds-users.json'}")
-    private String cldsUsersFile;
+    private ClampProperties refProp;
     @Value("${clamp.config.security.permission.type.cl:permission-type-cl}")
     private String cldsPersmissionTypeCl;
     @Value("${CLDS_PERMISSION_INSTANCE:dev}")
@@ -89,7 +87,7 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
             CldsUser[] usersList = loadUsers();
             // no users defined
             if (null == usersList) {
-                logger.warn("No users defined. Users should be defined under " + cldsUsersFile);
+                logger.warn("No users defined. Users should be defined under clds-users.json");
                 return;
             }
             for (CldsUser user : usersList) {
@@ -107,14 +105,11 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
      * CldsUser.
      * 
      * @return The array of CldsUser
+     * @throws IOException
+     *             In case of the file is not found
      */
-    private CldsUser[] loadUsers() {
-        try {
-            logger.info("Load from clds-users.properties");
-            return CldsUserJsonDecoder.decodeJson(appContext.getResource(cldsUsersFile).getInputStream());
-        } catch (IOException e) {
-            logger.error("Unable to decode the User Json file", e);
-            throw new CldsUsersException("Load from clds-users.properties", e);
-        }
+    private CldsUser[] loadUsers() throws IOException {
+        logger.info("Load from clds-users.properties");
+        return CldsUserJsonDecoder.decodeJson(refProp.getFileContent("files.cldsUsers"));
     }
 }
index 2968f60..9bd9c41 100644 (file)
@@ -472,19 +472,19 @@ public class CldsService extends SecureServiceBase {
             throw new CldsConfigException(e.getMessage(), e);
         }
         // refresh model info from db (get fresh event info)
-        CldsModel retreivedModel = CldsModel.retrieve(cldsDao, modelName, false);
+        CldsModel retrievedModel = CldsModel.retrieve(cldsDao, modelName, false);
         if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
                 || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
                 || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
             // To verify inventory status and modify model status to distribute
-            dcaeInventoryServices.setEventInventory(retreivedModel, getUserId());
-            retreivedModel.save(cldsDao, getUserId());
+            dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
+            retrievedModel.save(cldsDao, getUserId());
         }
         // audit log
         LoggingUtils.setTimeContext(startTime, new Date());
         LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName());
         auditLogger.info("Process model action completed");
-        return retreivedModel;
+        return retrievedModel;
     }
 
     /**
@@ -853,7 +853,7 @@ public class CldsService extends SecureServiceBase {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public CldsModel unDeployModel(@PathParam("action") String action, @PathParam("modelName") String modelName,
-            @QueryParam("test") String test, CldsModel model) throws IOException {
+            @QueryParam("test") String test, CldsModel model) {
         Date startTime = new Date();
         LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
         String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
index 2c3537d..3d56725 100644 (file)
@@ -106,10 +106,10 @@ async.core.pool.size=10
 async.max.pool.size=20\r
 async.queue.capacity=500\r
 \r
-org.onap.clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties\r
-org.onap.clamp.config.files.cldsUsers=classpath:/clds/clds-users.json\r
+clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties\r
+clamp.config.files.cldsUsers=classpath:/clds/clds-users.json\r
 clamp.config.files.globalProperties=classpath:/clds/templates/globalProperties.json\r
-org.onap.clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json\r
+clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json\r
 \r
 # Properties for Clamp\r
 # DCAE request build properties\r
index e81e093..adcd4d9 100644 (file)
@@ -106,10 +106,10 @@ async.core.pool.size=10
 async.max.pool.size=20\r
 async.queue.capacity=500\r
 \r
-org.onap.clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties\r
-org.onap.clamp.config.files.cldsUsers=classpath:/clds/clds-users.json\r
+clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties\r
+clamp.config.files.cldsUsers=classpath:/clds/clds-users.json\r
 clamp.config.files.globalProperties=classpath:/clds/templates/globalProperties.json\r
-org.onap.clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json\r
+clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json\r
 \r
 # Properties for Clamp\r
 # DCAE request build properties\r