VMware {code} Community
venkat70
Contributor
Contributor

NPE when calling findEntities

Any idea?

java.lang.NullPointerException

at java.util.regex.Matcher.getTextLength(Matcher.java:1140)

at java.util.regex.Matcher.reset(Matcher.java:291)

at java.util.regex.Matcher.<init>(Matcher.java:211)

at java.util.regex.Pattern.matcher(Pattern.java:888)

at java.util.regex.Pattern.matches(Pattern.java:929)

at com.vmware.contrib.vi.InventoryImpl.findEntities(InventoryImpl.java:334)

thanks

venkat

Reply
0 Kudos
16 Replies
admin
Immortal
Immortal

more details? sample code?

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

i'm trying to discover ESX servers, datacenters etc through a virtual center using VI java API (the vmware api and not the opensource API).

I hit some data centers which are empty (no folders or hosts in them).

My code is as below to get the HostSystem's

Inventory inv = InventoryFactory.getInventory(vmwareconnection);

Folder root = inv.getRootFolder();

ManagedEntity[] dcentities = inv.findEntities(root, Datacenter.class);

ManagedEntity[] hfentities = this.getSubEntities(dcentities, Folder.class, "host", inv);

//getSubEntities method below.

it throws NPE in findEntities call in the getSubEntities method.

protected ManagedEntity[] getSubEntities(ManagedEntity[] pentities, Class<? extends ManagedEntity> ctype, String filtername, Inventory inv) {

ArrayList<ManagedEntity> arrentities = new ArrayList<ManagedEntity>(0);

if (pentities != null && pentities.length > 0) {

for (int i=0;i<pentities.length;i++) {

ManagedEntity[] entities=null;

try {

entities = inv.findEntities(pentities[i], ctype, filtername);

}

catch (Throwable t) {

t.printStackTrace();

}

if (entities != null) {

for (int k=0;k<entities.length;k++) {

arrentities.add(entities[k]);

}

}

}

}

return arrentities.toArray(new ManagedEntity[0]);

}

Reply
0 Kudos
admin
Immortal
Immortal

1. findEntities() takes a single start entity, not an array

>>

entities = inv.findEntities(pentities, ctype, filtername);

pentities is an array?

2. The easy way to find HostSystem is:

ManagedEntiy[] hostSystems = inv.findEntities(root, HostSystem.class);

3. the exception looks like some ManagedEntity returns null as 'name'

I need to investigate this further.

It will be helpful If you can provide more debug information.

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

i'm passing one at a time. it's

 pentities[i] 

. when i pasted this in the forum, i forgot to enclose within

Reply
0 Kudos
venkat70
Contributor
Contributor

i did simple call like below

 ManagedEntity[] hsentities = inv.findEntities(root, HostSystem.class, esxdnsname); 

The esx i'm looking for is there. it's name attribute is having value. but this call throws again the same NPE.

i think it goes through all the HostSystem instances and compares the name. maybe it hits a host which has null value for Name.

it fails to get the host instance. i work for EMC. Let me know if i need to get this through a different channel. i can give you lot more information that way than what i'm giving you in the forum.

thanks

venkat

Reply
0 Kudos
admin
Immortal
Immortal

Yes, it gets all host first then try to match the name.

Can you try the following:

ManagedEntiy[] hosts = inv.findEntities(root, HostSystem.class);

for(ManagedEntiy host : hosts) {

System.out.println("host name " + host.getName());

}

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

i did that and for all the hosts, it's coming in as null. But i know at least 2 hosts which has Name value set. i can see it when i browse through mob when i go to HostSystem.

Null Check: The host name is null

Null Check: The host name is null

Null Check: The host name is null

Reply
0 Kudos
admin
Immortal
Immortal

That is strange, can you try some other types, such as:

ManagedEntiy[] folders = inv.findEntities(root, Folder.class);

for(ManagedEntiy folder : folders) {

System.out.println("folder name " + folder.getName());

}

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

folder name too is comming all null.

i have more than one thread which creates connection to the virtual center and queries data using Inventory.

The first thread seems to be fine. In all subsequent threads, all names are coming null.

is there any connection related issues?

thanks

venkat

Reply
0 Kudos
admin
Immortal
Immortal

I wonder why you have multiple threads which connect to the same VC?

more details?

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

that's our design.

if a vCenter contains 3 esx hosts, each thread will go and discover one esx server. If there are n hosts, there'll be n threads discovering those n hosts. We don't run out of threads though. It's limited by number of threads available in our system.

This was working fine before. suddenly it started with these nulls. i'm not sure why.

thanks

venkat

Reply
0 Kudos
admin
Immortal
Immortal

Can you write some testing code which reproduces the multithreading problem?

I will try and debug it if you send to me.

core API and toolkits team

Reply
0 Kudos
admin
Immortal
Immortal

or please log the SOAP message across the wire.

Since Axis2 use HttpClient, here is how to set up the logging:

http://hc.apache.org/httpclient-3.x/logging.html

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

Ok. i think i know what's the problem.

In one thread, i was closing the connection after everything is done by calling Connection.logout();

In the 2nd thread, i was again creating a new Connection. somehow, it is using the old stale connection where getName for everything is coming back as null.

i was maintaining a map of ip and connections. maybe i didn't cleanup the map after logging out.

thanks a lot for trying to help me. i'll check the maps and make sure i'm not using stale connections.

venkat

Reply
0 Kudos
admin
Immortal
Immortal

good.

But it will be more efficient if you can share a a single connection by multiple threads.

core API and toolkits team

Reply
0 Kudos
venkat70
Contributor
Contributor

i do. that's why i ended up using a logged out connection.

venkat

Reply
0 Kudos