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.

168 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tgroup.c
  5. Abstract:
  6. Test for cluster group API
  7. Author:
  8. John Vert (jvert) 15-Mar-1996
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "cluster.h"
  13. #include "stdio.h"
  14. #include "stdlib.h"
  15. int
  16. _cdecl
  17. main (argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21. HCLUSTER Cluster;
  22. HRESOURCE Resource;
  23. HGROUP Group;
  24. HNODE Node;
  25. HKEY ClusterRoot;
  26. HCLUSENUM ResEnum;
  27. DWORD ClusterCountBefore, ClusterCountAfter;
  28. HGROUPENUM hGroupEnum;
  29. DWORD GroupCountBefore, GroupCountAfter;
  30. DWORD i,j;
  31. DWORD Status;
  32. WCHAR NameBuf[50];
  33. DWORD NameLen;
  34. WCHAR NodeBuf[50];
  35. DWORD Type;
  36. CLUSTER_GROUP_STATE GroupState;
  37. //
  38. // Dump out group structure for current cluster.
  39. //
  40. Cluster = OpenCluster(NULL);
  41. if (Cluster == NULL) {
  42. fprintf(stderr, "OpenCluster(NULL) failed %d\n",GetLastError());
  43. return(0);
  44. }
  45. //
  46. // Dump groups
  47. //
  48. printf("\n\nENUMERATING GROUPS\n");
  49. ResEnum = ClusterOpenEnum(Cluster, CLUSTER_ENUM_GROUP);
  50. if (ResEnum == NULL) {
  51. fprintf(stderr, "ClusterOpenEnum failed %d\n",GetLastError());
  52. return(0);
  53. }
  54. ClusterCountBefore = ClusterGetEnumCount(ResEnum);
  55. for(i=0; ; i++) {
  56. NameLen = sizeof(NameBuf)/sizeof(WCHAR);
  57. Status = ClusterEnum(ResEnum,
  58. i,
  59. &Type,
  60. NameBuf,
  61. &NameLen);
  62. if (Status == ERROR_NO_MORE_ITEMS) {
  63. break;
  64. } else if (Status != ERROR_SUCCESS) {
  65. fprintf(stderr, "ClusterEnum %d returned error %d\n",i,Status);
  66. return(0);
  67. }
  68. if (Type != CLUSTER_ENUM_GROUP) {
  69. printf("Invalid Type %d returned from ClusterEnum\n", Type);
  70. return(0);
  71. }
  72. Group = OpenClusterGroup(Cluster, NameBuf);
  73. if (Group == NULL) {
  74. fprintf(stderr, "OpenClusterGroup %ws failed %d\n",NameBuf, GetLastError());
  75. return(0);
  76. }
  77. NameLen = sizeof(NodeBuf)/sizeof(WCHAR);
  78. GroupState = GetClusterGroupState(Group, NodeBuf, &NameLen);
  79. if (GroupState == -1) {
  80. fprintf(stderr, "GetClusterGroupState failed %d\n",GetLastError());
  81. return(0);
  82. }
  83. if (GroupState == ClusterGroupOnline) {
  84. printf("Group %ws is ONLINE at node %ws\n",NameBuf, NodeBuf);
  85. } else if (GroupState == ClusterGroupOffline) {
  86. printf("Group %ws is OFFLINE at node %ws\n",NameBuf, NodeBuf);
  87. } else if (GroupState == ClusterGroupFailed) {
  88. printf("Group %ws is FAILED at node %ws\n",NameBuf, NodeBuf);
  89. } else {
  90. fprintf(stderr, "Group %ws is in unknown state %d on node %ws\n",NameBuf, GroupState, NodeBuf);
  91. }
  92. hGroupEnum = ClusterGroupOpenEnum(Group,
  93. CLUSTER_GROUP_ENUM_CONTAINS | CLUSTER_GROUP_ENUM_NODES);
  94. if (hGroupEnum == NULL) {
  95. fprintf(stderr, "Group %ws failed to open enum %d\n",NameBuf, GetLastError());
  96. } else {
  97. GroupCountBefore = ClusterGroupGetEnumCount(hGroupEnum);
  98. for (j=0; ; j++) {
  99. NameLen = sizeof(NameBuf)/sizeof(WCHAR);
  100. Status = ClusterGroupEnum(hGroupEnum,
  101. j,
  102. &Type,
  103. NameBuf,
  104. &NameLen);
  105. if (Status == ERROR_NO_MORE_ITEMS) {
  106. break;
  107. } else if (Status != ERROR_SUCCESS) {
  108. fprintf(stderr, "Failed to enum group item %d, error %d\n",j,Status);
  109. } else {
  110. switch (Type) {
  111. case CLUSTER_GROUP_ENUM_NODES:
  112. printf("\tpreferred node %ws\n",NameBuf);
  113. break;
  114. case CLUSTER_GROUP_ENUM_CONTAINS:
  115. printf("\tcontains resource %ws\n",NameBuf);
  116. break;
  117. default:
  118. fprintf(stderr, "\tUnknown enum type %d\n",Type);
  119. break;
  120. }
  121. }
  122. }
  123. if (Status == ERROR_NO_MORE_ITEMS) {
  124. printf("\nGroup count: %d\n", j);
  125. GroupCountAfter = ClusterGroupGetEnumCount(hGroupEnum);
  126. if (GroupCountBefore != GroupCountAfter)
  127. fprintf(stderr, "\nReported group count was %d before enumeration, and %d afterward\n", GroupCountBefore, GroupCountAfter);
  128. else if (j != GroupCountBefore)
  129. fprintf(stderr, "\nReported group count: %d\n", GroupCountBefore);
  130. }
  131. ClusterGroupCloseEnum(hGroupEnum);
  132. }
  133. CloseClusterGroup(Group);
  134. }
  135. if (Status == ERROR_NO_MORE_ITEMS) {
  136. printf("\nCluster count: %d\n", i);
  137. ClusterCountAfter = ClusterGetEnumCount(ResEnum);
  138. if (ClusterCountBefore != ClusterCountAfter)
  139. fprintf(stderr, "\nReported cluster count was %d before enumeration, and %d afterward\n", ClusterCountBefore, ClusterCountAfter);
  140. else if (i != ClusterCountBefore)
  141. fprintf(stderr, "\nReported cluster count: %d\n", ClusterCountBefore);
  142. }
  143. ClusterCloseEnum(ResEnum);
  144. CloseCluster(Cluster);
  145. }