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.

1943 lines
45 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusObj.h
  7. //
  8. // Implementation File:
  9. // ClusObj.h (this file) and ClusObj.cpp
  10. //
  11. // Description:
  12. // Definition of the CClusterObject classes.
  13. //
  14. // Author:
  15. // David Potter (davidp) April 7, 1998
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef __CLUSOBJ_H_
  23. #define __CLUSOBJ_H_
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Forward Class Declarations
  26. /////////////////////////////////////////////////////////////////////////////
  27. class CClusterObject;
  28. class CClusterInfo;
  29. class CClusNodeInfo;
  30. class CClusGroupInfo;
  31. class CClusResInfo;
  32. class CClusResTypeInfo;
  33. class CClusNetworkInfo;
  34. class CClusNetIFInfo;
  35. /////////////////////////////////////////////////////////////////////////////
  36. // External Class Declarations
  37. /////////////////////////////////////////////////////////////////////////////
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Include Files
  40. /////////////////////////////////////////////////////////////////////////////
  41. #ifndef _LIST_
  42. #include <list> // for std::list
  43. #endif
  44. #ifndef _CLUSTER_API_
  45. #include <ClusApi.h> // for cluster types
  46. #endif
  47. #ifndef __cluadmex_h__
  48. #include "CluAdmEx.h" // for CLUADMEX_OBJECT_TYPE
  49. #endif
  50. #ifndef _CLUSUDEF_H_
  51. #include "ClusUDef.h" // for default values
  52. #endif
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Type Definitions
  55. /////////////////////////////////////////////////////////////////////////////
  56. typedef std::list< CClusterObject * > CClusObjPtrList;
  57. typedef std::list< CClusterInfo * > CClusterPtrList;
  58. typedef std::list< CClusNodeInfo * > CClusNodePtrList;
  59. typedef std::list< CClusGroupInfo * > CClusGroupPtrList;
  60. typedef std::list< CClusResInfo * > CClusResPtrList;
  61. typedef std::list< CClusResTypeInfo * > CClusResTypePtrList;
  62. typedef std::list< CClusNetworkInfo * > CClusNetworkPtrList;
  63. typedef std::list< CClusNetIFInfo * > CClusNetIFPtrList;
  64. union CLUSTER_REQUIRED_DEPENDENCY
  65. {
  66. CLUSTER_RESOURCE_CLASS rc;
  67. LPWSTR pszTypeName;
  68. };
  69. /////////////////////////////////////////////////////////////////////////////
  70. //++
  71. //
  72. // class CClusterObject
  73. //
  74. // Description:
  75. // Base class for all cluster object classes. Provides base
  76. // functionality.
  77. //
  78. // Inheritance:
  79. // CClusterObject
  80. //
  81. //--
  82. /////////////////////////////////////////////////////////////////////////////
  83. class CClusterObject
  84. {
  85. friend class CWizardThread;
  86. public:
  87. //
  88. // Construction.
  89. //
  90. // Default constructor
  91. CClusterObject( IN CLUADMEX_OBJECT_TYPE cot )
  92. {
  93. ATLASSERT( cot > CLUADMEX_OT_NONE );
  94. m_nReferenceCount = 0;
  95. Reset( NULL, NULL, cot );
  96. } //*** CClusterObject()
  97. // Constructor taking group name
  98. CClusterObject(
  99. IN CLUADMEX_OBJECT_TYPE cot,
  100. IN CClusterInfo * pci,
  101. IN LPCTSTR pszName
  102. )
  103. {
  104. ATLASSERT( cot > CLUADMEX_OT_NONE );
  105. m_nReferenceCount = 0;
  106. Reset( pci, pszName, cot );
  107. } //*** CClusterObject(pszName)
  108. virtual ~CClusterObject( void )
  109. {
  110. } //*** ~CClusterObject()
  111. // Copy another object into this one.
  112. void Copy( IN const CClusterObject & rco )
  113. {
  114. m_pci = rco.m_pci;
  115. m_bQueried = rco.m_bQueried;
  116. m_bCreated = rco.m_bCreated;
  117. m_cot = rco.m_cot;
  118. m_strName = rco.m_strName;
  119. m_strDescription = rco.m_strDescription;
  120. } //*** Copy()
  121. // Reset the data back to default values
  122. void Reset(
  123. IN CClusterInfo * pci,
  124. IN LPCTSTR pszName = NULL,
  125. IN CLUADMEX_OBJECT_TYPE cot = CLUADMEX_OT_NONE
  126. )
  127. {
  128. m_pci = pci;
  129. m_bQueried = FALSE;
  130. m_bCreated = FALSE;
  131. if ( cot != CLUADMEX_OT_NONE )
  132. {
  133. m_cot = cot;
  134. } // if: valid object type specified
  135. if ( pszName == NULL )
  136. {
  137. m_strName.Empty();
  138. } // if: no name specified
  139. else
  140. {
  141. m_strName = pszName;
  142. } // else: name specified
  143. m_strDescription.Empty();
  144. } //*** Reset()
  145. protected:
  146. //
  147. // Reference counting properties.
  148. //
  149. ULONG m_nReferenceCount;
  150. public:
  151. //
  152. // Reference counting methods.
  153. //
  154. // Get the current count of references
  155. ULONG NReferenceCount( void ) const { return m_nReferenceCount; }
  156. // Add a reference to this object
  157. ULONG AddRef( void )
  158. {
  159. ATLASSERT( m_nReferenceCount != (ULONG) -1 );
  160. return ++m_nReferenceCount;
  161. } //*** AddRef()
  162. // Release a reference to this object
  163. ULONG Release( void )
  164. {
  165. ULONG nReferenceCount;
  166. ATLASSERT( m_nReferenceCount != 0 );
  167. nReferenceCount = --m_nReferenceCount;
  168. if ( m_nReferenceCount == 0 )
  169. {
  170. delete this;
  171. } // if: no more references
  172. return nReferenceCount;
  173. } //*** Release()
  174. protected:
  175. //
  176. // Properties of a cluster object.
  177. //
  178. CClusterInfo * m_pci;
  179. BOOL m_bQueried;
  180. BOOL m_bCreated;
  181. CLUADMEX_OBJECT_TYPE
  182. m_cot;
  183. CString m_strName;
  184. CString m_strDescription;
  185. // Set query state
  186. BOOL BSetQueried( BOOL bQueried = TRUE )
  187. {
  188. BOOL bPreviousValue = m_bQueried;
  189. m_bQueried = bQueried;
  190. return bPreviousValue;
  191. } //*** BSetQueried()
  192. // Set created state
  193. BOOL BSetCreated( BOOL bCreated = TRUE )
  194. {
  195. BOOL bPreviousValue = m_bCreated;
  196. m_bCreated = bCreated;
  197. return bPreviousValue;
  198. } //*** BSetCreated()
  199. public:
  200. //
  201. // Accessor functions for cluster object properties.
  202. //
  203. CClusterInfo * Pci( void ) const { ATLASSERT( m_pci != NULL ); return m_pci; }
  204. BOOL BQueried( void ) const { return m_bQueried; }
  205. BOOL BCreated( void ) const { return m_bCreated; }
  206. CLUADMEX_OBJECT_TYPE Cot( void ) const { return m_cot; }
  207. const CString & RstrName( void ) const { return m_strName; }
  208. const CString & RstrDescription( void ) const { return m_strDescription; }
  209. // Set the cluster info pointer
  210. void SetClusterInfo( IN CClusterInfo * pci )
  211. {
  212. ATLASSERT( pci != NULL );
  213. ATLASSERT( m_pci == NULL );
  214. m_pci = pci;
  215. } //*** SetClusterInfo()
  216. // Set the name of the cluster object.
  217. void SetName( IN LPCTSTR pszName )
  218. {
  219. ATLASSERT( pszName != NULL );
  220. m_strName = pszName;
  221. } //*** SetName()
  222. // Set the description of the cluster object
  223. void SetDescription( IN LPCTSTR pszDescription )
  224. {
  225. ATLASSERT( pszDescription != NULL );
  226. m_strDescription = pszDescription;
  227. } //*** SetDescription()
  228. // Return the list of extensions for this object
  229. virtual const std::list< CString > * PlstrAdminExtensions( void ) const { return NULL; }
  230. }; //*** class CClusterObject
  231. /////////////////////////////////////////////////////////////////////////////
  232. //++
  233. //
  234. // class CClusterInfo
  235. //
  236. // Description:
  237. // Class for the information about the cluster object itself. Treats
  238. // the cluster as an object like other objects.
  239. //
  240. // Inheritance:
  241. // CClusterInfo
  242. // CClusterObject
  243. //
  244. // Notes:
  245. // 1) m_hCluster is not owned by this class.
  246. //
  247. //--
  248. /////////////////////////////////////////////////////////////////////////////
  249. class CClusterInfo : public CClusterObject
  250. {
  251. friend class CWizardThread;
  252. public:
  253. //
  254. // Construction.
  255. //
  256. // Default constructor
  257. CClusterInfo( void )
  258. : CClusterObject( CLUADMEX_OT_CLUSTER )
  259. {
  260. Reset();
  261. } //*** CClusterInfo()
  262. // Constructor taking cluster name
  263. CClusterInfo( IN LPCTSTR pszName )
  264. : CClusterObject( CLUADMEX_OT_CLUSTER, NULL, pszName )
  265. {
  266. Reset( pszName );
  267. } //*** CClusterInfo( pszName )
  268. // Copy another object into this one.
  269. void Copy( IN const CClusterInfo & rci )
  270. {
  271. CClusterObject::Copy( rci );
  272. m_hCluster = rci.m_hCluster;
  273. } //*** Copy()
  274. // Reset the data back to default values
  275. void Reset( IN LPCTSTR pszName = NULL )
  276. {
  277. CClusterObject::Reset( NULL, pszName, CLUADMEX_OT_CLUSTER );
  278. m_hCluster = NULL;
  279. } //*** Reset()
  280. protected:
  281. //
  282. // Properties of a cluster.
  283. //
  284. HCLUSTER m_hCluster;
  285. std::list< CString > m_lstrClusterAdminExtensions;
  286. std::list< CString > m_lstrNodesAdminExtensions;
  287. std::list< CString > m_lstrGroupsAdminExtensions;
  288. std::list< CString > m_lstrResourcesAdminExtensions;
  289. std::list< CString > m_lstrResTypesAdminExtensions;
  290. std::list< CString > m_lstrNetworksAdminExtensions;
  291. std::list< CString > m_lstrNetInterfacesAdminExtensions;
  292. public:
  293. //
  294. // Accessor functions for cluster properties.
  295. //
  296. HCLUSTER Hcluster( void )
  297. {
  298. ATLASSERT( m_hCluster != NULL );
  299. return m_hCluster;
  300. } //*** Hcluster()
  301. // Set the cluster handle managed by this object
  302. void SetClusterHandle( IN HCLUSTER hCluster )
  303. {
  304. ATLASSERT( hCluster != NULL );
  305. m_hCluster = hCluster;
  306. } //*** SetClusterHandle()
  307. const std::list< CString > * PlstrAdminExtensions( void ) const { return &m_lstrClusterAdminExtensions; }
  308. const std::list< CString > * PlstrNodesAdminExtensions( void ) const { return &m_lstrNodesAdminExtensions; }
  309. const std::list< CString > * PlstrGroupsAdminExtensions( void ) const { return &m_lstrGroupsAdminExtensions; }
  310. const std::list< CString > * PlstrResourcesAdminExtensions( void ) const { return &m_lstrResourcesAdminExtensions; }
  311. const std::list< CString > * PlstrResTypesAdminExtensions( void ) const { return &m_lstrResTypesAdminExtensions; }
  312. const std::list< CString > * PlstrNetworksAdminExtensions( void ) const { return &m_lstrNetworksAdminExtensions; }
  313. const std::list< CString > * PlstrNetInterfacesAdminExtensions( void ) const { return &m_lstrNetInterfacesAdminExtensions; }
  314. }; //*** class CClusterInfo
  315. /////////////////////////////////////////////////////////////////////////////
  316. //++
  317. //
  318. // class CClusNodeInfo
  319. //
  320. // Description:
  321. // Cluster node object.
  322. //
  323. // Inheritance:
  324. // CClusNodeInfo
  325. // CClusterObject
  326. //
  327. //--
  328. /////////////////////////////////////////////////////////////////////////////
  329. class CClusNodeInfo : public CClusterObject
  330. {
  331. friend class CWizardThread;
  332. public:
  333. //
  334. // Construction.
  335. //
  336. // Default constructor
  337. CClusNodeInfo( void )
  338. : CClusterObject( CLUADMEX_OT_NODE )
  339. , m_hNode( NULL )
  340. {
  341. Reset( NULL );
  342. } //*** CClusNodeInfo()
  343. // Constructor taking cluster info pointer
  344. CClusNodeInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  345. : CClusterObject( CLUADMEX_OT_NODE, pci, pszName )
  346. , m_hNode( NULL )
  347. {
  348. Reset( pci, pszName );
  349. } //*** CClusNodeInfo( pci )
  350. ~CClusNodeInfo( void )
  351. {
  352. Close();
  353. } //*** ~CClusNodeInfo()
  354. // Operator = is not allowed
  355. CClusNodeInfo & operator=( IN const CClusNodeInfo & rni )
  356. {
  357. ATLASSERT( FALSE );
  358. return *this;
  359. } //*** operator=()
  360. // Reset the data back to default values
  361. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  362. {
  363. Close();
  364. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_NODE );
  365. } //*** Reset()
  366. protected:
  367. //
  368. // Properties of a node.
  369. //
  370. HNODE m_hNode;
  371. public:
  372. //
  373. // Accessor functions for node properties.
  374. //
  375. HNODE Hnode( void ) { return m_hNode; }
  376. // Return the list of extensions for nodes
  377. const std::list< CString > * PlstrAdminExtensions( void ) const
  378. {
  379. ATLASSERT( Pci() != NULL );
  380. return Pci()->PlstrNodesAdminExtensions();
  381. } //*** PlstrAdminExtensions()
  382. public:
  383. //
  384. // Operations.
  385. //
  386. // Open the object
  387. DWORD ScOpen( void )
  388. {
  389. ATLASSERT( m_pci != NULL );
  390. ATLASSERT( m_pci->Hcluster() != NULL );
  391. ATLASSERT( m_hNode == NULL );
  392. ATLASSERT( m_strName.GetLength() > 0 );
  393. DWORD sc = ERROR_SUCCESS;
  394. //
  395. // Open a handle to the object.
  396. //
  397. m_hNode = OpenClusterNode( m_pci->Hcluster(), m_strName );
  398. if ( m_hNode == NULL )
  399. {
  400. sc = GetLastError();
  401. } // if: error opening the object
  402. return sc;
  403. } //*** ScOpen()
  404. // Copy another object into this one.
  405. DWORD ScCopy( IN const CClusNodeInfo & rni )
  406. {
  407. ATLASSERT( rni.m_pci != NULL );
  408. DWORD sc = ERROR_SUCCESS;
  409. Close();
  410. CClusterObject::Copy( rni );
  411. //
  412. // Initialize the object.
  413. //
  414. if ( rni.m_hNode != NULL )
  415. {
  416. sc = ScOpen();
  417. } // if: source object had the object opened
  418. return sc;
  419. } //*** ScCopy()
  420. // Close the object
  421. void Close( void )
  422. {
  423. if ( m_hNode != NULL )
  424. {
  425. CloseClusterNode( m_hNode );
  426. } // if: node is open
  427. m_hNode = NULL;
  428. m_bQueried = FALSE;
  429. m_bCreated = FALSE;
  430. } //*** Close()
  431. }; //*** class CClusNodeInfo
  432. /////////////////////////////////////////////////////////////////////////////
  433. //++
  434. //
  435. // class CClusGroupInfo
  436. //
  437. // Description:
  438. // Cluster group object.
  439. //
  440. // Inheritance:
  441. // CClusGroupInfo
  442. // CClusterObject
  443. //
  444. //--
  445. /////////////////////////////////////////////////////////////////////////////
  446. class CClusGroupInfo : public CClusterObject
  447. {
  448. friend class CWizardThread;
  449. public:
  450. //
  451. // Construction.
  452. //
  453. // Default constructor
  454. CClusGroupInfo( void )
  455. : CClusterObject( CLUADMEX_OT_GROUP )
  456. , m_hGroup( NULL )
  457. {
  458. Reset( NULL );
  459. } //*** CClusGroupInfo()
  460. // Constructor taking cluster info pointer
  461. CClusGroupInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  462. : CClusterObject( CLUADMEX_OT_GROUP, pci, pszName )
  463. , m_hGroup( NULL )
  464. {
  465. Reset( pci, pszName );
  466. } //*** CClusGroupInfo( pci )
  467. // Destructor
  468. ~CClusGroupInfo( void )
  469. {
  470. Close();
  471. } //*** ~CClusGroupInfo()
  472. // Operator = is not allowed
  473. CClusGroupInfo & operator=( IN const CClusGroupInfo & rgi )
  474. {
  475. ATLASSERT( FALSE );
  476. return *this;
  477. } //*** operator=()
  478. // Reset the data back to default values
  479. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  480. {
  481. Close();
  482. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_GROUP );
  483. m_bCollectedOwners = FALSE;
  484. m_bCollectedResources = FALSE;
  485. m_lpniPreferredOwners.erase( m_lpniPreferredOwners.begin(), m_lpniPreferredOwners.end() );
  486. m_lpriResources.erase( m_lpriResources.begin(), m_lpriResources.end() );
  487. m_bHasIPAddress = FALSE;
  488. m_bHasNetName = FALSE;
  489. m_nPersistentState = 0;
  490. m_nFailoverThreshold = CLUSTER_GROUP_DEFAULT_FAILOVER_THRESHOLD;
  491. m_nFailoverPeriod = CLUSTER_GROUP_DEFAULT_FAILOVER_PERIOD;
  492. m_cgaftAutoFailbackType = CLUSTER_GROUP_DEFAULT_AUTO_FAILBACK_TYPE;
  493. m_nFailbackWindowStart = CLUSTER_GROUP_DEFAULT_FAILBACK_WINDOW_START;
  494. m_nFailbackWindowEnd = CLUSTER_GROUP_DEFAULT_FAILBACK_WINDOW_END;
  495. } //*** Reset()
  496. protected:
  497. //
  498. // Properties of a group.
  499. //
  500. HGROUP m_hGroup;
  501. BOOL m_bHasIPAddress;
  502. BOOL m_bHasNetName;
  503. DWORD m_nPersistentState;
  504. DWORD m_nFailoverThreshold;
  505. DWORD m_nFailoverPeriod;
  506. CGAFT m_cgaftAutoFailbackType;
  507. DWORD m_nFailbackWindowStart;
  508. DWORD m_nFailbackWindowEnd;
  509. CString m_strNetworkName;
  510. CString m_strIPAddress;
  511. CString m_strNetwork;
  512. BOOL m_bCollectedOwners;
  513. BOOL m_bCollectedResources;
  514. CClusNodePtrList m_lpniPreferredOwners;
  515. CClusResPtrList m_lpriResources;
  516. // Set virtual server properties
  517. void SetVirtualServerProperties(
  518. IN LPCWSTR pszNetworkName,
  519. IN LPCWSTR pszIPAddress,
  520. IN LPCWSTR pszNetwork
  521. )
  522. {
  523. if ( pszNetworkName != NULL )
  524. {
  525. m_strNetworkName = pszNetworkName;
  526. } // if: network name specified
  527. if ( pszIPAddress != NULL )
  528. {
  529. m_strIPAddress = pszIPAddress;
  530. } // if: IP address specified
  531. if ( pszNetwork != NULL )
  532. {
  533. m_strNetwork = pszNetwork;
  534. } // if: network specified
  535. } //*** SetVirtualServerProperties()
  536. public:
  537. //
  538. // Accessor functions for group properties.
  539. //
  540. HGROUP Hgroup( void ) const { return m_hGroup; }
  541. BOOL BHasIPAddress( void ) const { return m_bHasIPAddress; }
  542. BOOL BHasNetName( void ) const { return m_bHasNetName; }
  543. DWORD NPersistentState( void ) const { return m_nPersistentState; }
  544. DWORD NFailoverThreshold( void ) const { return m_nFailoverThreshold; }
  545. DWORD NFailoverPeriod( void ) const { return m_nFailoverPeriod; }
  546. CGAFT CgaftAutoFailbackType( void ) const { return m_cgaftAutoFailbackType; }
  547. DWORD NFailbackWindowStart( void ) const { return m_nFailbackWindowStart; }
  548. DWORD NFailbackWindowEnd( void ) const { return m_nFailbackWindowEnd; }
  549. const CString & RstrNetworkName( void ) const { return m_strNetworkName; }
  550. const CString & RstrIPAddress( void ) const { return m_strIPAddress; }
  551. const CString & RstrNetwork( void ) const { return m_strNetwork; }
  552. BOOL BCollectedOwners( void ) const { return m_bCollectedOwners; }
  553. CClusNodePtrList * PlpniPreferredOwners( void ) { return &m_lpniPreferredOwners; }
  554. CClusResPtrList * PlpriResources( void ) { return &m_lpriResources; }
  555. // Returns whether the group is a virtual server or not
  556. BOOL BIsVirtualServer( void ) const
  557. {
  558. return m_bQueried && m_bHasIPAddress & m_bHasNetName;
  559. } //*** BIsVirtualServer()
  560. // Set failover properties for the group
  561. BOOL BSetFailoverProperties(
  562. IN DWORD nFailoverThreshold,
  563. IN DWORD nFailoverPeriod
  564. )
  565. {
  566. BOOL bChanged = FALSE;
  567. if ( m_nFailoverThreshold != nFailoverThreshold )
  568. {
  569. m_nFailoverThreshold = nFailoverThreshold;
  570. bChanged = TRUE;
  571. } // if: threshold changed
  572. if ( m_nFailoverPeriod != nFailoverPeriod )
  573. {
  574. m_nFailoverPeriod = nFailoverPeriod;
  575. bChanged = TRUE;
  576. } // if: period changed
  577. return bChanged;
  578. } //*** BSetFailoverProperties()
  579. // Set failback properties for the group
  580. BOOL BSetFailbackProperties(
  581. IN CGAFT cgaft,
  582. IN DWORD nFailbackWindowStart,
  583. IN DWORD nFailbackWindowEnd
  584. )
  585. {
  586. BOOL bChanged = FALSE;
  587. if ( m_cgaftAutoFailbackType != cgaft )
  588. {
  589. m_cgaftAutoFailbackType = cgaft;
  590. bChanged = TRUE;
  591. } // if: autofailback type changed
  592. if ( m_nFailbackWindowStart != nFailbackWindowStart )
  593. {
  594. m_nFailbackWindowStart = nFailbackWindowStart;
  595. bChanged = TRUE;
  596. } // if: failback start window changed
  597. if ( m_nFailbackWindowEnd != nFailbackWindowEnd )
  598. {
  599. m_nFailbackWindowEnd = nFailbackWindowEnd;
  600. bChanged = TRUE;
  601. } // if: failback end window changed
  602. return bChanged;
  603. } //*** BSetFailbackProperties()
  604. // Return the list of extensions for groups
  605. const std::list< CString > * PlstrAdminExtensions( void ) const
  606. {
  607. ATLASSERT( Pci() != NULL );
  608. return Pci()->PlstrGroupsAdminExtensions();
  609. } //*** PlstrAdminExtensions()
  610. public:
  611. //
  612. // Operations.
  613. //
  614. // Open the object
  615. DWORD ScOpen( void )
  616. {
  617. ATLASSERT( m_pci != NULL );
  618. ATLASSERT( m_pci->Hcluster() != NULL );
  619. ATLASSERT( m_hGroup == NULL );
  620. ATLASSERT( m_strName.GetLength() > 0 );
  621. DWORD sc = ERROR_SUCCESS;
  622. //
  623. // Open a handle to the object.
  624. //
  625. m_hGroup = OpenClusterGroup( m_pci->Hcluster(), m_strName );
  626. if ( m_hGroup == NULL )
  627. {
  628. sc = GetLastError();
  629. } // if: error opening the object
  630. return sc;
  631. } //*** ScOpen()
  632. // Create the object
  633. DWORD ScCreate( void )
  634. {
  635. ATLASSERT( m_pci != NULL );
  636. ATLASSERT( m_pci->Hcluster() != NULL );
  637. ATLASSERT( m_hGroup == NULL );
  638. ATLASSERT( m_strName.GetLength() > 0 );
  639. DWORD sc = ERROR_SUCCESS;
  640. //
  641. // Create the object.
  642. //
  643. m_hGroup = CreateClusterGroup( m_pci->Hcluster(), m_strName );
  644. if ( m_hGroup == NULL )
  645. {
  646. sc = GetLastError();
  647. } // if: error creating the object
  648. return sc;
  649. } //*** ScCreate()
  650. // Copy another object into this one.
  651. DWORD ScCopy( IN const CClusGroupInfo & rgi )
  652. {
  653. ATLASSERT( rgi.m_pci != NULL );
  654. DWORD sc = ERROR_SUCCESS;
  655. Close();
  656. CClusterObject::Copy( rgi );
  657. m_bHasIPAddress = rgi.m_bHasIPAddress;
  658. m_bHasNetName = rgi.m_bHasNetName;
  659. m_nPersistentState = rgi.m_nPersistentState;
  660. m_nFailoverThreshold = rgi.m_nFailoverThreshold;
  661. m_nFailoverPeriod = rgi.m_nFailoverPeriod;
  662. m_cgaftAutoFailbackType = rgi.m_cgaftAutoFailbackType;
  663. m_nFailbackWindowStart = rgi.m_nFailbackWindowStart;
  664. m_nFailbackWindowEnd = rgi.m_nFailbackWindowEnd;
  665. //
  666. // Copy the preferred owners and resources lists.
  667. //
  668. m_lpniPreferredOwners = rgi.m_lpniPreferredOwners;
  669. m_lpriResources = rgi.m_lpriResources;
  670. //
  671. // Initialize the object.
  672. //
  673. if ( rgi.m_hGroup != NULL )
  674. {
  675. sc = ScOpen();
  676. } // if: source object had the object open
  677. return sc;
  678. } //*** ScCopy()
  679. // Delete the object
  680. DWORD ScDelete( void )
  681. {
  682. ATLASSERT( m_pci != NULL );
  683. ATLASSERT( m_hGroup != NULL );
  684. DWORD sc = ERROR_SUCCESS;
  685. sc = DeleteClusterGroup( m_hGroup );
  686. if ( sc == ERROR_SUCCESS )
  687. {
  688. Close();
  689. m_bCreated = FALSE;
  690. } // if: objected deleted successfully
  691. return sc;
  692. } //*** ScDelete()
  693. // Close the object
  694. void Close( void )
  695. {
  696. if ( m_hGroup != NULL )
  697. {
  698. CloseClusterGroup( m_hGroup );
  699. } // if: group is open
  700. m_hGroup = NULL;
  701. m_bQueried = FALSE;
  702. m_bCreated = FALSE;
  703. } //*** Close()
  704. }; //*** class CClusGroupInfo
  705. /////////////////////////////////////////////////////////////////////////////
  706. //++
  707. //
  708. // class CClusResTypeInfo
  709. //
  710. // Description:
  711. // Cluster resource type object.
  712. //
  713. // Inheritance:
  714. // CClusResTypeInfo
  715. // CClusterObject
  716. //
  717. //--
  718. /////////////////////////////////////////////////////////////////////////////
  719. class CClusResTypeInfo : public CClusterObject
  720. {
  721. friend class CWizardThread;
  722. public:
  723. //
  724. // Construction.
  725. //
  726. // Default constructor
  727. CClusResTypeInfo( void )
  728. : CClusterObject( CLUADMEX_OT_RESOURCETYPE )
  729. , m_pcrd( NULL )
  730. {
  731. Reset( NULL );
  732. } //*** CClusResTypeInfo()
  733. // Constructor taking cluster info pointer
  734. CClusResTypeInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  735. : CClusterObject( CLUADMEX_OT_RESOURCETYPE, pci, pszName )
  736. , m_pcrd( NULL )
  737. {
  738. Reset( pci, pszName );
  739. } //*** CClusResTypeInfo( pci )
  740. // Destructor
  741. ~CClusResTypeInfo( void )
  742. {
  743. Close();
  744. delete [] m_pcrd;
  745. m_pcrd = NULL;
  746. } //*** ~CClusGroupInfo()
  747. // Operator = is not allowed
  748. CClusResTypeInfo & operator=( IN const CClusResTypeInfo & rrti )
  749. {
  750. ATLASSERT( FALSE );
  751. return *this;
  752. } //*** operator=()
  753. // Reset the data back to default values
  754. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  755. {
  756. Close();
  757. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_RESOURCETYPE );
  758. m_strDisplayName.Empty();
  759. m_strResDLLName.Empty();
  760. m_lstrAdminExtensions.erase( m_lstrAdminExtensions.begin(), m_lstrAdminExtensions.end() );
  761. m_lstrAllAdminExtensions.erase( m_lstrAllAdminExtensions.begin(), m_lstrAllAdminExtensions.end() );
  762. m_lstrResourceAdminExtensions.erase( m_lstrResourceAdminExtensions.begin(), m_lstrResourceAdminExtensions.end() );
  763. m_nLooksAlive = CLUSTER_RESTYPE_DEFAULT_LOOKS_ALIVE;
  764. m_nIsAlive = CLUSTER_RESTYPE_DEFAULT_IS_ALIVE;
  765. m_rciResClassInfo.rc = CLUS_RESCLASS_UNKNOWN;
  766. m_rciResClassInfo.SubClass = 0;
  767. m_fCharacteristics = CLUS_CHAR_UNKNOWN;
  768. m_fFlags = 0;
  769. delete [] m_pcrd;
  770. m_pcrd = NULL;
  771. } //*** Reset()
  772. protected:
  773. //
  774. // Properties of a resource type.
  775. //
  776. CString m_strDisplayName;
  777. CString m_strResDLLName;
  778. std::list< CString > m_lstrAdminExtensions;
  779. std::list< CString > m_lstrAllAdminExtensions;
  780. std::list< CString > m_lstrResourceAdminExtensions;
  781. DWORD m_nLooksAlive;
  782. DWORD m_nIsAlive;
  783. CLUS_RESOURCE_CLASS_INFO m_rciResClassInfo;
  784. DWORD m_fCharacteristics;
  785. DWORD m_fFlags;
  786. CLUSPROP_REQUIRED_DEPENDENCY * m_pcrd;
  787. public:
  788. //
  789. // Accessor functions for resource type properties
  790. //
  791. const CString & RstrDisplayName( void ) const { return m_strDisplayName; }
  792. const CString & RstrResDLLName( void ) const { return m_strResDLLName; }
  793. // Return list of extensions for this resource type
  794. const std::list< CString > * PlstrAdminExtensions( void )
  795. {
  796. //
  797. // If not done already, construct the complete list of extensions
  798. // from the extensions for this resource type and the extensions
  799. // for all resource types.
  800. //
  801. if ( m_lstrAllAdminExtensions.size() == 0 )
  802. {
  803. ATLASSERT( Pci() != NULL );
  804. m_lstrAllAdminExtensions = m_lstrAdminExtensions;
  805. m_lstrAllAdminExtensions.insert(
  806. m_lstrAllAdminExtensions.end(),
  807. Pci()->PlstrResTypesAdminExtensions()->begin(),
  808. Pci()->PlstrResTypesAdminExtensions()->end()
  809. );
  810. } // if: full list not constructed yet
  811. return &m_lstrAllAdminExtensions;
  812. } //*** PlstrAdminExtensions()
  813. // Return list of extensions for resources of this type
  814. const std::list< CString > * PlstrResourceAdminExtensions( void )
  815. {
  816. //
  817. // If not done already, construct the complete list of extensions
  818. // from the extensions for this resource type and the extensions
  819. // for all resources.
  820. //
  821. if ( m_lstrResourceAdminExtensions.size() == 0 )
  822. {
  823. ATLASSERT( Pci() != NULL );
  824. m_lstrResourceAdminExtensions = m_lstrAdminExtensions;
  825. m_lstrResourceAdminExtensions.insert(
  826. m_lstrResourceAdminExtensions.end(),
  827. Pci()->PlstrResourcesAdminExtensions()->begin(),
  828. Pci()->PlstrResourcesAdminExtensions()->end()
  829. );
  830. } // if: full list not constructed yet
  831. return &m_lstrResourceAdminExtensions;
  832. } //*** PlstrAdminExtensions()
  833. DWORD NLooksAlive( void ) const { return m_nLooksAlive; }
  834. DWORD NIsAlive( void ) const { return m_nIsAlive; }
  835. DWORD FCharacteristics( void ) const { return m_fCharacteristics; }
  836. DWORD FFlags( void ) const { return m_fFlags; }
  837. CLUS_RESOURCE_CLASS_INFO * PrciResClassInfo( void ) { return &m_rciResClassInfo; }
  838. CLUSTER_RESOURCE_CLASS ResClass( void ) const { return m_rciResClassInfo.rc; }
  839. CLUSPROP_REQUIRED_DEPENDENCY * Pcrd( void ) { return m_pcrd; }
  840. public:
  841. //
  842. // Operations.
  843. //
  844. // Open the object
  845. DWORD ScOpen( void )
  846. {
  847. ATLASSERT( m_pci != NULL );
  848. ATLASSERT( m_strName.GetLength() > 0 );
  849. DWORD sc = ERROR_SUCCESS;
  850. return sc;
  851. } //*** ScOpen()
  852. // Create the object
  853. DWORD ScCreate( IN HGROUP hGroup, IN DWORD dwFlags )
  854. {
  855. ATLASSERT( m_pci != NULL );
  856. ATLASSERT( m_pci->Hcluster() != NULL );
  857. ATLASSERT( m_strName.GetLength() > 0 );
  858. ATLASSERT( m_strDisplayName.GetLength() > 0 );
  859. ATLASSERT( m_strResDLLName.GetLength() > 0 );
  860. ATLASSERT( m_nLooksAlive != 0 );
  861. ATLASSERT( m_nIsAlive != 0 );
  862. DWORD sc;
  863. //
  864. // Create the object.
  865. //
  866. sc = CreateClusterResourceType(
  867. Pci()->Hcluster(),
  868. m_strName,
  869. m_strDisplayName,
  870. m_strResDLLName,
  871. m_nLooksAlive,
  872. m_nIsAlive
  873. );
  874. return sc;
  875. } //*** ScCreate()
  876. // Copy another object into this one.
  877. DWORD ScCopy( IN const CClusResTypeInfo & rrti )
  878. {
  879. ATLASSERT( rrti.m_pci != NULL );
  880. DWORD sc = ERROR_SUCCESS;
  881. Close();
  882. CClusterObject::Copy( rrti );
  883. m_strDisplayName = rrti.m_strDisplayName;
  884. m_strResDLLName = rrti.m_strResDLLName;
  885. m_lstrAdminExtensions = m_lstrAdminExtensions;
  886. m_lstrResourceAdminExtensions = rrti.m_lstrResourceAdminExtensions;
  887. m_nLooksAlive = rrti.m_nLooksAlive;
  888. m_nIsAlive = rrti.m_nIsAlive;
  889. m_rciResClassInfo.rc = rrti.m_rciResClassInfo.rc;
  890. m_rciResClassInfo.SubClass = rrti.m_rciResClassInfo.SubClass;
  891. m_fCharacteristics = rrti.m_fCharacteristics;
  892. m_fFlags = rrti.m_fFlags;
  893. //
  894. // Initialize the object.
  895. //
  896. // sc = ScOpen();
  897. return sc;
  898. } //*** ScCopy()
  899. // Close the object
  900. void Close( void )
  901. {
  902. // Dummy function to support similar semantics as other objects.
  903. m_bQueried = FALSE;
  904. m_bCreated = FALSE;
  905. } //*** Close();
  906. }; //*** class CClusResTypeInfo
  907. /////////////////////////////////////////////////////////////////////////////
  908. //++
  909. //
  910. // class CClusResInfo
  911. //
  912. // Description:
  913. // Cluster resource object.
  914. //
  915. // Inheritance:
  916. // CClusResInfo
  917. // CClusterObject
  918. //
  919. // Notes:
  920. // 1) Must appear after definition of CClusResTypeInfo because
  921. // CClusResTypeInfo methods are referenced in this class's methods.
  922. //
  923. //--
  924. /////////////////////////////////////////////////////////////////////////////
  925. class CClusResInfo : public CClusterObject
  926. {
  927. friend class CWizardThread;
  928. public:
  929. //
  930. // Construction.
  931. //
  932. // Default constructor
  933. CClusResInfo( void )
  934. : CClusterObject( CLUADMEX_OT_RESOURCE )
  935. , m_hResource( NULL )
  936. {
  937. Reset( NULL );
  938. } //*** CClusResInfo()
  939. // Constructor taking cluster info pointer
  940. CClusResInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  941. : CClusterObject( CLUADMEX_OT_RESOURCE, pci, pszName )
  942. , m_hResource( NULL )
  943. {
  944. Reset( pci, pszName );
  945. } //*** CClusResInfo( pci )
  946. ~CClusResInfo( void )
  947. {
  948. Close();
  949. } //*** ~CClusResInfo()
  950. // Operator = is not allowed
  951. CClusResInfo & operator=( IN const CClusResInfo & rri )
  952. {
  953. ATLASSERT( FALSE );
  954. return *this;
  955. } //*** operator=()
  956. // Reset the data back to default values
  957. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  958. {
  959. Close();
  960. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_RESOURCE );
  961. m_prti = NULL;
  962. m_pgi = NULL;
  963. m_pniOwner = NULL;
  964. m_bCollectedOwners = FALSE;
  965. m_bCollectedDependencies = FALSE;
  966. m_lpniPossibleOwners.erase( m_lpniPossibleOwners.begin(), m_lpniPossibleOwners.end() );
  967. m_lpriDependencies.erase( m_lpriDependencies.begin(), m_lpriDependencies.end() );
  968. m_bSeparateMonitor = FALSE;
  969. m_nPersistentState = 0;
  970. m_nLooksAlive = CLUSTER_RESOURCE_DEFAULT_LOOKS_ALIVE;
  971. m_nIsAlive = CLUSTER_RESOURCE_DEFAULT_IS_ALIVE;
  972. m_crraRestartAction = CLUSTER_RESOURCE_DEFAULT_RESTART_ACTION;
  973. m_nRestartThreshold = CLUSTER_RESOURCE_DEFAULT_RESTART_THRESHOLD;
  974. m_nRestartPeriod = CLUSTER_RESOURCE_DEFAULT_RESTART_PERIOD;
  975. m_nPendingTimeout = CLUSTER_RESOURCE_DEFAULT_PENDING_TIMEOUT;
  976. } //*** Reset()
  977. protected:
  978. //
  979. // Properties of a resource.
  980. //
  981. HRESOURCE m_hResource;
  982. CClusResTypeInfo * m_prti;
  983. CClusGroupInfo * m_pgi;
  984. CClusNodeInfo * m_pniOwner;
  985. BOOL m_bSeparateMonitor;
  986. DWORD m_nPersistentState;
  987. DWORD m_nLooksAlive;
  988. DWORD m_nIsAlive;
  989. CRRA m_crraRestartAction;
  990. DWORD m_nRestartThreshold;
  991. DWORD m_nRestartPeriod;
  992. DWORD m_nPendingTimeout;
  993. BOOL m_bCollectedOwners;
  994. BOOL m_bCollectedDependencies;
  995. CClusNodePtrList m_lpniPossibleOwners;
  996. CClusResPtrList m_lpriDependencies;
  997. public:
  998. //
  999. // Accessor functions for resource properties
  1000. //
  1001. HRESOURCE Hresource( void ) const { return m_hResource; }
  1002. CClusResTypeInfo * Prti( void ) const { ATLASSERT( m_prti != NULL ); return m_prti; }
  1003. CClusGroupInfo * Pgi( void ) const { ATLASSERT( m_pgi != NULL ); return m_pgi; }
  1004. CClusNodeInfo * PniOwner( void ) const { ATLASSERT( m_pniOwner != NULL ); return m_pniOwner; }
  1005. BOOL BSeparateMonitor( void ) const { return m_bSeparateMonitor; }
  1006. DWORD NPersistentState( void ) const { return m_nPersistentState; }
  1007. DWORD NLooksAlive( void ) const { return m_nLooksAlive; }
  1008. DWORD NIsAlive( void ) const { return m_nIsAlive; }
  1009. CRRA CrraRestartAction( void ) const { return m_crraRestartAction; }
  1010. DWORD NRestartThreshold( void ) const { return m_nRestartThreshold; }
  1011. DWORD NRestartPeriod( void ) const { return m_nRestartPeriod; }
  1012. DWORD NPendingTimeout( void ) const { return m_nPendingTimeout; }
  1013. BOOL BCollectedOwners( void ) const { return m_bCollectedOwners; }
  1014. BOOL BCollectedDependencies( void ) const { return m_bCollectedDependencies; }
  1015. CClusNodePtrList * PlpniPossibleOwners( void ) { return &m_lpniPossibleOwners; }
  1016. CClusResPtrList * PlpriDependencies( void ) { return &m_lpriDependencies; }
  1017. CLUSTER_RESOURCE_CLASS ResClass( void ) const { return Prti()->ResClass(); }
  1018. // Set the group
  1019. void SetGroup( IN CClusGroupInfo * pgi )
  1020. {
  1021. ATLASSERT( pgi != NULL );
  1022. m_pgi = pgi;
  1023. } //*** SetGroup()
  1024. // Set the resource type of the resource
  1025. BOOL BSetResourceType( IN CClusResTypeInfo * prti )
  1026. {
  1027. ATLASSERT( prti != NULL );
  1028. BOOL bChanged = FALSE;
  1029. //
  1030. // If the resource type changed, set it.
  1031. //
  1032. if ( m_prti != prti )
  1033. {
  1034. m_prti = prti;
  1035. bChanged = TRUE;
  1036. } // if: resource type changed
  1037. return bChanged;
  1038. } //*** BSetResourceType()
  1039. // Set the separate monitor property for the resource
  1040. BOOL BSetSeparateMonitor( IN BOOL bSeparateMonitor )
  1041. {
  1042. BOOL bChanged = FALSE;
  1043. if ( m_bSeparateMonitor != bSeparateMonitor )
  1044. {
  1045. m_bSeparateMonitor = bSeparateMonitor;
  1046. bChanged = TRUE;
  1047. } // if: separate monitor changed
  1048. return bChanged;
  1049. } //*** BSetSeparateMonitor()
  1050. // Set advanced properties for the resource
  1051. BOOL BSetAdvancedProperties(
  1052. IN CRRA crra,
  1053. IN DWORD nRestartThreshold,
  1054. IN DWORD nRestartPeriod,
  1055. IN DWORD nLooksAlive,
  1056. IN DWORD nIsAlive,
  1057. IN DWORD nPendingTimeout
  1058. )
  1059. {
  1060. BOOL bChanged = FALSE;
  1061. if ( m_crraRestartAction != crra )
  1062. {
  1063. m_crraRestartAction = crra;
  1064. bChanged = TRUE;
  1065. } // if: restart action changed
  1066. if ( m_nRestartThreshold != nRestartThreshold )
  1067. {
  1068. m_nRestartThreshold = nRestartThreshold;
  1069. bChanged = TRUE;
  1070. } // if: restart threshold changed
  1071. if ( m_nRestartPeriod != nRestartPeriod )
  1072. {
  1073. m_nRestartPeriod = nRestartPeriod;
  1074. bChanged = TRUE;
  1075. } // if: restart period changed
  1076. if ( m_nLooksAlive != nLooksAlive )
  1077. {
  1078. m_nLooksAlive = nLooksAlive;
  1079. bChanged = TRUE;
  1080. } // if: looks alive period changed
  1081. if ( m_nIsAlive != nIsAlive )
  1082. {
  1083. m_nIsAlive = nIsAlive;
  1084. bChanged = TRUE;
  1085. } // if: is alive period changed
  1086. if ( m_nPendingTimeout != nPendingTimeout )
  1087. {
  1088. m_nPendingTimeout = nPendingTimeout;
  1089. bChanged = TRUE;
  1090. } // if: pending timeout changed
  1091. return bChanged;
  1092. } //*** BSetAdvancedProperties()
  1093. // Return the list of extensions for resources
  1094. const std::list< CString > * PlstrAdminExtensions( void ) const
  1095. {
  1096. ATLASSERT( m_prti != NULL );
  1097. return m_prti->PlstrResourceAdminExtensions();
  1098. } //*** PlstrAdminExtensions()
  1099. public:
  1100. //
  1101. // Operations.
  1102. //
  1103. // Open the object
  1104. DWORD ScOpen( void )
  1105. {
  1106. ATLASSERT( m_pci != NULL );
  1107. ATLASSERT( m_pci->Hcluster() != NULL );
  1108. ATLASSERT( m_hResource == NULL );
  1109. ATLASSERT( m_strName.GetLength() > 0 );
  1110. DWORD sc = ERROR_SUCCESS;
  1111. //
  1112. // Open a handle to the object.
  1113. //
  1114. m_hResource = OpenClusterResource( m_pci->Hcluster(), m_strName );
  1115. if ( m_hResource == NULL )
  1116. {
  1117. sc = GetLastError();
  1118. } // if: error opening the object
  1119. return sc;
  1120. } //*** ScOpen()
  1121. // Create the object
  1122. DWORD ScCreate( IN HGROUP hGroup, IN DWORD dwFlags )
  1123. {
  1124. ATLASSERT( hGroup != NULL );
  1125. ATLASSERT( Prti() != NULL );
  1126. ATLASSERT( Prti()->RstrName().GetLength() > 0 );
  1127. ATLASSERT( m_hResource == NULL );
  1128. ATLASSERT( m_strName.GetLength() > 0 );
  1129. DWORD sc = ERROR_SUCCESS;
  1130. m_bSeparateMonitor = ( dwFlags & CLUSTER_RESOURCE_SEPARATE_MONITOR ) == CLUSTER_RESOURCE_SEPARATE_MONITOR;
  1131. //
  1132. // Create the object.
  1133. //
  1134. m_hResource = CreateClusterResource( hGroup, m_strName, Prti()->RstrName(), dwFlags );
  1135. if ( m_hResource == NULL )
  1136. {
  1137. sc = GetLastError();
  1138. } // if: error creating the object
  1139. return sc;
  1140. } //*** ScCreate()
  1141. // Copy another object into this one.
  1142. DWORD ScCopy( IN const CClusResInfo & rri )
  1143. {
  1144. ATLASSERT( rri.m_pci != NULL );
  1145. DWORD sc = ERROR_SUCCESS;
  1146. Close();
  1147. CClusterObject::Copy( rri );
  1148. m_prti = rri.m_prti;
  1149. m_pgi = rri.m_pgi;
  1150. m_pniOwner = rri.m_pniOwner;
  1151. m_bSeparateMonitor = rri.m_bSeparateMonitor;
  1152. m_nPersistentState = rri.m_nPersistentState;
  1153. m_nLooksAlive = rri.m_nLooksAlive;
  1154. m_nIsAlive = rri.m_nIsAlive;
  1155. m_crraRestartAction = rri.m_crraRestartAction;
  1156. m_nRestartThreshold = rri.m_nRestartThreshold;
  1157. m_nRestartPeriod = rri.m_nRestartPeriod;
  1158. m_nPendingTimeout = rri.m_nPendingTimeout;
  1159. //
  1160. // Copy the possible owners and dependencies lists.
  1161. //
  1162. m_lpniPossibleOwners = rri.m_lpniPossibleOwners;
  1163. m_lpriDependencies = rri.m_lpriDependencies;
  1164. //
  1165. // Initialize the object.
  1166. //
  1167. if ( rri.m_hResource != NULL )
  1168. {
  1169. sc = ScOpen();
  1170. } // if: source object had the object open
  1171. return sc;
  1172. } //*** ScCopy()
  1173. // Delete the object
  1174. DWORD ScDelete( void )
  1175. {
  1176. ATLASSERT( m_hResource != NULL );
  1177. DWORD sc = ERROR_SUCCESS;
  1178. sc = DeleteClusterResource( m_hResource );
  1179. if ( sc == ERROR_SUCCESS )
  1180. {
  1181. Close();
  1182. m_bCreated = FALSE;
  1183. } // if: objected deleted successfully
  1184. return sc;
  1185. } //*** ScDelete()
  1186. // Close the object
  1187. void Close( void )
  1188. {
  1189. if ( m_hResource != NULL )
  1190. {
  1191. CloseClusterResource( m_hResource );
  1192. } // if: resource is open
  1193. m_hResource = NULL;
  1194. m_bQueried = FALSE;
  1195. m_bCreated = FALSE;
  1196. } //*** Close()
  1197. // Get network name of first Network Name resource we are dependent on
  1198. BOOL BGetNetworkName(
  1199. OUT WCHAR * lpszNetName,
  1200. IN OUT DWORD * pcchNetName
  1201. )
  1202. {
  1203. ATLASSERT( m_hResource != NULL );
  1204. ATLASSERT( lpszNetName != NULL );
  1205. ATLASSERT( pcchNetName != NULL );
  1206. return GetClusterResourceNetworkName(
  1207. m_hResource,
  1208. lpszNetName,
  1209. pcchNetName
  1210. );
  1211. } //*** BGetNetworkName()
  1212. // Determine whether required dependencies are specified or not
  1213. BOOL BRequiredDependenciesPresent(
  1214. IN CClusResPtrList const * plpri,
  1215. OUT CString & rstrMissing,
  1216. OUT BOOL & rbMissingTypeName
  1217. );
  1218. }; //*** class CClusResInfo
  1219. /////////////////////////////////////////////////////////////////////////////
  1220. //++
  1221. //
  1222. // class CClusNetworkInfo
  1223. //
  1224. // Description:
  1225. // Cluster network object.
  1226. //
  1227. // Inheritance:
  1228. // CClusNetworkInfo
  1229. // CClusterObject
  1230. //
  1231. //--
  1232. /////////////////////////////////////////////////////////////////////////////
  1233. class CClusNetworkInfo : public CClusterObject
  1234. {
  1235. friend class CWizardThread;
  1236. public:
  1237. //
  1238. // Construction.
  1239. //
  1240. // Default constructor
  1241. CClusNetworkInfo( void )
  1242. : CClusterObject( CLUADMEX_OT_NETWORK )
  1243. , m_hNetwork( NULL )
  1244. {
  1245. Reset( NULL );
  1246. } //*** CClusNetworkInfo()
  1247. // Constructor taking cluster info pointer
  1248. CClusNetworkInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  1249. : CClusterObject( CLUADMEX_OT_NETWORK, pci, pszName )
  1250. , m_hNetwork( NULL )
  1251. {
  1252. Reset( pci, pszName );
  1253. } //*** CClusNetworkInfo( pci )
  1254. ~CClusNetworkInfo( void )
  1255. {
  1256. Close();
  1257. } //*** ~CClusterNetworkInfo()
  1258. // Operator = is not allowed
  1259. CClusNetworkInfo & operator=( IN const CClusNetworkInfo & rni )
  1260. {
  1261. ATLASSERT( FALSE );
  1262. return *this;
  1263. } //*** operator=()
  1264. // Reset the data back to default values
  1265. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  1266. {
  1267. Close();
  1268. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_NETWORK );
  1269. m_nRole = ClusterNetworkRoleNone;
  1270. m_strAddress.Empty();
  1271. m_strAddressMask.Empty();
  1272. m_nAddress = 0;
  1273. m_nAddressMask = 0;
  1274. } //*** Reset()
  1275. protected:
  1276. //
  1277. // Properties of a network.
  1278. //
  1279. HNETWORK m_hNetwork;
  1280. CLUSTER_NETWORK_ROLE m_nRole;
  1281. CString m_strAddress;
  1282. CString m_strAddressMask;
  1283. DWORD m_nAddress;
  1284. DWORD m_nAddressMask;
  1285. public:
  1286. //
  1287. // Accessor functions for network properties
  1288. //
  1289. HNETWORK Hnetwork( void ) const { return m_hNetwork; }
  1290. CLUSTER_NETWORK_ROLE NRole( void ) const { return m_nRole; }
  1291. const CString & RstrAddress( void ) const { return m_strAddress; }
  1292. const CString & RstrAddressMask( void ) const { return m_strAddressMask; }
  1293. DWORD NAddress( void ) const { return m_nAddress; }
  1294. DWORD NAddressMask( void ) const { return m_nAddressMask; }
  1295. // Returns whether the network is used for client access
  1296. BOOL BIsClientNetwork( void ) const
  1297. {
  1298. return m_bQueried && (m_nRole & ClusterNetworkRoleClientAccess);
  1299. } //*** BIsClientNetwork()
  1300. // Returns whether the network is used for internal cluster use
  1301. BOOL BIsInternalNetwork( void ) const
  1302. {
  1303. return m_bQueried && (m_nRole & ClusterNetworkRoleInternalUse);
  1304. } //*** BIsInternalNetwork()
  1305. // Return the list of extensions for networks
  1306. const std::list< CString > * PlstrAdminExtensions( void ) const
  1307. {
  1308. ATLASSERT( Pci() != NULL );
  1309. return Pci()->PlstrNetworksAdminExtensions();
  1310. } //*** PlstrAdminExtensions()
  1311. public:
  1312. //
  1313. // Operations.
  1314. //
  1315. // Open the object
  1316. DWORD ScOpen( void )
  1317. {
  1318. ATLASSERT( m_pci != NULL );
  1319. ATLASSERT( m_pci->Hcluster() != NULL );
  1320. ATLASSERT( m_hNetwork == NULL );
  1321. ATLASSERT( m_strName.GetLength() > 0 );
  1322. DWORD sc = ERROR_SUCCESS;
  1323. //
  1324. // Open a handle to the object.
  1325. //
  1326. m_hNetwork = OpenClusterNetwork( m_pci->Hcluster(), m_strName );
  1327. if ( m_hNetwork == NULL )
  1328. {
  1329. sc = GetLastError();
  1330. } // if: error opening the object
  1331. return sc;
  1332. } //*** ScOpen()
  1333. // Copy another object into this one.
  1334. DWORD ScCopy( IN const CClusNetworkInfo & rni )
  1335. {
  1336. ATLASSERT( rni.m_pci != NULL );
  1337. DWORD sc = ERROR_SUCCESS;
  1338. Close();
  1339. CClusterObject::Copy( rni );
  1340. m_nRole = rni.m_nRole;
  1341. m_strAddress = rni.m_strAddress;
  1342. m_strAddressMask = rni.m_strAddressMask;
  1343. m_nAddress = rni.m_nAddress;
  1344. m_nAddressMask = rni.m_nAddressMask;
  1345. //
  1346. // Initialize the object.
  1347. //
  1348. if ( rni.m_hNetwork != NULL )
  1349. {
  1350. sc = ScOpen();
  1351. } // if: source object had the object open
  1352. return sc;
  1353. } //*** ScCopy()
  1354. // Close the object
  1355. void Close( void )
  1356. {
  1357. if ( m_hNetwork != NULL )
  1358. {
  1359. CloseClusterNetwork( m_hNetwork );
  1360. } // if: network is open
  1361. m_hNetwork = NULL;
  1362. m_bQueried = FALSE;
  1363. m_bCreated = FALSE;
  1364. } //*** Close()
  1365. }; //*** class CClusNetworkInfo
  1366. /////////////////////////////////////////////////////////////////////////////
  1367. //++
  1368. //
  1369. // class CClusNetIFInfo
  1370. //
  1371. // Description:
  1372. // Cluster network interface object.
  1373. //
  1374. // Inheritance:
  1375. // CClusNetIFInfo
  1376. // CClusterObject
  1377. //
  1378. //--
  1379. /////////////////////////////////////////////////////////////////////////////
  1380. class CClusNetIFInfo : public CClusterObject
  1381. {
  1382. friend class CWizardThread;
  1383. public:
  1384. //
  1385. // Construction.
  1386. //
  1387. // Default constructor
  1388. CClusNetIFInfo( void )
  1389. : CClusterObject( CLUADMEX_OT_NETINTERFACE )
  1390. , m_hNetInterface( NULL )
  1391. {
  1392. Reset( NULL );
  1393. } //*** CClusNetworkInfo()
  1394. // Constructor taking cluster info pointer
  1395. CClusNetIFInfo( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  1396. : CClusterObject( CLUADMEX_OT_NETINTERFACE, pci, pszName )
  1397. , m_hNetInterface( NULL )
  1398. {
  1399. Reset( pci, pszName );
  1400. } //*** CClusNetIFInfo( pci )
  1401. ~CClusNetIFInfo( void )
  1402. {
  1403. Close();
  1404. } //*** ~CClusNetIFInfo()
  1405. // Operator = is not allowed
  1406. CClusNetIFInfo & operator=( IN const CClusNetIFInfo & rnii )
  1407. {
  1408. ATLASSERT( FALSE );
  1409. return *this;
  1410. } //*** operator=()
  1411. // Reset the data back to default values
  1412. void Reset( IN CClusterInfo * pci, IN LPCTSTR pszName = NULL )
  1413. {
  1414. Close();
  1415. CClusterObject::Reset( pci, pszName, CLUADMEX_OT_NETINTERFACE );
  1416. } //*** Reset()
  1417. protected:
  1418. //
  1419. // Properties of a network interface.
  1420. //
  1421. HNETINTERFACE m_hNetInterface;
  1422. public:
  1423. //
  1424. // Accessor functions for network properties
  1425. //
  1426. HNETINTERFACE Hnetinterface( void ) const { return m_hNetInterface; }
  1427. // Return the list of extensions for network interfaces
  1428. const std::list< CString > * PlstrAdminExtensions( void ) const
  1429. {
  1430. ATLASSERT( Pci() != NULL );
  1431. return Pci()->PlstrNetInterfacesAdminExtensions();
  1432. } //*** PlstrAdminExtensions()
  1433. public:
  1434. //
  1435. // Operations.
  1436. //
  1437. // Open the object
  1438. DWORD ScOpen( void )
  1439. {
  1440. ATLASSERT( m_pci != NULL );
  1441. ATLASSERT( m_pci->Hcluster() != NULL );
  1442. ATLASSERT( m_hNetInterface == NULL );
  1443. ATLASSERT( m_strName.GetLength() > 0 );
  1444. DWORD sc = ERROR_SUCCESS;
  1445. //
  1446. // Open a handle to the object.
  1447. //
  1448. m_hNetInterface = OpenClusterNetInterface( m_pci->Hcluster(), m_strName );
  1449. if ( m_hNetInterface == NULL )
  1450. {
  1451. sc = GetLastError();
  1452. } // if: error opening the object
  1453. return sc;
  1454. } //*** ScOpen()
  1455. // Copy another object into this one.
  1456. DWORD ScCopy( IN const CClusNetIFInfo & rnii )
  1457. {
  1458. ATLASSERT( rnii.m_pci != NULL );
  1459. DWORD sc = ERROR_SUCCESS;
  1460. Close();
  1461. CClusterObject::Copy( rnii );
  1462. //
  1463. // Initialize the object.
  1464. //
  1465. if ( rnii.m_hNetInterface != NULL )
  1466. {
  1467. sc = ScOpen();
  1468. } // if: source object had the object open
  1469. return sc;
  1470. } //*** ScCopy()
  1471. // Close the object
  1472. void Close( void )
  1473. {
  1474. if ( m_hNetInterface != NULL )
  1475. {
  1476. CloseClusterNetInterface( m_hNetInterface );
  1477. } // if: network interface is open
  1478. m_hNetInterface = NULL;
  1479. m_bQueried = FALSE;
  1480. m_bCreated = FALSE;
  1481. } //*** Close()
  1482. }; //*** class CClusNetIFInfo
  1483. /////////////////////////////////////////////////////////////////////////////
  1484. // Global Template Functions
  1485. /////////////////////////////////////////////////////////////////////////////
  1486. // Delete all list items from a pointer list
  1487. template < class ListT, class ObjT >
  1488. void DeleteListItems( ListT * ppl )
  1489. {
  1490. ListT::iterator it;
  1491. for ( it = ppl->begin() ; it != ppl->end() ; it++ )
  1492. {
  1493. ObjT * pco = *it;
  1494. delete pco;
  1495. } // for: each item in the list
  1496. } //*** DeleteListItems< ListT, ObjT >()
  1497. // Retrieve an object from a list by its name
  1498. template < class ObjT >
  1499. ObjT PobjFromName( std::list< ObjT > * pList, IN LPCTSTR pszName )
  1500. {
  1501. ATLASSERT( pList != NULL );
  1502. ATLASSERT( pszName != NULL );
  1503. //
  1504. // Get pointers to beginning and end of list.
  1505. //
  1506. std::list< ObjT >::iterator itCurrent = pList->begin();
  1507. std::list< ObjT >::iterator itLast = pList->end();
  1508. //
  1509. // Loop through the list looking for the object with the specified name.
  1510. //
  1511. while ( itCurrent != itLast )
  1512. {
  1513. if ( (*itCurrent)->RstrName() == pszName )
  1514. {
  1515. return *itCurrent;
  1516. } // if: found a match
  1517. itCurrent++;
  1518. } // while: more items in the list
  1519. return NULL;
  1520. } //*** PobjFromName< ObjT >()
  1521. /////////////////////////////////////////////////////////////////////////////
  1522. #endif // __CLUSOBJ_H_