String[] hostnameSplit = helixInstanceConfig.getHostName().split("_"); Preconditions.checkState(hostnameSplit.length >= 2); String adminPort = record.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY); String message = String.format("Admin port is missing for host: %s", helixInstanceConfig.getHostName()); LOGGER.error(message); throw new InvalidConfigException(message);
public static Instance fromInstanceConfig(InstanceConfig instanceConfig) { InstanceConfig ic = instanceConfig; String instanceName = ic.getInstanceName(); String type; if (instanceName.startsWith(CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE)) { type = CommonConstants.Helix.SERVER_INSTANCE_TYPE; } else if (instanceName.startsWith(CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE)) { type = CommonConstants.Helix.BROKER_INSTANCE_TYPE; } else { throw new RuntimeException("Unknown instance type for: " + instanceName); } Instance instance = new Instance(ic.getHostName(), ic.getPort(), type, org.apache.commons.lang.StringUtils.join(ic.getTags(), ',')); return instance; }
@GET @Path("/instances/{instanceName}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Get instance information", produces = MediaType.APPLICATION_JSON) @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 404, message = "Instance not found"), @ApiResponse(code = 500, message = "Internal error")}) public String getInstance( @ApiParam(value = "Instance name", required = true, example = "Server_a.b.com_20000 | Broker_my.broker.com_30000") @PathParam("instanceName") String instanceName) { InstanceConfig instanceConfig = pinotHelixResourceManager.getHelixInstanceConfig(instanceName); if (instanceConfig == null) { throw new ControllerApplicationException(LOGGER, "Instance " + instanceName + " not found", Response.Status.NOT_FOUND); } ObjectNode response = JsonUtils.newObjectNode(); response.put("instanceName", instanceConfig.getInstanceName()); response.put("hostName", instanceConfig.getHostName()); response.put("enabled", instanceConfig.getInstanceEnabled()); response.put("port", instanceConfig.getPort()); response.set("tags", JsonUtils.objectToJsonNode(instanceConfig.getTags())); return response.toString(); }
return QueryException.INTERNAL_ERROR.toString(); String hostNameWithPrefix = instanceConfig.getHostName(); String url = "http://" + hostNameWithPrefix.substring(hostNameWithPrefix.indexOf("_") + 1) + ":" + instanceConfig.getPort()
if (config.getHostName() == null) { config.setHostName(instanceId);
if (config.getHostName() == null) { config.setHostName(instanceId);
@Override public boolean setInstanceConfig(String clusterName, String instanceName, InstanceConfig newInstanceConfig) { logger.info("Set instance config for instance {} to cluster {} with new InstanceConfig {}.", instanceName, clusterName, newInstanceConfig == null ? "NULL" : newInstanceConfig.toString()); String instanceConfigPath = PropertyPathBuilder.getPath(PropertyType.CONFIGS, clusterName, HelixConfigScope.ConfigScopeProperty.PARTICIPANT.toString(), instanceName); if (!_zkClient.exists(instanceConfigPath)) { throw new HelixException( "instance" + instanceName + " does not exist in cluster " + clusterName); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey instanceConfigPropertyKey = accessor.keyBuilder().instanceConfig(instanceName); InstanceConfig currentInstanceConfig = accessor.getProperty(instanceConfigPropertyKey); if (!newInstanceConfig.getHostName().equals(currentInstanceConfig.getHostName()) || !newInstanceConfig.getPort().equals(currentInstanceConfig.getPort())) { throw new HelixException( "Hostname and port cannot be changed, current hostname: " + currentInstanceConfig .getHostName() + " and port: " + currentInstanceConfig.getPort() + " is different from new hostname: " + newInstanceConfig.getHostName() + "and new port: " + newInstanceConfig.getPort()); } return accessor.setProperty(instanceConfigPropertyKey, newInstanceConfig); }
@Override public boolean setInstanceConfig(String clusterName, String instanceName, InstanceConfig newInstanceConfig) { logger.info("Set instance config for instance {} to cluster {} with new InstanceConfig {}.", instanceName, clusterName, newInstanceConfig == null ? "NULL" : newInstanceConfig.toString()); String instanceConfigPath = PropertyPathBuilder.getPath(PropertyType.CONFIGS, clusterName, HelixConfigScope.ConfigScopeProperty.PARTICIPANT.toString(), instanceName); if (!_zkClient.exists(instanceConfigPath)) { throw new HelixException( "instance" + instanceName + " does not exist in cluster " + clusterName); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey instanceConfigPropertyKey = accessor.keyBuilder().instanceConfig(instanceName); InstanceConfig currentInstanceConfig = accessor.getProperty(instanceConfigPropertyKey); if (!newInstanceConfig.getHostName().equals(currentInstanceConfig.getHostName()) || !newInstanceConfig.getPort().equals(currentInstanceConfig.getPort())) { throw new HelixException( "Hostname and port cannot be changed, current hostname: " + currentInstanceConfig .getHostName() + " and port: " + currentInstanceConfig.getPort() + " is different from new hostname: " + newInstanceConfig.getHostName() + "and new port: " + newInstanceConfig.getPort()); } return accessor.setProperty(instanceConfigPropertyKey, newInstanceConfig); }
public void routeRequest(String database, String partition) { List<InstanceConfig> masters; List<InstanceConfig> slaves; masters = _routingTableProvider.getInstances(database, partition, "MASTER"); if (masters != null && !masters.isEmpty()) { System.out.println("Available masters to route request"); for (InstanceConfig config : masters) { System.out.println("HostName:" + config.getHostName() + " Port:" + config.getPort()); } } else { System.out.println("No masters available to route request"); } slaves = _routingTableProvider.getInstances(database, partition, "SLAVE"); if (slaves != null && !slaves.isEmpty()) { System.out.println("Available slaves to route request"); for (InstanceConfig config : slaves) { System.out.println("HostName:" + config.getHostName() + " Port:" + config.getPort()); } } else { System.out.println("No slaves available to route request"); } }
public void startReplication(InstanceConfig masterInstanceConfig) throws Exception { String remoteHost = masterInstanceConfig.getHostName(); String remoteChangeLogDir = masterInstanceConfig.getRecord().getSimpleField("change_log_dir"); String remoteFilestoreDir = masterInstanceConfig.getRecord().getSimpleField("file_store_dir"); String localChangeLogDir = localInstanceConfig.getRecord().getSimpleField("change_log_dir"); String localFilestoreDir = localInstanceConfig.getRecord().getSimpleField("file_store_dir"); String localcheckpointDir = localInstanceConfig.getRecord().getSimpleField("check_point_dir"); // setup rsync for the change log directory setupRsync(remoteHost, remoteChangeLogDir, localChangeLogDir); reader = new ChangeLogReader(localChangeLogDir); watchService = new FileSystemWatchService(localChangeLogDir, reader); processor = new ChangeLogProcessor(reader, remoteHost, remoteFilestoreDir, localFilestoreDir, localcheckpointDir); watchService.start(); processor.start(); isReplicationStarted.set(true); }
instancesArray = new InstanceConfig[instancesSet.size()]; instancesSet.toArray(instancesArray); AssertJUnit.assertEquals(instancesArray[0].getHostName(), "localhost"); AssertJUnit.assertEquals(instancesArray[0].getPort(), "8900"); AssertJUnit.assertEquals(instancesArray[1].getHostName(), "localhost"); AssertJUnit.assertEquals(instancesArray[1].getPort(), "8901"); } finally {