String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
/** * get the config for the AM or containers based on the containers' names. * * @return Config the config of this container */ protected Config getConfig() { Config config; try { if (isApplicationMaster) { config = JobModelManager.currentJobModelManager().jobModel().getConfig(); } else { String url = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); String response = HttpUtil.read(new URL(url), 30000, new ExponentialSleepStrategy()); config = SamzaObjectMapper.getObjectMapper().readValue(response, JobModel.class).getConfig(); } } catch (IOException e) { throw new SamzaException("can not read the config", e); } // Make system producer drop producer errors for StreamAppender config = new MapConfig(config, ImmutableMap.of(TaskConfig.DROP_PRODUCER_ERRORS(), "true")); return config; }
/** * get the config for the AM or containers based on the containers' names. * * @return Config the config of this container */ protected Config getConfig() { Config config; try { if (isApplicationMaster) { config = JobModelManager.currentJobModelManager().jobModel().getConfig(); } else { String url = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL()); String response = HttpUtil.read(new URL(url), 30000, new ExponentialSleepStrategy()); config = SamzaObjectMapper.getObjectMapper().readValue(response, JobModel.class).getConfig(); } } catch (IOException e) { throw new SamzaException("can not read the config", e); } // Make system producer drop producer errors for StreamAppender config = new MapConfig(config, ImmutableMap.of(TaskConfig.DROP_PRODUCER_ERRORS(), "true")); return config; }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }