本文整理了Java中org.apache.storm.utils.Utils.hostname()
方法的一些代码示例,展示了Utils.hostname()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.hostname()
方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:hostname
[英]Gets the storm.local.hostname value, or tries to figure out the local hostname if it is not set in the config.
[中]暴风雨来了。地方的主机名值,或者如果未在配置中设置,则尝试计算本地主机名。
代码示例来源:origin: apache/storm
@VisibleForTesting
String urlToMatchCenteredInLogPageDaemonFile(byte[] needle, Path canonicalPath, int offset, Integer port) throws UnknownHostException {
final String host = Utils.hostname();
final Path truncatedFilePath = truncatePathToLastElements(canonicalPath, 1);
Map<String, Object> parameters = new HashMap<>();
parameters.put("file", truncatedFilePath.toString());
parameters.put("start", Math.max(0, offset - (LogviewerConstant.DEFAULT_BYTES_PER_PAGE / 2) - (needle.length / -2)));
parameters.put("length", LogviewerConstant.DEFAULT_BYTES_PER_PAGE);
return UrlBuilder.build(String.format(this.scheme + "://%s:%d/api/v1/daemonlog", host, port), parameters);
}
代码示例来源:origin: apache/storm
@VisibleForTesting
String urlToMatchCenteredInLogPage(byte[] needle, Path canonicalPath, int offset, Integer port) throws UnknownHostException {
final String host = Utils.hostname();
final Path truncatedFilePath = truncatePathToLastElements(canonicalPath, 3);
Map<String, Object> parameters = new HashMap<>();
parameters.put("file", truncatedFilePath.toString());
parameters.put("start", Math.max(0, offset - (LogviewerConstant.DEFAULT_BYTES_PER_PAGE / 2) - (needle.length / -2)));
parameters.put("length", LogviewerConstant.DEFAULT_BYTES_PER_PAGE);
return UrlBuilder.build(String.format(this.scheme + "://%s:%d/api/v1/log", host, port), parameters);
}
代码示例来源:origin: apache/storm
@Override
public void report(Throwable error) {
LOG.error("Error", error);
if (Time.deltaSecs(intervalStartTime.get()) > errorIntervalSecs) {
intervalErrors.set(0);
intervalStartTime.set(Time.currentTimeSecs());
}
if (intervalErrors.incrementAndGet() <= maxPerInterval) {
try {
stormClusterState.reportError(stormId, componentId, Utils.hostname(),
workerTopologyContext.getThisWorkerPort().longValue(), error);
} catch (UnknownHostException e) {
throw Utils.wrapInRuntime(e);
}
}
}
}
代码示例来源:origin: apache/storm
String hostname = Utils.hostname();
代码示例来源:origin: apache/storm
@Test
public void testReturnsZeroMatchesForUnseenPattern() throws UnknownHostException, InvalidRequestException {
Utils prevUtils = null;
try {
Utils mockedUtil = mock(Utils.class);
prevUtils = Utils.setInstance(mockedUtil);
String pattern = "Not There";
when(mockedUtil.hostname()).thenReturn(expectedHost);
final File file = new File(String.join(File.separator, "src", "test", "resources"),
"test-worker.log.test");
Map<String, Object> expected = new HashMap<>();
expected.put("isDaemon", "no");
expected.put("searchString", pattern);
expected.put("startByteOffset", 0);
expected.put("matches", Collections.emptyList());
LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
Map<String, Object> searchResult = handler.substringSearch(file, pattern);
assertEquals(expected, searchResult);
} finally {
Utils.setInstance(prevUtils);
}
}
代码示例来源:origin: apache/storm
/**
* Send a heartbeat to local supervisor first to check if supervisor is ok for heartbeating.
*/
private void heartbeatToMasterIfLocalbeatFail(LSWorkerHeartbeat lsWorkerHeartbeat) {
if (ConfigUtils.isLocalMode(this.conf)) {
return;
}
//In distributed mode, send heartbeat directly to master if local supervisor goes down.
SupervisorWorkerHeartbeat workerHeartbeat = new SupervisorWorkerHeartbeat(lsWorkerHeartbeat.get_topology_id(),
lsWorkerHeartbeat.get_executors(),
lsWorkerHeartbeat.get_time_secs());
try (SupervisorClient client = SupervisorClient.getConfiguredClient(conf, Utils.hostname(), supervisorPort)) {
client.getClient().sendSupervisorWorkerHeartbeat(workerHeartbeat);
} catch (Exception tr1) {
//If any error/exception thrown, report directly to nimbus.
LOG.warn("Exception when send heartbeat to local supervisor", tr1.getMessage());
try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(conf)) {
nimbusClient.getClient().sendSupervisorWorkerHeartbeat(workerHeartbeat);
} catch (Exception tr2) {
//if any error/exception thrown, just ignore.
LOG.error("Exception when send heartbeat to master", tr2.getMessage());
}
}
}
代码示例来源:origin: apache/storm
@Test
public void testLogviewerLinkCentersTheMatchInThePageDaemon() throws UnknownHostException {
String expectedFname = "foobar.log";
LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
Utils prevUtils = null;
try {
Utils mockedUtil = mock(Utils.class);
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
String actualUrl = handler.urlToMatchCenteredInLogPageDaemonFile(new byte[42], new File(expectedFname).toPath(), 27526, 8888);
assertEquals("http://" + expectedHost + ":" + expectedPort + "/api/v1/daemonlog?file=" + expectedFname
+ "&start=1947&length=" + LogviewerConstant.DEFAULT_BYTES_PER_PAGE, actualUrl);
} finally {
Utils.setInstance(prevUtils);
}
}
代码示例来源:origin: apache/storm
@Test
public void testLogviewerLinkCentersTheMatchInThePage() throws UnknownHostException {
String expectedFname = "foobar.log";
LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
Utils prevUtils = null;
try {
Utils mockedUtil = mock(Utils.class);
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
String actualUrl = handler.urlToMatchCenteredInLogPage(new byte[42], new File(expectedFname).toPath(), 27526, 8888);
assertEquals("http://" + expectedHost + ":" + expectedPort + "/api/v1/log?file=" + expectedFname
+ "&start=1947&length=" + LogviewerConstant.DEFAULT_BYTES_PER_PAGE, actualUrl);
} finally {
Utils.setInstance(prevUtils);
}
}
代码示例来源:origin: apache/storm
@Test
public void testAreallySmallLogDaemonFile() throws InvalidRequestException, UnknownHostException {
Utils prevUtils = null;
try {
Utils mockedUtil = mock(Utils.class);
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
final File file = new File(String.join(File.separator, "src", "test", "resources"),
"small-worker.log.test");
Map<String, Object> expected = new HashMap<>();
expected.put("isDaemon", "yes");
expected.put("searchString", pattern);
expected.put("startByteOffset", 0);
List<Map<String, Object>> matches = new ArrayList<>();
matches.add(buildMatchData(7, "000000 ",
" 000000\n",
pattern,
"/api/v1/daemonlog?file=" + file.getName() + "&start=0&length=51200"
));
expected.put("matches", matches);
LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
Map<String, Object> searchResult = handler.substringSearchDaemonLog(file, pattern);
assertEquals(expected, searchResult);
} finally {
Utils.setInstance(prevUtils);
}
}
代码示例来源:origin: apache/storm
private Assignment getLocalAssignment(Map<String, Object> conf, IStormClusterState stormClusterState, String topologyId) {
if (!ConfigUtils.isLocalMode(conf)) {
try (SupervisorClient supervisorClient = SupervisorClient.getConfiguredClient(conf, Utils.hostname(),
supervisorPort)) {
Assignment assignment = supervisorClient.getClient().getLocalAssignmentForStorm(topologyId);
return assignment;
} catch (Throwable tr1) {
//if any error/exception thrown, fetch it from zookeeper
return stormClusterState.remoteAssignmentInfo(topologyId, null);
}
} else {
return stormClusterState.remoteAssignmentInfo(topologyId, null);
}
}
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: apache/storm
this.hostname = Utils.hostname();
} catch (UnknownHostException ignored) {
this.hostname = "";
代码示例来源:origin: apache/storm
@Test
public void testAreallySmallLogFile() throws Exception {
Utils prevUtils = null;
try {
Utils mockedUtil = mock(Utils.class);
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
final File file = new File(String.join(File.separator, "src", "test", "resources"),
"small-worker.log.test");
Map<String, Object> expected = new HashMap<>();
expected.put("isDaemon", "no");
expected.put("searchString", pattern);
expected.put("startByteOffset", 0);
List<Map<String, Object>> matches = new ArrayList<>();
matches.add(buildMatchData(7, "000000 ",
" 000000\n",
pattern,
"/api/v1/log?file=test" + encodedFileSeparator() + "resources" + encodedFileSeparator() + file.getName()
+ "&start=0&length=51200"
));
expected.put("matches", matches);
LogviewerLogSearchHandler handler = getSearchHandlerWithPort(expectedPort);
Map<String, Object> searchResult = handler.substringSearch(file, pattern);
assertEquals(expected, searchResult);
} finally {
Utils.setInstance(prevUtils);
}
}
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: apache/storm
this.hostName = Utils.hostname();
} catch (UnknownHostException e) {
throw Utils.wrapInRuntime(e);
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: apache/storm
prevUtils = Utils.setInstance(mockedUtil);
when(mockedUtil.hostname()).thenReturn(expectedHost);
代码示例来源:origin: org.apache.storm/storm-core
this.hostName = Utils.hostname();
} catch (UnknownHostException e) {
throw Utils.wrapInRuntime(e);
内容来源于网络,如有侵权,请联系作者删除!