diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-07 13:07:47 +0100 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-07 13:07:47 +0100 |
commit | 02490407e31862b68832185cc7e299f6d7dece96 (patch) | |
tree | f89b2d44f9484a05ecbafd37507b2c207f213e48 /src/main | |
parent | 32eaf1e97f17a9d7a7b304fdc2b2be00c5830434 (diff) |
Rework config
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>
Diffstat (limited to 'src/main')
6 files changed, 31 insertions, 25 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java index 5160d04a..144a48c9 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java @@ -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; diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java index 15d06b9a..bb1b9d13 100644 --- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java +++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java @@ -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. @@ -43,9 +46,17 @@ public class CldsUserJsonDecoder { */ 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); } diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java index c99dd21f..5b549042 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java @@ -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. diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java index 51bd6954..d9e5ef29 100644 --- a/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java +++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsSecurityConfigUsers.java @@ -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")); } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 2968f60a..9bd9c417 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -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(), diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2c3537d5..3d56725d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -106,10 +106,10 @@ async.core.pool.size=10 async.max.pool.size=20
async.queue.capacity=500
-org.onap.clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties
-org.onap.clamp.config.files.cldsUsers=classpath:/clds/clds-users.json
+clamp.config.files.cldsPolicyConfig=classpath:/clds/clds-policy-config.properties
+clamp.config.files.cldsUsers=classpath:/clds/clds-users.json
clamp.config.files.globalProperties=classpath:/clds/templates/globalProperties.json
-org.onap.clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json
+clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json
# Properties for Clamp
# DCAE request build properties
|