@@ -99,13 +99,14 @@ def open(self):
99
99
# initialize globals
100
100
101
101
# The following 3 globals mush match prefix hard coded in startServer.sh
102
- self .CUSTOM_PREFIX_JDBC = 'Custom-Sit-Cfg-JDBC--'
103
- self .CUSTOM_PREFIX_JMS = 'Custom-Sit-Cfg-JMS--'
104
- self .CUSTOM_PREFIX_CFG = 'Custom-Sit-Cfg-CFG--'
102
+ self .CUSTOM_PREFIX_JDBC = 'Sit-Cfg-JDBC--'
103
+ self .CUSTOM_PREFIX_JMS = 'Sit-Cfg-JMS--'
104
+ self .CUSTOM_PREFIX_WLDF = 'Sit-Cfg-WLDF--'
105
+ self .CUSTOM_PREFIX_CFG = 'Sit-Cfg-CFG--'
105
106
106
107
self .INTROSPECT_HOME = '/tmp/introspect/' + self .DOMAIN_UID
107
108
self .TOPOLOGY_FILE = self .INTROSPECT_HOME + '/topology.yaml'
108
- self .CM_FILE = self .INTROSPECT_HOME + '/' + self .CUSTOM_PREFIX_CFG + 'situational-config.xml'
109
+ self .CM_FILE = self .INTROSPECT_HOME + '/' + self .CUSTOM_PREFIX_CFG + 'introspector- situational-config.xml'
109
110
self .BOOT_FILE = self .INTROSPECT_HOME + '/boot.properties'
110
111
self .USERCONFIG_FILE = self .INTROSPECT_HOME + '/userConfigNodeManager.secure'
111
112
self .USERKEY_FILE = self .INTROSPECT_HOME + '/userKeyNodeManager.secure'
@@ -710,38 +711,21 @@ def __init__(self, env):
710
711
self .env = env
711
712
self .macroMap = {}
712
713
self .macroStr = ''
713
- self .jdbcModuleMap = {}
714
- self .jdbcModuleStr = ''
715
- self .jmsModuleMap = {}
716
- self .jmsModuleStr = ''
714
+ self .moduleMap = {}
715
+ self .moduleStr = ''
717
716
718
717
# Populate macro map with known secrets and env vars, log them
719
718
# env macro format: 'env:<somename>'
720
719
# plain text secret macro: 'secret:<somename>'
721
720
# encrypted secret macro: 'secret:<somename>:encrypt'
722
721
723
- # TODO factor common part of these two blocks into a helper fn:
724
-
725
722
if os .path .exists (self .env .CUSTOM_SECRET_ROOT ):
726
- for the_secret in os .listdir (self .env .CUSTOM_SECRET_ROOT ):
727
- the_secret_path = os .path .join (self .env .CUSTOM_SECRET_ROOT , the_secret )
728
- for the_file in os .listdir (the_secret_path ):
729
- the_file_path = os .path .join (the_secret_path , the_file )
730
- if os .path .isfile (the_file_path ):
731
- val = self .env .readFile (the_file_path )
732
- key = 'secret:' + the_secret + "." + the_file
733
- self .macroMap [key ] = val
734
- self .macroMap [key + ':encrypt' ] = self .env .encrypt (val )
735
-
736
- for the_file in os .listdir (self .env .ADMIN_SECRET_PATH ):
737
- the_file_path = os .path .join (self .env .ADMIN_SECRET_PATH , the_file )
738
- if os .path .isfile (the_file_path ):
739
- val = self .env .readFile (the_file_path )
740
- key = 'secret:' + self .env .ADMIN_SECRET_NAME + "." + the_file
741
- self .macroMap [key ] = val
742
- self .macroMap [key + ':encrypt' ] = self .env .encrypt (val )
723
+ for secret_name in os .listdir (self .env .CUSTOM_SECRET_ROOT ):
724
+ secret_path = os .path .join (self .env .CUSTOM_SECRET_ROOT , secret_name )
725
+ self .addSecretsFromDirectory (secret_path , secret_name )
743
726
744
- self .macroMap ['env:DOMAIN_UID' ] = self .env .DOMAIN_UID
727
+ self .addSecretsFromDirectory (self .env .ADMIN_SECRET_PATH ,
728
+ self .env .ADMIN_SECRET_NAME )
745
729
746
730
self .macroMap ['env:DOMAIN_UID' ] = self .env .DOMAIN_UID
747
731
self .macroMap ['env:DOMAIN_HOME' ] = self .env .DOMAIN_HOME
@@ -759,112 +743,155 @@ def __init__(self, env):
759
743
760
744
# Populate module maps with known module files and names, log them
761
745
762
- # TODO factor common part of these two blocks into a helper fn:
746
+ self .jdbcModuleStr = self .buildModuleTable (
747
+ 'jdbc' ,
748
+ self .env .getDomain ().getJDBCSystemResources (),
749
+ self .env .CUSTOM_PREFIX_JDBC )
763
750
764
- for module in self .env .getDomain ().getJMSSystemResources ():
765
- mfile = module .getDescriptorFileName ()
766
- mname = module .getName ()
767
- self .jmsModuleMap [mfile ] = mname
768
- if self .jmsModuleStr :
769
- self .jmsModuleStr += ', '
770
- self .jmsModuleStr += '(name=' + mname + ', file=' + mfile + ')'
751
+ self .jmsModuleStr = self .buildModuleTable (
752
+ 'jms' ,
753
+ self .env .getDomain ().getJMSSystemResources (),
754
+ self .env .CUSTOM_PREFIX_JMS )
771
755
772
- trace ('Available JMS modules: ' + self .jmsModuleStr )
756
+ self .wldfModuleStr = self .buildModuleTable (
757
+ 'wldf' ,
758
+ self .env .getDomain ().getWLDFSystemResources (),
759
+ self .env .CUSTOM_PREFIX_WLDF )
760
+
761
+ trace ('Available modules: ' + self .moduleStr )
762
+
763
+
764
+ def addSecretsFromDirectory (self , secret_path , secret_name ):
765
+ for the_file in os .listdir (secret_path ):
766
+ the_file_path = os .path .join (secret_path , the_file )
767
+ if os .path .isfile (the_file_path ):
768
+ val = self .env .readFile (the_file_path )
769
+ key = 'secret:' + secret_name + "." + the_file
770
+ self .macroMap [key ] = val
771
+ self .macroMap [key + ':encrypt' ] = self .env .encrypt (val )
772
+
773
+
774
+ def buildModuleTable (self , moduleTypeStr , moduleResourceBeans , customPrefix ):
775
+
776
+ # - Populate global 'moduleMap' with key of 'moduletype-modulename.xml'
777
+ # andvalue of 'module system resource file name' + '-situational-config.xml'.
778
+ # - Populate global 'moduleStr' with list of known modules.
779
+ # - Generate validation error if a module is not located in a config subdirectory
780
+ # that matches its type (e.g. jdbc modules are expected to be in directory 'jdbc').
781
+
782
+ if self .moduleStr :
783
+ self .moduleStr += ', '
784
+ self .moduleStr += 'type.' + moduleTypeStr + "=("
785
+ firstModule = true
786
+
787
+ for module in moduleResourceBeans :
773
788
774
- for module in self .env .getDomain ().getJDBCSystemResources ():
775
- mfile = module .getDescriptorFileName ()
776
789
mname = module .getName ()
777
- self .jdbcModuleMap [mfile ] = mname
778
- if self .jdbcModuleStr :
779
- self .jdbcModuleStr += ', '
780
- self .jdbcModuleStr += '(name=' + mname + ', file=' + mfile + ')'
790
+ mfile = module .getDescriptorFileName ()
781
791
782
- trace ('Available JDBC modules: ' + self .jdbcModuleStr )
792
+ if os .path .dirname (mfile ) != moduleTypeStr :
793
+ self .env .addError (
794
+ "Error, the operator expects module files of type '" + moduleTypeStr + "'"
795
+ + " to be located in directory '" + moduleTypeStr + "/'"
796
+ + ", but the " + moduleTypeStr + " system resource module '" + mname + "'"
797
+ + " is configured with DescriptorFileName='" + mfile + "'." )
798
+
799
+ if mfile .count (".xml" ) != 1 or mfile .find (".xml" ) + 4 != len (mfile ):
800
+ self .env .AddError (
801
+ "Error, the operator expects system resource module files"
802
+ + " to end in '.xml'"
803
+ + ", but the " + moduleTypeStr + " system resource module '" + mname + "'"
804
+ + " is configured with DescriptorFileName='" + mfile + "'." )
805
+
806
+ if not firstModule :
807
+ self .moduleStr += ", "
808
+ firstModule = false
809
+ self .moduleStr += "'" + mname + "'" ;
810
+
811
+ mfile = os .path .basename (mfile )
812
+ mfile = mfile .replace (".xml" ,"-situational-config.xml" )
813
+ mfile = customPrefix + mfile
814
+
815
+ self .moduleMap [moduleTypeStr + '-' + mname + '.xml' ] = mfile
816
+
817
+ # end of for loop
818
+
819
+ self .moduleStr += ')'
783
820
784
-
785
- # validateUnresolvedMacros()
786
- # Add a validation error if file contents have any unresolved macros
787
- # that contain a ":" in their name. This step is performed after all
788
- # known macros are already resolved. (Other macros are considered
789
- # valid server template macros in config.xml, so we assume they're
790
- # supposed to remain in the final sit-cfg xml).
791
821
792
822
def validateUnresolvedMacros (self , file , filestr ):
793
823
794
- errstr = ''
795
- for unknown_macro in re .findall ('\${[a-zA-Z0-9_-]*:[:a-zA-Z0-9_-]*}' , filestr ):
824
+ # Add a validation error if file contents have any unresolved macros
825
+ # that contain a ":" or "." in their name. This step is performed
826
+ # after all known macros are already resolved. (Other macros are
827
+ # considered valid server template macros in config.xml, so we
828
+ # assume they're supposed to remain in the final sit-cfg xml).
829
+
830
+ errstr = ''
831
+ for unknown_macro in re .findall ('\${[^}]*(:|.)[^}]*}' , filestr ):
796
832
if errstr :
797
- errstr = errstr + ", "
798
- errstr = errstr + "'" + unknown_macro + "'"
833
+ errstr += ","
834
+ errstr += unknown_macro
799
835
if errstr :
800
836
self .env .addError ("Error, unresolvable macro(s) '" + errstr + "'"
801
- + " in custom sit config file '" + file + "'"
837
+ + " in custom sit config file '" + file + "'. "
802
838
+ " Known macros are '" + self .macroStr + "'." )
803
839
804
- # validateFile()
805
- # Add a validation error if a custom sit config file name contains
806
- # a 'jdbc' or a 'jms' but has no corresponding module file in the
807
- # config.xml in the 'jdbc/' or 'jms/' directories.
808
-
809
- def validateFile (self , file ):
810
-
811
- if file .find ('jdbc' )!= - 1 and not self .jdbcModuleMap .has_key ('jdbc/' + file ):
812
- self .env .addError ("Error, custom sit config file '" + file + "'"
813
- + " has no matching config.xml module (a.k.a. 'system resource') configured at location 'jdbc/" + file + "'."
814
- + " Custom sit config files for a jdbc module must have a corresponding 'jdbc/' module file in config.xml."
815
- + " Known jdbc modules are '" + self .jdbcModuleStr + "'." )
816
840
817
- if file .find ('jms' )!= - 1 and not self .jmsModuleMap .has_key ('jms/' + file ):
818
- self .env .addError ("Error, custom sit config file '" + file + "'"
819
- + " has no matching config.xml module (a.k.a. 'system resource') configured at location 'jms/" + file + "'."
820
- + " Custom sit config files for a jdbc module must have a corresponding 'jms/' module file in config.xml."
821
- + " Known jms modules are '" + self .jmsModuleStr + "'." )
841
+ def generateAndValidate (self ):
822
842
823
- # generateAndValidate()
824
- # For each custom sit-cfg template, generate a file using macro substitution,
825
- # validate that it has a correponding jdbc/jms module if it's a jdbc/jms file,
826
- # and validate that all of its 'secret:' and 'env:' macros are resolvable.
843
+ # For each custom sit-cfg template, generate a file using macro substitution,
844
+ # validate that it has a correponding module if it's a module override file,
845
+ # and validate that all of its 'secret:' and 'env:' macros are resolvable.
827
846
828
- def generateAndValidate (self ):
829
847
if not os .path .exists (self .env .CUSTOM_SITCFG_PATH ):
830
- # Directory may not exist if no custom cfg been specified.
831
848
return
832
849
833
850
for the_file in os .listdir (self .env .CUSTOM_SITCFG_PATH ):
834
851
835
852
the_file_path = os .path .join (self .env .CUSTOM_SITCFG_PATH , the_file )
836
853
837
- if os .path .isfile (the_file_path ):
854
+ if not os .path .isfile (the_file_path ):
855
+ continue
856
+
857
+ trace ("Processing custom sit config file '" + the_file + "'" )
858
+
859
+ # check if file name corresponds with config.xml or a module
860
+
861
+ if not self .moduleMap .has_key (the_file ) and the_file != "config.xml" :
862
+ self .env .addError ("Error, custom sit config override file '" + the_file + "'"
863
+ + " is not named 'config.xml' or has no matching system resource"
864
+ + " module. Custom sit config files must be named 'config.xml'"
865
+ + " to override config.xml or 'moduletype-modulename.xml' to override"
866
+ + " a module. Known module names for each type: " + self .moduleStr + "." )
867
+ continue
868
+
869
+ # substitute macros and validate unresolved macros
870
+
871
+ file_str = self .env .readFile (the_file_path )
872
+ file_str_orig = 'dummyvalue'
873
+ while file_str != file_str_orig :
874
+ file_str_orig = file_str
875
+ for key ,val in self .macroMap .items ():
876
+ file_str = file_str .replace ('${' + key + '}' ,val )
877
+
878
+ self .validateUnresolvedMacros (the_file , file_str )
879
+
880
+ # put resolved template into a file
881
+
882
+ genfile = self .env .INTROSPECT_HOME + '/' ;
883
+
884
+ if the_file == 'config.xml' :
885
+ genfile += self .env .CUSTOM_PREFIX_CFG + 'custom-situational-config.xml'
886
+ else :
887
+ genfile += self .moduleMap [the_file ]
888
+
889
+ gen = Generator (self .env , genfile )
890
+ gen .open ()
891
+ gen .write (file_str )
892
+ gen .close ()
893
+ gen .addGeneratedFile ()
838
894
839
- trace ("Processing custom sit config file '" + the_file + "'" )
840
-
841
- # Note/TODO, it might work to use 'substitute' command instead
842
- # of multiple replaces. See http://www.jython.org/docs/library/string.html,
843
- # substitute takes a map and a template str, and replaces macros in the template
844
- # using the map values...
845
-
846
- file_str = self .env .readFile (the_file_path )
847
- file_str_orig = 'dummyvalue'
848
-
849
- while file_str != file_str_orig :
850
- file_str_orig = file_str
851
- for key ,val in self .macroMap .items ():
852
- file_str = file_str .replace ('${' + key + '}' ,val )
853
-
854
- filePrefix = self .env .CUSTOM_PREFIX_CFG
855
- if the_file .find ('jdbc' )!= - 1 :
856
- filePrefix = self .env .CUSTOM_PREFIX_JDBC
857
- if the_file .find ('jms' )!= - 1 :
858
- filePrefix = self .env .CUSTOM_PREFIX_JMS
859
-
860
- gen = Generator (self .env , self .env .INTROSPECT_HOME + '/' + filePrefix + the_file )
861
- gen .open ()
862
- gen .write (file_str )
863
- gen .close ()
864
- gen .addGeneratedFile ()
865
-
866
- self .validateFile (the_file )
867
- self .validateUnresolvedMacros (the_file , file_str )
868
895
869
896
class DomainIntrospector (SecretManager ):
870
897
0 commit comments