Symptoms:
VMware vCenter Server 7.0.x
In specific environments, tags associated with active objects in vCenter may be removed during the vCenter upgrade process, but the details of these deleted tags may not be reflected back in vCenter. As a result, the vCenter inventory may display valid objects linked to invalid tags.
When attempting to attach tags back to an object, it retrieves the IDs of all tags associated with the virtual machine from the VCDB, including those that are invalid. Hence when the function “isPassCardinality” attempts to access information related to an invalid tag ID, it results in a null pointer exception.
NOTE:
dcli> vcenter vm list Username: [email protected]
Password: ********
Do you want to save credentials in the credstore? (y or n) [y]:y
|---------------|-----|---------|-----------|---------|
|memory_size_MiB|vm |name |power_state|cpu_count|
|---------------|-----|---------|-----------|---------|
|128 |vm-1|Test_1 |POWERED_ON |1 |
|128 |vm-2|Test_2 |POWERED_ON |1 |
|1024 |vm-3|Test_3 |POWERED_OFF|1 |
|1024 |vm-4|Test_4 |POWERED_OFF|1 |
|---------------|-----|---------|-----------|---------|
dcli> tagging category create --name cat-1 --description "cat info" --cardinality SINGLE urn:vmomi:InventoryServiceCategory: ########-48ea-####-####-############:GLOBAL
dcli> tagging tag create --name tag-1 --description "tag info" --category-id urn:vmomi:InventoryServiceCategory:########-48ea-####-####-############:GLOBAL
urn:vmomi:InventoryServiceTag:########-1234-####-####-############:GLOBAL
dcli> tagging category create --name cat-2 --description "cat info 2" --cardinality MULTIPLE
urn:vmomi:InventoryServiceCategory:########-424c-####-########-####:GLOBAL
dcli> tagging tag create --name tag-2 --description "tag info 2" --category-id urn:vmomi:InventoryServiceCategory:########-424c-####-########-####:GLOBAL
urn:vmomi:InventoryServiceTag:########-5678-####-####-############:GLOBAL
dcli> tagassociation attach --id vm-3 --tag-id urn:vmomi:InventoryServiceTag:########-1234-####-####-############:GLOBAL --type VirtualMachine
dcli> tagassociation attach --id vm-4 --tag-id urn:vmomi:InventoryServiceTag:########-5678-####-####-############:GLOBAL --type VirtualMachine
dcli> tagging tag create --name tag-cat-single --description "tag info - cat single" --category-id urn:vmomi:InventoryServiceCategory:########-48ea-####-####-############:GLOBAL
urn:vmomi:InventoryServiceTag:########-6f35-####-########-####:GLOBAL
/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
select * from VPX_ENTITY_TAG_XREF;
entity_id | tag_id
-----------+--------
5 | 1
6 | 2
(2 rows)
select * from VPX_TAG_DEF;
id | tag_uuid | type_id
----+--------------------------------------+---------
1 | ########-1234-####-####-############ | 0
2 | ########-5678-####-####-############ | 0
insert into VPX_TAG_DEF (id, tag_uuid, type_id) values (5, ‘########-####-4186-####-############', 0);
insert into VPX_TAG_DEF (id, tag_uuid, type_id) values (6, '########-####-4817-####-############', 0);
insert into VPX_ENTITY_TAG_XREF (entity_id, tag_id) values (3, 5);
\q
service-control --restart vpxd
urn:vmomi:InventoryServiceTag:########-6f35-####-########-####:GLOBAL
) to vm-3 and vm-4, which should fail for vm-3dcli> tagassociation attach --id vm-3 --tag-id urn:vmomi:InventoryServiceTag:########-6f35-####-########-####:GLOBAL --type VirtualMachine
dcli> tagassociation attach --id vm-4 --tag-id urn:vmomi:InventoryServiceTag:########-6f35-####-########-####:GLOBAL --type VirtualMachine
var/log/vmware/vpxd-svcs/vpxd-svcs.log:
grep -ri -A 10 B 10 NullPointerException
./vpxd-svcs.log-YYYY-MM-DDTHH:MM:SSZ [tomcat-exec-112 INFO com.vmware.cis.server.util.PerfLog opId=] Requesting LDAP connection
./vpxd-svcs.log-YYYY-MM-DDTHH:MM:SSZ [tomcat-exec-112 DEBUG com.vmware.cis.lotus.LdapConnectionFactory opId=] Got connection; com.vmware.identity.interop.ldap.LdapConnection@3281dfc2
./vpxd-svcs.log-YYYY-MM-DDTHH:MM:SSZ [tomcat-exec-112 INFO com.vmware.cis.server.util.PerfLog opId=] Connection type: LDAP, Max allowed connections: 24, Number of active connections: 1, Number of idle connections: 1
./vpxd-svcs.log-YYYY-MM-DDTHH:MM:SSZ [tomcat-exec-112 DEBUG com.vmware.cis.lotus.LdapConnectionFactory opId=] Releasing connection; com.vmware.identity.interop.ldap.LdapConnection@3281dfc2
./vpxd-svcs.log-YYYY-MM-DDTHH:MM:SSZ [tomcat-exec-112 WARN com.vmware.vapi.internal.bindings.ApiMethodSkeleton opId=] Implementation method reported unexpected exception: java.lang.NullPointerException
./vpxd-svcs.log-java.lang.NullPointerException
./vpxd-svcs.log- at com.vmware.cis.core.tagging.internal.impl.TagAssociationManagerImpl.isPassCardinality(TagAssociationManagerImpl.java:549)
./vpxd-svcs.log- at com.vmware.cis.core.tagging.internal.impl.TagAssociationManagerImpl.attach(TagAssociationManagerImpl.java:229)
./vpxd-svcs.log- at com.vmware.cis.core.tagging.vapi.TagAssociationProviderImpl.attach(TagAssociationProviderImpl.java:59)
/opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres
\copy (select * from VPX_ENTITY_TAG_XREF) to ./vcdb-vpx-entity-tag-xref.csv CSV HEADER;
\copy (select * from VPX_TAG_DEF) to ./vcdb-vpx-tag-def.csv CSV HEADER;
\q
python3 collect-tag-associations.py --vcip '<vc ip>' --session '<session>'
python3 collect-tag-associations.py --vcip '<vc ip>' --username '<AD username>' --password '<AD password>'
This will generate a json file named 'tag-associations.json
'
valid vms : 2
valid tags from ldap : 4
From vcdb valid tags : 3
From vcdb invalid tags : 2
vpx_tag_entities_dict_valid_entity : 4
vpx_tag_entities_dict_invalid_entity : {}
valid_vms_found : 2
2
tag get --tag-id urn:vmomi:InventoryServiceTag:########-####-4186-####-############:GLOBAL
tag get --tag-id urn:vmomi:InventoryServiceTag:########-####-4817-####-############:GLOBAL
vpx-entity-tag-xref table: delete from VPX_ENTITY_TAG_XREF where tag_id in ( 3, 4 );
:
delete from VPX_TAG_DEF where id in ( 3, 4);service-control --restart vpxd
>1234,1001
>1234,1002
>1234,1003
>1234,1004
>1234,1005
>1234,1006
Workaround:
Unregister and re-register the VM in VC inventory