Deterministic startup for resourceSourceMappings 82/72082/4
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Tue, 6 Nov 2018 15:07:17 +0000 (10:07 -0500)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Thu, 8 Nov 2018 19:43:41 +0000 (19:43 +0000)
also fix a typo in property name

resourceSourceMappings is required for loading the resources
(templates, DDs, blueprint), but the bean initializing its values
was getting instantiated after the resources loading process, ending
 up failing loading the resources.

Mkaing DataBaseInitService dependent on the ApplicationRegistrationService
bean will force SpringBoot to have the dependsOn bean loaded before the one
declaring the dependency.

Change-Id: I573a7706212dd411a284ec7b57c9373d7d6ff376
Issue-ID: CCSDK-650
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java
ms/neng/src/main/docker/startService.sh

index fc7410f..d7f22e6 100644 (file)
@@ -27,7 +27,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.PostConstruct;\r
 import java.util.List;\r
 \r
-@Component\r
+@Component(value = "ApplicationRegistrationService")\r
 @SuppressWarnings("unused")\r
 public class ApplicationRegistrationService {\r
     private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class);\r
@@ -35,8 +35,7 @@ public class ApplicationRegistrationService {
     @Value("#{'${resourceSourceMappings}'.split(',')}")\r
     private List<String> resourceSourceMappings;\r
 \r
-    @PostConstruct\r
-    public void register() {\r
+    public ApplicationRegistrationService() {\r
         registerDictionarySources();\r
     }\r
 \r
index cfcf93d..4dc35fd 100644 (file)
@@ -39,6 +39,7 @@ import com.att.eelf.configuration.EELFManager;
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.beans.factory.annotation.Value;\r
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;\r
+import org.springframework.context.annotation.DependsOn;\r
 import org.springframework.core.io.Resource;\r
 import org.springframework.core.io.support.ResourcePatternResolver;\r
 import org.springframework.stereotype.Component;\r
@@ -56,6 +57,7 @@ import java.util.List;
  */\r
 \r
 @Component\r
+@DependsOn(value = "ApplicationRegistrationService")\r
 @ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true")\r
 public class DataBaseInitService {\r
 \r
@@ -86,7 +88,7 @@ public class DataBaseInitService {
      * @param configModelService configModelService\r
      */\r
     public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService,\r
-                               ConfigModelService configModelService) {\r
+        ConfigModelService configModelService) {\r
         this.modelTypeService = modelTypeService;\r
         this.resourceDictionaryService = resourceDictionaryService;\r
         this.configModelService = configModelService;\r
@@ -113,28 +115,26 @@ public class DataBaseInitService {
         try {\r
             Resource[] dataTypefiles = getPathResources(dataTypePath, ".json");\r
             StrBuilder errorBuilder = new StrBuilder();\r
-                for (Resource file : dataTypefiles) {\r
-                    if (file != null) {\r
-                        loadDataType(file, errorBuilder);\r
-                    }\r
+            for (Resource file : dataTypefiles) {\r
+                if (file != null) {\r
+                    loadDataType(file, errorBuilder);\r
                 }\r
+            }\r
 \r
             Resource[] nodeTypefiles = getPathResources(nodeTypePath, ".json");\r
-                       for (Resource file : nodeTypefiles) {\r
-                    if (file != null) {\r
-                        loadNodeType(file, errorBuilder);\r
-                    }\r
+            for (Resource file : nodeTypefiles) {\r
+                if (file != null) {\r
+                    loadNodeType(file, errorBuilder);\r
                 }\r
-\r
+            }\r
 \r
             Resource[] artifactTypefiles = getPathResources(artifactTypePath, ".json");\r
 \r
-                for (Resource file : artifactTypefiles) {\r
-                    if (file != null) {\r
-                        loadArtifactType(file, errorBuilder);\r
-                    }\r
+            for (Resource file : artifactTypefiles) {\r
+                if (file != null) {\r
+                    loadArtifactType(file, errorBuilder);\r
                 }\r
-\r
+            }\r
 \r
             if (!errorBuilder.isEmpty()) {\r
                 log.error(errorBuilder.toString());\r
@@ -146,58 +146,60 @@ public class DataBaseInitService {
 \r
     private void loadResourceDictionary() {\r
         log.info(\r
-                " *************************** loadResourceDictionary **********************");\r
+            " *************************** loadResourceDictionary **********************");\r
         try {\r
             Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, ".json");\r
 \r
-                StrBuilder errorBuilder = new StrBuilder();\r
-                String fileName;\r
-                for (Resource file : dataTypefiles) {\r
-                    try {\r
-                        fileName = file.getFilename();\r
-                        log.trace("Loading : {}", fileName);\r
-                        String definitionContent = getResourceContent(file);\r
-                        ResourceDefinition resourceDefinition =\r
-                                JacksonUtils.readValue(definitionContent, ResourceDefinition.class);\r
-                        if (resourceDefinition != null) {\r
-                            Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition");\r
-                            ResourceDictionary resourceDictionary = new ResourceDictionary();\r
-                            resourceDictionary.setName(resourceDefinition.getName());\r
-                            resourceDictionary.setDefinition(resourceDefinition);\r
-\r
-                            Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing");\r
-                            resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription());\r
-                            resourceDictionary.setDataType(resourceDefinition.getProperty().getType());\r
-                            if(resourceDefinition.getProperty().getEntrySchema() != null){\r
-                                resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType());\r
-                            }\r
-                            resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy());\r
-                            if (StringUtils.isBlank(resourceDefinition.getTags())) {\r
-                                resourceDictionary.setTags(\r
-                                        resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy()\r
-                                                + ", " + resourceDefinition.getUpdatedBy());\r
-\r
-                            } else {\r
-                                resourceDictionary.setTags(resourceDefinition.getTags());\r
-                            }\r
-                            resourceDictionaryService.saveResourceDictionary(resourceDictionary);\r
-\r
-                            log.trace(" Loaded successfully : {}", file.getFilename());\r
+            StrBuilder errorBuilder = new StrBuilder();\r
+            String fileName;\r
+            for (Resource file : dataTypefiles) {\r
+                try {\r
+                    fileName = file.getFilename();\r
+                    log.trace("Loading : {}", fileName);\r
+                    String definitionContent = getResourceContent(file);\r
+                    ResourceDefinition resourceDefinition =\r
+                        JacksonUtils.readValue(definitionContent, ResourceDefinition.class);\r
+                    if (resourceDefinition != null) {\r
+                        Preconditions\r
+                            .checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition");\r
+                        ResourceDictionary resourceDictionary = new ResourceDictionary();\r
+                        resourceDictionary.setName(resourceDefinition.getName());\r
+                        resourceDictionary.setDefinition(resourceDefinition);\r
+\r
+                        Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing");\r
+                        resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription());\r
+                        resourceDictionary.setDataType(resourceDefinition.getProperty().getType());\r
+                        if (resourceDefinition.getProperty().getEntrySchema() != null) {\r
+                            resourceDictionary\r
+                                .setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType());\r
+                        }\r
+                        resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy());\r
+                        if (StringUtils.isBlank(resourceDefinition.getTags())) {\r
+                            resourceDictionary.setTags(\r
+                                resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy()\r
+                                    + ", " + resourceDefinition.getUpdatedBy());\r
+\r
                         } else {\r
-                            throw new BluePrintException("couldn't get dictionary from content information");\r
+                            resourceDictionary.setTags(resourceDefinition.getTags());\r
                         }\r
-                    } catch (Exception e) {\r
-                        errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage());\r
+                        resourceDictionaryService.saveResourceDictionary(resourceDictionary);\r
+\r
+                        log.trace(" Loaded successfully : {}", file.getFilename());\r
+                    } else {\r
+                        throw new BluePrintException("couldn't get dictionary from content information");\r
                     }\r
+                } catch (Exception e) {\r
+                    errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage());\r
                 }\r
-                if (!errorBuilder.isEmpty()) {\r
-                    log.error(errorBuilder.toString());\r
-                }\r
+            }\r
+            if (!errorBuilder.isEmpty()) {\r
+                log.error(errorBuilder.toString());\r
+            }\r
 \r
 \r
         } catch (Exception e) {\r
             log.error(\r
-                    "Failed in Resource dictionary loading", e);\r
+                "Failed in Resource dictionary loading", e);\r
         }\r
     }\r
 \r
@@ -241,7 +243,8 @@ public class DataBaseInitService {
             String nodeKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class);\r
-            Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename()));\r
+            Preconditions\r
+                .checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);\r
             modelType.setDerivedFrom(nodeType.getDerivedFrom());\r
