Skip to content

Commit

Permalink
Fix NPE when GCE region is empty
Browse files Browse the repository at this point in the history
When GCE region is empty we get back from the API something like:

```
{
  "id": "dummy"
}
```

instead of:

```
{
  "id": "dummy",
  "items":[ ]
}
```

This generates a NPE when we aggregate all the lists into a single one.

Closes #16967.
  • Loading branch information
dadoonet committed Jun 30, 2016
1 parent c77dc4a commit 66e3b15
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public InstanceList run() throws Exception {
}
});
// assist type inference
return instanceList.isEmpty() ? Collections.<Instance>emptyList() : instanceList.getItems();
return instanceList.isEmpty() || instanceList.getItems() == null ? Collections.<Instance>emptyList() : instanceList.getItems();
} catch (PrivilegedActionException e) {
logger.warn("Problem fetching instance list for zone {}", e, zoneId);
logger.debug("Full exception:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,17 @@ public void testIllegalSettingsMissingZone() {
assertThat(expected.getMessage(), containsString("one or more gce discovery settings are missing."));
}
}

/**
* For issue https://github.com/elastic/elasticsearch/issues/16967
*/
public void testEmptyRegion16967() {
Settings nodeSettings = Settings.builder()
.put(GceComputeService.PROJECT_SETTING.getKey(), projectName)
.putArray(GceComputeService.ZONE_SETTING.getKey(), "europe-west1-b", "us-central1-a")
.build();
mock = new GceComputeServiceMock(nodeSettings, networkService);
List<DiscoveryNode> discoveryNodes = buildDynamicNodes(mock, nodeSettings);
assertThat(discoveryNodes, hasSize(1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id": "dummy",
"items":[
{
"description": "ES Node 1",
"id": "9309873766428965105",
"kind": "compute#instance",
"machineType": "n1-standard-1",
"name": "test1",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "104.155.13.147",
"type": "ONE_TO_ONE_NAT"
}
],
"name": "nic0",
"network": "default",
"networkIP": "10.240.79.59"
}
],
"status": "RUNNING",
"tags": {
"fingerprint": "xA6QJb-rGtg=",
"items": [
"elasticsearch",
"dev"
]
},
"zone": "europe-west1-b"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "dummy"
}

0 comments on commit 66e3b15

Please sign in to comment.