|
51 | 51 | */ |
52 | 52 | public class CommandMapBuilder { |
53 | 53 |
|
| 54 | + /** |
| 55 | + * @return a map of all commands relevant to deploying an application, including those that can write data to a |
| 56 | + * database and thus should only be run against a cluster that is not a replica cluster |
| 57 | + */ |
54 | 58 | public Map<String, List<Command>> buildCommandMap() { |
55 | 59 | Map<String, List<Command>> map = new HashMap<>(); |
| 60 | + addCommandsThatDoNotWriteToDatabases(map); |
| 61 | + addCommandsThatWriteToDatabases(map); |
| 62 | + return map; |
| 63 | + } |
56 | 64 |
|
57 | | - // Security |
58 | | - List<Command> securityCommands = new ArrayList<Command>(); |
59 | | - securityCommands.add(new DeployRolesCommand()); |
60 | | - securityCommands.add(new DeployUsersCommand()); |
61 | | - securityCommands.add(new DeployAmpsCommand()); |
62 | | - securityCommands.add(new DeployCertificateTemplatesCommand()); |
63 | | - securityCommands.add(new DeployCertificateAuthoritiesCommand()); |
64 | | - securityCommands.add(new InsertCertificateHostsTemplateCommand()); |
65 | | - securityCommands.add(new DeployExternalSecurityCommand()); |
66 | | - securityCommands.add(new DeployPrivilegesCommand()); |
67 | | - securityCommands.add(new DeployPrivilegeRolesCommand()); |
68 | | - securityCommands.add(new DeployProtectedCollectionsCommand()); |
69 | | - securityCommands.add(new DeployProtectedPathsCommand()); |
70 | | - securityCommands.add(new DeployQueryRolesetsCommand()); |
71 | | - map.put("mlSecurityCommands", securityCommands); |
| 65 | + /** |
| 66 | + * For deploying to a replica cluster, care must be taken not to run any command that will write to a database that |
| 67 | + * is likely to have database replication configured for it. This then returns a map of commands that are known not |
| 68 | + * to write any data to databases. The security commands are an exception though, as it's typical for the Security |
| 69 | + * database to not have database replication configured for it. If this is not the case for a user, the user can |
| 70 | + * still use this method and simply remove the commands that write to the Security database. |
| 71 | + * |
| 72 | + * @return |
| 73 | + */ |
| 74 | + public Map<String, List<Command>> buildCommandMapForReplicaCluster() { |
| 75 | + Map<String, List<Command>> map = new HashMap<>(); |
| 76 | + addCommandsThatDoNotWriteToDatabases(map); |
| 77 | + return map; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Same as buildCommandMapForReplicaCluster, but returns a list of all the commands. |
| 82 | + * |
| 83 | + * @return |
| 84 | + */ |
| 85 | + public List<Command> getCommandsForReplicaCluster() { |
| 86 | + return buildCommandMapForReplicaCluster() |
| 87 | + .values() |
| 88 | + .stream().reduce(new ArrayList<>(), (a, b) -> { |
| 89 | + a.addAll(b); |
| 90 | + return a; |
| 91 | + }); |
| 92 | + } |
72 | 93 |
|
73 | | - // Cluster |
| 94 | + private void addCommandsThatDoNotWriteToDatabases(Map<String, List<Command>> map) { |
74 | 95 | List<Command> clusterCommands = new ArrayList<Command>(); |
75 | 96 | clusterCommands.add(new ModifyLocalClusterCommand()); |
76 | 97 | map.put("mlClusterCommands", clusterCommands); |
77 | 98 |
|
78 | | - // Configurations |
79 | 99 | List<Command> configurationCommands = new ArrayList<>(); |
80 | 100 | configurationCommands.add(new DeployConfigurationsCommand()); |
81 | 101 | map.put("mlConfigurationCommands", configurationCommands); |
82 | 102 |
|
83 | | - // Databases |
84 | 103 | List<Command> dbCommands = new ArrayList<Command>(); |
85 | 104 | dbCommands.add(new DeployOtherDatabasesCommand()); |
86 | 105 | map.put("mlDatabaseCommands", dbCommands); |
87 | 106 |
|
88 | | - // Database rebalancer |
| 107 | + List<Command> forestCommands = new ArrayList<Command>(); |
| 108 | + forestCommands.add(new DeployCustomForestsCommand()); |
| 109 | + map.put("mlForestCommands", forestCommands); |
| 110 | + |
| 111 | + List<Command> replicaCommands = new ArrayList<Command>(); |
| 112 | + replicaCommands.add(new ConfigureForestReplicasCommand()); |
| 113 | + map.put("mlForestReplicaCommands", replicaCommands); |
| 114 | + |
| 115 | + List<Command> groupCommands = new ArrayList<Command>(); |
| 116 | + groupCommands.add(new DeployGroupsCommand()); |
| 117 | + map.put("mlGroupCommands", groupCommands); |
| 118 | + |
| 119 | + List<Command> hostCommands = new ArrayList<Command>(); |
| 120 | + hostCommands.add(new AssignHostsToGroupsCommand()); |
| 121 | + map.put("mlHostCommands", hostCommands); |
| 122 | + |
| 123 | + List<Command> mimetypeCommands = new ArrayList<Command>(); |
| 124 | + mimetypeCommands.add(new DeployMimetypesCommand()); |
| 125 | + map.put("mlMimetypeCommands", mimetypeCommands); |
| 126 | + |
| 127 | + List<Command> pluginCommands = new ArrayList<>(); |
| 128 | + pluginCommands.add(new InstallPluginsCommand()); |
| 129 | + map.put("mlPluginCommands", pluginCommands); |
| 130 | + |
89 | 131 | List<Command> rebalancerCommands = new ArrayList<>(); |
90 | 132 | rebalancerCommands.add(new DeployPartitionsCommand()); |
91 | 133 | rebalancerCommands.add(new DeployPartitionQueriesCommand()); |
92 | 134 | map.put("mlRebalancerCommands", rebalancerCommands); |
93 | 135 |
|
94 | | - // Schemas |
95 | | - List<Command> schemaCommands = new ArrayList<>(); |
96 | | - schemaCommands.add(new LoadSchemasCommand()); |
97 | | - map.put("mlSchemaCommands", schemaCommands); |
98 | | - |
99 | | - // REST API instance creation |
100 | 136 | List<Command> restApiCommands = new ArrayList<>(); |
101 | 137 | restApiCommands.add(new DeployRestApiServersCommand()); |
102 | 138 | map.put("mlRestApiCommands", restApiCommands); |
103 | 139 |
|
104 | | - // App servers |
| 140 | + List<Command> securityCommands = new ArrayList<Command>(); |
| 141 | + securityCommands.add(new DeployRolesCommand()); |
| 142 | + securityCommands.add(new DeployUsersCommand()); |
| 143 | + securityCommands.add(new DeployAmpsCommand()); |
| 144 | + securityCommands.add(new DeployCertificateTemplatesCommand()); |
| 145 | + securityCommands.add(new DeployCertificateAuthoritiesCommand()); |
| 146 | + securityCommands.add(new InsertCertificateHostsTemplateCommand()); |
| 147 | + securityCommands.add(new DeployExternalSecurityCommand()); |
| 148 | + securityCommands.add(new DeployPrivilegesCommand()); |
| 149 | + securityCommands.add(new DeployPrivilegeRolesCommand()); |
| 150 | + securityCommands.add(new DeployProtectedCollectionsCommand()); |
| 151 | + securityCommands.add(new DeployProtectedPathsCommand()); |
| 152 | + securityCommands.add(new DeployQueryRolesetsCommand()); |
| 153 | + map.put("mlSecurityCommands", securityCommands); |
| 154 | + |
105 | 155 | List<Command> serverCommands = new ArrayList<>(); |
106 | 156 | serverCommands.add(new DeployOtherServersCommand()); |
107 | 157 | serverCommands.add(new UpdateRestApiServersCommand()); |
108 | 158 | map.put("mlServerCommands", serverCommands); |
109 | 159 |
|
110 | | - // Modules |
111 | | - List<Command> moduleCommands = new ArrayList<>(); |
112 | | - moduleCommands.add(new LoadModulesCommand()); |
113 | | - moduleCommands.add(new DeleteTestModulesCommand()); |
114 | | - map.put("mlModuleCommands", moduleCommands); |
| 160 | + List<Command> taskCommands = new ArrayList<Command>(); |
| 161 | + taskCommands.add(new DeployScheduledTasksCommand()); |
| 162 | + taskCommands.add(new UpdateTaskServerCommand()); |
| 163 | + map.put("mlTaskCommands", taskCommands); |
| 164 | + } |
115 | 165 |
|
116 | | - // Alerting |
| 166 | + private void addCommandsThatWriteToDatabases(Map<String, List<Command>> map) { |
117 | 167 | List<Command> alertCommands = new ArrayList<Command>(); |
118 | 168 | alertCommands.add(new DeployAlertConfigsCommand()); |
119 | 169 | alertCommands.add(new DeployAlertActionsCommand()); |
120 | 170 | alertCommands.add(new DeployAlertRulesCommand()); |
121 | 171 | map.put("mlAlertCommands", alertCommands); |
122 | 172 |
|
123 | | - // CPF |
124 | 173 | List<Command> cpfCommands = new ArrayList<Command>(); |
125 | 174 | cpfCommands.add(new DeployCpfConfigsCommand()); |
126 | 175 | cpfCommands.add(new DeployDomainsCommand()); |
127 | 176 | cpfCommands.add(new DeployPipelinesCommand()); |
128 | 177 | map.put("mlCpfCommands", cpfCommands); |
129 | 178 |
|
130 | | - // Data |
131 | 179 | List<Command> dataCommands = new ArrayList<>(); |
132 | 180 | dataCommands.add(new LoadDataCommand()); |
133 | 181 | map.put("mlDataCommands", dataCommands); |
134 | 182 |
|
135 | | - // Flexrep |
136 | 183 | List<Command> flexrepCommands = new ArrayList<Command>(); |
137 | 184 | flexrepCommands.add(new DeployConfigsCommand()); |
138 | 185 | flexrepCommands.add(new DeployTargetsCommand()); |
139 | 186 | flexrepCommands.add(new DeployFlexrepCommand()); |
140 | 187 | map.put("mlFlexrepCommands", flexrepCommands); |
141 | 188 |
|
142 | | - // Groups |
143 | | - List<Command> groupCommands = new ArrayList<Command>(); |
144 | | - groupCommands.add(new DeployGroupsCommand()); |
145 | | - map.put("mlGroupCommands", groupCommands); |
146 | | - |
147 | | - List<Command> mimetypeCommands = new ArrayList<Command>(); |
148 | | - mimetypeCommands.add(new DeployMimetypesCommand()); |
149 | | - map.put("mlMimetypeCommands", mimetypeCommands); |
150 | | - |
151 | | - // Hosts |
152 | | - List<Command> hostCommands = new ArrayList<Command>(); |
153 | | - hostCommands.add(new AssignHostsToGroupsCommand()); |
154 | | - map.put("mlAssignHostsToGroups", hostCommands); |
155 | | - |
156 | | - // Forests |
157 | | - List<Command> forestCommands = new ArrayList<Command>(); |
158 | | - forestCommands.add(new DeployCustomForestsCommand()); |
159 | | - map.put("mlForestCommands", forestCommands); |
160 | | - |
161 | | - // Forest replicas |
162 | | - List<Command> replicaCommands = new ArrayList<Command>(); |
163 | | - replicaCommands.add(new ConfigureForestReplicasCommand()); |
164 | | - map.put("mlForestReplicaCommands", replicaCommands); |
165 | | - |
166 | | - // Plugins |
167 | | - List<Command> pluginCommands = new ArrayList<>(); |
168 | | - pluginCommands.add(new InstallPluginsCommand()); |
169 | | - map.put("mlPluginCommands", pluginCommands); |
| 189 | + List<Command> moduleCommands = new ArrayList<>(); |
| 190 | + moduleCommands.add(new LoadModulesCommand()); |
| 191 | + moduleCommands.add(new DeleteTestModulesCommand()); |
| 192 | + map.put("mlModuleCommands", moduleCommands); |
170 | 193 |
|
171 | | - // Tasks |
172 | | - List<Command> taskCommands = new ArrayList<Command>(); |
173 | | - taskCommands.add(new DeployScheduledTasksCommand()); |
174 | | - taskCommands.add(new UpdateTaskServerCommand()); |
175 | | - map.put("mlTaskCommands", taskCommands); |
| 194 | + List<Command> schemaCommands = new ArrayList<>(); |
| 195 | + schemaCommands.add(new LoadSchemasCommand()); |
| 196 | + map.put("mlSchemaCommands", schemaCommands); |
176 | 197 |
|
177 | | - // Temporal |
178 | 198 | List<Command> temporalCommands = new ArrayList<>(); |
179 | 199 | temporalCommands.add(new DeployTemporalAxesCommand()); |
180 | 200 | temporalCommands.add(new DeployTemporalCollectionsCommand()); |
181 | 201 | temporalCommands.add(new DeployTemporalCollectionsLSQTCommand()); |
182 | 202 | map.put("mlTemporalCommands", temporalCommands); |
183 | 203 |
|
184 | | - // Triggers |
185 | 204 | List<Command> triggerCommands = new ArrayList<Command>(); |
186 | 205 | triggerCommands.add(new DeployTriggersCommand()); |
187 | 206 | map.put("mlTriggerCommands", triggerCommands); |
188 | 207 |
|
189 | | - |
190 | | - // SQL Views |
191 | 208 | List<Command> viewCommands = new ArrayList<Command>(); |
192 | 209 | viewCommands.add(new DeployViewSchemasCommand()); |
193 | 210 | map.put("mlViewCommands", viewCommands); |
194 | | - |
195 | | - return map; |
196 | 211 | } |
197 | 212 | } |
0 commit comments