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.

208 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tres.c
  5. Abstract:
  6. Test for cluster group API
  7. Author:
  8. John Vert (jvert) 5/23/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. HCLUSENUM Enum;
  25. HRESENUM ResEnum;
  26. DWORD i,j;
  27. DWORD Status;
  28. WCHAR NameBuf[50];
  29. DWORD NameLen;
  30. DWORD GroupNameLen;
  31. WCHAR NodeBuf[50];
  32. WCHAR GroupBuf[50];
  33. CLUSTER_RESOURCE_STATE ResourceState;
  34. DWORD Type;
  35. DWORD ResCountBefore, ResCountAfter;
  36. DWORD ClusterCountBefore, ClusterCountAfter;
  37. //
  38. // Dump out resources 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 resources
  47. //
  48. printf("\n\nENUMERATING RESOURCES\n");
  49. Enum = ClusterOpenEnum(Cluster, CLUSTER_ENUM_RESOURCE);
  50. if (Enum == NULL) {
  51. fprintf(stderr, "ClusterOpenEnum failed %d\n",GetLastError());
  52. return(0);
  53. }
  54. ClusterCountBefore = ClusterGetEnumCount(Enum);
  55. for(i=0; ; i++) {
  56. NameLen = sizeof(NameBuf)/sizeof(WCHAR);
  57. Status = ClusterEnum(Enum,
  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_RESOURCE) {
  69. printf("Invalid Type %d returned from ClusterEnum\n", Type);
  70. return(0);
  71. }
  72. Resource = OpenClusterResource(Cluster, NameBuf);
  73. if (Resource == NULL) {
  74. fprintf(stderr, "OpenClusterResource %ws failed %d\n",NameBuf, GetLastError());
  75. return(0);
  76. }
  77. NameLen = sizeof(NodeBuf)/sizeof(WCHAR);
  78. GroupNameLen = sizeof(GroupBuf)/sizeof(WCHAR);
  79. ResourceState = GetClusterResourceState(Resource, NodeBuf, &NameLen, GroupBuf, &GroupNameLen);
  80. if (ResourceState == -1) {
  81. fprintf(stderr, "GetClusterResourceState2 failed %d\n",GetLastError());
  82. return(0);
  83. }
  84. switch (ResourceState) {
  85. case ClusterResourceInherited:
  86. printf("Resource %ws is INHERITED",NameBuf);
  87. break;
  88. case ClusterResourceInitializing:
  89. printf("Resource %ws is INITIALIZING",NameBuf);
  90. break;
  91. case ClusterResourceOnline:
  92. printf("Resource %ws is ONLINE",NameBuf);
  93. break;
  94. case ClusterResourceOffline:
  95. printf("Resource %ws is OFFLINE",NameBuf);
  96. break;
  97. case ClusterResourceFailed:
  98. printf("Resource %ws is FAILED",NameBuf);
  99. break;
  100. default:
  101. fprintf(stderr, "Group %ws is in unknown state %d", NameBuf, ResourceState);
  102. break;
  103. }
  104. printf(" on node %ws in group %ws\n",NodeBuf, GroupBuf);
  105. //
  106. // Dump out resource dependencies:
  107. //
  108. ResEnum = ClusterResourceOpenEnum(Resource, CLUSTER_RESOURCE_ENUM_DEPENDS);
  109. if (ResEnum == NULL) {
  110. fprintf(stderr,
  111. "ClusterResourceOpenEnum CLUSTER_RESOURCE_ENUM_DEPENDS failed %d\n",
  112. GetLastError());
  113. return(0);
  114. }
  115. ResCountBefore = ClusterResourceGetEnumCount(ResEnum);
  116. printf("\tDEPENDS ON:\t");
  117. for (j=0; ; j++) {
  118. NameLen = sizeof(NameBuf)/sizeof(WCHAR);
  119. Status = ClusterResourceEnum(ResEnum,
  120. j,
  121. &Type,
  122. NameBuf,
  123. &NameLen);
  124. if (Status == ERROR_NO_MORE_ITEMS) {
  125. break;
  126. } else if (Status != ERROR_SUCCESS) {
  127. fprintf(stderr, "ClusterResourceEnum %d returned error %d\n",i,Status);
  128. break;
  129. } else {
  130. printf("%ws ",NameBuf);
  131. }
  132. }
  133. if (Status == ERROR_NO_MORE_ITEMS) {
  134. printf("\nResource count: %d\n", j);
  135. ResCountAfter = ClusterResourceGetEnumCount(ResEnum);
  136. if (ResCountBefore != ResCountAfter)
  137. fprintf(stderr, "\nReported resource count was %d before enumeration, and %d afterward\n", ResCountBefore, ResCountAfter);
  138. else if (j != ResCountBefore)
  139. fprintf(stderr, "\nReported resource count: %d\n", ResCountBefore);
  140. }
  141. ClusterResourceCloseEnum(ResEnum);
  142. //
  143. // Dump out resource dependencies:
  144. //
  145. ResEnum = ClusterResourceOpenEnum(Resource, CLUSTER_RESOURCE_ENUM_PROVIDES);
  146. if (ResEnum == NULL) {
  147. fprintf(stderr,
  148. "ClusterResourceOpenEnum CLUSTER_RESOURCE_ENUM_PROVIDES failed %d\n",
  149. GetLastError());
  150. return(0);
  151. }
  152. ResCountBefore = ClusterResourceGetEnumCount(ResEnum);
  153. printf("\n\tPROVIDES FOR:\t");
  154. for (j=0; ; j++) {
  155. NameLen = sizeof(NameBuf)/sizeof(WCHAR);
  156. Status = ClusterResourceEnum(ResEnum,
  157. j,
  158. &Type,
  159. NameBuf,
  160. &NameLen);
  161. if (Status == ERROR_NO_MORE_ITEMS) {
  162. break;
  163. } else if (Status != ERROR_SUCCESS) {
  164. fprintf(stderr, "ClusterResourceEnum %d returned error %d\n",i,Status);
  165. break;
  166. } else {
  167. printf("%ws ",NameBuf);
  168. }
  169. }
  170. if (Status == ERROR_NO_MORE_ITEMS) {
  171. printf("\nResource count: %d\n", j);
  172. ResCountAfter = ClusterResourceGetEnumCount(ResEnum);
  173. if (ResCountBefore != ResCountAfter)
  174. fprintf(stderr, "\nReported resource count was %d before enumeration, and %d afterward\n", ResCountBefore, ResCountAfter);
  175. else if (j != ResCountBefore)
  176. fprintf(stderr, "\nReported resource count: %d\n", ResCountBefore);
  177. }
  178. printf("\n");
  179. ClusterResourceCloseEnum(ResEnum);
  180. CloseClusterResource(Resource);
  181. }
  182. if (Status == ERROR_NO_MORE_ITEMS) {
  183. printf("\nCluster count: %d\n", i);
  184. ClusterCountAfter = ClusterGetEnumCount(Enum);
  185. if (ClusterCountBefore != ClusterCountAfter)
  186. fprintf(stderr, "\nReported cluster count was %d before enumeration, and %d afterward\n", ClusterCountBefore, ClusterCountAfter);
  187. else if (i != ClusterCountBefore)
  188. fprintf(stderr, "\nReported cluster count: %d\n", ClusterCountBefore);
  189. }
  190. ClusterCloseEnum(Enum);
  191. }