|
1 | 1 | package com.marklogic.appdeployer;
|
2 | 2 |
|
| 3 | +import com.marklogic.mgmt.util.PropertySource; |
| 4 | +import com.marklogic.mgmt.util.PropertySourceFactory; |
| 5 | + |
3 | 6 | import java.io.File;
|
4 | 7 | import java.util.ArrayList;
|
5 | 8 | import java.util.Arrays;
|
6 | 9 | import java.util.List;
|
7 | 10 |
|
8 |
| -import com.marklogic.mgmt.util.PropertySource; |
9 |
| -import com.marklogic.mgmt.util.PropertySourceFactory; |
10 |
| - |
11 | 11 | public class DefaultAppConfigFactory extends PropertySourceFactory implements AppConfigFactory {
|
12 | 12 |
|
13 |
| - public DefaultAppConfigFactory() { |
14 |
| - super(); |
15 |
| - }; |
16 |
| - |
17 |
| - public DefaultAppConfigFactory(PropertySource propertySource) { |
18 |
| - super(propertySource); |
19 |
| - } |
20 |
| - |
21 |
| - @Override |
22 |
| - public AppConfig newAppConfig() { |
23 |
| - AppConfig c = new AppConfig(); |
24 |
| - |
25 |
| - String prop = null; |
26 |
| - String mlUsername = getProperty("mlUsername"); |
27 |
| - String mlPassword = getProperty("mlPassword"); |
28 |
| - |
29 |
| - prop = getProperty("mlAppName"); |
30 |
| - if (prop != null) { |
31 |
| - logger.info("App name: " + prop); |
32 |
| - c.setName(prop); |
33 |
| - } |
34 |
| - |
35 |
| - prop = getProperty("mlConfigDir"); |
36 |
| - if (prop != null) { |
37 |
| - logger.info("Config dir: " + prop); |
38 |
| - c.setConfigDir(new ConfigDir(new File(prop))); |
39 |
| - } |
40 |
| - |
41 |
| - prop = getProperty("mlSchemasPath"); |
42 |
| - if (prop != null) { |
43 |
| - logger.info("Schemas path: " + prop); |
44 |
| - c.setSchemasPath(prop); |
45 |
| - } |
46 |
| - |
47 |
| - prop = getProperty("mlHost"); |
48 |
| - if (prop != null) { |
49 |
| - logger.info("App host: " + prop); |
50 |
| - c.setHost(prop); |
51 |
| - } |
52 |
| - |
53 |
| - prop = getProperty("mlRestPort"); |
54 |
| - if (prop != null) { |
55 |
| - logger.info("App REST port: " + prop); |
56 |
| - c.setRestPort(Integer.parseInt(prop)); |
57 |
| - } |
58 |
| - |
59 |
| - prop = getProperty("mlTestRestPort"); |
60 |
| - if (prop != null) { |
61 |
| - logger.info("App test REST port: " + prop); |
62 |
| - c.setTestRestPort(Integer.parseInt(prop)); |
63 |
| - } |
64 |
| - |
65 |
| - prop = getProperty("mlAppServicesPort"); |
66 |
| - if (prop != null) { |
67 |
| - logger.info("App services port: " + prop); |
68 |
| - c.setAppServicesPort(Integer.parseInt(prop)); |
69 |
| - } |
70 |
| - |
71 |
| - prop = getProperty("mlRestAdminUsername"); |
72 |
| - if (prop != null) { |
73 |
| - logger.info("REST admin username: " + prop); |
74 |
| - c.setRestAdminUsername(prop); |
75 |
| - } else if (mlUsername != null) { |
76 |
| - logger.info("REST admin username: " + mlUsername); |
77 |
| - c.setRestAdminUsername(mlUsername); |
78 |
| - } |
79 |
| - |
80 |
| - prop = getProperty("mlRestAdminPassword"); |
81 |
| - if (prop != null) { |
82 |
| - c.setRestAdminPassword(prop); |
83 |
| - } else if (mlPassword != null) { |
84 |
| - c.setRestAdminPassword(mlPassword); |
85 |
| - } |
86 |
| - |
87 |
| - prop = getProperty("mlContentForestsPerHost"); |
88 |
| - if (prop != null) { |
89 |
| - logger.info("Content forests per host: " + prop); |
90 |
| - c.setContentForestsPerHost(Integer.parseInt(prop)); |
91 |
| - } |
92 |
| - |
93 |
| - prop = getProperty("mlModulePermissions"); |
94 |
| - if (prop != null) { |
95 |
| - logger.info("Module permissions: " + prop); |
96 |
| - c.setModulePermissions(prop); |
97 |
| - } |
98 |
| - |
99 |
| - prop = getProperty("mlModulesDatabaseName"); |
100 |
| - if (prop != null) { |
101 |
| - logger.info("Modules database name: " + prop); |
102 |
| - c.setModulesDatabaseName(prop); |
103 |
| - } |
104 |
| - |
105 |
| - prop = getProperty("mlAdditionalBinaryExtensions"); |
106 |
| - if (prop != null) { |
107 |
| - String[] values = prop.split(","); |
108 |
| - logger.info("Additional binary extensions for loading modules: " + Arrays.asList(values)); |
109 |
| - c.setAdditionalBinaryExtensions(values); |
110 |
| - } |
111 |
| - |
112 |
| - if (getProperty("mlSimpleSsl") != null) { |
113 |
| - logger.info( |
114 |
| - "Using simple SSL context and 'ANY' hostname verifier for authenticating against client REST API server"); |
115 |
| - c.setSimpleSslConfig(); |
116 |
| - } |
117 |
| - |
118 |
| - prop = getProperty("mlDatabaseNamesAndReplicaCounts"); |
119 |
| - if (prop != null) { |
120 |
| - logger.info("Database names and replica counts: " + prop); |
121 |
| - c.setDatabaseNamesAndReplicaCounts(prop); |
122 |
| - } |
123 |
| - |
124 |
| - prop = getProperty("mlFlexrepPath"); |
125 |
| - if (prop != null) { |
126 |
| - logger.info("Flexrep path: " + prop); |
127 |
| - c.setFlexrepPath(prop); |
128 |
| - } |
129 |
| - |
130 |
| - prop = getProperty("mlGroupName"); |
131 |
| - if (prop != null) { |
132 |
| - logger.info("Group name: " + prop); |
133 |
| - c.setGroupName(prop); |
134 |
| - } |
135 |
| - |
136 |
| - prop = getProperty("mlReplaceTokensInModules"); |
137 |
| - if (prop != null) { |
138 |
| - logger.info("Replace tokens in modules: " + prop); |
139 |
| - c.setReplaceTokensInModules(Boolean.parseBoolean(prop)); |
140 |
| - } |
141 |
| - |
142 |
| - prop = getProperty("mlUseRoxyTokenPrefix"); |
143 |
| - if (prop != null) { |
144 |
| - logger.info("Use Roxy token prefix of '@ml.': " + prop); |
145 |
| - c.setUseRoxyTokenPrefix(Boolean.parseBoolean(prop)); |
146 |
| - } |
147 |
| - |
148 |
| - prop = getProperty("mlModulePaths"); |
149 |
| - if (prop != null) { |
150 |
| - logger.info("Module paths: " + prop); |
151 |
| - String[] paths = prop.split(","); |
152 |
| - // Ensure we have a modifiable list |
153 |
| - List<String> list = new ArrayList<>(); |
154 |
| - for (String s : paths) { |
155 |
| - list.add(s); |
156 |
| - } |
157 |
| - c.setModulePaths(list); |
158 |
| - } |
159 |
| - |
160 |
| - return c; |
161 |
| - } |
| 13 | + public DefaultAppConfigFactory() { |
| 14 | + super(); |
| 15 | + } |
| 16 | + |
| 17 | + ; |
| 18 | + |
| 19 | + public DefaultAppConfigFactory(PropertySource propertySource) { |
| 20 | + super(propertySource); |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public AppConfig newAppConfig() { |
| 25 | + AppConfig c = new AppConfig(); |
| 26 | + |
| 27 | + String prop = null; |
| 28 | + |
| 29 | + /** |
| 30 | + * mlUsername and mlPassword are used as the default username/password for the admin, rest-admin, and manage-admin |
| 31 | + * roles when there isn't a specific username/password combo for those roles. |
| 32 | + */ |
| 33 | + String mlUsername = getProperty("mlUsername"); |
| 34 | + String mlPassword = getProperty("mlPassword"); |
| 35 | + |
| 36 | + /** |
| 37 | + * The application name is used as a prefix for default names for a variety of resources, such as REST API servers |
| 38 | + * and databases. |
| 39 | + */ |
| 40 | + prop = getProperty("mlAppName"); |
| 41 | + if (prop != null) { |
| 42 | + logger.info("App name: " + prop); |
| 43 | + c.setName(prop); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * The path to the directory containing all the resource configuration files. Defaults to src/main/ml-config. |
| 48 | + * mlConfigPath is the preferred one, as its name is consistent with other properties that refer to a path. |
| 49 | + * mlConfigDir is deprecated but still supported. |
| 50 | + */ |
| 51 | + prop = getProperty("mlConfigDir"); |
| 52 | + if (prop != null) { |
| 53 | + logger.info("mlConfigDir is deprecated; please use mlConfigPath; Config dir: " + prop); |
| 54 | + c.setConfigDir(new ConfigDir(new File(prop))); |
| 55 | + } |
| 56 | + prop = getProperty("mlConfigPath"); |
| 57 | + if (prop != null) { |
| 58 | + logger.info("Config path: " + prop); |
| 59 | + c.setConfigDir(new ConfigDir(new File(prop))); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Defines the path to files that should be loaded into a schemas database. Defaults to src/main/ml-schemas. |
| 64 | + */ |
| 65 | + prop = getProperty("mlSchemasPath"); |
| 66 | + if (prop != null) { |
| 67 | + logger.info("Schemas path: " + prop); |
| 68 | + c.setSchemasPath(prop); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Defines the MarkLogic host that requests should be sent to. Defaults to localhost. |
| 73 | + */ |
| 74 | + prop = getProperty("mlHost"); |
| 75 | + if (prop != null) { |
| 76 | + logger.info("App host: " + prop); |
| 77 | + c.setHost(prop); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * If a REST API server is created, it will use the following port. Modules will also be loaded via this port. |
| 82 | + */ |
| 83 | + prop = getProperty("mlRestPort"); |
| 84 | + if (prop != null) { |
| 85 | + logger.info("App REST port: " + prop); |
| 86 | + c.setRestPort(Integer.parseInt(prop)); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * If a test REST API server is created, it will use the following port. |
| 91 | + */ |
| 92 | + prop = getProperty("mlTestRestPort"); |
| 93 | + if (prop != null) { |
| 94 | + logger.info("App test REST port: " + prop); |
| 95 | + c.setTestRestPort(Integer.parseInt(prop)); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Defaults to port 8000. In rare cases, the ML App-Services app server will have been changed to listen on a |
| 100 | + * different port, in which case you can set this to that port. |
| 101 | + */ |
| 102 | + prop = getProperty("mlAppServicesPort"); |
| 103 | + if (prop != null) { |
| 104 | + logger.info("App services port: " + prop); |
| 105 | + c.setAppServicesPort(Integer.parseInt(prop)); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * The username and password for a ML user with the rest-admin role. This user is used for operations against the |
| 110 | + * Client REST API - namely, loading modules. |
| 111 | + */ |
| 112 | + prop = getProperty("mlRestAdminUsername"); |
| 113 | + if (prop != null) { |
| 114 | + logger.info("REST admin username: " + prop); |
| 115 | + c.setRestAdminUsername(prop); |
| 116 | + } else if (mlUsername != null) { |
| 117 | + logger.info("REST admin username: " + mlUsername); |
| 118 | + c.setRestAdminUsername(mlUsername); |
| 119 | + } |
| 120 | + prop = getProperty("mlRestAdminPassword"); |
| 121 | + if (prop != null) { |
| 122 | + c.setRestAdminPassword(prop); |
| 123 | + } else if (mlPassword != null) { |
| 124 | + c.setRestAdminPassword(mlPassword); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * When a content database is created, this property can be used to control the number of forests per host for |
| 129 | + * that database. |
| 130 | + */ |
| 131 | + prop = getProperty("mlContentForestsPerHost"); |
| 132 | + if (prop != null) { |
| 133 | + logger.info("Content forests per host: " + prop); |
| 134 | + c.setContentForestsPerHost(Integer.parseInt(prop)); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * This property can specify a comma-delimited list of database names and replica counts as a simple way of |
| 139 | + * setting up forest replicas - e.g. Documents,1,Security,2. |
| 140 | + */ |
| 141 | + prop = getProperty("mlDatabaseNamesAndReplicaCounts"); |
| 142 | + if (prop != null) { |
| 143 | + logger.info("Database names and replica counts: " + prop); |
| 144 | + c.setDatabaseNamesAndReplicaCounts(prop); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * When a REST API server is created, the name will default to mlAppName-modules. This property can be used to |
| 149 | + * override that name. |
| 150 | + */ |
| 151 | + prop = getProperty("mlModulesDatabaseName"); |
| 152 | + if (prop != null) { |
| 153 | + logger.info("Modules database name: " + prop); |
| 154 | + c.setModulesDatabaseName(prop); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * When modules are loaded via the Client REST API, if the app server requires an SSL connection, then |
| 159 | + * setting this property will force the simplest SSL connection to be created. |
| 160 | + */ |
| 161 | + if (getProperty("mlSimpleSsl") != null) { |
| 162 | + logger.info( |
| 163 | + "Using simple SSL context and 'ANY' hostname verifier for authenticating against client REST API server"); |
| 164 | + c.setSimpleSslConfig(); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Specifies the path for flexrep configuration files; used by DeployFlexrepCommand. |
| 169 | + */ |
| 170 | + prop = getProperty("mlFlexrepPath"); |
| 171 | + if (prop != null) { |
| 172 | + logger.info("Flexrep path: " + prop); |
| 173 | + c.setFlexrepPath(prop); |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * "Default" is the assumed group for group-specific resources, such as app servers and scheduled tasks. This |
| 178 | + * property can be set to override that. |
| 179 | + */ |
| 180 | + prop = getProperty("mlGroupName"); |
| 181 | + if (prop != null) { |
| 182 | + logger.info("Group name: " + prop); |
| 183 | + c.setGroupName(prop); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * When modules are loaded via the Client REST API, this property can specify a comma-delimited set of role/capability |
| 188 | + * permissions - e.g. rest-reader,read,rest-writer,update. |
| 189 | + */ |
| 190 | + prop = getProperty("mlModulePermissions"); |
| 191 | + if (prop != null) { |
| 192 | + logger.info("Module permissions: " + prop); |
| 193 | + c.setModulePermissions(prop); |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * When modules are loaded via the Client REST API, this property can specify a comma-delimited set of extensions |
| 198 | + * for files that should be loaded as binaries. |
| 199 | + */ |
| 200 | + prop = getProperty("mlAdditionalBinaryExtensions"); |
| 201 | + if (prop != null) { |
| 202 | + String[] values = prop.split(","); |
| 203 | + logger.info("Additional binary extensions for loading modules: " + Arrays.asList(values)); |
| 204 | + c.setAdditionalBinaryExtensions(values); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * By default, tokens in module files will be replaced. This property can be used to enable/disable that behavior. |
| 209 | + */ |
| 210 | + prop = getProperty("mlReplaceTokensInModules"); |
| 211 | + if (prop != null) { |
| 212 | + logger.info("Replace tokens in modules: " + prop); |
| 213 | + c.setReplaceTokensInModules(Boolean.parseBoolean(prop)); |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * To mimic Roxy behavior, tokens in modules are expected to start with "@ml.". If you do not want this behavior, |
| 218 | + * you can set this property to false to disable it. |
| 219 | + */ |
| 220 | + prop = getProperty("mlUseRoxyTokenPrefix"); |
| 221 | + if (prop != null) { |
| 222 | + logger.info("Use Roxy token prefix of '@ml.': " + prop); |
| 223 | + c.setUseRoxyTokenPrefix(Boolean.parseBoolean(prop)); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Comma-separated list of paths for loading modules. Defaults to src/main/ml-modules. |
| 228 | + */ |
| 229 | + prop = getProperty("mlModulePaths"); |
| 230 | + if (prop != null) { |
| 231 | + logger.info("Module paths: " + prop); |
| 232 | + String[] paths = prop.split(","); |
| 233 | + // Ensure we have a modifiable list |
| 234 | + List<String> list = new ArrayList<>(); |
| 235 | + for (String s : paths) { |
| 236 | + list.add(s); |
| 237 | + } |
| 238 | + c.setModulePaths(list); |
| 239 | + } |
| 240 | + |
| 241 | + return c; |
| 242 | + } |
162 | 243 |
|
163 | 244 | }
|
0 commit comments