Source code of Windows XP (NT5)
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.

331 lines
7.9 KiB

  1. #include "WLBS_Provider.h"
  2. #include "WLBS_NodeNodeSetting.h"
  3. #include "ClusterWrapper.h"
  4. #include "ControlWrapper.h"
  5. #include "utils.h"
  6. ////////////////////////////////////////////////////////////////////////////////
  7. //
  8. // CWLBS_NodeNodeSetting::CWLBS_NodeNodeSetting
  9. //
  10. // Purpose: Constructor
  11. //
  12. ////////////////////////////////////////////////////////////////////////////////
  13. CWLBS_NodeNodeSetting::CWLBS_NodeNodeSetting(CWbemServices* a_pNameSpace,
  14. IWbemObjectSink* a_pResponseHandler)
  15. : CWlbs_Root( a_pNameSpace, a_pResponseHandler )
  16. {
  17. }
  18. ////////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CWLBS_NodeNodeSetting::Create
  21. //
  22. // Purpose: This instantiates this class and is invoked from an array of
  23. // function pointers.
  24. //
  25. ////////////////////////////////////////////////////////////////////////////////
  26. CWlbs_Root* CWLBS_NodeNodeSetting::Create
  27. (
  28. CWbemServices* a_pNameSpace,
  29. IWbemObjectSink* a_pResponseHandler
  30. )
  31. {
  32. g_pWlbsControl->CheckMembership();
  33. CWlbs_Root* pRoot = new CWLBS_NodeNodeSetting( a_pNameSpace, a_pResponseHandler );
  34. if( !pRoot )
  35. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  36. return pRoot;
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////
  39. //
  40. // CWLBS_NodeNodeSetting::GetInstance
  41. //
  42. // Purpose:
  43. //
  44. ////////////////////////////////////////////////////////////////////////////////
  45. HRESULT CWLBS_NodeNodeSetting::GetInstance
  46. (
  47. const ParsedObjectPath* /* a_pParsedPath */,
  48. long /* a_lFlags */,
  49. IWbemContext* /* a_pIContex */
  50. )
  51. {
  52. IWbemClassObject* pWlbsInstance = NULL;
  53. HRESULT hRes = 0;
  54. try {
  55. //TODO: remove
  56. throw _com_error( WBEM_E_NOT_SUPPORTED );
  57. //get the node
  58. //FindInstance( &pWlbsInstance, a_pParsedPath );
  59. //send the results back to WinMgMt
  60. m_pResponseHandler->Indicate( 1, &pWlbsInstance );
  61. if( pWlbsInstance ) {
  62. pWlbsInstance->Release();
  63. pWlbsInstance = NULL;
  64. }
  65. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  66. hRes = WBEM_S_NO_ERROR;
  67. }
  68. catch(CErrorWlbsControl Err) {
  69. IWbemClassObject* pWbemExtStat = NULL;
  70. CreateExtendedStatus( m_pNameSpace,
  71. &pWbemExtStat,
  72. Err.Error(),
  73. (PWCHAR)(Err.Description()) );
  74. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  75. if( pWbemExtStat )
  76. pWbemExtStat->Release();
  77. if( pWlbsInstance )
  78. pWlbsInstance->Release();
  79. //do not return WBEM_E_FAILED, this causes a race condition
  80. hRes = WBEM_S_NO_ERROR;
  81. }
  82. catch(_com_error HResErr ) {
  83. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  84. if( pWlbsInstance )
  85. pWlbsInstance->Release();
  86. hRes = HResErr.Error();
  87. }
  88. catch(...) {
  89. if( pWlbsInstance )
  90. pWlbsInstance->Release();
  91. throw;
  92. }
  93. return hRes;
  94. }
  95. ////////////////////////////////////////////////////////////////////////////////
  96. //
  97. // CWLBS_NodeNodeSetting::EnumInstances
  98. //
  99. // Purpose: This verifies node existence and constructs associator.
  100. //
  101. ////////////////////////////////////////////////////////////////////////////////
  102. HRESULT CWLBS_NodeNodeSetting::EnumInstances
  103. (
  104. BSTR /* a_bstrClass */,
  105. long /* a_lFlags */,
  106. IWbemContext* /* a_pIContex */
  107. )
  108. {
  109. IWbemClassObject* pWlbsInstance = NULL;
  110. HRESULT hRes = 0;
  111. try {
  112. DWORD dwNumClusters = 0;
  113. CWlbsClusterWrapper** ppCluster = NULL;
  114. g_pWlbsControl->EnumClusters(ppCluster, &dwNumClusters);
  115. if (dwNumClusters == 0)
  116. {
  117. throw _com_error( WBEM_E_NOT_FOUND );
  118. }
  119. for (DWORD i=0; i < dwNumClusters; i++)
  120. {
  121. //spawn an instance of the associator
  122. SpawnInstance(MOF_NODENODESETTING::szName, &pWlbsInstance );
  123. FillWbemInstance(ppCluster[i] , pWlbsInstance);
  124. //send the results back to WinMgMt
  125. hRes= m_pResponseHandler->Indicate( 1, &pWlbsInstance );
  126. if( FAILED( hRes ) ) {
  127. throw _com_error( hRes );
  128. }
  129. if( pWlbsInstance )
  130. pWlbsInstance->Release();
  131. }
  132. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  133. hRes = WBEM_S_NO_ERROR;
  134. }
  135. catch(CErrorWlbsControl Err) {
  136. IWbemClassObject* pWbemExtStat = NULL;
  137. CreateExtendedStatus( m_pNameSpace,
  138. &pWbemExtStat,
  139. Err.Error(),
  140. (PWCHAR)(Err.Description()) );
  141. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  142. if( pWbemExtStat )
  143. pWbemExtStat->Release();
  144. if( pWlbsInstance )
  145. pWlbsInstance->Release();
  146. //do not return WBEM_E_FAILED, this causes a race condition
  147. hRes = WBEM_S_NO_ERROR;
  148. }
  149. catch(_com_error HResErr ) {
  150. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  151. if( pWlbsInstance )
  152. pWlbsInstance->Release();
  153. hRes = HResErr.Error();
  154. }
  155. catch(...) {
  156. if( pWlbsInstance )
  157. pWlbsInstance->Release();
  158. throw;
  159. }
  160. return hRes;
  161. }
  162. ////////////////////////////////////////////////////////////////////////////////
  163. //
  164. // CWLBS_NodeNodeSetting::FindInstance
  165. //
  166. // Purpose: This routine determines if a host is within the local cluster. If
  167. // it is, then the requested associator is returned.
  168. //
  169. ////////////////////////////////////////////////////////////////////////////////
  170. void CWLBS_NodeNodeSetting::FindInstance
  171. (
  172. IWbemClassObject** /*a_ppWbemInstance*/
  173. )
  174. {
  175. }
  176. ////////////////////////////////////////////////////////////////////////////////
  177. //
  178. // CWLBS_NodeNodeSetting::FillWbemInstance
  179. //
  180. // Purpose: This constructs the wbem associator.
  181. //
  182. ////////////////////////////////////////////////////////////////////////////////
  183. void CWLBS_NodeNodeSetting::FillWbemInstance
  184. (
  185. CWlbsClusterWrapper* pCluster,
  186. IWbemClassObject* a_pWbemInstance
  187. )
  188. {
  189. namespace NNS = MOF_NODENODESETTING;
  190. ASSERT( a_pWbemInstance );
  191. ParsedObjectPath NodeSetPath;
  192. ParsedObjectPath NodePath;
  193. LPWSTR szNodeSetPath = NULL;
  194. LPWSTR szNodePath = NULL;
  195. try {
  196. //set the names of the classes
  197. if( !NodeSetPath.SetClassName( MOF_NODESETTING::szName ) )
  198. throw _com_error( WBEM_E_FAILED );
  199. if( !NodePath.SetClassName( MOF_NODE::szName ) )
  200. throw _com_error( WBEM_E_FAILED );
  201. wstring wstrHostName;
  202. ConstructHostName( wstrHostName, pCluster->GetClusterIpOrIndex(g_pWlbsControl),
  203. pCluster->GetHostID() );
  204. //set the keys for the node and cluster
  205. if( !NodeSetPath.AddKeyRef( MOF_NODESETTING::pProperties[MOF_NODESETTING::NAME],
  206. &_variant_t(wstrHostName.c_str()) ) )
  207. throw _com_error( WBEM_E_FAILED );
  208. if( !NodePath.AddKeyRef( MOF_NODE::pProperties[MOF_NODE::NAME],
  209. &_variant_t(wstrHostName.c_str()) ) )
  210. throw _com_error( WBEM_E_FAILED );
  211. //convert parsed object paths to strings
  212. if (CObjectPathParser::Unparse(&NodeSetPath, &szNodeSetPath) != CObjectPathParser::NoError)
  213. throw _com_error( WBEM_E_FAILED );
  214. if (CObjectPathParser::Unparse(&NodePath, &szNodePath) != CObjectPathParser::NoError)
  215. throw _com_error( WBEM_E_FAILED );
  216. //Node reference
  217. HRESULT hRes = a_pWbemInstance->Put
  218. (
  219. _bstr_t( NNS::pProperties[NNS::NODESET] ),
  220. 0,
  221. &_variant_t(szNodeSetPath),
  222. NULL
  223. );
  224. if( FAILED( hRes ) )
  225. throw _com_error( hRes );
  226. //Cluster reference
  227. hRes = a_pWbemInstance->Put
  228. (
  229. _bstr_t( NNS::pProperties[NNS::NODE] ),
  230. 0,
  231. &_variant_t(szNodePath),
  232. NULL
  233. );
  234. if( FAILED( hRes ) )
  235. throw _com_error( hRes );
  236. //free resources
  237. NodePath.ClearKeys();
  238. NodeSetPath.ClearKeys();
  239. if( szNodePath )
  240. delete (szNodePath );
  241. if( szNodeSetPath )
  242. delete (szNodeSetPath);
  243. } catch (...) {
  244. NodePath.ClearKeys();
  245. NodeSetPath.ClearKeys();
  246. if( szNodePath )
  247. delete (szNodePath);
  248. if( szNodeSetPath )
  249. delete (szNodeSetPath);
  250. throw;
  251. }
  252. }