Fix NPE when GCE region is empty
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.
This commit is contained in:
parent
c77dc4a82c
commit
66e3b15d21
|
@ -97,7 +97,7 @@ public class GceComputeServiceImpl extends AbstractLifecycleComponent<GceCompute
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// assist type inference
|
// 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) {
|
} catch (PrivilegedActionException e) {
|
||||||
logger.warn("Problem fetching instance list for zone {}", e, zoneId);
|
logger.warn("Problem fetching instance list for zone {}", e, zoneId);
|
||||||
logger.debug("Full exception:", e);
|
logger.debug("Full exception:", e);
|
||||||
|
|
|
@ -254,4 +254,17 @@ public class GceDiscoveryTests extends ESTestCase {
|
||||||
assertThat(expected.getMessage(), containsString("one or more gce discovery settings are missing."));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"id": "dummy"
|
||||||
|
}
|
Loading…
Reference in New Issue