Skip to content

Commit

Permalink
Correctly handle setting cluster 'updated' value when managing groups (
Browse files Browse the repository at this point in the history
…#1356)

* Correctly handle setting cluster 'updated' value when managing groups

* update translations

* Fix test

* fix group removal, tests
  • Loading branch information
carrolp committed Mar 21, 2024
1 parent 4066faa commit 36918ac
Show file tree
Hide file tree
Showing 17 changed files with 1,104 additions and 891 deletions.
18 changes: 11 additions & 7 deletions app/apollo/resolvers/group.js
Expand Up @@ -414,8 +414,13 @@ const groupResolvers = {
},
}
}
// Do not set `updated` value for cluster records when altering groups -- the `updated` value is used to determine whether the cluster is active or inactive.
];
const res = await models.Cluster.collection.bulkWrite(ops, { ordered: true });
// Note: Exercise caution using `bulkWrite` with values other than strings (especially dates)
// If `findOneAndUpdate` uses `Date.now()`, the value is stored as a date string like `2024-03-20T21:05:28.645+00:00`
// If `bulkWrite` sets a date value to `Date.now()`, the value stored will be millis-since-epoch (using `new Date()` instead works)
// This can result in the record being retrieved later with a non-Date attribute, and errors if code attempts `record.attr.getTime()` for instance.

pubSub.channelSubChangedFunc({org_id}, context);

Expand Down Expand Up @@ -619,7 +624,7 @@ const groupResolvers = {
{
updateOne: {
filter: { org_id, cluster_id: clusterId },
update: { $pull: { groups: { $in: groupObjsToRemove } } },
update: { $pull: { groups: { uuid: { $in: groupObjsToRemove.map( (g) => g.uuid ) } } } },
}
},
{
Expand All @@ -628,14 +633,13 @@ const groupResolvers = {
update: { $push: { groups: { $each: groupObjsToAdd } } },
}
},
{
updateOne: {
filter: { org_id, cluster_id: clusterId },
update: { $set: { updated: Date.now() } },
}
},
// Do not set `updated` value for cluster records when altering groups -- the `updated` value is used to determine whether the cluster is active or inactive.
];
const res = await models.Cluster.collection.bulkWrite(ops, { ordered: true });
// Note: Exercise caution using `bulkWrite` with values other than strings (especially dates)
// If `findOneAndUpdate` uses `Date.now()`, the value is stored as a date string like `2024-03-20T21:05:28.645+00:00`
// If `bulkWrite` sets a date value to `Date.now()`, the value stored will be millis-since-epoch (using `new Date()` instead works)
// This can result in the record being retrieved later with a non-Date attribute, and errors if code attempts `record.attr.getTime()` for instance.

pubSub.channelSubChangedFunc({org_id}, context);

Expand Down
8 changes: 4 additions & 4 deletions app/apollo/test/cluster.spec.js
Expand Up @@ -58,10 +58,10 @@ let presetOrgs;
let presetUsers;
let presetClusters;

const group_01_uuid = 'fake_group_01_uuid;';
const group_02_uuid = 'fake_group_02_uuid;';
const group_03_uuid = 'fake_group_03_uuid;';
const group_01_77_uuid = 'fake_group_01_77_uuid;';
const group_01_uuid = 'fake_group_01_uuid';
const group_02_uuid = 'fake_group_02_uuid';
const group_03_uuid = 'fake_group_03_uuid';
const group_01_77_uuid = 'fake_group_01_77_uuid';
const org_01_orgkey = 'orgApiKey-0a9f5ee7-c879-4302-907c-238178ec9071';
const org_01_orgkey2 = {
orgKeyUuid: 'fcb8af1e-e4f1-4e7b-8c52-0e8360b48a13',
Expand Down
4 changes: 2 additions & 2 deletions app/apollo/test/group.fga.spec.js
Expand Up @@ -588,7 +588,7 @@ describe('groups graphql test suite', () => {
clusterId: testCluster1.cluster_id,
groupUuids: [testGroup1.uuid],
});
expect(response.data.data.editClusterGroups.modified).to.equal(2);
expect(response.data.data.editClusterGroups.modified).to.equal(1);
} catch (error) {
console.error(JSON.stringify({'API response:': response && response.data ? response.data : 'unexpected response'}, null, 3));
console.error('Test failure, error: ', error);
Expand All @@ -613,4 +613,4 @@ describe('groups graphql test suite', () => {
throw error;
}
});
});
});
10 changes: 5 additions & 5 deletions app/apollo/test/group.spec.js
Expand Up @@ -83,9 +83,9 @@ const subscription_02_uuid = 'fake_sub_02_uuid';
const subscription_03_name = 'fake_subscription_03';
const subscription_03_uuid = 'fake_sub_03_uuid';

