|
| 1 | +use proto::scheduler::{Resource, ResourceSummary}; |
| 2 | + |
| 3 | +pub struct ResourceParser {} |
| 4 | + |
| 5 | +impl ResourceParser { |
| 6 | + /// It converts a Resource struct to a proto::agent::Resource struct. |
| 7 | + /// |
| 8 | + /// Arguments: |
| 9 | + /// |
| 10 | + /// * `resource`: Resource |
| 11 | + /// |
| 12 | + /// Returns: |
| 13 | + /// |
| 14 | + /// A proto::agent::Resource struct |
| 15 | + pub fn to_agent_resource(resource: Resource) -> proto::agent::Resource { |
| 16 | + proto::agent::Resource { |
| 17 | + limit: resource.limit.map(Self::to_agent_resourcesummary), |
| 18 | + usage: resource.usage.map(Self::to_agent_resourcesummary), |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + /// It converts a Resource struct to a proto::controller::Resource struct. |
| 23 | + /// |
| 24 | + /// Arguments: |
| 25 | + /// |
| 26 | + /// * `resource`: Resource |
| 27 | + /// |
| 28 | + /// Returns: |
| 29 | + /// |
| 30 | + /// A proto::controller::Resource struct |
| 31 | + pub fn to_controller_resource(resource: Resource) -> proto::controller::Resource { |
| 32 | + proto::controller::Resource { |
| 33 | + limit: resource.limit.map(Self::to_controller_resourcesummary), |
| 34 | + usage: resource.usage.map(Self::to_controller_resourcesummary), |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /// It converts a proto::agent::Resource struct to a Resource struct. |
| 39 | + /// |
| 40 | + /// Arguments: |
| 41 | + /// |
| 42 | + /// * `resource`: proto::agent::Resource |
| 43 | + /// |
| 44 | + /// Returns: |
| 45 | + /// |
| 46 | + /// A Resource struct |
| 47 | + pub fn from_agent_resource(resource: proto::agent::Resource) -> Resource { |
| 48 | + Resource { |
| 49 | + limit: resource.limit.map(Self::from_agent_resourcesummary), |
| 50 | + usage: resource.usage.map(Self::from_agent_resourcesummary), |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /// It converts a ResourceSummary to a proto::agent::ResourceSummary struct. |
| 55 | + /// |
| 56 | + /// Arguments: |
| 57 | + /// |
| 58 | + /// * `resource`: ResourceSummary |
| 59 | + /// |
| 60 | + /// Returns: |
| 61 | + /// |
| 62 | + /// A proto::agent::ResourceSummary struct |
| 63 | + pub fn to_agent_resourcesummary(resource: ResourceSummary) -> proto::agent::ResourceSummary { |
| 64 | + proto::agent::ResourceSummary { |
| 65 | + cpu: resource.cpu, |
| 66 | + memory: resource.memory, |
| 67 | + disk: resource.disk, |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /// It converts a ResourceSummary to a proto::agent::ResourceSummary struct. |
| 72 | + /// |
| 73 | + /// Arguments: |
| 74 | + /// |
| 75 | + /// * `resource`: ResourceSummary |
| 76 | + /// |
| 77 | + /// Returns: |
| 78 | + /// |
| 79 | + /// A proto::agent::ResourceSummary struct |
| 80 | + pub fn to_controller_resourcesummary( |
| 81 | + resource: ResourceSummary, |
| 82 | + ) -> proto::controller::ResourceSummary { |
| 83 | + proto::controller::ResourceSummary { |
| 84 | + cpu: resource.cpu, |
| 85 | + memory: resource.memory, |
| 86 | + disk: resource.disk, |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + /// It converts a proto::agent::ResourceSummary to a ResourceSummary struct. |
| 91 | + /// |
| 92 | + /// Arguments: |
| 93 | + /// |
| 94 | + /// * `resource`: proto::agent::ResourceSummary |
| 95 | + /// |
| 96 | + /// Returns: |
| 97 | + /// |
| 98 | + /// A ResourceSummary struct |
| 99 | + pub fn from_agent_resourcesummary(resource: proto::agent::ResourceSummary) -> ResourceSummary { |
| 100 | + ResourceSummary { |
| 101 | + cpu: resource.cpu, |
| 102 | + memory: resource.memory, |
| 103 | + disk: resource.disk, |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments