public void run(final String defaultUsername, final String defaultPassword) throws Exception { Callable<Boolean> statusChecker = () -> { HttpGet statusGet = new HttpGet(statusUrl); ResponseHandler<String> statusHandler = new BasicResponseHandler(); String response = userRequestSender.sendRequestAsUser(statusGet, statusHandler, defaultUsername, defaultPassword); if (null != response && StringUtils.isNotBlank(response) && response.startsWith("{") && response.endsWith("}")) { JSON json = JSON.parse(response); return (null != json.get("enabled")); } return false; }; ScheduledFuture<Boolean> statusCheck = scheduledExecutor.schedule(statusChecker, period, TimeUnit.MILLISECONDS); long abortAfter = System.currentTimeMillis() + timeout; while (!statusCheck.get() && abortAfter > System.currentTimeMillis()) { statusCheck = scheduledExecutor.schedule(statusChecker, period, TimeUnit.MILLISECONDS); } if (abortAfter <= System.currentTimeMillis()) { throw new ConnectAddonInstallException("Connect App Plugin did not install within the allotted timeout"); } } }
public JSON getClientHttpDataJson() throws IOException, ParserException { return JSON.parse(waitForValue("client-http-data-json")); } }
public void assertAddonIsEnabled(String addonKey) { assertTrue(getPluginJson(addonKey).get("enabled").getBoolean()); }
@Override public String find(String expression) throws Exception { JPath path = JPath.parse(expression); Value value = path.evaluate(body); if (value == null) { log.warn("Can't find expression '" + expression + "' in\n" + body.toJSON()); return null; } else { return value.toString(); } }
public JSON getClientHttpDataJson() throws IOException, ParserException { return JSON.parse(waitForValue("client-http-data-json")); } }
public void assertAddonIsDisabled(String addonKey) { assertFalse(getPluginJson(addonKey).get("enabled").getBoolean()); }
@Override public String find(String expression) throws Exception { JPath path = JPath.parse(expression); Value value = path.evaluate(body); if (value == null) { log.warn("Can't find expression '" + expression + "' in\n" + body.toJSON()); return null; } else { return value.toString(); } }
String response = userRequestSender.sendRequestAsUser(statusGet, statusHandler, defaultUsername, defaultPassword); if (null != response && StringUtils.isNotBlank(response) && response.startsWith("{") && response.endsWith("}")) { JSON json = JSON.parse(response); Value statusValue = json.get("status"); if (statusValue != null) { Value errorMessageValue = statusValue.get("errorMessage"); return (null != json.get("enabled"));
public JSON testDeserializerByIdentifier(String deserializerIdentifier) throws Exception { HttpGet get = new HttpGet(baseUrl + TEST_STORAGE_URL + "/identifier/" + deserializerIdentifier); get.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = userRequestSender.sendRequestAsUser(get, responseHandler, defaultUsername, defaultPassword); return JSON.parse(response); } }
private static PerformanceResultsPublisherClient.PerformanceTestResult runPerformanceTest(TestPluginModuleStorageClient testPluginModuleStorageClient, PluginModulePerformanceTest performanceTest) throws Exception { final DescriptiveStatistics statistics = new DescriptiveStatistics(); final String deserializerIdentifier = performanceTest.getDeserializerIdentifier(); for (int i = 0; i < ITERATIONS; i++) { statistics.addValue(testPluginModuleStorageClient.testDeserializerByIdentifier(deserializerIdentifier).get("totalElapsedTimeMs").getDouble()); log.info("Moving median " + i + ": " + statistics.getPercentile(50)); } final double medianTimeMs = statistics.getPercentile(50); log.info("Median time for " + deserializerIdentifier + " with " + PLUGIN_MODULES + " modules: " + medianTimeMs + "ms"); final String assertionReason = "Deserializing " + deserializerIdentifier + " took too much time. More than " + performanceTest.maximumTimeMsForOneHundredModules() + "ms."; Assert.assertThat(assertionReason, medianTimeMs, Matchers.lessThanOrEqualTo(performanceTest.maximumTimeMsForOneHundredModules())); return new PerformanceResultsPublisherClient.PerformanceTestResult(deserializerIdentifier, medianTimeMs, statistics.getPercentile(99)); }
public void install(String registerUrl, boolean checkStatus) throws Exception { //get a upm token String token = getUpmToken(); HttpPost post = new HttpPost(baseUrl + UPM_URL_PATH + "?token=" + token); post.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); final ObjectNode installRequest = JsonNodeFactory.instance.objectNode(); installRequest.put("pluginUri", registerUrl); installRequest.put("pluginName", "the plugin name"); post.setEntity(new StringEntity(installRequest.toString(), ContentType.create("application/vnd.atl.plugins.install.uri+json"))); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = userRequestSender.sendRequestAsUser(post, responseHandler, defaultUsername, defaultPassword); if (Strings.isNullOrEmpty(response) || (!response.startsWith("{") && !response.endsWith("}"))) { install(registerUrl); } else { JSON json = JSON.parse(response); if (null == json.get("enabled")) { URI uri = new URI(baseUrl); final String statusUrl = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + json.get("links").get("self").getString(); // JCE-635 the timeout here used to be 1 minute but needed to be bumped - it should be changed back if possible InstallStatusChecker statusChecker = checkStatus ? new InstallStatusChecker(userRequestSender, statusUrl, 4, TimeUnit.MINUTES, 500, TimeUnit.MILLISECONDS) : new InstallStatusChecker(userRequestSender, statusUrl, 5, TimeUnit.SECONDS, 500, TimeUnit.MILLISECONDS); statusChecker.run(defaultUsername, defaultPassword); } } }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getRequestURI().endsWith("/webhook") || req.getRequestURI().endsWith("-lifecycle")) { String version = req.getHeader(HttpHeaderNames.ATLASSIAN_CONNECT_VERSION); final String authorizationHeader = getAuthorizationHeader(req); try { String readerToParse = IOUtils.toString(req.getReader()); JSON json = readerToParse.equals("") ? null : JSON.parse(readerToParse); webHooksQueue.push(new JsonWebHookBody(getFullURL(req), json, version, authorizationHeader)); resp.getWriter().write("OKEY DOKEY"); } catch (ParserException e) { throw new ServletException(e); } } }
public void install(String registerUrl, boolean checkStatus) throws Exception { //get a upm token String token = getUpmToken(); HttpPost post = new HttpPost(baseUrl + UPM_URL_PATH + "?token=" + token); post.addHeader("Accept", "application/json"); post.setEntity(new StringEntity("{ \"pluginUri\": \"" + registerUrl + "\", \"pluginName\": \"the plugin name\" }", ContentType.create("application/vnd.atl.plugins.install.uri+json"))); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = userRequestSender.sendRequestAsUser(post, responseHandler, defaultUsername, defaultPassword); if (Strings.isNullOrEmpty(response) || (!response.startsWith("{") && !response.endsWith("}"))) { install(registerUrl); } else { JSON json = JSON.parse(response); if (null == json.get("enabled")) { URI uri = new URI(baseUrl); final String statusUrl = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + json.get("links").get("self").getString(); if (checkStatus) { InstallStatusChecker statusChecker = new InstallStatusChecker(userRequestSender, statusUrl, 1, TimeUnit.MINUTES, 500, TimeUnit.MILLISECONDS); statusChecker.run(defaultUsername, defaultPassword); } else { InstallStatusChecker statusChecker = new InstallStatusChecker(userRequestSender, statusUrl, 5, TimeUnit.SECONDS, 500, TimeUnit.MILLISECONDS); try { statusChecker.run(defaultUsername, defaultPassword); } catch (Exception e) { } } } } }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getRequestURI().endsWith("/webhook") || req.getRequestURI().endsWith("-lifecycle")) { String version = req.getHeader(HttpHeaderNames.ATLASSIAN_CONNECT_VERSION); final String authorizationHeader = getAuthorizationHeader(req); try { webHooksQueue.push(new JsonWebHookBody(getFullURL(req), JSON.parse(IOUtils.toString(req.getReader())), version, authorizationHeader)); resp.getWriter().write("OKEY DOKEY"); } catch (ParserException e) { throw new ServletException(e); } } }
private JSON getPluginJson(String addonKey) { try { return JSON.parse(connectClient.getUpmPluginJson(addonKey)); } catch (Exception e) { fail("add-on is not installed"); return null; } }