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

Implements sooner resource validity checking #698

Merged
merged 1 commit into from
May 3, 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
7 changes: 4 additions & 3 deletions crates/hyperqueue/src/client/commands/submit/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ impl JobSubmitOpts {
},
)
}

Ok(ResourceRequest {
let request = ResourceRequest {
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
n_nodes: self.conf.nodes,
min_time: self.conf.time_request,
resources,
})
};
request.validate()?;
Ok(request)
}
}

Expand Down
18 changes: 18 additions & 0 deletions crates/tako/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize, Serializer};

use crate::internal::common::error::DsError;
use crate::internal::messages::common::TaskFailInfo;
use crate::internal::messages::worker::WorkerOverview;
use crate::internal::worker::configuration::WorkerConfiguration;
Expand Down Expand Up @@ -44,6 +45,23 @@ impl Default for ResourceRequest {
}
}

impl ResourceRequest {
pub fn validate(&self) -> crate::Result<()> {
for (i, entry) in self.resources.iter().enumerate() {
entry.policy.validate()?;
for entry2 in &self.resources[i + 1..] {
if entry.resource == entry2.resource {
return Err(DsError::GenericError(format!(
"Resource '{}' defined more than once",
entry.resource
)));
}
}
}
Ok(())
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub struct ResourceRequestVariants {
pub variants: SmallVec<[ResourceRequest; 1]>,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,16 @@ def test_manual_cpu_resource_sum(hq_env: HqEnv):
args=["worker", "start", "--resource", "cpus=sum(5)"],
expect_fail="Resource kind `sum` cannot be used with CPUs",
)


def test_resources_invalid_definitions(hq_env: HqEnv):
hq_env.start_server()
hq_env.command(
args=["submit", "--resource", "foo=10", "--resource", "foo=1", "--", "sleep", "1"],
expect_fail="Resource 'foo' defined more than once",
)

hq_env.command(
args=["submit", "--resource", "foo=0", "--", "sleep", "1"],
expect_fail="Zero resources cannot be requested",
)
Loading