Tag Base Service Mapping not updating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 07:25 AM
Hi
We are using Kubernetes Namespace as a tag to build the Maps. In fact we are doing so using a script
Below is the script to create the map. The reason why we are doing so is when the Application Service is created (created using a scheduled flow) the end points in the Application service are created using a HTTP End Point. We are deleting the same and creating the end point through a script. We have created a custom column called name space on the application service auto table
This code is working fine.
var gr = new GlideRecord('cmdb_ci_service_auto'); // use child table
gr.addEncodedQuery('sys_class_name!=cmdb_ci_alert_group^name=xxx.com');
gr.query();
while (gr.next()) {
//delete the existing tag based record
var gr3 = new GlideRecord('cmdb_ci_service_by_tags');
gr3.addQuery('name', gr.name);
gr3.query();
while (gr3.next()) {
gr3.deleteRecord();
}
// deleting the HTTPS entry point before converting the application service to tag-based application services
var gr1 = new GlideRecord('cmdb_ci_endpoint_http');
gr1.addQuery('host_name', gr.name);
gr1.query();
while (gr1.next()) {
gr1.deleteRecord();
}
var app_service1 = gr.name;
var namespace1 = gr.u_namespace;
gr.sys_class_name = 'cmdb_ci_service_by_tags'; // converting the application service to tag-based application services
gr.update();
Now after the map is created the user might change the namespace on the custom column in the cmdb_ci_service_by_tags table. Once it is changed, we have to rebuild the map with the new name space.
I have created a update business rule for the same.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
oldNameSpace = previous.u_namespace;
newNameSpace = current.u_namespace;
metaTagValue = current.getValue('metadata', '{"category_value"}');
appName = current.name;
findStr = metaTagValue.substr(74, 7);
//gs.info("Metatag new value: "+newNameSpace);
if (oldNameSpace != findStr) {
// // current.deleteRecord();
var gr1 = new GlideRecord('cmdb_ci_endpoint_http');
gr1.addQuery('host_name', appName);
gr1.query();
while (gr1.next()) {
gr1.deleteRecord();
}
var servicePopulatorRunner = new SNC.ServicePopulatorRunner('INTERACTIVE');
current.setValue('u_namespace', namespace);
current.setValue('metadata', '{"category_values":[{"category":"meta.helm.sh/release-namespace","value":"' + newNameSpace + '"}],"checksum":"WAITING_FOR_UPDATE"}');
current.service_populator = 'cae02879c3b23300daa79624a1d3ae2f';
current.populator_status = '1';
// gr2.update();
servicePopulatorRunner.run(current);
This is not updating the map.
Can anyone suggest what needs to be done in the context.
