Skip to content

Commit

Permalink
BIGTOP-4145: Improve docker development support scripts (apache#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
timyuer authored Sep 20, 2024
1 parent 74e4efb commit 103b8cf
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 894 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static <Entity> String insert(TableMetaData tableMetaData, Entity entity,
SQL sql = new SQL();
switch (DBType.toType(databaseId)) {
case MYSQL: {
sql.INSERT_INTO(tableMetaData.getTableName());
sql.INSERT_INTO(keywordsFormat(tableMetaData.getTableName(), DBType.MYSQL));
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
Expand All @@ -65,13 +65,13 @@ public static <Entity> String insert(TableMetaData tableMetaData, Entity entity,
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
if (!ObjectUtils.isEmpty(value)) {
sql.VALUES("`" + entry.getValue() + "`", getTokenParam(entry.getKey()));
sql.VALUES(keywordsFormat(entry.getValue(), DBType.MYSQL), getTokenParam(entry.getKey()));
}
}
break;
}
case POSTGRESQL: {
sql.INSERT_INTO("\"" + tableMetaData.getTableName() + "\"");
sql.INSERT_INTO(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
Expand All @@ -83,7 +83,7 @@ public static <Entity> String insert(TableMetaData tableMetaData, Entity entity,
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
if (!ObjectUtils.isEmpty(value)) {
sql.VALUES("\"" + entry.getValue() + "\"", getTokenParam(entry.getKey()));
sql.VALUES(keywordsFormat(entry.getValue(), DBType.POSTGRESQL), getTokenParam(entry.getKey()));
}
}
break;
Expand All @@ -104,7 +104,7 @@ public static <Entity> String update(TableMetaData tableMetaData, Entity entity,
SQL sql = new SQL();
switch (DBType.toType(databaseId)) {
case MYSQL: {
sql.UPDATE(tableMetaData.getTableName());
sql.UPDATE(keywordsFormat(tableMetaData.getTableName(), DBType.MYSQL));
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
Expand All @@ -116,15 +116,16 @@ public static <Entity> String update(TableMetaData tableMetaData, Entity entity,
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
if (!ObjectUtils.isEmpty(value)) {
sql.SET(getEquals(entry.getValue(), entry.getKey()));
sql.SET(getEquals(keywordsFormat(entry.getValue(), DBType.MYSQL), entry.getKey()));
}
}

sql.WHERE(getEquals(tableMetaData.getPkColumn(), tableMetaData.getPkProperty()));
sql.WHERE(getEquals(
keywordsFormat(tableMetaData.getPkColumn(), DBType.MYSQL), tableMetaData.getPkProperty()));
break;
}
case POSTGRESQL: {
sql.UPDATE("\"" + tableMetaData.getTableName() + "\"");
sql.UPDATE(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
Expand All @@ -136,10 +137,11 @@ public static <Entity> String update(TableMetaData tableMetaData, Entity entity,
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
if (!ObjectUtils.isEmpty(value)) {
sql.SET("\"" + getEquals(entry.getValue() + "\"", entry.getKey()));
sql.SET(getEquals(keywordsFormat(entry.getValue(), DBType.POSTGRESQL), entry.getKey()));
}
}
sql.WHERE(getEquals(tableMetaData.getPkColumn(), tableMetaData.getPkProperty()));
sql.WHERE(getEquals(
keywordsFormat(tableMetaData.getPkColumn(), DBType.POSTGRESQL), tableMetaData.getPkProperty()));
break;
}
default: {
Expand All @@ -166,7 +168,7 @@ public static String selectById(TableMetaData tableMetaData, String databaseId,
baseColumns = baseColumns.replace("user.", "\"user\".");
}
sql.SELECT(baseColumns);
sql.FROM("\"" + tableMetaData.getTableName() + "\"");
sql.FROM(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
sql.WHERE(tableMetaData.getPkColumn() + " = " + id);
break;
}
Expand Down Expand Up @@ -207,7 +209,7 @@ public static String selectByIds(
baseColumns = baseColumns.replace("user.", "\"user\".");
}
sql.SELECT(baseColumns);
sql.FROM("\"" + tableMetaData.getTableName() + "\"");
sql.FROM(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
sql.WHERE(tableMetaData.getPkColumn() + " in (" + idsStr + ")");
break;
}
Expand All @@ -229,7 +231,7 @@ public static String selectAll(TableMetaData tableMetaData, String databaseId) {
baseColumns = baseColumns.replace("user.", "\"user\".");
}
sql.SELECT(baseColumns);
sql.FROM("\"" + tableMetaData.getTableName() + "\"");
sql.FROM(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
break;
case MYSQL: {
sql.SELECT(tableMetaData.getBaseColumns());
Expand All @@ -253,7 +255,7 @@ public static String deleteById(TableMetaData tableMetaData, String databaseId,
break;
}
case POSTGRESQL: {
sql.FROM("\"" + tableMetaData.getTableName() + "\"");
sql.FROM(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
sql.WHERE(tableMetaData.getPkColumn() + " = " + id);
break;
}
Expand Down Expand Up @@ -286,7 +288,7 @@ public static String deleteByIds(
}
case POSTGRESQL: {
String idsStr = ids.stream().map(String::valueOf).collect(Collectors.joining(", "));
sql.DELETE_FROM("\"" + tableMetaData.getTableName() + "\"");
sql.DELETE_FROM(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));
sql.WHERE(tableMetaData.getPkColumn() + " in (" + idsStr + ")");
break;
}
Expand Down Expand Up @@ -318,8 +320,16 @@ public static <Condition> String findByCondition(
return sql.toString();
}

private static String keywordsFormat(String keyword, DBType dbType) {
return switch (dbType) {
case MYSQL -> "`" + keyword + "`";
case POSTGRESQL -> "\"" + keyword + "\"";
default -> keyword;
};
}

private static String getEquals(String column, String property) {
return "`" + column + "` = " + getTokenParam(property);
return column + " = " + getTokenParam(property);
}

private static String getTokenParam(String property) {
Expand Down
23 changes: 8 additions & 15 deletions dev-support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,31 @@ yum install -y git docker
```
### **Step 2**: Download Bigtop Manager source
```shell
git clone https://github.com/kevinw66/bigtop-manager.git
git clone https://github.com/apache/bigtop-manager.git
```
> You need to change the `node.version` in the `pom.xml` file under the `bigtop-manager-ui` module to `16.x` if you are using CentOS-7.
### **Step 3**: Enter workspace
**RHEL (Rocky 8) :**
```shell
cd bigtop-manager/dev-support/docker/rocky8/
```
### **Step 4**: Build develop basic image
### **Step 3**: Build develop basic image
Run the setup command, you will get `bigtop-manager/develop:trunk-rocky-8` image. It has the enviroment needed to compile Bigtop-Manager and run servers such as Bigtop-Manager Server, Bigtop-Manager Agent, Mysql, etc.

**RHEL (Rocky 8) :**
```shell
./build-image.sh
/bin/bash dev-support/docker/image/build.sh trunk-rocky-8
```
### **Step 5**: Build source & create cluster
### **Step 4**: Build source & create cluster
* Bigtop Manager UI、Bigtop Manager Server Debug Port、MariaDB Server are also exposed to local ports: 8080、5005、3306.
* Docker hostnames are: bigtop-manager-server、bigtop-manager-agent-01、bigtop-manager-agent-02.

**RHEL (Rocky 8) :**
```shell
./build-containers.sh
/bin/bash dev-support/docker/containers/build.sh -e postgres -c 3 -o trunk-rocky-8 [--skip-compile]
```
### **Step 6**: Insert data to Database
Copy SQL on `dev-support/example/bigtop_manager/user.sql` and run on mysql database `bigtop_manager` which is installed in container bigtop-manager-server.
### **Step 7**: Access Web UI
### **Step 5**: Access Web UI
Now you can access Web UI which exposes on `http://localhost:8080`. Log in with username `admin` and password `admin`.
### **Step 8**: Clear cluster
### **Step 6**: Clear cluster
Clean up the containers when you are done developing or testing.

**RHEL (Rocky 8) :**
```shell
./clear-containers.sh
/bin/bash dev-support/docker/containers/build.sh -d
```
32 changes: 0 additions & 32 deletions dev-support/docker/centos7/Dockerfile

This file was deleted.

111 changes: 0 additions & 111 deletions dev-support/docker/centos7/build-containers.sh

This file was deleted.

30 changes: 0 additions & 30 deletions dev-support/docker/centos7/build-image.sh

This file was deleted.

Loading

0 comments on commit 103b8cf

Please sign in to comment.