const group_01_uuid = 'fake_group_01_uuid;';
const group_02_uuid = 'fake_group_02_uuid;';
const group_01_77_uuid = 'fake_group_01_77_uuid;';
const group_01_uuid = 'fake_group_01_uuid';
const group_02_uuid = 'fake_group_02_uuid';
const group_01_77_uuid = 'fake_group_01_77_uuid';

const createOrganizations = async () => {
org01Data = JSON.parse(
Expand Down Expand Up @@ -814,7 +814,7 @@ describe('groups graphql test suite', () => {
clusterId: 'cluster_01',
groupUuids: [group_01_uuid, group_02_uuid],
});
expect(editClusterGroups.modified).to.equal(2);
expect(editClusterGroups.modified).to.equal(1);

} catch (error) {
if (error.response) {
Expand All @@ -825,4 +825,4 @@ describe('groups graphql test suite', () => {
throw error;
}
});
});
});
3 changes: 3 additions & 0 deletions app/apollo/utils/applyQueryFields.js
Expand Up @@ -44,6 +44,9 @@ const applyQueryFieldsToClusters = async(clusters, queryFields={}, args, context
_.each(clusters, (cluster)=>{
cluster.name = cluster.name || (cluster.metadata || {}).name || (cluster.registration || {}).name || cluster.clusterId || cluster.id;

// Ensure cluster `updated` value is a Date (may have been set as millis-since-epoch incorrectly by group apis -- see `bulkWrite` notes in resolvers/group.js)
if( !cluster.updated.getTime ) cluster.updated = new Date(cluster.updated);

/*
Cluster records have their `updated` field set at creation and when the `api/v2/addUpdateCluster` is called by the watch-keeper.
As long as record creation time and updated time are within TIME_DIFF_TOLERATION milliseconds, it is considered to be un-updated *since creation*.
Expand Down
14 changes: 9 additions & 5 deletions locales/de/razee-resources.json
Expand Up @@ -9,14 +9,14 @@
"A cluster name is not defined in the registration data": "In den Registrierungsdaten ist kein Clustername definiert.",
"Added subscription \"{{name}}\" must reference a valid version.": "Das hinzugefügte Abonnement \"{{name}}\" muss auf eine gültige Version verweisen.",
"Another cluster already exists with the same registration name {{registration.name}}": "Es ist bereits ein anderer Cluster mit demselben eingetragenen Namen {{registration.name}} vorhanden.",
"Channel { uuid: \"{{uuid}}\", org_id:{{org_id}} } not found.": "Channel { uuid: \"{{uuid}}\", org_id:{{org_id}} } not found.",
"Channel uuid \"{{channel_uuid}}\" not found.": "Kanal-UUID \"{{channel_uuid}}\" nicht gefunden.",
"Cluster with cluster_id \"{{clusterId}}\" not found": "Cluster mit Cluster-ID \"{{clusterId}}\" nicht gefunden",
"commonResourceSearch encountered an error. {{error.message}}": "commonResourceSearch hat einen Fehler festgestellt. {{error.message}}",
"commonResourcesSearch encountered an error. {{error.message}}": "commonResourcesSearch hat einen Fehler festgestellt. {{error.message}}",
"Could not find all the cluster groups {{groups}} in the groups database, please create them first.": "In der Gruppendatenbank konnten nicht alle Clustergruppen {{groups}} gefunden werden. Bitte erstellen Sie diese zuerst.",
"could not find group with name {{name}}.": "Die Gruppe mit dem Namen {{name}} konnte nicht gefunden werden.",
"could not find group with uuid {{uuid}}.": "Die Gruppe mit der UUID {{uuid}} konnte nicht gefunden werden.",
"Could not find subscriptions.": "Subskriptionen konnten nicht gefunden werden.",
"Could not find the cluster for the cluster id {{cluster_id}}.": "Der Cluster für die Cluster-ID {{cluster_id}} konnte nicht gefunden werden.",
"Could not find the cluster with Id {{clusterId}}.": "Der Cluster mit der ID {{clusterId}} konnte nicht gefunden werden.",
"Could not find the cluster with name {{clusterName}}.": "Der Cluster mit dem Namen {{clusterName}} konnte nicht gefunden werden.",
Expand All @@ -26,26 +26,28 @@
"Could not find the organization key.": "Der Organisationsschlüssel wurde nicht gefunden.",
"Could not find the organization with ID {{org_id}}.": "Die Organisation mit der ID {{org_id}} konnte nicht gefunden werden.",
"Could not find the subscription for the subscription id {{subscription_id}}.": "Die Subskription für die Subskriptions-ID {{subscription_id}} konnte nicht gefunden werden.",
"Could not find the subscription.": "Die Subskription konnte nicht gefunden werden.",
"Could not locate the cluster with cluster_id {{cluster_id}}": "Der Cluster mit der Cluster-ID {{cluster_id}} konnte nicht gefunden werden.",
"Could not locate the cluster with clusterName {{clusterName}}": "Der Cluster mit dem Clusternamen {{clusterName}} konnte nicht gefunden werden.",
"DeployableVersion is not found for {{channel.name}}:{{channel.uuid}}/{{versionObj.name}}:{{versionObj.uuid}}.": "DeployableVersion konnte für {{channel.name}}:{{channel.uuid}}/{{versionObj.name}}:{{versionObj.uuid}} nicht gefunden werden.",
"Failed to Publish resource notification, please reload the page.": "Publizieren der Ressourcenbenachrichtigung fehlgeschlagen. Bitte laden Sie die Seite erneut.",
"Failed to Publish resource notification, pubsub is not ready yet, please retry later.": "Publizieren der Ressourcenbenachrichtigung fehlgeschlagen. pubsub ist noch nicht bereit. Bitte versuchen Sie es später erneut.",
"Failed to Publish subscription notification to clusters, please retry.": "Publizieren der Subskriptionsbenachrichtigung an Cluster fehlgeschlagen. Bitte versuchen Sie es erneut.",
"Failed to Publish subscription notification to clusters, pubsub is not ready yet, please retry.": "Publizieren der Subskriptionsbenachrichtigungen an Cluster fehlgeschlagen. pubsub ist noch nicht bereit. Bitte versuchen Sie es später erneut.",
"Failed to retrieve service subscriptions.": "Abrufen der Servicesubskriptionen fehlgeschlagen. ",
"group name \"{{name}}\" not found": "Gruppenname \"{{name}}\" nicht gefunden",
"group uuid \"{{uuid}}\" not found": "Gruppen-UUID \"{{uuid}}\" nicht gefunden",
"hist _id \"{{histId}}\" not found": "Verlaufs-ID \"{{histId}}\" nicht gefunden",
"Invalid razee-org-key was submitted for {{queryName}}": "Ungültiger razee-org-key wurde für {{queryName}} übergeben.",
"Maximum number of Organization Keys reached: {{number}}": "Es wurde die maximale Anzahl von Organisationsschlüsseln erreicht: {{number}}",
"More than one {{type}} matches {{name}}": "Mehrere {{type}} entsprechen {{name}}",
"No changes specified.": "Keine Änderungen angegeben.",
"No cluster uuids were passed": "No cluster uuids were passed",
"No clusters were passed": "No clusters were passed",
"No org was found for the org key.": "Für den Organisationsschlüssel wurde keine Organisation gefunden.",
"No razee-org-key was supplied.": "Es wurde kein razee-org-key bereitgestellt.",
"None of the passed group uuids were found": "Keine der übergebenen Gruppen-UUIDs wurde gefunden.",
"One or more of the clusters was not found": "One or more of the clusters was not found",
"One or more of the passed group uuids were not found": "Mindestens eine der übergebenen Gruppen-UUIDs wurde nicht gefunden.",
"One or more of the passed groups were not found": "One or more of the passed groups were not found",
"org id was not found": "Organisation-ID nicht gefunden",
"Organization key {{id}} cannot be altered, but it may be deleted.": "Der Organisationsschlüssel {{id}} kann nicht geändert, aber gelöscht werden.",
"Organization key {{id}} cannot be removed or altered because it is in use by one or more clusters.": "Der Organisationsschlüssel {{id}} kann nicht entfernt oder geändert werden, weil er von mindestens einem Cluster verwendet wird.",
Expand All @@ -54,14 +56,14 @@
"Organization key {{id}} cannot be removed or altered because it is the last one.": "Der Organisationsschlüssel {{id}} kann nicht entfernt oder geändert werden, weil er der letzte Schlüssel ist.",
"Organization key {{id}} cannot be removed or altered because it is the only Primary key.": "Der Organisationsschlüssel {{id}} kann nicht entfernt oder geändert werden, da er der einzige Primärschlüssel ist.",
"Provided YAML content is not valid: {{error}}": "Bereitgestellter YAML-Inhalt ist ungültig: {{error}}",
"Query {{queryName}} error. {{error.message}}": "Bei Abfrage {{queryName}} Fehler {{error.message}}",
"Query {{queryName}} error. MessageID: {{req_id}}.": "Bei Abfrage {{queryName}} Fehler. Nachrichten-ID: {{req_id}}.",
"Query {{queryName}} find error. MessageID: {{req_id}}.": "Bei Abfrage {{queryName}} Suchfehler. Nachrichten-ID: {{req_id}}.",
"Remote version source details must be provided.": "Es müssen Details zur Version der fernen Quelle angegeben werden.",
"resourcesCount encountered an error. {{error.message}}": "resourcesCount hat einen Fehler festgestellt. {{error.message}}",
"Service subscription with ssid \"{{ssid}}\" not found.": "Servicesubskription mit SSID \"{{ssid}}\" nicht gefunden.",
"Subscription { id: \"{{id}}\" } not found.": "Subskription { ID: \"{{id}}\" } nicht gefunden.",
"Subscription { uuid: \"{{uuid}}\", org_id:{{org_id}} } not found.": "Subskription { uuid: \"{{uuid}}\", org_id:{{org_id}} } nicht gefunden.",
"Subscription not found.": "Subscription not found.",
"Subscription uuid \"{{uuid}}\" not found.": "Subskriptions-UUID \"{{uuid}}\" nicht gefunden.",
"The configuration channel name {{name}} already exists.": "Der Konfigurationskanalname {{name}} ist bereits vorhanden.",
"The content type {{contentType}} is not valid. Allowed values: [{{contentTypes}}]": "Der Inhaltstyp {{contentType}} ist nicht gültig. Zulässige Werte: [{{contentTypes}}]",
Expand All @@ -76,6 +78,7 @@
"Too many configuration channels are registered under {{org_id}}.": "Unter {{org_id}} sind zu viele Konfigurationskanäle registriert.",
"Too many subscriptions are registered under {{org_id}}.": "Unter {{org_id}} sind zu viele Subskriptionen registriert.",
"Unsupported arguments: [{{args}}]": "Nicht unterstützte Argumente: [{{args}}]",
"Unsupported mutation: {{args}}": "Unsupported mutation: {{args}}",
"Uploaded versions must specify a \"file\" or \"content\".": "Bei hochgeladenen Versionen muss \"file\" (Datei) oder \"content\" (Inhalt) angegeben sein.",
"Version uuid \"{{version_uuid}}\" not found.": "Versions-UUID \"{{version_uuid}}\" nicht gefunden.",
"Versions must specify a \"name\".": "Bei Versionen muss \"name\" (Name) angegeben sein.",
Expand All @@ -88,6 +91,7 @@
"You are not allowed to read resources due to missing permissions on subscription group {{group}}.": "Sie dürfen Ressourcen nicht lesen, da die Berechtigungen für die Subskriptionsgruppe {{group}} fehlen.",
"You are not allowed to read subscriptions due to missing permissions on cluster group {{group.name}}.": "Sie dürfen Subskriptionen nicht lesen, da Berechtigungen für die Clustergruppe {{group.name}} fehlen.",
"You are not allowed to set subscription for all of {{subscription.groups}} groups.": "Sie dürfen keine Subskription für alle {{subscription.groups}}-Gruppen festlegen.",
"You are not authorized to modify some of the cluster groups": "You are not authorized to modify some of the cluster groups",
"You have exceeded the maximum amount of clusters for this org - {{org_id}}": "Sie haben den Maximalwert an Clustern für diese Organisation {{org_id}} überschritten.",
"You have exeeded the maximum amount of pending clusters for this org - {{org_id}}.": "Sie haben den Maximalwert an anstehenden Clustern für diese Organisation {{org_id}} überschritten."
}
}
1 change: 1 addition & 0 deletions locales/en/razee-resources.json
Expand Up @@ -91,6 +91,7 @@
"You are not allowed to read resources due to missing permissions on subscription group {{group}}.": "You are not allowed to read resources due to missing permissions on subscription group {{group}}.",
"You are not allowed to read subscriptions due to missing permissions on cluster group {{group.name}}.": "You are not allowed to read subscriptions due to missing permissions on cluster group {{group.name}}.",
"You are not allowed to set subscription for all of {{subscription.groups}} groups.": "You are not allowed to set subscription for all of {{subscription.groups}} groups.",
"You are not authorized to modify some of the cluster groups": "You are not authorized to modify some of the cluster groups",
"You have exceeded the maximum amount of clusters for this org - {{org_id}}": "You have exceeded the maximum amount of clusters for this org - {{org_id}}",
"You have exeeded the maximum amount of pending clusters for this org - {{org_id}}.": "You have exeeded the maximum amount of pending clusters for this org - {{org_id}}."
}

0 comments on commit 36918ac

Please sign in to comment.