Skip to content
Permalink
Browse files
[improvement] Change manager server getServerAddr to configure STUDIO…
…_IP (#56)

* Change manager server getServerAddr to configure STUDIO_IP

* choose configure write fixed STUDIO_IP and automatically ip address

* choose configure write fixed STUDIO_IP and automatically ip address

* update manager.conf configure db.mysql default port 8306=>3306

* Change .gitignore files

Co-authored-by: 王博坤 Bokun <bokun.wang@jiduauto.com>
  • Loading branch information
wangbokun and 王博坤 Bokun committed Apr 29, 2022
1 parent 888d685 commit 0d4dc5517fe9331453047933f577b435115d307b
Showing 7 changed files with 55 additions and 16 deletions.
@@ -1,7 +1,4 @@
custom_env.sh
flink-doris-connector/dependency-reduced-pom.xml
flink-doris-connector/output/
flink-doris-connector/target/
spark-doris-connector/dependency-reduced-pom.xml
spark-doris-connector/output/
spark-doris-connector/target/
manager/**/web-resource
manager/**/target
manager/**/*.iml
.idea/
@@ -19,6 +19,11 @@
#http port
STUDIO_PORT=8080

# Manger server ip
# Default value is empty.
# If there are more ip address.You can write a fixed address
# STUDIO_IP=10.10.10.1

# The deployment depends on three data service types: mysql/h2/postgresql. MySQL is supported by default.
MB_DB_TYPE=mysql

@@ -58,4 +63,4 @@ ENCRYPT_KEY=12dfA67887iyW321
# DS_SITE_NAME=test-Doris-Manager

# The language of the current Doris manage service instance is Chinese (zh) by default, and can support zh and en
# DS_SITE_LOCALE=zh
# DS_SITE_LOCALE=zh
@@ -465,13 +465,16 @@ private boolean checkEventBeCancelled(long eventId) {
* get server address
*/
private String getServerAddr() {
String host = null;
try {
host = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new ServerException("get server ip fail");
}
String host = System.getenv(EnvironmentDefine.STUDIO_IP_ENV);
String port = System.getenv(EnvironmentDefine.STUDIO_PORT_ENV);

if (host == null || host.isEmpty()) {
try {
host = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new ServerException("get server ip fail");
}
}
return host + ":" + port;
}

@@ -62,6 +62,9 @@ private EnvironmentDefine() {
// Data storage connection port environment variable
public static final String STUDIO_PORT_ENV = "STUDIO_PORT";

// Data storage connection ip environment variable
public static final String STUDIO_IP_ENV = "STUDIO_IP";

// key used to encrypt password
public static final String ENCRYPT_KEY_ENV = "ENCRYPT_KEY";

@@ -36,6 +36,9 @@ private PropertyDefine() {
// Application port configuration item
public static final String SERVER_PORT_PROPERTY = "server.port";

// Application ip configuration item
public static final String SERVER_IP_PROPERTY = "server.ip";

// spring tomcat waiting queue length, default 100
public static final String SERVER_ACCEPT_COUNT_PROPERTY = "server.tomcat.accept-count";

@@ -0,0 +1,15 @@
package org.apache.doris.stack.util;

import sun.net.util.IPAddressUtil;

public class AddressVerification {

public static boolean IpVerification(String ipStr) {
boolean iPv4LiteralAddress = IPAddressUtil.isIPv4LiteralAddress(ipStr);
boolean iPv6LiteralAddress = IPAddressUtil.isIPv6LiteralAddress(ipStr);
if (!(iPv4LiteralAddress || iPv6LiteralAddress)) {
return false;
}
return true;
}
}
@@ -49,6 +49,8 @@ private CommonPropertyUtil() {

private static final String DB_HOST = System.getenv(EnvironmentDefine.DB_HOST_ENV);

private static final String STUDIO_IP = System.getenv(EnvironmentDefine.STUDIO_IP_ENV);

private static final String STUDIO_PORT = System.getenv(EnvironmentDefine.STUDIO_PORT_ENV);

private static final String ENCRYPT_KEY = System.getenv(EnvironmentDefine.ENCRYPT_KEY_ENV);
@@ -106,6 +108,17 @@ public static Map<String, Object> getProperties() throws ConfigItemException {
properties.put(PropertyDefine.SERVER_PORT_PROPERTY, STUDIO_PORT);
}

if (STUDIO_IP == null || STUDIO_IP.isEmpty()) {
log.debug("STUDIO_IP is empty,Manger IP will be used automatically");
} else {
AddressVerification addressVerification = new AddressVerification();
if (addressVerification.IpVerification(STUDIO_IP)) {
properties.put(PropertyDefine.SERVER_IP_PROPERTY, STUDIO_IP);
} else {
throw new ConfigItemException("config item [STUDIO_IP] is invalid");
}
}

if (ENCRYPT_KEY == null || ENCRYPT_KEY.isEmpty()) {
log.error("config item [ENCRYPT_KEY] is not set");
throw new ConfigItemException("config item [ENCRYPT_KEY] is not set");
@@ -164,8 +177,8 @@ public static Map<String, Object> getProperties() throws ConfigItemException {
}
url.append(":");
if (StringUtils.isEmpty(DB_PORT)) {
url.append("8306");
properties.put(PropertyDefine.MYSQL_PORT_PROPERTY, 8306);
url.append("3306");
properties.put(PropertyDefine.MYSQL_PORT_PROPERTY, 3306);
} else {
url.append(DB_PORT);
properties.put(PropertyDefine.MYSQL_PORT_PROPERTY, DB_PORT);

0 comments on commit 0d4dc55

Please sign in to comment.