Dispatcher.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * Dispatcher.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. *
  14. */
  15. import java.math.BigInteger;
  16. import java.rmi.RemoteException;
  17. import com.cognos.developer.schemas.bibus._3.AuditLevelEnum;
  18. import com.cognos.developer.schemas.bibus._3.AuditLevelEnumProp;
  19. import com.cognos.developer.schemas.bibus._3.BaseClass;
  20. import com.cognos.developer.schemas.bibus._3.Dispatcher_Type;
  21. import com.cognos.developer.schemas.bibus._3.NonNegativeIntegerProp;
  22. import com.cognos.developer.schemas.bibus._3.OrderEnum;
  23. import com.cognos.developer.schemas.bibus._3.PingReply;
  24. import com.cognos.developer.schemas.bibus._3.PropEnum;
  25. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  26. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  27. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  28. import com.cognos.developer.schemas.bibus._3.Sort;
  29. import com.cognos.developer.schemas.bibus._3.UpdateOptions;
  30. public class Dispatcher {
  31. // get available Dispatchers according to the specified search path
  32. public BaseClassWrapper[] getDispatcherInfo(CRNConnect Con,
  33. String searchPath) {
  34. BaseClassWrapper[] dispatcherInfo = null;
  35. if ((searchPath == null) || (searchPath.length() == 0)
  36. || (searchPath.compareTo("") == 0)) {
  37. System.out.println("Invalid searchPath"
  38. + System.getProperty("line.separator"));
  39. return null;
  40. }
  41. // Search properties: we need the defaultName and the searchPath.
  42. PropEnum[] properties = { PropEnum.defaultName, PropEnum.searchPath };
  43. // Sort options: ascending sort on the defaultName property.
  44. Sort[] sortBy = { new Sort() };
  45. sortBy[0].setOrder(OrderEnum.ascending);
  46. sortBy[0].setPropName(PropEnum.defaultName);
  47. // Query options; use the defaults.
  48. QueryOptions options = new QueryOptions();
  49. try {
  50. BaseClass[] results = Con.getCMService().query(
  51. new SearchPathMultipleObject(searchPath), properties,
  52. sortBy, options);
  53. if (results != null && results.length > 0) {
  54. dispatcherInfo = new BaseClassWrapper[results.length];
  55. for (int i = 0; i < results.length; i++) {
  56. dispatcherInfo[i] = new BaseClassWrapper(results[i]);
  57. }
  58. }
  59. } catch (RemoteException remoteEx) {
  60. System.out.println("The request threw an RMI exception:");
  61. System.out.println(remoteEx.getMessage());
  62. System.out.println("Stack trace:");
  63. remoteEx.printStackTrace();
  64. return null;
  65. }
  66. return dispatcherInfo;
  67. }
  68. // Get available dispatchers' search path
  69. public String[] getAvailableDispatcher(CRNConnect Con, String searchPath) {
  70. String[] dispatcherList = null;
  71. BaseClassWrapper[] availableDispatcher = getDispatcherInfo(Con,
  72. searchPath);
  73. if (availableDispatcher != null && availableDispatcher.length > 0) {
  74. dispatcherList = new String[availableDispatcher.length];
  75. for (int n = 0; n < availableDispatcher.length; n++) {
  76. dispatcherList[n] = availableDispatcher[n].getBaseClassObject()
  77. .getSearchPath().getValue();
  78. }
  79. }
  80. return dispatcherList;
  81. }
  82. // get Services name
  83. public BaseClassWrapper[] getService(CRNConnect Con, String searchPath) {
  84. BaseClassWrapper[] serviceList = null;
  85. int count = 0;
  86. BaseClassWrapper[] myServiceList = getDispatcherInfo(Con, searchPath);
  87. if (myServiceList != null && myServiceList.length > 0) {
  88. serviceList = new BaseClassWrapper[myServiceList.length];
  89. for (int i = 0; i < myServiceList.length; i++) {
  90. String serviceName = myServiceList[i].toString();
  91. // filter some components that are not Service
  92. if (serviceName.indexOf("installedComponent") == -1
  93. && serviceName.indexOf("Service") != -1) {
  94. serviceList[count] = myServiceList[i];
  95. count++;
  96. }
  97. }
  98. }
  99. return serviceList;
  100. }
  101. // method uses to ping dispatcher
  102. public String getDispatcherVersion(CRNConnect Con, String dispSearchPathURL) {
  103. // sn_dg_sdk_method_dispatcher_ping_start_0
  104. String pingResult = null;
  105. SearchPathSingleObject myDispSearchPath = new SearchPathSingleObject(
  106. dispSearchPathURL);
  107. try {
  108. PingReply pingReplyResult = Con.getDispatcherService().ping(
  109. myDispSearchPath);
  110. if (pingReplyResult != null) {
  111. pingResult = pingReplyResult.getVersion();
  112. }
  113. // sn_dg_sdk_method_dispatcher_ping_end_0
  114. } catch (RemoteException re) {
  115. System.out
  116. .println("Error calling Ping method: "
  117. + re.getMessage());
  118. }
  119. return pingResult;
  120. }
  121. // method uses to get dispatcher status
  122. public Dispatcher_Type getDispatcherStatus(CRNConnect Con,
  123. String dispSearchPathURL) {
  124. BaseClass[] bcDispatcher = null;
  125. Dispatcher_Type dispatcherStatus = null;
  126. SearchPathMultipleObject myDispSearchPath = new SearchPathMultipleObject(
  127. dispSearchPathURL);
  128. // set properties
  129. PropEnum[] props = new PropEnum[5];
  130. props[0] = PropEnum.searchPath;
  131. props[1] = PropEnum.dispatcherPath;
  132. props[2] = PropEnum.rsAffineConnections;
  133. props[3] = PropEnum.asAuditLevel;
  134. props[4] = PropEnum.brsMaximumProcesses;
  135. try {
  136. bcDispatcher = Con.getCMService().query(myDispSearchPath, props,
  137. new Sort[] {}, new QueryOptions());
  138. if (bcDispatcher != null && bcDispatcher.length > 0) {
  139. dispatcherStatus = (Dispatcher_Type) bcDispatcher[0];
  140. }
  141. } catch (RemoteException re) {
  142. System.out
  143. .println("Error getting Dispatcher status: "
  144. + re.getMessage());
  145. return null;
  146. }
  147. return dispatcherStatus;
  148. }
  149. // method uses to start service
  150. public boolean startService(CRNConnect Con, String dispSearchPathURL) {
  151. // sn_dg_sdk_method_dispatcher_startService_start_0
  152. SearchPathSingleObject myDispSearchPath = new SearchPathSingleObject(
  153. dispSearchPathURL);
  154. try {
  155. Con.getDispatcherService().startService(myDispSearchPath);
  156. // sn_dg_sdk_method_dispatcher_startService_end_0
  157. } catch (RemoteException re) {
  158. System.out.println("Error starting service: "
  159. + re.getMessage());
  160. return false;
  161. }
  162. return true;
  163. }
  164. // method uses to stop service
  165. public boolean stopService(CRNConnect Con, String dispSearchPathURL) {
  166. // sn_dg_sdk_method_dispatcher_stopService_start_0
  167. SearchPathSingleObject myDispSearchPath = new SearchPathSingleObject(
  168. dispSearchPathURL);
  169. try {
  170. Con.getDispatcherService().stopService(myDispSearchPath, true);
  171. // sn_dg_sdk_method_dispatcher_stopService_end_0
  172. } catch (RemoteException re) {
  173. System.out.println("Error stopping service: "
  174. + re.getMessage());
  175. return false;
  176. }
  177. return true;
  178. }
  179. // method uses to set logging level
  180. public String setLoggingLevel(CRNConnect Con, String dispSearchPathURL,
  181. String serviceName, String mySettingLevel) {
  182. String updatedLevelResult = null;
  183. BaseClass[] bcLoggingLevel = null;
  184. BaseClass[] setLoggingLevelResult = null;
  185. // Array of available services
  186. String[] arrOfServices = { "AgentService", "BatchReportService",
  187. "ContentManagerService", "DataIntegrationService",
  188. "dispatcher", "DeliveryService", "EventManagementService",
  189. "IndexDataService", "IndexSearchService", "IndexUpdateService",
  190. "JobService", "MobileService", "MetadataService",
  191. "MetricsManagerService", "MonitorService",
  192. "PlanningAdministrationConsoleService",
  193. "PlanningRuntimeService", "PresentationService",
  194. "PlanningTaskService", "reportDataService", "ReportService",
  195. "SystemService" };
  196. // set the logging level
  197. AuditLevelEnumProp auditLevelProp = new AuditLevelEnumProp();
  198. if (mySettingLevel.equalsIgnoreCase("Minimal")) {
  199. auditLevelProp.setValue(AuditLevelEnum.minimal);
  200. } else if (mySettingLevel.equalsIgnoreCase("Basic")) {
  201. auditLevelProp.setValue(AuditLevelEnum.basic);
  202. } else if (mySettingLevel.equalsIgnoreCase("Request")) {
  203. auditLevelProp.setValue(AuditLevelEnum.request);
  204. } else if (mySettingLevel.equalsIgnoreCase("Trace")) {
  205. auditLevelProp.setValue(AuditLevelEnum.trace);
  206. } else if (mySettingLevel.equalsIgnoreCase("Full")) {
  207. auditLevelProp.setValue(AuditLevelEnum.full);
  208. }
  209. Dispatcher_Type myDispatcherType = this.getDispatcherStatus(Con,
  210. dispSearchPathURL);
  211. if (myDispatcherType != null) {
  212. // setting logging level for different Services
  213. if (serviceName.compareToIgnoreCase(arrOfServices[0]) == 0) {
  214. myDispatcherType.setAsAuditLevel(auditLevelProp);
  215. } else if (serviceName.compareToIgnoreCase(arrOfServices[1]) == 0) {
  216. myDispatcherType.setBrsAuditLevel(auditLevelProp);
  217. } else if (serviceName.compareToIgnoreCase(arrOfServices[2]) == 0) {
  218. myDispatcherType.setCmsAuditLevel(auditLevelProp);
  219. } else if (serviceName.compareToIgnoreCase(arrOfServices[3]) == 0) {
  220. myDispatcherType.setDisAuditLevel(auditLevelProp);
  221. } else if (serviceName.compareToIgnoreCase(arrOfServices[4]) == 0) {
  222. myDispatcherType.setDispatcherAuditLevel(auditLevelProp);
  223. } else if (serviceName.compareToIgnoreCase(arrOfServices[5]) == 0) {
  224. myDispatcherType.setDsAuditLevel(auditLevelProp);
  225. } else if (serviceName.compareToIgnoreCase(arrOfServices[6]) == 0) {
  226. myDispatcherType.setEmsAuditLevel(auditLevelProp);
  227. } else if (serviceName.compareToIgnoreCase(arrOfServices[7]) == 0) {
  228. myDispatcherType.setIdsAuditLevel(auditLevelProp);
  229. } else if (serviceName.compareToIgnoreCase(arrOfServices[8]) == 0) {
  230. myDispatcherType.setIssAuditLevel(auditLevelProp);
  231. } else if (serviceName.compareToIgnoreCase(arrOfServices[9]) == 0) {
  232. myDispatcherType.setIusAuditLevel(auditLevelProp);
  233. } else if (serviceName.compareToIgnoreCase(arrOfServices[10]) == 0) {
  234. myDispatcherType.setJsAuditLevel(auditLevelProp);
  235. } else if (serviceName.compareToIgnoreCase(arrOfServices[11]) == 0) {
  236. myDispatcherType.setMbsAuditLevel(auditLevelProp);
  237. } else if (serviceName.compareToIgnoreCase(arrOfServices[12]) == 0) {
  238. myDispatcherType.setMdsAuditLevel(auditLevelProp);
  239. } else if (serviceName.compareToIgnoreCase(arrOfServices[13]) == 0) {
  240. myDispatcherType.setMmsAuditLevel(auditLevelProp);
  241. } else if (serviceName.compareToIgnoreCase(arrOfServices[14]) == 0) {
  242. myDispatcherType.setMsAuditLevel(auditLevelProp);
  243. } else if (serviceName.compareToIgnoreCase(arrOfServices[15]) == 0) {
  244. myDispatcherType.setPacsAuditLevel(auditLevelProp);
  245. } else if (serviceName.compareToIgnoreCase(arrOfServices[16]) == 0) {
  246. myDispatcherType.setPrsAuditLevel(auditLevelProp);
  247. } else if (serviceName.compareToIgnoreCase(arrOfServices[17]) == 0) {
  248. myDispatcherType.setPsAuditLevel(auditLevelProp);
  249. } else if (serviceName.compareToIgnoreCase(arrOfServices[18]) == 0) {
  250. myDispatcherType.setPtsAuditLevel(auditLevelProp);
  251. } else if (serviceName.compareToIgnoreCase(arrOfServices[19]) == 0) {
  252. myDispatcherType.setRdsAuditLevel(auditLevelProp);
  253. } else if (serviceName.compareToIgnoreCase(arrOfServices[20]) == 0) {
  254. myDispatcherType.setRsAuditLevel(auditLevelProp);
  255. } else if (serviceName.compareToIgnoreCase(arrOfServices[21]) == 0) {
  256. myDispatcherType.setSsAuditLevel(auditLevelProp);
  257. }
  258. } else {
  259. return null;
  260. }
  261. bcLoggingLevel = new BaseClass[1];
  262. bcLoggingLevel[0] = myDispatcherType;
  263. try {
  264. // update logging level for selected Service
  265. setLoggingLevelResult = Con.getCMService().update(bcLoggingLevel,
  266. new UpdateOptions());
  267. if (setLoggingLevelResult != null
  268. && setLoggingLevelResult.length > 0) {
  269. updatedLevelResult = setLoggingLevelResult[0].getStoreID()
  270. .getValue().get_value();
  271. }
  272. } catch (RemoteException re) {
  273. System.out
  274. .println("Error setting logging level: "
  275. + re.getMessage());
  276. return null;
  277. }
  278. return updatedLevelResult;
  279. }
  280. // method uses to set maximum number of processes for Batch Report Service
  281. public String setMaxProcesses(CRNConnect Con, String dispSearchPathURL,
  282. String myServiceName, String maxProcessesNum) {
  283. String updatedProcessNumResult = null;
  284. BaseClass[] bcMaxProcesses = null;
  285. BaseClass[] setMaxProcessesResult = null;
  286. // set maximum number of processes
  287. NonNegativeIntegerProp processNum = new NonNegativeIntegerProp();
  288. BigInteger myNum = new BigInteger(maxProcessesNum);
  289. processNum.setValue(myNum);
  290. Dispatcher_Type myDispatcherType = this.getDispatcherStatus(Con,
  291. dispSearchPathURL);
  292. if (myDispatcherType != null) {
  293. if (myServiceName.equalsIgnoreCase("BatchReportService")) {
  294. myDispatcherType.setBrsMaximumProcesses(processNum);
  295. } else if (myServiceName.equalsIgnoreCase("ReportService")) {
  296. myDispatcherType.setRsMaximumProcesses(processNum);
  297. }
  298. } else {
  299. return null;
  300. }
  301. bcMaxProcesses = new BaseClass[1];
  302. bcMaxProcesses[0] = myDispatcherType;
  303. try {
  304. setMaxProcessesResult = Con.getCMService().update(bcMaxProcesses,
  305. new UpdateOptions());
  306. if (setMaxProcessesResult != null
  307. && setMaxProcessesResult.length > 0) {
  308. updatedProcessNumResult = setMaxProcessesResult[0].getStoreID()
  309. .getValue().get_value();
  310. }
  311. } catch (RemoteException re) {
  312. System.out
  313. .println("Error setting Maximum Processes: "
  314. + re.getMessage());
  315. return null;
  316. }
  317. return updatedProcessNumResult;
  318. }
  319. }