/src/prod/src/Reliability/Failover/fm/NodeInfo.h

https://github.com/Microsoft/service-fabric · C Header · 228 lines · 160 code · 61 blank · 7 comment · 7 complexity · 43ebd10eecf898d06dcb035ff345ada4 MD5 · raw file

  1. // ------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
  4. // ------------------------------------------------------------
  5. #pragma once
  6. namespace Reliability
  7. {
  8. namespace FailoverManagerComponent
  9. {
  10. class NodeInfo : public StoreData
  11. {
  12. public:
  13. NodeInfo();
  14. NodeInfo(
  15. Federation::NodeInstance const& nodeInstance,
  16. NodeDescription && nodeDescription,
  17. bool isReplicaUploaded);
  18. NodeInfo(
  19. Federation::NodeInstance const& nodeInstance,
  20. NodeDescription && nodeDescription,
  21. bool isUp,
  22. bool isReplicaUploaded,
  23. bool isNodeStateRemoved,
  24. Common::DateTime lastUpdated);
  25. NodeInfo(NodeInfo const& other);
  26. NodeInfo(NodeInfo && other);
  27. void InitializeNodeName();
  28. NodeInfo & operator=(NodeInfo && other);
  29. static std::wstring const& GetStoreType();
  30. virtual std::wstring const& GetStoreKey() const;
  31. FABRIC_FIELDS_17(
  32. nodeInstance_,
  33. lastUpdated_,
  34. isUp_,
  35. isReplicaUploaded_,
  36. isNodeHealthReportedDuringDeactivate_,
  37. isNodeStateRemoved_,
  38. nodeDescription_,
  39. actualUpgradeDomainId_,
  40. sequenceNumber_,
  41. deactivationInfo_,
  42. healthSequence_,
  43. isNodeHealthReportedDuringUpgrade_,
  44. isPendingDeactivateNode_,
  45. isPendingFabricUpgrade_,
  46. pendingApplicationUpgrades_,
  47. nodeUpTime_,
  48. nodeDownTime_);
  49. __declspec (property(get=get_NodeId)) Federation::NodeId Id;
  50. Federation::NodeId get_NodeId() const { return nodeInstance_.Id; }
  51. __declspec (property(get=get_NodeInstance)) Federation::NodeInstance const& NodeInstance;
  52. Federation::NodeInstance const& get_NodeInstance() const { return nodeInstance_; }
  53. __declspec (property(get=get_Description, put=set_Description)) NodeDescription & Description;
  54. NodeDescription const& get_Description() const { return nodeDescription_; }
  55. void set_Description(NodeDescription const& value) { nodeDescription_ = value; }
  56. __declspec (property(get=get_NodeStatus)) FABRIC_QUERY_NODE_STATUS NodeStatus;
  57. FABRIC_QUERY_NODE_STATUS get_NodeStatus() const;
  58. __declspec (property(get=get_NodeUpTime, put=set_NodeUpTime)) Common::DateTime NodeUpTime;
  59. Common::DateTime get_NodeUpTime() const { return nodeUpTime_; }
  60. void set_NodeUpTime(Common::DateTime value) { nodeUpTime_ = value; }
  61. __declspec (property(get = get_NodeDownTime, put = set_NodeDownTime)) Common::DateTime NodeDownTime;
  62. Common::DateTime get_NodeDownTime() const { return nodeDownTime_; }
  63. void set_NodeDownTime(Common::DateTime value) { nodeDownTime_ = value; }
  64. __declspec (property(get=get_VersionInstance)) Common::FabricVersionInstance const& VersionInstance;
  65. Common::FabricVersionInstance const& get_VersionInstance() const { return nodeDescription_.VersionInstance; }
  66. __declspec (property(get=get_IdString)) std::wstring const& IdString;
  67. std::wstring const& get_IdString() const;
  68. __declspec (property(get=get_IsUp)) bool IsUp;
  69. bool get_IsUp() const { return isUp_; }
  70. __declspec (property(get=get_IsUnknown)) bool IsUnknown;
  71. bool get_IsUnknown() const { return VersionInstance == Common::FabricVersionInstance::Invalid; }
  72. __declspec (property(get=get_IsReplicaUploaded, put=set_IsReplicaUploaded)) bool IsReplicaUploaded;
  73. bool get_IsReplicaUploaded() const { return isReplicaUploaded_; }
  74. void set_IsReplicaUploaded(bool value) { isReplicaUploaded_ = value; }
  75. __declspec (property(get=get_DeactivationInfo, put=set_DeactivationInfo)) NodeDeactivationInfo & DeactivationInfo;
  76. NodeDeactivationInfo const& get_DeactivationInfo() const { return deactivationInfo_; }
  77. NodeDeactivationInfo & get_DeactivationInfo() { return deactivationInfo_; }
  78. void set_DeactivationInfo(NodeDeactivationInfo const& value) { deactivationInfo_ = value; }
  79. __declspec (property(get=get_IsNodeStateRemoved, put=set_IsNodeStateRemoved)) bool IsNodeStateRemoved;
  80. bool get_IsNodeStateRemoved() const { return isNodeStateRemoved_; }
  81. void set_IsNodeStateRemoved(bool value) { isNodeStateRemoved_ = value; }
  82. __declspec (property(get=get_IsStale, put=set_IsStale)) bool IsStale;
  83. bool get_IsStale() const { return isStale_; }
  84. void set_IsStale(bool value) { isStale_ = value; }
  85. __declspec (property(get=get_LastUpdated)) Common::DateTime LastUpdated;
  86. Common::DateTime get_LastUpdated() const { return lastUpdated_; }
  87. __declspec (property(get=get_SequenceNumber, put=set_SequenceNumber)) uint64 SequenceNumber;
  88. uint64 get_SequenceNumber() const { return sequenceNumber_; }
  89. void set_SequenceNumber(uint64 value) { sequenceNumber_ = value; }
  90. __declspec (property(get=get_HealthSequence, put=set_HealthSequence)) FABRIC_SEQUENCE_NUMBER HealthSequence;
  91. FABRIC_SEQUENCE_NUMBER get_HealthSequence() const { return healthSequence_; }
  92. void set_HealthSequence(FABRIC_SEQUENCE_NUMBER value) { healthSequence_ = value; }
  93. __declspec (property(get=get_IsNodeHealthReportedDuringUpgrade, put=set_IsNodeHealthReportedDuringUpgrade)) bool IsNodeHealthReportedDuringUpgrade;
  94. bool get_IsNodeHealthReportedDuringUpgrade() const { return isNodeHealthReportedDuringUpgrade_; }
  95. void set_IsNodeHealthReportedDuringUpgrade(bool value) { isNodeHealthReportedDuringUpgrade_ = value; }
  96. __declspec (property(get = get_IsNodeHealthReportedDuringDeactivate, put = set_IsNodeHealthReportedDuringDeactivate)) bool IsNodeHealthReportedDuringDeactivate;
  97. bool get_IsNodeHealthReportedDuringDeactivate() const { return isNodeHealthReportedDuringDeactivate_; }
  98. void set_IsNodeHealthReportedDuringDeactivate(bool value) { isNodeHealthReportedDuringDeactivate_ = value; }
  99. __declspec (property(get=get_NodeProperties)) std::map<std::wstring, std::wstring> const& NodeProperties;
  100. std::map<std::wstring, std::wstring> const& get_NodeProperties() const { return nodeDescription_.NodePropertyMap; }
  101. __declspec (property(get=get_NodeCapacityRatios)) std::map<std::wstring, uint> const& NodeCapacityRatios;
  102. std::map<std::wstring, uint> const& get_NodeCapacityRatios() const { return nodeDescription_.NodeCapacityRatioMap; }
  103. __declspec (property(get=get_NodeCapacities)) std::map<std::wstring, uint> const& NodeCapacities;
  104. std::map<std::wstring, uint> const& get_NodeCapacities() const { return nodeDescription_.NodeCapacityMap; }
  105. __declspec (property(get=get_UpgradeDomainId)) std::wstring const& UpgradeDomainId;
  106. std::wstring const& get_UpgradeDomainId() const { return nodeDescription_.NodeUpgradeDomainId; }
  107. __declspec (property(get=get_ActualUpgradeDomainId)) std::wstring const& ActualUpgradeDomainId;
  108. std::wstring const& get_ActualUpgradeDomainId() const { return actualUpgradeDomainId_; }
  109. __declspec (property(get=get_FaultDomainIds)) std::vector<Common::Uri> const & FaultDomainIds;
  110. std::vector<Common::Uri> const & get_FaultDomainIds() const { return nodeDescription_.NodeFaultDomainIds; }
  111. __declspec (property(get=get_FaultDomainId)) std::wstring FaultDomainId;
  112. std::wstring get_FaultDomainId() const;
  113. __declspec (property(get=get_NodeName)) std::wstring const& NodeName;
  114. std::wstring const& get_NodeName() const { return nodeDescription_.NodeName; }
  115. __declspec (property(get=get_NodeType)) std::wstring const& NodeType;
  116. std::wstring const& get_NodeType() const { return nodeDescription_.NodeType; }
  117. __declspec (property(get=get_IpAddressOrFQDN)) std::wstring const& IpAddressOrFQDN;
  118. std::wstring const& get_IpAddressOrFQDN() const { return nodeDescription_.IpAddressOrFQDN; }
  119. __declspec (property(get = get_DisabledPartitions, put = set_DisabledPartitions)) std::vector<PartitionId> DisabledPartitions;
  120. std::vector<PartitionId> get_DisabledPartitions() const { return disabledPartitions_; }
  121. void set_DisabledPartitions(std::vector<PartitionId> && value) { disabledPartitions_ = move(value); }
  122. __declspec (property(get=get_IsPendingDeactivateNode, put=set_IsPendingDeactivateNode)) bool IsPendingDeactivateNode;
  123. bool get_IsPendingDeactivateNode() const { return isPendingDeactivateNode_; }
  124. void set_IsPendingDeactivateNode(bool value) { isPendingDeactivateNode_ = value; }
  125. __declspec (property(get=get_IsPendingFabricUpgrade, put=set_IsPendingFabricUpgrade)) bool IsPendingFabricUpgrade;
  126. bool get_IsPendingFabricUpgrade() const { return isPendingFabricUpgrade_; }
  127. void set_IsPendingFabricUpgrade(bool value) { isPendingFabricUpgrade_ = value; }
  128. __declspec (property(get = get_IsPendingUpgrade)) bool IsPendingUpgrade;
  129. bool get_IsPendingUpgrade() const { return (isPendingFabricUpgrade_ || !pendingApplicationUpgrades_.empty()); }
  130. bool IsPendingApplicationUpgrade(ServiceModel::ApplicationIdentifier const& applicationId) const;
  131. void AddPendingApplicationUpgrade(ServiceModel::ApplicationIdentifier const& applicationId);
  132. void RemovePendingApplicationUpgrade(ServiceModel::ApplicationIdentifier const& applicationId);
  133. bool IsPendingUpgradeOrDeactivateNode() const;
  134. bool IsPendingNodeClose(FailoverManager const& fm) const;
  135. bool IsPendingClose(FailoverManager const& fm, ApplicationInfo const& applicationInfo) const;
  136. static std::wstring GetActualUpgradeDomain(Federation::NodeId nodeId, std::wstring const& upgradeDomain);
  137. LoadBalancingComponent::NodeDescription GetPLBNodeDescription() const;
  138. void PostUpdate(Common::DateTime updatedTime);
  139. void WriteTo(Common::TextWriter&, Common::FormatOptions const &) const;
  140. private:
  141. Federation::NodeInstance nodeInstance_;
  142. Common::DateTime lastUpdated_;
  143. bool isUp_;
  144. bool isReplicaUploaded_;
  145. bool isNodeStateRemoved_;
  146. NodeDescription nodeDescription_;
  147. Common::DateTime nodeUpTime_;
  148. Common::DateTime nodeDownTime_;
  149. std::wstring actualUpgradeDomainId_;
  150. // Used to detect stale messages
  151. uint64 sequenceNumber_;
  152. NodeDeactivationInfo deactivationInfo_;
  153. bool isPendingDeactivateNode_;
  154. bool isPendingFabricUpgrade_;
  155. std::vector<ServiceModel::ApplicationIdentifier> pendingApplicationUpgrades_;
  156. std::vector<PartitionId> disabledPartitions_;
  157. FABRIC_SEQUENCE_NUMBER healthSequence_;
  158. bool isNodeHealthReportedDuringUpgrade_;
  159. bool isNodeHealthReportedDuringDeactivate_;
  160. // this fields indicate that whether there is a newer
  161. // NodeInfo in the node cache for this node
  162. mutable bool isStale_;
  163. mutable std::wstring idString_;
  164. };
  165. }
  166. }
  167. DEFINE_USER_ARRAY_UTILITY(Reliability::FailoverManagerComponent::NodeInfo);