Source code of Windows XP (NT5)
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.

192 lines
4.1 KiB

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