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.

193 lines
4.4 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: ClusterInstallationUnit.cpp
  4. //
  5. // Synopsis: Defines a ClusterInstallationUnit
  6. // This object has the knowledge for installing the
  7. // clustering service
  8. //
  9. // History: 02/09/2001 JeffJon Created
  10. #include "pch.h"
  11. #include "resource.h"
  12. #include "ClusterInstallationUnit.h"
  13. #include <clusapi.h>
  14. // Finish page help
  15. static PCWSTR CYS_CLUSTER_FINISH_PAGE_HELP = L"cys.chm::/cys_configuring_cluster_server.htm";
  16. static PCWSTR CYS_CLUSTER_AFTER_FINISH_HELP = L"cys.chm::/cys_after_cluster_server.htm";
  17. ClusterInstallationUnit::ClusterInstallationUnit() :
  18. makeNewCluster(true),
  19. InstallationUnit(
  20. IDS_CLUSTER_SERVER_TYPE,
  21. IDS_CLUSTER_SERVER_DESCRIPTION,
  22. CYS_CLUSTER_FINISH_PAGE_HELP,
  23. CYS_CLUSTER_AFTER_FINISH_HELP,
  24. CLUSTERSERVER_INSTALL)
  25. {
  26. LOG_CTOR(ClusterInstallationUnit);
  27. }
  28. ClusterInstallationUnit::~ClusterInstallationUnit()
  29. {
  30. LOG_DTOR(ClusterInstallationUnit);
  31. }
  32. InstallationReturnType
  33. ClusterInstallationUnit::InstallService(HANDLE logfileHandle, HWND /*hwnd*/)
  34. {
  35. LOG_FUNCTION(ClusterInstallationUnit::InstallService);
  36. InstallationReturnType result = INSTALL_SUCCESS;
  37. // Log heading
  38. CYS_APPEND_LOG(String::load(IDS_LOG_CLUSTER_HEADING));
  39. String commandLine;
  40. // Build the command line
  41. if (MakeNewCluster())
  42. {
  43. commandLine = L"cluster /Create /Wizard";
  44. }
  45. else
  46. {
  47. commandLine = L"cluster /Add /Wizard";
  48. }
  49. // Run the wizard
  50. DWORD exitCode = 0;
  51. HRESULT hr = CreateAndWaitForProcess(commandLine, exitCode);
  52. if (FAILED(hr))
  53. {
  54. // Failed to launch the wizard
  55. LOG(String::format(
  56. L"Failed to launch cluster wizard: hr = 0x%1!x!",
  57. hr));
  58. if (MakeNewCluster())
  59. {
  60. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_LAUNCH_FAILED_NEW_CLUSTER));
  61. }
  62. else
  63. {
  64. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_LAUNCH_FAILED_ADD_NODE));
  65. }
  66. result = INSTALL_FAILURE;
  67. }
  68. else if (SUCCEEDED(hr) &&
  69. exitCode == 0)
  70. {
  71. // Wizard was launched and completed successfully
  72. LOG(L"Cluster wizard launched and completed successfully");
  73. if (MakeNewCluster())
  74. {
  75. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_SUCCESS_NEW_CLUSTER));
  76. }
  77. else
  78. {
  79. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_SUCCESS_ADD_NODE));
  80. }
  81. result = INSTALL_SUCCESS;
  82. }
  83. else // if (SUCCEEDED(hr) && exitCode == ????<some exit code for cancelled>???
  84. {
  85. // Wizard was cancelled by the user
  86. LOG(L"Cluster wizard cancelled by user");
  87. if (MakeNewCluster())
  88. {
  89. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_CANCELLED_NEW_CLUSTER));
  90. }
  91. else
  92. {
  93. CYS_APPEND_LOG(String::load(IDS_CLUSTER_LOG_CANCELLED_ADD_NODE));
  94. }
  95. result = INSTALL_FAILURE;
  96. }
  97. LOG_INSTALL_RETURN(result);
  98. return result;
  99. }
  100. bool
  101. ClusterInstallationUnit::IsServiceInstalled()
  102. {
  103. LOG_FUNCTION(ClusterInstallationUnit::IsServiceInstalled);
  104. bool result = false;
  105. DWORD clusterState = 0;
  106. DWORD err = ::GetNodeClusterState(0, &clusterState);
  107. if (err == ERROR_SUCCESS &&
  108. clusterState != ClusterStateNotConfigured)
  109. {
  110. result = true;
  111. }
  112. else
  113. {
  114. LOG(String::format(
  115. L"GetNodeClusterState returned err = %1!x!",
  116. err));
  117. }
  118. LOG_BOOL(result);
  119. return result;
  120. }
  121. bool
  122. ClusterInstallationUnit::GetFinishText(String& message)
  123. {
  124. LOG_FUNCTION(ClusterInstallationUnit::GetFinishText);
  125. if (MakeNewCluster())
  126. {
  127. message = String::load(IDS_CLUSTER_FINISH_TEXT_NEW_CLUSTER);
  128. }
  129. else
  130. {
  131. message = String::load(IDS_CLUSTER_FINISH_TEXT_EXISTING_CLUSTER);
  132. }
  133. LOG_BOOL(true);
  134. return true;
  135. }
  136. String
  137. ClusterInstallationUnit::GetServiceDescription()
  138. {
  139. LOG_FUNCTION(ClusterInstallationUnit::GetServiceDescription);
  140. unsigned int descriptionID = IDS_CLUSTER_SERVER_DESCRIPTION;
  141. if (IsServiceInstalled())
  142. {
  143. descriptionID = IDS_CLUSTER_SERVER_DESCRIPTION_INSTALLED;
  144. }
  145. return String::load(descriptionID);
  146. }
  147. bool
  148. ClusterInstallationUnit::MakeNewCluster() const
  149. {
  150. LOG_FUNCTION(ClusterInstallationUnit::MakeNewCluster);
  151. return makeNewCluster;
  152. }