WUManager.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. // WUManager.cpp : Defines the entry point for the console application.
  14. //
  15. //#include "stdafx.h"
  16. #include <stdio.h>
  17. #include "jlib.hpp"
  18. #include "ws_workunits.hpp"
  19. #include "ws_workunits_esp.ipp"
  20. void diaplaySyntax()
  21. {
  22. printf("Usage:\n");
  23. printf(" WUManager EXPORT <URL> <dest-file-path>\n");
  24. printf("Security: /UserName:name -- UserName to authenticate access to service\n");
  25. printf(" /Password:password -- Password to authenticate access to service\n\n");
  26. printf("Filters: /Cluster:name -- WUs run on this cluster\n");
  27. printf(" /Owner:name -- WUs with this owner\n");
  28. printf(" /StartDate:yyyymmdd -- WUs created on or after this date\n");
  29. printf(" /EndDate:yyyymmdd -- WUs created on or before this date\n");
  30. printf(" /State:flag -- WUs with this state\n");
  31. printf("State Flags:\n");
  32. printf(" unknown\n");
  33. printf(" compiled\n");
  34. printf(" running\n");
  35. printf(" completed\n");
  36. printf(" failed\n");
  37. printf(" archived\n");
  38. printf(" aborting\n");
  39. printf(" aborted\n");
  40. printf(" blocked\n");
  41. printf("Example:\n");
  42. printf(" WUManager EXPORT http://server:8010/WsWorkunits Mylocalfile.xml /UserName:jsmith /Password:12345 /StartDate:20030701");
  43. }
  44. int main(int argc, char* argv[])
  45. {
  46. InitModuleObjects();
  47. if (argc < 3 || (argv[1][1]=='?') || (argv[1][2]=='?') )
  48. {
  49. diaplaySyntax();
  50. return 0;
  51. }
  52. StringBuffer file,url,action,username,password,cluster,owner,start,end,state;
  53. if(argc >= 2 && argv[1])
  54. {
  55. action.append(argv[1]);
  56. }
  57. else
  58. {
  59. printf("You must define an action");
  60. return 0;
  61. }
  62. if(argc >= 3 && argv[2])
  63. url.append(argv[2]);
  64. else
  65. {
  66. printf("You must define an SMC server to query");
  67. return 0 ;
  68. }
  69. if(argc >= 4 && argv[3])
  70. {
  71. file.append(argv[3]);
  72. }
  73. else
  74. {
  75. printf("You must specify an output file to write the WU information to.");
  76. return 0 ;
  77. }
  78. for (int i=4;i<argc;i++) {
  79. char* delim = strstr(argv[i],":");
  80. if (delim)
  81. {
  82. if (strstr(argv[i],"UserName")!=0)
  83. username.append( delim+1);
  84. else if (strstr(argv[i],"Password")!=0)
  85. password.append(delim+1);
  86. else if (strstr(argv[i],"Cluster")!=0)
  87. cluster.append(delim+1);
  88. else if (strstr(argv[i],"Owner")!=0)
  89. owner.append(delim+1);
  90. else if (strstr(argv[i],"StartDate")!=0)
  91. start.append(delim+1);
  92. else if (strstr(argv[i],"EndDate")!=0)
  93. end.append(delim+1);
  94. else if (strstr(argv[i],"State")!=0)
  95. state.append(delim+1);
  96. }
  97. }
  98. if (stricmp(action.str(),"EXPORT") == 0)
  99. {
  100. try
  101. {
  102. Owned<IFile> _file = createIFile(file.str());
  103. if (_file->exists() == true)
  104. {
  105. printf("A file exists at %s. Do you wish to replace it (y/n)?",file.str());
  106. int ch = getchar();
  107. if (ch=='n' || ch=='N')
  108. return 0;
  109. }
  110. Owned<IFileIO> _fileio = _file->open(IFOcreate);
  111. Owned<IClientWsWorkunits> pServer = new CClientWsWorkunits();
  112. pServer->addServiceUrl(url.str());
  113. pServer->setUsernameToken(username.str(),password.str(),"");
  114. Owned<IClientWUExportRequest> req = pServer->createWUExportRequest();
  115. req->setCluster(cluster.str());
  116. req->setEndDate(end.str());
  117. req->setOwner(owner.str());
  118. req->setStartDate(start.str());
  119. req->setState(state.str());
  120. printf("Processing request....");
  121. Owned<IClientWUExportResponse> resp = pServer->WUExport(req);
  122. __int64 _bytesWritten = _fileio->write(0, resp->getExportData().length(), resp->getExportData().toByteArray());
  123. printf("Write to file %s is complete.", file.str() );
  124. }
  125. catch(IException* e)
  126. {
  127. StringBuffer errorStr;
  128. e->errorMessage(errorStr);
  129. printf("Exception %s thrown while generate export file",errorStr.str());
  130. return 0;
  131. }
  132. catch(...)
  133. {
  134. printf("Unknown exception thrown while generate export file");
  135. return 0;
  136. }
  137. }
  138. else
  139. printf("Unknown action %s",action.str());
  140. releaseAtoms();
  141. return 0;
  142. }