/** * Get the hostname or IP address. * * @return The hostname if available, otherwise a dotted quad address. Returns null if neither can be determined. */ public static String getHostnameOrAddress() { try { return InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException ignored) { try { return getHostAddress(); } catch (Exception e) { return null; } } } }
public String run() throws Exception { if (_brokerHost == null) { _brokerHost = NetUtil.getHostAddress(); } LOGGER.info("Executing command: " + toString()); String request = JsonUtils.objectToString(Collections.singletonMap("pql", _query)); return sendPostRequest("http://" + _brokerHost + ":" + _brokerPort + "/query", request); }
public MinionStarter(String zkAddress, String helixClusterName, Configuration config) throws Exception { _helixClusterName = helixClusterName; _config = config; _instanceId = config.getString(CommonConstants.Helix.Instance.INSTANCE_ID_KEY, CommonConstants.Minion.INSTANCE_PREFIX + NetUtil.getHostAddress() + "_" + CommonConstants.Minion.DEFAULT_HELIX_PORT); _helixManager = new ZKHelixManager(_helixClusterName, _instanceId, InstanceType.PARTICIPANT, zkAddress); _taskExecutorFactoryRegistry = new TaskExecutorFactoryRegistry(); _eventObserverFactoryRegistry = new EventObserverFactoryRegistry(); }
@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } String stateValue = _state.toLowerCase(); if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) { throw new IllegalArgumentException( "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop"); } HttpClient httpClient = new HttpClient(); HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName); url.setQuery("state", stateValue); GetMethod httpGet = new GetMethod(url.getEscapedURI()); int status = httpClient.executeMethod(httpGet); if (status != 200) { throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString()); } return true; }
public boolean execute(JsonNode node) throws IOException { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } _controllerAddress = "http://" + _controllerHost + ":" + _controllerPort; if (!_exec) { LOGGER.warn("Dry Running Command: " + toString()); LOGGER.warn("Use the -exec option to actually execute the command."); return true; } LOGGER.info("Executing command: " + toString()); String res = AbstractBaseAdminCommand .sendPostRequest(ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableCreate(), node.toString()); LOGGER.info(res); return true; }
throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress();
@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } if (!_exec) { LOGGER.warn("Dry Running Command: " + toString()); LOGGER.warn("Use the -exec option to actually execute the command."); return true; } File schemaFile = new File(_schemaFile); LOGGER.info("Executing command: " + toString()); if (!schemaFile.exists()) { throw new FileNotFoundException("file does not exist, + " + _schemaFile); } Schema schema = Schema.fromFile(schemaFile); try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) { fileUploadDownloadClient.addSchema( FileUploadDownloadClient.getUploadSchemaHttpURI(_controllerHost, Integer.parseInt(_controllerPort)), schema.getSchemaName(), schemaFile); } return true; } }
try { if (_serverHost == null) { _serverHost = NetUtil.getHostAddress();
@Override public boolean execute() throws Exception { if (_controllerAddress == null) { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } _controllerAddress = "http://" + _controllerHost + ":" + _controllerPort; } if (!_exec) { LOGGER.warn("Dry Running Command: " + toString()); LOGGER.warn("Use the -exec option to actually execute the command."); return true; } LOGGER.info("Executing command: " + toString()); Tenant t = new Tenant.TenantBuilder(_name).setRole(_role).setTotalInstances(_instanceCount) .setOfflineInstances(_offlineInstanceCount).setRealtimeInstances(_realtimeInstanceCount).build(); String res = AbstractBaseAdminCommand .sendPostRequest(ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTenantCreate(), t.toString()); LOGGER.info(res); System.out.print(res); return true; }
try { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress();
} else { String host = _helixServerConfig.getString(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST, NetUtil.getHostAddress()); int port = _helixServerConfig .getInt(CommonConstants.Helix.KEY_OF_SERVER_NETTY_PORT, CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT);
brokerHost = NetUtil.getHostAddress();
ClusterStarter(QueryComparisonConfig config) throws SocketException, UnknownHostException { _segmentName = config.getSegmentName(); _schemaFileName = config.getSchemaFileName(); _inputDataDir = config.getInputDataDir(); _segmentDirName = config.getSegmentsDir(); _localhost = NetUtil.getHostAddress(); _zkAddress = config.getZookeeperAddress(); _clusterName = config.getClusterName(); _controllerPort = config.getControllerPort(); _brokerHost = config.getBrokerHost(); _brokerPort = config.getBrokerPort(); _serverPort = config.getServerPort(); _perfUrl = config.getPerfUrl(); _startZookeeper = config.getStartZookeeper(); _tableName = config.getTableName(); _timeColumnName = config.getTimeColumnName(); _timeUnit = config.getTimeUnit(); _tableConfigFile = config.getTableConfigFile(); _enableStarTreeIndex = false; }
/** * Helper method to start a fake server that only implements Helix part. * * @throws Exception */ private void startFakeServer() throws Exception { _serverInstance = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + NetUtil.getHostAddress() + "_" + CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT; // Create server instance with the fake server state model _serverHelixManager = HelixManagerFactory .getZKHelixManager(_clusterName, _serverInstance, InstanceType.PARTICIPANT, ZkStarter.DEFAULT_ZK_STR); _serverHelixManager.getStateMachineEngine() .registerStateModelFactory(SegmentOnlineOfflineStateModelFactory.getStateModelName(), new FakeServerSegmentStateModelFactory()); _serverHelixManager.connect(); // Add Helix tag to the server _serverHelixManager.getClusterManagmentTool().addInstanceTag(_clusterName, _serverInstance, TableNameBuilder.REALTIME.tableNameWithType(TagNameUtils.DEFAULT_TENANT_NAME)); // Initialize controller leader locator ControllerLeaderLocator.create(_serverHelixManager); }