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.

703 lines
19 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterGroup.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterGroup class
  10. //
  11. // Maintained by:
  12. // Ozan Ozhan (OzanO) 26-NOV-2002
  13. // Henry Wang (HenryWa) 24-AUG-1999
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "Pch.h"
  17. #include "ClusterGroup.h"
  18. #include "ClusterGroup.tmh"
  19. //****************************************************************************
  20. //
  21. // CClusterGroup
  22. //
  23. //****************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //++
  26. //
  27. // CClusterGroup::CClusterGroup
  28. //
  29. // Description:
  30. // Constructor.
  31. //
  32. // Arguments:
  33. // pwszNameIn -- Class name
  34. // pNamespaceIn -- Namespace
  35. //
  36. // Return Values:
  37. // None.
  38. //
  39. //--
  40. //////////////////////////////////////////////////////////////////////////////
  41. CClusterGroup::CClusterGroup(
  42. LPCWSTR pwszNameIn,
  43. CWbemServices * pNamespaceIn
  44. )
  45. : CProvBase( pwszNameIn, pNamespaceIn )
  46. {
  47. } //*** CClusterGroup::CClusterGroup()
  48. //////////////////////////////////////////////////////////////////////////////
  49. //++
  50. //
  51. // static
  52. // CClusterGroup::S_CreateThis
  53. //
  54. // Description:
  55. // Create a CClusterGroup object.
  56. //
  57. // Arguments:
  58. // pwszNameIn -- Class name
  59. // pNamespaceIn -- Namespace
  60. // dwEnumTypeIn -- Type id
  61. //
  62. // Return Values:
  63. // pointer to the CProvBase
  64. //
  65. //--
  66. //////////////////////////////////////////////////////////////////////////////
  67. CProvBase *
  68. CClusterGroup::S_CreateThis(
  69. LPCWSTR pwszNameIn,
  70. CWbemServices * pNamespaceIn,
  71. DWORD dwEnumTypeIn
  72. )
  73. {
  74. TracePrint(("CClusterGroup::S_CreatThis for Name = %ws, EnumType %u\n", pwszNameIn, dwEnumTypeIn ));
  75. return new CClusterGroup( pwszNameIn, pNamespaceIn );
  76. } //*** CClusterGroup::S_CreateThis()
  77. //////////////////////////////////////////////////////////////////////////////
  78. //++
  79. //
  80. // CClusterGroup::GetPropMap
  81. //
  82. // Description:
  83. // Retrieve the property maping table of the cluster group.
  84. //
  85. // Arguments:
  86. // None.
  87. //
  88. // Return Values:
  89. // Reference to the array of property maping table.
  90. //
  91. //--
  92. //////////////////////////////////////////////////////////////////////////////
  93. const SPropMapEntryArray *
  94. CClusterGroup::RgGetPropMap( void )
  95. {
  96. static SPropMapEntry s_rgpm[] =
  97. {
  98. {
  99. NULL,
  100. CLUSREG_NAME_GRP_LOADBAL_STATE,
  101. DWORD_TYPE,
  102. READWRITE
  103. }
  104. };
  105. static SPropMapEntryArray s_pamea(
  106. sizeof( s_rgpm ) / sizeof( SPropMapEntry ),
  107. s_rgpm
  108. );
  109. return &s_pamea;
  110. } //*** CClusterGroup::GetPropMap()
  111. //////////////////////////////////////////////////////////////////////////////
  112. //++
  113. //
  114. // CClusterGroup::EnumInstance
  115. //
  116. // Description:
  117. // Enum cluster instance.
  118. //
  119. // Arguments:
  120. // lFlagsIn -- WMI flag
  121. // pCtxIn -- WMI context
  122. // pHandlerIn -- WMI sink pointer
  123. //
  124. // Return Values:
  125. // WBEM_S_NO_ERROR
  126. //
  127. //--
  128. //////////////////////////////////////////////////////////////////////////////
  129. SCODE
  130. CClusterGroup::EnumInstance(
  131. long lFlagsIn,
  132. IWbemContext * pCtxIn,
  133. IWbemObjectSink * pHandlerIn
  134. )
  135. {
  136. SAFECLUSTER shCluster;
  137. SAFEGROUP shGroup;
  138. LPCWSTR pwszGroup;
  139. TracePrint(( "CClusterGroup::EnumInstance, pHandlerIn = %p\n", pHandlerIn ));
  140. shCluster = OpenCluster( NULL );
  141. CClusterEnum cluEnum( shCluster, CLUSTER_ENUM_GROUP );
  142. while ( ( pwszGroup = cluEnum.GetNext() ) != NULL )
  143. {
  144. shGroup = OpenClusterGroup( shCluster, pwszGroup );
  145. ClusterToWMI( shGroup, pHandlerIn );
  146. } // while: more groups
  147. return WBEM_S_NO_ERROR;
  148. } //*** CClusterGroup::EnumInstance()
  149. //////////////////////////////////////////////////////////////////////////////
  150. //++
  151. //
  152. // CClusterGroup::ClusterToWMI
  153. //
  154. // Description:
  155. // Translate a cluster group object to WMI object.
  156. //
  157. // Arguments:
  158. // hGroupIn -- Handle to group
  159. // pHandlerIn -- Handler
  160. //
  161. // Return Values:
  162. // None.
  163. //
  164. //--
  165. //////////////////////////////////////////////////////////////////////////////
  166. void
  167. CClusterGroup::ClusterToWMI(
  168. HGROUP hGroupIn,
  169. IWbemObjectSink * pHandlerIn
  170. )
  171. {
  172. static SGetControl s_rgControl[] =
  173. {
  174. { CLUSCTL_GROUP_GET_RO_COMMON_PROPERTIES, FALSE },
  175. { CLUSCTL_GROUP_GET_COMMON_PROPERTIES, FALSE },
  176. { CLUSCTL_GROUP_GET_RO_PRIVATE_PROPERTIES, TRUE },
  177. { CLUSCTL_GROUP_GET_PRIVATE_PROPERTIES, TRUE }
  178. };
  179. static UINT s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  180. CError er;
  181. UINT idx;
  182. CWbemClassObject wco;
  183. m_pClass->SpawnInstance( 0, &wco );
  184. for ( idx = 0 ; idx < s_cControl ; idx++ )
  185. {
  186. CClusPropList pl;
  187. er = pl.ScGetGroupProperties(
  188. hGroupIn,
  189. s_rgControl[ idx ].dwControl,
  190. NULL,
  191. 0
  192. );
  193. CClusterApi::GetObjectProperties(
  194. RgGetPropMap(),
  195. pl,
  196. wco,
  197. s_rgControl[ idx ].fPrivate
  198. );
  199. } // for: each common property type
  200. //
  201. // flags and characteristics
  202. //
  203. {
  204. DWORD cbReturned;
  205. DWORD dwOut;
  206. DWORD dwState;
  207. er = ClusterGroupControl(
  208. hGroupIn,
  209. NULL,
  210. CLUSCTL_GROUP_GET_CHARACTERISTICS,
  211. NULL,
  212. 0,
  213. &dwOut,
  214. sizeof( DWORD ),
  215. &cbReturned
  216. );
  217. wco.SetProperty(
  218. dwOut,
  219. PVD_PROP_CHARACTERISTIC
  220. );
  221. dwState = GetClusterGroupState(
  222. hGroupIn,
  223. NULL,
  224. NULL
  225. );
  226. wco.SetProperty( dwState, PVD_PROP_GROUP_STATE );
  227. }
  228. pHandlerIn->Indicate( 1, &wco );
  229. return;
  230. } //*** CClusterGroup::ClusterToWMI()
  231. //////////////////////////////////////////////////////////////////////////////
  232. //++
  233. //
  234. // CClusterGroup::GetObject
  235. //
  236. // Description:
  237. // Retrieve cluster group object based given object path.
  238. //
  239. // Arguments:
  240. // rObjPathIn -- Object path to cluster object
  241. // lFlagsIn -- WMI flag
  242. // pCtxIn -- WMI context
  243. // pHandlerIn -- WMI sink pointer
  244. //
  245. // Return Values:
  246. // WBEM_S_NO_ERROR
  247. //
  248. //--
  249. //////////////////////////////////////////////////////////////////////////////
  250. SCODE
  251. CClusterGroup::GetObject(
  252. CObjPath & rObjPathIn,
  253. long lFlagsIn,
  254. IWbemContext * pCtxIn,
  255. IWbemObjectSink * pHandlerIn
  256. )
  257. {
  258. SAFECLUSTER shCluster;
  259. SAFEGROUP shGroup;
  260. shCluster = OpenCluster( NULL );
  261. shGroup = OpenClusterGroup(
  262. shCluster,
  263. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  264. );
  265. ClusterToWMI( shGroup, pHandlerIn );
  266. return WBEM_S_NO_ERROR;
  267. } //*** CClusterGroup::GetObject()
  268. //////////////////////////////////////////////////////////////////////////////
  269. //++
  270. //
  271. // CClusterGroup::ExecuteMethod
  272. //
  273. // Description:
  274. // Execute methods defined in the mof for cluster node.
  275. //
  276. // Arguments:
  277. // rObjPathIn -- Object path to cluster object
  278. // pwszMethodNameIn -- Name of the method to be invoked
  279. // lFlagIn -- WMI flag
  280. // pParamsIn -- Input parameters for the method
  281. // pHandlerIn -- WMI sink pointer
  282. //
  283. // Return Values:
  284. // WBEM_S_NO_ERROR
  285. //
  286. //--
  287. //////////////////////////////////////////////////////////////////////////////
  288. SCODE
  289. CClusterGroup::ExecuteMethod(
  290. CObjPath & rObjPathIn,
  291. WCHAR * pwszMethodNameIn,
  292. long lFlagIn,
  293. IWbemClassObject * pParamsIn,
  294. IWbemObjectSink * pHandlerIn
  295. )
  296. {
  297. SAFECLUSTER shCluster;
  298. SAFEGROUP shGroup;
  299. CWbemClassObject InArgs( pParamsIn );
  300. CError er;
  301. shCluster = OpenCluster( NULL );
  302. //
  303. // static method
  304. //
  305. if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_CREATEGROUP ) == 0 )
  306. {
  307. _bstr_t bstrNewGroup;
  308. InArgs.GetProperty( bstrNewGroup, PVD_MTH_GROUP_PARM_GROUPNAME );
  309. shGroup = CreateClusterGroup( shCluster, bstrNewGroup );
  310. er = HrWrapOnlineClusterGroup( shCluster, shGroup );
  311. } // if: CREATEGROUP
  312. else
  313. {
  314. shGroup = OpenClusterGroup(
  315. shCluster,
  316. rObjPathIn.GetStringValueForProperty( PVD_PROP_GROUP_NAME )
  317. );
  318. if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_DELETEGROUP ) == 0 )
  319. {
  320. er = DeleteClusterGroup( shGroup );
  321. }
  322. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_TAKEOFFLINE ) == 0 )
  323. {
  324. DWORD dwTimeOut = 0;
  325. InArgs.GetProperty( &dwTimeOut, PVD_MTH_GROUP_PARM_TIMEOUT );
  326. er = HrWrapOfflineClusterGroup( shCluster, shGroup, dwTimeOut );
  327. } // if: TAKEOFFLINE
  328. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_BRINGONLINE ) == 0 )
  329. {
  330. DWORD dwTimeOut = 0;
  331. InArgs.GetProperty( &dwTimeOut, PVD_MTH_GROUP_PARM_TIMEOUT );
  332. er = HrWrapOnlineClusterGroup( shCluster, shGroup, NULL, dwTimeOut );
  333. } // else if: BRINGONLINE
  334. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_MOVETONEWNODE ) == 0 )
  335. {
  336. _bstr_t bstrNewNode;
  337. SAFENODE shNode;
  338. DWORD dwTimeOut = 0;
  339. InArgs.GetProperty( &dwTimeOut, PVD_MTH_GROUP_PARM_TIMEOUT );
  340. InArgs.GetProperty( bstrNewNode, PVD_MTH_GROUP_PARM_NODENAME );
  341. shNode = OpenClusterNode( shCluster, bstrNewNode );
  342. er = HrWrapMoveClusterGroup( shCluster, shGroup, shNode, dwTimeOut );
  343. } // else if: MOVETONEWNODE
  344. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_GROUP_RENAME ) == 0 )
  345. {
  346. _bstr_t bstrNewName;
  347. InArgs.GetProperty( bstrNewName, PVD_MTH_GROUP_PARM_NEWNAME );
  348. er = SetClusterGroupName( shGroup, bstrNewName );
  349. } // else if: RENAME
  350. else
  351. {
  352. er = static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER );
  353. }
  354. } // else: not create new group
  355. return WBEM_S_NO_ERROR;
  356. } //*** CClusterGroup::ExecuteMethod()
  357. //////////////////////////////////////////////////////////////////////////////
  358. //++
  359. //
  360. // CClusterGroup::PutInstance
  361. //
  362. // Description:
  363. // Save this instance.
  364. //
  365. // Arguments:
  366. // rInstToPutIn -- WMI object to be saved
  367. // lFlagIn -- WMI flag
  368. // pCtxIn -- WMI context
  369. // pHandlerIn -- WMI sink pointer
  370. //
  371. // Return Values:
  372. // WBEM_S_NO_ERROR
  373. //
  374. //--
  375. //////////////////////////////////////////////////////////////////////////////
  376. SCODE
  377. CClusterGroup::PutInstance(
  378. CWbemClassObject & rInstToPutIn,
  379. long lFlagIn,
  380. IWbemContext * pCtxIn,
  381. IWbemObjectSink * pHandlerIn
  382. )
  383. {
  384. static SGetSetControl s_rgControl[] =
  385. {
  386. {
  387. CLUSCTL_GROUP_GET_COMMON_PROPERTIES,
  388. CLUSCTL_GROUP_SET_COMMON_PROPERTIES,
  389. FALSE
  390. },
  391. {
  392. CLUSCTL_GROUP_GET_PRIVATE_PROPERTIES,
  393. CLUSCTL_GROUP_SET_PRIVATE_PROPERTIES,
  394. TRUE
  395. }
  396. };
  397. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  398. _bstr_t bstrName;
  399. SAFECLUSTER shCluster;
  400. SAFEGROUP shGroup;
  401. CError er;
  402. UINT idx;
  403. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NAME );
  404. shCluster = OpenCluster( NULL );
  405. shGroup = OpenClusterGroup( shCluster, bstrName );
  406. for ( idx = 0 ; idx < s_cControl ; idx++ )
  407. {
  408. CClusPropList plOld;
  409. CClusPropList plNew;
  410. er = plOld.ScGetGroupProperties(
  411. shGroup,
  412. s_rgControl[ idx ].dwGetControl,
  413. NULL,
  414. NULL,
  415. 0
  416. );
  417. CClusterApi::SetObjectProperties(
  418. NULL,
  419. plNew,
  420. plOld,
  421. rInstToPutIn,
  422. s_rgControl[ idx ].fPrivate
  423. );
  424. if ( plNew.Cprops() > 0 )
  425. {
  426. er = ClusterGroupControl(
  427. shGroup,
  428. NULL,
  429. s_rgControl[ idx ].dwSetControl,
  430. plNew.PbPropList(),
  431. static_cast< DWORD >( plNew.CbPropList() ),
  432. NULL,
  433. 0,
  434. NULL
  435. );
  436. }
  437. } // for: each control code
  438. return WBEM_S_NO_ERROR;
  439. } //*** CClusterGroup::PutInstance()
  440. //////////////////////////////////////////////////////////////////////////////
  441. //++
  442. //
  443. // CClusterGroup::DeleteInstance
  444. //
  445. // Description:
  446. // Delete the object specified in rObjPathIn.
  447. //
  448. // Arguments:
  449. // rObjPathIn -- ObjPath for the instance to be deleted
  450. // lFlagIn -- WMI flag
  451. // pCtxIn -- WMI context
  452. // pHandlerIn -- WMI sink pointer
  453. //
  454. // Return Values:
  455. // WBEM_S_NO_ERROR
  456. //
  457. //--
  458. //////////////////////////////////////////////////////////////////////////////
  459. SCODE
  460. CClusterGroup::DeleteInstance(
  461. CObjPath & rObjPathIn,
  462. long lFlagIn,
  463. IWbemContext * pCtxIn,
  464. IWbemObjectSink * pHandlerIn
  465. )
  466. {
  467. SAFECLUSTER shCluster;
  468. SAFEGROUP shGroup;
  469. CError er;
  470. shCluster = OpenCluster( NULL );
  471. shGroup = OpenClusterGroup(
  472. shCluster,
  473. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  474. );
  475. er = DeleteClusterGroup( shGroup );
  476. return WBEM_S_NO_ERROR;
  477. } //*** CClusterGroup::DeleteInstance()
  478. //****************************************************************************
  479. //
  480. // CClusterGroupRes
  481. //
  482. //****************************************************************************
  483. //////////////////////////////////////////////////////////////////////////////
  484. //++
  485. //
  486. // CClusterGroupRes::CClusterGroupRes
  487. //
  488. // Description:
  489. // Constructor.
  490. //
  491. // Arguments:
  492. // pwszNameIn -- Class name
  493. // pNamespaceIn -- Namespace
  494. // dwEnumTypeIn -- Type id
  495. //
  496. // Return Values:
  497. // None.
  498. //
  499. //--
  500. //////////////////////////////////////////////////////////////////////////////
  501. CClusterGroupRes::CClusterGroupRes(
  502. LPCWSTR pwszNameIn,
  503. CWbemServices * pNamespaceIn,
  504. DWORD dwEnumTypeIn
  505. )
  506. : CClusterObjAssoc( pwszNameIn, pNamespaceIn, dwEnumTypeIn )
  507. {
  508. } //*** CClusterGroupRes::CClusterGroupRes()
  509. //////////////////////////////////////////////////////////////////////////////
  510. //++
  511. //
  512. // static
  513. // CClusterGroupRes::S_CreateThis
  514. //
  515. // Description:
  516. // Create a cluster node object
  517. //
  518. // Arguments:
  519. // pwszNameIn -- Class name
  520. // pNamespaceIn -- Namespace
  521. // dwEnumTypeIn -- Type id
  522. //
  523. // Return Values:
  524. // pointer to the CProvBase
  525. //
  526. //--
  527. //////////////////////////////////////////////////////////////////////////////
  528. CProvBase *
  529. CClusterGroupRes::S_CreateThis(
  530. LPCWSTR pwszNameIn,
  531. CWbemServices * pNamespaceIn,
  532. DWORD dwEnumTypeIn
  533. )
  534. {
  535. return new CClusterGroupRes(
  536. pwszNameIn,
  537. pNamespaceIn,
  538. dwEnumTypeIn
  539. );
  540. } //*** CClusterGroupRes::S_CreateThis()
  541. //////////////////////////////////////////////////////////////////////////////
  542. //++
  543. //
  544. // CClusterGroupRes::EnumInstance
  545. //
  546. // Description:
  547. // Retrieve the property maping table of the cluster node active resource.
  548. //
  549. // Arguments:
  550. // lFlagsIn --
  551. // pCtxIn --
  552. // pHandlerIn --
  553. //
  554. // Return Values:
  555. // SCODE
  556. //
  557. //--
  558. //////////////////////////////////////////////////////////////////////////////
  559. SCODE
  560. CClusterGroupRes::EnumInstance(
  561. long lFlagsIn,
  562. IWbemContext * pCtxIn,
  563. IWbemObjectSink * pHandlerIn
  564. )
  565. {
  566. SAFECLUSTER shCluster;
  567. SAFEGROUP shGroup;
  568. SAFERESOURCE shResource;
  569. LPCWSTR pwszName = NULL;
  570. DWORD cchGroupName = MAX_PATH;
  571. CWstrBuf wsbGroupName;
  572. DWORD cch;
  573. CError er;
  574. DWORD dwError;
  575. CWbemClassObject wcoGroup;
  576. CWbemClassObject wcoPart;
  577. _bstr_t bstrGroup;
  578. _bstr_t bstrPart;
  579. wsbGroupName.SetSize( cchGroupName );
  580. shCluster = OpenCluster( NULL );
  581. CClusterEnum clusEnum( shCluster, m_dwEnumType );
  582. m_wcoGroup.SpawnInstance( 0, &wcoGroup );
  583. m_wcoPart.SpawnInstance( 0, &wcoPart );
  584. while ( ( pwszName = clusEnum.GetNext() ) != NULL )
  585. {
  586. CWbemClassObject wco;
  587. DWORD dwState;
  588. cch = cchGroupName;
  589. wcoPart.SetProperty( pwszName, PVD_PROP_RES_NAME );
  590. wcoPart.GetProperty( bstrPart, PVD_WBEM_RELPATH );
  591. shResource = OpenClusterResource( shCluster, pwszName );
  592. dwState = GetClusterResourceState(
  593. shResource,
  594. NULL,
  595. 0,
  596. wsbGroupName,
  597. &cch
  598. );
  599. if ( dwState == ClusterResourceStateUnknown )
  600. {
  601. dwError = GetLastError();
  602. if ( dwError == ERROR_MORE_DATA )
  603. {
  604. cchGroupName = ++cch;
  605. wsbGroupName.SetSize( cch );
  606. dwState = GetClusterResourceState(
  607. shResource,
  608. NULL,
  609. 0,
  610. wsbGroupName,
  611. &cch
  612. );
  613. } // if: more data
  614. else
  615. {
  616. er = dwError;
  617. }
  618. } // if: state unknown
  619. wcoGroup.SetProperty( wsbGroupName, CLUSREG_NAME_GRP_NAME );
  620. wcoGroup.GetProperty( bstrGroup, PVD_WBEM_RELPATH );
  621. m_pClass->SpawnInstance( 0, &wco );
  622. wco.SetProperty( (LPWSTR) bstrGroup, PVD_PROP_GROUPCOMPONENT );
  623. wco.SetProperty( (LPWSTR) bstrPart, PVD_PROP_PARTCOMPONENT );
  624. pHandlerIn->Indicate( 1, &wco );
  625. } // while: more resources
  626. return WBEM_S_NO_ERROR;
  627. } //*** CClusterGroupRes::EnumInstance()