Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
7.9 KiB

  1. #include "stdafx.h"
  2. #include "ServList.hpp"
  3. #include "globals.h"
  4. #include "resstr.h"
  5. #include "resource.h"
  6. #import "VarSet.tlb" no_namespace, named_guids rename("property", "aproperty")
  7. extern GlobalData gData;
  8. //----------------------------------------------------------------------------
  9. // Function: QueryStatusFromFile
  10. //
  11. // Synopsis: Query the job status from the status file
  12. //
  13. // Arguments:
  14. //
  15. // statusFilename the name of the status file
  16. //
  17. // Returns:
  18. //
  19. // Modifies: Call SetFinished and SetSeverity functions
  20. //
  21. //----------------------------------------------------------------------------
  22. void TServerNode::QueryStatusFromFile(WCHAR* statusFilename)
  23. {
  24. if (bHasQueriedStatusFromFile)
  25. return;
  26. try
  27. {
  28. IVarSetPtr pVarSet;
  29. IStoragePtr store;
  30. HRESULT hr = S_OK;
  31. BOOL bDoneTry = FALSE;
  32. SetQueryFailed(FALSE);
  33. // attempt to open status file
  34. while (TRUE)
  35. {
  36. hr = StgOpenStorage(statusFilename,
  37. NULL,
  38. STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,
  39. NULL,
  40. 0,
  41. &store);
  42. // if sharing or lock violation then...
  43. if ((hr == STG_E_SHAREVIOLATION) || (hr == STG_E_LOCKVIOLATION))
  44. {
  45. // wait 30 seconds before trying again
  46. if (bDoneTry)
  47. break;
  48. Sleep(30000);
  49. bDoneTry = TRUE; // we only try once
  50. }
  51. else
  52. {
  53. // otherwise stop trying
  54. break;
  55. }
  56. }
  57. // load varset from file and check the status
  58. if (SUCCEEDED(hr))
  59. {
  60. hr = OleLoad(store, IID_IVarSet, NULL, (void**)&pVarSet);
  61. if (SUCCEEDED(hr))
  62. {
  63. bHasQueriedStatusFromFile = TRUE;
  64. _bstr_t jobStatus = pVarSet->get(GET_BSTR(DCTVS_JobStatus));
  65. if (!UStrICmp(jobStatus,GET_STRING(IDS_DCT_Status_Completed)))
  66. SetFinished();
  67. else if (!UStrICmp(jobStatus,GET_STRING(IDS_DCT_Status_Completed_With_Errors)))
  68. {
  69. SetFinished();
  70. SetSeverity(2);
  71. }
  72. }
  73. else
  74. SetQueryFailed(TRUE);
  75. }
  76. else
  77. SetQueryFailed(TRUE);
  78. }
  79. catch (...)
  80. {
  81. SetQueryFailed(TRUE);
  82. }
  83. }
  84. void TServerNode::QueryStatusFromFile()
  85. {
  86. if (bHasQueriedStatusFromFile)
  87. return;
  88. try
  89. {
  90. _bstr_t remoteResultPath = GetRemoteResultPath();
  91. _bstr_t statusFilename = remoteResultPath + GetJobID();
  92. QueryStatusFromFile(statusFilename);
  93. }
  94. catch (...)
  95. {
  96. SetQueryFailed(TRUE);
  97. }
  98. }
  99. //----------------------------------------------------------------------------
  100. // Function: PrepareForLogging
  101. //
  102. // Synopsis: Prepare the status and error message for logging agent
  103. // completion status into migration log.
  104. // The logic is taken from COLUMN_STATUS and COLUMN_MESSAGE parts
  105. // of CAgentMonitorDlg::OnGetdispinfoServerlist.
  106. // Due to the fact that this code is added for RTM, the minimum
  107. // change is preferred to prevent behavioral regression.
  108. // These two codes should be consolidated after ADMT v2.
  109. //
  110. // Arguments:
  111. //
  112. // Returns:
  113. //
  114. // Modifies: It updates the bstrStatusForLogging, bstrErrorMessageForLogging
  115. // and dwStatusForLogging member variables.
  116. //
  117. //----------------------------------------------------------------------------
  118. void TServerNode::PrepareForLogging()
  119. {
  120. CString status;
  121. status.LoadString(IDS_Status_Installing);
  122. dwStatusForLogging = Completion_Status_Installing;
  123. if (HasFailed())
  124. {
  125. status.LoadString(IDS_Status_InstallFailed);
  126. dwStatusForLogging = Completion_Status_InstallFailed;
  127. }
  128. if (IsInstalled())
  129. {
  130. if (!HasFailed())
  131. {
  132. status.LoadString(IDS_Status_Installed);
  133. dwStatusForLogging = Completion_Status_Installed;
  134. }
  135. else
  136. {
  137. status.LoadString(IDS_Status_DidNotStart);
  138. dwStatusForLogging = Completion_Status_DidNotStart;
  139. }
  140. }
  141. if (GetStatus() & Agent_Status_Started)
  142. {
  143. if (!HasFailed())
  144. {
  145. status.LoadString(IDS_Status_Running);
  146. dwStatusForLogging = Completion_Status_Running;
  147. }
  148. else
  149. {
  150. status.LoadString(IDS_Status_Failed);
  151. dwStatusForLogging = Completion_Status_StatusUnknown;
  152. }
  153. }
  154. if (IsFinished())
  155. {
  156. if (QueryFailed())
  157. {
  158. // we show "Status Unknown" in the status field
  159. status.LoadString(IDS_Status_Unknown);
  160. dwStatusForLogging = Completion_Status_StatusUnknown;
  161. }
  162. else if (!IsResultPullingTried() || (HasResult() && !IsResultProcessed()))
  163. {
  164. // if still pulling results or results not yet processed
  165. // we want to show the status of still running
  166. status.LoadString(IDS_Status_Running);
  167. dwStatusForLogging = Completion_Status_Running;
  168. }
  169. else
  170. {
  171. if (!HasResult())
  172. {
  173. // if there is no result, we consider it an error
  174. status.LoadString(IDS_Status_Completed_With_Errors);
  175. dwStatusForLogging = Completion_Status_CompletedWithErrors;
  176. }
  177. else if (!GetSeverity())
  178. {
  179. // if we have the result and no error happened during agent operation
  180. // we show the status of complete
  181. status.LoadString(IDS_Status_Completed);
  182. dwStatusForLogging = Completion_Status_Completed;
  183. }
  184. else
  185. {
  186. // if we have the result, we set the status
  187. // based on the error/warning level
  188. switch (GetSeverity())
  189. {
  190. case 1:
  191. status.LoadString(IDS_Status_Completed_With_Warnings);
  192. dwStatusForLogging = Completion_Status_CompletedWithWarnings;
  193. break;
  194. case 2:
  195. case 3:
  196. default:
  197. status.LoadString(IDS_Status_Completed_With_Errors);
  198. dwStatusForLogging = Completion_Status_CompletedWithErrors;
  199. break;
  200. }
  201. }
  202. }
  203. }
  204. bstrStatusForLogging = (LPCWSTR)status;
  205. // this part deals with the error message
  206. status = L""; // reset the status
  207. if (IsFinished() && QueryFailed())
  208. {
  209. // in this case, we show the error during the query
  210. status = GetMessageText();
  211. }
  212. else if (IsFinished()
  213. && (!IsResultPullingTried()
  214. || (HasResult() && !IsResultProcessed())))
  215. {
  216. // if agent has finished but result not yet pulled or processed,
  217. // we show the status of "still processing results"
  218. status.LoadString(IDS_Status_Processing_Results);
  219. }
  220. else if (IsFinished() && IsResultPullingTried() && !HasResult())
  221. {
  222. // if agent finished but we cannot retrieve results
  223. // we show the status of "cannot retrieve results"
  224. status.LoadString(IDS_Status_Cannot_Retrieve_Results);
  225. }
  226. else if (HasFailed() || QueryFailed() || GetSeverity() || IsFinished())
  227. {
  228. // for these cases, we get the message stored on the node
  229. status = GetMessageText();
  230. }
  231. bstrErrorMessageForLogging = (LPCWSTR)status;
  232. }