org.apache.storm.utils.Utils.localHostname()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中org.apache.storm.utils.Utils.localHostname()方法的一些代码示例,展示了Utils.localHostname()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.localHostname()方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:localHostname

Utils.localHostname介绍

暂无

代码示例

代码示例来源:origin: apache/storm

public static String memoizedLocalHostname() throws UnknownHostException {
  if (memoizedLocalHostnameString == null) {
    memoizedLocalHostnameString = localHostname();
  }
  return memoizedLocalHostnameString;
}

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
@Override
public void prepare(Map<String, Object> conf, int partitionIndex, int numPartitions) {
  this.partitionIndex = partitionIndex;
  try {
    this.host = Utils.localHostname();
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: apache/storm

public static String getBlobstoreHDFSPrincipal(Map conf) throws UnknownHostException {
    String principal = (String) conf.get(Config.BLOBSTORE_HDFS_PRINCIPAL);
    if (principal != null) {
      String[] components = principal.split("[/@]");
      if (components.length == 3 && components[1].equals(HOSTNAME_PATTERN)) {
        principal = components[0] + "/" + Utils.localHostname() + "@" + components[2];
      }
    }
    return principal;
  }
}

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
@Override
public void prepare(Map<String, Object> conf, TopologyContext topologyContext) {
  this.componentId = topologyContext.getThisComponentId();
  this.taskId = topologyContext.getThisTaskId();
  try {
    this.host = Utils.localHostname();
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: apache/storm

public static void start(Map<String, Object> stormConfig, DaemonType type) {
  try {
    hostName = dotToUnderScore(Utils.localHostname());
  } catch (UnknownHostException e) {
    LOG.warn("Unable to determine hostname while starting the metrics system. Hostname will be reported"
         + " as 'localhost'.");
  }
  LOG.info("Starting metrics reporters...");
  List<Map<String, Object>> reporterList = (List<Map<String, Object>>) stormConfig.get(Config.STORM_METRICS_REPORTERS);
  if (reporterList != null && reporterList.size() > 0) {
    for (Map<String, Object> reporterConfig : reporterList) {
      // only start those requested
      List<String> daemons = (List<String>) reporterConfig.get("daemons");
      for (String daemon : daemons) {
        if (DaemonType.valueOf(daemon.toUpperCase()) == type) {
          startReporter(stormConfig, reporterConfig);
        }
      }
    }
  }
}

代码示例来源:origin: apache/storm

@Test
public void testParameters() {
  SimpleFileNameFormat format = new SimpleFileNameFormat()
    .withName("$TIME.$HOST.$COMPONENT.$TASK.$NUM.txt")
    .withPath("/mypath")
    .withTimeFormat("yyyy-MM-dd HH:mm:ss");
  Map<String, Object> topoConf = new HashMap();
  format.prepare(null, createTopologyContext(topoConf));
  long now = System.currentTimeMillis();
  String path = format.getPath();
  String name = format.getName(1, now);
  Assert.assertEquals("/mypath", path);
  String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
  String host = null;
  try {
    host = Utils.localHostname();
  } catch (UnknownHostException e) {
    e.printStackTrace();
  }
  Assert.assertEquals(time + "." + host + ".Xcom.7.1.txt", name);
}

代码示例来源:origin: apache/storm

@Test
public void testParameters() {
  SimpleFileNameFormat format = new SimpleFileNameFormat()
    .withName("$TIME.$HOST.$PARTITION.$NUM.txt")
    .withPath("/mypath")
    .withTimeFormat("yyyy-MM-dd HH:mm:ss");
  format.prepare(null, 3, 5);
  long now = System.currentTimeMillis();
  String path = format.getPath();
  String name = format.getName(1, now);
  Assert.assertEquals("/mypath", path);
  String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
  String host = null;
  try {
    host = Utils.localHostname();
  } catch (UnknownHostException e) {
    e.printStackTrace();
  }
  Assert.assertEquals(time + "." + host + ".3.1.txt", name);
}

代码示例来源:origin: apache/storm

@Test
  public void getBlobstoreHDFSPrincipal() throws UnknownHostException {
    Map<String, Object> conf = mockMap(Config.BLOBSTORE_HDFS_PRINCIPAL, "primary/_HOST@EXAMPLE.COM");
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), "primary/" +  Utils.localHostname() + "@EXAMPLE.COM");

    String principal = "primary/_HOST_HOST@EXAMPLE.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);

    principal = "primary/_HOST2@EXAMPLE.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);

    principal = "_HOST/instance@EXAMPLE.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);

    principal = "primary/instance@_HOST.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);

    principal = "_HOST@EXAMPLE.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);

    principal = "primary/instance@EXAMPLE.COM";
    conf.put(Config.BLOBSTORE_HDFS_PRINCIPAL, principal);
    Assert.assertEquals(Config.getBlobstoreHDFSPrincipal(conf), principal);
  }
}

代码示例来源:origin: org.apache.storm/storm-core

public static String memoizedLocalHostname () throws UnknownHostException {
  if (memoizedLocalHostnameString == null) {
    memoizedLocalHostnameString = localHostname();
  }
  return memoizedLocalHostnameString;
}

代码示例来源:origin: org.apache.storm/storm-hdfs

@SuppressWarnings("unchecked")
@Override
public void prepare(Map conf, int partitionIndex, int numPartitions) {
  this.partitionIndex = partitionIndex;
  try {
    this.host = Utils.localHostname();
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.apache.storm/storm-hdfs

@SuppressWarnings("unchecked")
@Override
public void prepare(Map conf, TopologyContext topologyContext) {
  this.componentId = topologyContext.getThisComponentId();
  this.taskId = topologyContext.getThisTaskId();
  try {
    this.host = Utils.localHostname();
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.apache.storm/storm-core

public static void start(Map<String, Object> stormConfig, DaemonType type){
  try {
    hostName = dotToUnderScore(Utils.localHostname());
  } catch (UnknownHostException e) {
     LOG.warn("Unable to determine hostname while starting the metrics system. Hostname will be reported" +
         " as 'localhost'.");
  }
  LOG.info("Starting metrics reporters...");
  List<Map<String, Object>> reporterList = (List<Map<String, Object>>)stormConfig.get(Config.STORM_METRICS_REPORTERS);
  if(reporterList != null && reporterList.size() > 0) {
    for (Map<String, Object> reporterConfig : reporterList) {
      // only start those requested
      List<String> daemons = (List<String>) reporterConfig.get("daemons");
      for (String daemon : daemons) {
        if (DaemonType.valueOf(daemon.toUpperCase()) == type) {
          startReporter(stormConfig, reporterConfig);
        }
      }
    }
  }
}

相关文章

Utils类方法