Service Mapping NullPointerException errorDescription<!-- div.margin{ padding: 10px 40px 40px 30px; } table.tocTable{ border: 1px solid; border-color:#E0E0E0; background-color: rgb(245, 245, 245); padding-top: .6em; padding-bottom: .6em; padding-left: .9em; padding-right: .6em; } table.noteTable{ border:1px solid; border-color:#E0E0E0; background-color: rgb(245, 245, 245); width: 100%; border-spacing:2; } table.internaltable { white-space:nowrap; text-align:left; border-width: 1px; border-collapse: collapse; font-size:14px; width: 85%; } table.internaltable th { border-width: 1px; padding: 5px; border-style: solid; border-color: rgb(245, 245, 245); background-color: rgb(245, 245, 245); } table.internaltable td { border-width: 1px; padding: 5px; border-style: solid; border-color: #E0E0E0; color: #000000; } .title { color: #D1232B; font-weight:normal; font-size:28px; } h1{ color: #D1232B; font-weight:normal; font-size:21px; margin-bottom:-5px } h2{ color: #646464; font-weight:bold; font-size:18px; } h3{ color: #000000; font-weight:BOLD; font-size:16px; text-decoration:underline; } h4{ color: #646464; font-weight:BOLD; font-size:15px; text-decoration:; } h5{ color: #000000; font-weight:BOLD; font-size:13px; text-decoration:; } h6{ color: #000000; font-weight:BOLD; font-size:14px; text-decoration:; } hr{ border-top-width: 1px; border-top-style: solid; border-top-color: #cccccc; } ul { list-style: disc outside none; margin-left: 0; padding-left: 1em; } li { padding-left: 1em; } --> Issue When starting a discovery of a service map, discovery stops immediately and the java.lang.NullPointerException error can be seen in the log. Troubleshooting The NullPointerException error is thrown during recomputation of the business service. The most common reason for this error during recomputation is an existing duplicate dependencies in cmdb_rel_ci table. Having an NPE (NullPointerException) in such cases is not desirable; however, the recomputation logic behavior was completely updated in Kingston and such errors are not likely to happen in Kingston and newer releases. To find the root cause for the issue you need to (short term): Find the CI that the recomputation was processing when the error happenedLook for duplicate relationships for the device and remove them For a long-term solution, you need to determine what caused the duplicate relationships. Finding the CI To find the CI, navigate to System Definition > Scripts - Background and run the following script. The output will be logged to the screen. Note – Replace empty in gr.get('empty') with the sys_id for the business service. gs.setProperty("glide.cmdb.logger.source.service_mapping.coordinator","info,warn,error,*"); gs.setProperty("glide.cmdb.logger.source.service_mapping.template", "info,warn,error,*"); gs.setProperty("glide.cmdb.logger.source.service_mapping.matching", "info,warn,error,*"); gs.setProperty('glide.transaction.max_logs', 200*10000); var gr = new GlideRecord('cmdb_ci_service_discovered'); gr.get('empty'); // <This line must be updated with service sys_idvar layerId= gr.layer; var layerGr= new GlideRecord('svc_layer'); layerGr.get(layerId); var env= sn_svcmod.ServiceContainerFactory.loadEnvironment(layerGr.environment); var allLayers= env.layers(); for (var i= 0 ; i< allLayers.length; i++) { var layer = allLayers[i]; layer.markRecomputationNeeded(); } SNC.ServiceMappingFactory.recomputeLayer(layerGr); gs.setProperty('glide.transaction.max_logs', 200*1000); gs.setProperty("glide.cmdb.logger.source.service_mapping.coordinator","info,warn,error"); gs.setProperty("glide.cmdb.logger.source.service_mapping.template", "info,warn,error"); gs.setProperty("glide.cmdb.logger.source.service_mapping.matching", "info,warn,error"); The CI with the duplicate relationship should be the last CI seen in the output before the NPE error. In the following example output snippet, the CI would be 567bcdb49179390020e5db5405e32514. service_mapping.template :>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>## UPDATE: convertRecordIntoElements: (CI:cmdb_ci_win_server:9667 # 567bcdb49179390020e5db5405e32514) => (cmdb_ci_win_server:9668) service_mapping.coordinator : Attempting to process layer Template on environment bb5e3069dbbb4304fc1cf9961d9619bb resulted in an exception:: no thrown error service_mapping.coordinator : >> java.lang.NullPointerException: no thrown error service_mapping.coordinator : : no thrown error In this example, it was found that the CI had multiple "hosted on:hosts" relationship records to the same CI. For different CI records, there will be different relationship types that might cause the error. Once the CI is found, relationships in the cmdb_rel_ci table can be filtered for "parent = CI or child = CI", CI found in script output, to look for duplicate relationships. Identification rules Very often such duplicate relationship/CI(s) are created due to identification rules that should be dependent but are set to independent. To look for such identification rules, navigate to System Definition > Scripts - Background and run the following script to find identifiers that are set to independent and should not be. var gr = new GlideRecord('cmdb_identifier'); gr.addQuery('independent', 1); gr.query(); while (gr.next()) { if (GlideDBObjectManager.get().isInstanceOf(gr.applies_to, 'cmdb_ci_appl') || GlideDBObjectManager.get().isInstanceOf(gr.applies_to, 'cmdb_ci_lb_service')) { gs.print("Application " + gr.applies_to + " has an independent identifier rule"); } } Once these steps are followed (duplicate relationships are found and removed), the business service map discovery can be run again without the NPE error. Background scripts, to search for duplicate application and cluster relationships // find an application that runs on more than one host (wrong identifier). var gr = new GlideAggregate('cmdb_rel_ci'); gr.addQuery('type', '60bc4e22c0a8010e01f074cbe6bd73c3'); // runs on relation gr.addQuery('child.sys_class_name','INSTANCEOF','cmdb_ci_server' ); gr.addQuery('parent.sys_class_name','INSTANCEOF','cmdb_ci_appl' ); gr.addAggregate('COUNT'); gr.groupBy('parent'); gr.query(); gs.print('*** Affected Applicataions: ***'); while (gr.next()) { if (gr.getAggregate('COUNT') > 1) { gs.print(gr.parent + ":" + gr.parent.name); } } // find servers that are hosted on more then one cluster node var gr = new GlideAggregate('cmdb_rel_ci'); gr.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815'); gr.addQuery('child.sys_class_name', 'cmdb_ci_win_server'); gr.addQuery('parent.sys_class_name', 'cmdb_ci_win_cluster_node'); gr.addAggregate('COUNT'); gr.groupBy('child'); gr.query(); gs.print('*** Affected Servers: ***'); while (gr.next()) { if (gr.getAggregate('COUNT') > 1) { gs.print(gr.child + ":" + gr.child.name); } }