Skip to main content

mssf_core/runtime/
self_reconfiguring_proxy.rs

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
6use crate::ErrorCode;
7use crate::types::{
8    FaultType, HealthInformation, LoadMetric, LoadMetricListRef, MoveCost,
9    SelfReconfiguringConfigurationReport, ServicePartitionInformation,
10};
11use mssf_com::FabricRuntime::IFabricSelfReconfiguringServicePartition;
12
13/// Wrapper for the `IFabricSelfReconfiguringServicePartition` COM interface.
14///
15/// Unlike the stateless partition, this interface has no versioned successor, so
16/// the base interface is wrapped directly.
17#[derive(Debug, Clone)]
18pub struct SelfReconfiguringServicePartition {
19    com_impl: IFabricSelfReconfiguringServicePartition,
20}
21
22impl SelfReconfiguringServicePartition {
23    pub fn new(
24        com_impl: IFabricSelfReconfiguringServicePartition,
25    ) -> SelfReconfiguringServicePartition {
26        SelfReconfiguringServicePartition { com_impl }
27    }
28
29    pub fn get_com(&self) -> &IFabricSelfReconfiguringServicePartition {
30        &self.com_impl
31    }
32}
33
34impl crate::runtime::ISelfReconfiguringServicePartition for SelfReconfiguringServicePartition {
35    fn get_partition_info(&self) -> crate::Result<ServicePartitionInformation> {
36        // Treat a null partition info pointer as an error rather than panicking,
37        // following the stateful partition proxy pattern.
38        unsafe { self.com_impl.GetPartitionInfo()?.as_ref() }
39            .ok_or(ErrorCode::E_POINTER.into())
40            .map(ServicePartitionInformation::from)
41    }
42
43    fn report_load(&self, metrics: &[LoadMetric]) -> crate::Result<()> {
44        let metrics_ref = LoadMetricListRef::from_slice(metrics);
45        let raw = metrics_ref.as_raw_slice();
46        unsafe { self.com_impl.ReportLoad(raw) }.map_err(crate::Error::from)
47    }
48
49    fn report_fault(&self, fault_type: FaultType) -> crate::Result<()> {
50        unsafe { self.com_impl.ReportFault(fault_type.into()) }.map_err(crate::Error::from)
51    }
52
53    fn report_move_cost(&self, move_cost: MoveCost) -> crate::Result<()> {
54        unsafe { self.com_impl.ReportMoveCost(move_cost.into()) }.map_err(crate::Error::from)
55    }
56
57    fn report_instance_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
58        let healthinfo_ref = &healthinfo.into();
59        unsafe {
60            self.com_impl
61                .ReportInstanceHealth(healthinfo_ref, std::ptr::null())
62        }
63        .map_err(crate::Error::from)
64    }
65
66    fn report_partition_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
67        let healthinfo_ref = &healthinfo.into();
68        unsafe {
69            self.com_impl
70                .ReportPartitionHealth(healthinfo_ref, std::ptr::null())
71        }
72        .map_err(crate::Error::from)
73    }
74
75    fn report_configuration(
76        &self,
77        report: &SelfReconfiguringConfigurationReport,
78    ) -> crate::Result<()> {
79        let view = report.get_view();
80        unsafe { self.com_impl.ReportConfiguration(view.get_raw()) }.map_err(crate::Error::from)
81    }
82}