@@ -251,7 +254,7 @@ public class DataBaseInitService {
             modelType.setVersion(nodeType.getVersion());\r
             modelType.setUpdatedBy("System");\r
             modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + ","\r
-                    + nodeType.getDerivedFrom());\r
+                + nodeType.getDerivedFrom());\r
             modelTypeService.saveModel(modelType);\r
             log.trace("Loaded Node Type successfully : {}", file.getFilename());\r
         } catch (Exception e) {\r
@@ -265,7 +268,8 @@ public class DataBaseInitService {
             String dataKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);\r
-            Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename()));\r
+            Preconditions\r
+                .checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
             modelType.setDerivedFrom(dataType.getDerivedFrom());\r
@@ -275,7 +279,7 @@ public class DataBaseInitService {
             modelType.setVersion(dataType.getVersion());\r
             modelType.setUpdatedBy("System");\r
             modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + ","\r
-                    + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
+                + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
             modelTypeService.saveModel(modelType);\r
             log.trace(" Loaded Data Type successfully : {}", file.getFilename());\r
         } catch (Exception e) {\r
@@ -289,7 +293,8 @@ public class DataBaseInitService {
             String dataKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class);\r
-            Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename()));\r
+            Preconditions.checkNotNull(artifactType,\r
+                String.format("failed to get artifact type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
             modelType.setDerivedFrom(artifactType.getDerivedFrom());\r
@@ -299,7 +304,7 @@ public class DataBaseInitService {
             modelType.setVersion(artifactType.getVersion());\r
             modelType.setUpdatedBy("System");\r
             modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + ","\r
-                    + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
+                + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
             modelTypeService.saveModel(modelType);\r
             log.trace("Loaded Artifact Type successfully : {}", file.getFilename());\r
         } catch (Exception e) {\r
index be45897..814fc47 100644 (file)
@@ -29,7 +29,7 @@ APP_ARGS=${APP_ARGS}" -Dpol_req_id="${POL_REQ_ID}
 APP_ARGS=${APP_ARGS}" -Daai_cert_pass="${AAI_CERT_PASS}
 APP_ARGS=${APP_ARGS}" -Daai_cert_path="${AAI_CERT_PATH}
 APP_ARGS=${APP_ARGS}" -Daai_uri="${AAI_URI}
-APP_ARGS=${APP_ARGS}" -Daai_auth="${AAIC_AUTH}
+APP_ARGS=${APP_ARGS}" -Daai_auth="${AAI_AUTH}
 APP_ARGS=${APP_ARGS}" -cp /opt/etc/config"
 
 echo "APP_ARGS ="${APP_ARGS}