/** * This method verifies the busy status of the template to be used. In the event of a busy status, * it enters a wait/retry loop. * * @param tempId */ private Boolean checkIsTemplateAvailable(String tempId) { JenkinsLogger.log("Checking availability of template with id: " + tempId); // build busy check request String requestURL = buildCheckTemplateURL(tempId); HttpGet hg = SkytapUtils.buildHttpGetRequest(requestURL, this.authCredentials); // repeatedly execute request until template is not busy String httpRespBody = ""; Boolean templateIsAvailable = false; try { int numPollingAttempts = 0; while (!templateIsAvailable && (numPollingAttempts < this.NUMBER_OF_RETRIES)) { httpRespBody = SkytapUtils.executeHttpRequest(hg); // get json object from the response JsonParser parser = new JsonParser(); JsonElement je = parser.parse(httpRespBody); JsonObject jo = je.getAsJsonObject(); // get busy status - if busy in returned // JSON array is 'null', means template is not busy if (jo.get("busy").isJsonNull()) { templateIsAvailable = true; JenkinsLogger.log("Template is available."); } else { templateIsAvailable = false; JenkinsLogger.log("Template is busy."); // wait before trying again int sleepTime = this.RETRY_INTERVAL_SECONDS; JenkinsLogger.log("Sleeping for " + sleepTime + " seconds."); Thread.sleep(sleepTime * 1000); } numPollingAttempts++; } return templateIsAvailable; } catch (SkytapException ex) { JenkinsLogger.error("Request returned an error: " + ex.getError()); JenkinsLogger.error("Failing build step."); return false; } catch (InterruptedException e1) { JenkinsLogger.error(e1.getMessage()); return false; } }