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

V2 state get wo si #1853

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 16 additions & 14 deletions src/features/device-state/routes/state-get-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,13 @@ function buildAppFromRelease(
// extract the per-image information
const image = ipr.image[0];

const si = device.service_install.find(
({ service }) => service.__id === image.is_a_build_of__service[0].id,
);
const svc = image.is_a_build_of__service[0];
const environment: Dictionary<string> = {};
varListInsert(ipr.image_environment_variable, environment);
varListInsert(application.application_environment_variable, environment);
varListInsert(svc.service_environment_variable, environment);
varListInsert(device.device_environment_variable, environment);
if (si != null) {
varListInsert(si.device_service_environment_variable, environment);
}
varListInsert(svc.device_service_environment_variable, environment);

const labels: Dictionary<string> = {};
for (const { label_name, value } of [
Expand Down Expand Up @@ -188,6 +183,21 @@ const stateQuery = _.once(() =>
is_a_build_of__service: {
$select: ['id', 'service_name'],
$expand: {
device_service_environment_variable: {
$select: ['name', 'value'],
$filter: {
device: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this $filter (or some variation of it) as otherwise the expand will get all device_service_environment_variable for that server and ignore the device filter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other idea would be to directly expand from the device on the top level to dsev but then we need to do something similar for service (which isa bit longer)

$any: {
$alias: 'd',
$expr: {
d: {
uuid: { '@': 'uuid' },
},
},
},
},
},
},
service_environment_variable: {
$select: ['name', 'value'],
},
Expand All @@ -208,14 +218,6 @@ const stateQuery = _.once(() =>
},
},
},
service_install: {
$select: ['id', 'service'],
$expand: {
device_service_environment_variable: {
$select: ['name', 'value'],
},
},
},
belongs_to__application: {
$select: ['id', 'app_name'],
$expand: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"service": "app1_service1",
"name": "name_si",
"value": "value_si"
},
"si2_svc": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces the state get tests to consider the case why I added the $filter on the device expand above

"user": "admin",
"device": "device2",
"service": "app1_service1",
"name": "name_si_2",
"value": "value_si_2"
}
}
7 changes: 7 additions & 0 deletions test/fixtures/03-device-state/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"belongs_to__user": "admin",
"uuid": "c47e4dec05f76ee37c4b8e805c35c1eee54335803b3a40458928f8afce618c",
"is_pinned_on__release": "release1"
},
"device2": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"uuid": "b47e4dec05f76ee37c4b8e805c35c1eee54335803b3a40458928f8afce618c",
"is_pinned_on__release": "release1"
}
}
Loading