Skip to content

Commit

Permalink
database write prohibition integration: mongodb, mysql
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Mar 14, 2024
1 parent 69bf48f commit 63a5ac4
Show file tree
Hide file tree
Showing 18 changed files with 1,765 additions and 20 deletions.
38 changes: 38 additions & 0 deletions .github/actions/common/database-write-prohibition/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Common operations"
description: "do something common for database-write-prohibition plugin test"
runs:
using: "composite"
steps:
- name: Set up JDK ${{ env.javaVersion }}
uses: actions/setup-java@v3
with:
java-version: ${{ env.javaVersion }}
distribution: 'adopt'
cache: maven
- name: get zookeeper from cache
uses: actions/cache@v3
with:
path: apache-zookeeper-3.6.3-bin.tar.gz
key: ${{ runner.os }}-apache-zookeeper-3.6.3
- name: run zookeeper
shell: bash
run: |
tar -zxf apache-zookeeper-3.6.3-bin.tar.gz
bash apache-zookeeper-3.6.3-bin/bin/zkServer.sh start apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg
- name: cache dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: cache agent
uses: actions/cache@v3
with:
path: sermant-agent-*/
key: ${{ runner.os }}-agent-${{ github.run_id }}
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/database-write-prohibition/common
key: ${{ runner.os }}-agent-${{ github.run_id }}
95 changes: 95 additions & 0 deletions .github/workflows/database_write_prohibition_integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: database-write-prohibition integration test
env:
sermantVersion: 1.0.0
on:
push:
pull_request:
branches:
- '*'
paths:
- 'sermant-agentcore/**'
- 'sermant-integration-tests/database-write-prohibition-test/**'
- 'sermant-plugins/sermant-database-write-prohibition/**'
- '.github/workflows/database_write_prohibition_integration_test.yml'
- '.github/actions/common/database-write-prohibition/**'
- '.github/actions/scenarios/database-write-prohibition/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
download-midwares-and-cache:
name: download midwares and cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: cache zookeeper
uses: actions/cache@v3
with:
path: apache-zookeeper-3.6.3-bin.tar.gz
key: ${{ runner.os }}-apache-zookeeper-3.6.3
restore-keys: |
${{ runner.os }}-apache-zookeeper-3.6.3
- name: download zookeeper
run: |
export ROOT_PATH=$(pwd)
bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh zk
build-agent-and-cache:
name: build agent and cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
cache: maven
- name: cache agent
uses: actions/cache@v3
with:
path: sermant-agent-*/
key: ${{ runner.os }}-agent-${{ github.run_id }}
- name: package agent
run: |
sed -i '/sermant-backend/d' pom.xml
sed -i '/sermant-integration-tests/d' pom.xml
sed -i '/sermant-injector/d' pom.xml
mvn package -DskipTests -Ptest --file pom.xml
test-for-database-write-prohibition-mongodb:
name: Test for database-write-prohibition mongodb
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
strategy:
matrix:
include:
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/database-write-prohibition
- name: database-write-prohibition-mongodb test for mongodbVersion=${{ matrix.mongodbVersion }}
uses: ./.github/actions/scenarios/database-write-prohibition/mongodb
test-for-database-write-prohibition-mysql:
name: Test for database-write-prohibition mysql
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
strategy:
matrix:
include:
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/database-write-prohibition
- name: database-write-prohibition-mysql test for mysqlVersion=${{ matrix.mysqlVersion }}
uses: ./.github/actions/scenarios/database-write-prohibition/mysql
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class DatabaseConstant {
public static final String SQL_EXCEPTION_MESSAGE_PREFIX = "Database prohibit to write";

/**
* succeed to prohibit database status code
* fail to execute database write operation status code
*/
public static final int SUCCEED_PROHIBITION_CODE = 100;
public static final String OPERATION_FAIL_CODE = "100";

/**
* failed to prohibit database status code
* succeed to execute database write operation status code
*/
public static final int FAILED_PROHIBITION_CODE = 101;
public static final String OPERATION_SUCCEED_CODE = "101";

private DatabaseConstant() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
</properties>

<dependencies>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>database-write-prohibition-common</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -63,15 +59,4 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024-2024 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.huaweicloud.sermant.database.prohibition.integration.constant;

/**
* common constant
*
* @author daizhenyu
* @since 2024-03-11
**/
public class DatabaseConstant {
/**
* fail to execute database write operation status code
*/
public static final String OPERATION_FAIL_CODE = "100";

/**
* succeed to execute database write operation status code
*/
public static final String OPERATION_SUCCEED_CODE = "101";

/**
* database table data count
*/
public static final String DATA_COUNT = "1";

/**
* line separator
*/
public static final String LINE_SEPARATOR = System.getProperty("line.separator");

private DatabaseConstant() {
}
}
Loading

0 comments on commit 63a5ac4

Please sign in to comment.