|
1 | | -# Copyright 2020, Oracle Corporation and/or its affiliates. |
2 | | -# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
3 | | -import xml.dom.minidom |
4 | | -import re |
5 | | -import sys |
6 | | - |
7 | | -def getManagedServerCount(domainHome): |
8 | | -# use the parse() function to load and parse an XML file |
9 | | - doc = xml.dom.minidom.parse(domainHome + "/config/config.xml") |
10 | | - servers = doc.getElementsByTagName("server") |
11 | | - print "Total Configured Managed Servers: %d " % (servers.length - 1) |
12 | | - return servers.length - 1; |
13 | | - |
14 | | - |
15 | | -# Method to uncomment and comment the required tag and save back |
16 | | -def replaceXml(domainHome, ms_server): |
17 | | - f = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml","r+w") |
18 | | - filecontent = f.read() |
19 | | - #Uncomment the one to be used |
20 | | - filecontent = re.sub ( r'<!--<cacheManagerPeerProviderFactory','<cacheManagerPeerProviderFactory', filecontent,1) |
21 | | - filecontent = re.sub ( r'cas_tgt" />-->','cas_tgt" />', filecontent,1) |
22 | | - #Comment the one not used |
23 | | - filecontent = re.sub ( r'<cacheManagerPeerProviderFactory','<!--cacheManagerPeerProviderFactory', filecontent,1) |
24 | | - filecontent = re.sub ( r'propertySeparator="," />','propertySeparator="," -->', filecontent,1) |
25 | | - f.seek(0) |
26 | | - f.write(filecontent) |
27 | | - f.write("\n\n\n") |
28 | | - f.close() |
29 | | - |
30 | | -# Method to replace the properties |
31 | | -def replaceRmiUrlsInCache(domainHome, prefix, n, ms_server, excludedServerNumber, filename, port): |
32 | | - doc = xml.dom.minidom.parse(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/" + filename) |
33 | | - abc = doc.getElementsByTagName("cacheManagerPeerProviderFactory") |
34 | | - processString = "peerDiscovery=manual,rmiUrls=//localhost:<port>/notifier" |
35 | | - |
36 | | - for element in abc: |
37 | | - element.setAttribute("properties", processString) |
38 | | - |
39 | | - for x in range (1,n-1): |
40 | | - processString = processString + "|//localhost:<port>/notifier" |
41 | | - |
42 | | - # We should have got the properties attribute now tokenized with localhost and 41001. Exclude 1 add the rest |
43 | | - for i in range (1,n+1): |
44 | | - if i <> int(excludedServerNumber): |
45 | | - processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
46 | | - processString = re.sub ( r'<port>',str(port), processString,1) |
47 | | - |
48 | | - element.setAttribute("properties", processString) |
49 | | - print(processString) |
50 | | - ghi = doc.getElementsByTagName("cacheManagerPeerListenerFactory") |
51 | | - for element in ghi: |
52 | | - processString = element.getAttribute("properties") |
53 | | - processString = "hostName="+prefix+ str(excludedServerNumber) +",port=" + str(port) +",remoteObjectPort=" + str(int(port)+1) + ",socketTimeoutMillis=12000" |
54 | | - element.setAttribute("properties", processString) |
55 | | - myfile = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/" + filename , "w") |
56 | | - myfile.write(doc.toxml()) |
57 | | - myfile.close() |
58 | | - print("Updated " + filename) |
59 | | - |
60 | | -# Method to replace the properties |
61 | | -def replaceRmiUrls(domainHome, prefix, n, ms_server, excludedServerNumber, port): |
62 | | - doc = xml.dom.minidom.parse(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml") |
63 | | - abc = doc.getElementsByTagName("cacheManagerPeerProviderFactory") |
64 | | - processString = "" |
65 | | - |
66 | | - for element in abc: |
67 | | - processString = element.getAttribute("properties") |
68 | | - |
69 | | - for x in range (1,n-1): |
70 | | - processString = processString + "|//localhost:41001/cas_st|//localhost:41001/cas_tgt" |
71 | | - |
72 | | - # We should have got the properties attribute now tokenized with localhost and 41001. Exclude 1 add the rest |
73 | | - for i in range (1,n+1): |
74 | | - if i <> int(excludedServerNumber): |
75 | | - processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
76 | | - processString = re.sub ( r'41001',str(port), processString,1) |
77 | | - processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
78 | | - processString = re.sub ( r'41001',str(port), processString,1) |
79 | | - |
80 | | - element.setAttribute("properties", processString) |
81 | | - print(processString) |
82 | | - ghi = doc.getElementsByTagName("cacheManagerPeerListenerFactory") |
83 | | - for element in ghi: |
84 | | - processString = element.getAttribute("properties") |
85 | | - processString = "hostName=" + prefix + str(excludedServerNumber) + ",port=" + str(port) + ",remoteObjectPort=" + str(int(port)+1) + ",socketTimeoutMillis=12000" |
86 | | - element.setAttribute("properties", processString) |
87 | | - myfile = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml", "w") |
88 | | - myfile.write(doc.toxml()) |
89 | | - myfile.close() |
90 | | - print("Updated " + "ticket-cache.xml") |
91 | | - |
92 | | -def main(): |
93 | | - # count the arguments |
94 | | - arguments = len(sys.argv) - 1 |
95 | | - print ("The script is called with %i arguments" % (arguments)) |
96 | | - domainHome = sys.argv[1] |
97 | | - serverPrefix = sys.argv[2] |
98 | | - ms_server = sys.argv[3] |
99 | | - port = sys.argv[4] |
100 | | - excludedServerNumber = ms_server[-1] |
101 | | - print("Host prefix set to " + serverPrefix) |
102 | | - print("Managed Server set to - " + ms_server) |
103 | | - print("Excluded Server Number set to - " + excludedServerNumber) |
104 | | - print("Starting port set to - " + port) |
105 | | - replaceXml(domainHome, ms_server) |
106 | | - servercount = getManagedServerCount(domainHome) |
107 | | - replaceRmiUrls(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, port) |
108 | | - replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "linked-cache.xml", int(port) + 2) |
109 | | - replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "cs-cache.xml", int(port) + 4) |
110 | | - replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "cas-cache.xml", int(port) + 6 ) |
111 | | - replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "ss-cache.xml", int(port) + 8 ) |
112 | | - |
113 | | - |
114 | | -if __name__ == "__main__": |
115 | | - # calling main function |
116 | | - main() |
117 | | - |
| 1 | +# Copyright 2020, Oracle Corporation and/or its affiliates. |
| 2 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 3 | +import xml.dom.minidom |
| 4 | +import re |
| 5 | +import sys |
| 6 | + |
| 7 | +def getManagedServerCount(domainHome): |
| 8 | +# use the parse() function to load and parse an XML file |
| 9 | + doc = xml.dom.minidom.parse(domainHome + "/config/config.xml") |
| 10 | + servers = doc.getElementsByTagName("server") |
| 11 | + print "Total Configured Managed Servers: %d " % (servers.length - 1) |
| 12 | + return servers.length - 1; |
| 13 | + |
| 14 | + |
| 15 | +# Method to uncomment and comment the required tag and save back |
| 16 | +def replaceXml(domainHome, ms_server): |
| 17 | + f = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml","r+w") |
| 18 | + filecontent = f.read() |
| 19 | + #Uncomment the one to be used |
| 20 | + filecontent = re.sub ( r'<!--<cacheManagerPeerProviderFactory','<cacheManagerPeerProviderFactory', filecontent,1) |
| 21 | + filecontent = re.sub ( r'cas_tgt" />-->','cas_tgt" />', filecontent,1) |
| 22 | + #Comment the one not used |
| 23 | + filecontent = re.sub ( r'<cacheManagerPeerProviderFactory','<!--cacheManagerPeerProviderFactory', filecontent,1) |
| 24 | + filecontent = re.sub ( r'propertySeparator="," />','propertySeparator="," -->', filecontent,1) |
| 25 | + f.seek(0) |
| 26 | + f.write(filecontent) |
| 27 | + f.write("\n\n\n") |
| 28 | + f.close() |
| 29 | + |
| 30 | +# Method to replace the properties |
| 31 | +def replaceRmiUrlsInCache(domainHome, prefix, n, ms_server, excludedServerNumber, filename, port): |
| 32 | + doc = xml.dom.minidom.parse(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/" + filename) |
| 33 | + abc = doc.getElementsByTagName("cacheManagerPeerProviderFactory") |
| 34 | + processString = "peerDiscovery=manual,rmiUrls=//localhost:<port>/notifier" |
| 35 | + |
| 36 | + for element in abc: |
| 37 | + element.setAttribute("properties", processString) |
| 38 | + |
| 39 | + for x in range (1,n-1): |
| 40 | + processString = processString + "|//localhost:<port>/notifier" |
| 41 | + |
| 42 | + # We should have got the properties attribute now tokenized with localhost and 41001. Exclude 1 add the rest |
| 43 | + for i in range (1,n+1): |
| 44 | + if i <> int(excludedServerNumber): |
| 45 | + processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
| 46 | + processString = re.sub ( r'<port>',str(port), processString,1) |
| 47 | + |
| 48 | + element.setAttribute("properties", processString) |
| 49 | + print(processString) |
| 50 | + ghi = doc.getElementsByTagName("cacheManagerPeerListenerFactory") |
| 51 | + for element in ghi: |
| 52 | + processString = element.getAttribute("properties") |
| 53 | + processString = "hostName="+prefix+ str(excludedServerNumber) +",port=" + str(port) +",remoteObjectPort=" + str(int(port)+1) + ",socketTimeoutMillis=12000" |
| 54 | + element.setAttribute("properties", processString) |
| 55 | + myfile = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/" + filename , "w") |
| 56 | + myfile.write(doc.toxml()) |
| 57 | + myfile.close() |
| 58 | + print("Updated " + filename) |
| 59 | + |
| 60 | +# Method to replace the properties |
| 61 | +def replaceRmiUrls(domainHome, prefix, n, ms_server, excludedServerNumber, port): |
| 62 | + doc = xml.dom.minidom.parse(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml") |
| 63 | + abc = doc.getElementsByTagName("cacheManagerPeerProviderFactory") |
| 64 | + processString = "" |
| 65 | + |
| 66 | + for element in abc: |
| 67 | + processString = element.getAttribute("properties") |
| 68 | + |
| 69 | + for x in range (1,n-1): |
| 70 | + processString = processString + "|//localhost:41001/cas_st|//localhost:41001/cas_tgt" |
| 71 | + |
| 72 | + # We should have got the properties attribute now tokenized with localhost and 41001. Exclude 1 add the rest |
| 73 | + for i in range (1,n+1): |
| 74 | + if i <> int(excludedServerNumber): |
| 75 | + processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
| 76 | + processString = re.sub ( r'41001',str(port), processString,1) |
| 77 | + processString = re.sub ( r'localhost',prefix + str(i), processString,1) |
| 78 | + processString = re.sub ( r'41001',str(port), processString,1) |
| 79 | + |
| 80 | + element.setAttribute("properties", processString) |
| 81 | + print(processString) |
| 82 | + ghi = doc.getElementsByTagName("cacheManagerPeerListenerFactory") |
| 83 | + for element in ghi: |
| 84 | + processString = element.getAttribute("properties") |
| 85 | + processString = "hostName=" + prefix + str(excludedServerNumber) + ",port=" + str(port) + ",remoteObjectPort=" + str(int(port)+1) + ",socketTimeoutMillis=12000" |
| 86 | + element.setAttribute("properties", processString) |
| 87 | + myfile = open(domainHome + "/config/fmwconfig/servers/" + ms_server + "/config/ticket-cache.xml", "w") |
| 88 | + myfile.write(doc.toxml()) |
| 89 | + myfile.close() |
| 90 | + print("Updated " + "ticket-cache.xml") |
| 91 | + |
| 92 | +def main(): |
| 93 | + # count the arguments |
| 94 | + arguments = len(sys.argv) - 1 |
| 95 | + print ("The script is called with %i arguments" % (arguments)) |
| 96 | + domainHome = sys.argv[1] |
| 97 | + serverPrefix = sys.argv[2] |
| 98 | + ms_server = sys.argv[3] |
| 99 | + port = sys.argv[4] |
| 100 | + excludedServerNumber = ms_server[-1] |
| 101 | + print("Host prefix set to " + serverPrefix) |
| 102 | + print("Managed Server set to - " + ms_server) |
| 103 | + print("Excluded Server Number set to - " + excludedServerNumber) |
| 104 | + print("Starting port set to - " + port) |
| 105 | + replaceXml(domainHome, ms_server) |
| 106 | + servercount = getManagedServerCount(domainHome) |
| 107 | + replaceRmiUrls(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, port) |
| 108 | + replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "linked-cache.xml", int(port) + 2) |
| 109 | + replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "cs-cache.xml", int(port) + 4) |
| 110 | + replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "cas-cache.xml", int(port) + 6 ) |
| 111 | + replaceRmiUrlsInCache(domainHome, serverPrefix, servercount, ms_server, excludedServerNumber, "ss-cache.xml", int(port) + 8 ) |
| 112 | + |
| 113 | + |
| 114 | +if __name__ == "__main__": |
| 115 | + # calling main function |
| 116 | + main() |
| 117 | + |
0 commit comments