private URI uri(final String path, final Multimap<String, String> query) { checkArgument(path.startsWith("/")); final URIBuilder builder = new URIBuilder() .setScheme("http") .setHost("helios") .setPath(path); for (final Map.Entry<String, String> q : query.entries()) { builder.addParameter(q.getKey(), q.getValue()); } builder.addParameter("user", user); try { return builder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * In the case that listening address configured as 0.0.0.0, the publish address will be determined * by the query result for the net interfaces. * * @return the publish address, or {@code null} if the param {@code address} is null. */ public static String getPublishAddress(String schema, String address) { if (address == null) { return address; } try { URI originalURI = new URI(schema + "://" + address); IpPort ipPort = NetUtils.parseIpPort(originalURI); if (ipPort == null) { LOGGER.warn("address {} not valid.", address); return null; } IpPort publishIpPort = genPublishIpPort(schema, ipPort); URIBuilder builder = new URIBuilder(originalURI); return builder.setHost(publishIpPort.getHostOrIp()).setPort(publishIpPort.getPort()).build().toString(); } catch (URISyntaxException e) { LOGGER.warn("address {} not valid.", address); return null; } }
public PathBuilder() { b = new URIBuilder(); b.setScheme("matrix"); b.setHost("dummy"); }
public CompletableFuture<ClusterStateSimpleEntity> fetchClusterMode(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_MODE_PATH); return executeCommand(FETCH_CLUSTER_MODE_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterStateSimpleEntity.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster mode", ex); return AsyncUtils.newFailedFuture(ex); } }
protected URIBuilder createUriBuilder() { Assert.notNull(host,"No host configured"); Assert.notNull(port,"No port configured"); URIBuilder builder = new URIBuilder(); builder .setScheme(DEFAULT_PROTOCOL) .setHost(host) .setPort(port); return builder; } }
public CompletableFuture<ClusterClientInfoVO> fetchClusterClientInfoAndConfig(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_CLIENT_CONFIG_PATH); return executeCommand(FETCH_CLUSTER_CLIENT_CONFIG_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterClientInfoVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster client config", ex); return AsyncUtils.newFailedFuture(ex); } }
private URIBuilder requestURIBuilder() { return new URIBuilder() .setScheme("http") .setHost(APIHost) .setPort(APIPort); }
URIBuilder builder = new URIBuilder().setScheme(scheme).setHost(host).setPort(port); builder.setPath(path); try { LOG.debug("About to issue a GET to {}", builder); HttpGet httpget = new HttpGet(builder.build()); String responseBody; responseBody = httpclient.execute(httpget, GETStringResponseHandler.getInstance());
private URIBuilder getUriBuilder() { URIBuilder builder = new URIBuilder(); builder .setScheme(DEFAULT_PROTOCOL) .setHost(host) .setPort(port); return builder; }
public CompletableFuture<ClusterServerStateVO> fetchClusterServerBasicInfo(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_SERVER_BASIC_INFO_PATH); return executeCommand(FETCH_CLUSTER_SERVER_BASIC_INFO_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterServerStateVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster sever all config and basic info", ex); return AsyncUtils.newFailedFuture(ex); } } }
public CompletableFuture<Void> setParamFlowRuleOfMachine(String app, String ip, int port, List<ParamFlowRuleEntity> rules) { if (rules == null) { return CompletableFuture.completedFuture(null); } if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { String data = JSON.toJSONString( rules.stream().map(ParamFlowRuleEntity::getRule).collect(Collectors.toList()) ); data = URLEncoder.encode(data, DEFAULT_CHARSET.name()); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(SET_PARAM_RULE_PATH) .setParameter("data", data); return executeCommand(SET_PARAM_RULE_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Push parameter flow rules to client failed: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when setting parameter flow rule", ex); return AsyncUtils.newFailedFuture(ex); } }
public CompletableFuture<Void> modifyClusterServerFlowConfig(String app, String ip, int port, ServerFlowConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(MODIFY_CLUSTER_SERVER_FLOW_CONFIG_PATH) .setParameter("data", JSON.toJSONString(config)); return executeCommand(MODIFY_CLUSTER_SERVER_FLOW_CONFIG_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server flow config: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server flow config", ex); return AsyncUtils.newFailedFuture(ex); } }
public CompletableFuture<Void> modifyClusterServerNamespaceSet(String app, String ip, int port, Set<String> set) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(MODIFY_CLUSTER_SERVER_NAMESPACE_SET_PATH) .setParameter("data", JSON.toJSONString(set)); return executeCommand(MODIFY_CLUSTER_SERVER_NAMESPACE_SET_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server NamespaceSet: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server NamespaceSet", ex); return AsyncUtils.newFailedFuture(ex); } }
public CompletableFuture<Void> modifyClusterMode(String app, String ip, int port, int mode) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(MODIFY_CLUSTER_MODE_PATH) .setParameter("mode", String.valueOf(mode)); return executeCommand(MODIFY_CLUSTER_MODE_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster mode: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster mode", ex); return AsyncUtils.newFailedFuture(ex); } }
public CompletableFuture<Void> modifyClusterClientConfig(String app, String ip, int port, ClusterClientConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(MODIFY_CLUSTER_CLIENT_CONFIG_PATH) .setParameter("data", JSON.toJSONString(config)); return executeCommand(MODIFY_CLUSTER_MODE_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster client config: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster client config", ex); return AsyncUtils.newFailedFuture(ex); } }
public String getConnectionURI(boolean includeDatabase) throws URISyntaxException { this.setSSLOptions(); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("jdbc:mysql"); uriBuilder.setHost(host); uriBuilder.setPort(port); if (database != null && includeDatabase) { uriBuilder.setPath("/" + database); } for (Map.Entry<String, String> jdbcOption : jdbcOptions.entrySet()) { uriBuilder.addParameter(jdbcOption.getKey(), jdbcOption.getValue()); } // added by d8888 2018/09/10, force JDBC to use UTF-8 to support using non-english db, table & column names uriBuilder.addParameter("characterEncoding", "UTF-8"); uriBuilder.addParameter("tinyInt1isBit", "false"); return uriBuilder.build().toString(); }
AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(GET_RULES_PATH) .setParameter("type", AUTHORITY_TYPE); try { String body = httpGetContent(uriBuilder.build().toString()); return Optional.ofNullable(body) .map(RuleUtils::parseAuthorityRule)
/** * Fetch all parameter flow rules from provided machine. * * @param app application name * @param ip machine client IP * @param port machine client port * @return all retrieved parameter flow rules * @since 0.2.1 */ public CompletableFuture<List<ParamFlowRuleEntity>> fetchParamFlowRulesOfMachine(String app, String ip, int port) { try { AssertUtil.notEmpty(app, "Bad app name"); AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); URIBuilder uriBuilder = new URIBuilder(); String commandName = GET_PARAM_RULE_PATH; uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(commandName); return executeCommand(commandName, uriBuilder.build()) .thenApply(RuleUtils::parseParamFlowRule) .thenApply(rules -> rules.stream() .map(e -> ParamFlowRuleEntity.fromAuthorityRule(app, ip, port, e)) .collect(Collectors.toList()) ); } catch (Exception e) { logger.error("Error when fetching parameter flow rules", e); return AsyncUtils.newFailedFuture(e); } }
public CompletableFuture<Void> modifyClusterServerTransportConfig(String app, String ip, int port, ServerTransportConfig config) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(MODIFY_CLUSTER_SERVER_TRANSPORT_CONFIG_PATH) .setParameter("port", config.getPort().toString()) .setParameter("idleSeconds", config.getIdleSeconds().toString()); return executeCommand(MODIFY_CLUSTER_SERVER_TRANSPORT_CONFIG_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server transport config: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server transport config", ex); return AsyncUtils.newFailedFuture(ex); } }
/** * helper function to build a valid URI. * * @param host host name. * @param port host port. * @param path extra path after host. * @param isHttp indicates if whether Http or HTTPS should be used. * @param params extra query parameters. * @return the URI built from the inputs. */ public static URI buildUri(final String host, final int port, final String path, final boolean isHttp, final Pair<String, String>... params) throws IOException { final URIBuilder builder = new URIBuilder(); builder.setScheme(isHttp ? "http" : "https").setHost(host).setPort(port); if (null != path && path.length() > 0) { builder.setPath(path); } if (params != null) { for (final Pair<String, String> pair : params) { builder.setParameter(pair.getFirst(), pair.getSecond()); } } try { return builder.build(); } catch (final URISyntaxException e) { throw new IOException(e); } }