From 9f07e91746dc6774cae29351dff45f740fa7b785 Mon Sep 17 00:00:00 2001 From: Oliver Mueller Date: Fri, 28 Aug 2020 11:37:25 +0200 Subject: [PATCH] Use id for start/stop/uninstall no regex is constructed anymore makes it unambigous which component is meant --- north/src/command_processor.rs | 71 ++++------ north_api/src/proto/api.proto | 6 +- north_api/src/proto/api.rs | 234 ++++++++++++++++----------------- north_client/src/main.rs | 27 ++-- 4 files changed, 160 insertions(+), 178 deletions(-) diff --git a/north/src/command_processor.rs b/north/src/command_processor.rs index 869eb344a..8b66a0bca 100644 --- a/north/src/command_processor.rs +++ b/north/src/command_processor.rs @@ -26,8 +26,8 @@ pub async fn init(tx: &EventTx) -> Result<()> { let tx = tx.clone(); // Spawn a task that handles messages received on the command port. task::spawn(async move { - while let Ok((line, tx_reply)) = rx.recv().await { - tx.send(Event::Command(line, tx_reply)).await; + while let Ok((command, tx_reply)) = rx.recv().await { + tx.send(Event::Command(command, tx_reply)).await; } }); @@ -52,28 +52,16 @@ pub async fn process( Some(api::Request_oneof_instruction::list_containers(_)) => list(state).await, Some(api::Request_oneof_instruction::running_containers(_)) => ps(state).await, Some(api::Request_oneof_instruction::start_container(ref id)) => { - let regex = if id.has_regex() { - Some(id.get_regex()) - } else { - None - }; - start(state, regex).await + let id_str = if id.has_id() { Some(id.get_id()) } else { None }; + start(state, id_str).await } Some(api::Request_oneof_instruction::stop_container(ref id)) => { - let regex = if id.has_regex() { - Some(id.get_regex()) - } else { - None - }; - stop(state, regex).await + let id_str = if id.has_id() { Some(id.get_id()) } else { None }; + stop(state, id_str).await } Some(api::Request_oneof_instruction::uninstall_container(ref id)) => { - let regex = if id.has_regex() { - Some(id.get_regex()) - } else { - None - }; - uninstall(state, regex).await + let id_str = if id.has_id() { Some(id.get_id()) } else { None }; + uninstall(state, id_str).await } Some(api::Request_oneof_instruction::update(ref dir)) => { update(state, dir.get_update_dir()).await @@ -156,15 +144,13 @@ async fn ps(state: &State) -> Result { Ok(response) } -/// Start applications. If no regex string is provided, *all* known applications that -/// are not in a running state are started. If a regex string is supplied it -/// is used to construct a Regex and all container (names) matching that -/// Regex are attempted to be started. -async fn start(state: &mut State, regex_str: Option<&str>) -> Result { +/// Start applications. If no id is provided, *all* known applications that +/// are not in a running state are started. If an id is supplied only a container +/// with this id is started +async fn start(state: &mut State, id_str: Option<&str>) -> Result { let mut response = api::Response::new(); let mut started_containers = api::StartedResponse::default(); let startup_list = started_containers.mut_startup_list(); - let re = id_to_regex(regex_str)?; let apps = state .applications() @@ -173,7 +159,10 @@ async fn start(state: &mut State, regex_str: Option<&str>) -> Result id == app.name(), + None => true, + }) // Sort container by name .sorted_by_key(|app| app.name().clone()) .map(|app| app.name().clone()) @@ -228,15 +217,18 @@ async fn versions(state: &mut State) -> Result { } /// Stop one, some or all containers. See start for the argument handling. -async fn stop(state: &mut State, regex_str: Option<&str>) -> Result { +async fn stop(state: &mut State, id_str: Option<&str>) -> Result { let mut response = api::Response::new(); let mut stopped_containers = api::StoppedResponse::default(); let stop_list = stopped_containers.mut_stop_list(); - let re = id_to_regex(regex_str)?; + let apps = state .applications() .filter(|app| app.process_context().is_some()) - .filter(|app| re.is_match(app.name())) + .filter(|app| match id_str { + Some(id) => id == app.name(), + None => true, + }) .map(|app| app.name().clone()) .collect::>(); for app in &apps { @@ -265,17 +257,19 @@ async fn stop(state: &mut State, regex_str: Option<&str>) -> Result) -> Result { +async fn uninstall(state: &mut State, id_str: Option<&str>) -> Result { let mut response = api::Response::new(); let mut uninstalled_containers = api::UninstallResponse::default(); let uninstall_list = uninstalled_containers.mut_status(); - let re = id_to_regex(regex_str)?; let to_uninstall = state .applications .values() .filter(|app| app.process_context().is_none()) - .filter(|app| re.is_match(app.name())) + .filter(|app| match id_str { + Some(id) => id == app.name(), + None => true, + }) .map(|app| app.name()) .cloned() .collect::>(); @@ -391,14 +385,3 @@ async fn serve() -> Result, sync::Sender>)>> { }); Ok(rx) } - -fn id_to_regex(regex_str: Option<&str>) -> Result { - match regex_str { - Some(s) => { - regex::Regex::new(s).with_context(|| format!("Invalid container name regex {}", s)) - } - None => { - regex::Regex::new(".*").with_context(|| "Invalid container name regex .*".to_string()) - } - } -} diff --git a/north_api/src/proto/api.proto b/north_api/src/proto/api.proto index 6e1128e8a..cf8b7dc3a 100644 --- a/north_api/src/proto/api.proto +++ b/north_api/src/proto/api.proto @@ -37,9 +37,9 @@ message Response { message ListRequest {} message PsRequest {} -message StartRequest { optional string regex = 1; } -message StopRequest { optional string regex = 1; } -message UninstallRequest { optional string regex = 1; } +message StartRequest { optional string id = 1; } +message StopRequest { optional string id = 1; } +message UninstallRequest { optional string id = 1; } message UpdateRequest { required string update_dir = 1; } message ShutdownRequest {} message GetSettingsRequest {} diff --git a/north_api/src/proto/api.rs b/north_api/src/proto/api.rs index 92970010f..535d50aa7 100644 --- a/north_api/src/proto/api.rs +++ b/north_api/src/proto/api.rs @@ -1979,7 +1979,7 @@ impl ::protobuf::reflect::ProtobufValue for PsRequest { #[derive(PartialEq,Clone,Default)] pub struct StartRequest { // message fields - regex: ::protobuf::SingularField<::std::string::String>, + id: ::protobuf::SingularField<::std::string::String>, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -1996,40 +1996,40 @@ impl StartRequest { ::std::default::Default::default() } - // optional string regex = 1; + // optional string id = 1; - pub fn get_regex(&self) -> &str { - match self.regex.as_ref() { + pub fn get_id(&self) -> &str { + match self.id.as_ref() { Some(v) => &v, None => "", } } - pub fn clear_regex(&mut self) { - self.regex.clear(); + pub fn clear_id(&mut self) { + self.id.clear(); } - pub fn has_regex(&self) -> bool { - self.regex.is_some() + pub fn has_id(&self) -> bool { + self.id.is_some() } // Param is passed by value, moved - pub fn set_regex(&mut self, v: ::std::string::String) { - self.regex = ::protobuf::SingularField::some(v); + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = ::protobuf::SingularField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_regex(&mut self) -> &mut ::std::string::String { - if self.regex.is_none() { - self.regex.set_default(); + pub fn mut_id(&mut self) -> &mut ::std::string::String { + if self.id.is_none() { + self.id.set_default(); } - self.regex.as_mut().unwrap() + self.id.as_mut().unwrap() } // Take field - pub fn take_regex(&mut self) -> ::std::string::String { - self.regex.take().unwrap_or_else(|| ::std::string::String::new()) + pub fn take_id(&mut self) -> ::std::string::String { + self.id.take().unwrap_or_else(|| ::std::string::String::new()) } } @@ -2043,7 +2043,7 @@ impl ::protobuf::Message for StartRequest { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.regex)?; + ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.id)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -2057,7 +2057,7 @@ impl ::protobuf::Message for StartRequest { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { my_size += ::protobuf::rt::string_size(1, &v); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); @@ -2066,7 +2066,7 @@ impl ::protobuf::Message for StartRequest { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { os.write_string(1, &v)?; } os.write_unknown_fields(self.get_unknown_fields())?; @@ -2108,9 +2108,9 @@ impl ::protobuf::Message for StartRequest { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "regex", - |m: &StartRequest| { &m.regex }, - |m: &mut StartRequest| { &mut m.regex }, + "id", + |m: &StartRequest| { &m.id }, + |m: &mut StartRequest| { &mut m.id }, )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "StartRequest", @@ -2128,7 +2128,7 @@ impl ::protobuf::Message for StartRequest { impl ::protobuf::Clear for StartRequest { fn clear(&mut self) { - self.regex.clear(); + self.id.clear(); self.unknown_fields.clear(); } } @@ -2148,7 +2148,7 @@ impl ::protobuf::reflect::ProtobufValue for StartRequest { #[derive(PartialEq,Clone,Default)] pub struct StopRequest { // message fields - regex: ::protobuf::SingularField<::std::string::String>, + id: ::protobuf::SingularField<::std::string::String>, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -2165,40 +2165,40 @@ impl StopRequest { ::std::default::Default::default() } - // optional string regex = 1; + // optional string id = 1; - pub fn get_regex(&self) -> &str { - match self.regex.as_ref() { + pub fn get_id(&self) -> &str { + match self.id.as_ref() { Some(v) => &v, None => "", } } - pub fn clear_regex(&mut self) { - self.regex.clear(); + pub fn clear_id(&mut self) { + self.id.clear(); } - pub fn has_regex(&self) -> bool { - self.regex.is_some() + pub fn has_id(&self) -> bool { + self.id.is_some() } // Param is passed by value, moved - pub fn set_regex(&mut self, v: ::std::string::String) { - self.regex = ::protobuf::SingularField::some(v); + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = ::protobuf::SingularField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_regex(&mut self) -> &mut ::std::string::String { - if self.regex.is_none() { - self.regex.set_default(); + pub fn mut_id(&mut self) -> &mut ::std::string::String { + if self.id.is_none() { + self.id.set_default(); } - self.regex.as_mut().unwrap() + self.id.as_mut().unwrap() } // Take field - pub fn take_regex(&mut self) -> ::std::string::String { - self.regex.take().unwrap_or_else(|| ::std::string::String::new()) + pub fn take_id(&mut self) -> ::std::string::String { + self.id.take().unwrap_or_else(|| ::std::string::String::new()) } } @@ -2212,7 +2212,7 @@ impl ::protobuf::Message for StopRequest { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.regex)?; + ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.id)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -2226,7 +2226,7 @@ impl ::protobuf::Message for StopRequest { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { my_size += ::protobuf::rt::string_size(1, &v); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); @@ -2235,7 +2235,7 @@ impl ::protobuf::Message for StopRequest { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { os.write_string(1, &v)?; } os.write_unknown_fields(self.get_unknown_fields())?; @@ -2277,9 +2277,9 @@ impl ::protobuf::Message for StopRequest { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "regex", - |m: &StopRequest| { &m.regex }, - |m: &mut StopRequest| { &mut m.regex }, + "id", + |m: &StopRequest| { &m.id }, + |m: &mut StopRequest| { &mut m.id }, )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "StopRequest", @@ -2297,7 +2297,7 @@ impl ::protobuf::Message for StopRequest { impl ::protobuf::Clear for StopRequest { fn clear(&mut self) { - self.regex.clear(); + self.id.clear(); self.unknown_fields.clear(); } } @@ -2317,7 +2317,7 @@ impl ::protobuf::reflect::ProtobufValue for StopRequest { #[derive(PartialEq,Clone,Default)] pub struct UninstallRequest { // message fields - regex: ::protobuf::SingularField<::std::string::String>, + id: ::protobuf::SingularField<::std::string::String>, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -2334,40 +2334,40 @@ impl UninstallRequest { ::std::default::Default::default() } - // optional string regex = 1; + // optional string id = 1; - pub fn get_regex(&self) -> &str { - match self.regex.as_ref() { + pub fn get_id(&self) -> &str { + match self.id.as_ref() { Some(v) => &v, None => "", } } - pub fn clear_regex(&mut self) { - self.regex.clear(); + pub fn clear_id(&mut self) { + self.id.clear(); } - pub fn has_regex(&self) -> bool { - self.regex.is_some() + pub fn has_id(&self) -> bool { + self.id.is_some() } // Param is passed by value, moved - pub fn set_regex(&mut self, v: ::std::string::String) { - self.regex = ::protobuf::SingularField::some(v); + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = ::protobuf::SingularField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_regex(&mut self) -> &mut ::std::string::String { - if self.regex.is_none() { - self.regex.set_default(); + pub fn mut_id(&mut self) -> &mut ::std::string::String { + if self.id.is_none() { + self.id.set_default(); } - self.regex.as_mut().unwrap() + self.id.as_mut().unwrap() } // Take field - pub fn take_regex(&mut self) -> ::std::string::String { - self.regex.take().unwrap_or_else(|| ::std::string::String::new()) + pub fn take_id(&mut self) -> ::std::string::String { + self.id.take().unwrap_or_else(|| ::std::string::String::new()) } } @@ -2381,7 +2381,7 @@ impl ::protobuf::Message for UninstallRequest { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.regex)?; + ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.id)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -2395,7 +2395,7 @@ impl ::protobuf::Message for UninstallRequest { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { my_size += ::protobuf::rt::string_size(1, &v); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); @@ -2404,7 +2404,7 @@ impl ::protobuf::Message for UninstallRequest { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.regex.as_ref() { + if let Some(ref v) = self.id.as_ref() { os.write_string(1, &v)?; } os.write_unknown_fields(self.get_unknown_fields())?; @@ -2446,9 +2446,9 @@ impl ::protobuf::Message for UninstallRequest { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "regex", - |m: &UninstallRequest| { &m.regex }, - |m: &mut UninstallRequest| { &mut m.regex }, + "id", + |m: &UninstallRequest| { &m.id }, + |m: &mut UninstallRequest| { &mut m.id }, )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "UninstallRequest", @@ -2466,7 +2466,7 @@ impl ::protobuf::Message for UninstallRequest { impl ::protobuf::Clear for UninstallRequest { fn clear(&mut self) { - self.regex.clear(); + self.id.clear(); self.unknown_fields.clear(); } } @@ -6789,54 +6789,54 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x0b2\x0f.north.SettingsH\0R\x10settingsResponseB\0\x12@\n\x11versions_r\ esponse\x18\t\x20\x01(\x0b2\x0f.north.VersionsH\0R\x10versionsResponseB\ \0\x12\x1c\n\x08duration\x18\x14\x20\x01(\x03R\x08durationB\0B\t\n\x07co\ - ntent:\0\"\x0f\n\x0bListRequest:\0\"\r\n\tPsRequest:\0\"(\n\x0cStartRequ\ - est\x12\x16\n\x05regex\x18\x01\x20\x01(\tR\x05regexB\0:\0\"'\n\x0bStopRe\ - quest\x12\x16\n\x05regex\x18\x01\x20\x01(\tR\x05regexB\0:\0\",\n\x10Unin\ - stallRequest\x12\x16\n\x05regex\x18\x01\x20\x01(\tR\x05regexB\0:\0\"2\n\ - \rUpdateRequest\x12\x1f\n\nupdate_dir\x18\x01\x20\x02(\tR\tupdateDirB\0:\ - \0\"\x13\n\x0fShutdownRequest:\0\"\x16\n\x12GetSettingsRequest:\0\"\x16\ - \n\x12GetVersionsRequest:\0\"0\n\x08Settings\x12\"\n\x0bdescription\x18\ - \x01\x20\x01(\tR\x0bdescriptionB\0:\0\"\xaa\x01\n\x08Versions\x123\n\x05\ - infos\x18\x01\x20\x03(\x0b2\x1b.north.Versions.VersionInfoR\x05infosB\0\ - \x1ag\n\x0bVersionInfo\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\ - \x12\x1a\n\x07version\x18\x02\x20\x01(\tR\x07versionB\0\x12$\n\x0carchit\ - ecture\x18\x03\x20\x01(\tR\x0carchitectureB\0:\0:\0\"\xc4\x01\n\rContain\ - erInfo\x12\x14\n\x04name\x18\x01\x20\x02(\tR\x04nameB\0\x12\x1a\n\x07ver\ - sion\x18\x02\x20\x02(\tR\x07versionB\0\x12!\n\x0brunning_pid\x18\x03\x20\ - \x01(\rR\nrunningPidB\0\x12/\n\x04type\x18\x04\x20\x02(\x0e2\x19.north.C\ - ontainerInfo.TypeR\x04typeB\0\"+\n\x04Type\x12\x07\n\x03APP\x10\0\x12\ - \x0c\n\x08RESOURCE\x10\x01\x12\n\n\x06SYSTEM\x10\x02\x1a\0:\0\"\x96\x02\ - \n\x0bProcessInfo\x12\x14\n\x04name\x18\x01\x20\x02(\tR\x04nameB\0\x12\ - \x1a\n\x07version\x18\x02\x20\x02(\tR\x07versionB\0\x12\x12\n\x03pid\x18\ - \x03\x20\x02(\rR\x03pidB\0\x12\x14\n\x04size\x18\x04\x20\x01(\x04R\x04si\ - zeB\0\x12\x1c\n\x08resident\x18\x05\x20\x01(\x04R\x08residentB\0\x12\x18\ - \n\x06shared\x18\x06\x20\x01(\x04R\x06sharedB\0\x12\x14\n\x04text\x18\ - \x07\x20\x01(\x04R\x04textB\0\x12\x14\n\x04data\x18\x08\x20\x01(\x04R\ - \x04dataB\0\x12\x18\n\x06uptime\x18\t\x20\x01(\x04R\x06uptimeB\0\"+\n\ - \x04Type\x12\x07\n\x03APP\x10\0\x12\x0c\n\x08RESOURCE\x10\x01\x12\n\n\ - \x06SYSTEM\x10\x02\x1a\0:\0\"C\n\x0bProcessList\x122\n\tprocesses\x18\ - \x01\x20\x03(\x0b2\x12.north.ProcessInfoR\tprocessesB\0:\0\"I\n\rContain\ - erList\x126\n\ncontainers\x18\x01\x20\x03(\x0b2\x14.north.ContainerInfoR\ - \ncontainersB\0:\0\"b\n\x0eStatusResponse\x12!\n\x0bstatus_info\x18\x01\ - \x20\x01(\tR\nstatusInfoB\0\x12+\n\x10command_response\x18\x02\x20\x01(\ - \tR\x0fcommandResponseB\0:\0\"\x8e\x01\n\x11UninstallResponse\x12:\n\x06\ - status\x18\x01\x20\x03(\x0b2\x20.north.UninstallResponse.OutcomeR\x06sta\ - tusB\0\x1a;\n\x07Outcome\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\ - \0\x12\x18\n\x06result\x18\x02\x20\x01(\tR\x06resultB\0:\0:\0\"\xc3\x01\ - \n\x0eUpdateResponse\x12C\n\x0bupdate_list\x18\x01\x20\x03(\x0b2\x20.nor\ - th.UpdateResponse.UpdateInfoR\nupdateListB\0\x1aj\n\nUpdateInfo\x12\x14\ - \n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12!\n\x0bold_version\x18\x02\ - \x20\x01(\tR\noldVersionB\0\x12!\n\x0bnew_version\x18\x03\x20\x01(\tR\nn\ - ewVersionB\0:\0:\0\"\xc3\x01\n\x0fStartedResponse\x12G\n\x0cstartup_list\ - \x18\x01\x20\x03(\x0b2\".north.StartedResponse.StartupInfoR\x0bstartupLi\ - stB\0\x1ae\n\x0bStartupInfo\x12\x10\n\x02id\x18\x01\x20\x02(\tR\x02idB\0\ - \x12\x1a\n\x07success\x18\x02\x20\x01(\tR\x07successB\0\x12&\n\x0edurati\ - on_in_ns\x18\x03\x20\x01(\x04R\x0cdurationInNsB\0:\0:\0\"\xb7\x01\n\x0fS\ - toppedResponse\x12>\n\tstop_list\x18\x01\x20\x03(\x0b2\x1f.north.Stopped\ - Response.StopInfoR\x08stopListB\0\x1ab\n\x08StopInfo\x12\x10\n\x02id\x18\ - \x01\x20\x02(\tR\x02idB\0\x12\x1a\n\x07success\x18\x02\x20\x01(\tR\x07su\ - ccessB\0\x12&\n\x0eduration_in_ns\x18\x03\x20\x01(\x04R\x0cdurationInNsB\ - \0:\0:\0B\0b\x06proto2\ + ntent:\0\"\x0f\n\x0bListRequest:\0\"\r\n\tPsRequest:\0\"\"\n\x0cStartReq\ + uest\x12\x10\n\x02id\x18\x01\x20\x01(\tR\x02idB\0:\0\"!\n\x0bStopRequest\ + \x12\x10\n\x02id\x18\x01\x20\x01(\tR\x02idB\0:\0\"&\n\x10UninstallReques\ + t\x12\x10\n\x02id\x18\x01\x20\x01(\tR\x02idB\0:\0\"2\n\rUpdateRequest\ + \x12\x1f\n\nupdate_dir\x18\x01\x20\x02(\tR\tupdateDirB\0:\0\"\x13\n\x0fS\ + hutdownRequest:\0\"\x16\n\x12GetSettingsRequest:\0\"\x16\n\x12GetVersion\ + sRequest:\0\"0\n\x08Settings\x12\"\n\x0bdescription\x18\x01\x20\x01(\tR\ + \x0bdescriptionB\0:\0\"\xaa\x01\n\x08Versions\x123\n\x05infos\x18\x01\ + \x20\x03(\x0b2\x1b.north.Versions.VersionInfoR\x05infosB\0\x1ag\n\x0bVer\ + sionInfo\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x1a\n\x07v\ + ersion\x18\x02\x20\x01(\tR\x07versionB\0\x12$\n\x0carchitecture\x18\x03\ + \x20\x01(\tR\x0carchitectureB\0:\0:\0\"\xc4\x01\n\rContainerInfo\x12\x14\ + \n\x04name\x18\x01\x20\x02(\tR\x04nameB\0\x12\x1a\n\x07version\x18\x02\ + \x20\x02(\tR\x07versionB\0\x12!\n\x0brunning_pid\x18\x03\x20\x01(\rR\nru\ + nningPidB\0\x12/\n\x04type\x18\x04\x20\x02(\x0e2\x19.north.ContainerInfo\ + .TypeR\x04typeB\0\"+\n\x04Type\x12\x07\n\x03APP\x10\0\x12\x0c\n\x08RESOU\ + RCE\x10\x01\x12\n\n\x06SYSTEM\x10\x02\x1a\0:\0\"\x96\x02\n\x0bProcessInf\ + o\x12\x14\n\x04name\x18\x01\x20\x02(\tR\x04nameB\0\x12\x1a\n\x07version\ + \x18\x02\x20\x02(\tR\x07versionB\0\x12\x12\n\x03pid\x18\x03\x20\x02(\rR\ + \x03pidB\0\x12\x14\n\x04size\x18\x04\x20\x01(\x04R\x04sizeB\0\x12\x1c\n\ + \x08resident\x18\x05\x20\x01(\x04R\x08residentB\0\x12\x18\n\x06shared\ + \x18\x06\x20\x01(\x04R\x06sharedB\0\x12\x14\n\x04text\x18\x07\x20\x01(\ + \x04R\x04textB\0\x12\x14\n\x04data\x18\x08\x20\x01(\x04R\x04dataB\0\x12\ + \x18\n\x06uptime\x18\t\x20\x01(\x04R\x06uptimeB\0\"+\n\x04Type\x12\x07\n\ + \x03APP\x10\0\x12\x0c\n\x08RESOURCE\x10\x01\x12\n\n\x06SYSTEM\x10\x02\ + \x1a\0:\0\"C\n\x0bProcessList\x122\n\tprocesses\x18\x01\x20\x03(\x0b2\ + \x12.north.ProcessInfoR\tprocessesB\0:\0\"I\n\rContainerList\x126\n\ncon\ + tainers\x18\x01\x20\x03(\x0b2\x14.north.ContainerInfoR\ncontainersB\0:\0\ + \"b\n\x0eStatusResponse\x12!\n\x0bstatus_info\x18\x01\x20\x01(\tR\nstatu\ + sInfoB\0\x12+\n\x10command_response\x18\x02\x20\x01(\tR\x0fcommandRespon\ + seB\0:\0\"\x8e\x01\n\x11UninstallResponse\x12:\n\x06status\x18\x01\x20\ + \x03(\x0b2\x20.north.UninstallResponse.OutcomeR\x06statusB\0\x1a;\n\x07O\ + utcome\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x18\n\x06res\ + ult\x18\x02\x20\x01(\tR\x06resultB\0:\0:\0\"\xc3\x01\n\x0eUpdateResponse\ + \x12C\n\x0bupdate_list\x18\x01\x20\x03(\x0b2\x20.north.UpdateResponse.Up\ + dateInfoR\nupdateListB\0\x1aj\n\nUpdateInfo\x12\x14\n\x04name\x18\x01\ + \x20\x01(\tR\x04nameB\0\x12!\n\x0bold_version\x18\x02\x20\x01(\tR\noldVe\ + rsionB\0\x12!\n\x0bnew_version\x18\x03\x20\x01(\tR\nnewVersionB\0:\0:\0\ + \"\xc3\x01\n\x0fStartedResponse\x12G\n\x0cstartup_list\x18\x01\x20\x03(\ + \x0b2\".north.StartedResponse.StartupInfoR\x0bstartupListB\0\x1ae\n\x0bS\ + tartupInfo\x12\x10\n\x02id\x18\x01\x20\x02(\tR\x02idB\0\x12\x1a\n\x07suc\ + cess\x18\x02\x20\x01(\tR\x07successB\0\x12&\n\x0eduration_in_ns\x18\x03\ + \x20\x01(\x04R\x0cdurationInNsB\0:\0:\0\"\xb7\x01\n\x0fStoppedResponse\ + \x12>\n\tstop_list\x18\x01\x20\x03(\x0b2\x1f.north.StoppedResponse.StopI\ + nfoR\x08stopListB\0\x1ab\n\x08StopInfo\x12\x10\n\x02id\x18\x01\x20\x02(\ + \tR\x02idB\0\x12\x1a\n\x07success\x18\x02\x20\x01(\tR\x07successB\0\x12&\ + \n\x0eduration_in_ns\x18\x03\x20\x01(\x04R\x0cdurationInNsB\0:\0:\0B\0b\ + \x06proto2\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/north_client/src/main.rs b/north_client/src/main.rs index 187173969..7f6c1abe1 100644 --- a/north_client/src/main.rs +++ b/north_client/src/main.rs @@ -35,8 +35,7 @@ use rustyline::{ use rustyline_derive::Validator; use std::{ borrow::Cow::{self, Owned}, - collections::HashMap, - collections::HashSet, + collections::{HashMap, HashSet}, env, fs, io::{Read, Write}, iter, @@ -67,33 +66,33 @@ lazy_static! { static ref COMMAND_LIST: Vec<&'static str> = COMMANDS.keys().copied().collect(); } -fn start_command(regex_str: Option<&str>) -> api::Request { +fn start_command(id_str: Option<&str>) -> api::Request { let mut cmd = api::Request::new(); let mut id_cmd = api::StartRequest::default(); - if let Some(r) = regex_str { - id_cmd.set_regex(r.to_string()); + if let Some(id) = id_str { + id_cmd.set_id(id.to_string()); } cmd.instruction = Some(api::Request_oneof_instruction::start_container(id_cmd)); cmd.set_description(String::from("start")); cmd } -fn stop_command(regex_str: Option<&str>) -> api::Request { +fn stop_command(id_str: Option<&str>) -> api::Request { let mut cmd = api::Request::new(); let mut id_cmd = api::StopRequest::default(); - if let Some(r) = regex_str { - id_cmd.set_regex(r.to_string()); + if let Some(id) = id_str { + id_cmd.set_id(id.to_string()); } cmd.instruction = Some(api::Request_oneof_instruction::stop_container(id_cmd)); cmd.set_description(String::from("stop")); cmd } -fn uninstall_command(regex_str: Option<&str>) -> api::Request { +fn uninstall_command(id_str: Option<&str>) -> api::Request { let mut cmd = api::Request::new(); let mut id_cmd = api::UninstallRequest::default(); - if let Some(r) = regex_str { - id_cmd.set_regex(r.to_string()); + if let Some(id) = id_str { + id_cmd.set_id(id.to_string()); } cmd.instruction = Some(api::Request_oneof_instruction::uninstall_container(id_cmd)); cmd.set_description(String::from("uninstall")); @@ -322,10 +321,10 @@ fn receive_message(r: &mut dyn Read) -> Result> { Ok(Vec::from(&buffer[4..n])) } -fn send_message(socket: &mut dyn Write, out_bytes: &[u8]) -> Result<()> { +fn send_message(socket: &mut dyn Write, data: &[u8]) -> Result<()> { let mut frame_with_length = vec![]; - frame_with_length.write_u32::(out_bytes.len() as u32 + 4)?; - frame_with_length.extend(out_bytes); + frame_with_length.write_u32::(data.len() as u32 + 4)?; + frame_with_length.extend(data); socket .write_all(&frame_with_length) .context("Failed to send command")?;