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.

299 lines
6.9 KiB

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