I'm using following code to add a target pool to Google compute engine in java using Google Compute Engine Java API.
Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute();
I need to make sure that target pool is successfully added or not before execute the next line. What is the best way to do this in Google Compute Engine API?
You need to wait until operation will be in status DONE and then check if it has no errors. To do that you need to do polling on the operation using the compute."operations"().get() - I've put operations in quotation marks because there are three types of operations: global, regional and zonal and each of them has its own service: globalOperations(), regionOperations() and zoneOperations(). As targetPools are regional resource, operation created by insert is also regional so you need to use compute().regionOperations().get(). Code: