public static SSLContextBuilder builder() { return new SSLContextBuilder(); }
protected void pushToController(String releaseId, String containerId, String alias) throws Exception { String[] gav = releaseId.split(":"); String jsonPayload = CONTAINER_SPEC_JSON .replaceFirst("#1@", containerId) .replaceFirst("#2@", alias) .replaceFirst("#3@", gav[0]) .replaceFirst("#4@", gav[1]) .replaceFirst("#5@", gav[2]); HttpUtils.putHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId, jsonPayload); log.infof("Added %s container into controller at %s ", containerId, CONTROLLER); }
public static void getHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'GET' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode != 200) { throw new IOException("Unsucessful response code " + responseCode); } }
@Test public void testSecondAlias() { try { SSLContextBuilder.builder() .setKeyStorePath(KEYSTORE_PATH) .setKeyStorePassword(KEYSTORE_PASSWORD) .setKeyAlias(KEYSTORE_ALIAS_TWO) .build(); } catch (RuntimeException e) { fail(e.getMessage()); } }
while (it.hasNext()) { FailedHostInfo fHost = (FailedHostInfo) it.next(); if (attemptsLimit == fHost.getAttempts()) { it.remove(); log.info("Host " + fHost.getServerUrl() + " has reached reconnect attempts limit " + attemptsLimit + " quiting"); continue; HttpUtils.getHttpCall(fHost.getServerUrl()); log.info("Server at " + fHost.getServerUrl() + " is back online"); failedHostsReconnects.cancel(false); for (String containerId : fHost.getContainers()) { configuration.addContainerHost(containerId, fHost.getServerUrl()); configuration.addServerHost(fHost.getServerId(), fHost.getServerUrl()); log.debug("Host " + fHost.getServerUrl() + " is still not available, attempting to reconnect in " + interval + " seconds, error " + e.getMessage()); } finally { fHost.attempted();
protected void dropFromController(String containerId) throws Exception { HttpUtils.deleteHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId); log.infof("Removed %s container from controller at %s ", containerId, CONTROLLER); }
); FailedHostInfo failedHost = new FailedHostInfo(serverId, serverUrl, containers); return failedHost;
@Test public void testFirstAlias() { try { SSLContextBuilder.builder() .setKeyStorePath(KEYSTORE_PATH) .setKeyStorePassword(KEYSTORE_PASSWORD) .setKeyAlias(KEYSTORE_ALIAS_ONE) .build(); } catch (RuntimeException e) { fail(e.getMessage()); } }
while (it.hasNext()) { FailedHostInfo fHost = (FailedHostInfo) it.next(); if (attemptsLimit == fHost.getAttempts()) { it.remove(); log.info("Host " + fHost.getServerUrl() + " has reached reconnect attempts limit " + attemptsLimit + " quiting"); continue; HttpUtils.getHttpCall(fHost.getServerUrl()); log.info("Server at " + fHost.getServerUrl() + " is back online"); failedHostsReconnects.cancel(false); for (String containerId : fHost.getContainers()) { configuration.addContainerHost(containerId, fHost.getServerUrl()); configuration.addServerHost(fHost.getServerId(), fHost.getServerUrl()); log.debug("Host " + fHost.getServerUrl() + " is still not available, attempting to reconnect in " + interval + " seconds, error " + e.getMessage()); } finally { fHost.attempted();
protected void dropFromController(String containerId) throws Exception { HttpUtils.deleteHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId); log.infof("Removed %s container from controller at %s ", containerId, CONTROLLER); }
public static void deleteHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("DELETE"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'DELETE' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 204) { throw new IOException("Unsucessful response code " + responseCode); } }
public static SSLContextBuilder builder() { return new SSLContextBuilder(); }
protected void pushToController(String releaseId, String containerId, String alias) throws Exception { String[] gav = releaseId.split(":"); String jsonPayload = CONTAINER_SPEC_JSON .replaceFirst("#1@", containerId) .replaceFirst("#2@", alias) .replaceFirst("#3@", gav[0]) .replaceFirst("#4@", gav[1]) .replaceFirst("#5@", gav[2]); HttpUtils.putHttpCall(CONTROLLER + "/management/servers/" + KieServerInfoHandler.getRouterId() + "/containers/" + containerId, jsonPayload); log.infof("Added %s container into controller at %s ", containerId, CONTROLLER); }
); FailedHostInfo failedHost = new FailedHostInfo(serverId, serverUrl, containers); return failedHost;
@Test public void testIncorrectPassword() { try { SSLContextBuilder.builder() .setKeyStorePath(KEYSTORE_PATH) .setKeyStorePassword("bla") .setKeyAlias(KEYSTORE_ALIAS_ONE) .build(); // should fail fail("Exception not thrown"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof IOException); } } }
protected void disconnectToController() { if (CONTROLLER == null) { return; } try { HttpUtils.deleteHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId() + "/?location=" + URLEncoder.encode(KieServerInfoHandler.getLocationUrl(), "UTF-8")); log.infof("KieServerRouter disconnected from controller at " + CONTROLLER); } catch (Exception e) { log.error("Error when disconnecting from controller at " + CONTROLLER, e); } }
public static void deleteHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("DELETE"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'DELETE' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode > 204) { throw new IOException("Unsucessful response code " + responseCode); } }
@Test public void testNonExistingAlias() { try { SSLContextBuilder.builder() .setKeyStorePath(KEYSTORE_PATH) .setKeyStorePassword(KEYSTORE_PASSWORD) .setKeyAlias("bla") .build(); // should fail fail("Exception not thrown"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof IllegalArgumentException); } }
protected void disconnectToController() { if (CONTROLLER == null) { return; } try { HttpUtils.deleteHttpCall(CONTROLLER + "/server/" + KieServerInfoHandler.getRouterId() + "/?location=" + URLEncoder.encode(KieServerInfoHandler.getLocationUrl(), "UTF-8")); log.infof("KieServerRouter disconnected from controller at " + CONTROLLER); } catch (Exception e) { log.error("Error when disconnecting from controller at " + CONTROLLER, e); } }
public static void getHttpCall(String url) throws Exception { URL controllerURL = new URL(url); HttpURLConnection con = (HttpURLConnection) controllerURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty(Headers.ACCEPT_STRING, "application/json"); con.setRequestProperty(Headers.CONTENT_TYPE_STRING, "application/json"); con.setRequestProperty(Headers.AUTHORIZATION_STRING, getAuthorization()); con.setDoOutput(true); log.debugf("Sending 'GET' request to URL : %s", controllerURL); int responseCode = con.getResponseCode(); log.debugf("Response Code : %s", responseCode); if (responseCode != 200) { throw new IOException("Unsucessful response code " + responseCode); } }