-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from k82cn/flm_119
Add register_application
- Loading branch information
Showing
14 changed files
with
316 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2025 The Flame Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::{fs, path::Path}; | ||
|
||
use serde_derive::{Deserialize, Serialize}; | ||
|
||
use common::ctx::FlameContext; | ||
use flame_client::{self as flame, ApplicationAttributes, FlameError, Shim}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
struct MetadataYaml { | ||
pub name: String, | ||
} | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
struct SpecYaml { | ||
pub shim: Option<String>, | ||
pub url: Option<String>, | ||
pub command: Option<String>, | ||
pub arguments: Option<Vec<String>>, | ||
pub environments: Option<Vec<String>>, | ||
pub working_directory: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
struct ApplicationYaml { | ||
pub metadata: MetadataYaml, | ||
pub spec: SpecYaml, | ||
} | ||
|
||
pub async fn run(ctx: &FlameContext, path: &String) -> Result<(), FlameError> { | ||
if !Path::new(&path).is_file() { | ||
return Err(FlameError::InvalidConfig(format!( | ||
"<{}> is not a file", | ||
path | ||
))); | ||
} | ||
|
||
let contents = | ||
fs::read_to_string(path.clone()).map_err(|e| FlameError::Internal(e.to_string()))?; | ||
let app: ApplicationYaml = | ||
serde_yaml::from_str(&contents).map_err(|e| FlameError::Internal(e.to_string()))?; | ||
|
||
let app_attr = ApplicationAttributes::try_from(&app)?; | ||
|
||
let conn = flame::connect(&ctx.endpoint).await?; | ||
|
||
conn.register_application(app.metadata.name, app_attr) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
impl TryFrom<&ApplicationYaml> for ApplicationAttributes { | ||
type Error = FlameError; | ||
|
||
fn try_from(yaml: &ApplicationYaml) -> Result<Self, Self::Error> { | ||
let shim = match yaml | ||
.spec | ||
.shim | ||
.clone() | ||
.unwrap_or(String::from("grpc")) | ||
.to_lowercase() | ||
.as_str() | ||
{ | ||
"grpc" => Ok(Shim::Grpc), | ||
_ => Err(FlameError::InvalidConfig("unsupported shim".to_string())), | ||
}?; | ||
|
||
Ok(Self { | ||
shim, | ||
url: yaml.spec.url.clone(), | ||
command: yaml.spec.command.clone(), | ||
arguments: yaml.spec.arguments.clone().unwrap_or_default(), | ||
environments: yaml.spec.environments.clone().unwrap_or_default(), | ||
working_directory: yaml.spec.working_directory.clone(), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2025 The Flame Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use std::error::Error; | ||
|
||
use common::ctx::FlameContext; | ||
|
||
pub async fn run(_: &FlameContext, _: &String) -> Result<(), Box<dyn Error>> { | ||
todo!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.