1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jumpmind.symmetric.service.jmx;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.FileOutputStream;
25 import java.util.Map;
26
27 import javax.sql.DataSource;
28
29 import org.apache.commons.dbcp.BasicDataSource;
30 import org.jumpmind.symmetric.model.Node;
31 import org.jumpmind.symmetric.service.IBootstrapService;
32 import org.jumpmind.symmetric.service.IClusterService;
33 import org.jumpmind.symmetric.service.IDataExtractorService;
34 import org.jumpmind.symmetric.service.IDataService;
35 import org.jumpmind.symmetric.service.INodeService;
36 import org.jumpmind.symmetric.service.IOutgoingBatchService;
37 import org.jumpmind.symmetric.service.IParameterService;
38 import org.jumpmind.symmetric.service.IPurgeService;
39 import org.jumpmind.symmetric.service.IRegistrationService;
40 import org.jumpmind.symmetric.transport.IOutgoingTransport;
41 import org.jumpmind.symmetric.transport.internal.InternalOutgoingTransport;
42 import org.springframework.jmx.export.annotation.ManagedAttribute;
43 import org.springframework.jmx.export.annotation.ManagedOperation;
44 import org.springframework.jmx.export.annotation.ManagedOperationParameter;
45 import org.springframework.jmx.export.annotation.ManagedOperationParameters;
46 import org.springframework.jmx.export.annotation.ManagedResource;
47
48 @Deprecated
49 @ManagedResource(description = "The management interface for SymmetricDS")
50 public class SymmetricManagementService {
51
52 private IBootstrapService bootstrapService;
53
54 private IParameterService parameterService;
55
56 private IPurgeService purgeService;
57
58 private INodeService nodeService;
59
60 private IDataService dataService;
61
62 private IOutgoingBatchService outgoingBatchService;
63
64 private IRegistrationService registrationService;
65
66 private IDataExtractorService dataExtractorService;
67
68 private IClusterService clusterService;
69
70 private DataSource dataSource;
71
72 @ManagedOperation(description = "Run the purge process")
73 public void purge() {
74 purgeService.purge();
75 }
76
77 @ManagedOperation(description = "Synchronize the triggers")
78 public void syncTriggers() {
79 bootstrapService.syncTriggers();
80 }
81
82 @ManagedAttribute(description = "The properties configured for this symmetric instance")
83 public String getPropertiesList() {
84 Map<String, String> properties = parameterService.getAllParameters();
85 StringBuilder buffer = new StringBuilder();
86 for (String key : properties.keySet()) {
87 buffer.append(key).append("=").append(properties.get(key)).append("<br/>");
88 }
89 return buffer.toString();
90 }
91
92 @ManagedAttribute(description = "The group this node belongs to")
93 public String getNodeGroupId() {
94 return parameterService.getNodeGroupId();
95 }
96
97 @ManagedAttribute(description = "An external name give to this symmetric node")
98 public String getExternalId() {
99 return parameterService.getExternalId();
100 }
101
102 @ManagedAttribute(description = "Whether the basic data source is being used as the default datasource.")
103 public boolean isBasicDataSource() {
104 return dataSource instanceof BasicDataSource;
105 }
106
107 @ManagedAttribute(description = "If a BasicDataSource, then show the number of active connections")
108 public int getNumberOfActiveConnections() {
109 if (isBasicDataSource()) {
110 return ((BasicDataSource) dataSource).getNumActive();
111 } else {
112 return -1;
113 }
114 }
115
116 @ManagedOperation(description = "Check to see if the external id is registered")
117 @ManagedOperationParameters( {
118 @ManagedOperationParameter(name = "nodeGroupId", description = "The node group id for a node"),
119 @ManagedOperationParameter(name = "externalId", description = "The external id for a node") })
120 public boolean isExternalIdRegistered(String nodeGroupdId, String externalId) {
121 return nodeService.isExternalIdRegistered(nodeGroupdId, externalId);
122 }
123
124 @ManagedOperation(description = "Emergency remove all locks (if left abandoned on a cluster)")
125 public void clearAllLocks() {
126 clusterService.clearAllLocks();
127 }
128
129 @Deprecated
130 @ManagedOperation(description = "Deprecated. Check to see if the external id is registered")
131 @ManagedOperationParameters( { @ManagedOperationParameter(name = "externalId", description = "The external id for a node") })
132 public boolean isExternalIdRegistered(String externalId) {
133 return nodeService.isExternalIdRegistered("store", externalId);
134 }
135
136 @ManagedOperation(description = "Check to see if the initial load for a node id is complete. This method will throw an exception if the load error'd out or was never started.")
137 @ManagedOperationParameters( { @ManagedOperationParameter(name = "nodeId", description = "The node id") })
138 public boolean isInitialLoadComplete(String nodeId) {
139 return outgoingBatchService.isInitialLoadComplete(nodeId);
140 }
141
142 @ManagedOperation(description = "Enable or disable synchronization completely for a node")
143 @ManagedOperationParameters( {
144 @ManagedOperationParameter(name = "nodeId", description = "The node to enable or disable"),
145 @ManagedOperationParameter(name = "syncEnabled", description = "true is enabled, false is disabled") })
146 public boolean setSyncEnabledForNode(String nodeId, boolean syncEnabled) {
147 Node node = nodeService.findNode(nodeId);
148 if (node != null) {
149 node.setSyncEnabled(syncEnabled);
150 nodeService.updateNode(node);
151 return true;
152 } else {
153 return false;
154 }
155 }
156
157 @Deprecated
158 @ManagedOperation(description = "Deprecated. Enable or disable a channel for a specific external id. ")
159 @ManagedOperationParameters( {
160 @ManagedOperationParameter(name = "ignore", description = "Set to true to enable and false to disable"),
161 @ManagedOperationParameter(name = "channelId", description = "The channel id to enable or disable"),
162 @ManagedOperationParameter(name = "externalId", description = "The external id for a node") })
163 public void ignoreNodeChannelForExternalId(boolean ignore, String channelId, String externalId) {
164 nodeService.ignoreNodeChannelForExternalId(ignore, channelId, "store", externalId);
165 }
166
167 @ManagedOperation(description = "Enable or disable a channel for a specific external id")
168 @ManagedOperationParameters( {
169 @ManagedOperationParameter(name = "ignore", description = "Set to true to enable and false to disable"),
170 @ManagedOperationParameter(name = "channelId", description = "The channel id to enable or disable"),
171 @ManagedOperationParameter(name = "nodeGroupId", description = "The node group id for a node"),
172 @ManagedOperationParameter(name = "externalId", description = "The external id for a node") })
173 public void ignoreNodeChannelForExternalId(boolean ignore, String channelId, String nodeGroupId, String externalId) {
174 nodeService.ignoreNodeChannelForExternalId(ignore, channelId, nodeGroupId, externalId);
175 }
176
177 @ManagedOperation(description = "Open the registration for a node with the specified external id")
178 @ManagedOperationParameters( {
179 @ManagedOperationParameter(name = "nodeGroup", description = "The node group id this node will belong to"),
180 @ManagedOperationParameter(name = "externalId", description = "The external id for the node") })
181 public void openRegistration(String nodeGroupId, String externalId) {
182 Node node = nodeService.findNodeByExternalId(nodeGroupId, externalId);
183 if (node != null) {
184 registrationService.reOpenRegistration(node.getExternalId());
185 } else {
186 registrationService.openRegistration(nodeGroupId, externalId);
187 }
188 }
189
190 @ManagedOperation(description = "Send an initial load of data to a node.")
191 @ManagedOperationParameters( { @ManagedOperationParameter(name = "nodeId", description = "The node id to reload.") })
192 public String reloadNode(String nodeId) {
193 return dataService.reloadNode(nodeId);
194 }
195
196 @ManagedOperation(description = "Send a SQL event to a node.")
197 @ManagedOperationParameters( {
198 @ManagedOperationParameter(name = "nodeId", description = "The node id to sent the event to."),
199 @ManagedOperationParameter(name = "tableName", description = "The table name the SQL is for."),
200 @ManagedOperationParameter(name = "sql", description = "The SQL statement to send.") })
201 public String sendSQL(String nodeId, String tableName, String sql) {
202 return dataService.sendSQL(nodeId, tableName, sql);
203 }
204
205 @ManagedOperation(description = "Send a delete and reload of a table to a node.")
206 @ManagedOperationParameters( { @ManagedOperationParameter(name = "nodeId", description = "The node id to reload."),
207 @ManagedOperationParameter(name = "tableName", description = "The table name to reload.") })
208 public String reloadTable(String nodeId, String tableName) {
209 return dataService.reloadTable(nodeId, tableName);
210 }
211
212 @ManagedOperation(description = "Send a delete and reload of a table to a node.")
213 @ManagedOperationParameters( {
214 @ManagedOperationParameter(name = "nodeId", description = "The node id to reload."),
215 @ManagedOperationParameter(name = "tableName", description = "The table name to reload."),
216 @ManagedOperationParameter(name = "overrideInitialLoadSelect", description = "Override initial load select where-clause.") })
217 public String reloadTable(String nodeId, String tableName, String overrideInitialLoadSelect) {
218 return dataService.reloadTable(nodeId, tableName, overrideInitialLoadSelect);
219 }
220
221 @ManagedOperation(description = "Show a batch in Symmetric Data Format.")
222 @ManagedOperationParameters( { @ManagedOperationParameter(name = "batchId", description = "The batch ID to display") })
223 public String showBatch(String batchId) throws Exception {
224 ByteArrayOutputStream out = new ByteArrayOutputStream();
225 IOutgoingTransport transport = new InternalOutgoingTransport(out);
226 dataExtractorService.extractBatchRange(transport, batchId, batchId);
227 transport.close();
228 out.close();
229 return out.toString();
230 }
231
232 @ManagedOperation(description = "Write a range of batches to a file in Symmetric Data Format.")
233 @ManagedOperationParameters( {
234 @ManagedOperationParameter(name = "startBatchId", description = "Starting batch ID of range"),
235 @ManagedOperationParameter(name = "endBatchId", description = "Ending batch ID of range"),
236 @ManagedOperationParameter(name = "fileName", description = "File name to write batches") })
237 public void writeBatchRangeToFile(String startBatchId, String endBatchId, String fileName) throws Exception {
238 FileOutputStream out = new FileOutputStream(fileName);
239 IOutgoingTransport transport = new InternalOutgoingTransport(out);
240 dataExtractorService.extractBatchRange(transport, startBatchId, endBatchId);
241 transport.close();
242 out.close();
243 }
244
245 public void setBootstrapService(IBootstrapService bootstrapService) {
246 this.bootstrapService = bootstrapService;
247 }
248
249 public void setPurgeService(IPurgeService purgeService) {
250 this.purgeService = purgeService;
251 }
252
253 public void setDataSource(DataSource dataSource) {
254 this.dataSource = dataSource;
255 }
256
257 public void setDataService(IDataService dataService) {
258 this.dataService = dataService;
259 }
260
261 public void setNodeService(INodeService nodeService) {
262 this.nodeService = nodeService;
263 }
264
265 public void setRegistrationService(IRegistrationService registrationService) {
266 this.registrationService = registrationService;
267 }
268
269 public void setOutgoingBatchService(IOutgoingBatchService outgoingBatchService) {
270 this.outgoingBatchService = outgoingBatchService;
271 }
272
273 public void setDataExtractorService(IDataExtractorService dataExtractorService) {
274 this.dataExtractorService = dataExtractorService;
275 }
276
277 public void setClusterService(IClusterService clusterService) {
278 this.clusterService = clusterService;
279 }
280
281 public void setParameterService(IParameterService parameterService) {
282 this.parameterService = parameterService;
283 }
284
285 }