Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Some small updates
Browse files Browse the repository at this point in the history
Signed-off-by: johnsonw <[email protected]>
  • Loading branch information
johnsonw committed Oct 21, 2020
1 parent 569b1d7 commit b039434
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 220 deletions.
3 changes: 1 addition & 2 deletions chroma_core/models/ldev_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# license that can be found in the LICENSE file.

from chroma_core.lib.job import Step
from chroma_core.lib.util import invoke_rust_agent
from chroma_core.models import Job
from chroma_help.help import help_text
from django.contrib.postgres import fields
Expand All @@ -18,7 +17,7 @@ def run(self, kwargs):
ldev_entries = json.loads(ldev_entries)

for (fqdn, entries) in ldev_entries.items():
self.invoke_rust_agent(fqdn, "create_ldev_conf", entries)
self.invoke_rust_agent_expect_result(fqdn, "create_ldev_conf", entries)


class ConfigureLDevJob(Job):
Expand Down
8 changes: 4 additions & 4 deletions iml-agent/src/action_plugins/ldev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn read_ldev_config() -> Result<String, ImlAgentError> {
fn parse_entries(ldev_config: String) -> BTreeSet<LdevEntry> {
ldev_config
.lines()
.filter(|x| x.trim().chars().take(1).next() != Some('#'))
.filter(|x| !x.trim_start().starts_with("#"))
.map(LdevEntry::from)
.collect()
}
Expand Down Expand Up @@ -275,21 +275,21 @@ mod tests {
LdevEntry {
primary: "oss2".into(),
failover: Some("oss1".into()),
label: "zfsmo-OST00011".into(),
label: "zfsmo-OST0011".into(),
device: "zfs:ost17/ost17".into(),
fs_type: FsType::Zfs,
},
LdevEntry {
primary: "oss2".into(),
failover: Some("oss1".into()),
label: "zfsmo-OST00012".into(),
label: "zfsmo-OST0012".into(),
device: "zfs:ost18/ost18".into(),
fs_type: FsType::Zfs,
},
LdevEntry {
primary: "oss2".into(),
failover: Some("oss1".into()),
label: "zfsmo-OST00013".into(),
label: "zfsmo-OST0013".into(),
device: "zfs:ost19/ost19".into(),
fs_type: FsType::Zfs,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ oss2 oss1 zfsmo-OST000d zfs:ost13/ost13
oss2 oss1 zfsmo-OST000e zfs:ost14/ost14
oss2 oss1 zfsmo-OST000f zfs:ost15/ost15
oss2 oss1 zfsmo-OST0010 zfs:ost16/ost16
oss2 oss1 zfsmo-OST00011 zfs:ost17/ost17
oss2 oss1 zfsmo-OST00012 zfs:ost18/ost18
oss2 oss1 zfsmo-OST00013 zfs:ost19/ost19
oss2 oss1 zfsmo-OST0011 zfs:ost17/ost17
oss2 oss1 zfsmo-OST0012 zfs:ost18/ost18
oss2 oss1 zfsmo-OST0013 zfs:ost19/ost19
2 changes: 2 additions & 0 deletions iml-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum ImlApiError {
FilesystemNotFound,
#[error("Filesystem Not Found")]
MgsNotFound,
#[error("All targets must be mounted when configuring ldev conf.")]
TargetsNotMounted,
}

impl reject::Reject for ImlApiError {}
Expand Down
69 changes: 38 additions & 31 deletions iml-api/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,55 +872,62 @@ impl MutationRoot {
fs_type: x.fs_type.as_str().into(),
};

return (
return Ok((
fs_to_fqdn_map
.get(&x.filesystems[0])
.expect("get first filesystem"),
ldev_entry,
);
));
} else {
panic!("All targets must be mounted when configuring ldev conf.");
return Err(ImlApiError::TargetsNotMounted);
}
} else {
panic!(
"All targets must be mounted on an active host when configuring ldev conf."
);
return Err(ImlApiError::TargetsNotMounted);
}
})
.fold(
.try_fold(
vec![].into_iter().collect(),
|mut acc: HashMap<String, Vec<LdevEntry>>, (fqdn, ldev_entry)| {
let items = acc.entry(fqdn.to_string()).or_insert(vec![]);
(*items).push(ldev_entry);
|mut acc: HashMap<String, Vec<LdevEntry>>, entry| match entry {
Ok((fqdn, ldev_entry)) => {
let items = acc.entry(fqdn.to_string()).or_insert(vec![]);
(*items).push(ldev_entry);

acc
Ok(acc)
}
Err(e) => Err(e),
},
);

tracing::debug!("ldev entries: {:?}", ldev_entries);

let kwargs: HashMap<String, String> = vec![("message".into(), "Creating LDev Conf".into())]
.into_iter()
.collect();

let jobs = serde_json::json!([{
"class_name": "ConfigureLDevJob",
"args": {
"ldev_entries": serde_json::to_string(&ldev_entries)?
}
}]);
let command_id: i32 = iml_job_scheduler_rpc::call(
&context.rabbit_pool.get().await?,
"run_jobs",
vec![jobs],
Some(kwargs),
)
.map_err(ImlApiError::ImlJobSchedulerRpcError)
.await?;
match ldev_entries {
Ok(ldev_entries) => {
let kwargs: HashMap<String, String> =
vec![("message".into(), "Creating LDev Conf".into())]
.into_iter()
.collect();

let jobs = serde_json::json!([{
"class_name": "ConfigureLDevJob",
"args": {
"ldev_entries": serde_json::to_string(&ldev_entries)?
}
}]);
let command_id: i32 = iml_job_scheduler_rpc::call(
&context.rabbit_pool.get().await?,
"run_jobs",
vec![jobs],
Some(kwargs),
)
.map_err(ImlApiError::ImlJobSchedulerRpcError)
.await?;

let command = get_command(&context.pg_pool, command_id).await?;
let command = get_command(&context.pg_pool, command_id).await?;

Ok(command)
Ok(command)
}
Err(e) => Err(FieldError::new(e.to_string(), Value::null())),
}
}
}

Expand Down
Loading

0 comments on commit b039434

Please sign in to comment.