Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refine rust codes #453

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
"args": [
"--gtest_filter=SendTest.NotSpecifyDest"
"--gtest_filter=ExtensionTest.PredefinedGraphMultiExtension1"
],
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"env": {
Expand Down
22 changes: 5 additions & 17 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,12 @@ fn write_pkgs_into_lock(pkgs: &Vec<&PkgInfo>, app_dir: &Path) -> Result<()> {

fn parse_pkg_name_version(
pkg_name_version: &str,
) -> Result<(String, String, VersionReq)> {
) -> Result<(String, VersionReq)> {
let parts: Vec<&str> = pkg_name_version.split('@').collect();
if parts.len() == 2 {
Ok((
parts[0].to_string(),
parts[1].to_string(),
VersionReq::parse(parts[1])?,
))
Ok((parts[0].to_string(), VersionReq::parse(parts[1])?))
} else {
Ok((
pkg_name_version.to_string(),
VersionReq::STAR.to_string(),
VersionReq::STAR,
))
Ok((pkg_name_version.to_string(), VersionReq::STAR))
}
}

Expand Down Expand Up @@ -540,11 +532,8 @@ pub async fn execute_cmd(
// Case 1: tman install <package_type> <package_name>

let desired_pkg_type_: PkgType = package_type_str.parse()?;
let (
desired_pkg_src_name_,
desired_pkg_src_version_str_,
desired_pkg_src_version_,
) = parse_pkg_name_version(&command_data.package_name.unwrap())?;
let (desired_pkg_src_name_, desired_pkg_src_version_) =
parse_pkg_name_version(&command_data.package_name.unwrap())?;

desired_pkg_type = Some(desired_pkg_type_);
desired_pkg_src_name = Some(desired_pkg_src_name_.clone());
Expand Down Expand Up @@ -599,7 +588,6 @@ pub async fn execute_cmd(
name: desired_pkg_src_name_.clone(),
},
version_req: desired_pkg_src_version_.clone(),
version_req_str: desired_pkg_src_version_str_,
},
};
extra_dependency_relationships.push(extra_dependency_relationship);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
],
"connections": [
{
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
11 changes: 0 additions & 11 deletions core/src/ten_manager/src/designer/graphs/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::designer::DesignerState;
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct DesignerConnection {
pub app: String,
pub extension_group: String,
pub extension: String,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -43,7 +42,6 @@ impl From<GraphConnection> for DesignerConnection {
fn from(conn: GraphConnection) -> Self {
DesignerConnection {
app: conn.get_app_uri().to_string(),
extension_group: conn.extension_group,
extension: conn.extension,

cmd: conn.cmd.map(get_designer_msg_flow_from_property),
Expand Down Expand Up @@ -89,7 +87,6 @@ fn get_designer_msg_flow_from_property(
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct DesignerDestination {
pub app: String,
pub extension_group: String,
pub extension: String,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -100,7 +97,6 @@ impl From<GraphDestination> for DesignerDestination {
fn from(destination: GraphDestination) -> Self {
DesignerDestination {
app: destination.get_app_uri().to_string(),
extension_group: destination.extension_group,
extension: destination.extension,
msg_conversion: destination.msg_conversion,
}
Expand Down Expand Up @@ -240,13 +236,11 @@ mod tests {

let expected_connections = vec![DesignerConnection {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_1".to_string(),
cmd: Some(vec![DesignerMessageFlow {
name: "hello_world".to_string(),
dest: vec![DesignerDestination {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_2".to_string(),
msg_conversion: None,
}],
Expand Down Expand Up @@ -322,13 +316,11 @@ mod tests {

let expected_connections = vec![DesignerConnection {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_1".to_string(),
cmd: Some(vec![DesignerMessageFlow {
name: "hello_world".to_string(),
dest: vec![DesignerDestination {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_2".to_string(),
msg_conversion: None,
}],
Expand All @@ -337,7 +329,6 @@ mod tests {
name: "data".to_string(),
dest: vec![DesignerDestination {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_2".to_string(),
msg_conversion: None,
}],
Expand All @@ -346,7 +337,6 @@ mod tests {
name: "pcm".to_string(),
dest: vec![DesignerDestination {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_2".to_string(),
msg_conversion: None,
}],
Expand All @@ -355,7 +345,6 @@ mod tests {
name: "image".to_string(),
dest: vec![DesignerDestination {
app: localhost(),
extension_group: "extension_group_1".to_string(),
extension: "extension_2".to_string(),
msg_conversion: None,
}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
],
"connections": [
{
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
],
"connections": [
{
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -38,7 +36,6 @@
"name": "data",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -49,7 +46,6 @@
"name": "pcm",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -60,7 +56,6 @@
"name": "image",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
"connections": [
{
"app": "localhost",
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"app": "localhost",
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
],
"connections": [
{
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -38,7 +36,6 @@
"name": "data",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -49,7 +46,6 @@
"name": "pcm",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand All @@ -60,7 +56,6 @@
"name": "image",
"dest": [
{
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
"connections": [
{
"app": "localhost",
"extension_group": "extension_group_1",
"extension": "extension_1",
"cmd": [
{
"name": "hello_world",
"dest": [
{
"app": "localhost",
"extension_group": "extension_group_1",
"extension": "extension_2"
}
]
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_manager/src/manifest_lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ impl<'a> From<&'a ManifestLockItem> for PkgInfo {
name: dep.name,
},
version_req: VersionReq::STAR,
version_req_str: VersionReq::STAR.to_string(),
})
.collect()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl From<DesignerConnection> for GraphConnection {
fn from(designer_connection: DesignerConnection) -> Self {
GraphConnection {
app: Some(designer_connection.app),
extension_group: designer_connection.extension_group,
extension: designer_connection.extension,

cmd: designer_connection
Expand Down Expand Up @@ -58,7 +57,6 @@ impl From<DesignerDestination> for GraphDestination {
fn from(designer_destination: DesignerDestination) -> Self {
GraphDestination {
app: Some(designer_destination.app),
extension_group: designer_destination.extension_group,
extension: designer_destination.extension,
msg_conversion: designer_destination.msg_conversion,
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_manager/src/solver/introducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn extract_introducer_relations_from_raw_solver_results(
// The `version` declared in the `dependencies` section in
// manifest.json is always present.
requested_version_str =
requested_dep_in_introducer.version_req_str.clone();
requested_dep_in_introducer.version_req.to_string();
} else {
return Err(anyhow::anyhow!(
"Requested dependency [{}]{} not found in introducer, should not happen.", pkg_type_str, name
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn get_dependency_chain(
)
.unwrap();
chain.push((
requested_dep_in_introducer.version_req_str.clone(),
requested_dep_in_introducer.version_req.to_string(),
conflict_pkg_identity.clone(),
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
],
"connections": [
{
"extension_group": "some_group",
"extension": "ext_a",
"app": "http://localhost:8000",
"extension": "ext_a",
"cmd": [
{
"name": "cmd_1",
"dest": [
{
"extension_group": "some_group",
"extension": "ext_b"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
],
"connections": [
{
"extension_group": "some_group",
"extension": "ext_a",
"cmd": [
{
"name": "cmd_1",
"dest": [
{
"extension_group": "some_group",
"extension": "ext_b"
}
]
Expand Down Expand Up @@ -55,14 +53,12 @@
],
"connections": [
{
"extension_group": "some_group",
"extension": "ext_a",
"cmd": [
{
"name": "cmd_1",
"dest": [
{
"extension_group": "some_group",
"extension": "ext_c"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
],
"connections": [
{
"extension_group": "some_group",
"extension": "ext_a",
"cmd": [
{
"name": "cmd_1",
"dest": [
{
"extension_group": "some_group",
"extension": "ext_b"
}
]
Expand All @@ -38,4 +36,4 @@
}
]
}
}
}
Loading
Loading