Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

GCP Java API sometimes fail with 400 and 403 statuses

Below is a simple for loop that reproduces the errors.  What's baffling is that lines 5 & 7 sometimes fail, and sometimes are successful, seemingly randomly.  The stack traces sometimes reference a 400/Bad Request status code, and sometimes 403/Forbidden status code.  For brevity, I didn't include the rest of the lengthy code, and since it sometimes works, this seems to be a serious bug and/or poor error responses with the GCE Java API (com.google.cloud.compute.v1) - Anyone ever experience this or have any ideas why GCE Java API sometimes/randomly fails?

 

 

 

 

for(int i = 0; i < 10; i++) {
				GameServer gs = null;
				if((gs = GCPTools.getActiveGameServer(40, 5)) != null) {
					System.out.println("Found an active game server:" + gs);
				} else if((gs = GCPTools.startAGameServer()) != null) {//no running server available so try to start an existing one
					System.out.println("Started an available game server:" + gs);
				} else if((gs = GCPTools.createANewGameServer("projects/myProject/global/machineImages/i5-game-server-mi-015")) != null) {//no available game servers so create and start a new one
					System.out.println("Created a game server:" + gs);
				}
			}

 

 

 

 

 

0 1 145