Skip to content

Commit

Permalink
update: using PkgType in GraphNode
Browse files Browse the repository at this point in the history
  • Loading branch information
leoadonia committed Sep 23, 2024
1 parent 14777d0 commit 641cae7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Graph {
self.nodes
.iter()
.find_map(|node| {
if node.node_type == "extension"
if node.node_type == PkgType::Extension
&& node.name.as_str() == extension
&& node.app.as_str() == app
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//
use anyhow::Result;

use crate::pkg_info::graph::{Graph, GraphMessageFlow};
use crate::pkg_info::{
graph::{Graph, GraphMessageFlow},
pkg_type::PkgType,
};

impl Graph {
fn check_if_dest_of_connection_are_defined_in_nodes(
Expand Down Expand Up @@ -47,7 +50,7 @@ impl Graph {

let mut all_extensions: Vec<String> = Vec::new();
for node in &self.nodes {
if node.node_type.as_str() == "extension" {
if node.node_type == PkgType::Extension {
let unique_ext_name = format!(
"{}:{}:{}",
node.app.as_str(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
use anyhow::Result;

use crate::pkg_info::graph::Graph;
use crate::pkg_info::{graph::Graph, pkg_type::PkgType};

impl Graph {
pub fn check_if_nodes_duplicated(&self) -> Result<()> {
Expand All @@ -15,8 +15,8 @@ impl Graph {
let mut all_extension_groups: Vec<String> = Vec::new();

for (node_idx, node) in self.nodes.iter().enumerate() {
match node.node_type.as_str() {
"extension" => {
match node.node_type {
PkgType::Extension => {
let unique_ext_name = format!(
"{}:{}:{}",
node.app.as_str(),
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Graph {
}
}

"extension_group" => {
PkgType::ExtensionGroup => {
let unique_ext_group_name =
format!("{}:{}", node.app.as_str(), node.name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::collections::HashMap;

use anyhow::Result;

use crate::pkg_info::{graph::Graph, PkgInfo};
use crate::pkg_info::{graph::Graph, pkg_type::PkgType, PkgInfo};

impl Graph {
pub fn check_if_nodes_have_installed(
&self,
all_needed_pkgs: &HashMap<String, Vec<PkgInfo>>,
) -> Result<()> {
// app, node_type, node_addon
let mut not_installed_pkgs: Vec<(String, String, String)> = Vec::new();
let mut not_installed_pkgs: Vec<(String, PkgType, String)> = Vec::new();

for node in &self.nodes {
if !all_needed_pkgs.contains_key(node.app.as_str()) {
Expand All @@ -29,7 +29,7 @@ impl Graph {

let pkgs_in_app = all_needed_pkgs.get(node.app.as_str()).unwrap();
let found = pkgs_in_app.iter().find(|pkg| {
pkg.pkg_identity.pkg_type.to_string() == node.node_type
pkg.pkg_identity.pkg_type == node.node_type
&& pkg.pkg_identity.name == node.addon
&& pkg.is_local_installed
});
Expand Down
9 changes: 6 additions & 3 deletions core/src/ten_rust/src/pkg_info/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::{
pkg_type::PkgType,
predefined_graphs::{
connection::{PkgConnection, PkgDestination, PkgMessageFlow},
node::PkgNode,
Expand Down Expand Up @@ -76,7 +77,7 @@ impl Graph {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GraphNode {
#[serde(rename = "type")]
pub node_type: String,
pub node_type: PkgType,
pub name: String,
pub addon: String,

Expand All @@ -95,7 +96,9 @@ pub struct GraphNode {
impl GraphNode {
fn validate_and_complete(&mut self) -> Result<()> {
// extension node must specify extension_group name.
if self.node_type == "extension" && self.extension_group.is_none() {
if self.node_type == PkgType::Extension
&& self.extension_group.is_none()
{
return Err(anyhow::anyhow!(
"Node '{}' of type 'extension' must have an 'extension_group' defined.",
self.name
Expand All @@ -109,7 +112,7 @@ impl GraphNode {
impl From<PkgNode> for GraphNode {
fn from(pkg_node: PkgNode) -> Self {
GraphNode {
node_type: pkg_node.node_type.to_string(),
node_type: pkg_node.node_type.clone(),
name: pkg_node.name.clone(),
addon: pkg_node.addon.clone(),
extension_group: pkg_node.extension_group.clone(),
Expand Down
4 changes: 1 addition & 3 deletions core/src/ten_rust/src/pkg_info/predefined_graphs/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
use std::str::FromStr;

use crate::pkg_info::{graph::GraphNode, pkg_type::PkgType, PkgInfo};

#[derive(Debug, Clone)]
Expand All @@ -28,7 +26,7 @@ pub struct PkgNode {
impl From<GraphNode> for PkgNode {
fn from(manifest_node: GraphNode) -> Self {
PkgNode {
node_type: PkgType::from_str(&manifest_node.node_type).unwrap(),
node_type: manifest_node.node_type,
name: manifest_node.name,
addon: manifest_node.addon,
extension_group: manifest_node.extension_group,
Expand Down

0 comments on commit 641cae7

Please sign in to comment.