Skip to main content

mssf_core/runtime/
stateless_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::types::{
7    FaultType, HealthInformation, LoadMetric, LoadMetricListRef, MoveCost,
8    ServicePartitionInformation,
9};
10use mssf_com::FabricRuntime::{
11    IFabricStatelessServicePartition, IFabricStatelessServicePartition3,
12};
13use windows_core::Interface;
14// wrap of com interface
15#[derive(Debug, Clone)]
16pub struct StatelessServicePartition {
17    com_impl: IFabricStatelessServicePartition3,
18}
19
20impl StatelessServicePartition {
21    pub fn new(com_impl: IFabricStatelessServicePartition) -> StatelessServicePartition {
22        StatelessServicePartition {
23            com_impl: com_impl.cast().unwrap(),
24        } // cast to the newer version.
25    }
26
27    pub fn get_com(&self) -> &IFabricStatelessServicePartition3 {
28        &self.com_impl
29    }
30}
31
32impl crate::runtime::IStatelessServicePartition for StatelessServicePartition {
33    fn get_partition_info(&self) -> crate::Result<ServicePartitionInformation> {
34        let raw = unsafe { self.com_impl.GetPartitionInfo() }?;
35        let raw_ref = unsafe { raw.as_ref().unwrap() };
36        assert!(!raw.is_null());
37        Ok(raw_ref.into())
38    }
39
40    fn report_load(&self, metrics: &[LoadMetric]) -> crate::Result<()> {
41        let metrics_ref = LoadMetricListRef::from_slice(metrics);
42        let raw = metrics_ref.as_raw_slice();
43        unsafe { self.com_impl.ReportLoad(raw) }.map_err(crate::Error::from)
44    }
45
46    fn report_fault(&self, fault_type: FaultType) -> crate::Result<()> {
47        unsafe { self.com_impl.ReportFault(fault_type.into()) }.map_err(crate::Error::from)
48    }
49
50    fn report_move_cost(&self, move_cost: MoveCost) -> crate::Result<()> {
51        unsafe { self.com_impl.ReportMoveCost(move_cost.into()) }.map_err(crate::Error::from)
52    }
53
54    fn report_partition_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
55        let healthinfo_ref = &healthinfo.into();
56        unsafe { self.com_impl.ReportPartitionHealth(healthinfo_ref) }.map_err(crate::Error::from)
57    }
58
59    fn report_instance_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
60        let healthinfo_ref = &healthinfo.into();
61        unsafe { self.com_impl.ReportInstanceHealth(healthinfo_ref) }.map_err(crate::Error::from)
62    }
63}