diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000000..bb20b2bc7c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,10 @@ +--- +name: Bug Report +about: Report a bug encountered while operating bk-job +title: '' +labels: kind/bug +assignees: '' + +--- + + diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md new file mode 100644 index 0000000000..9a33852a12 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -0,0 +1,10 @@ +--- +name: Enhancement Request +about: Suggest an enhancement to the bk-job project +title: '' +labels: kind/enhancement +assignees: '' + +--- + + diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000000..c70f8b181e --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,47 @@ +# This is a basic workflow to help you get started with Actions + +name: Backend CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ master ] + paths: + - 'src/backend/**' + pull_request: + branches: [ master, 3.* ] + paths: + - 'src/backend/**' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - name: init mysql + run: | + sudo /etc/init.d/mysql start + export MYSQL_PWD=root + for i in */*.sql;do echo $i;mysql -h localhost -uroot < $i;done + working-directory: support-files/sql + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Gradle Build + working-directory: src/backend + run: ./gradlew clean build -DmysqlURL=127.0.0.1:3306 -DmysqlUser=root -DmysqlPasswd=root -DmavenRepoUrl="http://maven.aliyun.com/nexus/content/groups/public/" diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000000..4f92e912cb --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,27 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Frontend CI + +on: + push: + branches: [ master ] + paths: + - 'src/frontend/**' + pull_request: + branches: [ master, 3.* ] + paths: + - 'src/frontend/**' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - run: echo "npm version=$(npm -v)" + - name: build + run: | + export JOB_VERSION=3.latest + npm i && npm run build + working-directory: src/frontend diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..5fdf62417b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,80 @@ +name: Tag Realse +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build whole project and release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up variables + id: variables + run: | + tag="$(basename $GITHUB_REF)" + version=${tag##v} + echo "::set-output name=tag::${tag}" + echo "::set-output name=version::${version}" + - name: init mysql + run: | + sudo /etc/init.d/mysql start + export MYSQL_PWD=root + for i in */*.sql;do echo $i;mysql -h localhost -uroot < $i;done + working-directory: support-files/sql + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Gradle Build Backend + working-directory: src/backend + run: ./gradlew clean build -Dversion=${{ steps.variables.outputs.version }} -DmysqlURL=127.0.0.1:3306 -DmysqlUser=root -DmysqlPasswd=root -DmavenRepoUrl="http://maven.aliyun.com/nexus/content/groups/public/" + + - name: Npm Build Frontend + run: | + echo "npm version=$(npm -v)" + export JOB_VERSION=${{ steps.variables.outputs.version }} + npm i && npm run build + mkdir -p release/job/frontend + cp -r dist/* release/job/frontend + working-directory: src/frontend + + - name: Build VersionLogs + run: python genBundledVersionLog.py + working-directory: versionLogs + + - name: Create artifact - make package + id: create_artifact + run: | + echo ${{ steps.variables.outputs.version }} > ./VERSION + chmod 755 ./package.sh + ./package.sh -m all -v ${{ steps.variables.outputs.version }} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: bk-job ${{ github.ref }} + draft: true + prerelease: true + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release/job_ce-${{ steps.variables.outputs.version }}.tgz + asset_name: job_ce-${{ steps.variables.outputs.version }}.tgz + asset_content_type: application/gzip diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000..4bdf2b49ed --- /dev/null +++ b/README.en.md @@ -0,0 +1,82 @@ +![LOGO](docs/resource/img/bk-job.png) +--- +[![license](https://img.shields.io/badge/license-mit-brightgreen.svg?style=flat)](https://github.com/Tencent/bk-job/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/github/v/release/Tencent/bk-job?include_prereleases)](https://github.com/Tencent/bk-job/releases) + +English | [简体中文](README.md) + +> **Notice**: During the process of development, the 'master' branch might be in an *unstable state or unavailable state*. +Please access the stable binary file via [releases](https://github.com/tencent/bk-job/releases) instead of 'master'. + +The BK-JOB is a ops script management and execution system with the capability of dealing with multiple tasks simultaneously. In addition to script execution, file distribution, cron jobs, and other basic operation environments, it is also capable of putting together all the individual tasks into an automated workflow. All tasks, as individual nodes, can be offered to upper-level or peripheral systems/platforms, making it an automated cross-system dispatching system. + +## Benefits + +### Dependable Dangerous Command Detection Ability + +As an underlying atomic operation platform made for server OS, the verification of user command's validity and safety is of critical importance! The platform allows for regular expression detection rules for dangerous commands in various script languages, and provides a log for intercepted operations. Even when a command is made by a peripheral system via API, it'll be intercepted immediately, making the server more secure! + +### Comprehensive Script Version Management + +Cloud management of script versions, which is accordant with the modern concept of collaboration. Aided by the convenient platform and version management feature, BK-JOB users can share script resources, control the releasing status of various versions, and reduce loss if there's a security vulnerability. + +### Arrange Jobs for All Scenarios + +When an operation scenario requires multiple interconnected steps, clicking them one by one is too inefficient! Besides, it is inconvenient for later usage and maintenance. + +The task management feature offers an optimal solution. Users can set up the necessary steps on the "Job Template" before making up an "Executable Plan" as required by the scenario; As such, job templates and its instances are set apart rather than welded together, which is also beneficial to later management and maintenance. + +### The Authentic Cron Jobs + +Linux's original crontab job feature is preserved, allowing the maintenance team to access them easily. The friendly monitoring feature allows you to easily control and assess the situation of scheduled tasks. + +### Scalable File Source Management + +When it comes to file distribution, we not only use remote server and local files as source of transmission, we also need to retrieve files from different file systems/services such as object storage, FTP, and Samba. + +To meet the diversified demands, we have enabled the file source plug-in feature, which allows developers to develop plugins for the file management modules on the platform according to their own file system. As such, they can distribute files from various file systems. + + +BK-JOB provides quick execution, task arrangement, cron job, and a wide range of core services, meeting the demands of all environments: +- **Quick Execution**: Offers a temporary, versatile, quick access. +- **Task Arrangement**: Transforms repetitive operations into "jobs" using the arrangement feature to make them easy to use and manage. +- **Scheduled Execution**: Allows users to make up periodic or one-off execution plans according to the logical needs of their business. +- **Script Management**: Manage scripts in a cloud-based mode, which further facilitates job arrangement and the flexibility of peripheral system scheduling. +- **Account Management**: The execution account of that manages server OS, such as Linux root or Windows administrator, etc. +- **Notification**: Allows businesses to send notifications on the execution result for various task statuses. +- **File Source Management**: Enables file source plugins, allowing it to retrieve and transfer files from various file systems. +- **Operation Analysis**: Displays platform operation statistics, which allows the administrator to have an all-around insight into the operation of the platform. +- **Platform Management**: A versatile platform management tool whose features include, but not limited to, information modification, message channel settings, rules for detecting dangerous commands, feature limitation settings, public script management, background service status display, etc. + +## Overview + +- [Architecture Design](docs/overview/architecture.en.md) +- [Code Directory](docs/overview/code_framework.en.md) +- [Design Philosophy](docs/overview/design.en.md) + +## Features + +For more information, please check Blueking's official website [Platform Product Overview](https://bk.tencent.com/docs/document/6.0/125/5748) + +## Getting started +- [Download and Compile](docs/overview/source_compile.en.md) +- [Installation Setup](docs/overview/installation.en.md) + +## Support +1. [GitHub Community](https://github.com/Tencent/bk-job/discussions) + +## BlueKing Community +- [BK-BCS](https://github.com/Tencent/bk-bcs): Blueking Container Service is a container-based basic service platform that provides management service to microservice businesses. +- [BK-BCS-SaaS](https://github.com/Tencent/bk-bcs-saas): Blueking Container Platform SaaS is based on two modes: original Kubernetes and self-developed Mesos, offering users highly scalable, flexible container service. +- [BK-CI](https://github.com/Tencent/bk-ci): Blueking Continuous Integration platform is a free, open source CI service, which allows developers to automatically create - test - release workflow, and continuously, efficiently deliver their high-quality products. +- [BK-CMDB](https://github.com/Tencent/bk-cmdb): BlueKing CMDB is an enterprise-level management platform designed for assets and applications. +- [BK-PaaS](https://github.com/Tencent/bk-PaaS): Blueking PaaS is an open development platform that allows developers to efficiently create, develop, set up, and manage SaaS apps. +- [BK-SOPS](https://github.com/Tencent/bk-sops): Blueking SOPS is a system that features workflow arrangement and execution using a graphical interface. It's a lightweight task scheduling and arrangement SaaS product of the Blueking system. + +## Contributing +- For more information about bk-job's fork management, issue and PR rules, please check [Contributing](CONTRIBUTING.md). +- [Tencent Open Source Incentive Plan](https://opensource.tencent.com/contribution) encourages developers to engage and contribute in the community. Join us now! + + +## License +BK-JOB is based on the MIT agreement. For more information, please check [LICENSE](LICENSE.txt). + diff --git a/README.md b/README.md index 45afdbed19..1dbbac98d1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ --- [![license](https://img.shields.io/badge/license-mit-brightgreen.svg?style=flat)](https://github.com/Tencent/bk-job/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/github/v/release/Tencent/bk-job?include_prereleases)](https://github.com/Tencent/bk-job/releases) +[English](README.en.md) | 简体中文 > **重要提示**: `master` 分支在开发过程中可能处于 *不稳定或者不可用状态* 。 请通过[releases](https://github.com/tencent/bk-job/releases) 而非 `master` 去获取稳定的二进制文件。 diff --git a/UPGRADE.en.md b/UPGRADE.en.md new file mode 100644 index 0000000000..cf1b5b834a --- /dev/null +++ b/UPGRADE.en.md @@ -0,0 +1,28 @@ +## About Updates + +English | [简体中文](UPGRADE.md) + +### Version 3.3.4.x +This version is joined by a new update tool (upgrader-3.3.4.x.jar, in the same directory with other binary packages). It needs to be run before and after restarting the process of Job binary Jar file update (all microservice processes), which is twice in total for the tool, in order to transfer permission data and encrypted account data. + +**Compatibility** +It is used for updates from 3.x.x.x to 3.3.4.x or higher. It doesn't need to be executed when updating within the 3.3.4.x version (e.g. 3.3.4.0-->3.3.4.3) + +**Using the Tool** +Launch the tool with the command: `java -Dfile.encoding=utf8 -Djob.log.dir=path/to/log/dir -Dconfig.file=/path/to/config/file -jar upgrader-[x.x.x.x].jar [fromVersion] [toVersion] [executeTime]` Next, enter the specific parameters of the version update task based on the command line prompts, then run the update tool. + +/path/to/log/dir The log saving path for specified tools, mostly ${BK_HOME}/logs/job +/path/to/config/file The configuration file loaded by specific tools. The configuration file is automatically generated by the setup script. Its path is: ${BK_HOME}/etc/job/upgrader/upgrader.properties +fromVersion is the current platform version, e.g. 3.2.7.3 +toVersion is target platform version, e.g. 3.3.4.0 +executeTime is the execution time of the update task, its has BEFORE_UPDATE_JOB and AFTER_UPDATE_JOB values. If you're running this tool before the platform update, enter BEFORE_UPDATE_JOB. If its after the update, enter AFTER_UPDATE_JOB + +Example: +Before Job process update: +```shell script +/opt/java/bin/java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties -jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 BEFORE_UPDATE_JOB +``` +After Job process update: +```shell script +/opt/java/bin/java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties -jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 AFTER_UPDATE_JOB +``` diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000000..53a5fc1463 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,28 @@ +## 升级说明 + +[English](UPGRADE.en.md) | 简体中文 + +### 版本3.3.4.x +该版本增加一个升级工具(upgrader-3.3.4.x.jar,与其他二进制包在同一目录),需要在更新Job二进制Jar文件重启进程(所有微服务进程)前后用不同参数分别执行一次,工具总共执行两次,用于迁移权限数据和账号加密数据。 + +**适用范围** +适用于从3.x.x.x向3.3.4.x及以上版本升级,3.3.4.x版本内升级(如3.3.4.0-->3.3.4.3)无需执行。 + +**工具用法** +使用命令`java -Dfile.encoding=utf8 -Djob.log.dir=path/to/log/dir -Dconfig.file=/path/to/config/file -jar upgrader-[x.x.x.x].jar [fromVersion] [toVersion] [executeTime]` 启动工具,再根据命令行提示输入与具体版本升级任务相关的特定参数,运行升级工具。 + +/path/to/log/dir用于指定工具日志保存路径,通常为${BK_HOME}/logs/job +/path/to/config/file用于指定工具读取的配置文件,该配置文件由部署脚本自动渲染生成,路径为${BK_HOME}/etc/job/upgrader/upgrader.properties +fromVersion为当前作业平台版本,如3.2.7.3 +toVersion为目标作业平台版本,如3.3.4.0 +executeTime为升级任务执行的时间点,取值为BEFORE_UPDATE_JOB、AFTER_UPDATE_JOB,在更新作业平台进程前执行本工具填写BEFORE_UPDATE_JOB,更新进程后执行则填写AFTER_UPDATE_JOB + +示例: +Job进程更新前: +```shell script +/opt/java/bin/java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties -jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 BEFORE_UPDATE_JOB +``` +Job进程更新后: +```shell script +/opt/java/bin/java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties -jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 AFTER_UPDATE_JOB +``` diff --git a/docs/install/backend.en.md b/docs/install/backend.en.md new file mode 100644 index 0000000000..4cb016ea43 --- /dev/null +++ b/docs/install/backend.en.md @@ -0,0 +1,62 @@ +# Backend Microservice Setup + +English | [简体中文](backend.md) + +There are 10 microservices and 1 file source access point (job-file-worker) on bk-job's backend. The compiled products are listed below: + +|Package Name | Description | +|:---- |:----| +job-analysis-{version}.jar | Statistical Analysis Microservice Springboot.jar +job-backup-{version}.jar | Backup Management Microservice Springboot.jar +job-config-{version}.jar | Configuration Center Microservice Springboot.jar +job-crontab-{version}.jar | Scheduled Task Microservice Springboot.jar +job-execute-{version}.jar | Job Execution Microservice Springboot.jar +job-file-gateway-{version}.jar | File Gateway Microservice Springboot.jar +job-file-worker-{version}.jar | File Source Access Point Springboot.jar +job-gateway-{version}.jar | Backend Gateway Microservice Springboot.jar +job-logsvr-{version}.jar | Log Management Microservice Springboot.jar +job-manage-{version}.jar | Job Management Microservice Springboot.jar +job-ticket-{version}.jar | Ticket Management Microservice Springboot.jar + +**Process** +1. Check System Dependencies +Make sure that the basic Blueking environment has been properly configured, including PaaS, user management, ESB, CMDB, GSE, and IAM. Make sure the opened ESB interface and backend interface is working properly. + +2. Check Basic Environment +Make sure that the bk-job's component dependencies (MySQL, Redis, etc.) have been set up in the previous step. + +3. Configure and Launch Service +(1) Create a directory structure as shown below. Place the compiled products and the files under Scripts and Support-files directories in the corresponding locations. +``` +|- /data/bkee/job # Home Directory + |- support-files # Resource Files + |- backend # The program that stores backend microservices and file source access points + |- job-manage # job-manage Microservice Jar package and ops script. There are 11 directories in total, which have already been introduced above. + |- job-manage.jar # job-manage Microservice's SpringBoot.jar + |- bin + |- job-manage.sh # job-manage Microservice's ops script + |- job-xxx +``` +(2) After ensuring JAVA_HOME's environment variables have been properly configured, start all microservice processes in sequence: +Example of starting microservice: +```shell script +cd /data/bkee/job/backend/job-config/bin +./job-config.sh start +``` + +Sequence: +job-config (The configuration center is essential for other microservices. Therefore, it needs to be started first.) +job-manage +job-backup +job-logsvr +job-ticket +job-file-gateway +job-execute +job-crontab +job-gateway +job-file-worker +job-analysis +The sequence mentioned above is the optimal one recommended as per invocation relations. If you need to start all services immediately, after launching job-config, you can start other microservices and job-file-worker at the same time. Once it's completed, check the log output and process state and restart the failed processes. +When the microservice is started, log directory will be automatically created: +${BK_HOME}/logs/${PROJECT_NAME}/${SERVICE_NAME}/ +In this example, BK_HOME is /data/bkee, PROJECT_NAME is job, SERVICE_NAME is the name of the microservice. Job-file-worker doesn't count as a microservice, but the way of launching it is the same with other microservices. diff --git a/docs/install/backend.md b/docs/install/backend.md index c39cbf492f..01afa99627 100644 --- a/docs/install/backend.md +++ b/docs/install/backend.md @@ -1,4 +1,7 @@ # 后端微服务部署 + +[English](backend.en.md) | 简体中文 + bk-job后端共有10个微服务和一个文件源接入点(job-file-worker),编译产物如下表所示: |包名称 | 描述 | diff --git a/docs/overview/architecture.en.md b/docs/overview/architecture.en.md new file mode 100644 index 0000000000..06edc227c0 --- /dev/null +++ b/docs/overview/architecture.en.md @@ -0,0 +1,36 @@ +# Blueking (BK-JOB) Architecture Design + +English | [简体中文](architecture.md) + +![Architecture](../resource/img/architecture.png) + +The BlueKing Platform (aka **bk-job** ) is written in multiple languages including java/js/html/python/shell/gradle, featuring separation of frontend and backend, with highly-accessible, scalabe, service-oriented architecture: + +- **Frontend (FrontEnd):** + + Features ES6 grammar, MVVM architecture vue.js, and webpack4 package. + +- **Backend (BackEnd):** + +Written in Java, featuring microservice architecture of Spring Cloud. Here is a brief rundown on each of the microservice modules: + + - **job-config:** Configuration Center: Manages and coordinates the configuration information of all microservices. + - **job-gateway:** Microservice Gateway: In charge of authentication, traffic throttling, routing requests, etc. + - **job-manage:** Job Management Microservice: In charge of managing the resources on the platform, including script, account, job template, execution plans, notification, and general settings. + - **job-execute:** Job Execution Microservice: Serves Blueking GSE by submitting file distribution/script execution tasks, retrieving task logs, and converting task statuses. + - **job-logsvr:** Log Management Microservice: Connects to the underlying MongoDB. In charge of storing the logs generated from script execution, file distribution, and source file downloading. + - **job-crontab:** Scheduled Task Microservice. Task scheduling and management of BK-job based on the Quartz engine. + - **job-backup:** Backup Management Microservice: Imports and exports jobs in bk-job and archives job execution history on a regular basis. + - **job-analysis:** Statistical Analysis Microservice. Provides backend access to job error message on the main page and operation analysis module; dispatches timed tasks; acquires and analyzes the metadata from other microservices; generates analysis result and statistics; provides data for the operation of bk-job; improves accessibility of the platform. + - **job-ticket:** Credential Management Microservice: Provides a variety of credentials for the third party file source connected to the file gateway; stores, encrypts and decrypts credentials. + - **job-file-gateway:** File Gateway Microservice: Connects with various third party file sources via FileWorker (object-based storage, file system storage, etc.); schedules the file downloading tasks from file source; works with the execution engine to distribute files from third party file source. + - **job-file-worker:** An access point, an expandable module independent of other bk-job backend microservice; multiple instances can be set up; communicate with the file gateway to connect to various types of third party file sources; executes file downloading tasks. + +- **Resource Service (Resource):** Provides the necessary basic middleware for storage. + - **Consul:** Used as a service discovery server; You need to build a Consul Server and install Consul on the machine where bk-job microservices are deployed, and run it as Agent. + - **RabbitMQ:** Core Message Queue Service: bk-job's task execution engine uses RabbitMQ to deliver the message of task status changes. + - **MySQL:** bk-job's primary database. Uses mysql 5.7.2 to store the relational data of all microservices listed above. + - **Redis:** Core Service Cache 4.0.14: Provides host information for distributed locks and cache service. + - **MongoDB:** BK-job's log database. MongoDB 4.2.2. Used to store the log data generated from script execution/file distribution. + - **NFS:** Used to store user-uploaded local files in local file distribution scenario and store temporary files generated from job import and export. + diff --git a/docs/overview/architecture.md b/docs/overview/architecture.md index f13cd866f2..dec5082d28 100644 --- a/docs/overview/architecture.md +++ b/docs/overview/architecture.md @@ -1,5 +1,7 @@ # 蓝鲸作业平台(BK-JOB)架构设计 +[English](architecture.en.md) | 简体中文 + ![Architecture](../resource/img/architecture.png) 蓝鲸作业平台(简称**bk-job** )是基于 java/js/html/python/shell/gradle等多种语言编写实现的,采用完全前后端分离,具备高可用可扩展的服务架构设计: diff --git a/docs/overview/code_framework.en.md b/docs/overview/code_framework.en.md new file mode 100644 index 0000000000..a38bd51df9 --- /dev/null +++ b/docs/overview/code_framework.en.md @@ -0,0 +1,122 @@ +# Blueking Platform (BK-JOB)'s Code Structure + +English | [简体中文](code_framework.md) + +```shell script +|- bk-job + |- docs + |- scripts + |- src + |- backend + |- frontend + |- support-files + |- versionLogs +``` +## Project Source Code (src) +The project contains a mixture of vue/java/shell and other languages. They can be divided by function as: frontend, backend, support files, version logs, ops script. and other sub-directories. +### Frontend Code +```shell script +|- bk-job/src + |- frontend/src + |- lib # Third Party Library Source Code + |- src + |- common # Public Module + |- components # Public Interaction Components + |- css # Global CSS + |- domain + |- model # Service Model + |- service # Backend API Service + |- source # Backend API Configuration + |- variable-object # The Variable Object That Serves Frontend Logic + |- i18n # Global Internationalization + |- images # Static Images + |- router # Routing Configuration + |- store # State Management + |- utils # Public Method + |- views # System Module + |- account-manage # Account Management + |- index.vue # Module Entrance + |- local.js # Module Internationalization + |- routes.js # Module Routing Table Configuration + |- cron-job # Scheduled Task + |- detect-records # Dangerous Rule Interception Record + |- dashboard # Operation Analysis + |- detect-records # Dangerous Command Interception Record + |- executive-history # Task Execution History + |- fast-execution # Quick Execution + |- file-manage # File Management + |- home # Service Overview + |- notify-manage # Notification + |- plan-manage # Execution Plan Management + |- public-script-manage # Public Script Management + |- script-manage # Script Management + |- script-template # Script Template + |- service-state # Service Status + |- setting # Global Settings + |- task-manage # Job Management + |- ticket-manage # Credential Management + |- white-ip # IP White List + |- 404.vue # Routing 404 Page + |- business-permission.vue # No Service Permission Page + |- index.vue # System Module Entrance File + |- App.vue # Page Render Entrance + |- iframe-app.vue # Rendering Entrance when Accessing via iframe + |- layout-new.vue # Navigation Layout + |- main.js # Frontend Entrance File + |- index-dev.html # Local Dev Service Entrance + |- index.html # Build Service Entrance + |- webpack.config.js # Webpack Config +``` + +### Backend Microservice Code (Backend) +```shell script +|- bk-job/src + |- backend + |- buildSrc # Custom Gradle Task that enables special features when packaging. + |- commons # Public Module + |- cmdb-sdk # Refers to the public code of Blueking Management Platform (CMDB) + |- cmdb-sdk-ext # Adds Redis throttling to CMDB-SDK. + |- common # Universal constants, errors, and other public codes + |- common-i18n # Internationalization + |- common-iam # Connects to Blueking permission center. + |- common-redis # Redis operations + |- common-security # Security control + |- common-spring-ext # General Spring expansion (custom listener, processor, etc.) + |- common-statistics # General Statistics + |- common-utils # General Tools + |- common-web # Web tools (filter, interceptor, etc.) + |- esb-sdk # Connects to Blueking ESB + |- gse-sdk # Connects to Blueking GSE + |- paas-sdk # Connects to Blueking PaaS Platform + |- job-analysis # Statistical Analysis Microservice + |- api-job-analysis # API Difinition Abstraction Layer + |- boot-job-analysis # Launching and Other Configurations + |- model-job-analysis # Table Structure Models Automatically Generated by JOOQ + |- service-job-analysis # Service Logic Implementation Layer + |- job-backup # Backup Management Microservice + |- job-config # Configuration Center Microservice + |- job-crontab # Scheduled Task Microservice + |- job-execute # Job Execution Microservice + |- job-file-gateway # File Gateway Microservice + |- job-file-worker # Realization of Access Points + |- job-file-worker-sdk # Access Points’ Common Logic SDK + |- job-gateway # Microservice Gateway + |- job-logsvr # Log Management Microservice + |- job-manage # Job Management Microservice + |- job-ticket # Ticket Management Microservice + |- upgrader # Upgrade Facility Tools +``` + +### Support Files (support-files) +```shell script +|- bk-job/support-files + |- bkiam # Migration File of Permission Changes + |- sql # Migration File of Records MySQL Database Changes + |- templates # Configuration templates that will be replaced with environment variables when storing microservices. +``` + +### Version Logs (versionLogs) +Stores version logs in both Chinese and English, as well as scripts generated by frontend resources. + +### Ops Script (scripts) +Stores the ops scripts of the launch/shut down/restart of various microservices on the backend. diff --git a/docs/overview/code_framework.md b/docs/overview/code_framework.md index a43a8695cf..13a1ac9b67 100644 --- a/docs/overview/code_framework.md +++ b/docs/overview/code_framework.md @@ -1,4 +1,7 @@ # 蓝鲸作业平台(BK-JOB)的代码结构 + +[English](code_framework.en.md) | 简体中文 + ```shell script |- bk-job |- docs diff --git a/docs/overview/design.en.md b/docs/overview/design.en.md new file mode 100644 index 0000000000..55279db38f --- /dev/null +++ b/docs/overview/design.en.md @@ -0,0 +1,9 @@ +# BK-JOB Design Philosophy + +English | [简体中文](design.md) + +- Batch Execution: Dispatch multiple scripts or files simultaneously on multiple devices. +- Security Control: Verify and intercept operators' permission and script's security level. +- Reuse Resources: Abstract scripts, tasks, objectives, and other common resources for future resuse. +- Upper-level Application: Provide environmental services such as upper level records, indexing, statistical analysis, and process arrangement based on the execution content. +- Flexibility: The file source management uses scalable architecture. Allows users to access multiple heterogeneous data sources via the access point. diff --git a/docs/overview/design.md b/docs/overview/design.md index dcc1a9f355..4da470e6fa 100644 --- a/docs/overview/design.md +++ b/docs/overview/design.md @@ -1,4 +1,7 @@ # BK-JOB的设计理念 + +[English](design.en.md) | 简体中文 + - 批量执行:满足多业务、多主机、高并发完成脚本/文件分发任务 - 安全管控:对执行者权限、脚本本身安全性进行有效检查与拦截 - 资源复用:对脚本、作业、执行目标等通用资源进行抽象,提供复用途径 diff --git a/docs/overview/installation.en.md b/docs/overview/installation.en.md new file mode 100644 index 0000000000..1f9ce92c0f --- /dev/null +++ b/docs/overview/installation.en.md @@ -0,0 +1,138 @@ +# Installation Setup + +English | [简体中文](installation.md) + +## 1. About Setup Directory + +The directory should conform to Blueking rules of operation. We're taking /data/bkee as the primary directory. Users can feel free to change them. The details are shown as follows: + +``` +|- /data/bkee # Blueking Root Directory + |- job # job Setup Program Directory + |- etc # Blueking Config File Catalog + |- job # job Config File Menu +``` + +Detailed explanation of the following chapters: + +### 1.1 job Setup Directory + +``` +|- /data/bkee/job # Home Directory + |- frontend # Static Resource Directory for Frontend Programs + |- index.html # Frontend Home Page File + |- __init__ # Initialization File Directory + |- js # Static JS Directory + |- static # Other Static File Directory + |- support-files # Resource Files + |- backend # The program that stores backend microservices and file source access points + |- job-manage # job-manage Microservice Jar package and ops script. There are 11 directories in total, which have already been introduced above. + |- job-manage.jar # job-manage Microservice's SpringBoot.jar + |- bin + |- job-manage.sh # job-manage Microservice's ops script + |- job-xxx +``` + +### 1.2 job Config File Directory + +``` +|- /data/bkee/etc # Blueking Config File Catalog + |- job # job Config File Menu + |- job.env # Specified environment variables when rendering job configuration files through template + |- application-manage.yml # job-manage's basic configuration. Each microservice has 1 yaml file. If there are new microservices, please put them here. + |- job-manage # job-manage's extended configuration. Each microservice has 1 corresponding directory for the extended configuration files. If there are new microservices, new directories should be added accordingly. + |- job-manage.properties # job-manage Extended configuration properties file +``` + +## 2. Basic Environment Setup + +### 2.1 System Requirement + +- CentOS 7.X +- jdk: 1.8 +- gradle: 6.3 +- redis: 4.0.14 +- mysql 5.7 +- rabbitmq: 3.7.14 +- mongoDB: 4.2.2 +- nginx: 1.16.1 +- Consul: 1.0+ + +### 2.2 Database Initialization + +Run the files under support-files/sql/* by the file sequence. + + +## 3 Program Setup + +### 3.1 support-files/template Initialize configuration file + +The underlined variables in the configuration file should be replaced with real data (e.g. MySQL account and password.) When the placement is made, the configuration file should be moved to the correct file directory to be read by the Configuration Center Microservice. + +### 3.2 Backend Microservice Setup + +- [Backend Service Setup] (../install/backend.md) + +### 3.3 Frontend Setup + +First, place all compiled static frontend files under the correct frontend directory. Refer to chapter 1.1 - Directory Setup. +Second, replace the variables of index.html in the frontend setup directory: +Location: /data/bkee/job/frontend/index.html +Change {{JOB_API_GATEWAY_URL}} into backend job API address (usually an independent API domain.) +And that's all the preparations for frontend setup. Later, you can set Nginx as frontend static service. + +### 3.4 Nginx Configuration and Setup +Job uses Nginx as the frontend static resource server, and forwards backend requests to the job-gateway microservice. The configuration is listed as follows: +```shell script +# Server Configuration of Frontend Static Resources +server { + listen 80; + server_name {{JOB_FRONTEND_HOST}}; + + gzip on; + client_max_body_size 150M; + root /data/bkee/job/frontend; + index index.html; + + location / { + add_header Cache-Control no-cache; + expires 0; + try_files $uri $uri/ @rewrites; + } + + location @rewrites { + rewrite ^(.+)$ /index.html last; + } +} +# Backend API Forwards Server Configuration +upstream job_gateway_servers { + server {{JOB_GATEWAY_IP0}}:19802; + server {{JOB_GATEWAY_IP1}}:19802; +} +server { + listen 80; + server_name {{JOB_API_HOST}}; + location / { + proxy_pass http://job_gateway_servers; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + } + access_log /data/bkee/logs/nginx-access.log json_combined; + client_max_body_size 2048M; + error_log /data/bkee/logs/nginx-error.log; + error_page 404 403 500 502 503 504 /job_error.html; + location = /job_error.html { + root /data/html; + } +} +``` +When the configuration is completed, reload nginx to make the settings effective: +```shell script +nginx -s reload -c /path/to/nginx.conf +``` + +### 3.5 Access Job's Home Page +Access Job's home page via {{JOB_FRONTEND_HOST}} to use Job features. diff --git a/docs/overview/installation.md b/docs/overview/installation.md index 5949eda831..e6e57a5dca 100644 --- a/docs/overview/installation.md +++ b/docs/overview/installation.md @@ -1,5 +1,7 @@ # 安装部署 +[English](installation.en.md) | 简体中文 + ## 1. 部署目录说明 部署的目录遵循蓝鲸运营规范,这里举例以/data/bkee 作为主目录,用户可以自行更换,具体如下: @@ -36,7 +38,7 @@ ``` |- /data/bkee/etc # 蓝鲸配置文件总目录 |- job # job配置文件目录 - |- api.cert # job调用GSE接口使用的证书文件 + |- job.env # 通过模板渲染job配置文件时所需要指定的环境变量 |- application-manage.yml # job-manage的基础配置,每个微服务各有1个基础配置yaml文件,如有增加微服务也放此处 |- job-manage # job-manage的扩展配置,每个微服务各有1个对应目录存放扩展配置文件,如有增加微服务须增加对应目录 |- job-manage.properties # job-manage扩展配置properties文件 diff --git a/docs/overview/source_compile.en.md b/docs/overview/source_compile.en.md new file mode 100644 index 0000000000..4420404907 --- /dev/null +++ b/docs/overview/source_compile.en.md @@ -0,0 +1,77 @@ +# bk-job About Compiling + +English | [简体中文](source_compile.md) + +### Compiling Frontend Code + +## System Requirement + +nodejs 6.9.0 or higher +npm 6.0.0 or higher + +## About Installation + +- 1. Package the vue project +Go to the src/frontend directory +``` +# Install the dependent package +npm i +``` + +``` +# Local Development +npm run dev +``` + +``` +# Setup build +npm run build +``` + +## Backend Microservice Compiling (Java) + +## System Requirement + +- MySQL 5.7 +- JDK 1.8 +- Gradle 6.3 + +#### Initialize Database + +When compiling PO, JOOQ is used for DB table and PO mapping, which is dependent on the database table. Therefore, database needs to be initialized first. Initialization script can be found in bk-job/support-files/sql. Please log into the database and execute in sequence. + +#### gradle Pre-compiling Config +gradle.properties Change the following configuration items: + + ``` + MAVEN_REPO_URL=Change it into your private Maven library, if there's any. If not, use the public source. + MAVEN_REPO_SNAPSHOT_URL=Change it into your snapshoot Maven library, if there's any. If not, use the public source. + MAVEN_REPO_DEPLOY_URL= If you need to deploy your Jar package to your private Maven library, set it as your address. + MAVEN_REPO_USERNAME=Needs to be filled out when deployed. + MAVEN_REPO_PASSWORD=Needs to be filled out when deployed. + DB_HOST=Your database. When compiling, JOOQ needs to connect to the database and access the database table to create PO compiling. + DB_USERNAME=Username of the database + DB_PASSWORD=Password of the database + ``` + +#### Compiling + +```shell +cd bk-job/src/backend & gradle clean build +``` + +All created products are placed in backend/release. The detailed content is listed below: + +|Package Name | Description | +|:---- |:----| +job-analysis-{version}.jar | Statistical Analysis Microservice Springboot.jar +job-backup-{version}.jar | Backup Management Microservice Springboot.jar +job-config-{version}.jar | Configuration Center Microservice Springboot.jar +job-crontab-{version}.jar | Scheduled Task Microservice Springboot.jar +job-execute-{version}.jar | Job Execution Microservice Springboot.jar +job-file-gateway-{version}.jar | File Gateway Microservice Springboot.jar +job-file-worker-{version}.jar | File Source Access Point Springboot.jar +job-gateway-{version}.jar | Backend Gateway Microservice Springboot.jar +job-logsvr-{version}.jar | Log Management Microservice Springboot.jar +job-manage-{version}.jar | Job Management Microservice Springboot.jar +job-ticket-{version}.jar | Ticket Management Microservice Springboot.jar diff --git a/docs/overview/source_compile.md b/docs/overview/source_compile.md index 5ca693ab88..1c1f21e34b 100644 --- a/docs/overview/source_compile.md +++ b/docs/overview/source_compile.md @@ -1,4 +1,7 @@ # bk-job 编译说明 + +[English](source_compile.en.md) | 简体中文 + ## Frontend前端代码编译 ## 系统要求 diff --git a/docs/specification/commit-spec.en.md b/docs/specification/commit-spec.en.md new file mode 100644 index 0000000000..cb7b43dea2 --- /dev/null +++ b/docs/specification/commit-spec.en.md @@ -0,0 +1,59 @@ +# Code Commit Convention + +English | [简体中文](commit-spec.md) + +## Code Review Recommendation +The BK-JOB project refers to multiple languages (JavaScript/Java/Python). By default, our dev team uses the following tool for code review. In order to improve the efficiency of Merge, please do a self-check before submission. +- ESLint +- Based on IntelliJ Idea's default coding style, set Continuation indent to 4. Set other parameters to default. + + +## Commit Formats + +Commit message convention for personal fork + +``` +type:messsge issue +``` + +* type: range info + * feature: new feature + * fix: bug fixes + * docs: file changes + * style: (format, without semicolon, etc.; no changes to codes) + * refactor: code reconstruction + * test: Adds missing tests; reconstruction test; no changes to codes + * chore: Codes related to script or task creation. +* message: Description of the commit +* issue: The issue id of the commit + +## Merge Request/Pull Request Suggestions + +The developers might have some commit message on their forks. It is recommended to simplify commit with Git Rebase before submitting Merge Requests. For more information on simplification, please check +the previous chapter. The detailed process is listed below: + +```shell +# Developing with a new fork +git checkout feature1-pick +#Multiple debugging and commits +git commit -m "xxx" +git commit -m "yyy" +git commit -m "zzz" +# When introducing a third party app, use DEP to manage it. +dep ensure -v -add github.com/org/project + +# Rebase and merge multiple changes (up to 3 times), under the feature1-pick fork. +# Fill in the standard commit message again. +git rebase -i HEAD~3 + +# Push to the far end of the storage +git push origin feature1-pick:feature1-pick + +# Submit PR/MR and wait for the merge +#...................... +#...................... + +# After PR/MR merge, follow it with the local master fork +git fetch upstream +git rebase upstream/master +``` diff --git a/docs/specification/commit-spec.md b/docs/specification/commit-spec.md index 222464b96f..2a1d4e39ae 100644 --- a/docs/specification/commit-spec.md +++ b/docs/specification/commit-spec.md @@ -1,5 +1,7 @@ # 代码提交规范 +[English](commit-spec.en.md) | 简体中文 + ## 代码检查建议 BK-JOB工程一共涉及 JavaScript/Java/Python 等多种语言,我们开发团队默认使用如下工具进行代码检查,为了提高Merge效率,请提交前自行检测。 - ESLint diff --git a/docs/specification/review.en.md b/docs/specification/review.en.md new file mode 100644 index 0000000000..9962770f86 --- /dev/null +++ b/docs/specification/review.en.md @@ -0,0 +1,51 @@ +# Reviewing for BK-JOB + +English | [简体中文](review.md) + +We believe in the value of code review: It not only improves the quality and readability of codes, but also improves developers' professional competence and coding ability, +encouraging them to make better designs. + +Here are Blueking Team's review issues and guides on PRs/MRs. + +- [Welcome PRs/MRs](#Welcome PRs/MRs) +- [Code Reviewer](#Code Reviewer) +- [Details](#Details) + - [Owned PR](#Owned PR/MR) +- [Merge](#Merge) + +## Welcome PRs/MRs + +Most importantly: If you have any questions or feedbacks, please let us know immediately. + +Before making any commits, please check [commit-spec](./commit-spec.md) + +## Code Reviewer + +Although code review can slightly delay features and issue resolving, it also causes extra work for review. Therefore, Team Blueking hopes that the participants are active reviewers too, +that the reviewers have expertise in specific areas so that the efficiency can be improved. + +## Details of Code Review + +When PR/MR is submitted, the reviewers need to classify PR/MR, such as closing the repetitive ones, discerning and labeling simple user errors. +Confirm which reviewers with professional knowledge should be in charge of reviewing this PR/MR. + +If the PR/MR is rejected, the reviewer needs to provide the initiator with detailed feedback and an explanation of its closure. + +During the reviewing process, the initiator of PR/MR should actively answer the reviewer's questions and make comments on them. If necessary, it is recommended to make changes to the submitted content. + +On workdays, the reviewer is supposed to deal with the PR/MR issues at once. On non-working days, there will be a delay in the handling of the issues. + +### Owner of PR/MR + +Participants can't be dealing with requests all the time. If an issue cannot be dealt with on time, it is recommended to give your feedback in the discussion section of PR/MR. +As the initiatior of PR/MR, the right approach is to negotiate with the reviewer and make a reasonable deadline, or discuss with other reviewers +about the transfer of PR/MR. + +## Merge + +PR/MR will be merged in the following situations: + +* The reviewer doesn't raise any objections or opinions on rectification. +* All objections or change suggestions have been dealt with. +* At least one fork maintainer supports merging. +* There are relevant files and tests. diff --git a/docs/specification/review.md b/docs/specification/review.md index fc6d616376..309b053be7 100644 --- a/docs/specification/review.md +++ b/docs/specification/review.md @@ -1,5 +1,7 @@ # Reviewing for BK-JOB +[English](review.en.md) | 简体中文 + 我们坚信code review所带来的价值:code review不仅可以提高质量、代码的可读性,同时也能不断提高开发者的水平, 促进开发者的编码能力,做出更好的设计。 diff --git a/package.sh b/package.sh index 0c61277231..0a7f4d8091 100644 --- a/package.sh +++ b/package.sh @@ -4,11 +4,12 @@ echo 'Begin to package job' BACKEND_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-ticket job-file-worker job-analysis) FRONTEND_MODULES=(job-frontend) ALL_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-ticket job-file-worker job-analysis job-frontend) +JOB_EDITION=ce if [[ ! -d "release" ]]; then - mkdir release + mkdir release else - rm -rf release/* + rm -rf release/* fi usage () { @@ -17,6 +18,7 @@ usage () { $PROGRAM [ -h --help -? 查看帮助 ] [ -m, --module [必选] "子模块(${PROJECTS[*]}), 逗号分隔。ALL表示全部都更新" ] [ -v, --version [必选] "Job版本" ] + [ -e, --edition [非必选] "Job出包类型,ce表示社区版,ee表示企业版,默认ce" ] EOF } @@ -51,6 +53,10 @@ while (( $# > 0 )); do shift JOB_VERSION="$1" ;; + -e | --edition ) + shift + JOB_EDITION="$1" + ;; --help | -h | '-?' ) usage_and_exit 0 ;; @@ -79,65 +85,137 @@ fi function packageJarAndScript() { - backend_module="$1" - log "Packaging $backend_module ..." - if [[ ! -d "release" ]]; then - mkdir release - fi - - mkdir -p release/job/backend/${backend_module}/bin - - cp src/backend/release/${backend_module}-${JOB_VERSION}.jar release/job/backend/${backend_module}/${backend_module}.jar - cp scripts/${backend_module}/${backend_module}.sh release/job/backend/${backend_module}/bin/ - chmod 755 release/job/backend/${backend_module}/bin/${backend_module}.sh - echo "Package ${backend_module} successfully" + backend_module="$1" + log "Packaging $backend_module ..." + if [[ ! -d "release" ]]; then + mkdir release + fi + + mkdir -p release/job/backend/${backend_module}/bin + + cp src/backend/release/${backend_module}-${JOB_VERSION}.jar release/job/backend/${backend_module}/${backend_module}.jar + cp scripts/${backend_module}/${backend_module}.sh release/job/backend/${backend_module}/bin/ + chmod 755 release/job/backend/${backend_module}/bin/${backend_module}.sh + echo "Package ${backend_module} successfully" } # Package the back-end jar file and the corresponding execution script for m in "${PACKAGE_MODULES[@]}"; do - for BACKEND_MODULE in ${BACKEND_MODULES[@]} - do - [ "$BACKEND_MODULE" == "$m" ] && packageJarAndScript $m - done - # Package Upgrader - if [[ ! -d "release/job/backend" ]]; then - mkdir -p release/job/backend + for BACKEND_MODULE in ${BACKEND_MODULES[@]} + do + [ "$BACKEND_MODULE" == "$m" ] && packageJarAndScript $m + done + # Package Upgrader + if [[ ! -d "release/job/backend" ]]; then + mkdir -p release/job/backend + fi + if [[ -f "src/backend/release/upgrader-${JOB_VERSION}.jar" ]]; then + cp src/backend/release/upgrader-${JOB_VERSION}.jar release/job/backend/upgrader-${JOB_VERSION}.jar fi - cp src/backend/release/upgrader-${JOB_VERSION}.jar release/job/backend/upgrader-${JOB_VERSION}.jar done # Package versionLogs if [ ! -d "src/frontend/release/job/frontend/static" ] then - mkdir -p src/frontend/release/job/frontend/static + mkdir -p src/frontend/release/job/frontend/static fi if [ ! -d "release/job/frontend/static" ] then - mkdir -p release/job/frontend/static + mkdir -p release/job/frontend/static fi cp versionLogs/bundledVersionLog*.json release/job/frontend/static if [ ! -d "src/frontend/dist/*" ] then - mkdir -p src/frontend/dist/_init_ + mkdir -p src/frontend/dist/_init_ fi # Package front-end static files for m in "${PACKAGE_MODULES[@]}"; do - for FRONTEND_MODULE in ${FRONTEND_MODULES[@]} - do - if [[ "$FRONTEND_MODULE" == "$m" ]]; then - log "Packaging $m ..." - mkdir -p release/job/frontend - cp -r src/frontend/dist/* release/job/frontend/ - echo "Package frontend successfully" - fi - done + for FRONTEND_MODULE in ${FRONTEND_MODULES[@]} + do + if [[ "$FRONTEND_MODULE" == "$m" ]]; then + log "Packaging $m ..." + mkdir -p release/job/frontend + cp -r src/frontend/dist/* release/job/frontend/ + echo "Package frontend successfully" + fi + done done - # Package support-files log "Packaging support-files ..." -cp -r support-files/ release/job/ +if [[ ! -d "release/job/support-files" ]]; then + mkdir -p release/job/support-files +fi +cp -r support-files/bkiam/ release/job/support-files/ +cp -r support-files/dependJarInfo/ release/job/support-files/ +# Package dependJarLists +if [[ -d "support-files/dependJarLists/" ]]; then + cp -r support-files/dependJarLists/ release/job/support-files/ +fi +# Package SQL by modules +if [[ ! -d "release/job/support-files/sql" ]]; then + mkdir -p release/job/support-files/sql +fi +for m in "${PACKAGE_MODULES[@]}"; do + if [[ -d "support-files/sql/${m}" ]]; then + cp -r "support-files/sql/${m}/" release/job/support-files/sql/ + fi +done +# Package Templates by modules +if [[ -d "support-files/templates" ]]; then + if [[ ! -d "release/job/support-files/templates" ]]; then + mkdir -p release/job/support-files/templates + fi + for m in "${PACKAGE_MODULES[@]}"; do + if [[ "job-frontend" == "${m}" ]]; then + continue + fi + simpleName=${m:4} + # Copy yml templates + ymlFilePath="support-files/templates/#etc#job#application-${simpleName}.yml" + if [[ -f "${ymlFilePath}" ]]; then + cp "${ymlFilePath}" release/job/support-files/templates + else + if [[ "${simpleName}" != "config" && "${simpleName}" != "file-worker" ]];then + echo "cannot find yml template of job-${simpleName}" + exit 1 + fi + fi + # Copy properties templates + propertiesFilePath="support-files/templates/#etc#job#job-${simpleName}#job-${simpleName}.properties" + if [[ -f "${propertiesFilePath}" ]]; then + cp "${propertiesFilePath}" release/job/support-files/templates + else + if [[ "${simpleName}" != "config" && "${simpleName}" != "file-worker" ]];then + echo "cannot find properties template of job-${simpleName}" + exit 1 + fi + fi + done + # Copy upgrader.properties + upgraderPropertiesFile="support-files/templates/#etc#job#upgrader#upgrader.properties" + if [[ -f "${upgraderPropertiesFile}" ]]; then + cp "${upgraderPropertiesFile}" release/job/support-files/templates + else + echo "warn: cannot find ${upgraderPropertiesFile}, ignore" + fi + # Copy job.env + jobEnvFile="support-files/templates/job.env" + if [[ -f "${jobEnvFile}" ]]; then + cp "${jobEnvFile}" release/job/support-files/templates + else + echo "warn: cannot find ${jobEnvFile}, ignore" + fi +fi +# readme.md、requirements.txt +for fileName in "readme.md" "requirements.txt"; +do +filePath="support-files/${fileName}" +if [[ -f "${filePath}" ]]; then + cp "${filePath}" release/job/support-files/ +fi +done echo "Package support-files successfully" # Package project documents @@ -145,12 +223,20 @@ log "Packaging project doc ..." cp README.md release/job/ cp projects.yaml release/job/ cp release.md release/job/ +cp UPGRADE.md release/job/ cp VERSION release/job/ cp -r docs/ release/job/ echo "Package project doc successfully" cd release -tar -czf "job_ee-${JOB_VERSION}.tgz" job -log "Package job successfully! File: job_ee-${JOB_VERSION}.tgz" +# 企业版、社区版包名称差异处理 +if [[ "${JOB_EDITION}" == "ee" ]];then + tar -czf "job_ee-${JOB_VERSION}.tgz" job + log "Package job successfully! File: job_ee-${JOB_VERSION}.tgz" +else + tar -czf "job_ce-${JOB_VERSION}.tgz" job + log "Package job successfully! File: job_ce-${JOB_VERSION}.tgz" +fi + set +e diff --git a/package_ce.sh b/package_ce.sh deleted file mode 100644 index 713b95966d..0000000000 --- a/package_ce.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash -set -e -echo 'Begin to package job' -BACKEND_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-ticket job-file-worker job-analysis) -FRONTEND_MODULES=(job-frontend) -ALL_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-ticket job-file-worker job-analysis job-frontend) - -if [[ ! -d "release" ]]; then - mkdir release -else - rm -rf release/* -fi - -usage () { - cat <&2 - usage_and_exit 1 -} - -warning () { - echo "$@" 1>&2 - EXITCODE=$((EXITCODE + 1)) -} - -# 解析命令行参数,长短混合模式 -(( $# == 0 )) && usage_and_exit 1 -while (( $# > 0 )); do - case "$1" in - -m | --module ) - shift - JOB_MODULES="$1" - ;; - -v | --version ) - shift - JOB_VERSION="$1" - ;; - --help | -h | '-?' ) - usage_and_exit 0 - ;; - -*) - error "不可识别的参数: $1" - ;; - *) - break - ;; - esac - shift -done - -JOB_MODULES=${JOB_MODULES,,} # to lower case -# 判断参数 -if [[ -z $JOB_MODULES ]] || ! [[ $JOB_MODULES =~ ^[A-Za-z,-]+$ ]]; then - warning "-m, --module必须指定要更新的模块名, 逗号分隔: 如job-config,job-logsvr" -fi - -# 解析需要更新的模块,如果是all/ALL,则包含所有模块 -if [[ $JOB_MODULES = all ]]; then - PACKAGE_MODULES=("${ALL_MODULES[@]}") -else - IFS=, read -ra PACKAGE_MODULES <<<"$JOB_MODULES" -fi - -function packageJarAndScript() -{ - backend_module="$1" - log "Packaging $backend_module ..." - if [[ ! -d "release" ]]; then - mkdir release - fi - - mkdir -p release/job/backend/${backend_module}/bin - - cp src/backend/release/${backend_module}-${JOB_VERSION}.jar release/job/backend/${backend_module}/${backend_module}.jar - cp scripts/${backend_module}/${backend_module}.sh release/job/backend/${backend_module}/bin/ - chmod 755 release/job/backend/${backend_module}/bin/${backend_module}.sh - echo "Package ${backend_module} successfully" -} - -# Package the back-end jar file and the corresponding execution script -for m in "${PACKAGE_MODULES[@]}"; do - for BACKEND_MODULE in ${BACKEND_MODULES[@]} - do - [ "$BACKEND_MODULE" == "$m" ] && packageJarAndScript $m - done - # Package Upgrader - cp src/backend/release/upgrader-${JOB_VERSION}.jar release/job/backend/upgrader-${JOB_VERSION}.jar -done - -# Package versionLogs -if [ ! -d "src/frontend/release/job/frontend/static" ] -then - mkdir -p src/frontend/release/job/frontend/static -fi -if [ ! -d "release/job/frontend/static" ] -then - mkdir -p release/job/frontend/static -fi -cp versionLogs/bundledVersionLog*.json release/job/frontend/static -if [ ! -d "src/frontend/dist/*" ] -then - mkdir -p src/frontend/dist/_init_ -fi - -# Package front-end static files -for m in "${PACKAGE_MODULES[@]}"; do - for FRONTEND_MODULE in ${FRONTEND_MODULES[@]} - do - if [[ "$FRONTEND_MODULE" == "$m" ]]; then - log "Packaging $m ..." - mkdir -p release/job/frontend - cp -r src/frontend/dist/* release/job/frontend/ - echo "Package frontend successfully" - fi - done -done - - -# Package support-files -log "Packaging support-files ..." -cp -r support-files/ release/job/ -sed -i 's/job.edition=ee/job.edition=ce/g' "release/job/support-files/templates/#etc#job#job-gateway#job-gateway.properties" -sed -i 's/job.edition=ee/job.edition=ce/g' "release/job/support-files/templates/#etc#job#job-manage#job-manage.properties" -echo "Package support-files successfully" - -# Package project documents -log "Packaging project doc ..." -cp README.md release/job/ -cp projects.yaml release/job/ -cp release.md release/job/ -cp VERSION release/job/ -cp -r docs/ release/job/ -echo "Package project doc successfully" - -cd release -tar -czf "job_ce-${JOB_VERSION}.tgz" job - -log "Package job successfully! File: job_ce-${JOB_VERSION}.tgz" -set +e diff --git a/src/backend/.gitignore b/src/backend/.gitignore index b265a41ed1..44fb873544 100644 --- a/src/backend/.gitignore +++ b/src/backend/.gitignore @@ -5,4 +5,6 @@ build release -**/bin \ No newline at end of file +**/bin +build.yml +.codecc/ \ No newline at end of file diff --git a/src/backend/build.gradle b/src/backend/build.gradle index cb692d9583..ebd2fcc316 100644 --- a/src/backend/build.gradle +++ b/src/backend/build.gradle @@ -26,8 +26,8 @@ import com.dorongold.gradle.tasktree.TaskTreePlugin buildscript { ext { - set('springDependencyManagePluginVersion', "1.0.8.RELEASE") - set("springBootVersion", "2.3.5.RELEASE") + set('springDependencyManagePluginVersion', "1.0.11.RELEASE") + set("springBootVersion", "2.4.6") set("gradleJooqVersion", "3.0.0") } @@ -56,21 +56,21 @@ buildscript { } plugins { - id "java" - id "io.spring.dependency-management" version '1.0.8.RELEASE' apply false - id 'org.springframework.boot' version '2.3.5.RELEASE' apply false + id "java-library" + id "io.spring.dependency-management" version '1.0.11.RELEASE' apply false + id 'org.springframework.boot' version '2.4.6' apply false id "idea" id 'nu.studer.jooq' version '3.0.0' } ext { // https://mvnrepository.com/artifact/org.springframework/spring-jdbc - set("springVersion", "5.2.9.RELEASE") - set("springAmqpVersion", "2.2.6.RELEASE") + set("springVersion", "5.3.9") + set("springAmqpVersion", "2.3.7") // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies - set("springBootVersion", "2.3.5.RELEASE") + set("springBootVersion", "2.4.6") // https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies - set('springCloudVersion', "Hoxton.SR3") + set('springCloudVersion', "2020.0.3") // https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui set('swaggerVersion', "2.9.2") set('junitVersion', "5.5.2") @@ -80,7 +80,7 @@ ext { set('jacksonVersion', "2.11.0") set('jaxrsVersion', "2.0") // https://mvnrepository.com/artifact/ch.qos.logback/logback-core - set('logbackVersion', "1.2.3") + set('logbackVersion', "1.2.10") // https://mvnrepository.com/artifact/org.slf4j/slf4j-api set('slf4jVersion', "1.7.30") set('servletVersion', "3.0.1") @@ -126,7 +126,7 @@ allprojects { apply plugin: "idea" apply plugin: "eclipse" - apply plugin: "java" + apply plugin: "java-library" sourceCompatibility = '1.8' targetCompatibility = '1.8' @@ -155,7 +155,7 @@ allprojects { } subprojects { - apply plugin: "java" + apply plugin: "java-library" apply plugin: "idea" apply plugin: "io.spring.dependency-management" diff --git a/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/GenCompleteDependJarListAndRemoveInfectedJarsTask.java b/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/GenCompleteDependJarListAndRemoveInfectedJarsTask.java index e40ebd8a7b..3af937d442 100644 --- a/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/GenCompleteDependJarListAndRemoveInfectedJarsTask.java +++ b/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/GenCompleteDependJarListAndRemoveInfectedJarsTask.java @@ -48,7 +48,7 @@ class GenCompleteDependJarListAndRemoveInfectedJarsTask extends DefaultTask { @Input public String dependJarInfoRootPath = "../../support-files/dependJarInfo"; @Input - public String defaultEdition = "ee"; + public String defaultEdition = "ce"; @Input public String defaultPackageType = "allInOne"; Set patternSet = new HashSet<>(); @@ -407,4 +407,44 @@ public void genJarListAndRemoveInjectedJars() { public void remove(String pattern) { patternSet.add(pattern); } + + public FileCollection getBootJarOutputFiles() { + return bootJarOutputFiles; + } + + public void setBootJarOutputFiles(FileCollection bootJarOutputFiles) { + this.bootJarOutputFiles = bootJarOutputFiles; + } + + public String getCompleteJarListsRootPath() { + return completeJarListsRootPath; + } + + public void setCompleteJarListsRootPath(String completeJarListsRootPath) { + this.completeJarListsRootPath = completeJarListsRootPath; + } + + public String getDependJarInfoRootPath() { + return dependJarInfoRootPath; + } + + public void setDependJarInfoRootPath(String dependJarInfoRootPath) { + this.dependJarInfoRootPath = dependJarInfoRootPath; + } + + public String getDefaultEdition() { + return defaultEdition; + } + + public void setDefaultEdition(String defaultEdition) { + this.defaultEdition = defaultEdition; + } + + public String getDefaultPackageType() { + return defaultPackageType; + } + + public void setDefaultPackageType(String defaultPackageType) { + this.defaultPackageType = defaultPackageType; + } } diff --git a/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceCETextTask.java b/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceEditionTextTask.java similarity index 79% rename from src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceCETextTask.java rename to src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceEditionTextTask.java index 7f6ca3d12d..ea13075717 100644 --- a/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceCETextTask.java +++ b/src/backend/buildSrc/src/main/java/com/tencent/bk/gradle/tasks/ReplaceEditionTextTask.java @@ -38,7 +38,7 @@ import java.util.Set; import java.util.regex.Pattern; -class ReplaceCETextTask extends DefaultTask { +class ReplaceEditionTextTask extends DefaultTask { @InputFiles public FileCollection processResourcesOutputFiles; @@ -47,13 +47,13 @@ class ReplaceCETextTask extends DefaultTask { @Input public String targetStr = null; @Input - public String defaultEdition = "ee"; + public String defaultEdition = "ce"; @Input public String defaultPackageType = "allInOne"; Set patternSet = new HashSet<>(); @Inject - public ReplaceCETextTask() { + public ReplaceEditionTextTask() { } @TaskAction @@ -73,12 +73,12 @@ public void replace() { } System.out.println("edition=" + edition); System.out.println("packageType=" + packageType); - if ("ce".equals(edition)) { - replaceCEText(); + if ("ee".equals(edition)) { + replaceEditionText(); } else { - System.out.println("Skip ReplaceCETextTask, set build param edition=ce to enable"); + System.out.println("Skip ReplaceEditionTextTask, set build param edition=ee to enable"); } - System.out.println("ReplaceCETextTask Done"); + System.out.println("ReplaceEditionTextTask Done"); } private boolean match(String pattern, String targetStr) { @@ -91,7 +91,7 @@ private boolean match(String pattern, String targetStr) { return Pattern.matches(pattern, targetStr); } - private void replaceCEText() { + private void replaceEditionText() { for (File file : processResourcesOutputFiles) { String absPath = file.getAbsolutePath(); System.out.println("check file:" + absPath); @@ -159,4 +159,44 @@ private void writeStringToFile(String str, File file) { public void process(String pattern) { patternSet.add(pattern); } + + public FileCollection getProcessResourcesOutputFiles() { + return processResourcesOutputFiles; + } + + public void setProcessResourcesOutputFiles(FileCollection processResourcesOutputFiles) { + this.processResourcesOutputFiles = processResourcesOutputFiles; + } + + public String getSrcStr() { + return srcStr; + } + + public void setSrcStr(String srcStr) { + this.srcStr = srcStr; + } + + public String getTargetStr() { + return targetStr; + } + + public void setTargetStr(String targetStr) { + this.targetStr = targetStr; + } + + public String getDefaultEdition() { + return defaultEdition; + } + + public void setDefaultEdition(String defaultEdition) { + this.defaultEdition = defaultEdition; + } + + public String getDefaultPackageType() { + return defaultPackageType; + } + + public void setDefaultPackageType(String defaultPackageType) { + this.defaultPackageType = defaultPackageType; + } } diff --git a/src/backend/commons/build.gradle b/src/backend/commons/build.gradle index 06ecd5b4a5..b100261dc9 100644 --- a/src/backend/commons/build.gradle +++ b/src/backend/commons/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobCommonVersion")) { set("jobCommonVersion", System.getProperty("jobCommonVersion")) + } else if (System.getProperty("version")) { + set("jobCommonVersion", System.getProperty("version")) } else { set("jobCommonVersion", "1.0.0") } diff --git a/src/backend/commons/cmdb-sdk-ext/build.gradle b/src/backend/commons/cmdb-sdk-ext/build.gradle index b8a865de4c..e678a01998 100644 --- a/src/backend/commons/cmdb-sdk-ext/build.gradle +++ b/src/backend/commons/cmdb-sdk-ext/build.gradle @@ -24,6 +24,6 @@ apply plugin: 'java' dependencies { - compile project(":commons:cmdb-sdk") - compile project(":commons:common-redis") + api project(":commons:cmdb-sdk") + api project(":commons:common-redis") } diff --git a/src/backend/commons/cmdb-sdk/build.gradle b/src/backend/commons/cmdb-sdk/build.gradle index acc2fb99fd..4b163cf6cf 100644 --- a/src/backend/commons/cmdb-sdk/build.gradle +++ b/src/backend/commons/cmdb-sdk/build.gradle @@ -24,15 +24,15 @@ apply plugin: 'java' dependencies { - compile project(":commons:common") - compile project(":commons:esb-sdk") - compile project(":commons:gse-sdk") - compile project(":commons:common-i18n") + api project(":commons:common") + api project(":commons:esb-sdk") + api project(":commons:gse-sdk") + api project(":commons:common-i18n") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' implementation 'io.micrometer:micrometer-registry-prometheus' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' implementation "net.sf.dozer:dozer" implementation 'org.apache.commons:commons-collections4' implementation group: 'org.apache.httpcomponents', name: 'httpclient' @@ -40,6 +40,6 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation "org.junit.jupiter:junit-jupiter" testImplementation 'org.springframework.boot:spring-boot-starter-test' - compile "com.google.guava:guava:20.0" - compile("org.springframework:spring-context") + api "com.google.guava:guava:20.0" + api("org.springframework:spring-context") } diff --git a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/EsbCcClient.java b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/EsbCcClient.java index 4c9161f632..bd73d46bc9 100644 --- a/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/EsbCcClient.java +++ b/src/backend/commons/cmdb-sdk/src/main/java/com/tencent/bk/job/common/cc/sdk/EsbCcClient.java @@ -770,6 +770,98 @@ public List findModuleHostRelationConcurrently(long appI return applicationHostInfoDTOList; } + private void fillAgentInfo( + ApplicationHostInfoDTO applicationHostInfoDTO, + FindModuleHostRelationResult.HostProp host + ) { + String multiIp = host.getIp(); + multiIp = multiIp.trim(); + if (queryAgentStatusClient != null) { + if (multiIp.contains(",")) { + Pair pair = queryAgentStatusClient.getHostIpWithAgentStatus(multiIp, + host.getCloudAreaId()); + if (pair != null) { + log.debug("query agent status:{}:{}", pair.getLeft(), pair.getRight()); + String ipWithCloudId = pair.getLeft(); + applicationHostInfoDTO.setGseAgentAlive(pair.getRight()); + if (ipWithCloudId.contains(":")) { + String[] arr = ipWithCloudId.split(":"); + applicationHostInfoDTO.setCloudAreaId(Long.parseLong(arr[0])); + applicationHostInfoDTO.setIp(arr[1]); + } else { + applicationHostInfoDTO.setIp(ipWithCloudId); + } + } else { + log.warn("Fail to get agentStatus, host={}", JsonUtils.toJson(host)); + } + } else { + applicationHostInfoDTO.setGseAgentAlive(false); + applicationHostInfoDTO.setCloudAreaId(host.getCloudAreaId()); + applicationHostInfoDTO.setIp(multiIp); + } + } else { + log.warn("queryAgentStatusClient==null, please check!"); + List ipList = Utils.getNotBlankSplitList(multiIp, ","); + if (ipList.size() > 0) { + applicationHostInfoDTO.setIp(ipList.get(0)); + } else { + log.warn("no available ip after queryAgentStatusClient"); + } + } + } + + private ApplicationHostInfoDTO convertToHostInfoDTO( + Long appId, + FindModuleHostRelationResult.HostWithModules hostWithModules + ) { + FindModuleHostRelationResult.HostProp host = hostWithModules.getHost(); + String multiIp = host.getIp(); + if (multiIp != null) { + multiIp = multiIp.trim(); + } else { + log.warn("multiIp is null, appId={}, host={}", appId, hostWithModules); + } + //包装为ApplicationHostInfoDTO + ApplicationHostInfoDTO applicationHostInfoDTO = new ApplicationHostInfoDTO(); + applicationHostInfoDTO.setAppId(appId); + applicationHostInfoDTO.setDisplayIp(multiIp); + applicationHostInfoDTO.setCloudAreaId(host.getCloudAreaId()); + applicationHostInfoDTO.setHostId(host.getHostId()); + fillAgentInfo(applicationHostInfoDTO, host); + List modules = hostWithModules.getModules(); + for (FindModuleHostRelationResult.ModuleProp module : modules) { + if (module == null || null == module.getModuleId()) { + log.warn("invalid host:" + JsonUtils.toJson(applicationHostInfoDTO)); + } + } + List validModules = + hostWithModules.getModules().stream().filter(Objects::nonNull).collect(Collectors.toList()); + applicationHostInfoDTO.setModuleId( + validModules.stream() + .map(FindModuleHostRelationResult.ModuleProp::getModuleId) + .collect(Collectors.toList())); + applicationHostInfoDTO.setSetId( + validModules.stream() + .map(FindModuleHostRelationResult.ModuleProp::getSetId) + .collect(Collectors.toList())); + applicationHostInfoDTO.setModuleType(validModules.stream().map(it -> { + try { + return Long.parseLong(it.getModuleType()); + } catch (Exception e) { + return 0L; + } + }).collect(Collectors.toList())); + applicationHostInfoDTO.setIpDesc(host.getHostName()); + String os = host.getOs(); + if (os != null && os.length() > 512) { + applicationHostInfoDTO.setOs(os.substring(0, 512)); + } else { + applicationHostInfoDTO.setOs(os); + } + applicationHostInfoDTO.setOsType(host.getOsType()); + return applicationHostInfoDTO; + } + private List convertToHostInfoDTOList( long appId, List hostWithModulesList) { @@ -784,68 +876,7 @@ private List convertToHostInfoDTOList( ipSet.add(host.getCloudAreaId() + ":" + host.getIp()); String multiIp = host.getIp(); if (!StringUtils.isBlank(multiIp)) { - multiIp = multiIp.trim(); - //包装为ApplicationHostInfoDTO - ApplicationHostInfoDTO applicationHostInfoDTO = new ApplicationHostInfoDTO(); - applicationHostInfoDTO.setAppId(appId); - applicationHostInfoDTO.setDisplayIp(multiIp); - applicationHostInfoDTO.setCloudAreaId(host.getCloudAreaId()); - applicationHostInfoDTO.setHostId(host.getHostId()); - if (queryAgentStatusClient != null) { - if (multiIp.contains(",")) { - Pair pair = queryAgentStatusClient.getHostIpWithAgentStatus(host.getIp(), - host.getCloudAreaId()); - if (pair != null) { - log.debug("query agent status:{}:{}", pair.getLeft(), pair.getRight()); - String ipWithCloudId = pair.getLeft(); - applicationHostInfoDTO.setGseAgentAlive(pair.getRight()); - if (ipWithCloudId.contains(":")) { - String[] arr = ipWithCloudId.split(":"); - applicationHostInfoDTO.setCloudAreaId(Long.parseLong(arr[0])); - applicationHostInfoDTO.setIp(arr[1]); - } else { - applicationHostInfoDTO.setIp(ipWithCloudId); - } - } else { - log.warn("Fail to get agentStatus, host={}", JsonUtils.toJson(host)); - } - } else { - applicationHostInfoDTO.setGseAgentAlive(false); - applicationHostInfoDTO.setCloudAreaId(host.getCloudAreaId()); - applicationHostInfoDTO.setIp(multiIp); - } - } else { - log.warn("queryAgentStatusClient==null, please check!"); - List ipList = Utils.getNotBlankSplitList(multiIp, ","); - if (ipList.size() > 0) { - applicationHostInfoDTO.setIp(ipList.get(0)); - } else { - log.warn("no available ip after queryAgentStatusClient"); - } - } - applicationHostInfoDTO.setModuleId( - hostWithModules.getModules().stream() - .map(FindModuleHostRelationResult.ModuleProp::getModuleId) - .collect(Collectors.toList())); - applicationHostInfoDTO.setSetId( - hostWithModules.getModules().stream() - .map(FindModuleHostRelationResult.ModuleProp::getSetId) - .collect(Collectors.toList())); - applicationHostInfoDTO.setModuleType(hostWithModules.getModules().stream().map(it -> { - try { - return Long.parseLong(it.getModuleType()); - } catch (Exception e) { - return 0L; - } - }).collect(Collectors.toList())); - applicationHostInfoDTO.setIpDesc(host.getHostName()); - String os = host.getOs(); - if (os != null && os.length() > 512) { - applicationHostInfoDTO.setOs(os.substring(0, 512)); - } else { - applicationHostInfoDTO.setOs(os); - } - applicationHostInfoDTO.setOsType(host.getOsType()); + ApplicationHostInfoDTO applicationHostInfoDTO = convertToHostInfoDTO(appId, hostWithModules); applicationHostInfoDTOList.add(applicationHostInfoDTO); } else { log.info("bk_host_innerip is blank, ignore, hostId={},host={}", host.getHostId(), diff --git a/src/backend/commons/common-i18n/build.gradle b/src/backend/commons/common-i18n/build.gradle index f3af52223d..8ae359d65c 100644 --- a/src/backend/commons/common-i18n/build.gradle +++ b/src/backend/commons/common-i18n/build.gradle @@ -24,10 +24,11 @@ apply plugin: 'java' dependencies { - compileOnly 'org.springframework.boot:spring-boot-starter-web' + implementation "org.springframework:spring-context" + implementation "org.springframework:spring-core" annotationProcessor 'org.projectlombok:lombok' testImplementation "org.junit.jupiter:junit-jupiter" testImplementation 'org.springframework.boot:spring-boot-starter-test' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' compileOnly 'org.projectlombok:lombok' } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/I18nConfig.java b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/config/MessageSourceConfig.java similarity index 88% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/I18nConfig.java rename to src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/config/MessageSourceConfig.java index bb84d03a4c..a7a598b762 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/I18nConfig.java +++ b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/config/MessageSourceConfig.java @@ -22,28 +22,26 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.config; +package com.tencent.bk.job.common.i18n.config; -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import java.nio.charset.StandardCharsets; -/** - * @date 2019/09/19 - */ @Configuration -public class I18nConfig { +public class MessageSourceConfig { @Bean("messageSource") public ReloadableResourceBundleMessageSource messageSource() { MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); + messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", + "classpath*:i18n/common/message"); messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); messageSource.setUseCodeAsDefaultMessage(true); return messageSource; } + } + diff --git a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/locale/LocaleUtils.java b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/locale/LocaleUtils.java index c97a8f48a9..1de0bc1294 100644 --- a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/locale/LocaleUtils.java +++ b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/locale/LocaleUtils.java @@ -43,7 +43,7 @@ public class LocaleUtils { */ public static final String COMMON_LANG_HEADER = "lang"; - public static final Map localeMap = new HashMap<>(); + private static final Map localeMap = new HashMap<>(); static { localeMap.put("zh", LANG_ZH); @@ -62,7 +62,7 @@ public class LocaleUtils { */ public static String getNormalLang(String lang) { lang = lang.toLowerCase(); - if (localeMap.keySet().contains(lang)) { + if (localeMap.containsKey(lang)) { return localeMap.get(lang); } return lang; @@ -70,7 +70,7 @@ public static String getNormalLang(String lang) { public static Locale getLocale(String lang) { if (StringUtils.isBlank(lang)) { - return Locale.CHINESE; + return Locale.SIMPLIFIED_CHINESE; } else if (lang.equalsIgnoreCase(LANG_ZH_CN)) { return Locale.SIMPLIFIED_CHINESE; } else if (lang.equalsIgnoreCase(LANG_ZH)) { @@ -80,7 +80,7 @@ public static Locale getLocale(String lang) { } else if (lang.equalsIgnoreCase(LANG_EN_US)) { return Locale.US; } else { - return Locale.CHINESE; + return Locale.SIMPLIFIED_CHINESE; } } } diff --git a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/MessageI18nService.java b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/MessageI18nService.java similarity index 97% rename from src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/MessageI18nService.java rename to src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/MessageI18nService.java index e5e16d70d5..7f3d074177 100644 --- a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/MessageI18nService.java +++ b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/MessageI18nService.java @@ -22,7 +22,7 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.i18n; +package com.tencent.bk.job.common.i18n.service; import java.util.Locale; diff --git a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/impl/MessageI18nServiceImpl.java b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/impl/MessageI18nServiceImpl.java similarity index 95% rename from src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/impl/MessageI18nServiceImpl.java rename to src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/impl/MessageI18nServiceImpl.java index 1244c843ee..eafff9d27f 100644 --- a/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/impl/MessageI18nServiceImpl.java +++ b/src/backend/commons/common-i18n/src/main/java/com/tencent/bk/job/common/i18n/service/impl/MessageI18nServiceImpl.java @@ -22,9 +22,9 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.i18n.impl; +package com.tencent.bk.job.common.i18n.service.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message.properties index 78cef618d8..eec006eef1 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message.properties @@ -36,6 +36,10 @@ permission.resource.type.name.account=执行账号 permission.resource.type.name.public_script=公共脚本 permission.resource.type.name.tag=标签 permission.resource.type.name.host=主机 +permission.resource.type.name.sys_cloud_area=云区域 +permission.resource.type.name.set=集群 +permission.resource.type.name.module=模块 +permission.resource.type.name.biz_custom_query=动态分组 permission.resource.type.name.dashboard_view=运营视图 permission.resource.type.name.file_source=文件源 permission.resource.type.name.ticket=凭证 @@ -101,3 +105,6 @@ permission.action.name.manage_public_script=公共脚本管理 permission.action.name.manage_public_script_instance=公共脚本管理 # 全局设置 permission.action.name.global_settings=全局设置管理 +# 高危语句 +permission.action.name.high-risk_detect_rule=高危语句规则管理 +permission.action.name.high-risk_detect_record=高危语句拦截记录查看 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en.properties index 25143dcd3c..4b20701800 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en.properties @@ -36,6 +36,10 @@ permission.resource.type.name.account=Accounts permission.resource.type.name.public_script=Public Scripts permission.resource.type.name.tag=Tags permission.resource.type.name.host=Hosts +permission.resource.type.name.sys_cloud_area=Cloud Areas +permission.resource.type.name.set=Sets +permission.resource.type.name.module=Modules +permission.resource.type.name.biz_custom_query=Dynamic Groups permission.resource.type.name.dashboard_view=Dashboard Views permission.resource.type.name.file_source=File Sources permission.resource.type.name.ticket=Tickets @@ -101,3 +105,6 @@ permission.action.name.manage_public_script=Manage Public Script permission.action.name.manage_public_script_instance=Manage Public Script # 全局设置 permission.action.name.global_settings=Manage Global Settings +# 高危语句 +permission.action.name.high-risk_detect_rule=High-risk Detect Rule Setting +permission.action.name.high-risk_detect_record=High-risk Detect Record diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en_US.properties index 25143dcd3c..4b20701800 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_en_US.properties @@ -36,6 +36,10 @@ permission.resource.type.name.account=Accounts permission.resource.type.name.public_script=Public Scripts permission.resource.type.name.tag=Tags permission.resource.type.name.host=Hosts +permission.resource.type.name.sys_cloud_area=Cloud Areas +permission.resource.type.name.set=Sets +permission.resource.type.name.module=Modules +permission.resource.type.name.biz_custom_query=Dynamic Groups permission.resource.type.name.dashboard_view=Dashboard Views permission.resource.type.name.file_source=File Sources permission.resource.type.name.ticket=Tickets @@ -101,3 +105,6 @@ permission.action.name.manage_public_script=Manage Public Script permission.action.name.manage_public_script_instance=Manage Public Script # 全局设置 permission.action.name.global_settings=Manage Global Settings +# 高危语句 +permission.action.name.high-risk_detect_rule=High-risk Detect Rule Setting +permission.action.name.high-risk_detect_record=High-risk Detect Record diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh.properties index 78cef618d8..eec006eef1 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh.properties @@ -36,6 +36,10 @@ permission.resource.type.name.account=执行账号 permission.resource.type.name.public_script=公共脚本 permission.resource.type.name.tag=标签 permission.resource.type.name.host=主机 +permission.resource.type.name.sys_cloud_area=云区域 +permission.resource.type.name.set=集群 +permission.resource.type.name.module=模块 +permission.resource.type.name.biz_custom_query=动态分组 permission.resource.type.name.dashboard_view=运营视图 permission.resource.type.name.file_source=文件源 permission.resource.type.name.ticket=凭证 @@ -101,3 +105,6 @@ permission.action.name.manage_public_script=公共脚本管理 permission.action.name.manage_public_script_instance=公共脚本管理 # 全局设置 permission.action.name.global_settings=全局设置管理 +# 高危语句 +permission.action.name.high-risk_detect_rule=高危语句规则管理 +permission.action.name.high-risk_detect_record=高危语句拦截记录查看 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh_CN.properties index 78cef618d8..eec006eef1 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/common/message_zh_CN.properties @@ -36,6 +36,10 @@ permission.resource.type.name.account=执行账号 permission.resource.type.name.public_script=公共脚本 permission.resource.type.name.tag=标签 permission.resource.type.name.host=主机 +permission.resource.type.name.sys_cloud_area=云区域 +permission.resource.type.name.set=集群 +permission.resource.type.name.module=模块 +permission.resource.type.name.biz_custom_query=动态分组 permission.resource.type.name.dashboard_view=运营视图 permission.resource.type.name.file_source=文件源 permission.resource.type.name.ticket=凭证 @@ -101,3 +105,6 @@ permission.action.name.manage_public_script=公共脚本管理 permission.action.name.manage_public_script_instance=公共脚本管理 # 全局设置 permission.action.name.global_settings=全局设置管理 +# 高危语句 +permission.action.name.high-risk_detect_rule=高危语句规则管理 +permission.action.name.high-risk_detect_record=高危语句拦截记录查看 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties index 2f5e7da6ce..8e7f35b187 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties @@ -126,16 +126,16 @@ 1244018=脚本未上线,无法执行 1244019=高危脚本,禁止执行 1244020=作业执行历史查询时间范围必须小于30天 +1244021=文件任务数量超过限制:{0} ##业务错误-日志服务(job-logsvr) 1246001=获取作业执行日志失败 1246002=保存作业执行日志失败 1246003=删除作业执行日志失败 ##业务错误-文件网关服务(job-file-gateway) 1260001=文件源不存在:{0} -1260002=接入点响应异常:ListBucket,详情:{0} -1260003=接入点响应异常:ListObjects,详情:{0} -1260008=接入点响应异常:DeleteBucket,详情:{0} -1260009=接入点响应异常:DeleteBucketFile,详情:{0} +1260002=接入点响应异常:ListFileNode,详情:{0} +1260003=接入点响应异常:FileAvailable,详情:{0} +1260008=接入点响应异常:ExecuteAction,详情:{0} 1260004=文件源别名已存在:{0} 1260005=无法匹配到有效接入点,请检查文件源配置 1260006=接入点响应异常:ClearTaskFiles,详情:{0} diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties index 061da05367..214a235220 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties @@ -127,16 +127,16 @@ 1244018=Script version is not online, cannot be executed 1244019=Dangerous script, cannot be executed 1244020=The job execution history query time range must be less than 30 days +1244021=The number of file tasks exceeds the limit:{0} ## Business error - job-logsvr 1246001=Failed to get execution log 1246002=Failed to save execution log 1246003=Failed to delete execution log ## Business error (job-file-gateway) 1260001=FileSource does not exist:{0} -1260002=FileWorker response error:ListBucket, Detail:{0} -1260003=FileWorker response error:ListObjects, Detail:{0} -1260008=FileWorker response error:DeleteBucket, Detail:{0} -1260009=FileWorker response error:DeleteBucketFile, Detail:{0} +1260002=FileWorker response error:ListFileNode, Detail:{0} +1260003=FileWorker response error:FileAvailable, Detail:{0} +1260008=FileWorker response error:ExecuteAction, Detail:{0} 1260004=FileSource alias already exists:{0} 1260005=Cannot find available file worker, please check configuration of fileSource 1260006=FileWorker response error:ClearTaskFiles, Detail:{0} diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties index 061da05367..214a235220 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties @@ -127,16 +127,16 @@ 1244018=Script version is not online, cannot be executed 1244019=Dangerous script, cannot be executed 1244020=The job execution history query time range must be less than 30 days +1244021=The number of file tasks exceeds the limit:{0} ## Business error - job-logsvr 1246001=Failed to get execution log 1246002=Failed to save execution log 1246003=Failed to delete execution log ## Business error (job-file-gateway) 1260001=FileSource does not exist:{0} -1260002=FileWorker response error:ListBucket, Detail:{0} -1260003=FileWorker response error:ListObjects, Detail:{0} -1260008=FileWorker response error:DeleteBucket, Detail:{0} -1260009=FileWorker response error:DeleteBucketFile, Detail:{0} +1260002=FileWorker response error:ListFileNode, Detail:{0} +1260003=FileWorker response error:FileAvailable, Detail:{0} +1260008=FileWorker response error:ExecuteAction, Detail:{0} 1260004=FileSource alias already exists:{0} 1260005=Cannot find available file worker, please check configuration of fileSource 1260006=FileWorker response error:ClearTaskFiles, Detail:{0} diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties index 2f5e7da6ce..8e7f35b187 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties @@ -126,16 +126,16 @@ 1244018=脚本未上线,无法执行 1244019=高危脚本,禁止执行 1244020=作业执行历史查询时间范围必须小于30天 +1244021=文件任务数量超过限制:{0} ##业务错误-日志服务(job-logsvr) 1246001=获取作业执行日志失败 1246002=保存作业执行日志失败 1246003=删除作业执行日志失败 ##业务错误-文件网关服务(job-file-gateway) 1260001=文件源不存在:{0} -1260002=接入点响应异常:ListBucket,详情:{0} -1260003=接入点响应异常:ListObjects,详情:{0} -1260008=接入点响应异常:DeleteBucket,详情:{0} -1260009=接入点响应异常:DeleteBucketFile,详情:{0} +1260002=接入点响应异常:ListFileNode,详情:{0} +1260003=接入点响应异常:FileAvailable,详情:{0} +1260008=接入点响应异常:ExecuteAction,详情:{0} 1260004=文件源别名已存在:{0} 1260005=无法匹配到有效接入点,请检查文件源配置 1260006=接入点响应异常:ClearTaskFiles,详情:{0} diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties index 2f5e7da6ce..8e7f35b187 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties @@ -126,16 +126,16 @@ 1244018=脚本未上线,无法执行 1244019=高危脚本,禁止执行 1244020=作业执行历史查询时间范围必须小于30天 +1244021=文件任务数量超过限制:{0} ##业务错误-日志服务(job-logsvr) 1246001=获取作业执行日志失败 1246002=保存作业执行日志失败 1246003=删除作业执行日志失败 ##业务错误-文件网关服务(job-file-gateway) 1260001=文件源不存在:{0} -1260002=接入点响应异常:ListBucket,详情:{0} -1260003=接入点响应异常:ListObjects,详情:{0} -1260008=接入点响应异常:DeleteBucket,详情:{0} -1260009=接入点响应异常:DeleteBucketFile,详情:{0} +1260002=接入点响应异常:ListFileNode,详情:{0} +1260003=接入点响应异常:FileAvailable,详情:{0} +1260008=接入点响应异常:ExecuteAction,详情:{0} 1260004=文件源别名已存在:{0} 1260005=无法匹配到有效接入点,请检查文件源配置 1260006=接入点响应异常:ClearTaskFiles,详情:{0} diff --git a/src/backend/commons/common-iam/build.gradle b/src/backend/commons/common-iam/build.gradle index ed5af94a56..06866747ce 100644 --- a/src/backend/commons/common-iam/build.gradle +++ b/src/backend/commons/common-iam/build.gradle @@ -24,11 +24,11 @@ apply plugin: 'java' dependencies { - compile(files("libs/iam-sdk-1.0.0.jar")) + api(files("libs/iam-sdk-1.0.0.jar")) + implementation 'org.aspectj:aspectjweaver' implementation(group: 'org.springframework', name: 'spring-context') - implementation(project(":commons:common-web")) implementation(project(":commons:esb-sdk")) - compile(project(":commons:common")) + api(project(":commons:common")) compileOnly 'org.springframework.boot:spring-boot-starter-web' implementation group: 'org.apache.httpcomponents', name: 'httpclient' } diff --git a/src/backend/commons/common-iam/libs/iam-sdk-1.0.0.jar b/src/backend/commons/common-iam/libs/iam-sdk-1.0.0.jar index 7fa403b707..e216caafc5 100644 Binary files a/src/backend/commons/common-iam/libs/iam-sdk-1.0.0.jar and b/src/backend/commons/common-iam/libs/iam-sdk-1.0.0.jar differ diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/aspect/IamCallbackAspect.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/aspect/IamCallbackAspect.java new file mode 100644 index 0000000000..708887fce8 --- /dev/null +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/aspect/IamCallbackAspect.java @@ -0,0 +1,55 @@ +package com.tencent.bk.job.common.iam.aspect; + +import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Aspect +@Component +public class IamCallbackAspect { + + @Autowired + public IamCallbackAspect() { + } + + @Pointcut("execution (* com.tencent.bk.job.*.api.iam.impl.*.callback(..))") + public void processCallbackRequest() { + } + + private void logRequest(CallbackRequestDTO callbackRequest) { + if (log.isDebugEnabled()) { + log.debug("callbackRequest={}", JsonUtils.toJson(callbackRequest)); + } else { + log.info( + "Received iam callbackRequest:[{}|{}|{}|{}]", + callbackRequest.getMethod().getMethod(), + callbackRequest.getType(), + callbackRequest.getFilter(), + callbackRequest.getPage() + ); + } + } + + @Around("processCallbackRequest()") + public Object logBeforeProcessCallbackRequest(ProceedingJoinPoint pjp) throws Exception { + try { + Object[] args = pjp.getArgs(); + if (args.length < 1) { + log.warn("unexpected ProceedingJoinPoint, please check"); + return pjp.proceed(); + } + CallbackRequestDTO callbackRequest = (CallbackRequestDTO) args[0]; + logRequest(callbackRequest); + return pjp.proceed(); + } catch (Throwable throwable) { + throw new Exception("Fail to execute logBeforeProcessCallbackRequest", throwable); + } + } +} diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java index 1e14fcb705..95af6ba1ca 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/client/EsbIamClient.java @@ -64,7 +64,12 @@ public EsbIamClient(String esbHostUrl, String appCode, String appSecret, String @Override public String getApplyUrl(List actionList) { - GetApplyUrlRequest getApplyUrlRequest = makeBaseReqByWeb(GetApplyUrlRequest.class, null, "admin", "superadmin"); + GetApplyUrlRequest getApplyUrlRequest = makeBaseReqByWeb( + GetApplyUrlRequest.class, + null, + "admin", + "superadmin" + ); getApplyUrlRequest.setSystem(SystemId.JOB); getApplyUrlRequest.setAction(actionList); String respStr = null; @@ -136,7 +141,11 @@ public boolean registerResource(String id, String name, String type, String crea } @Override - public EsbIamAuthedPolicy authByPath(EsbIamAction esbIamAction, EsbIamSubject esbIamSubject, List esbIamResources) { + public EsbIamAuthedPolicy authByPath( + EsbIamAction esbIamAction, + EsbIamSubject esbIamSubject, + List esbIamResources + ) { AuthByPathReq authByPathReq = makeBaseReqByWeb(AuthByPathReq.class, null, "admin", "superadmin"); authByPathReq.setAction(esbIamAction); @@ -150,15 +159,23 @@ public EsbIamAuthedPolicy authByPath(EsbIamAction esbIamAction, EsbIamSubject es } @Override - public List batchAuthByPath(List esbIamActions, EsbIamSubject esbIamSubject, List esbIamBatchPathResources, Long expiredAt) { + public List batchAuthByPath( + List esbIamActions, + EsbIamSubject esbIamSubject, + List esbIamBatchPathResources, + Long expiredAt + ) { BatchAuthByPathReq batchAuthByPathReq = makeBaseReqByWeb(BatchAuthByPathReq.class, null, "admin", "superadmin"); batchAuthByPathReq.setActions(esbIamActions); batchAuthByPathReq.setSubject(esbIamSubject); batchAuthByPathReq.setResources(esbIamBatchPathResources); batchAuthByPathReq.setExpiredAt(expiredAt); - EsbResp> esbResp = getEsbRespByReq(HttpPost.METHOD_NAME, - API_BATCH_AUTH_BY_PATH_URL, batchAuthByPathReq, new TypeReference>>() { + EsbResp> esbResp = getEsbRespByReq( + HttpPost.METHOD_NAME, + API_BATCH_AUTH_BY_PATH_URL, + batchAuthByPathReq, + new TypeReference>>() { }); return esbResp.getData(); } diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/config/JobIamAutoConfiguration.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/config/JobIamAutoConfiguration.java index a60a0c55ba..e8885abe50 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/config/JobIamAutoConfiguration.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/config/JobIamAutoConfiguration.java @@ -46,25 +46,25 @@ public class JobIamAutoConfiguration { /** * 权限中心对应的系统 ID */ - @Value("${iam.system-id}") + @Value("${iam.system-id:}") private String systemId; /** * ESB 分配的系统 App Code */ - @Value("${app.code}") + @Value("${app.code:}") private String appCode; /** * ESB 分配的系统 App Secret */ - @Value("${app.secret}") + @Value("${app.secret:}") private String appSecret; /** * 权限中心的访问地址 */ - @Value("${iam.base-url}") + @Value("${iam.base-url:}") private String iamBaseUrl; /** diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ActionId.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ActionId.java index ff45c22af9..646bdec03e 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ActionId.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ActionId.java @@ -87,4 +87,9 @@ public class ActionId { public static final String USE_TICKET = "use_ticket"; public static final String CREATE_TICKET = "create_ticket"; public static final String MANAGE_TICKET = "manage_ticket"; + // 高危语句 + // 高危语句规则管理 + public static final String HIGH_RISK_DETECT_RULE = "high-risk_detect_rule"; + // 高危语句拦截记录查看 + public static final String HIGH_RISK_DETECT_RECORD = "high-risk_detect_record"; } diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ResourceId.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ResourceId.java index 8c285ea3f6..6cec7f0a53 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ResourceId.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/constant/ResourceId.java @@ -28,38 +28,58 @@ * @since 9/6/2020 15:38 */ public class ResourceId { + /** + * 业务 + */ + public static final String APP = "biz"; + /** + * 脚本 + */ public static final String SCRIPT = "script"; + /** + * 作业模板 + */ public static final String TEMPLATE = "job_template"; + /** + * 作业执行方案 + */ public static final String PLAN = "job_plan"; + /** + * 定时任务 + */ public static final String CRON = "cron"; + /** + * 执行账号 + */ public static final String ACCOUNT = "account"; + /** + * 公共脚本 + */ public static final String PUBLIC_SCRIPT = "public_script"; + /** + * 标签 + */ public static final String TAG = "tag"; - /** - * 业务 + * 主机 */ - public static final String APP = "biz"; + public static final String HOST = "host"; /** - * 模块 + * 云区域 */ - public static final String MODULE = "module"; + public static final String CLOUD_AREA = "sys_cloud_area"; /** * 集群 */ public static final String SET = "set"; /** - * 主机 + * 模块 */ - public static final String HOST = "host"; + public static final String MODULE = "module"; /** * 动态分组 */ public static final String DYNAMIC_GROUP = "biz_custom_query"; - /** - * 云区域 - */ - public static final String CLOUD_AREA = "sys_cloud_area"; /** * 运营视图 */ diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/AuthAppInterceptor.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/AuthAppInterceptor.java new file mode 100644 index 0000000000..20629f311f --- /dev/null +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/AuthAppInterceptor.java @@ -0,0 +1,95 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.iam.interceptor; + +import com.tencent.bk.job.common.constant.JobConstants; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.util.JobContextUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Slf4j +@Component +public class AuthAppInterceptor extends HandlerInterceptorAdapter { + + private final AuthService authService; + + @Autowired + public AuthAppInterceptor(AuthService authService) { + this.authService = authService; + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + String url = request.getRequestURI(); + Pair userAppIdPair = null; + userAppIdPair = findUserAndAppId(); + if (userAppIdPair != null) { + String username = userAppIdPair.getLeft(); + Long appId = userAppIdPair.getRight(); + if (appId != JobConstants.PUBLIC_APP_ID && appId > 0) { + log.info("auth {} access_business {}", username, appId); + AuthResult authResult = authService.auth(true, username, ActionId.LIST_BUSINESS, + ResourceTypeEnum.BUSINESS, appId.toString(), null); + if (!authResult.isPass()) { + throw new InSufficientPermissionException(authResult); + } + } else { + log.info("ignore auth {} access_business public app {}", username, appId); + } + } else { + log.info("can not find username/appId for url:{}", url); + } + return true; + } + + private Pair findUserAndAppId() { + String username = JobContextUtil.getUsername(); + Long appId = JobContextUtil.getAppId(); + if (username != null && appId != null) { + return Pair.of(username, appId); + } + return null; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) { + } +} diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/JobIamInterceptor.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/JobIamInterceptor.java new file mode 100644 index 0000000000..91ef6a5abd --- /dev/null +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/interceptor/JobIamInterceptor.java @@ -0,0 +1,70 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.iam.interceptor; + +import com.tencent.bk.sdk.iam.helper.AuthHelper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Slf4j +@Component +public class JobIamInterceptor extends HandlerInterceptorAdapter { + + private AuthHelper authHelper; + + @Autowired + public JobIamInterceptor(AuthHelper authHelper) { + this.authHelper = authHelper; + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + + if (!shouldFilter(request)) { + return true; + } + return authHelper.validRequest(request); + } + + private boolean shouldFilter(HttpServletRequest request) { + String uri = request.getRequestURI(); + return uri.startsWith("/iam/api/v1/resources/"); + } + + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) { + } +} diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/BaseIamCallbackService.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/BaseIamCallbackService.java new file mode 100644 index 0000000000..f74385a571 --- /dev/null +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/BaseIamCallbackService.java @@ -0,0 +1,70 @@ +package com.tencent.bk.job.common.iam.service; + +import com.tencent.bk.sdk.iam.constants.CommonResponseCode; +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListAttributeResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListAttributeValueResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceByPolicyResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class BaseIamCallbackService { + + public CallbackBaseResponseDTO getFailResp(Long code, String message) { + CallbackBaseResponseDTO respDTO = new CallbackBaseResponseDTO(); + respDTO.setCode(code); + respDTO.setMessage(message); + return respDTO; + } + + public CallbackBaseResponseDTO getNotFoundResp(String message) { + return getFailResp(CommonResponseCode.NOT_FOUND, message); + } + + public CallbackBaseResponseDTO getNotFoundRespById(String id) { + String msg = String.format("cannot find resource by id %d, may be deleted", id); + log.warn(msg); + return getNotFoundResp(msg); + } + + protected abstract ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest); + + protected abstract SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest); + + protected abstract CallbackBaseResponseDTO fetchInstanceResp(CallbackRequestDTO callbackRequest); + + public CallbackBaseResponseDTO baseCallback(CallbackRequestDTO callbackRequest) { + CallbackBaseResponseDTO response; + switch (callbackRequest.getMethod()) { + case LIST_INSTANCE: + response = listInstanceResp(callbackRequest); + break; + case FETCH_INSTANCE_INFO: + response = fetchInstanceResp(callbackRequest); + break; + case LIST_ATTRIBUTE: + response = new ListAttributeResponseDTO(); + response.setCode(0L); + break; + case LIST_ATTRIBUTE_VALUE: + response = new ListAttributeValueResponseDTO(); + response.setCode(0L); + break; + case LIST_INSTANCE_BY_POLICY: + response = new ListInstanceByPolicyResponseDTO(); + response.setCode(0L); + break; + case SEARCH_INSTANCE: + response = searchInstanceResp(callbackRequest); + break; + default: + log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), + callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); + response = new CallbackBaseResponseDTO(); + } + return response; + } +} diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/WebAuthService.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/WebAuthService.java index b43d2c131a..caf58560bd 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/WebAuthService.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/WebAuthService.java @@ -40,6 +40,8 @@ */ public interface WebAuthService { + AuthService getAuthService(); + void setResourceAppInfoQueryService(ResourceAppInfoQueryService resourceAppInfoQueryService); /** diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/AuthServiceImpl.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/AuthServiceImpl.java index fc539eb113..b53c0b448d 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/AuthServiceImpl.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/AuthServiceImpl.java @@ -30,7 +30,7 @@ import com.tencent.bk.job.common.esb.model.iam.EsbApplyPermissionDTO; import com.tencent.bk.job.common.esb.model.iam.EsbInstanceDTO; import com.tencent.bk.job.common.esb.model.iam.EsbRelatedResourceTypeDTO; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.client.EsbIamClient; import com.tencent.bk.job.common.iam.config.EsbConfiguration; import com.tencent.bk.job.common.iam.constant.ActionId; @@ -38,7 +38,11 @@ import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.dto.AppIdResult; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; -import com.tencent.bk.job.common.iam.model.*; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.model.PermissionActionResource; +import com.tencent.bk.job.common.iam.model.PermissionResource; +import com.tencent.bk.job.common.iam.model.PermissionResourceGroup; +import com.tencent.bk.job.common.iam.model.ResourceAppInfo; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.iam.service.ResourceAppInfoQueryService; import com.tencent.bk.job.common.iam.service.ResourceNameQueryService; @@ -61,7 +65,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; import java.util.stream.Collectors; @Slf4j diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/WebAuthServiceImpl.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/WebAuthServiceImpl.java index 6bf568869e..776d8bc121 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/WebAuthServiceImpl.java +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/service/impl/WebAuthServiceImpl.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.common.iam.service.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.dto.AppIdResult; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -59,6 +59,11 @@ public WebAuthServiceImpl(MessageI18nService i18nService, AuthService authServic this.authService = authService; } + @Override + public AuthService getAuthService() { + return authService; + } + @Override public void setResourceAppInfoQueryService(ResourceAppInfoQueryService resourceAppInfoQueryService) { this.authService.setResourceAppInfoQueryService(resourceAppInfoQueryService); diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/util/IamRespUtil.java b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/util/IamRespUtil.java new file mode 100644 index 0000000000..1a650ea82d --- /dev/null +++ b/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/util/IamRespUtil.java @@ -0,0 +1,54 @@ +package com.tencent.bk.job.common.iam.util; + +import com.tencent.bk.job.common.model.PageData; +import com.tencent.bk.sdk.iam.dto.callback.response.BaseDataResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; + +import java.util.List; +import java.util.stream.Collectors; + +public class IamRespUtil { + + public interface InstanceInfoDTOConverter { + InstanceInfoDTO convert(T t); + } + + private static List convertToInstanceList( + List rawDataList, + InstanceInfoDTOConverter converter + ) { + return rawDataList.parallelStream().map(converter::convert).collect(Collectors.toList()); + } + + public static ListInstanceResponseDTO getListInstanceRespFromPageData( + PageData tagDTOPageData, + InstanceInfoDTOConverter converter + ) { + List instanceInfoList = convertToInstanceList(tagDTOPageData.getData(), converter); + + ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); + instanceResponse.setCode(0L); + BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); + baseDataResponse.setResult(instanceInfoList); + baseDataResponse.setCount(tagDTOPageData.getTotal()); + instanceResponse.setData(baseDataResponse); + return instanceResponse; + } + + public static SearchInstanceResponseDTO getSearchInstanceRespFromPageData( + PageData tagDTOPageData, + InstanceInfoDTOConverter converter + ) { + List instanceInfoList = convertToInstanceList(tagDTOPageData.getData(), converter); + + SearchInstanceResponseDTO instanceResponse = new SearchInstanceResponseDTO(); + instanceResponse.setCode(0L); + BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); + baseDataResponse.setResult(instanceInfoList); + baseDataResponse.setCount(tagDTOPageData.getTotal()); + instanceResponse.setData(baseDataResponse); + return instanceResponse; + } +} diff --git a/src/backend/commons/common-redis/build.gradle b/src/backend/commons/common-redis/build.gradle index 8403ab1b9d..221d0d6a4b 100644 --- a/src/backend/commons/common-redis/build.gradle +++ b/src/backend/commons/common-redis/build.gradle @@ -24,9 +24,9 @@ apply plugin: 'java' dependencies { - compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') - compile(group: 'org.springframework.boot', name: 'spring-boot-configuration-processor') - compile(group: 'org.apache.commons', name: 'commons-pool2') - compile project(":commons:common-utils") - compile project(":commons:common") + api(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') + api(group: 'org.springframework.boot', name: 'spring-boot-configuration-processor') + api(group: 'org.apache.commons', name: 'commons-pool2') + api project(":commons:common-utils") + api project(":commons:common") } diff --git a/src/backend/commons/common-security/build.gradle b/src/backend/commons/common-security/build.gradle index ccc7d781dd..ff1ff02ece 100644 --- a/src/backend/commons/common-security/build.gradle +++ b/src/backend/commons/common-security/build.gradle @@ -24,12 +24,12 @@ apply plugin: 'java' dependencies { - compile project(":commons:common-utils") + api project(":commons:common-utils") implementation 'io.jsonwebtoken:jjwt' implementation 'com.google.guava:guava' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' - compile(group: 'org.springframework.boot', name: 'spring-boot') - compile(group: 'org.springframework.boot', name: 'spring-boot-autoconfigure') + api(group: 'org.springframework.boot', name: 'spring-boot') + api(group: 'org.springframework.boot', name: 'spring-boot-autoconfigure') implementation 'org.springframework:spring-context' - compile(group: 'org.springframework.boot', name: 'spring-boot-configuration-processor') + api(group: 'org.springframework.boot', name: 'spring-boot-configuration-processor') } diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/autoconfigure/ServiceSecurityAutoConfiguration.java b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/autoconfigure/ServiceSecurityAutoConfiguration.java index cdb3b70677..929c828213 100644 --- a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/autoconfigure/ServiceSecurityAutoConfiguration.java +++ b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/autoconfigure/ServiceSecurityAutoConfiguration.java @@ -24,7 +24,8 @@ package com.tencent.bk.job.common.security.autoconfigure; -import com.tencent.bk.job.common.security.jwt.JwtManager; +import com.tencent.bk.job.common.security.jwt.AutoUpdateJwtManager; +import com.tencent.bk.job.common.util.jwt.JwtManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -44,7 +45,10 @@ public class ServiceSecurityAutoConfiguration { @ConditionalOnMissingBean(name = "jwtManager") JwtManager jwtManager(@Autowired ServiceSecurityProperties securityProperties) throws IOException, GeneralSecurityException { - return new JwtManager(securityProperties.getPrivateKeyBase64(), securityProperties.getPublicKeyBase64()); + return new AutoUpdateJwtManager( + securityProperties.getPrivateKeyBase64(), + securityProperties.getPublicKeyBase64() + ); } } diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignBasicAuthRequestInterceptor.java b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignBasicAuthRequestInterceptor.java index 4e5fc4a9c6..cca93f1d90 100644 --- a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignBasicAuthRequestInterceptor.java +++ b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignBasicAuthRequestInterceptor.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.common.security.feign; -import com.tencent.bk.job.common.security.jwt.JwtManager; +import com.tencent.bk.job.common.util.jwt.JwtManager; import feign.RequestInterceptor; import feign.RequestTemplate; import lombok.extern.slf4j.Slf4j; diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignSecurityConfiguration.java b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignSecurityConfiguration.java new file mode 100644 index 0000000000..d9ca0cb5df --- /dev/null +++ b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignSecurityConfiguration.java @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.security.feign; + +import com.tencent.bk.job.common.util.jwt.JwtManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FeignSecurityConfiguration { + + /** + * Feign 服务认证拦截 + * + * @param jwtManager jwt管理 + * @return + */ + @Bean + public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor(@Autowired JwtManager jwtManager) { + return new FeignBasicAuthRequestInterceptor(jwtManager); + } + +} + diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/AutoUpdateJwtManager.java b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/AutoUpdateJwtManager.java new file mode 100644 index 0000000000..76dc95b062 --- /dev/null +++ b/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/AutoUpdateJwtManager.java @@ -0,0 +1,22 @@ +package com.tencent.bk.job.common.security.jwt; + +import com.tencent.bk.job.common.util.jwt.BasicJwtManager; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +@Slf4j +public class AutoUpdateJwtManager extends BasicJwtManager { + public AutoUpdateJwtManager(String privateKeyBase64, String publicKeyBase64) + throws IOException, GeneralSecurityException { + super(privateKeyBase64, publicKeyBase64); + } + + @Scheduled(fixedDelay = 5 * 60 * 1000) + public void refreshToken() { + log.info("Refresh token"); + generateToken(); + } +} diff --git a/src/backend/commons/common-utils/build.gradle b/src/backend/commons/common-utils/build.gradle index 2a3a69fb73..c7089ac749 100644 --- a/src/backend/commons/common-utils/build.gradle +++ b/src/backend/commons/common-utils/build.gradle @@ -32,7 +32,7 @@ dependencies { implementation 'commons-codec:commons-codec' implementation 'com.google.guava:guava' implementation 'io.jsonwebtoken:jjwt' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation "org.junit.jupiter:junit-jupiter" diff --git a/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/crypto/AESUtils.java b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/crypto/AESUtils.java index d1eb17fe7c..d8ec577ccc 100644 --- a/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/crypto/AESUtils.java +++ b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/crypto/AESUtils.java @@ -71,14 +71,25 @@ public static byte[] encrypt(String data, String password) throws Exception { * * @param data 待加密数据 * @param password 密钥 - * @return byte[] 加密后的数据 + * @return String 加密后的数据 */ public static String encryptToBase64EncodedCipherText(byte[] data, String password) throws Exception { return Base64Util.encodeContentToStr(encrypt(data, password.getBytes(StandardCharsets.UTF_8))); } /** - * 加密数据 + * 解密base64编码的数据,并转换成字符明文 + * + * @param data 待解密数据,base64编码 + * @param password 密钥 + * @return String 解密后的数据 + */ + public static String decryptBase64EncodedDataToPlainText(String data, String password) throws Exception { + return decryptToPlainText(Base64Util.decodeContentToByte(data), password); + } + + /** + * 加密数据,并是使用base64编码 * * @param data 待加密数据 * @param password 密钥 diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/JwtManager.java b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/BasicJwtManager.java similarity index 82% rename from src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/JwtManager.java rename to src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/BasicJwtManager.java index 28b5edde09..d6f3342a1c 100644 --- a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/jwt/JwtManager.java +++ b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/BasicJwtManager.java @@ -22,7 +22,7 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.security.jwt; +package com.tencent.bk.job.common.util.jwt; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -32,7 +32,6 @@ import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import java.io.IOException; import java.security.GeneralSecurityException; @@ -44,16 +43,16 @@ @Slf4j -public class JwtManager { +public class BasicJwtManager implements JwtManager { private volatile String token = null; - private PublicKey publicKey; - private PrivateKey privateKey; + private final PublicKey publicKey; + private final PrivateKey privateKey; - private Cache tokenCache = CacheBuilder.newBuilder() + private final Cache tokenCache = CacheBuilder.newBuilder() .maximumSize(9999).expireAfterWrite(5, TimeUnit.MINUTES).build(); - public JwtManager(String privateKeyBase64, - String publicKeyBase64) throws IOException, GeneralSecurityException { + public BasicJwtManager(String privateKeyBase64, + String publicKeyBase64) throws IOException, GeneralSecurityException { this.privateKey = RSAUtils.getPrivateKey(privateKeyBase64); this.publicKey = RSAUtils.getPublicKey(publicKeyBase64); log.info("Init JwtManager successfully!"); @@ -64,6 +63,7 @@ public JwtManager(String privateKeyBase64, * * @return */ + @Override public String getToken() { if (token != null) { return token; @@ -71,20 +71,27 @@ public String getToken() { return generateToken(); } - private String generateToken() { + @Override + public String generateToken(long expireMills) { // token 超时10min - long expireAt = System.currentTimeMillis() + 1000 * 60 * 10; + long expireAt = System.currentTimeMillis() + expireMills; this.token = Jwts.builder().setSubject("job-service-auth").setExpiration(new Date(expireAt)) .signWith(SignatureAlgorithm.RS512, privateKey).compact(); return token; } + public String generateToken() { + // token 默认超时10min + return generateToken(10 * 60 * 1000); + } + /** * 验证JWT * * @param token jwt token * @return */ + @Override public boolean verifyJwt(String token) { long start = System.currentTimeMillis(); Long tokenExpireAt = tokenCache.getIfPresent(token); @@ -106,23 +113,17 @@ public boolean verifyJwt(String token) { tokenCache.put(token, expireAt.getTime()); } } catch (ExpiredJwtException e) { - log.warn("Token is expire!", e); + log.error("Token is expire!", e); return false; } catch (Exception e) { - log.warn("Verify jwt caught exception", e); + log.error("Verify jwt caught exception", e); return false; } finally { long cost = System.currentTimeMillis() - start; - if (cost > 5) { + if (cost > 10) { log.warn("Verify jwt cost too much, cost:{}", cost); } } return true; } - - @Scheduled(fixedDelay = 5 * 60 * 1000) - public void refreshToken() { - log.info("Refresh token"); - generateToken(); - } } diff --git a/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/JwtManager.java b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/JwtManager.java new file mode 100644 index 0000000000..edfbf16267 --- /dev/null +++ b/src/backend/commons/common-utils/src/main/java/com/tencent/bk/job/common/util/jwt/JwtManager.java @@ -0,0 +1,9 @@ +package com.tencent.bk.job.common.util.jwt; + +public interface JwtManager { + String getToken(); + + String generateToken(long expireMills); + + boolean verifyJwt(String token); +} diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/consts/BkConsts.java b/src/backend/commons/common-utils/src/test/java/com/tencent/bk/job/common/util/crypto/AESUtilsTest.java similarity index 62% rename from src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/consts/BkConsts.java rename to src/backend/commons/common-utils/src/test/java/com/tencent/bk/job/common/util/crypto/AESUtilsTest.java index 0e915ff9da..bcc191d214 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/consts/BkConsts.java +++ b/src/backend/commons/common-utils/src/test/java/com/tencent/bk/job/common/util/crypto/AESUtilsTest.java @@ -22,25 +22,27 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.esb.consts; +package com.tencent.bk.job.common.util.crypto; -/** - * 常量定义 - */ -public final class BkConsts { +import org.junit.jupiter.api.Test; - public static final String X_CSRF_KEY = "X-CSRFToken"; - public static final String CSRF_KEY = "csrftoken"; - public static final String C_BK_TOKEN = "bk_token"; - public static final String C_BK_UID = "bk_uid"; - public static final String C_BK_TICKET = "bk_ticket"; - public static final String SYS_LANGUAGE = "lang"; - public static final String USER_SESSION = "user"; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - public static final String STATIC_VERSION = "STATIC_VERSION"; // 静态资源URL - public static final String APP_ID = "APP_ID"; - public static final String SITE_URL = "SITE_URL"; //APP URL +public class AESUtilsTest { + @Test + void testEncryptToBase64EncodedCipherText() throws Exception { + String text = "job"; + String encryptPassword = "job#123"; + String encryptedData = AESUtils.encryptToBase64EncodedCipherText(text, encryptPassword); + assertThat(encryptedData).isNotEmpty(); + } + @Test + void testDecryptBase64EncodedCipherText() throws Exception { + String encryptedBase64EncodedData = "GQ6kLqtMevL8z/kXGVANQ+VP5o2Bt30yzXALfZbeOoY="; + String encryptPassword = "job#123"; + String decodeData = AESUtils.decryptBase64EncodedDataToPlainText(encryptedBase64EncodedData, encryptPassword); + assertThat(decodeData).isEqualTo("job"); + } - public static final String TZ_ASIA_SHANGHAI = "Asia/Shanghai"; } diff --git a/src/backend/commons/common-web/build.gradle b/src/backend/commons/common-web/build.gradle index 80d3c18cb9..1c3834f63c 100644 --- a/src/backend/commons/common-web/build.gradle +++ b/src/backend/commons/common-web/build.gradle @@ -27,6 +27,12 @@ dependencies { implementation project(":commons:common") implementation project(":commons:common-security") implementation project(":commons:common-spring-ext") + implementation project(":commons:esb-sdk") + implementation project(":commons:common-iam") + implementation 'io.springfox:springfox-swagger2' + implementation "org.hibernate.validator:hibernate-validator" + implementation('jakarta.validation:jakarta.validation-api') implementation "org.springframework.cloud:spring-cloud-starter-sleuth" + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' compileOnly 'org.springframework.boot:spring-boot-starter-web' } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/controller/AbstractJobController.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/controller/AbstractJobController.java index 0f5bb87c8e..3efffdc86d 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/controller/AbstractJobController.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/controller/AbstractJobController.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.common.web.controller; +import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ServiceResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -41,18 +42,27 @@ @Slf4j public abstract class AbstractJobController { + AuthService authService; + + public AbstractJobController(AuthService authService) { + this.authService = authService; + } + public boolean preService(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - log.debug("Default pre service for |{}", handler); + log.debug("Default pre service for {} |{}", request.getRequestURI(), handler); return true; } public void postService(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - log.debug("Default post service for |{}", handler); + log.debug("Default post service for {}|{}", request.getRequestURI(), handler); } @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) - public ServiceResponse messageNotReadable(HttpMessageNotReadableException exception, HttpServletResponse response) { + public ServiceResponse messageNotReadable( + HttpMessageNotReadableException exception, + HttpServletResponse response + ) { log.error("请求参数不匹配", exception); return ServiceResponse.buildCommonFailResp(exception.getMessage()); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/EsbExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java similarity index 73% rename from src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/EsbExceptionControllerAdvice.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java index e7c87b35da..e918f2fd8f 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/EsbExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/EsbExceptionControllerAdvice.java @@ -22,13 +22,19 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.execute.common; +package com.tencent.bk.job.common.web.exception.handler; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.model.error.BadRequestDetail; +import com.tencent.bk.job.common.model.error.ErrorDetail; import lombok.extern.slf4j.Slf4j; +import org.hibernate.validator.spi.nodenameprovider.JavaBeanProperty; import org.springframework.beans.ConversionNotSupportedException; import org.springframework.beans.TypeMismatchException; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +44,8 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException; @@ -55,18 +63,30 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolationException; /** * 处理ESB异常 */ -@ControllerAdvice({"com.tencent.bk.job.execute.api.esb"}) +@ControllerAdvice(annotations = {EsbAPI.class}) @Slf4j public class EsbExceptionControllerAdvice extends ResponseEntityExceptionHandler { private final MessageI18nService i18nService; + private final AuthService authService; @Autowired - public EsbExceptionControllerAdvice(MessageI18nService i18nService) { + public EsbExceptionControllerAdvice(MessageI18nService i18nService, AuthService authService) { this.i18nService = i18nService; + this.authService = authService; + } + + @ExceptionHandler(InSufficientPermissionException.class) + @ResponseBody + ResponseEntity handleControllerInSufficientPermissionException(HttpServletRequest request, ServiceException ex) { + log.warn("Handle service exception", ex); + // esb请求错误统一返回200,具体的错误信息放在返回数据里边 + return new ResponseEntity<>(authService.buildEsbAuthFailResp((InSufficientPermissionException) ex), + HttpStatus.OK); } @ExceptionHandler(ServiceException.class) @@ -87,12 +107,20 @@ ResponseEntity handleControllerException(HttpServletRequest request, Throwabl HttpStatus.OK); } + @ExceptionHandler(ConstraintViolationException.class) + @ResponseBody + ResponseEntity handleConstraintViolationException(HttpServletRequest request, + ConstraintViolationException ex) { + log.warn("Handle ConstraintViolationException", ex); + EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + return new ResponseEntity<>(resp, HttpStatus.OK); + } @Override protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpRequestMethodNotSupportedException, cause:{}", ex.getMessage()); + log.warn("Handle HttpRequestMethodNotSupportedException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -101,7 +129,7 @@ protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequest protected ResponseEntity handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMediaTypeNotSupportedException, cause:{}", ex.getMessage()); + log.warn("Handle HttpMediaTypeNotSupportedException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -110,7 +138,7 @@ protected ResponseEntity handleHttpMediaTypeNotSupported(HttpMediaTypeNo protected ResponseEntity handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMediaTypeNotAcceptableException, cause:{}", ex.getMessage()); + log.warn("Handle HttpMediaTypeNotAcceptableException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -118,7 +146,7 @@ protected ResponseEntity handleHttpMediaTypeNotAcceptable(HttpMediaTypeN @Override protected ResponseEntity handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingPathVariableException, cause:{}", ex.getMessage()); + log.warn("Handle MissingPathVariableException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -127,7 +155,7 @@ protected ResponseEntity handleMissingPathVariable(MissingPathVariableEx protected ResponseEntity handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingServletRequestParameterException, cause:{}", ex.getMessage()); + log.warn("Handle MissingServletRequestParameterException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -136,7 +164,7 @@ protected ResponseEntity handleMissingServletRequestParameter(MissingSer protected ResponseEntity handleServletRequestBindingException(ServletRequestBindingException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch ServletRequestBindingException, cause:{}", ex.getMessage()); + log.warn("Handle ServletRequestBindingException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -145,7 +173,7 @@ protected ResponseEntity handleServletRequestBindingException(ServletReq protected ResponseEntity handleConversionNotSupported(ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch ConversionNotSupportedException, cause:{}", ex.getMessage()); + log.warn("Handle ConversionNotSupportedException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -153,7 +181,7 @@ protected ResponseEntity handleConversionNotSupported(ConversionNotSuppo @Override protected ResponseEntity handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch TypeMismatchException, cause:{}", ex.getMessage()); + log.warn("Handle TypeMismatchException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -162,7 +190,7 @@ protected ResponseEntity handleTypeMismatch(TypeMismatchException ex, Ht protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMessageNotReadableException, cause:{}", ex.getMessage()); + log.warn("Handle HttpMessageNotReadableException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -171,7 +199,7 @@ protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotRead protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMessageNotWritableException, cause:{}", ex.getMessage()); + log.warn("Handle HttpMessageNotWritableException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -180,16 +208,58 @@ protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWrit protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MethodArgumentNotValidException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle MethodArgumentNotValidException", ex); + BindingResult bindingResult = ex.getBindingResult(); + + EsbResp resp = null; + for (FieldError fieldError : bindingResult.getFieldErrors()) { + // fail fast + BadRequestDetail badRequestDetail = new BadRequestDetail(fieldError.getField(), + null, + fieldError.getDefaultMessage()); + ErrorDetail errorDetail = new ErrorDetail(badRequestDetail); + resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, errorDetail, i18nService); + break; + } return new ResponseEntity<>(resp, HttpStatus.OK); } + private String getFieldName(String field) { + if (!field.contains(".")) { + return field; + } + String[] fieldPath = field.split("\\."); + if (fieldPath.length == 0) { + return field; + } + return fieldPath[fieldPath.length - 1]; + } + + private static class JavaBeanPropertyImpl implements JavaBeanProperty { + private final Class declaringClass; + private final String name; + + private JavaBeanPropertyImpl(Class declaringClass, String name) { + this.declaringClass = declaringClass; + this.name = name; + } + + @Override + public Class getDeclaringClass() { + return declaringClass; + } + + @Override + public String getName() { + return name; + } + } + @Override protected ResponseEntity handleMissingServletRequestPart(MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingServletRequestPartException, cause:{}", ex.getMessage()); + log.warn("Handle MissingServletRequestPartException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -197,7 +267,7 @@ protected ResponseEntity handleMissingServletRequestPart(MissingServletR @Override protected ResponseEntity handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch BindException, cause:{}", ex.getMessage()); + log.warn("Handle BindException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -205,7 +275,7 @@ protected ResponseEntity handleBindException(BindException ex, HttpHeade @Override protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch NoHandlerFoundException, cause:{}", ex.getMessage()); + log.warn("Handle NoHandlerFoundException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -214,7 +284,7 @@ protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundExc protected ResponseEntity handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { - log.warn("Catch AsyncRequestTimeoutException, cause:{}", ex.getMessage()); + log.warn("Handle AsyncRequestTimeoutException", ex); EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/ServiceExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java similarity index 84% rename from src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/ServiceExceptionControllerAdvice.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java index ea90bb0db7..bbdf98788f 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/ServiceExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/ServiceExceptionControllerAdvice.java @@ -22,15 +22,15 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.execute.common; +package com.tencent.bk.job.common.web.exception.handler; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -42,7 +42,7 @@ import javax.servlet.http.HttpServletRequest; -@ControllerAdvice({"com.tencent.bk.job.execute.api.inner"}) +@ControllerAdvice(annotations = {InternalAPI.class}) @Slf4j public class ServiceExceptionControllerAdvice extends ResponseEntityExceptionHandler { private final MessageI18nService i18nService; @@ -81,18 +81,6 @@ ResponseEntity handleControllerException(HttpServletRequest request, Throwabl i18nService), status); } - @ExceptionHandler(FeignException.class) - @ResponseBody - ResponseEntity handleFeignException(HttpServletRequest request, FeignException ex) { - log.warn("Handle feign exception", ex); - if (ex.status() == HttpStatus.UNAUTHORIZED.value()) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_AUTH_FAIL, i18nService) - , HttpStatus.UNAUTHORIZED); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), HttpStatus.INTERNAL_SERVER_ERROR); - } - } private HttpStatus getStatus(HttpServletRequest request) { Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/EsbExceptionControllerAdvice.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java similarity index 61% rename from src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/EsbExceptionControllerAdvice.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java index f8afc459f2..ecf833d946 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/EsbExceptionControllerAdvice.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/exception/handler/WebExceptionControllerAdvice.java @@ -22,13 +22,19 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.crontab.common; +package com.tencent.bk.job.common.web.exception.handler; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.WebAuthService; +import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.ConversionNotSupportedException; import org.springframework.beans.TypeMismatchException; import org.springframework.beans.factory.annotation.Autowired; @@ -55,44 +61,77 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolationException; -/** - * 处理ESB异常 - */ -@ControllerAdvice({"com.tencent.bk.job.crontab.api.esb"}) +@ControllerAdvice(annotations = {WebAPI.class}) @Slf4j -public class EsbExceptionControllerAdvice extends ResponseEntityExceptionHandler { +public class WebExceptionControllerAdvice extends ResponseEntityExceptionHandler { private final MessageI18nService i18nService; + private final WebAuthService webAuthService; @Autowired - public EsbExceptionControllerAdvice(MessageI18nService i18nService) { + public WebExceptionControllerAdvice(MessageI18nService i18nService, WebAuthService webAuthService) { this.i18nService = i18nService; + this.webAuthService = webAuthService; } @ExceptionHandler(ServiceException.class) @ResponseBody ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.warn("Handle service exception", ex); - // esb请求错误统一返回200,具体的错误信息放在返回数据里边 - return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex.getErrorCode(), i18nService), HttpStatus.OK); + if (ex instanceof HttpStatusServiceException) { + log.warn("Handle service exception", ex); + HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; + return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException, i18nService), + httpStatusServiceException.getHttpStatus()); + } else if (ex instanceof InSufficientPermissionException) { + InSufficientPermissionException inSufficientPermissionException = (InSufficientPermissionException) ex; + AuthResult authResult = inSufficientPermissionException.getAuthResult(); + log.debug("Insufficient permission, authResult: {}", authResult); + if (StringUtils.isEmpty(authResult.getApplyUrl())) { + authResult.setApplyUrl(webAuthService.getApplyUrl(authResult.getRequiredActionResources())); + } + return new ResponseEntity<>(ServiceResponse.buildAuthFailResp( + webAuthService.toAuthResultVO(inSufficientPermissionException.getAuthResult())), HttpStatus.OK); + } else { + log.warn("Handle service exception", ex); + return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex, i18nService), + HttpStatus.OK); + } } @ExceptionHandler(Throwable.class) @ResponseBody ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { log.warn("Handle exception", ex); - // esb请求错误统一返回200,具体的错误信息放在返回数据里边 - return new ResponseEntity<>(EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService), - HttpStatus.OK); + // 默认处理 + HttpStatus status = getStatus(request); + return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, + i18nService), status); } + private HttpStatus getStatus(HttpServletRequest request) { + Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); + if (statusCode == null) { + return HttpStatus.INTERNAL_SERVER_ERROR; + } + return HttpStatus.valueOf(statusCode); + } + + @ExceptionHandler(ConstraintViolationException.class) + @ResponseBody + ResponseEntity handleConstraintViolationException(HttpServletRequest request, + ConstraintViolationException ex) { + log.warn("Handle ConstraintViolationException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + return new ResponseEntity<>(resp, HttpStatus.OK); + } @Override protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpRequestMethodNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle HttpRequestMethodNotSupportedException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -100,8 +139,8 @@ protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequest protected ResponseEntity handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMediaTypeNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle HttpMediaTypeNotSupportedException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -109,16 +148,16 @@ protected ResponseEntity handleHttpMediaTypeNotSupported(HttpMediaTypeNo protected ResponseEntity handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMediaTypeNotAcceptableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle HttpMediaTypeNotAcceptableException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @Override protected ResponseEntity handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingPathVariableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); + log.warn("Handle MissingPathVariableException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -126,8 +165,8 @@ protected ResponseEntity handleMissingPathVariable(MissingPathVariableEx protected ResponseEntity handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingServletRequestParameterException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle MissingServletRequestParameterException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -135,8 +174,8 @@ protected ResponseEntity handleMissingServletRequestParameter(MissingSer protected ResponseEntity handleServletRequestBindingException(ServletRequestBindingException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch ServletRequestBindingException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle ServletRequestBindingException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -144,16 +183,16 @@ protected ResponseEntity handleServletRequestBindingException(ServletReq protected ResponseEntity handleConversionNotSupported(ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch ConversionNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); + log.warn("Handle ConversionNotSupportedException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @Override protected ResponseEntity handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch TypeMismatchException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle TypeMismatchException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -161,8 +200,8 @@ protected ResponseEntity handleTypeMismatch(TypeMismatchException ex, Ht protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMessageNotReadableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle HttpMessageNotReadableException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -170,8 +209,8 @@ protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotRead protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch HttpMessageNotWritableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); + log.warn("Handle HttpMessageNotWritableException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -179,8 +218,8 @@ protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWrit protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MethodArgumentNotValidException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle MethodArgumentNotValidException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -188,24 +227,24 @@ protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotV protected ResponseEntity handleMissingServletRequestPart(MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch MissingServletRequestPartException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle MissingServletRequestPartException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @Override protected ResponseEntity handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch BindException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle BindException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @Override protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { - log.warn("Catch NoHandlerFoundException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); + log.warn("Handle NoHandlerFoundException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } @@ -213,8 +252,9 @@ protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundExc protected ResponseEntity handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { - log.warn("Catch AsyncRequestTimeoutException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); + log.warn("Handle AsyncRequestTimeoutException", ex); + ServiceResponse resp = ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); return new ResponseEntity<>(resp, HttpStatus.OK); } + } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignAddHeaderRequestInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignAddHeaderRequestInterceptor.java new file mode 100644 index 0000000000..739ed7780f --- /dev/null +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignAddHeaderRequestInterceptor.java @@ -0,0 +1,40 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.web.feign; + +import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.util.JobContextUtil; +import feign.RequestInterceptor; +import feign.RequestTemplate; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class FeignAddHeaderRequestInterceptor implements RequestInterceptor { + @Override + public void apply(RequestTemplate template) { + String lang = JobContextUtil.getUserLang(); + template.header(LocaleUtils.COMMON_LANG_HEADER, lang); + } +} diff --git a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignConfiguration.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignConfiguration.java similarity index 78% rename from src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignConfiguration.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignConfiguration.java index d611edf681..d66849ba3e 100644 --- a/src/backend/commons/common-security/src/main/java/com/tencent/bk/job/common/security/feign/FeignConfiguration.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/feign/FeignConfiguration.java @@ -22,26 +22,15 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.security.feign; +package com.tencent.bk.job.common.web.feign; -import com.tencent.bk.job.common.security.jwt.JwtManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class FeignConfiguration { - - /** - * Feign 服务认证拦截 - * - * @param jwtManager jwt管理 - * @return - */ @Bean - public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor(@Autowired JwtManager jwtManager) { - return new FeignBasicAuthRequestInterceptor(jwtManager); + public FeignAddHeaderRequestInterceptor feignAddHeaderRequestInterceptor() { + return new FeignAddHeaderRequestInterceptor(); } - } - diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadServletRequestResponseFilter.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadWriteServletRequestResponseFilter.java similarity index 79% rename from src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadServletRequestResponseFilter.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadWriteServletRequestResponseFilter.java index fe4c138947..a48aeebe73 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadServletRequestResponseFilter.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/filter/RepeatableReadWriteServletRequestResponseFilter.java @@ -24,26 +24,31 @@ package com.tencent.bk.job.common.web.filter; -import com.tencent.bk.job.common.web.model.RepeatableReadHttpServletRequest; import com.tencent.bk.job.common.web.model.RepeatableReadHttpServletResponse; +import com.tencent.bk.job.common.web.model.RepeatableReadWriteHttpServletRequest; import lombok.extern.slf4j.Slf4j; -import javax.servlet.*; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Slf4j -public class RepeatableReadServletRequestResponseFilter implements Filter { +public class RepeatableReadWriteServletRequestResponseFilter implements Filter { @Override - public void init(FilterConfig filterConfig) throws ServletException { + public void init(FilterConfig filterConfig) { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - ServletRequest requestWrapper = new RepeatableReadHttpServletRequest((HttpServletRequest) request); + ServletRequest requestWrapper = new RepeatableReadWriteHttpServletRequest((HttpServletRequest) request); ServletResponse responseWrapper = new RepeatableReadHttpServletResponse((HttpServletResponse) response); chain.doFilter(requestWrapper, responseWrapper); } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/I18nConfig.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/I18nConfig.java new file mode 100644 index 0000000000..f2337f4fff --- /dev/null +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/I18nConfig.java @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.web.i18n; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Locale; + +@Configuration +@Slf4j +public class I18nConfig { + + @Bean("localeResolver") + public JobLangHeaderLocaleResolver localeResolver() { + log.info("Init JobLangHeaderLocaleResolver"); + JobLangHeaderLocaleResolver resolver = new JobLangHeaderLocaleResolver(); + resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); + return resolver; + } +} + diff --git a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/common/i18n/JobLangHeaderLocaleResolver.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/JobLangHeaderLocaleResolver.java similarity index 78% rename from src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/common/i18n/JobLangHeaderLocaleResolver.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/JobLangHeaderLocaleResolver.java index 52a44e941c..cd5191db7d 100644 --- a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/common/i18n/JobLangHeaderLocaleResolver.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/i18n/JobLangHeaderLocaleResolver.java @@ -22,11 +22,12 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.execute.common.i18n; +package com.tencent.bk.job.common.web.i18n; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.lang.Nullable; -import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleResolver; import javax.servlet.http.HttpServletRequest; @@ -36,6 +37,7 @@ /** * Job 自定义国际化LocaleResolver */ +@Slf4j public class JobLangHeaderLocaleResolver implements LocaleResolver { @Nullable private Locale defaultLocale; @@ -53,17 +55,21 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) { } public Locale resolveLocale(HttpServletRequest request) { - Locale defaultLocale = getDefaultLocale(); - if (defaultLocale != null && StringUtils.isEmpty(request.getHeader(LocaleUtils.COMMON_LANG_HEADER))) { - return defaultLocale; - } else { + if (StringUtils.isNotBlank(request.getHeader(LocaleUtils.COMMON_LANG_HEADER))) { String lang = request.getHeader(LocaleUtils.COMMON_LANG_HEADER); - return LocaleUtils.getLocale(lang); + Locale locale = LocaleUtils.getLocale(lang); + if (locale == null) { + locale = getDefaultLocale(); + } + return locale; + } else { + return getDefaultLocale(); } } - public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) { - throw new UnsupportedOperationException("Cannot change HTTP accept header - use a different locale resolution" + - " strategy"); + public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, + @Nullable Locale locale) { + throw new UnsupportedOperationException( + "Cannot change HTTP accept header - use a different locale resolution strategy"); } } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java index 18fb3e3fe7..05390a6996 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbApiLogInterceptor.java @@ -26,9 +26,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.model.RepeatableReadHttpServletRequest; import com.tencent.bk.job.common.web.model.RepeatableReadHttpServletResponse; +import com.tencent.bk.job.common.web.model.RepeatableReadWriteHttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; @@ -43,24 +44,29 @@ @Component public class EsbApiLogInterceptor extends HandlerInterceptorAdapter { + private static final String ATTR_REQUEST_START = "request-start"; + private static final String ATTR_API_NAME = "api-name"; + private static final String ATTR_USERNAME = "username"; + private static final String ATTR_APP_CODE = "app-code"; + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - if (!(request instanceof RepeatableReadHttpServletRequest)) { + if (!(request instanceof RepeatableReadWriteHttpServletRequest)) { return true; } - RepeatableReadHttpServletRequest wrapperRequest = (RepeatableReadHttpServletRequest) request; + RepeatableReadWriteHttpServletRequest wrapperRequest = (RepeatableReadWriteHttpServletRequest) request; String desensitizedBody = ""; String desensitizedQueryParams = ""; String username = ""; String appCode = ""; String apiName = ""; - String lang = request.getHeader("blueking-language"); - String requestId = request.getHeader("x-bkapi-request-id"); + String lang = request.getHeader(JobCommonHeaders.BK_GATEWAY_LANG); + String requestId = request.getHeader(JobCommonHeaders.BK_GATEWAY_REQUEST_ID); try { - request.setAttribute("request-start", System.currentTimeMillis()); + request.setAttribute(ATTR_REQUEST_START, System.currentTimeMillis()); apiName = getAPIName(wrapperRequest.getRequestURI()); - request.setAttribute("api-name", apiName); + request.setAttribute(ATTR_API_NAME, apiName); if (request.getMethod().equals(HttpMethod.POST.name()) || request.getMethod().equals(HttpMethod.PUT.name())) { if (StringUtils.isNotBlank(wrapperRequest.getBody())) { @@ -80,8 +86,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons appCode = request.getParameter("bk_app_code"); desensitizedQueryParams = desensitizeQueryParams(request.getQueryString()); - request.setAttribute("username", username); - request.setAttribute("app-code", appCode); + request.setAttribute(ATTR_USERNAME, username); + request.setAttribute(ATTR_APP_CODE, appCode); } } catch (Throwable e) { return true; @@ -129,11 +135,11 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp } RepeatableReadHttpServletResponse wrapperResponse = (RepeatableReadHttpServletResponse) response; try { - Long startTimeInMills = (Long) request.getAttribute("request-start"); - String apiName = (String) request.getAttribute("api-name"); - String appCode = (String) request.getAttribute("app-code"); - String username = (String) request.getAttribute("username"); - String requestId = request.getHeader("x-bkapi-request-id"); + Long startTimeInMills = (Long) request.getAttribute(ATTR_REQUEST_START); + String apiName = (String) request.getAttribute(ATTR_API_NAME); + String appCode = (String) request.getAttribute(ATTR_APP_CODE); + String username = (String) request.getAttribute(ATTR_USERNAME); + String requestId = request.getHeader(JobCommonHeaders.BK_GATEWAY_REQUEST_ID); int respStatus = response.getStatus(); long cost = System.currentTimeMillis() - startTimeInMills; log.info("request-id:{}|API:{}|uri:{}|appCode:{}|username:{}|status:{}|resp:{}|cost:{}", requestId, apiName, diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java new file mode 100644 index 0000000000..7db4312af7 --- /dev/null +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/EsbReqRewriteInterceptor.java @@ -0,0 +1,100 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.web.interceptor; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; +import com.tencent.bk.job.common.constant.JobCommonHeaders; +import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.job.common.web.model.RepeatableReadWriteHttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Slf4j +@Component +public class EsbReqRewriteInterceptor extends HandlerInterceptorAdapter { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + if (!(request instanceof RepeatableReadWriteHttpServletRequest)) { + return true; + } + RepeatableReadWriteHttpServletRequest wrapperRequest = (RepeatableReadWriteHttpServletRequest) request; + + String appCode = request.getHeader(JobCommonHeaders.APP_CODE); + String username = request.getHeader(JobCommonHeaders.USERNAME); + + try { + if (request.getMethod().equals(HttpMethod.POST.name()) + || request.getMethod().equals(HttpMethod.PUT.name())) { + if (StringUtils.isNotBlank(wrapperRequest.getBody())) { + ObjectNode jsonBody = (ObjectNode) JsonUtils.toJsonNode(wrapperRequest.getBody()); + if (jsonBody == null) { + return true; + } + // reset username and appCode + if (StringUtils.isNotBlank(username)) { + JsonNode bkUserNameNode = jsonBody.get("bk_username"); + if (bkUserNameNode != null && StringUtils.isNotBlank(bkUserNameNode.asText()) + && !bkUserNameNode.asText().equals(username)) { + log.error("Invalid username, usernameInBody: {}, username: {}", bkUserNameNode.asText(), + username); + } + jsonBody.set("bk_username", new TextNode(username)); + } else { + log.error("Header {} is missing", JobCommonHeaders.USERNAME); + } + + if (StringUtils.isNotBlank(appCode)) { + JsonNode bkAppCodeNode = jsonBody.get("bk_app_code"); + if (bkAppCodeNode != null && StringUtils.isNotBlank(bkAppCodeNode.asText()) + && !bkAppCodeNode.asText().equals(appCode)) { + log.error("Invalid appCode, appCodeInBody: {}, appCode: {}", bkAppCodeNode.asText(), + appCode); + } + jsonBody.set("bk_app_code", new TextNode(appCode)); + } else { + log.error("Header {} is missing", JobCommonHeaders.APP_CODE); + } + + // hidden sensitive data + jsonBody.set("bk_app_secret", TextNode.valueOf("***")); + wrapperRequest.setBody(jsonBody.toString()); + } + } + } catch (Throwable e) { + log.warn("Rewrite EsbReq error", e); + return true; + } + return true; + } +} diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/JobCommonInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/JobCommonInterceptor.java index 512dd52ac6..38f8c11746 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/JobCommonInterceptor.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/JobCommonInterceptor.java @@ -25,13 +25,18 @@ package com.tencent.bk.job.common.web.interceptor; import brave.Tracer; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; import com.tencent.bk.job.common.util.ApplicationContextRegister; import com.tencent.bk.job.common.util.JobContextUtil; +import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.common.web.controller.AbstractJobController; +import com.tencent.bk.job.common.web.model.RepeatableReadWriteHttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; @@ -71,7 +76,20 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons JobContextUtil.setRequest(request); JobContextUtil.setResponse(response); + // Web接口Header String username = request.getHeader("username"); + // ESB接口Header + // 网关从JWT中解析出的Username最高优先级 + if (StringUtils.isBlank(username)) { + username = request.getHeader(JobCommonHeaders.USERNAME); + log.debug("username from gateway:{}", username); + } + // QueryString/Body中的Username次优先 + if (StringUtils.isBlank(username)) { + username = parseUsernameFromQueryStringOrBody(request); + log.debug("username from query/body:{}", username); + } + if (StringUtils.isNotBlank(username)) { JobContextUtil.setUsername(username); } @@ -84,25 +102,29 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons JobContextUtil.setUserLang(LocaleUtils.LANG_ZH_CN); } - long appId = parseAppId(request.getRequestURI()); - JobContextUtil.setAppId(appId); + Long appId = parseAppIdFromPath(request.getRequestURI()); + log.debug("appId from path:{}", appId); + if (appId == null) { + appId = parseAppIdFromQueryStringOrBody(request); + log.debug("appId from query/body:{}", appId); + } + if (appId != null) { + JobContextUtil.setAppId(appId); + } return preService(request, response, handler); } private boolean shouldFilter(HttpServletRequest request) { String uri = request.getRequestURI(); // 只拦截web/service/esb的API请求 - if (uri.startsWith("/web/") || uri.startsWith("/service/") || uri.startsWith("/esb/")) { - return true; - } - return false; + return uri.startsWith("/web/") || uri.startsWith("/service/") || uri.startsWith("/esb/"); } - private long parseAppId(String requestURI) { + private Long parseAppIdFromPath(String requestURI) { Matcher matcher = APP_ID_PATTERN.matcher(requestURI); if (matcher.find()) { String appIdStr = matcher.group(1); - long appId = 0; + Long appId = null; try { appId = Long.parseLong(appIdStr); } catch (NumberFormatException e) { @@ -110,7 +132,52 @@ private long parseAppId(String requestURI) { } return appId; } - return 0; + return null; + } + + private String parseUsernameFromQueryStringOrBody(HttpServletRequest request) { + return parseValueFromQueryStringOrBody(request, "bk_username"); + } + + private Long parseAppIdFromQueryStringOrBody(HttpServletRequest request) { + String appIdStr = null; + try { + appIdStr = parseValueFromQueryStringOrBody(request, "bk_biz_id"); + if (appIdStr == null) return null; + return Long.parseLong(appIdStr); + } catch (Exception e) { + log.warn("Fail to parse appId from {}", appIdStr, e); + } + return null; + } + + private String parseValueFromQueryStringOrBody(HttpServletRequest request, String key) { + try { + if (request.getMethod().equals(HttpMethod.POST.name()) + || request.getMethod().equals(HttpMethod.PUT.name())) { + if (!(request instanceof RepeatableReadWriteHttpServletRequest)) { + return null; + } + RepeatableReadWriteHttpServletRequest wrapperRequest = + (RepeatableReadWriteHttpServletRequest) request; + if (StringUtils.isNotBlank(wrapperRequest.getBody())) { + ObjectNode jsonBody = (ObjectNode) JsonUtils.toJsonNode(wrapperRequest.getBody()); + if (jsonBody == null) { + return null; + } + String value = jsonBody.get(key) == null ? null : jsonBody.get(key).asText(); + log.debug("parsed from POST/PUT: {}={}", key, value); + return value; + } + } else if (request.getMethod().equals(HttpMethod.GET.name())) { + String value = request.getParameter(key); + log.debug("parsed from GET: {}={}", key, value); + return value; + } + } catch (Exception e) { + log.warn("Fail to parse {} from request", key, e); + } + return null; } @Override @@ -159,13 +226,9 @@ private AbstractJobController getControllerInstance(HandlerMethod handler) { private boolean preService(HttpServletRequest request, HttpServletResponse response, Object handler) { if (handler instanceof HandlerMethod) { - try { - AbstractJobController controllerInstance = getControllerInstance((HandlerMethod) handler); - if (controllerInstance != null) { - return controllerInstance.preService(request, response, (HandlerMethod) handler); - } - } catch (Exception e) { - log.error("Error while calling pre service method!", e); + AbstractJobController controllerInstance = getControllerInstance((HandlerMethod) handler); + if (controllerInstance != null) { + return controllerInstance.preService(request, response, (HandlerMethod) handler); } return true; } else { @@ -174,14 +237,9 @@ private boolean preService(HttpServletRequest request, HttpServletResponse respo } private void postService(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - try { - AbstractJobController controllerInstance = getControllerInstance(handler); - if (controllerInstance != null) { - controllerInstance.postService(request, response, handler); - } - } catch (Exception e) { - log.error("Error while calling post service method!", e); + AbstractJobController controllerInstance = getControllerInstance(handler); + if (controllerInstance != null) { + controllerInstance.postService(request, response, handler); } } - } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/ServiceSecurityInterceptor.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/ServiceSecurityInterceptor.java index 8409ef2971..9162095b2d 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/ServiceSecurityInterceptor.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/interceptor/ServiceSecurityInterceptor.java @@ -24,8 +24,7 @@ package com.tencent.bk.job.common.web.interceptor; -import com.tencent.bk.job.common.security.autoconfigure.ServiceSecurityProperties; -import com.tencent.bk.job.common.security.jwt.JwtManager; +import com.tencent.bk.job.common.util.jwt.JwtManager; import com.tencent.bk.job.common.web.exception.ServiceNoAuthException; import com.tencent.bk.job.common.web.util.ProfileUtil; import lombok.extern.slf4j.Slf4j; @@ -45,14 +44,11 @@ public class ServiceSecurityInterceptor extends HandlerInterceptorAdapter { private final JwtManager jwtManager; private final ProfileUtil profileUtil; - private final ServiceSecurityProperties securityProperties; @Autowired - public ServiceSecurityInterceptor(JwtManager jwtManager, ProfileUtil profileUtil, - ServiceSecurityProperties securityProperties) { + public ServiceSecurityInterceptor(JwtManager jwtManager, ProfileUtil profileUtil) { this.jwtManager = jwtManager; this.profileUtil = profileUtil; - this.securityProperties = securityProperties; } @@ -61,12 +57,12 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons if (shouldFilter(request)) { String jwt = request.getHeader("x-job-auth-token"); if (StringUtils.isEmpty(jwt)) { - log.warn("Invalid request, jwt is empty! url: {}", request.getRequestURI()); + log.error("Invalid request, jwt is empty! url: {}", request.getRequestURI()); throw new ServiceNoAuthException(); } boolean checkResult = jwtManager.verifyJwt(jwt); if (!checkResult) { - log.warn("Invalid request, jwt is invalid or expired! url: {}", request.getRequestURI()); + log.error("Invalid request, jwt is invalid or expired! url: {}", request.getRequestURI()); throw new ServiceNoAuthException(); } } diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/InnerServiceResponse.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/InnerServiceResponse.java new file mode 100644 index 0000000000..68df06d837 --- /dev/null +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/InnerServiceResponse.java @@ -0,0 +1,208 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.web.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.exception.ServiceException; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.model.ValidateResult; +import com.tencent.bk.job.common.model.error.ErrorDetail; +import com.tencent.bk.job.common.util.ApplicationContextRegister; +import com.tencent.bk.job.common.util.JobContextUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +@Slf4j +@Getter +@Setter +@ToString +@NoArgsConstructor +@ApiModel("服务间调用通用返回结构") +public class InnerServiceResponse { + public static final Integer SUCCESS_CODE = 0; + public static final Integer COMMON_FAIL_CODE = 1; + private static volatile MessageI18nService i18nService; + + @ApiModelProperty("是否成功") + private boolean success; + + @ApiModelProperty("返回码") + private Integer code; + + @ApiModelProperty("错误信息") + private String errorMsg; + + @ApiModelProperty("请求成功返回的数据") + private T data; + + @ApiModelProperty("请求 ID") + private String requestId; + + @ApiModelProperty("鉴权结果,当返回码为1238001时,该字段有值") + @JsonProperty("authResult") + private AuthResult authResult; + + @ApiModelProperty("错误详情") + @JsonProperty("errorDetail") + private ErrorDetail errorDetail; + + public InnerServiceResponse(Integer code, String errorMsg, T data) { + this.code = code; + this.errorMsg = errorMsg; + this.data = data; + this.requestId = JobContextUtil.getRequestId(); + } + + private static MessageI18nService getI18nService() { + if (i18nService == null) { + synchronized (InnerServiceResponse.class) { + if (i18nService == null) { + i18nService = ApplicationContextRegister.getBean(MessageI18nService.class); + } + } + } + return i18nService; + } + + public static InnerServiceResponse buildSuccessResp(T data) { + InnerServiceResponse resp = new InnerServiceResponse<>(SUCCESS_CODE, null, data); + resp.success = true; + return resp; + } + + public static InnerServiceResponse buildAuthFailResp(AuthResult authResult) { + MessageI18nService i18nService = getI18nService(); + String message = null; + if (i18nService != null) { + message = i18nService.getI18n(String.valueOf(ErrorCode.USER_NO_PERMISSION_COMMON)); + } else { + log.warn("cannot find available i18nService"); + } + InnerServiceResponse resp = new InnerServiceResponse(ErrorCode.USER_NO_PERMISSION_COMMON, message, null); + resp.success = false; + resp.authResult = authResult; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(String msg) { + InnerServiceResponse resp = new InnerServiceResponse<>(COMMON_FAIL_CODE, msg, null); + resp.success = false; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(Integer errorCode, String msg) { + InnerServiceResponse resp = new InnerServiceResponse<>(errorCode, msg, null); + resp.success = false; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(Integer errorCode) { + try { + getI18nService(); + } catch (Exception e) { + log.warn("cannot get i18nService from spring context"); + } + String errorMsg = null; + if (i18nService != null) { + errorMsg = i18nService.getI18n(errorCode.toString()); + } + InnerServiceResponse resp = new InnerServiceResponse<>(errorCode, errorMsg, null); + resp.success = false; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(Integer errorCode, MessageI18nService i18nService) { + String errorMsg = i18nService.getI18n(String.valueOf(errorCode)); + if (StringUtils.isEmpty(errorMsg)) { + errorMsg = String.valueOf(errorCode); + } + InnerServiceResponse resp = new InnerServiceResponse<>(errorCode, errorMsg, null); + resp.success = false; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(Integer errorCode, Object[] params) { + getI18nService(); + return buildCommonFailResp(errorCode, params, i18nService); + } + + public static InnerServiceResponse buildCommonFailResp(Integer errorCode, Object[] params, + MessageI18nService i18nService) { + String errorMsg = ""; + if (params != null && params.length > 0) { + errorMsg = i18nService.getI18nWithArgs(String.valueOf(errorCode), params); + } else { + errorMsg = i18nService.getI18n(String.valueOf(errorCode)); + } + if (StringUtils.isEmpty(errorMsg)) { + errorMsg = String.valueOf(errorCode); + } + InnerServiceResponse resp = new InnerServiceResponse<>(errorCode, errorMsg, null); + resp.success = false; + return resp; + } + + public static InnerServiceResponse buildCommonFailResp(ServiceException e, MessageI18nService i18nService) { + log.info("exception: {}|{}|{}", e.getErrorCode(), e.getErrorMsg(), e.getErrorParams()); + int errorCode = e.getErrorCode(); + String errorMsg = e.getErrorMsg(); + if (StringUtils.isEmpty(errorMsg)) { + errorMsg = i18nService.getI18nWithArgs(String.valueOf(errorCode), e.getErrorParams()); + log.info("{}", errorMsg); + } + if (StringUtils.isEmpty(errorMsg)) { + errorMsg = String.valueOf(errorCode); + } + return new InnerServiceResponse<>(e.getErrorCode(), errorMsg, null); + } + + public static InnerServiceResponse buildValidateFailResp(MessageI18nService i18nService, + ValidateResult validateResult) { + if (validateResult.getErrorParams() != null && validateResult.getErrorParams().length > 0) { + return InnerServiceResponse.buildCommonFailResp(validateResult.getErrorCode(), + i18nService.getI18nWithArgs(String.valueOf(validateResult.getErrorCode()), + validateResult.getErrorParams())); + } else { + return InnerServiceResponse.buildCommonFailResp(validateResult.getErrorCode(), + i18nService.getI18n(String.valueOf(validateResult.getErrorCode()))); + } + } + + public static InnerServiceResponse buildCommonFailResp(int errorCode, ErrorDetail errorDetail, + MessageI18nService i18nService) { + String errorMsg = i18nService.getI18n(String.valueOf(errorCode)); + InnerServiceResponse esbResp = new InnerServiceResponse<>(errorCode, errorMsg, null); + esbResp.setErrorDetail(errorDetail); + return esbResp; + } +} diff --git a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadHttpServletRequest.java b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadWriteHttpServletRequest.java similarity index 88% rename from src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadHttpServletRequest.java rename to src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadWriteHttpServletRequest.java index b5ee66ac90..c627dde9a6 100644 --- a/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadHttpServletRequest.java +++ b/src/backend/commons/common-web/src/main/java/com/tencent/bk/job/common/web/model/RepeatableReadWriteHttpServletRequest.java @@ -30,17 +30,21 @@ import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; /** - * 由于HttpServletRequest的InputStream只允许读取一次,为了能够重复读取body,需要用装饰模式来包装 + * 由于HttpServletRequest的InputStream只允许读取一次,为了能够重复读写body,需要用装饰模式来包装 */ @Slf4j -public class RepeatableReadHttpServletRequest extends HttpServletRequestWrapper { - private final String body; +public class RepeatableReadWriteHttpServletRequest extends HttpServletRequestWrapper { + private String body; - public RepeatableReadHttpServletRequest(HttpServletRequest request) { + public RepeatableReadWriteHttpServletRequest(HttpServletRequest request) { super(request); StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; @@ -103,4 +107,8 @@ public BufferedReader getReader() { public String getBody() { return this.body; } + + public void setBody(String newBody) { + this.body = newBody; + } } diff --git a/src/backend/commons/common/build.gradle b/src/backend/commons/common/build.gradle index 5ac664b79d..1020c40ee8 100644 --- a/src/backend/commons/common/build.gradle +++ b/src/backend/commons/common/build.gradle @@ -24,8 +24,8 @@ apply plugin: 'java' dependencies { - compile project(":commons:common-i18n") - compile project(":commons:common-utils") + api project(":commons:common-i18n") + api project(":commons:common-utils") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' @@ -35,8 +35,10 @@ dependencies { implementation 'net.sourceforge.jchardet:jchardet' implementation group: 'org.apache.httpcomponents', name: 'httpclient' implementation "org.springframework:spring-jdbc" + implementation "org.hibernate.validator:hibernate-validator" + implementation('jakarta.validation:jakarta.validation-api') compileOnly "org.springframework:spring-web" - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation "org.junit.jupiter:junit-jupiter" diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/EsbAPI.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/EsbAPI.java new file mode 100644 index 0000000000..2106f9d7ec --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/EsbAPI.java @@ -0,0 +1,35 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.annotation; + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface EsbAPI { +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/InternalAPI.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/InternalAPI.java new file mode 100644 index 0000000000..38e36385bc --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/InternalAPI.java @@ -0,0 +1,36 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface InternalAPI { +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/WebAPI.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/WebAPI.java new file mode 100644 index 0000000000..4799a62560 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/annotation/WebAPI.java @@ -0,0 +1,35 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.annotation; + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface WebAPI { +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java index d53a4c012d..e919d4fa2f 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java @@ -220,6 +220,7 @@ public class ErrorCode { public static final int DANGEROUS_SCRIPT_FORBIDDEN_EXECUTION = 1244019; // 作业执行历史查询时间范围必须小于30天 public static final int TASK_INSTANCE_QUERY_TIME_SPAN_MORE_THAN_30_DAYS = 1244020; + public static final int FILE_TASKS_EXCEEDS_LIMIT = 1244021; // 作业执行 end // 定时作业 start @@ -251,14 +252,12 @@ public class ErrorCode { // 文件网关 start // 文件源不存在:{0} public static final int FILE_SOURCE_NOT_EXIST = 1260001; - // 接入点响应异常:ListBucket,详情:{0} - public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_BUCKET = 1260002; - // 接入点响应异常:ListObjects,详情:{0} - public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_OBJECTS = 1260003; - // 接入点响应异常:DeleteBucket,详情:{0} - public static final int FAIL_TO_REQUEST_FILE_WORKER_DELETE_BUCKET = 1260008; - // 接入点响应异常:DeleteBucketFile,详情:{0} - public static final int FAIL_TO_REQUEST_FILE_WORKER_DELETE_BUCKET_FILE = 1260009; + // 接入点响应异常:ListFileNode,详情:{0} + public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_FILE_NODE = 1260002; + // 接入点响应异常:FileAvailable,详情:{0} + public static final int FAIL_TO_REQUEST_FILE_WORKER_FILE_AVAILABLE = 1260003; + // 接入点响应异常:ExecuteAction,详情:{0} + public static final int FAIL_TO_REQUEST_FILE_WORKER_EXECUTE_ACTION = 1260008; // 文件源别名已存在:{0} public static final int FILE_SOURCE_ALIAS_ALREADY_EXISTS = 1260004; @@ -303,13 +302,13 @@ public class ErrorCode { public static final int API_NO_PERMISSION = 9900403; // ========= 系统错误-请求 ====================// - // 服务不可用 - public static final int SERVICE_INTERNAL_ERROR = 1240002; // 内部服务异常 - public static final int BAD_REQUEST = 1240003; + public static final int SERVICE_INTERNAL_ERROR = 1240002; // 错误的请求 - public static final int COOKIE_ILLEGAL = 1240004; + public static final int BAD_REQUEST = 1240003; // Cookie过期或者不存在 + public static final int COOKIE_ILLEGAL = 1240004; + // 服务不可用 public static final int SERVICE_UNAVAILABLE = 1240001; // 服务认证失败 public static final int SERVICE_AUTH_FAIL = 1240005; diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobCommonHeaders.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobCommonHeaders.java new file mode 100644 index 0000000000..c2692bef8a --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobCommonHeaders.java @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.constant; + +public interface JobCommonHeaders { + + String APP_CODE = "X-AppCode"; + String USERNAME = "X-Username"; + String REQUEST_ID = "X-Bk-Job-Request-Id"; + + /** + * 蓝鲸网关-语言 + */ + String BK_GATEWAY_LANG = "Blueking-Language"; + /** + * 蓝鲸网关-RequestId + */ + String BK_GATEWAY_REQUEST_ID = "X-Bkapi-Request-Id"; + /** + * 蓝鲸网关-JWT + */ + String BK_GATEWAY_JWT = "X-Bkapi-JWT"; +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/constants/JobManageConstants.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobConstants.java similarity index 94% rename from src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/constants/JobManageConstants.java rename to src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobConstants.java index ab80a0d436..160a1bb01c 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/constants/JobManageConstants.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/JobConstants.java @@ -22,9 +22,9 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.manage.common.constants; +package com.tencent.bk.job.common.constant; -public class JobManageConstants { +public class JobConstants { /** * 公共资源对应的业务ID(比如公共脚本) */ diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/ServiceResponse.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/ServiceResponse.java index 7441ef0524..901e08be9b 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/ServiceResponse.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/ServiceResponse.java @@ -27,7 +27,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.model.error.ErrorDetail; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.ApplicationContextRegister; import com.tencent.bk.job.common.util.JobContextUtil; @@ -50,20 +51,30 @@ public class ServiceResponse { public static final Integer SUCCESS_CODE = 0; public static final Integer COMMON_FAIL_CODE = 1; private static volatile MessageI18nService i18nService; + @ApiModelProperty("是否成功") private boolean success; + @ApiModelProperty("返回码") private Integer code; + @ApiModelProperty("错误信息") private String errorMsg; + @ApiModelProperty("请求成功返回的数据") private T data; + @ApiModelProperty("请求 ID") private String requestId; + @ApiModelProperty("鉴权结果,当返回码为1238001时,该字段有值") @JsonProperty("authResult") private AuthResultVO authResult; + @ApiModelProperty("错误详情") + @JsonProperty("errorDetail") + private ErrorDetail errorDetail; + public ServiceResponse(Integer code, String errorMsg, T data) { this.code = code; this.errorMsg = errorMsg; @@ -185,4 +196,12 @@ public static ServiceResponse buildValidateFailResp(MessageI18nService i1 i18nService.getI18n(String.valueOf(validateResult.getErrorCode()))); } } + + public static ServiceResponse buildCommonFailResp(int errorCode, ErrorDetail errorDetail, + MessageI18nService i18nService) { + String errorMsg = i18nService.getI18n(String.valueOf(errorCode)); + ServiceResponse esbResp = new ServiceResponse<>(errorCode, errorMsg, null); + esbResp.setErrorDetail(errorDetail); + return esbResp; + } } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/BadRequestDetail.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/BadRequestDetail.java new file mode 100644 index 0000000000..375ea50c24 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/BadRequestDetail.java @@ -0,0 +1,65 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.model.error; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BadRequestDetail { + + @JsonProperty("field_violations") + private List fieldViolations; + + public BadRequestDetail(String field, String rejectedValue, String description) { + this.fieldViolations = new ArrayList<>(); + this.fieldViolations.add(new FieldViolation(field, rejectedValue, description)); + } + + @Data + @JsonInclude(JsonInclude.Include.NON_NULL) + private static class FieldViolation { + @JsonProperty("field") + private String field; + @JsonProperty("rejected_value") + private String rejectedValue; + @JsonProperty("description") + private String description; + + FieldViolation(String field, String rejectedValue, String description) { + this.field = field; + this.rejectedValue = rejectedValue; + this.description = description; + } + } + +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorDetail.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorDetail.java new file mode 100644 index 0000000000..0d78ff3ed9 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorDetail.java @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.model.error; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class ErrorDetail { + /** + * @see ErrorType + */ + private Integer type; + + @JsonProperty("bad_request_detail") + private BadRequestDetail badRequestDetail; + + public ErrorDetail(BadRequestDetail badRequestDetail) { + this.badRequestDetail = badRequestDetail; + this.type = ErrorType.BadRequest.getType(); + } +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorType.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorType.java new file mode 100644 index 0000000000..018e8acfe7 --- /dev/null +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/model/error/ErrorType.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB 蓝鲸作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB 蓝鲸作业平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.tencent.bk.job.common.model.error; + +public enum ErrorType { + BadRequest(1); + private int type; + + ErrorType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public ErrorType valOf(Integer type) { + if (type == null) { + return null; + } + for (ErrorType errorType : values()) { + if (errorType.getType() == type) { + return errorType; + } + } + return null; + } +} diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/CustomCollectionUtils.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/CustomCollectionUtils.java index 6a43c60de5..a06c8f46cb 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/CustomCollectionUtils.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/CustomCollectionUtils.java @@ -24,34 +24,39 @@ package com.tencent.bk.job.common.util; -import lombok.val; - import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Set; -/** - * @Description - * @Date 2019/12/24 - * @Version 1.0 - */ public class CustomCollectionUtils { + public static List mergeList(List list1, List list2) { + if (list1 == null || list1.isEmpty()) return list2; + if (list2 == null || list2.isEmpty()) return list1; + Set set = new HashSet<>(list1); + List resultList = new ArrayList<>(list1); + list2.forEach(it -> { + if (!set.contains(it)) { + resultList.add(it); + set.add(it); + } + }); + return resultList; + } + public static List getNoDuplicateList(String rawStr, String separator) { if (rawStr == null || rawStr.isEmpty()) { return new ArrayList<>(); } - val set = new HashSet(); - val arr = rawStr.split(separator); - for (int i = 0; i < arr.length; i++) { - set.add(arr[i]); - } - List list = new ArrayList<>(set); - return list; + String[] arr = rawStr.split(separator); + Set set = new HashSet(Arrays.asList(arr)); + return new ArrayList<>(set); } - public static boolean isEmptyCollection(Collection collection) { + public static boolean isEmptyCollection(Collection collection) { return collection == null || collection.isEmpty(); } } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/I18nUtil.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/I18nUtil.java index 416b905770..bb8f91b750 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/I18nUtil.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/I18nUtil.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.common.util; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; /** * @Description diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/PageUtil.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/PageUtil.java index 8e6b904e8d..16abfc3f0f 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/PageUtil.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/PageUtil.java @@ -32,6 +32,9 @@ public class PageUtil { + public static final int DEFAULT_START = 0; + public static final int DEFAULT_POSITIVE_LENGTH = 10; + public static Pair normalizePageParam(Integer start, Integer pageSize) { if (start == null) { start = 0; diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ReflectUtil.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ReflectUtil.java index 277b91c535..8d8a538418 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ReflectUtil.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ReflectUtil.java @@ -38,7 +38,7 @@ public static Object getFieldValue(Object obj, String propertyName) { field.setAccessible(true); return field.get(obj); } catch (NoSuchFieldException e) { - log.info("Fail to get field {} of {}", propertyName, obj); + log.info("no field {} of {}", propertyName, obj); } catch (IllegalAccessException e) { log.info("Cannot access field {} of {}", propertyName, obj); } diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/StringUtil.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/StringUtil.java index 550f79d45e..fbaff9c83f 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/StringUtil.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/StringUtil.java @@ -30,7 +30,13 @@ import org.apache.commons.lang3.tuple.Pair; import java.net.URLEncoder; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -44,6 +50,7 @@ public class StringUtil { public static String replacePathVariables(String rawStr, Object obj) { + if (obj == null) return rawStr; List placeholderList = findOneRegexPatterns(rawStr, "(\\{.*?\\})"); for (String placeholder : placeholderList) { String fieldName = placeholder.substring(1, placeholder.length() - 1); diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ip/IpUtils.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ip/IpUtils.java index 0c39214209..a7f540733b 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ip/IpUtils.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/util/ip/IpUtils.java @@ -51,11 +51,9 @@ public class IpUtils { */ public static final long DEFAULT_CLOUD_ID = 0; private static final Pattern IP_PATTERN = Pattern.compile( - "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.(" + - "(?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); + "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); private static final Pattern pattern = Pattern.compile( - "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.(" + - "(?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); + "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"); /** * 校验云区域:服务器IP diff --git a/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/CustomCollectionUtilsTest.java b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/CustomCollectionUtilsTest.java new file mode 100644 index 0000000000..e2243c7342 --- /dev/null +++ b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/CustomCollectionUtilsTest.java @@ -0,0 +1,23 @@ +package com.tencent.bk.job.common.util; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CustomCollectionUtilsTest { + + @Test + void testMergeList() { + List list1 = Arrays.asList(1L, 2L); + List list2 = Arrays.asList(1L, 3L, 4L); + assertThat(CustomCollectionUtils.mergeList(null, null)).isNull(); + assertThat(CustomCollectionUtils.mergeList(list1, null)).hasSize(2); + assertThat(CustomCollectionUtils.mergeList(null, list2)).hasSize(3); + List mergedList = CustomCollectionUtils.mergeList(list1, list2); + assertThat(mergedList).hasSize(4); + mergedList.forEach(System.out::println); + } +} diff --git a/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java index c97d1806df..19057c2842 100644 --- a/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java +++ b/src/backend/commons/common/src/test/java/com/tencent/bk/job/common/util/date/DateUtilTest.java @@ -31,6 +31,7 @@ import java.sql.Timestamp; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -85,16 +86,20 @@ public void testCalculateMillsBetweenDateTime() { @Test void testConvertFromMillSeconds() { + ZoneId zoneId = ZoneOffset.systemDefault(); + String zoneIdStr = zoneId.getId(); + System.out.println("systemDefault zoneId=" + zoneIdStr); long timestamp = 1572766266451L; LocalDateTime actual = DateUtils.convertFromMillSeconds(timestamp); - assertThat(actual.getYear()).isEqualTo(2019); - assertThat(actual.getMonthValue()).isEqualTo(11); - assertThat(actual.getDayOfMonth()).isEqualTo(3); - assertThat(actual.getHour()).isEqualTo(15); - assertThat(actual.getMinute()).isEqualTo(31); - assertThat(actual.getSecond()).isEqualTo(6); - assertThat(actual.getNano()).isEqualTo(451_000_000); - + if ("Asia/Shanghai".equals(zoneIdStr)) { + assertThat(actual.getYear()).isEqualTo(2019); + assertThat(actual.getMonthValue()).isEqualTo(11); + assertThat(actual.getDayOfMonth()).isEqualTo(3); + assertThat(actual.getHour()).isEqualTo(15); + assertThat(actual.getMinute()).isEqualTo(31); + assertThat(actual.getSecond()).isEqualTo(6); + assertThat(actual.getNano()).isEqualTo(451_000_000); + } } @Test diff --git a/src/backend/commons/esb-sdk/build.gradle b/src/backend/commons/esb-sdk/build.gradle index 7461e73259..e3e10c5874 100644 --- a/src/backend/commons/esb-sdk/build.gradle +++ b/src/backend/commons/esb-sdk/build.gradle @@ -24,13 +24,14 @@ apply plugin: 'java' dependencies { - compile project(":commons:common") + api project(":commons:common") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' implementation 'io.springfox:springfox-swagger2' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' implementation "org.springframework:spring-jdbc" + implementation 'org.springframework:spring-web' implementation "net.sf.dozer:dozer" implementation 'org.apache.commons:commons-collections4' implementation 'net.sourceforge.jchardet:jchardet' @@ -38,6 +39,8 @@ dependencies { implementation 'org.aspectj:aspectjweaver' implementation 'io.micrometer:micrometer-registry-prometheus' implementation group: 'org.apache.httpcomponents', name: 'httpclient' + implementation "org.hibernate.validator:hibernate-validator" + implementation('jakarta.validation:jakarta.validation-api') compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation "org.junit.jupiter:junit-jupiter" diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/config/EsbConfig.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/config/EsbConfig.java index 9ee5665799..80e9236198 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/config/EsbConfig.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/config/EsbConfig.java @@ -32,10 +32,10 @@ @Component public class EsbConfig { - @Value("${app.code}") + @Value("${app.code:}") private String appCode; - @Value("${app.secret}") + @Value("${app.secret:}") private String appSecret; @Value("${esb.service.url:}") diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/metrics/EsbApiTimedAspect.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/metrics/EsbApiTimedAspect.java index a47b93011e..156bd6b8ba 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/metrics/EsbApiTimedAspect.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/metrics/EsbApiTimedAspect.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.common.esb.metrics; -import com.tencent.bk.job.common.esb.model.EsbReq; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; @@ -35,7 +35,11 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; @@ -61,29 +65,21 @@ public static Tag exception(Throwable exception) { @Around("execution (@com.tencent.bk.job.common.esb.metrics.EsbApiTimed * *.*(..))") public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable { - Object[] args = pjp.getArgs(); - if (args == null || args.length == 0) { - return pjp.proceed(); + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = null; + if (requestAttributes != null) { + request = ((ServletRequestAttributes)requestAttributes).getRequest(); } - - String appCode = ""; - try { - for (Object arg : args) { - if (arg instanceof EsbReq) { - EsbReq esbReq = (EsbReq) arg; - appCode = esbReq.getAppCode(); - break; - } - } - } catch (Throwable e) { - log.error("Process EsbReq fail!", e); + if (request == null) { return pjp.proceed(); } + String appCode = request.getHeader(JobCommonHeaders.APP_CODE); + Tags tags = Tags.of("app_code", StringUtils.isNotBlank(appCode) ? appCode : "None"); + Method method = ((MethodSignature) pjp.getSignature()).getMethod(); EsbApiTimed timed = method.getAnnotation(EsbApiTimed.class); final String metricName = timed.value(); - Tags tags = Tags.of("app_code", StringUtils.isNotBlank(appCode) ? appCode : "None"); return processWithTimer(pjp, timed, metricName, tags); } diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbResp.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbResp.java index 1cef57cc65..30bfc5d105 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbResp.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/EsbResp.java @@ -29,8 +29,9 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.iam.EsbApplyPermissionDTO; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; +import com.tencent.bk.job.common.model.error.ErrorDetail; import com.tencent.bk.job.common.util.JobContextUtil; import lombok.Data; import lombok.NoArgsConstructor; @@ -48,13 +49,16 @@ public class EsbResp { private Boolean result; - @JsonProperty("request_id") + @JsonProperty("job_request_id") private String requestId; private String message; private T data; + @JsonProperty("error_detail") + private ErrorDetail errorDetail; + /** * 无权限返回数据 */ @@ -100,6 +104,14 @@ public static EsbResp buildCommonFailResp(int errorCode, MessageI18nServi return new EsbResp<>(errorCode, errorMsg, null); } + public static EsbResp buildCommonFailResp(int errorCode, ErrorDetail errorDetail, + MessageI18nService i18nService) { + String errorMsg = i18nService.getI18n(String.valueOf(errorCode)); + EsbResp esbResp = new EsbResp<>(errorCode, errorMsg, null); + esbResp.setErrorDetail(errorDetail); + return esbResp; + } + public static EsbResp buildCommonFailResp(int errorCode, MessageI18nService i18nService, Object... errorParams) { String errorMsg = i18nService.getI18nWithArgs(String.valueOf(errorCode), errorParams); diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbCCTopoNodeDTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbCCTopoNodeDTO.java index d0ebf319ee..d8e0a36701 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbCCTopoNodeDTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbCCTopoNodeDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.common.esb.model.job; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.model.dto.CCTopoNodeDTO; import lombok.Data; @@ -33,13 +32,13 @@ * CMDB topo 节点 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbCCTopoNodeDTO { /** * topo节点ID */ @JsonProperty("id") private Long id; + /** * topo节点类型 */ diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbFileSourceDTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbFileSourceDTO.java index 2674253840..634a6dfa8c 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbFileSourceDTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbFileSourceDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.common.esb.model.job; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -34,12 +33,9 @@ * 源文件定义-ESB */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbFileSourceDTO { /** * 文件源类型 - * - * @see com.tencent.bk.job.manage.common.consts.task.TaskFileTypeEnum */ @JsonProperty("file_type") private Integer fileType; @@ -63,7 +59,6 @@ public class EsbFileSourceDTO { /** * ip列表 */ - @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("ip_list") private List ipList; @@ -71,10 +66,8 @@ public class EsbFileSourceDTO { * 动态分组ID列表 */ @JsonProperty("custom_query_id") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List dynamicGroupIdList; @JsonProperty("target_server") - @JsonInclude(JsonInclude.Include.NON_NULL) private EsbServerDTO targetServer; } diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbIpDTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbIpDTO.java index cabcbcf72c..3c665ae476 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbIpDTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/EsbIpDTO.java @@ -24,10 +24,10 @@ package com.tencent.bk.job.common.esb.model.job; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.model.dto.ApplicationHostInfoDTO; import com.tencent.bk.job.common.model.dto.HostDTO; +import com.tencent.bk.job.common.util.ip.IpUtils; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -35,12 +35,14 @@ @Setter @Getter -@JsonInclude(JsonInclude.Include.NON_NULL) @NoArgsConstructor @AllArgsConstructor public class EsbIpDTO { + @JsonProperty("bk_cloud_id") private Long cloudAreaId; + + @JsonProperty("ip") private String ip; public static EsbIpDTO fromApplicationHostInfo(ApplicationHostInfoDTO applicationHostInfo) { @@ -62,4 +64,12 @@ public static EsbIpDTO fromHost(HostDTO host) { esbIp.setIp(host.getIp()); return esbIp; } + + public static EsbIpDTO fromCloudIp(String cloudIp) { + if (!IpUtils.checkCloudAreaIdAndIpStr(cloudIp)) { + return null; + } + String[] ipProps = cloudIp.split(IpUtils.COLON); + return new EsbIpDTO(Long.valueOf(ipProps[0]), ipProps[1]); + } } diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbAccountV3BasicDTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbAccountV3BasicDTO.java index 4816034c0f..ee481a05c8 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbAccountV3BasicDTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbAccountV3BasicDTO.java @@ -24,14 +24,12 @@ package com.tencent.bk.job.common.esb.model.job.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; /** * 账号信息 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbAccountV3BasicDTO { /** * 账号ID diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbDynamicGroupDTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbDynamicGroupDTO.java index 22ab0ad887..a7cdafc38c 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbDynamicGroupDTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbDynamicGroupDTO.java @@ -24,14 +24,12 @@ package com.tencent.bk.job.common.esb.model.job.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; /** * 动态分组 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbDynamicGroupDTO { /** * 动态分组ID diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbFileSourceV3DTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbFileSourceV3DTO.java index 2f1d8ae92e..a24b738de5 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbFileSourceV3DTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbFileSourceV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.common.esb.model.job.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -34,7 +33,6 @@ * 源文件定义-ESB */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbFileSourceV3DTO { /** * 文件列表 diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbGlobalVarV3DTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbGlobalVarV3DTO.java index cdd685137d..b0cdcaafa6 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbGlobalVarV3DTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbGlobalVarV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.common.esb.model.job.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -32,7 +31,6 @@ * 全局变量 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbGlobalVarV3DTO { /** * 全局变量ID diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbPageDataV3.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbPageDataV3.java index dec08ee65a..3f7aff9cd7 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbPageDataV3.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbPageDataV3.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.common.esb.model.job.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.model.PageData; import lombok.Data; @@ -41,7 +40,6 @@ */ @NoArgsConstructor @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbPageDataV3 { private Integer start; @JsonProperty("length") diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbServerV3DTO.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbServerV3DTO.java index ca2ac89928..01e82c452d 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbServerV3DTO.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/model/job/v3/EsbServerV3DTO.java @@ -36,11 +36,11 @@ * 服务器定义-ESB */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbServerV3DTO { /** * 目标服务器对应的主机变量 */ + @JsonInclude(JsonInclude.Include.NON_NULL) private String variable; @JsonProperty("ip_list") diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServer.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServer.java new file mode 100644 index 0000000000..4e4ef74aa1 --- /dev/null +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServer.java @@ -0,0 +1,55 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.esb.validate; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_USE}) +@Retention(RUNTIME) +@Constraint(validatedBy = CheckServerValidator.class) +@Documented +@Repeatable(CheckServer.List.class) +public @interface CheckServer { + String message() default "{validation.CheckServer.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + @Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE}) + @Retention(RUNTIME) + @Documented + @interface List { + CheckServer[] value(); + } +} diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServerValidator.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServerValidator.java new file mode 100644 index 0000000000..ed142e0888 --- /dev/null +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/validate/CheckServerValidator.java @@ -0,0 +1,68 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.common.esb.validate; + +import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; +import com.tencent.bk.job.common.esb.model.job.v3.EsbServerV3DTO; +import com.tencent.bk.job.common.util.ip.IpUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class CheckServerValidator implements ConstraintValidator { + @Override + public boolean isValid(EsbServerV3DTO value, ConstraintValidatorContext context) { + if (value == null) { + return false; + } + + HibernateConstraintValidatorContext hibernateContext = context.unwrap( + HibernateConstraintValidatorContext.class + ); + + if(!(CollectionUtils.isEmpty(value.getIps()) && CollectionUtils.isEmpty(value.getDynamicGroups()) + && CollectionUtils.isEmpty(value.getTopoNodes()))) { + hibernateContext.disableDefaultConstraintViolation(); + hibernateContext + .buildConstraintViolationWithTemplate( "{validation.constraints.Pattern.ip.message}" ) + .addConstraintViolation(); + + } + for (EsbIpDTO ip : value.getIps()) { + if (!IpUtils.checkIp(ip.getIp())) { + hibernateContext.disableDefaultConstraintViolation(); + hibernateContext.addMessageParameter("ip", ip.getIp()); + hibernateContext + .buildConstraintViolationWithTemplate("{validation.constraints.Pattern.ip.message}") + .addPropertyNode("ips") + .addPropertyNode("ip").inIterable().atIndex(1).addConstraintViolation(); + return false; + } + } + return true; + } +} diff --git a/src/backend/commons/gse-sdk/build.gradle b/src/backend/commons/gse-sdk/build.gradle index 17dc4e2e69..f4cf438732 100644 --- a/src/backend/commons/gse-sdk/build.gradle +++ b/src/backend/commons/gse-sdk/build.gradle @@ -24,14 +24,14 @@ apply plugin: 'java' dependencies { - compile project(":commons:common") - compile files("libs/ee-gse-task-3.1.jar") + api project(":commons:common") + api files("libs/ee-gse-task-3.1.jar") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' implementation group: 'org.apache.httpcomponents', name: 'httpclient' implementation 'org.apache.thrift:libthrift:0.12.0' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' implementation 'org.apache.commons:commons-collections4' implementation group: 'org.apache.httpcomponents', name: 'httpclient' compileOnly 'org.projectlombok:lombok' diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/service/QueryAgentStatusClientImpl.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/service/QueryAgentStatusClientImpl.java index ced1f5bf8e..e441a13bfa 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/service/QueryAgentStatusClientImpl.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/service/QueryAgentStatusClientImpl.java @@ -39,7 +39,12 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Slf4j public class QueryAgentStatusClientImpl implements QueryAgentStatusClient { diff --git a/src/backend/commons/paas-sdk/build.gradle b/src/backend/commons/paas-sdk/build.gradle index e8e52163bf..e9b65df7e9 100644 --- a/src/backend/commons/paas-sdk/build.gradle +++ b/src/backend/commons/paas-sdk/build.gradle @@ -24,13 +24,13 @@ apply plugin: 'java' dependencies { - compile project(":commons:common") - compile project(":commons:esb-sdk") - compile project(":commons:common-i18n") + api project(":commons:common") + api project(":commons:esb-sdk") + api project(":commons:common-i18n") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' - compile 'org.apache.commons:commons-lang3' + api 'org.apache.commons:commons-lang3' implementation "net.sf.dozer:dozer" implementation 'io.micrometer:micrometer-registry-prometheus' implementation 'org.apache.commons:commons-collections4' diff --git a/src/backend/gradle/wrapper/gradle-wrapper.properties b/src/backend/gradle/wrapper/gradle-wrapper.properties index dccaa081d7..69651c356a 100644 --- a/src/backend/gradle/wrapper/gradle-wrapper.properties +++ b/src/backend/gradle/wrapper/gradle-wrapper.properties @@ -23,7 +23,7 @@ # #Sun Nov 08 17:54:30 CST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/backend/job-analysis/api-job-analysis/build.gradle b/src/backend/job-analysis/api-job-analysis/build.gradle index 62f8066482..93fb7c8f5e 100644 --- a/src/backend/job-analysis/api-job-analysis/build.gradle +++ b/src/backend/job-analysis/api-job-analysis/build.gradle @@ -23,13 +23,13 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') - compile project(':commons:cmdb-sdk') - compile project(':commons:common-iam') - compile project(':commons:common-statistics') - compile project(':job-execute:api-job-execute') - compile project(':job-manage:api-job-manage') + api project(':commons:common') + api project(':commons:common-i18n') + api project(':commons:cmdb-sdk') + api project(':commons:common-iam') + api project(':commons:common-statistics') + api project(':job-execute:api-job-execute') + api project(':job-manage:api-job-manage') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation("org.apache.commons:commons-collections4") diff --git a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebIndexResource.java b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebIndexResource.java index 19a33a6b56..8b0e934892 100644 --- a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebIndexResource.java +++ b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebIndexResource.java @@ -25,17 +25,24 @@ package com.tencent.bk.job.analysis.api.web; import com.tencent.bk.job.analysis.model.web.AnalysisResultVO; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-analysis:web:Index"}) @RequestMapping("/web/index/app/{appId}") @RestController +@WebAPI public interface WebIndexResource { @ApiOperation(value = "获取分析结果列表", produces = "application/json") diff --git a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebScriptStatisticsResource.java b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebScriptStatisticsResource.java index 47159fd6eb..69521579a4 100644 --- a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebScriptStatisticsResource.java +++ b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebScriptStatisticsResource.java @@ -25,17 +25,23 @@ package com.tencent.bk.job.analysis.api.web; import com.tencent.bk.job.analysis.model.web.ScriptCiteStatisticVO; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-analysis:web:脚本统计量统计接口"}) @RequestMapping("/web/statistics/script") @RestController +@WebAPI public interface WebScriptStatisticsResource { @ApiOperation(value = "查询脚本引用统计信息", produces = "application/json") diff --git a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebStatisticsResource.java b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebStatisticsResource.java index 3982ec57d3..42a594f612 100644 --- a/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebStatisticsResource.java +++ b/src/backend/job-analysis/api-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/WebStatisticsResource.java @@ -28,12 +28,22 @@ import com.tencent.bk.job.analysis.consts.DistributionMetricEnum; import com.tencent.bk.job.analysis.consts.ResourceEnum; import com.tencent.bk.job.analysis.consts.TotalMetricEnum; -import com.tencent.bk.job.analysis.model.web.*; +import com.tencent.bk.job.analysis.model.web.CommonDistributionVO; +import com.tencent.bk.job.analysis.model.web.CommonStatisticWithRateVO; +import com.tencent.bk.job.analysis.model.web.CommonTrendElementVO; +import com.tencent.bk.job.analysis.model.web.DayDistributionElementVO; +import com.tencent.bk.job.analysis.model.web.PerAppStatisticVO; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @@ -41,6 +51,7 @@ @Api(tags = {"job-analysis:web:统计量统计接口"}) @RequestMapping("/web/statistics") @RestController +@WebAPI public interface WebStatisticsResource { @ApiOperation(value = "查询某个统计量的统计信息", produces = "application/json") diff --git a/src/backend/job-analysis/boot-job-analysis/build.gradle b/src/backend/job-analysis/boot-job-analysis/build.gradle index 2ca568f920..cc0b78fa84 100644 --- a/src/backend/job-analysis/boot-job-analysis/build.gradle +++ b/src/backend/job-analysis/boot-job-analysis/build.gradle @@ -25,9 +25,9 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-analysis:service-job-analysis") - compile project(":commons:common-redis") - compile project(":commons:common-i18n") + api project(":job-analysis:service-job-analysis") + api project(":commons:common-redis") + api project(":commons:common-i18n") implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp' implementation 'org.springframework:spring-webmvc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' @@ -45,7 +46,7 @@ dependencies { testImplementation("com.h2database:h2") } springBoot { - mainClassName = "com.tencent.bk.job.analysis.JobAnalysisBootApplication" + mainClass = "com.tencent.bk.job.analysis.JobAnalysisBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/FilterConfig.java b/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/FilterConfig.java index b4869f34e2..9b4c38af10 100644 --- a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/FilterConfig.java +++ b/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/FilterConfig.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.config; -import com.tencent.bk.job.common.web.filter.RepeatableReadServletRequestResponseFilter; +import com.tencent.bk.job.common.web.filter.RepeatableReadWriteServletRequestResponseFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,7 +33,7 @@ public class FilterConfig { @Bean public FilterRegistrationBean repeatableRSRRFilterRegister() { - FilterRegistrationBean registration = + FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(repeatableRRRFilter()); registration.addUrlPatterns("/esb/api/*"); @@ -43,7 +43,7 @@ public FilterRegistrationBean repeatableRSRRFilterRegister() { } @Bean(name = "repeatableReadRequestResponseFilter") - public RepeatableReadServletRequestResponseFilter repeatableRRRFilter() { - return new RepeatableReadServletRequestResponseFilter(); + public RepeatableReadWriteServletRequestResponseFilter repeatableRRRFilter() { + return new RepeatableReadWriteServletRequestResponseFilter(); } } diff --git a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/I18nConfig.java b/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/I18nConfig.java deleted file mode 100644 index 26e614272d..0000000000 --- a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/I18nConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.analysis.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/InterceptorConfiguration.java b/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/InterceptorConfiguration.java index a6dd081fbb..e6bf07d007 100644 --- a/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/InterceptorConfiguration.java +++ b/src/backend/job-analysis/boot-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/InterceptorConfiguration.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.analysis.config; import com.tencent.bk.job.analysis.interceptor.UriPermissionInterceptor; -import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import org.springframework.beans.factory.annotation.Autowired; @@ -37,17 +37,19 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; - private final EsbApiLogInterceptor esbApiLogInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; private final UriPermissionInterceptor uriPermissionInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - EsbApiLogInterceptor esbApiLogInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor, - UriPermissionInterceptor uriPermissionInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor, + UriPermissionInterceptor uriPermissionInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; - this.esbApiLogInterceptor = esbApiLogInterceptor; + this.authAppInterceptor = authAppInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; this.uriPermissionInterceptor = uriPermissionInterceptor; } @@ -59,6 +61,6 @@ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(jobCommonInterceptor).addPathPatterns("/**").order(1); registry.addInterceptor(uriPermissionInterceptor) .addPathPatterns(uriPermissionInterceptor.getControlUriPatterns()).order(2); - registry.addInterceptor(esbApiLogInterceptor).addPathPatterns("/esb/api/**").order(10); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(3); } } diff --git a/src/backend/job-analysis/build.gradle b/src/backend/job-analysis/build.gradle index 5fc624cba9..37b6143478 100644 --- a/src/backend/job-analysis/build.gradle +++ b/src/backend/job-analysis/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobAnalysisVersion")) { set("jobAnalysisVersion", System.getProperty("jobAnalysisVersion")) + } else if (System.getProperty("version")) { + set("jobAnalysisVersion", System.getProperty("version")) } else { set("jobAnalysisVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobAnalysisVersion}" subprojects { version "${jobAnalysisVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api 'org.springframework.boot:spring-boot-autoconfigure' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-analysis/service-job-analysis/build.gradle b/src/backend/job-analysis/service-job-analysis/build.gradle index ba01bb6ef4..5a4d9aa83f 100644 --- a/src/backend/job-analysis/service-job-analysis/build.gradle +++ b/src/backend/job-analysis/service-job-analysis/build.gradle @@ -24,19 +24,19 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-manage:api-job-manage") - compile project(":job-analysis:api-job-analysis") - compile project(":job-analysis:model-job-analysis") - compile project(":job-crontab:api-job-crontab") - compile project(":commons:common") - compile project(":commons:common-web") - compile project(":commons:common-iam") - compile project(":commons:common-security") - compile project(":commons:common-redis") - compile project(":commons:cmdb-sdk") - compile project(":commons:paas-sdk") - compile project(":commons:esb-sdk") - compile project(":commons:gse-sdk") + api project(":job-manage:api-job-manage") + api project(":job-analysis:api-job-analysis") + api project(":job-analysis:model-job-analysis") + api project(":job-crontab:api-job-crontab") + api project(":commons:common") + api project(":commons:common-web") + api project(":commons:common-iam") + api project(":commons:common-security") + api project(":commons:common-redis") + api project(":commons:cmdb-sdk") + api project(":commons:paas-sdk") + api project(":commons:esb-sdk") + api project(":commons:gse-sdk") implementation "org.springframework.boot:spring-boot-starter-web" implementation "org.springframework.boot:spring-boot-starter-jdbc" implementation "org.springframework.boot:spring-boot-starter-jooq" diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/iam/impl/IamDashBoardViewCallbackResourceImpl.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/iam/impl/IamDashBoardViewCallbackResourceImpl.java index 8e6076f47a..7b793aa217 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/iam/impl/IamDashBoardViewCallbackResourceImpl.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/iam/impl/IamDashBoardViewCallbackResourceImpl.java @@ -26,9 +26,17 @@ import com.tencent.bk.job.analysis.api.iam.IamDashBoardViewCallbackResource; import com.tencent.bk.job.analysis.consts.AnalysisConsts; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.BaseDataResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -38,87 +46,93 @@ @RestController @Slf4j -public class IamDashBoardViewCallbackResourceImpl implements IamDashBoardViewCallbackResource { +public class IamDashBoardViewCallbackResourceImpl extends BaseIamCallbackService + implements IamDashBoardViewCallbackResource { @Autowired public IamDashBoardViewCallbackResourceImpl() { } @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; - IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + List instanceInfoList = new ArrayList<>(); + // TODO:当前只有全局视图,待后续视图功能开发后更新这里 + InstanceInfoDTO tmpInstanceInfo = new InstanceInfoDTO(); + tmpInstanceInfo.setId(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID); + tmpInstanceInfo.setDisplayName(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME); + instanceInfoList.add(tmpInstanceInfo); - List instanceInfoList = new ArrayList<>(); - // TODO:当前只有全局视图,待后续视图功能开发后更新这里 - InstanceInfoDTO tmpInstanceInfo = new InstanceInfoDTO(); - tmpInstanceInfo.setId(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID); - tmpInstanceInfo.setDisplayName(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME); - instanceInfoList.add(tmpInstanceInfo); + ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); + instanceResponse.setCode(0L); + BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); + baseDataResponse.setResult(instanceInfoList); + baseDataResponse.setCount(1L); + instanceResponse.setData(baseDataResponse); + return instanceResponse; + } - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - baseDataResponse.setResult(instanceInfoList); - baseDataResponse.setCount(1L); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + SearchInstanceResponseDTO instanceResponse = new SearchInstanceResponseDTO(); + String keyword = callbackRequest.getFilter().getKeyword(); + if (keyword == null || AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME.contains(keyword)) { + List instanceInfoList = new ArrayList<>(); + InstanceInfoDTO tmpInstanceInfo = new InstanceInfoDTO(); + tmpInstanceInfo.setId(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID); + tmpInstanceInfo.setDisplayName(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME); + instanceInfoList.add(tmpInstanceInfo); + + instanceResponse.setCode(0L); + BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); + baseDataResponse.setResult(instanceInfoList); + baseDataResponse.setCount(1L); + instanceResponse.setData(baseDataResponse); + } else { + instanceResponse.setCode(0L); + BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); + baseDataResponse.setResult(new ArrayList<>()); + baseDataResponse.setCount(0L); + instanceResponse.setData(baseDataResponse); + } + return instanceResponse; + } - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - if (AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID.equals(instanceId)) { - instanceInfo.setDisplayName(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME); - } else { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected dashBoardViewId:{} passed by iam", instanceId); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + if (!AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID.equals(instanceId)) { + return getNotFoundRespById(instanceId); } + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.DASHBOARD_VIEW); + rootNode.setId(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_ID); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(AnalysisConsts.GLOBAL_DASHBOARD_VIEW_NAME); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } + } - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); - } - return response; + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); } } diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/op/impl/OpResourceImpl.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/op/impl/OpResourceImpl.java index d649e295f0..8953abc627 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/op/impl/OpResourceImpl.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/op/impl/OpResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.analysis.api.op.impl; import com.tencent.bk.job.analysis.api.op.OpResource; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.op.*; import com.tencent.bk.job.analysis.task.statistics.StatisticsTaskScheduler; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebIndexResourceImpl.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebIndexResourceImpl.java index 9d9e68edc5..22eb5f8cc6 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebIndexResourceImpl.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebIndexResourceImpl.java @@ -28,7 +28,6 @@ import com.tencent.bk.job.analysis.model.web.AnalysisResultVO; import com.tencent.bk.job.analysis.service.IndexService; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -37,7 +36,7 @@ @RestController @Slf4j -public class WebIndexResourceImpl extends AbstractJobController implements WebIndexResource { +public class WebIndexResourceImpl implements WebIndexResource { private final IndexService indexService; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebStatisticsResourceImpl.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebStatisticsResourceImpl.java index 2cb318bfa1..3d3e1a3694 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebStatisticsResourceImpl.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/api/web/impl/WebStatisticsResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.analysis.api.web.impl; import com.tencent.bk.job.analysis.api.web.WebStatisticsResource; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.consts.DimensionEnum; import com.tencent.bk.job.analysis.consts.DistributionMetricEnum; import com.tencent.bk.job.analysis.consts.ResourceEnum; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/common/ExceptionControllerAdvice.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/common/ExceptionControllerAdvice.java deleted file mode 100644 index 2d8122c600..0000000000 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/common/ExceptionControllerAdvice.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.analysis.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; -import com.tencent.bk.job.common.iam.model.AuthResult; -import com.tencent.bk.job.common.iam.service.WebAuthService; -import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.model.permission.AuthResultVO; -import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import feign.FeignException; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MaxUploadSizeExceededException; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice({"com.tencent.bk.job.analysis.api.web"}) -@Slf4j -public class ExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - private final WebAuthService webAuthService; - - @Autowired - public ExceptionControllerAdvice(MessageI18nService i18nService, WebAuthService webAuthService) { - this.i18nService = i18nService; - this.webAuthService = webAuthService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.error("Handle service exception", ex); - if (ex instanceof HttpStatusServiceException) { - HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException.getErrorCode() - , i18nService), httpStatusServiceException.getHttpStatus()); - } else if (ex instanceof InSufficientPermissionException) { - InSufficientPermissionException inSufficientPermissionException = (InSufficientPermissionException) ex; - AuthResultVO authResultVO = null; - if (inSufficientPermissionException.getAuthResult() != null) { - AuthResult authResult = inSufficientPermissionException.getAuthResult(); - log.debug("Insufficient permission, authResult: {}", authResult); - if (StringUtils.isEmpty(authResult.getApplyUrl())) { - authResult.setApplyUrl(webAuthService.getApplyUrl(authResult.getRequiredActionResources())); - } - authResultVO = webAuthService.toAuthResultVO(authResult); - } else if (ex.getErrorParams()[0] != null && ex.getErrorParams()[0] instanceof AuthResultVO) { - authResultVO = (AuthResultVO) ex.getErrorParams()[0]; - } - return new ResponseEntity<>(ServiceResponse.buildAuthFailResp(authResultVO), HttpStatus.OK); - } else if (ex != null) { - if (ex.getErrorCode() > 0) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorCode(), - ex.getErrorParams(), i18nService), HttpStatus.OK); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorMsg()), HttpStatus.OK); - } - } else { - // 通用处理 - HttpStatus commonStatus = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), commonStatus); - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.error("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - @ExceptionHandler(FeignException.class) - @ResponseBody - ResponseEntity handleFeignException(HttpServletRequest request, FeignException ex) { - log.warn("Handle feign exception", ex); - if (ex.status() == HttpStatus.UNAUTHORIZED.value()) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_AUTH_FAIL, i18nService) - , HttpStatus.UNAUTHORIZED); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @ExceptionHandler(MaxUploadSizeExceededException.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, MaxUploadSizeExceededException ex) { - log.error("Handle MaxUploadSizeExceededException, maxFileSize:{}", ex.getMaxUploadSize()); - long maxFileSize = ex.getMaxUploadSize(); - String fileSizeDesc = (maxFileSize << 20) + "G"; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.UPLOAD_FILE_MAX_SIZE_EXCEEDED, - new String[]{fileSizeDesc}, i18nService), - HttpStatus.OK); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } -} diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/listener/StatisticConfig.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/StatisticConfig.java similarity index 95% rename from src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/listener/StatisticConfig.java rename to src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/StatisticConfig.java index 7ea45dd8a0..a2798a2df7 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/listener/StatisticConfig.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/config/StatisticConfig.java @@ -22,7 +22,7 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.analysis.config.listener; +package com.tencent.bk.job.analysis.config; import lombok.Data; import org.springframework.beans.factory.annotation.Value; @@ -50,7 +50,7 @@ public class StatisticConfig { @Value("${job.analysis.statistics.yoy.days:7}") private Integer yoyDays; - @Value("${job.analysis.statistics.tag.num.max:100}") + @Value("${job.analysis.statistics.tag.num.max:120}") private Integer maxTagNum; /** diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/dao/impl/StatisticsDAOImpl.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/dao/impl/StatisticsDAOImpl.java index 245f390175..9640f452a1 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/dao/impl/StatisticsDAOImpl.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/dao/impl/StatisticsDAOImpl.java @@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import lombok.var; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.conf.ParamType; import org.jooq.generated.tables.Statistics; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/AppStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/AppStatisticService.java index 25ee7bb4c0..585e731671 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/AppStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/AppStatisticService.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.analysis.service; import com.fasterxml.jackson.core.type.TypeReference; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.dto.SimpleAppInfoDTO; import com.tencent.bk.job.analysis.model.web.CommonStatisticWithRateVO; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/CommonStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/CommonStatisticService.java index f42c85c5c6..492df6f571 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/CommonStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/CommonStatisticService.java @@ -24,10 +24,12 @@ package com.tencent.bk.job.analysis.service; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.fasterxml.jackson.core.type.TypeReference; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.consts.DistributionMetricEnum; import com.tencent.bk.job.analysis.consts.TotalMetricEnum; import com.tencent.bk.job.analysis.dao.StatisticsDAO; +import com.tencent.bk.job.analysis.model.dto.SimpleAppInfoDTO; import com.tencent.bk.job.analysis.model.web.CommonDistributionVO; import com.tencent.bk.job.analysis.model.web.CommonStatisticWithRateVO; import com.tencent.bk.job.analysis.model.web.CommonTrendElementVO; @@ -35,12 +37,19 @@ import com.tencent.bk.job.analysis.util.calc.SimpleMomYoyCalculator; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; import com.tencent.bk.job.common.statistics.model.dto.StatisticsDTO; +import com.tencent.bk.job.common.util.CustomCollectionUtils; import com.tencent.bk.job.common.util.date.DateUtils; +import com.tencent.bk.job.common.util.json.JsonUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Slf4j @Service @@ -60,6 +69,15 @@ public CommonStatisticService(StatisticsDAO statisticsDAO, StatisticConfig stati this.appService = appService; } + public List getJoinedAppIdList(String date) { + StatisticsDTO statisticsDTO = statisticsDAO.getStatistics(StatisticsConstants.DEFAULT_APP_ID, + StatisticsConstants.RESOURCE_APP, StatisticsConstants.DIMENSION_APP_STATISTIC_TYPE, + StatisticsConstants.DIMENSION_VALUE_APP_STATISTIC_TYPE_APP_LIST, date); + List applicationDTOList = JsonUtils.fromJson(statisticsDTO.getValue(), + new TypeReference>() { + }); + return applicationDTOList.parallelStream().map(SimpleAppInfoDTO::getId).collect(Collectors.toList()); + } /** * @param statisticsDTO @@ -166,7 +184,12 @@ public int compare(CommonTrendElementVO o1, CommonTrendElementVO o2) { public List listByPerApp(String resource, TotalMetricEnum metric, List appIdList, String date) { - List statisticsDTOList = statisticsDAO.getStatisticsList(appIdList, null, resource, + // 增加筛选范围:已接入的业务 + List scopedAppIdList = CustomCollectionUtils.mergeList(appIdList, getJoinedAppIdList(date)); + List statisticsDTOList = statisticsDAO.getStatisticsList( + scopedAppIdList, + null, + resource, StatisticsConstants.DIMENSION_GLOBAL_STATISTIC_TYPE, StatisticsConstants.DIMENSION_VALUE_GLOBAL_STATISTIC_TYPE_PREFIX + metric.name(), date); List perAppStatisticVOList = new ArrayList<>(); diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastFileStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastFileStatisticService.java index 8d86a24431..85c21787be 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastFileStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastFileStatisticService.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.service; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.web.DayDistributionElementVO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastScriptStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastScriptStatisticService.java index 34008209d4..e4cafba34f 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastScriptStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/FastScriptStatisticService.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.service; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.web.DayDistributionElementVO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/HostStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/HostStatisticService.java index a5304ade1f..d6780771de 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/HostStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/HostStatisticService.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.service; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.web.CommonDistributionVO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java index f26fd9c921..d3cca2d0e6 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/IndexService.java @@ -35,12 +35,12 @@ import com.tencent.bk.job.analysis.task.analysis.task.IAnalysisTask; import com.tencent.bk.job.analysis.task.analysis.task.impl.DefaultTipsProvider; import com.tencent.bk.job.analysis.task.analysis.task.pojo.AnalysisTaskResultVO; -import com.tencent.bk.job.common.i18n.MessageI18nService; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.StringUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/ScriptStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/ScriptStatisticService.java index 921039527e..f72ae92907 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/ScriptStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/ScriptStatisticService.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.service; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.web.ScriptCiteStatisticVO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/TagStatisticService.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/TagStatisticService.java index 7f95a0e32e..cde280943c 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/TagStatisticService.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/service/TagStatisticService.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.analysis.service; import com.fasterxml.jackson.core.type.TypeReference; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.web.CommonDistributionVO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java index 9e85c90d0b..9401cc3eae 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/StatisticsTaskScheduler.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.task.statistics; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.task.statistics.task.*; import com.tencent.bk.job.common.redis.util.LockUtils; import com.tencent.bk.job.common.redis.util.RedisKeyHeartBeatThread; @@ -35,7 +35,7 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/ClearExpiredStatisticsTask.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/ClearExpiredStatisticsTask.java index fee9adab61..40b5ccc111 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/ClearExpiredStatisticsTask.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/ClearExpiredStatisticsTask.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.task.statistics.task; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; import com.tencent.bk.job.common.util.TimeUtil; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/PastStatisticsMakeupTask.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/PastStatisticsMakeupTask.java index dcb1cad179..b5090ddec8 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/PastStatisticsMakeupTask.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/PastStatisticsMakeupTask.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.analysis.task.statistics.task; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.common.statistics.consts.StatisticsConstants; import com.tencent.bk.job.common.util.TimeUtil; diff --git a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/impl/app/AppStatisticsTask.java b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/impl/app/AppStatisticsTask.java index 7d3894bd0c..a566e18a9c 100644 --- a/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/impl/app/AppStatisticsTask.java +++ b/src/backend/job-analysis/service-job-analysis/src/main/java/com/tencent/bk/job/analysis/task/statistics/task/impl/app/AppStatisticsTask.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.analysis.client.ExecuteMetricsClient; -import com.tencent.bk.job.analysis.config.listener.StatisticConfig; +import com.tencent.bk.job.analysis.config.StatisticConfig; import com.tencent.bk.job.analysis.dao.StatisticsDAO; import com.tencent.bk.job.analysis.model.dto.SimpleAppInfoDTO; import com.tencent.bk.job.analysis.service.BasicServiceManager; diff --git a/src/backend/job-backup/api-job-backup/build.gradle b/src/backend/job-backup/api-job-backup/build.gradle index 2d725dfa42..16918f3f08 100644 --- a/src/backend/job-backup/api-job-backup/build.gradle +++ b/src/backend/job-backup/api-job-backup/build.gradle @@ -23,9 +23,9 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-iam') - compile project(':commons:common-i18n') + api project(':commons:common') + api project(':commons:common-iam') + api project(':commons:common-i18n') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation("org.apache.commons:commons-collections4") diff --git a/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/inner/ServiceArchiveResource.java b/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/inner/ServiceArchiveResource.java index 9373acf556..2ba181fd88 100644 --- a/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/inner/ServiceArchiveResource.java +++ b/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/inner/ServiceArchiveResource.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.backup.api.inner; import com.tencent.bk.job.backup.model.inner.ServiceArchiveDBRequest; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import org.springframework.web.bind.annotation.PostMapping; @@ -35,6 +36,7 @@ @Api(tags = {"DB_Archive"}) @RequestMapping("/service/archiveDB") @RestController +@InternalAPI public interface ServiceArchiveResource { @PostMapping ServiceResponse archive(@RequestBody ServiceArchiveDBRequest request); diff --git a/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/WebBackupResource.java b/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/WebBackupResource.java index 19796f0cf9..75897b23e9 100644 --- a/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/WebBackupResource.java +++ b/src/backend/job-backup/api-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/WebBackupResource.java @@ -30,12 +30,21 @@ import com.tencent.bk.job.backup.model.web.BackupJobInfoVO; import com.tencent.bk.job.backup.model.web.ExportInfoVO; import com.tencent.bk.job.backup.model.web.ImportInfoVO; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; @@ -45,6 +54,7 @@ @Api(tags = {"job-backup:web:Backup"}) @RequestMapping("/web/app/{appId}/backup") @RestController +@WebAPI public interface WebBackupResource { @ApiOperation(value = "开始导出", produces = "application/json") diff --git a/src/backend/job-backup/boot-job-backup/build.gradle b/src/backend/job-backup/boot-job-backup/build.gradle index b863a2a20e..ce7bce55f0 100644 --- a/src/backend/job-backup/boot-job-backup/build.gradle +++ b/src/backend/job-backup/boot-job-backup/build.gradle @@ -25,9 +25,9 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-backup:service-job-backup") - compile project(":commons:common-redis") - compile project(":commons:common-i18n") + api project(":job-backup:service-job-backup") + api project(":commons:common-redis") + api project(":commons:common-i18n") implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp' implementation 'org.springframework:spring-webmvc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' @@ -45,7 +46,7 @@ dependencies { testImplementation("com.h2database:h2") } springBoot { - mainClassName = "com.tencent.bk.job.backup.JobBackupBootApplication" + mainClass = "com.tencent.bk.job.backup.JobBackupBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/I18nConfig.java b/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/I18nConfig.java deleted file mode 100644 index 5156401ce0..0000000000 --- a/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/I18nConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.backup.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -/** - * @date 2019/09/19 - */ -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/InterceptorConfiguration.java b/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/InterceptorConfiguration.java index 90a585cef8..41ddd87c83 100644 --- a/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/InterceptorConfiguration.java +++ b/src/backend/job-backup/boot-job-backup/src/main/java/com/tencent/bk/job/backup/config/InterceptorConfiguration.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.backup.config; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import org.springframework.beans.factory.annotation.Autowired; @@ -38,12 +39,17 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; + this.authAppInterceptor = authAppInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; } @@ -52,5 +58,6 @@ public void addInterceptors(InterceptorRegistry registry) { // 注册拦截器 registry.addInterceptor(serviceSecurityInterceptor).addPathPatterns("/**").order(0); registry.addInterceptor(jobCommonInterceptor).addPathPatterns("/**").order(1); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(2); } } diff --git a/src/backend/job-backup/boot-job-backup/src/main/resources/bootstrap.yml b/src/backend/job-backup/boot-job-backup/src/main/resources/bootstrap.yml index fcc7c5d5ab..ddedf73f0d 100644 --- a/src/backend/job-backup/boot-job-backup/src/main/resources/bootstrap.yml +++ b/src/backend/job-backup/boot-job-backup/src/main/resources/bootstrap.yml @@ -10,6 +10,9 @@ spring: instance-id: job-backup-${machine.ip}-${server.port} enabled: true prefer-ip-address: true + mvc: + async: + request-timeout: 120000 ribbon: ServerListRefreshInterval: 3000 diff --git a/src/backend/job-backup/build.gradle b/src/backend/job-backup/build.gradle index b52153f72e..5936544cb7 100644 --- a/src/backend/job-backup/build.gradle +++ b/src/backend/job-backup/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobBackupVersion")) { set("jobBackupVersion", System.getProperty("jobBackupVersion")) + } else if (System.getProperty("version")) { + set("jobBackupVersion", System.getProperty("version")) } else { set("jobBackupVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobBackupVersion}" subprojects { version "${jobBackupVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api 'org.springframework.boot:spring-boot-autoconfigure' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-backup/model-job-backup/task_gen_jooq.gradle b/src/backend/job-backup/model-job-backup/task_gen_jooq.gradle index 74b10b0a3e..0ed6aefc8a 100644 --- a/src/backend/job-backup/model-job-backup/task_gen_jooq.gradle +++ b/src/backend/job-backup/model-job-backup/task_gen_jooq.gradle @@ -1,7 +1,7 @@ apply plugin: 'nu.studer.jooq' dependencies { - compile "org.jooq:jooq" + api "org.jooq:jooq" jooqRuntime "mysql:mysql-connector-java" } diff --git a/src/backend/job-backup/service-job-backup/build.gradle b/src/backend/job-backup/service-job-backup/build.gradle index 2e60a429a5..b36696a3f7 100644 --- a/src/backend/job-backup/service-job-backup/build.gradle +++ b/src/backend/job-backup/service-job-backup/build.gradle @@ -24,22 +24,23 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-backup:api-job-backup") - compile project(":job-backup:model-job-backup") - compile project(":job-manage:api-job-manage") - compile project(":job-execute:model-job-execute") - compile project(":commons:common-web") - compile project(":commons:common-security") - compile project(":commons:common-redis") + api project(":job-backup:api-job-backup") + api project(":job-backup:model-job-backup") + api project(":job-manage:api-job-manage") + api project(":job-execute:model-job-execute") + api project(":commons:common-web") + api project(":commons:common-security") + api project(":commons:common-redis") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-jooq") implementation "org.apache.commons:commons-collections4" - compile("org.springframework.cloud:spring-cloud-starter-consul-discovery") - compile("org.springframework.cloud:spring-cloud-starter-sleuth") + api("org.springframework.cloud:spring-cloud-starter-consul-discovery") + api("org.springframework.cloud:spring-cloud-starter-sleuth") implementation('org.springframework.cloud:spring-cloud-starter-openfeign') implementation "ch.qos.logback:logback-core" implementation "ch.qos.logback:logback-classic" implementation "org.slf4j:slf4j-api" + implementation 'joda-time:joda-time' } diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/impl/WebBackupResourceImpl.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/impl/WebBackupResourceImpl.java index e2faef737a..3578c9d311 100644 --- a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/impl/WebBackupResourceImpl.java +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/api/web/impl/WebBackupResourceImpl.java @@ -49,7 +49,6 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.redis.util.LockUtils; import com.tencent.bk.job.common.util.JobContextUtil; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; @@ -72,7 +71,7 @@ */ @Slf4j @RestController -public class WebBackupResourceImpl extends AbstractJobController implements WebBackupResource { +public class WebBackupResourceImpl implements WebBackupResource { private final ImportJobService importJobService; private final ExportJobService exportJobService; diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/BackupResourceAppInfoQueryService.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/BackupResourceAppInfoQueryService.java new file mode 100644 index 0000000000..422a2b5fae --- /dev/null +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/BackupResourceAppInfoQueryService.java @@ -0,0 +1,90 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.backup.auth; + +import com.tencent.bk.job.backup.client.ServiceApplicationResourceClient; +import com.tencent.bk.job.common.constant.AppTypeEnum; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.model.ResourceAppInfo; +import com.tencent.bk.job.common.iam.service.ResourceAppInfoQueryService; +import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +@Service +public class BackupResourceAppInfoQueryService implements ResourceAppInfoQueryService { + + private final ServiceApplicationResourceClient applicationService; + + @Autowired + public BackupResourceAppInfoQueryService(ServiceApplicationResourceClient applicationService) { + this.applicationService = applicationService; + } + + private ResourceAppInfo convert(ServiceApplicationDTO applicationInfoDTO) { + if (applicationInfoDTO == null) { + return null; + } else { + ResourceAppInfo resourceAppInfo = new ResourceAppInfo(); + resourceAppInfo.setAppId(applicationInfoDTO.getId()); + resourceAppInfo.setAppType(AppTypeEnum.valueOf(applicationInfoDTO.getAppType())); + String maintainerStr = applicationInfoDTO.getMaintainers(); + List maintainerList = new ArrayList<>(); + if (StringUtils.isNotBlank(maintainerStr)) { + String[] maintainers = maintainerStr.split("[,;]"); + maintainerList.addAll(Arrays.asList(maintainers)); + } + resourceAppInfo.setMaintainerList(maintainerList); + return resourceAppInfo; + } + } + + private ResourceAppInfo getResourceAppInfoById(Long appId) { + if (appId == null || appId <= 0) { + return null; + } + return convert(applicationService.queryAppById(appId)); + } + + @Override + public ResourceAppInfo getResourceAppInfo(ResourceTypeEnum resourceType, String resourceId) { + if (resourceType == ResourceTypeEnum.BUSINESS) { + long appId = Long.parseLong(resourceId); + if (appId > 0) { + return getResourceAppInfoById(appId); + } + } else { + return null; + } + return null; + } +} diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceNameQueryServiceImpl.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceNameQueryServiceImpl.java new file mode 100644 index 0000000000..686f1fe65d --- /dev/null +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceNameQueryServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.backup.auth; + +import com.tencent.bk.job.backup.client.ServiceApplicationResourceClient; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.iam.service.ResourceNameQueryService; +import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service("ResourceNameQueryService") +public class ResourceNameQueryServiceImpl implements ResourceNameQueryService { + + private final ServiceApplicationResourceClient applicationResourceClient; + + @Autowired + public ResourceNameQueryServiceImpl(AuthService authService, + ServiceApplicationResourceClient applicationResourceClient) { + this.applicationResourceClient = applicationResourceClient; + authService.setResourceNameQueryService(this); + } + + private String getAppName(long appId) { + ServiceApplicationDTO serviceApplicationDTO = applicationResourceClient.queryAppById(appId); + if (serviceApplicationDTO == null) return null; + return serviceApplicationDTO.getName(); + } + + @Override + public String getResourceName(ResourceTypeEnum resourceType, String resourceId) { + if (resourceType == ResourceTypeEnum.BUSINESS) { + long appId = Long.parseLong(resourceId); + if (appId > 0) { + return getAppName(appId); + } + log.warn("Cannot find appName by appId {}", appId); + return null; + } + log.warn("Cannot find ResourceName by resourceType {} resourceId {}", resourceType, resourceId); + return null; + } + +} diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbRequestIdHeaderGatewayFilterFactory.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceServiceRegister.java similarity index 61% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbRequestIdHeaderGatewayFilterFactory.java rename to src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceServiceRegister.java index fab3808f2b..9e6f1dd58b 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbRequestIdHeaderGatewayFilterFactory.java +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/auth/ResourceServiceRegister.java @@ -22,43 +22,33 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.filter.esb; +package com.tencent.bk.job.backup.auth; -import brave.Tracer; -import com.tencent.bk.job.common.util.RequestUtil; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.iam.service.ResourceAppInfoQueryService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; -/** - * ESB request-id 设置 - */ @Slf4j @Component -public class AddEsbRequestIdHeaderGatewayFilterFactory - extends AbstractGatewayFilterFactory { - private final Tracer tracer; +@Lazy(false) +public class ResourceServiceRegister implements InitializingBean { + + private final ResourceAppInfoQueryService resourceAppInfoQueryService; + private final AuthService authService; @Autowired - public AddEsbRequestIdHeaderGatewayFilterFactory(Tracer tracer) { - super(Config.class); - this.tracer = tracer; + public ResourceServiceRegister(ResourceAppInfoQueryService resourceAppInfoQueryService, + AuthService authService) { + this.resourceAppInfoQueryService = resourceAppInfoQueryService; + this.authService = authService; } @Override - public GatewayFilter apply(Config config) { - return (exchange, chain) -> { - ServerHttpRequest request = exchange.getRequest(); - String requestId = RequestUtil.getHeaderValue(request, "X-Bkapi-Request-Id"); - return chain.filter(exchange.mutate().request(request).build()); - }; - } - - static class Config { - + public void afterPropertiesSet() { + this.authService.setResourceAppInfoQueryService(resourceAppInfoQueryService); } - } diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ExportJobExecutor.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ExportJobExecutor.java index 0c7abd10bf..403f8e7d59 100644 --- a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ExportJobExecutor.java +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ExportJobExecutor.java @@ -34,7 +34,7 @@ import com.tencent.bk.job.backup.service.*; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.Base64Util; import com.tencent.bk.job.common.util.crypto.AESUtils; import com.tencent.bk.job.common.util.file.ZipUtil; diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ImportJobExecutor.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ImportJobExecutor.java index a36ae1fbf5..de13a57d17 100644 --- a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ImportJobExecutor.java +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/executor/ImportJobExecutor.java @@ -33,7 +33,7 @@ import com.tencent.bk.job.backup.service.*; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.json.JsonMapper; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; diff --git a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/service/impl/ImportJobServiceImpl.java b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/service/impl/ImportJobServiceImpl.java index edd28ac5f0..cca371cf52 100644 --- a/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/service/impl/ImportJobServiceImpl.java +++ b/src/backend/job-backup/service-job-backup/src/main/java/com/tencent/bk/job/backup/service/impl/ImportJobServiceImpl.java @@ -33,7 +33,7 @@ import com.tencent.bk.job.backup.service.ImportJobService; import com.tencent.bk.job.backup.service.LogService; import com.tencent.bk.job.backup.service.StorageService; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.redis.util.LockUtils; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.crypto.AESUtils; diff --git a/src/backend/job-config/build.gradle b/src/backend/job-config/build.gradle index 1cd2c9b9dd..2b835d13f5 100644 --- a/src/backend/job-config/build.gradle +++ b/src/backend/job-config/build.gradle @@ -25,15 +25,17 @@ ext { if (System.getProperty("jobConfigVersion")) { set("jobConfigVersion", System.getProperty("jobConfigVersion")) + } else if (System.getProperty("version")) { + set("jobConfigVersion", System.getProperty("version")) } else { set("jobConfigVersion", "1.0.0") } } version "${jobConfigVersion}" dependencies { - compile project(':commons:common') - compile project(":commons:common-i18n") - compile project(":commons:common-spring-ext") + api project(':commons:common') + api project(":commons:common-i18n") + api project(":commons:common-spring-ext") implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation("org.springframework.boot:spring-boot-autoconfigure") @@ -41,6 +43,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' implementation 'org.springframework.cloud:spring-cloud-config-server' @@ -51,13 +54,13 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-annotations' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } apply plugin: 'org.springframework.boot' springBoot { - mainClassName = "com.tencent.bk.job.config.JobConfigBootApplication" + mainClass = "com.tencent.bk.job.config.JobConfigBootApplication" buildInfo() } apply from: "$rootDir/task_job_package.gradle" diff --git a/src/backend/job-config/src/main/java/com/tencent/bk/job/config/config/WebSecurityConfiguration.java b/src/backend/job-config/src/main/java/com/tencent/bk/job/config/config/WebSecurityConfiguration.java index ebdd280307..8e4cca6ef6 100644 --- a/src/backend/job-config/src/main/java/com/tencent/bk/job/config/config/WebSecurityConfiguration.java +++ b/src/backend/job-config/src/main/java/com/tencent/bk/job/config/config/WebSecurityConfiguration.java @@ -24,40 +24,27 @@ package com.tencent.bk.job.config.config; -import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.util.matcher.AnyRequestMatcher; @Configuration @EnableWebSecurity public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { -// @Override -// protected void configure(HttpSecurity http) throws Exception { -// http.csrf().disable().authorizeRequests() -// .anyRequest().authenticated().and() -// .httpBasic(); -// } @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); - http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() - .antMatchers("/actuator/health").permitAll() - .antMatchers("/actuator/info").permitAll() - .antMatchers(HttpMethod.POST, "/actuator/loggers/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/configprops/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/env/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/mappings/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/metrics/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/prometheus/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/beans/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/conditions/**").hasRole("ENDPOINT_ADMIN") - .antMatchers("/actuator/scheduledtasks/**").hasRole("ENDPOINT_ADMIN") + http.requestMatcher(AnyRequestMatcher.INSTANCE).authorizeRequests() + .antMatchers("/actuator/health/**", "/actuator/info").permitAll() .and() - .httpBasic(); + .httpBasic() + .and() + .authorizeRequests() + .anyRequest() + .authenticated(); } } diff --git a/src/backend/job-crontab/api-job-crontab/build.gradle b/src/backend/job-crontab/api-job-crontab/build.gradle index 6fa384f0e4..8b22068cf7 100644 --- a/src/backend/job-crontab/api-job-crontab/build.gradle +++ b/src/backend/job-crontab/api-job-crontab/build.gradle @@ -23,11 +23,11 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') - compile project(':commons:esb-sdk') - compile project(':commons:common-iam') - compile project(":job-execute:api-job-execute") + api project(':commons:common') + api project(':commons:common-i18n') + api project(':commons:esb-sdk') + api project(':commons:common-iam') + api project(":job-execute:api-job-execute") implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/EsbCronJobResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/EsbCronJobResource.java index 8b8fe4b803..3ecc47e9e0 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/EsbCronJobResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/EsbCronJobResource.java @@ -24,35 +24,33 @@ package com.tencent.bk.job.crontab.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.crontab.model.esb.request.EsbGetCronListRequest; import com.tencent.bk.job.crontab.model.esb.request.EsbSaveCronRequest; import com.tencent.bk.job.crontab.model.esb.request.EsbUpdateCronStatusRequest; import com.tencent.bk.job.crontab.model.esb.response.EsbCronInfoResponse; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * @since 26/2/2020 16:24 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbCronJobResource { @PostMapping("/get_cron_list") - EsbResp> getCronList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbGetCronListRequest request); + EsbResp> getCronList(@RequestBody EsbGetCronListRequest request); @PostMapping(value = "/update_cron_status") - EsbResp updateCronStatus( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbUpdateCronStatusRequest request); + EsbResp updateCronStatus(@RequestBody EsbUpdateCronStatusRequest request); @PostMapping(value = "/save_cron") - EsbResp saveCron(@RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbSaveCronRequest request); + EsbResp saveCron(@RequestBody EsbSaveCronRequest request); } diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java index d12acb9ed3..b305b580a9 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.crontab.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.crontab.model.esb.v3.request.EsbGetCronDetailV3Request; @@ -31,62 +33,84 @@ import com.tencent.bk.job.crontab.model.esb.v3.request.EsbSaveCronV3Request; import com.tencent.bk.job.crontab.model.esb.v3.request.EsbUpdateCronStatusV3Request; import com.tencent.bk.job.crontab.model.esb.v3.response.EsbCronInfoV3Response; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @since 26/2/2020 16:24 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbCronJobV3Resource { + @GetMapping("/get_cron_list") + EsbResp> getCronList( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "creator", required = false) String creator, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "create_time_start", required = false) Long createTimeStart, + @RequestParam(value = "create_time_end", required = false) Long createTimeEnd, + @RequestParam(value = "last_modify_user", required = false) String lastModifyUser, + @RequestParam(value = "last_modify_time_start", required = false) Long lastModifyTimeStart, + @RequestParam(value = "last_modify_time_end", required = false) Long lastModifyTimeEnd, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_cron_detail") + EsbResp getCronDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "id") Long id); + + /** * 获取定时任务列表 * - * @param lang 用户语言 * @param request 查询请求 * @return 定时任务列表 */ @PostMapping("/get_cron_list") - EsbResp> getCronList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp> getCronListUsingPost( @RequestBody EsbGetCronListV3Request request); /** * 获取定时任务详情 * - * @param lang 用户语言 * @param request 查询请求 * @return 定时任务详情 */ @PostMapping("/get_cron_detail") - EsbResp getCronDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getCronDetailUsingPost( @RequestBody EsbGetCronDetailV3Request request); /** * 更新定时任务状态 * - * @param lang 用户语言 * @param request 更新请求 * @return 定时任务详情 */ @PostMapping(value = "/update_cron_status") EsbResp updateCronStatus( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbUpdateCronStatusV3Request request); /** * 更新定时任务详情 * - * @param lang 用户语言 * @param request 更新请求 * @return 定时任务详情 */ @PostMapping(value = "/save_cron") EsbResp saveCron( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbSaveCronV3Request request); } diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/IamCallbackController.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/IamCallbackController.java index fbcd7ff788..2ced74041a 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/IamCallbackController.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/IamCallbackController.java @@ -43,5 +43,5 @@ public interface IamCallbackController { * @return 权限中心回调响应 */ @PostMapping("/job") - CallbackBaseResponseDTO cronJobCallback(@RequestBody CallbackRequestDTO callbackRequest); + CallbackBaseResponseDTO callback(@RequestBody CallbackRequestDTO callbackRequest); } diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronJobResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronJobResource.java index 27ce67dd38..da4fd7f81c 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronJobResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronJobResource.java @@ -24,13 +24,23 @@ package com.tencent.bk.job.crontab.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.crontab.model.CronJobCreateUpdateReq; import com.tencent.bk.job.crontab.model.CronJobVO; import com.tencent.bk.job.crontab.model.inner.ServiceCronJobDTO; +import com.tencent.bk.job.crontab.model.inner.request.InternalUpdateCronStatusRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @@ -40,6 +50,8 @@ */ @Api(tags = {"Cron_Job"}) @RequestMapping("/service/app/{appId}/cron/job") +@RestController +@InternalAPI public interface ServiceCronJobResource { /** @@ -81,11 +93,17 @@ ServiceResponse saveCronJob( * @param status 定时任务状态 * @return 是否更新成功 */ - @PutMapping("/{cronJobId}/status") + @PostMapping("/{cronJobId}/status") ServiceResponse updateCronJobStatus( - @ApiParam(value = "业务 ID", required = true, example = "2") @PathVariable("appId") Long appId, - @ApiParam(value = "定时任务 ID", required = true) @PathVariable("cronJobId") Long cronJobId, - @ApiParam(value = "状态", required = true) @RequestParam(value = "status") Integer status + @ApiParam(value = "业务 ID", required = true, example = "2") + @PathVariable("appId") + Long appId, + @ApiParam(value = "定时任务 ID", required = true) + @PathVariable("cronJobId") + Long cronJobId, + @ApiParam(value = "状态", required = true) + @RequestBody + InternalUpdateCronStatusRequest request ); /** diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronMetricsResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronMetricsResource.java index 4fab574a45..d60e64079b 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronMetricsResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceCronMetricsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.crontab.api.inner; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -36,6 +37,7 @@ @Api(tags = {"job-crontab:Service:Metrics"}) @RequestMapping("/service/metrics") @RestController +@EsbAPI public interface ServiceCronMetricsResource { @ApiOperation(value = "定时任务总量", produces = "application/json") diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceInnerCronJobResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceInnerCronJobResource.java index b41a8f4731..1e67660f75 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceInnerCronJobResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/ServiceInnerCronJobResource.java @@ -24,11 +24,18 @@ package com.tencent.bk.job.crontab.api.inner; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.crontab.model.inner.ServiceInnerCronJobInfoDTO; import com.tencent.bk.job.crontab.model.inner.request.ServiceAddInnerCronJobRequestDTO; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -38,6 +45,7 @@ @Api(tags = {"Inner_Cron_Job"}) @RequestMapping("/service/inner/cron/job") @RestController +@EsbAPI public interface ServiceInnerCronJobResource { /** diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebCronJobResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebCronJobResource.java index a09a4599ac..9f94173eda 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebCronJobResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebCronJobResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.crontab.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.crontab.model.BatchUpdateCronJobReq; @@ -33,7 +34,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @@ -44,6 +54,7 @@ @Api(tags = {"job-crontab:web:Cron_Job"}) @RequestMapping("/web/app/{appId}/cron/job") @RestController +@WebAPI public interface WebCronJobResource { /** diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebPermissionResource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebPermissionResource.java index 796f092b80..ff58da3f20 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebPermissionResource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/WebPermissionResource.java @@ -24,17 +24,25 @@ package com.tencent.bk.job.crontab.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.crontab.model.OperationPermissionReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-crontab:web:Permission"}) @RequestMapping("/web/permission/") @RestController +@WebAPI public interface WebPermissionResource { /** * 获取权限申请URL diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/constants/CronStatusEnum.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/constants/CronStatusEnum.java new file mode 100644 index 0000000000..10daee242b --- /dev/null +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/constants/CronStatusEnum.java @@ -0,0 +1,57 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.crontab.common.constants; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * 定时任务状态 + */ +public enum CronStatusEnum { + RUNNING(1), STOPPING(2); + + + @JsonValue + private final Integer status; + + CronStatusEnum(Integer status) { + this.status = status; + } + + @JsonCreator + public static CronStatusEnum valOf(int cronStatus) { + for (CronStatusEnum status : values()) { + if (status.getStatus() == cronStatus) { + return status; + } + } + return null; + } + + public Integer getStatus() { + return status; + } +} diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/response/EsbCronInfoResponse.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/response/EsbCronInfoResponse.java index 6d2780c7e0..3e6e8f75fa 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/response/EsbCronInfoResponse.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/response/EsbCronInfoResponse.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.crontab.model.esb.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -32,7 +31,6 @@ * @since 26/2/2020 20:58 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbCronInfoResponse { /** diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbSaveCronV3Request.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbSaveCronV3Request.java index 53c9043179..02a4a2caa6 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbSaveCronV3Request.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbSaveCronV3Request.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.EsbReq; import com.tencent.bk.job.common.esb.model.job.v3.EsbGlobalVarV3DTO; +import com.tencent.bk.job.common.exception.InvalidParamException; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.lang3.StringUtils; @@ -70,6 +71,14 @@ public class EsbSaveCronV3Request extends EsbReq { @JsonProperty("expression") private String cronExpression; + /** + * 单次执行的指定执行时间(Unix时间戳) + *

+ * 不可与 cronExpression 同时为空 + */ + @JsonProperty("execute_time") + private Long executeTime; + /** * 定时任务的变量信息 */ @@ -78,20 +87,23 @@ public class EsbSaveCronV3Request extends EsbReq { public boolean validate() { if (appId == null || appId <= 0) { - return false; + throw new InvalidParamException("bk_biz_id", "bk_biz_id must be a positive long number"); } if (id != null && id < 0) { - return false; + throw new InvalidParamException("id", "id must be a positive long number when updating"); } if (id == null || id == 0) { if (planId == null || planId <= 0) { - return false; + throw new InvalidParamException("job_plan_id", "job_plan_id must be a positive long number"); } if (StringUtils.isBlank(name)) { - return false; + throw new InvalidParamException("name", "name cannot be null or blank when create"); } - if (StringUtils.isBlank(cronExpression)) { - return false; + if (StringUtils.isBlank(cronExpression) && (executeTime == null || executeTime <= 0)) { + throw new InvalidParamException( + "expression/execute_time", + "expression/execute_time cannot both be null or invalid" + ); } } else { boolean hasChange = false; @@ -108,8 +120,16 @@ public boolean validate() { } else { cronExpression = null; } + if (executeTime != null && executeTime > 0) { + hasChange = true; + } else { + executeTime = null; + } if (!hasChange) { - return false; + throw new InvalidParamException( + "job_plan_id/name/expression/execute_time", + "At least one of job_plan_id/name/expression/execute_time must be given to update cron " + id + ); } } return true; diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbUpdateCronStatusV3Request.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbUpdateCronStatusV3Request.java index 17afb21ac8..99f34e492c 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbUpdateCronStatusV3Request.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbUpdateCronStatusV3Request.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.EsbReq; +import com.tencent.bk.job.common.exception.InvalidParamException; import lombok.Data; import lombok.EqualsAndHashCode; @@ -55,11 +56,12 @@ public class EsbUpdateCronStatusV3Request extends EsbReq { private Integer status; public boolean validate() { - if (id > 0) { - if (status == 0 || status == 1) { - return true; - } + if (id == null || id <= 0) { + throw new InvalidParamException("id", "id must be a positive integer"); } - return false; + if (status == null || status < 0) { + throw new InvalidParamException("status", "status must >= 0"); + } + return true; } } diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/response/EsbCronInfoV3Response.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/response/EsbCronInfoV3Response.java index 76a377b9d0..0231a5a3cb 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/response/EsbCronInfoV3Response.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/response/EsbCronInfoV3Response.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.crontab.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.v3.EsbGlobalVarV3DTO; import lombok.Data; @@ -35,7 +34,6 @@ * @since 26/2/2020 20:58 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbCronInfoV3Response { /** diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/MigrationService.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/inner/request/InternalUpdateCronStatusRequest.java similarity index 84% rename from src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/MigrationService.java rename to src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/inner/request/InternalUpdateCronStatusRequest.java index 71b020bf3e..d38d209753 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/MigrationService.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/inner/request/InternalUpdateCronStatusRequest.java @@ -22,17 +22,18 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.manage.service; +package com.tencent.bk.job.crontab.model.inner.request; + +import lombok.Data; /** - * 微服务升级 + * 更新定时任务状态-启停 */ -public interface MigrationService { +@Data +public class InternalUpdateCronStatusRequest { + private String operator; /** - * 加密DB账号的密码 - * - * @param key 加密key - * @return 结果 + * 定时任务状态,1-启动,2-停止 */ - boolean encryptDbAccountPassword(String key); + private Integer status; } diff --git a/src/backend/job-crontab/boot-job-crontab/build.gradle b/src/backend/job-crontab/boot-job-crontab/build.gradle index c3d4fd099d..da0c99e8d5 100644 --- a/src/backend/job-crontab/boot-job-crontab/build.gradle +++ b/src/backend/job-crontab/boot-job-crontab/build.gradle @@ -25,8 +25,8 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-crontab:service-job-crontab") - compile project(":commons:common-i18n") + api project(":job-crontab:service-job-crontab") + api project(":commons:common-i18n") implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -39,12 +39,13 @@ dependencies { implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-quartz') implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') implementation 'org.springframework:spring-webmvc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' runtimeOnly 'mysql:mysql-connector-java' testImplementation("com.h2database:h2") } springBoot { - mainClassName = "com.tencent.bk.job.crontab.JobCrontabBootApplication" + mainClass = "com.tencent.bk.job.crontab.JobCrontabBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/FilterConfig.java b/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/FilterConfig.java index ec8d76b380..3dcd1283fd 100644 --- a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/FilterConfig.java +++ b/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/FilterConfig.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.crontab.config; -import com.tencent.bk.job.common.web.filter.RepeatableReadServletRequestResponseFilter; +import com.tencent.bk.job.common.web.filter.RepeatableReadWriteServletRequestResponseFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,7 +33,7 @@ public class FilterConfig { @Bean public FilterRegistrationBean repeatableRSRRFilterRegister() { - FilterRegistrationBean registration = + FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(repeatableRRRFilter()); registration.addUrlPatterns("/esb/api/*"); @@ -43,7 +43,7 @@ public FilterRegistrationBean repeatableRSRRFilterRegister() { } @Bean(name = "repeatableReadRequestResponseFilter") - public RepeatableReadServletRequestResponseFilter repeatableRRRFilter() { - return new RepeatableReadServletRequestResponseFilter(); + public RepeatableReadWriteServletRequestResponseFilter repeatableRRRFilter() { + return new RepeatableReadWriteServletRequestResponseFilter(); } } diff --git a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/I18nConfig.java b/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/I18nConfig.java deleted file mode 100644 index 4233d406d0..0000000000 --- a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/I18nConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.crontab.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -/** - * @date 2019/09/19 - */ -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/InterceptorConfiguration.java b/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/InterceptorConfiguration.java index 529b400b1e..25e4fb4735 100644 --- a/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/InterceptorConfiguration.java +++ b/src/backend/job-crontab/boot-job-crontab/src/main/java/com/tencent/bk/job/crontab/config/InterceptorConfiguration.java @@ -24,7 +24,10 @@ package com.tencent.bk.job.crontab.config; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; +import com.tencent.bk.job.common.iam.interceptor.JobIamInterceptor; import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; +import com.tencent.bk.job.common.web.interceptor.EsbReqRewriteInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import org.springframework.beans.factory.annotation.Autowired; @@ -39,16 +42,27 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final EsbApiLogInterceptor esbApiLogInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; + private final JobIamInterceptor iamInterceptor; + private final EsbReqRewriteInterceptor esbReqRewriteInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - EsbApiLogInterceptor esbApiLogInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + EsbApiLogInterceptor esbApiLogInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor, + JobIamInterceptor iamInterceptor, + EsbReqRewriteInterceptor esbReqRewriteInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; + this.authAppInterceptor = authAppInterceptor; this.esbApiLogInterceptor = esbApiLogInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; + this.iamInterceptor = iamInterceptor; + this.esbReqRewriteInterceptor = esbReqRewriteInterceptor; } @Override @@ -56,7 +70,10 @@ public void addInterceptors(InterceptorRegistry registry) { // 注册拦截器 registry.addInterceptor(serviceSecurityInterceptor).addPathPatterns("/**").order(0); registry.addInterceptor(jobCommonInterceptor).addPathPatterns("/**").order(1); + registry.addInterceptor(iamInterceptor).addPathPatterns("/iam/api/v1/resources/**").order(2); registry.addInterceptor(esbApiLogInterceptor).addPathPatterns("/esb/api/**").order(10); + registry.addInterceptor(esbReqRewriteInterceptor).addPathPatterns("/esb/api/**").order(11); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(12); } } diff --git a/src/backend/job-crontab/build.gradle b/src/backend/job-crontab/build.gradle index e52a27f88c..679ad309ed 100644 --- a/src/backend/job-crontab/build.gradle +++ b/src/backend/job-crontab/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobCrontabVersion")) { set("jobCrontabVersion", System.getProperty("jobCrontabVersion")) + } else if (System.getProperty("version")) { + set("jobCrontabVersion", System.getProperty("version")) } else { set("jobCrontabVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobCrontabVersion}" subprojects { version "${jobCrontabVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation('ch.qos.logback:logback-classic') implementation('io.springfox:springfox-swagger2') implementation('io.springfox:springfox-swagger-ui') - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-crontab/service-job-crontab/build.gradle b/src/backend/job-crontab/service-job-crontab/build.gradle index 78b071e936..d93d943b96 100644 --- a/src/backend/job-crontab/service-job-crontab/build.gradle +++ b/src/backend/job-crontab/service-job-crontab/build.gradle @@ -24,21 +24,21 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":commons:common-redis") - compile project(":commons:common-web") - compile project(':commons:common-security') - compile project(":job-execute:api-job-execute") - compile project(":job-manage:api-job-manage") - compile project(":job-crontab:api-job-crontab") - compile project(":job-crontab:model-job-crontab") + api project(":commons:common-redis") + api project(":commons:common-web") + api project(':commons:common-security') + api project(":job-execute:api-job-execute") + api project(":job-manage:api-job-manage") + api project(":job-crontab:api-job-crontab") + api project(":job-crontab:model-job-crontab") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-jooq") implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-quartz') implementation "org.apache.commons:commons-collections4" - compile("org.springframework.cloud:spring-cloud-starter-consul-discovery") - compile("org.springframework.cloud:spring-cloud-starter-sleuth") + api("org.springframework.cloud:spring-cloud-starter-consul-discovery") + api("org.springframework.cloud:spring-cloud-starter-sleuth") implementation('org.springframework.cloud:spring-cloud-starter-openfeign') implementation "ch.qos.logback:logback-core" implementation "ch.qos.logback:logback-classic" diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/impl/EsbCronJobResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/impl/EsbCronJobResourceImpl.java index edf7dba7e6..dad6777a0d 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/impl/EsbCronJobResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/impl/EsbCronJobResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -77,7 +77,7 @@ public EsbCronJobResourceImpl(CronJobService cronJobService, MessageI18nService @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_cron_list"}) - public EsbResp> getCronList(String lang, EsbGetCronListRequest request) { + public EsbResp> getCronList(EsbGetCronListRequest request) { if (request == null) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService.getI18n(String.valueOf(ErrorCode.ILLEGAL_PARAM))); @@ -135,7 +135,7 @@ public EsbResp> getCronList(String lang, EsbGetCronLis @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_update_cron_status"}) - public EsbResp updateCronStatus(String lang, EsbUpdateCronStatusRequest request) { + public EsbResp updateCronStatus(EsbUpdateCronStatusRequest request) { String username = request.getUserName(); Long appId = request.getAppId(); if (request.validate()) { @@ -173,7 +173,7 @@ public EsbResp updateCronStatus(String lang, EsbUpdateCronS @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_save_cron"}) - public EsbResp saveCron(String lang, EsbSaveCronRequest request) { + public EsbResp saveCron(EsbSaveCronRequest request) { CronJobInfoDTO cronJobInfo = new CronJobInfoDTO(); EsbCronInfoResponse esbCronInfoResponse = new EsbCronInfoResponse(); esbCronInfoResponse.setId(0L); diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java index 8a7cf9d8fb..ef7128db2a 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java @@ -30,7 +30,8 @@ import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbGlobalVarV3DTO; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.exception.ServiceException; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -42,6 +43,7 @@ import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.crontab.api.esb.v3.EsbCronJobV3Resource; import com.tencent.bk.job.crontab.client.ServiceTaskPlanResourceClient; +import com.tencent.bk.job.crontab.common.constants.CronStatusEnum; import com.tencent.bk.job.crontab.exception.TaskExecuteAuthFailedException; import com.tencent.bk.job.crontab.model.dto.CronJobInfoDTO; import com.tencent.bk.job.crontab.model.dto.CronJobVariableDTO; @@ -83,9 +85,52 @@ public EsbCronJobV3ResourceImpl(CronJobService cronJobService, MessageI18nServic this.taskPlanResource = taskPlanResource; } + @Override + public EsbResp> getCronList(String username, + String appCode, + Long appId, + Long id, + String creator, + String name, + Integer status, + Long createTimeStart, + Long createTimeEnd, + String lastModifyUser, + Long lastModifyTimeStart, + Long lastModifyTimeEnd, + Integer start, + Integer length) { + EsbGetCronListV3Request request = new EsbGetCronListV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setId(id); + request.setCreator(creator); + request.setName(name); + request.setStatus(status); + request.setCreateTimeStart(createTimeStart); + request.setLastModifyUser(lastModifyUser); + request.setCreateTimeEnd(createTimeEnd); + request.setLastModifyTimeEnd(lastModifyTimeEnd); + request.setLastModifyTimeStart(lastModifyTimeStart); + request.setStart(start); + request.setLength(length); + return getCronListUsingPost(request); + } + + @Override + public EsbResp getCronDetail(String username, String appCode, Long appId, Long id) { + EsbGetCronDetailV3Request request = new EsbGetCronDetailV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setId(id); + return getCronDetailUsingPost(request); + } + @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_cron_list"}) - public EsbResp> getCronList(String lang, EsbGetCronListV3Request request) { + public EsbResp> getCronListUsingPost(EsbGetCronListV3Request request) { if (request == null) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService.getI18n(String.valueOf(ErrorCode.ILLEGAL_PARAM))); @@ -154,37 +199,32 @@ public EsbResp> getCronList(String lang, Es @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_update_cron_status"}) - public EsbResp updateCronStatus(String lang, EsbUpdateCronStatusV3Request request) { + public EsbResp updateCronStatus(EsbUpdateCronStatusV3Request request) { String username = request.getUserName(); Long appId = request.getAppId(); - if (request.validate()) { - - AuthResult authResult = authService.auth(true, request.getUserName(), ActionId.MANAGE_CRON, - ResourceTypeEnum.CRON, request.getId().toString(), - PathBuilder.newBuilder(ResourceTypeEnum.BUSINESS.getId(), appId.toString()).build()); - if (!authResult.isPass()) { - return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources()); - } + request.validate(); + AuthResult authResult = authService.auth(true, request.getUserName(), ActionId.MANAGE_CRON, + ResourceTypeEnum.CRON, request.getId().toString(), + PathBuilder.newBuilder(ResourceTypeEnum.BUSINESS.getId(), appId.toString()).build()); + if (!authResult.isPass()) { + return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources()); + } - Boolean updateResult = null; - try { - updateResult = cronJobService.changeCronJobEnableStatus(username, appId, request.getId(), - request.getStatus() == 1); - } catch (TaskExecuteAuthFailedException e) { - if (e.getAuthResult() != null) { - return authService.buildEsbAuthFailResp(e.getAuthResult().getRequiredActionResources()); - } else { - return EsbResp.buildAuthFailResult(null, i18nService); - } - } - if (updateResult) { - EsbCronInfoV3Response esbCronInfoV3Response = new EsbCronInfoV3Response(); - esbCronInfoV3Response.setId(request.getId()); - return EsbResp.buildSuccessResp(esbCronInfoV3Response); + Boolean updateResult = null; + try { + updateResult = cronJobService.changeCronJobEnableStatus(username, appId, request.getId(), + CronStatusEnum.RUNNING.getStatus().equals(request.getStatus())); + } catch (TaskExecuteAuthFailedException e) { + if (e.getAuthResult() != null) { + return authService.buildEsbAuthFailResp(e.getAuthResult().getRequiredActionResources()); + } else { + return EsbResp.buildAuthFailResult(null, i18nService); } - } else { - return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, - i18nService.getI18n(String.valueOf(ErrorCode.ILLEGAL_PARAM))); + } + if (updateResult) { + EsbCronInfoV3Response esbCronInfoV3Response = new EsbCronInfoV3Response(); + esbCronInfoV3Response.setId(request.getId()); + return EsbResp.buildSuccessResp(esbCronInfoV3Response); } return EsbResp.buildCommonFailResp(ErrorCode.UPDATE_CRON_JOB_FAILED, i18nService.getI18n(String.valueOf(ErrorCode.UPDATE_CRON_JOB_FAILED))); @@ -192,23 +232,38 @@ public EsbResp updateCronStatus(String lang, EsbUpdateCro @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_save_cron"}) - public EsbResp saveCron(String lang, EsbSaveCronV3Request request) { + public EsbResp saveCron(EsbSaveCronV3Request request) { CronJobInfoDTO cronJobInfo = new CronJobInfoDTO(); EsbCronInfoV3Response esbCronInfoV3Response = new EsbCronInfoV3Response(); esbCronInfoV3Response.setId(0L); - if (request == null || !request.validate()) { - return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, - i18nService.getI18n(String.valueOf(ErrorCode.ILLEGAL_PARAM))); + if (request != null) { + request.validate(); + } else { + throw new ServiceException(ErrorCode.ILLEGAL_PARAM, "request body cannot be null"); } Long appId = request.getAppId(); AuthResult authResult; if (request.getId() != null && request.getId() > 0) { - authResult = authService.auth(true, request.getUserName(), ActionId.MANAGE_CRON, ResourceTypeEnum.CRON, - request.getId().toString(), PathBuilder.newBuilder(ResourceTypeEnum.BUSINESS.getId(), - appId.toString()).build()); + authResult = authService.auth( + true, + request.getUserName(), + ActionId.MANAGE_CRON, + ResourceTypeEnum.CRON, + request.getId().toString(), + PathBuilder.newBuilder( + ResourceTypeEnum.BUSINESS.getId(), + appId.toString() + ).build() + ); } else { - authResult = authService.auth(true, request.getUserName(), ActionId.CREATE_CRON, ResourceTypeEnum.BUSINESS, - request.getAppId().toString(), null); + authResult = authService.auth( + true, + request.getUserName(), + ActionId.CREATE_CRON, + ResourceTypeEnum.BUSINESS, + request.getAppId().toString(), + null + ); } if (!authResult.isPass()) { return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources()); @@ -218,6 +273,7 @@ public EsbResp saveCron(String lang, EsbSaveCronV3Request cronJobInfo.setName(request.getName()); cronJobInfo.setTaskPlanId(request.getPlanId()); cronJobInfo.setCronExpression(request.getCronExpression()); + cronJobInfo.setExecuteTime(request.getExecuteTime()); List globalVarV3DTOList = request.getGlobalVarList(); if (globalVarV3DTOList != null) { // 校验id/name,解析id @@ -295,7 +351,7 @@ public EsbResp saveCron(String lang, EsbSaveCronV3Request } @Override - public EsbResp getCronDetail(String lang, EsbGetCronDetailV3Request request) { + public EsbResp getCronDetailUsingPost(EsbGetCronDetailV3Request request) { AuthResult authResult = authService.auth(true, request.getUserName(), ActionId.LIST_BUSINESS, ResourceTypeEnum.BUSINESS, request.getAppId().toString(), null); if (!authResult.isPass()) { diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/impl/IamCallbackControllerImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/impl/IamCallbackControllerImpl.java index da49e9a30f..516d559082 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/impl/IamCallbackControllerImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/iam/impl/IamCallbackControllerImpl.java @@ -24,118 +24,136 @@ package com.tencent.bk.job.crontab.api.iam.impl; -import com.tencent.bk.job.common.iam.controller.AbstractIamController; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.crontab.api.iam.IamCallbackController; import com.tencent.bk.job.crontab.model.dto.CronJobInfoDTO; import com.tencent.bk.job.crontab.service.CronJobService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; -import com.tencent.bk.sdk.iam.helper.AuthHelper; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import java.util.Map; -/** - * @since 23/3/2020 11:20 - */ @Slf4j @RestController -public class IamCallbackControllerImpl extends AbstractIamController implements IamCallbackController { +public class IamCallbackControllerImpl extends BaseIamCallbackService implements IamCallbackController { private final CronJobService cronJobService; @Autowired - public IamCallbackControllerImpl(CronJobService cronJobService, AuthHelper authHelper) { - super(authHelper); + public IamCallbackControllerImpl(CronJobService cronJobService) { this.cronJobService = cronJobService; } + private Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); + + CronJobInfoDTO cronJobQuery = new CronJobInfoDTO(); + cronJobQuery.setAppId(searchCondition.getAppIdList().get(0)); + return Pair.of(cronJobQuery, baseSearchCondition); + } + + private InstanceInfoDTO convert(CronJobInfoDTO cronJobInfo) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(cronJobInfo.getId())); + instanceInfo.setDisplayName(cronJobInfo.getName()); + return instanceInfo; + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp( + CallbackRequestDTO callbackRequest + ) { + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + CronJobInfoDTO cronJobQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + cronJobQuery.setName(callbackRequest.getFilter().getKeyword()); + PageData cronJobInfoPageData = + cronJobService.listPageCronJobInfos(cronJobQuery, baseSearchCondition); + + return IamRespUtil.getSearchInstanceRespFromPageData(cronJobInfoPageData, this::convert); + } + + @Override + protected ListInstanceResponseDTO listInstanceResp( + CallbackRequestDTO callbackRequest + ) { + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + CronJobInfoDTO cronJobQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + PageData cronJobInfoPageData = + cronJobService.listPageCronJobInfos(cronJobQuery, baseSearchCondition); + + return IamRespUtil.getListInstanceRespFromPageData(cronJobInfoPageData, this::convert); + } + @Override - public CallbackBaseResponseDTO cronJobCallback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - CronJobInfoDTO condition = new CronJobInfoDTO(); - condition.setAppId(searchCondition.getAppIdList().get(0)); - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - PageData cronJobInfoPageData = - cronJobService.listPageCronJobInfos(condition, baseSearchCondition); - - List instanceInfoList = - cronJobInfoPageData.getData().parallelStream().map(cronJobInfo -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(cronJobInfo.getId())); - instanceInfo.setDisplayName(cronJobInfo.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO listInstanceResponseData = new BaseDataResponseDTO<>(); - listInstanceResponseData.setResult(instanceInfoList); - listInstanceResponseData.setCount(cronJobInfoPageData.getTotal()); - instanceResponse.setData(listInstanceResponseData); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - long id = Long.parseLong(instanceId); - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - instanceInfo.setDisplayName(cronJobService.getCronJobNameById(id)); - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); + List instanceAttributeInfoList = new ArrayList<>(); + List cronJobIdList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + long id = Long.parseLong(instanceId); + cronJobIdList.add(id); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } } - return response; + Map cronJobInfoMap = cronJobService.getCronJobInfoMapByIds(cronJobIdList); + for (Long id : cronJobIdList) { + CronJobInfoDTO cronJobInfoDTO = cronJobInfoMap.get(id); + if (cronJobInfoDTO == null) { + return getNotFoundRespById(id.toString()); + } + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(cronJobInfoDTO.getAppId().toString()); + PathInfoDTO cronJobNode = new PathInfoDTO(); + cronJobNode.setType(ResourceId.CRON); + cronJobNode.setId(cronJobInfoDTO.getId().toString()); + rootNode.setChild(cronJobNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(id.toString()); + instanceInfo.setDisplayName(cronJobInfoDTO.getName()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); } } diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/impl/ServiceCronJobResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/impl/ServiceCronJobResourceImpl.java index dce5420846..9099180cec 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/impl/ServiceCronJobResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/inner/impl/ServiceCronJobResourceImpl.java @@ -32,10 +32,12 @@ import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.crontab.api.inner.ServiceCronJobResource; +import com.tencent.bk.job.crontab.common.constants.CronStatusEnum; import com.tencent.bk.job.crontab.model.CronJobCreateUpdateReq; import com.tencent.bk.job.crontab.model.CronJobVO; import com.tencent.bk.job.crontab.model.dto.CronJobInfoDTO; import com.tencent.bk.job.crontab.model.inner.ServiceCronJobDTO; +import com.tencent.bk.job.crontab.model.inner.request.InternalUpdateCronStatusRequest; import com.tencent.bk.job.crontab.service.CronJobService; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -86,13 +88,16 @@ public ServiceResponse> listCronJobs(Long appId, Boolean @Override public ServiceResponse saveCronJob(String username, Long appId, Long cronJobId, - CronJobCreateUpdateReq cronJobCreateUpdateReq) { + CronJobCreateUpdateReq cronJobCreateUpdateReq) { return null; } @Override - public ServiceResponse updateCronJobStatus(Long appId, Long cronJobId, Integer status) { - return null; + public ServiceResponse updateCronJobStatus(Long appId, Long cronJobId, + InternalUpdateCronStatusRequest request) { + log.info("Update cron job status, appId: {}, cronJobId: {}, request: {}", appId, cronJobId, request); + return ServiceResponse.buildSuccessResp(cronJobService.changeCronJobEnableStatus(request.getOperator(), + appId, cronJobId, CronStatusEnum.RUNNING.getStatus().equals(request.getStatus()))); } @Override @@ -111,8 +116,8 @@ public ServiceResponse>> batchListCronJobByPlanIds(Lon @Override public ServiceResponse saveCronJobWithId(String username, Long appId, Long cronJobId, Long createTime, - Long lastModifyTime, String lastModifyUser, - CronJobCreateUpdateReq cronJobCreateUpdateReq) { + Long lastModifyTime, String lastModifyUser, + CronJobCreateUpdateReq cronJobCreateUpdateReq) { JobContextUtil.setAllowMigration(true); CronJobInfoDTO cronJobInfoDTO = CronJobInfoDTO.fromReq(username, appId, cronJobCreateUpdateReq); cronJobInfoDTO.setId(cronJobId); diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebCronJobResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebCronJobResourceImpl.java index 537630768d..82d8d679e4 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebCronJobResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebCronJobResourceImpl.java @@ -27,7 +27,7 @@ import com.google.common.base.CaseFormat; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.service.WebAuthService; @@ -36,10 +36,13 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.JobContextUtil; -import com.tencent.bk.job.common.util.check.*; +import com.tencent.bk.job.common.util.check.IlegalCharChecker; +import com.tencent.bk.job.common.util.check.MaxLengthChecker; +import com.tencent.bk.job.common.util.check.NotEmptyChecker; +import com.tencent.bk.job.common.util.check.StringCheckHelper; +import com.tencent.bk.job.common.util.check.TrimChecker; import com.tencent.bk.job.common.util.check.exception.StringCheckException; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.crontab.api.web.WebCronJobResource; import com.tencent.bk.job.crontab.constant.ExecuteStatusEnum; import com.tencent.bk.job.crontab.exception.TaskExecuteAuthFailedException; @@ -64,7 +67,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -72,7 +79,7 @@ */ @Slf4j @RestController -public class WebCronJobResourceImpl extends AbstractJobController implements WebCronJobResource { +public class WebCronJobResourceImpl implements WebCronJobResource { private final CronJobService cronJobService; private final CronJobHistoryService cronJobHistoryService; @@ -82,11 +89,11 @@ public class WebCronJobResourceImpl extends AbstractJobController implements Web @Autowired public WebCronJobResourceImpl(CronJobService cronJobService, CronJobHistoryService cronJobHistoryService, MessageI18nService i18nService, - WebAuthService authService) { + WebAuthService webAuthService) { this.cronJobService = cronJobService; this.cronJobHistoryService = cronJobHistoryService; this.i18nService = i18nService; - this.authService = authService; + this.authService = webAuthService; } @Override diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebPermissionResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebPermissionResourceImpl.java index bb17064b4c..b96e269888 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebPermissionResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/web/impl/WebPermissionResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.crontab.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.service.WebAuthService; diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/ExceptionControllerAdvice.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/ExceptionControllerAdvice.java deleted file mode 100644 index db474aac05..0000000000 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/common/ExceptionControllerAdvice.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.crontab.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import feign.FeignException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MaxUploadSizeExceededException; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice({"com.tencent.bk.job.crontab.api.web", "com.tencent.bk.job.crontab.api.inner"}) -@Slf4j -public class ExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - - @Autowired - public ExceptionControllerAdvice(MessageI18nService i18nService) { - this.i18nService = i18nService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.error("Handle service exception", ex); - if (ex instanceof HttpStatusServiceException) { - HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException, i18nService), - httpStatusServiceException.getHttpStatus()); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex, i18nService), HttpStatus.OK); - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.error("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - @ExceptionHandler(FeignException.class) - @ResponseBody - ResponseEntity handleFeignException(HttpServletRequest request, FeignException ex) { - log.warn("Handle feign exception", ex); - if (ex.status() == HttpStatus.UNAUTHORIZED.value()) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_AUTH_FAIL, i18nService) - , HttpStatus.UNAUTHORIZED); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @ExceptionHandler(MaxUploadSizeExceededException.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, MaxUploadSizeExceededException ex) { - log.error("Handle MaxUploadSizeExceededException, maxFileSize:{}", ex.getMaxUploadSize()); - long maxFileSize = ex.getMaxUploadSize(); - String fileSizeDesc = (maxFileSize << 20) + "G"; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.UPLOAD_FILE_MAX_SIZE_EXCEEDED, - new String[]{fileSizeDesc}, i18nService), - HttpStatus.OK); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } -} diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/CronJobDAO.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/CronJobDAO.java index 842d4bf42f..218936c7e6 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/CronJobDAO.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/CronJobDAO.java @@ -53,6 +53,14 @@ PageData listPageCronJobsByCondition(CronJobInfoDTO cronJobCondi */ CronJobInfoDTO getCronJobById(long cronJobId); + /** + * 根据定时任务 IDs 查询定时任务信息 + * + * @param cronJobIdList 定时任务 IDs + * @return 定时任务信息 + */ + List getCronJobByIds(List cronJobIdList); + /** * 根据定时任务 ID 查询定时任务信息 * diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/impl/CronJobDAOImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/impl/CronJobDAOImpl.java index a87679e204..0eca749458 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/impl/CronJobDAOImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/dao/impl/CronJobDAOImpl.java @@ -36,7 +36,7 @@ import com.tencent.bk.job.crontab.util.DbUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.CronJob; import org.jooq.generated.tables.records.CronJobRecord; @@ -172,6 +172,14 @@ public CronJobInfoDTO getCronJobById(long cronJobId) { return getCronJobByConditions(conditions); } + @Override + public List getCronJobByIds(List cronJobIdList) { + List conditions = new ArrayList<>(); + conditions.add(TABLE.ID.in(cronJobIdList.parallelStream().map(ULong::valueOf).collect(Collectors.toList()))); + conditions.add(TABLE.IS_DELETED.equal(UByte.valueOf(0))); + return fetchData(conditions); + } + @Override public CronJobInfoDTO getCronJobById(long appId, long cronJobId) { List conditions = new ArrayList<>(); @@ -389,7 +397,7 @@ public boolean isExistAnyAppCronJob(Long appId) { return context.fetchExists(TABLE, conditions); } - private List fetchData(List conditions) { + private List fetchData(Collection conditions) { Result> records = context @@ -401,7 +409,7 @@ private List fetchData(List conditions) { .from(TABLE).where(conditions).fetch(); List cronJobInfoList = new ArrayList<>(); - if (records != null && records.size() >= 1) { + if (records.size() >= 1) { records.map(record -> cronJobInfoList.add(convertToCronJobDTO(record))); } return cronJobInfoList; diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/CronJobInfoDTO.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/CronJobInfoDTO.java index 38603df874..baf3d1cbdc 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/CronJobInfoDTO.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/CronJobInfoDTO.java @@ -43,7 +43,7 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.quartz.CronExpression; import java.text.ParseException; diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/CronJobService.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/CronJobService.java index ed92058fba..341433178f 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/CronJobService.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/CronJobService.java @@ -57,6 +57,22 @@ PageData listPageCronJobInfos(CronJobInfoDTO cronJobCondition, */ CronJobInfoDTO getCronJobInfoById(Long cronJobId); + /** + * 根据 IDs 查询定时任务信息,按照传入的id顺序返回结果 + * + * @param cronJobIdList 定时任务 IDs + * @return 定时任务信息 + */ + List getOrderedCronJobInfoByIds(List cronJobIdList); + + /** + * 根据 IDs 查询定时任务信息,返回Map + * + * @param cronJobIdList 定时任务 IDs + * @return 定时任务信息 + */ + Map getCronJobInfoMapByIds(List cronJobIdList); + /** * 根据 ID 查询定时任务信息 * diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/impl/CronJobServiceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/impl/CronJobServiceImpl.java index d42b1bfdb6..2204d0a537 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/impl/CronJobServiceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/impl/CronJobServiceImpl.java @@ -47,7 +47,11 @@ import com.tencent.bk.job.crontab.service.ExecuteTaskService; import com.tencent.bk.job.crontab.service.TaskExecuteResultService; import com.tencent.bk.job.crontab.service.TaskPlanService; -import com.tencent.bk.job.crontab.timer.*; +import com.tencent.bk.job.crontab.timer.AbstractQuartzTaskHandler; +import com.tencent.bk.job.crontab.timer.QuartzJob; +import com.tencent.bk.job.crontab.timer.QuartzJobBuilder; +import com.tencent.bk.job.crontab.timer.QuartzTrigger; +import com.tencent.bk.job.crontab.timer.QuartzTriggerBuilder; import com.tencent.bk.job.crontab.timer.executor.InnerJobExecutor; import com.tencent.bk.job.crontab.timer.executor.NotifyJobExecutor; import com.tencent.bk.job.crontab.timer.executor.SimpleJobExecutor; @@ -67,7 +71,12 @@ import java.sql.Date; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -122,6 +131,29 @@ public CronJobInfoDTO getCronJobInfoById(Long cronJobId) { return cronJobDAO.getCronJobById(cronJobId); } + @Override + public List getOrderedCronJobInfoByIds(List cronJobIdList) { + Map map = getCronJobInfoMapByIds(cronJobIdList); + List cronJobInfoDTOList = new ArrayList<>(); + for (Long id : cronJobIdList) { + CronJobInfoDTO cronJobInfoDTO = map.get(id); + if (cronJobInfoDTO != null) { + cronJobInfoDTOList.add(cronJobInfoDTO); + } + } + return cronJobInfoDTOList; + } + + @Override + public Map getCronJobInfoMapByIds(List cronJobIdList) { + List cronJobInfoDTOList = cronJobDAO.getCronJobByIds(cronJobIdList); + Map map = new HashMap<>(); + for (CronJobInfoDTO cronJobInfoDTO : cronJobInfoDTOList) { + map.put(cronJobInfoDTO.getId(), cronJobInfoDTO); + } + return map; + } + @Override public CronJobInfoDTO getCronJobInfoById(Long appId, Long cronJobId) { return cronJobDAO.getCronJobById(appId, cronJobId); diff --git a/src/backend/job-execute/api-job-execute/build.gradle b/src/backend/job-execute/api-job-execute/build.gradle index c359915f45..a0e1a29785 100644 --- a/src/backend/job-execute/api-job-execute/build.gradle +++ b/src/backend/job-execute/api-job-execute/build.gradle @@ -23,11 +23,11 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-iam') - compile project(':commons:common-i18n') - compile project(':commons:esb-sdk') - compile project(':commons:common-statistics') + api project(':commons:common') + api project(':commons:common-iam') + api project(':commons:common-i18n') + api project(':commons:esb-sdk') + api project(':commons:common-statistics') implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-annotations' @@ -35,4 +35,6 @@ dependencies { implementation "javax.ws.rs:javax.ws.rs-api" implementation "javax.servlet:javax.servlet-api" implementation('org.springframework:spring-webmvc') + implementation "org.hibernate.validator:hibernate-validator" + implementation('jakarta.validation:jakarta.validation-api') } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseGetProcResultResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseGetProcResultResource.java index 8be820358e..8400fd1e03 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseGetProcResultResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseGetProcResultResource.java @@ -24,25 +24,26 @@ package com.tencent.bk.job.execute.api.esb.gse; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.gse.req.EsbGseGetProcResultRequest; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.Map; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * GSE接口-操作服务器上的进程结果查询 */ @RequestMapping(value = {"/esb/api/v2", "/esb/api/v3"}) @RestController +@EsbAPI public interface GseGetProcResultResource { @PostMapping("/get_proc_result") - EsbResp> gseGetProcResult( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbGseGetProcResultRequest request); + EsbResp> gseGetProcResult(@RequestBody EsbGseGetProcResultRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseManageProcessResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseManageProcessResource.java index 451787a855..5c038f2165 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseManageProcessResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseManageProcessResource.java @@ -24,24 +24,25 @@ package com.tencent.bk.job.execute.api.esb.gse; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.gse.EsbGseTaskResultDTO; import com.tencent.bk.job.execute.model.esb.gse.req.EsbGseManageProcRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * GSE接口-进程管理接口-- 注册托管/取消注册托管 */ @RequestMapping(value = {"/esb/api/v2", "/esb/api/v3"}) @RestController +@EsbAPI public interface GseManageProcessResource { @PostMapping("/manage_proc") - EsbResp gseManageProc( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbGseManageProcRequest request); + EsbResp gseManageProc(@RequestBody EsbGseManageProcRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessResource.java index 5304a4e4bc..73245bd980 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessResource.java @@ -24,24 +24,25 @@ package com.tencent.bk.job.execute.api.esb.gse; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.gse.EsbGseTaskResultDTO; import com.tencent.bk.job.execute.model.esb.gse.req.EsbGseOperateProcessRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * GSE接口-GSE进程操作-V1版本 */ @RequestMapping(value = {"/esb/api/v2", "/esb/api/v3"}) @RestController +@EsbAPI public interface GseOperateProcessResource { @PostMapping("/operate_proc") - EsbResp gseOperateProcess( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbGseOperateProcessRequest request); + EsbResp gseOperateProcess(@RequestBody EsbGseOperateProcessRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessV2Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessV2Resource.java index 4c4c19bedd..05d3c071e9 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessV2Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/GseOperateProcessV2Resource.java @@ -24,24 +24,25 @@ package com.tencent.bk.job.execute.api.esb.gse; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.gse.EsbGseTaskResultDTO; import com.tencent.bk.job.execute.model.esb.gse.req.EsbGseOperateProcessRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * GSE接口-GSE进程操作-V2版本 */ @RequestMapping(value = {"/esb/api/v2", "/esb/api/v3"}) @RestController +@EsbAPI public interface GseOperateProcessV2Resource { @PostMapping("/operate_process") - EsbResp gseOperateProcessV2( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbGseOperateProcessRequest request); + EsbResp gseOperateProcessV2(@RequestBody EsbGseOperateProcessRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java index f8f629f39c..3125653e09 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbExecuteTaskResource.java @@ -24,24 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbExecuteJobRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 执行作业API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbExecuteTaskResource { @PostMapping("/execute_job") - EsbResp executeJob( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbExecuteJobRequest request); + EsbResp executeJob(@RequestBody EsbExecuteJobRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java index d65227a2fe..8b1f16756c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteSQLResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastExecuteSQLRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行SQL-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbFastExecuteSQLResource { @PostMapping("/fast_execute_sql") EsbResp fastExecuteSQL( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbFastExecuteSQLRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java index 65a70f4f80..d15ccb0acc 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastExecuteScriptResource.java @@ -24,24 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastExecuteScriptRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行脚本API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbFastExecuteScriptResource { @PostMapping("/fast_execute_script") - EsbResp fastExecuteScript( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestBody EsbFastExecuteScriptRequest request); + EsbResp fastExecuteScript(@RequestBody EsbFastExecuteScriptRequest request); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastPushFileResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastPushFileResource.java index d87c15d1fc..2a98196423 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastPushFileResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbFastPushFileResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbFastPushFileRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行脚本API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbFastPushFileResource { @PostMapping("/fast_push_file") EsbResp fastPushFile( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbFastPushFileRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceGlobalVarValueResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceGlobalVarValueResource.java index 364e0b31c2..336db28173 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceGlobalVarValueResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceGlobalVarValueResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbTaskInstanceGlobalVarValueDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbGetJobInstanceGlobalVarValueRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 获取作业实例全局变量的值-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetJobInstanceGlobalVarValueResource { @PostMapping("/get_job_instance_global_var_value") EsbResp getJobInstanceGlobalVarValue( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetJobInstanceGlobalVarValueRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceLogResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceLogResource.java index ffa71be0b8..70555fe74e 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceLogResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceLogResource.java @@ -24,32 +24,37 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbStepInstanceResultAndLog; import com.tencent.bk.job.execute.model.esb.v2.request.EsbGetJobInstanceLogRequest; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * 根据作业实例ID查询作业执行日志-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetJobInstanceLogResource { @PostMapping("/get_job_instance_log") EsbResp> getJobInstanceLogUsingPost( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetJobInstanceLogRequest request); @GetMapping("/get_job_instance_log") EsbResp> getJobInstanceLog( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestParam(value = "bk_app_code") String appCode, - @RequestParam(value = "bk_username") String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, @RequestParam(value = "bk_biz_id") Long appId, @RequestParam(value = "job_instance_id") Long taskInstanceId); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceStatusResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceStatusResource.java index 52fa4368d9..e08533e319 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceStatusResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetJobInstanceStatusResource.java @@ -24,30 +24,35 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobInstanceStatusDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbGetJobInstanceStatusRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 根据作业实例 ID 查询作业执行状态API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetJobInstanceStatusResource { @PostMapping("/get_job_instance_status") EsbResp getJobInstanceStatusUsingPost( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetJobInstanceStatusRequest request); @GetMapping("/get_job_instance_status") EsbResp getJobInstanceStatus( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, - @RequestParam(value = "bk_app_code") String appCode, - @RequestParam(value = "bk_username") String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, @RequestParam(value = "bk_biz_id") Long appId, @RequestParam(value = "job_instance_id") Long taskInstanceId); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetStepInstanceStatusResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetStepInstanceStatusResource.java index 5dc326eaa8..c4e7b0fdf5 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetStepInstanceStatusResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbGetStepInstanceStatusResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbStepInstanceStatusDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbGetStepInstanceStatusRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 根据步骤实例 ID 查询步骤执行状态API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetStepInstanceStatusResource { @PostMapping("/get_step_instance_status") EsbResp getJobStepInstanceStatus( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetStepInstanceStatusRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateJobInstanceResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateJobInstanceResource.java index b39e4e84fb..e4e3b6ef33 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateJobInstanceResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateJobInstanceResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbOperateJobInstanceRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 步骤操作API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbOperateJobInstanceResource { @PostMapping("/operate_job_instance") EsbResp operateJobInstance( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbOperateJobInstanceRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateStepInstanceResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateStepInstanceResource.java index 4488e57c6a..f607dbb6ad 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateStepInstanceResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbOperateStepInstanceResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbOperateStepInstanceRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 步骤操作API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbOperateStepInstanceResource { @PostMapping("/operate_step_instance") EsbResp operateStepInstance( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbOperateStepInstanceRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbPushConfigFileResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbPushConfigFileResource.java index 59d49919b2..c23c81098c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbPushConfigFileResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/EsbPushConfigFileResource.java @@ -24,18 +24,21 @@ package com.tencent.bk.job.execute.api.esb.v2; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v2.EsbJobExecuteDTO; import com.tencent.bk.job.execute.model.esb.v2.request.EsbPushConfigFileRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 推送配置文件API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbPushConfigFileResource { /** @@ -43,7 +46,6 @@ public interface EsbPushConfigFileResource { */ @PostMapping("/push_config_file") EsbResp pushConfigFile( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbPushConfigFileRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3Resource.java new file mode 100644 index 0000000000..8893cf70d5 --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3Resource.java @@ -0,0 +1,48 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.api.esb.v3; + +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.execute.model.esb.v3.EsbIpLogsV3DTO; +import com.tencent.bk.job.execute.model.esb.v3.request.EsbBatchGetJobInstanceIpLogV3Request; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 根据ip批量查询作业执行日志 -V3 + */ +@RequestMapping("/esb/api/v3") +@RestController +@EsbAPI +public interface EsbBatchGetJobInstanceIpLogV3Resource { + + @PostMapping("/batch_get_job_instance_ip_log") + EsbResp batchGetJobInstanceIpLogs( + @RequestBody EsbBatchGetJobInstanceIpLogV3Request request); + +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3Resource.java index 47f7e6ef7b..47cf912ed9 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbExecuteJobV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 执行作业执行方案API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbExecuteJobPlanV3Resource { @PostMapping("/execute_job_plan") EsbResp executeJobPlan( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbExecuteJobV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3Resource.java index df47d8dcf7..7d3caf3781 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbFastExecuteSQLV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行SQL-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbFastExecuteSQLV3Resource { @PostMapping("/fast_execute_sql") EsbResp fastExecuteSQL( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbFastExecuteSQLV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3Resource.java index 45ebca6772..85bac20e37 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbFastExecuteScriptV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行脚本ESB-API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbFastExecuteScriptV3Resource { @PostMapping("/fast_execute_script") EsbResp fastExecuteScript( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbFastExecuteScriptV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3Resource.java index 736a333838..abfbe87baf 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbFastTransferFileV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 快速执行脚本API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbFastTransferFileV3Resource { @PostMapping("/fast_transfer_file") EsbResp fastTransferFile( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbFastTransferFileV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3Resource.java index 977f0017de..7d55d89c53 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3Resource.java @@ -24,26 +24,37 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobInstanceGlobalVarValueV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbGetJobInstanceGlobalVarValueV3Request; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 获取作业实例全局变量的值-V3 */ @RequestMapping("/esb/api/v3") +@RestController +@EsbAPI public interface EsbGetJobInstanceGlobalVarValueV3Resource { @PostMapping("/get_job_instance_global_var_value") - EsbResp getJobInstanceGlobalVarValue( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getJobInstanceGlobalVarValueUsingPost( @RequestBody EsbGetJobInstanceGlobalVarValueV3Request request); + @GetMapping("/get_job_instance_global_var_value") + EsbResp getJobInstanceGlobalVarValue( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "job_instance_id") Long taskInstanceId); + } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3Resource.java index 7f93f35e81..b118522d34 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3Resource.java @@ -24,24 +24,39 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbIpLogV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbGetJobInstanceIpLogV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 根据ip查询作业执行日志 -V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbGetJobInstanceIpLogV3Resource { @PostMapping("/get_job_instance_ip_log") - EsbResp getJobInstanceIpLog( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getJobInstanceIpLogUsingPost( @RequestBody EsbGetJobInstanceIpLogV3Request request); + @GetMapping("/get_job_instance_ip_log") + EsbResp getJobInstanceIpLog( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "job_instance_id") Long taskInstanceId, + @RequestParam(value = "step_instance_id") Long stepInstanceId, + @RequestParam(value = "bk_cloud_id") Long cloudAreaId, + @RequestParam(value = "ip") String ip); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java index 480a04ac27..da25f902fd 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3Resource.java @@ -24,25 +24,48 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.execute.model.esb.v3.EsbTaskInstanceV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbGetJobInstanceListV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** - * 根据ip查询作业执行日志 -V3 + * 查询作业执行历史 -V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbGetJobInstanceListV3Resource { @PostMapping("/get_job_instance_list") - EsbResp> getJobInstanceList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp> getJobInstanceListUsingPost( @RequestBody EsbGetJobInstanceListV3Request request); + @GetMapping("/get_job_instance_list") + EsbResp> getJobInstanceList( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "create_time_start") Long createTimeStart, + @RequestParam(value = "create_time_end") Long createTimeEnd, + @RequestParam(value = "job_instance_id", required = false) Long taskInstanceId, + @RequestParam(value = "operator", required = false) String operator, + @RequestParam(value = "name", required = false) String taskName, + @RequestParam(value = "launch_mode", required = false) Integer startupMode, + @RequestParam(value = "type", required = false) Integer taskType, + @RequestParam(value = "status", required = false) Integer taskStatus, + @RequestParam(value = "ip", required = false) String ip, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3Resource.java index 4ed4314398..696bf274ae 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3Resource.java @@ -24,24 +24,37 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobInstanceStatusV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbGetJobInstanceStatusV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 根据作业实例 ID 查询作业执行状态API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbGetJobInstanceStatusV3Resource { @PostMapping("/get_job_instance_status") - EsbResp getJobInstanceStatus( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getJobInstanceStatusUsingPost( @RequestBody EsbGetJobInstanceStatusV3Request request); + @GetMapping("/get_job_instance_status") + EsbResp getJobInstanceStatus( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "job_instance_id") Long taskInstanceId, + @RequestParam(value = "return_ip_result", required = false, defaultValue = "false") boolean returnIpResult); } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3Resource.java index c915a1b11d..f08dffe2a4 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbOperateJobInstanceV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 步骤操作API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbOperateJobInstanceV3Resource { @PostMapping("/operate_job_instance") EsbResp operateJobInstance( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbOperateJobInstanceV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3Resource.java index bd9c642d4e..208a25132d 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3Resource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbOperateStepInstanceV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 步骤操作API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbOperateStepInstanceV3Resource { @PostMapping("/operate_step_instance") EsbResp operateStepInstance( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbOperateStepInstanceV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileV3Resource.java index fd02e1d9a4..691802b28c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileV3Resource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileV3Resource.java @@ -24,18 +24,21 @@ package com.tencent.bk.job.execute.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.execute.model.esb.v3.EsbJobExecuteV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbPushConfigFileV3Request; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 配置文件API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbPushConfigFileV3Resource { /** @@ -43,7 +46,6 @@ public interface EsbPushConfigFileV3Resource { */ @PostMapping("/push_config_file") EsbResp pushConfigFile( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbPushConfigFileV3Request request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResource.java index 30443152c0..6423adcbdb 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.execute.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.execute.model.inner.ServiceTaskExecuteResult; @@ -42,6 +43,7 @@ @Api(tags = {"Task_Execute"}) @RequestMapping("/service/execution") @RestController +@InternalAPI public interface ServiceExecuteTaskResource { @PostMapping("/task-execution/task") ServiceResponse executeTask(@RequestBody ServiceTaskExecuteRequest request); diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceMetricsResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceMetricsResource.java index a2ccea205a..3c17481d7b 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceMetricsResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceMetricsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.execute.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.statistics.model.dto.StatisticsDTO; import com.tencent.bk.job.execute.common.constants.RunStatusEnum; @@ -34,13 +35,19 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-execute:service:Metrics"}) @RequestMapping("/service/metrics") @RestController +@InternalAPI public interface ServiceMetricsResource { @ApiOperation(value = "接入(执行过一次任务)的业务Id列表", produces = "application/json") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResource.java index 9f4ae79d59..c63f3e1495 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.execute.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.execute.model.inner.ServiceCronTaskExecuteResultStatistics; @@ -32,7 +33,13 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.Map; @@ -42,6 +49,7 @@ @Api(tags = {"job-execute:service:Task_Execution_Result"}) @RequestMapping("/service/execution") @RestController +@InternalAPI public interface ServiceTaskExecuteResultResource { /** * @param request 定时任务结果统计请求 diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebDangerousRecordResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebDangerousRecordResource.java index 6fd02a6180..babcbe788f 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebDangerousRecordResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebDangerousRecordResource.java @@ -24,13 +24,18 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.execute.model.web.vo.DangerousRecordVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 高危检测记录API-前端调用 @@ -38,6 +43,7 @@ @Api(tags = {"job-execute:web:Dangerous_Record"}) @RequestMapping("/web/dangerous-record") @RestController +@WebAPI public interface WebDangerousRecordResource { @ApiOperation(value = "分页获取高危检测记录", produces = "application/json") @GetMapping("/list") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebExecuteTaskResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebExecuteTaskResource.java index cab8f362a5..f053f60cfe 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebExecuteTaskResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebExecuteTaskResource.java @@ -24,15 +24,25 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.execute.model.web.request.*; +import com.tencent.bk.job.execute.model.web.request.RedoTaskRequest; +import com.tencent.bk.job.execute.model.web.request.WebFastExecuteScriptRequest; +import com.tencent.bk.job.execute.model.web.request.WebFastPushFileRequest; +import com.tencent.bk.job.execute.model.web.request.WebStepOperation; +import com.tencent.bk.job.execute.model.web.request.WebTaskExecuteRequest; import com.tencent.bk.job.execute.model.web.vo.StepExecuteVO; import com.tencent.bk.job.execute.model.web.vo.StepOperationVO; import com.tencent.bk.job.execute.model.web.vo.TaskExecuteVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 作业执行API-前端调用 @@ -42,6 +52,7 @@ @Api(tags = {"job-execute:web:Task_Execute"}) @RequestMapping("/web/execution/") @RestController +@WebAPI public interface WebExecuteTaskResource { @ApiOperation(value = "执行作业", produces = "application/json") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebPermissionResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebPermissionResource.java index b55eb944fa..5136384059 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebPermissionResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebPermissionResource.java @@ -24,17 +24,25 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.execute.model.web.request.OperationPermissionReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-execute:web:Permission"}) @RequestMapping("/web/permission/") @RestController +@WebAPI public interface WebPermissionResource { /** * 获取权限申请URL diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskExecutionResultResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskExecutionResultResource.java index 68ac7cd674..f91d171416 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskExecutionResultResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskExecutionResultResource.java @@ -24,15 +24,30 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.HostDTO; import com.tencent.bk.job.execute.common.constants.TaskTotalTimeTypeEnum; -import com.tencent.bk.job.execute.model.web.vo.*; +import com.tencent.bk.job.execute.model.web.vo.ExecuteVariableVO; +import com.tencent.bk.job.execute.model.web.vo.FileDistributionDetailVO; +import com.tencent.bk.job.execute.model.web.vo.IpFileLogContentVO; +import com.tencent.bk.job.execute.model.web.vo.IpScriptLogContentVO; +import com.tencent.bk.job.execute.model.web.vo.StepExecutionDetailVO; +import com.tencent.bk.job.execute.model.web.vo.StepExecutionRecordVO; +import com.tencent.bk.job.execute.model.web.vo.TaskExecuteResultVO; +import com.tencent.bk.job.execute.model.web.vo.TaskInstanceVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -42,6 +57,7 @@ @Api(tags = {"job-execute:web:Task_Execution_Result"}) @RequestMapping("/web/execution") @RestController +@WebAPI public interface WebTaskExecutionResultResource { @ApiOperation(value = "获取作业执行历史列表", produces = "application/json") @GetMapping("/app/{appId}/task-execution-history/list") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskInstanceResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskInstanceResource.java index 298cc6cc58..74900a431b 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskInstanceResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskInstanceResource.java @@ -24,12 +24,21 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.execute.model.web.vo.*; +import com.tencent.bk.job.execute.model.web.vo.ExecuteStepVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteVariableVO; +import com.tencent.bk.job.execute.model.web.vo.TaskInstanceDetailVO; +import com.tencent.bk.job.execute.model.web.vo.TaskInstanceVO; +import com.tencent.bk.job.execute.model.web.vo.TaskOperationLogVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -39,6 +48,7 @@ @Api(tags = {"job-execute:web:Task_Step_Instance"}) @RequestMapping("/web/execution/") @RestController +@WebAPI public interface WebTaskInstanceResource { @ApiOperation(value = "获取作业步骤实例详情", produces = "application/json") @GetMapping("/app/{appId}/task-instance/step_instance/{stepInstanceId}") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskLogResource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskLogResource.java index f939c9abd4..e884f6067f 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskLogResource.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/WebTaskLogResource.java @@ -24,13 +24,19 @@ package com.tencent.bk.job.execute.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.execute.model.web.vo.LogExportJobInfoVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; import javax.servlet.http.HttpServletResponse; @@ -41,6 +47,7 @@ @Api(tags = {"job-execute:web:Task_Execution_Log"}) @RequestMapping("/web/execution") @RestController +@WebAPI public interface WebTaskLogResource { @ApiOperation(value = "请求下载执行日志文件", produces = "application/json") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbGseTaskResultDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbGseTaskResultDTO.java index d8b2959161..ee517c6986 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbGseTaskResultDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbGseTaskResultDTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.execute.model.esb.gse; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbGseTaskResultDTO { @JsonProperty("bk_gse_taskid") private String gseTaskId; diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbProcessInfoDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbProcessInfoDTO.java index f66d94f5c0..9b5f864396 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbProcessInfoDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/gse/EsbProcessInfoDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.gse; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; import lombok.Data; @@ -32,7 +31,6 @@ import java.util.List; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbProcessInfoDTO { /** * 进程路径, 例如/usr/local/gse/sbin @@ -87,7 +85,6 @@ public class EsbProcessInfoDTO { /** * IP对象数组 */ - @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("ip_list") private List ipList; /** diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbIpStatusDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbIpStatusDTO.java index 8b6237d8fd..acba2f6a1a 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbIpStatusDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbIpStatusDTO.java @@ -24,14 +24,12 @@ package com.tencent.bk.job.execute.model.esb.v2; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import lombok.Setter; @Setter @Getter -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbIpStatusDTO { private String ip; @JsonProperty("bk_cloud_id") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbJobInstanceStatusDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbJobInstanceStatusDTO.java index 950de2aa9d..0415318e67 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbJobInstanceStatusDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbJobInstanceStatusDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.v2; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; @@ -48,7 +47,6 @@ public class EsbJobInstanceStatusDTO { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class JobInstance { @JsonProperty("job_instance_id") private Long id; @@ -116,7 +114,6 @@ public static class JobInstance { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class Block { /** * 步骤块中包含的各个步骤对象 @@ -127,7 +124,6 @@ public static class Block { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class StepInst { /** * id diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceResultAndLog.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceResultAndLog.java index 2d8968cdd0..b342908b21 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceResultAndLog.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceResultAndLog.java @@ -25,7 +25,6 @@ package com.tencent.bk.job.execute.model.esb.v2; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; @@ -36,7 +35,6 @@ import java.util.List; -@JsonInclude(JsonInclude.Include.NON_NULL) @Setter @Getter public class EsbStepInstanceResultAndLog { @@ -61,7 +59,6 @@ public class EsbStepInstanceResultAndLog { /** * 当前步骤下所有ip的日志 按tag分类或 ip的执行状态(ip_status)归类存放 */ - @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("step_results") private List stepResults; @@ -85,7 +82,6 @@ public static class StepInstResultDTO { * ip 日志内容 */ @JsonProperty("ip_logs") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List ipLogs; } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceStatusDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceStatusDTO.java index 38a000fa81..c53cd95c44 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceStatusDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbStepInstanceStatusDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.v2; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; @@ -35,7 +34,6 @@ import java.util.Map; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbStepInstanceStatusDTO { @JsonProperty("is_finished") private Boolean isFinished; @@ -47,7 +45,6 @@ public class EsbStepInstanceStatusDTO { private List> ayalyseResult; @Data - @JsonInclude(JsonInclude.Include.NON_NULL) public static class StepInstance { @JsonProperty("step_instance_id") private Long id; diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbTaskInstanceGlobalVarValueDTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbTaskInstanceGlobalVarValueDTO.java index 3e138ff54b..fe1524dd4c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbTaskInstanceGlobalVarValueDTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v2/EsbTaskInstanceGlobalVarValueDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.v2; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.Getter; @@ -43,7 +42,6 @@ public class EsbTaskInstanceGlobalVarValueDTO { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class EsbStepInstanceGlobalVarValues { @JsonProperty("step_instance_id") private Long stepInstanceId; @@ -54,7 +52,6 @@ public static class EsbStepInstanceGlobalVarValues { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class GlobalVarValue { @JsonProperty("name") private String name; diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileIpLogV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileIpLogV3DTO.java new file mode 100644 index 0000000000..cc652a708e --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileIpLogV3DTO.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * IP对应的文件分发日志 + */ +@Data +public class EsbFileIpLogV3DTO { + + /** + * 云区域ID + */ + @JsonProperty("bk_cloud_id") + private Long cloudAreaId; + + @JsonProperty("ip") + private String ip; + + /** + * 文件任务日志 + */ + @JsonProperty("file_logs") + private List fileLogs; +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileLogV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileLogV3DTO.java new file mode 100644 index 0000000000..7f146d81f0 --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbFileLogV3DTO.java @@ -0,0 +1,60 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; +import lombok.Data; + +/** + * 文件任务日志 + */ +@Data +public class EsbFileLogV3DTO { + + @JsonProperty("mode") + private Integer mode; + + @JsonProperty("src_ip") + private EsbIpDTO srcIp; + + @JsonProperty("src_path") + private String srcPath; + + @JsonProperty("dest_ip") + private EsbIpDTO destIp; + + @JsonProperty("dest_path") + private String destPath; + + @JsonProperty("status") + private Integer status; + + @JsonProperty("log_content") + private String logContent; + +} + + diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogListV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogListV3DTO.java new file mode 100644 index 0000000000..43e68d1d80 --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogListV3DTO.java @@ -0,0 +1,48 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * IP对应的作业执行日志 + */ +@Data +public class EsbIpLogListV3DTO { + /** + * 日志类型 + */ + @JsonProperty("log_type") + private Integer logType; + + private String ip; + + /** + * 日志内容 + */ + @JsonProperty("log_content") + private String logContent; +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogV3DTO.java index f96271c816..94286c752c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogV3DTO.java @@ -27,11 +27,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import java.util.List; + /** * IP对应的作业执行日志 */ @Data public class EsbIpLogV3DTO { + /** + * 日志类型 + */ + @JsonProperty("log_type") + private Integer logType; /** * 云区域ID */ @@ -41,8 +48,14 @@ public class EsbIpLogV3DTO { private String ip; /** - * 日志内容 + * 脚本任务日志内容 */ @JsonProperty("log_content") - private String logContent; + private String scriptLogContent; + + /** + * 文件任务日志 + */ + @JsonProperty("file_logs") + private List fileLogs; } diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogsV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogsV3DTO.java new file mode 100644 index 0000000000..e50e81eb28 --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbIpLogsV3DTO.java @@ -0,0 +1,66 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * IP(批量)对应的作业执行日志 + */ +@Data +public class EsbIpLogsV3DTO { + /** + * 作业实例ID + */ + @JsonProperty("job_instance_id") + private Long taskInstanceId; + + /** + * 步骤实例 ID + */ + @JsonProperty("step_instance_id") + private Long stepInstanceId; + + /** + * 日志类型 + */ + @JsonProperty("log_type") + private Integer logType; + + /** + * 脚本任务日志 + */ + @JsonProperty("script_task_logs") + private List scriptTaskLogs; + + /** + * 文件任务日志 + */ + @JsonProperty("file_task_logs") + private List fileTaskLogs; +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobExecuteV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobExecuteV3DTO.java index 7a66c1022e..b85ff1c86c 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobExecuteV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobExecuteV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -32,7 +31,6 @@ * 作业下发信息 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbJobExecuteV3DTO { /** * 作业实例ID diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceGlobalVarValueV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceGlobalVarValueV3DTO.java index a10b092783..f26f462442 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceGlobalVarValueV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceGlobalVarValueV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.model.esb.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.Getter; @@ -46,7 +45,6 @@ public class EsbJobInstanceGlobalVarValueV3DTO { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class EsbStepInstanceGlobalVarValuesV3DTO { @JsonProperty("step_instance_id") private Long stepInstanceId; @@ -57,7 +55,6 @@ public static class EsbStepInstanceGlobalVarValuesV3DTO { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class GlobalVarValueV3DTO { @JsonProperty("name") private String name; diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceStatusV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceStatusV3DTO.java index aefda4557b..6fb653c763 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceStatusV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbJobInstanceStatusV3DTO.java @@ -46,7 +46,6 @@ public class EsbJobInstanceStatusV3DTO { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class JobInstance { @JsonProperty("job_instance_id") private Long id; @@ -89,7 +88,6 @@ public static class JobInstance { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class StepInst { /** * id @@ -146,7 +144,6 @@ public static class StepInst { @Setter @Getter - @JsonInclude(JsonInclude.Include.NON_NULL) public static class IpResult { private String ip; @JsonProperty("bk_cloud_id") diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbScriptIpLogV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbScriptIpLogV3DTO.java new file mode 100644 index 0000000000..624cf6d6f3 --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbScriptIpLogV3DTO.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * IP对应的脚本执行日志 + */ +@Data +public class EsbScriptIpLogV3DTO { + + /** + * 云区域ID + */ + @JsonProperty("bk_cloud_id") + private Long cloudAreaId; + + @JsonProperty("ip") + private String ip; + + /** + * 脚本任务日志内容 + */ + @JsonProperty("log_content") + private String logContent; +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskInstanceV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskInstanceV3DTO.java index 52f48763a5..7574910906 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskInstanceV3DTO.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskInstanceV3DTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.execute.model.esb.v3; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbTaskInstanceV3DTO { /** * id diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbBatchGetJobInstanceIpLogV3Request.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbBatchGetJobInstanceIpLogV3Request.java new file mode 100644 index 0000000000..b860688d2f --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbBatchGetJobInstanceIpLogV3Request.java @@ -0,0 +1,63 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.model.esb.v3.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.esb.model.EsbReq; +import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +@Getter +@Setter +@ToString +public class EsbBatchGetJobInstanceIpLogV3Request extends EsbReq { + /** + * 业务 ID + */ + @JsonProperty("bk_biz_id") + private Long appId; + + /** + * 作业执行实例 ID + */ + @JsonProperty("job_instance_id") + private Long taskInstanceId; + + /** + * 作业步骤实例ID + */ + @JsonProperty("step_instance_id") + private Long stepInstanceId; + + /** + * 目标服务器IP列表 + */ + @JsonProperty("ip_list") + private List ipList; +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbGetJobInstanceIpLogV3Request.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbGetJobInstanceIpLogV3Request.java index 133e80e1a9..a648ec7cef 100644 --- a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbGetJobInstanceIpLogV3Request.java +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/request/EsbGetJobInstanceIpLogV3Request.java @@ -29,9 +29,6 @@ import lombok.Getter; import lombok.Setter; -/** - * get_job_instance_log,根据作业实例ID查询作业执行日志请求 - */ @Getter @Setter public class EsbGetJobInstanceIpLogV3Request extends EsbReq { diff --git a/src/backend/job-execute/boot-job-execute/build.gradle b/src/backend/job-execute/boot-job-execute/build.gradle index a21f62c071..ff6607b929 100644 --- a/src/backend/job-execute/boot-job-execute/build.gradle +++ b/src/backend/job-execute/boot-job-execute/build.gradle @@ -25,10 +25,11 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-execute:service-job-execute") - compile project(":commons:common-i18n") + api project(":job-execute:service-job-execute") + api project(":commons:common-i18n") implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' implementation 'org.springframework.cloud:spring-cloud-starter-config' @@ -41,7 +42,7 @@ dependencies { testImplementation("com.h2database:h2") } springBoot { - mainClassName = "com.tencent.bk.job.execute.JobExecuteBootApplication" + mainClass = "com.tencent.bk.job.execute.JobExecuteBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/FilterConfig.java b/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/FilterConfig.java index 93f638c91e..d5f85336d9 100644 --- a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/FilterConfig.java +++ b/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/FilterConfig.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.execute.config; -import com.tencent.bk.job.common.web.filter.RepeatableReadServletRequestResponseFilter; +import com.tencent.bk.job.common.web.filter.RepeatableReadWriteServletRequestResponseFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,7 +33,7 @@ public class FilterConfig { @Bean public FilterRegistrationBean repeatableRSRRFilterRegister() { - FilterRegistrationBean registration = + FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(repeatableRRRFilter()); registration.addUrlPatterns("/esb/api/*"); @@ -43,7 +43,7 @@ public FilterRegistrationBean repeatableRSRRFilterRegister() { } @Bean(name = "repeatableReadRequestResponseFilter") - public RepeatableReadServletRequestResponseFilter repeatableRRRFilter() { - return new RepeatableReadServletRequestResponseFilter(); + public RepeatableReadWriteServletRequestResponseFilter repeatableRRRFilter() { + return new RepeatableReadWriteServletRequestResponseFilter(); } } diff --git a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/I18nConfig.java b/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/I18nConfig.java deleted file mode 100644 index d3009b9697..0000000000 --- a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/I18nConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.execute.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import com.tencent.bk.job.common.i18n.locale.LocaleUtils; -import com.tencent.bk.job.execute.common.i18n.JobLangHeaderLocaleResolver; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -/** - * @date 2019/09/19 - */ -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - JobLangHeaderLocaleResolver resolver = new JobLangHeaderLocaleResolver(); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName(LocaleUtils.COMMON_LANG_HEADER); - return interceptor; - } - -} diff --git a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/InterceptorConfiguration.java b/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/InterceptorConfiguration.java index e2e5f35653..72361293fd 100644 --- a/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/InterceptorConfiguration.java +++ b/src/backend/job-execute/boot-job-execute/src/main/java/com/tencent/bk/job/execute/config/InterceptorConfiguration.java @@ -24,9 +24,12 @@ package com.tencent.bk.job.execute.config; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; +import com.tencent.bk.job.common.web.interceptor.EsbReqRewriteInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; +import com.tencent.bk.job.execute.common.interceptor.UriPermissionInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; @@ -36,16 +39,26 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; + private final UriPermissionInterceptor uriPermissionInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final EsbApiLogInterceptor esbApiLogInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; + private final EsbReqRewriteInterceptor esbReqRewriteInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - EsbApiLogInterceptor esbApiLogInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + UriPermissionInterceptor uriPermissionInterceptor, EsbApiLogInterceptor esbApiLogInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor, + EsbReqRewriteInterceptor esbReqRewriteInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; + this.uriPermissionInterceptor = uriPermissionInterceptor; + this.authAppInterceptor = authAppInterceptor; this.esbApiLogInterceptor = esbApiLogInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; + this.esbReqRewriteInterceptor = esbReqRewriteInterceptor; } @Override @@ -53,6 +66,12 @@ public void addInterceptors(InterceptorRegistry registry) { // 注册拦截器 registry.addInterceptor(serviceSecurityInterceptor).addPathPatterns("/**").order(0); registry.addInterceptor(jobCommonInterceptor).addPathPatterns("/**").order(1); + registry.addInterceptor(uriPermissionInterceptor) + .addPathPatterns( + uriPermissionInterceptor.getControlUriPatterns() + ).order(2); registry.addInterceptor(esbApiLogInterceptor).addPathPatterns("/esb/api/**").order(10); + registry.addInterceptor(esbReqRewriteInterceptor).addPathPatterns("/esb/api/**").order(11); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(12); } } diff --git a/src/backend/job-execute/build.gradle b/src/backend/job-execute/build.gradle index 6634c005f3..fca22e8401 100644 --- a/src/backend/job-execute/build.gradle +++ b/src/backend/job-execute/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobExecuteVersion")) { set("jobExecuteVersion", System.getProperty("jobExecuteVersion")) + } else if (System.getProperty("version")) { + set("jobExecuteVersion", System.getProperty("version")) } else { set("jobExecuteVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobExecuteVersion}" subprojects { version "${jobExecuteVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -41,7 +43,7 @@ subprojects { implementation 'ch.qos.logback:logback-classic' implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-execute/service-job-execute/build.gradle b/src/backend/job-execute/service-job-execute/build.gradle index 0cedba656a..c581acb770 100644 --- a/src/backend/job-execute/service-job-execute/build.gradle +++ b/src/backend/job-execute/service-job-execute/build.gradle @@ -24,20 +24,20 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(':commons:common-web') - compile project(":job-file-gateway:api-job-file-gateway") - compile project(":job-execute:api-job-execute") - compile project(":job-execute:model-job-execute") - compile project(":job-manage:api-job-manage") - compile project(":job-logsvr:api-job-logsvr") - compile project(':commons:gse-sdk') - compile project(':commons:common-security') - compile project(':commons:common-redis') - compile project(":commons:cmdb-sdk-ext") - compile("org.springframework.boot:spring-boot-starter-web") - compile("org.springframework.boot:spring-boot-starter-jdbc") - compile("org.springframework.cloud:spring-cloud-starter-consul-discovery") - compile "org.springframework.boot:spring-boot-starter-jooq" + api project(':commons:common-web') + api project(":job-file-gateway:api-job-file-gateway") + api project(":job-execute:api-job-execute") + api project(":job-execute:model-job-execute") + api project(":job-manage:api-job-manage") + api project(":job-logsvr:api-job-logsvr") + api project(':commons:gse-sdk') + api project(':commons:common-security') + api project(':commons:common-redis') + api project(":commons:cmdb-sdk-ext") + api("org.springframework.boot:spring-boot-starter-web") + api("org.springframework.boot:spring-boot-starter-jdbc") + api("org.springframework.cloud:spring-cloud-starter-consul-discovery") + api "org.springframework.boot:spring-boot-starter-jooq" implementation "org.springframework.cloud:spring-cloud-stream" implementation "org.springframework.cloud:spring-cloud-starter-sleuth" implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' @@ -51,10 +51,11 @@ dependencies { implementation 'com.google.guava:guava' implementation 'org.apache.commons:commons-pool2' implementation 'io.micrometer:micrometer-registry-prometheus' + implementation "org.hibernate.validator:hibernate-validator" // https://mvnrepository.com/artifact/org.apache.curator/curator-framework - compile(group: 'org.apache.curator', name: 'curator-framework', version: '2.13.0') + api(group: 'org.apache.curator', name: 'curator-framework', version: '2.13.0') // https://mvnrepository.com/artifact/org.apache.curator/curator-recipes - compile(group: 'org.apache.curator', name: 'curator-recipes', version: '2.13.0') + api(group: 'org.apache.curator', name: 'curator-recipes', version: '2.13.0') testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.apache.commons:commons-lang3' diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseGetProcResultResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseGetProcResultResourceImpl.java index d0ff662dad..81c50af5a7 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseGetProcResultResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseGetProcResultResourceImpl.java @@ -29,7 +29,7 @@ import com.tencent.bk.gse.taskapi.api_map_rsp; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.execute.api.esb.gse.GseGetProcResultResource; import com.tencent.bk.job.execute.gse.GseApiExecutor; @@ -37,7 +37,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -55,7 +55,7 @@ public GseGetProcResultResourceImpl(MessageI18nService i18nService) { } @Override - public EsbResp> gseGetProcResult(String lang, EsbGseGetProcResultRequest request) { + public EsbResp> gseGetProcResult(EsbGseGetProcResultRequest request) { log.info("Gse process result, request={}", request); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseManageProcessResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseManageProcessResourceImpl.java index de45f72254..4f83628014 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseManageProcessResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseManageProcessResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.execute.api.esb.gse.GseManageProcessResource; import com.tencent.bk.job.execute.engine.model.GseTaskResponse; @@ -56,7 +56,7 @@ public GseManageProcessResourceImpl(MessageI18nService i18nService) { } @Override - public EsbResp gseManageProc(String lang, EsbGseManageProcRequest request) { + public EsbResp gseManageProc(EsbGseManageProcRequest request) { log.info("Gse manage process, request={}", request); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessResourceImpl.java index 4ce3b97f46..b41799b4e0 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.execute.api.esb.gse.GseOperateProcessResource; import com.tencent.bk.job.execute.engine.model.GseTaskResponse; @@ -56,7 +56,7 @@ public GseOperateProcessResourceImpl(MessageI18nService i18nService) { } @Override - public EsbResp gseOperateProcess(String lang, EsbGseOperateProcessRequest request) { + public EsbResp gseOperateProcess(EsbGseOperateProcessRequest request) { log.info("Gse operate process, request={}", request); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessV2ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessV2ResourceImpl.java index b5bb7f3af1..d34de9ca2b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessV2ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/gse/impl/GseOperateProcessV2ResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.execute.api.esb.gse.GseOperateProcessV2Resource; import com.tencent.bk.job.execute.engine.model.GseTaskResponse; @@ -57,7 +57,7 @@ public GseOperateProcessV2ResourceImpl(MessageI18nService i18nService) { } @Override - public EsbResp gseOperateProcessV2(String lang, EsbGseOperateProcessRequest request) { + public EsbResp gseOperateProcessV2(EsbGseOperateProcessRequest request) { log.info("Gse operate process v2, request={}", request); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java index da94a50129..184858bb8b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbExecuteTaskResourceImpl.java @@ -31,7 +31,7 @@ import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; import com.tencent.bk.job.common.esb.model.job.EsbServerDTO; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -72,7 +72,7 @@ public EsbExecuteTaskResourceImpl(TaskExecuteService taskExecuteService, Message @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_execute_job"}) - public EsbResp executeJob(String lang, EsbExecuteJobRequest request) { + public EsbResp executeJob(EsbExecuteJobRequest request) { log.info("Execute task, request={}", JsonUtils.toJson(request)); ValidateResult checkResult = checkExecuteTaskRequest(request); if (!checkResult.isPass()) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java index 59536496fc..73fd07a9ad 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteSQLResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -84,7 +84,7 @@ public EsbFastExecuteSQLResourceImpl(TaskExecuteService taskExecuteService, Acco @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_fast_execute_sql"}) - public EsbResp fastExecuteSQL(String lang, EsbFastExecuteSQLRequest request) { + public EsbResp fastExecuteSQL(EsbFastExecuteSQLRequest request) { ValidateResult validateResult = checkFastExecuteSQLRequest(request); if (!validateResult.isPass()) { log.warn("Fast execute SQL request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java index 52fa0e4637..7795cb6a93 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastExecuteScriptResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -86,7 +86,7 @@ public EsbFastExecuteScriptResourceImpl(TaskExecuteService taskExecuteService, A @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_fast_execute_script"}) - public EsbResp fastExecuteScript(String lang, EsbFastExecuteScriptRequest request) { + public EsbResp fastExecuteScript(EsbFastExecuteScriptRequest request) { ValidateResult checkResult = checkFastExecuteScriptRequest(request); if (!checkResult.isPass()) { log.warn("Fast execute script request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastPushFileResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastPushFileResourceImpl.java index 574e394b46..b992db8217 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastPushFileResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastPushFileResourceImpl.java @@ -30,7 +30,7 @@ import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.EsbFileSourceDTO; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -82,7 +82,7 @@ public EsbFastPushFileResourceImpl(TaskExecuteService taskExecuteService, Messag @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_fast_push_file"}) - public EsbResp fastPushFile(String lang, EsbFastPushFileRequest request) { + public EsbResp fastPushFile(EsbFastPushFileRequest request) { ValidateResult checkResult = checkFastPushFileRequest(request); if (!checkResult.isPass()) { log.warn("Fast transfer file request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceGlobalVarValueResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceGlobalVarValueResourceImpl.java index b6707b806f..80e9469368 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceGlobalVarValueResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceGlobalVarValueResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.execute.api.esb.v2.EsbGetJobInstanceGlobalVarValueResource; import com.tencent.bk.job.execute.api.esb.v3.EsbGetJobInstanceGlobalVarValueV3Resource; @@ -64,7 +64,6 @@ public EsbGetJobInstanceGlobalVarValueResourceImpl( @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_job_instance_global_var_value"}) public EsbResp getJobInstanceGlobalVarValue( - String lang, EsbGetJobInstanceGlobalVarValueRequest request) { ValidateResult checkResult = checkRequest(request); @@ -76,7 +75,7 @@ public EsbResp getJobInstanceGlobalVarValue( EsbGetJobInstanceGlobalVarValueV3Request newRequest = convertToEsbGetJobInstanceGlobalVarValueV3Request(request); EsbResp esbResp = - proxyGetJobInstanceGlobalVarService.getJobInstanceGlobalVarValue(lang, newRequest); + proxyGetJobInstanceGlobalVarService.getJobInstanceGlobalVarValueUsingPost(newRequest); return EsbResp.convertData(esbResp, this::convertToEsbJobInstanceGlobalVarValueDTO); } @@ -92,32 +91,32 @@ public EsbResp getJobInstanceGlobalVarValue( } private EsbTaskInstanceGlobalVarValueDTO convertToEsbJobInstanceGlobalVarValueDTO( - EsbJobInstanceGlobalVarValueV3DTO esbJobInstanceGlobalVarValueV3DTO) { - if (esbJobInstanceGlobalVarValueV3DTO == null) { + EsbJobInstanceGlobalVarValueV3DTO originResult) { + if (originResult == null) { return null; } EsbTaskInstanceGlobalVarValueDTO result = new EsbTaskInstanceGlobalVarValueDTO(); - result.setTaskInstanceId(esbJobInstanceGlobalVarValueV3DTO.getTaskInstanceId()); + result.setTaskInstanceId(originResult.getTaskInstanceId()); - if (CollectionUtils.isNotEmpty(result.getStepGlobalVarValues())) { + if (CollectionUtils.isNotEmpty(originResult.getStepGlobalVarValues())) { List globalVarValuesForSteps = new ArrayList<>(); - result.getStepGlobalVarValues().forEach(originGlobalVarValuesForStep -> { - EsbStepInstanceGlobalVarValues globalVarValuesForStep = + originResult.getStepGlobalVarValues().forEach(originStepGlobalVarValues -> { + EsbStepInstanceGlobalVarValues stepGlobalVarValues = new EsbStepInstanceGlobalVarValues(); - globalVarValuesForStep.setStepInstanceId(originGlobalVarValuesForStep.getStepInstanceId()); - if (CollectionUtils.isNotEmpty(originGlobalVarValuesForStep.getGlobalVarValues())) { + stepGlobalVarValues.setStepInstanceId(originStepGlobalVarValues.getStepInstanceId()); + if (CollectionUtils.isNotEmpty(originStepGlobalVarValues.getGlobalVarValues())) { List globalVarValues = new ArrayList<>(); - originGlobalVarValuesForStep.getGlobalVarValues().forEach(originGlobalVarValue -> { + originStepGlobalVarValues.getGlobalVarValues().forEach(originGlobalVarValue -> { GlobalVarValue globalVarValue = new GlobalVarValue(); - globalVarValue.setCategory(originGlobalVarValue.getCategory()); + globalVarValue.setCategory(originGlobalVarValue.getType()); globalVarValue.setName(originGlobalVarValue.getName()); globalVarValue.setValue(originGlobalVarValue.getValue()); globalVarValues.add(globalVarValue); }); - globalVarValuesForStep.setGlobalVarValues(globalVarValues); + stepGlobalVarValues.setGlobalVarValues(globalVarValues); } - globalVarValuesForSteps.add(globalVarValuesForStep); + globalVarValuesForSteps.add(stepGlobalVarValues); }); result.setStepGlobalVarValues(globalVarValuesForSteps); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceLogResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceLogResourceImpl.java index 7aa3528181..1f4b91fdfc 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceLogResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceLogResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.Utils; import com.tencent.bk.job.execute.api.esb.v2.EsbGetJobInstanceLogResource; @@ -60,8 +60,7 @@ public EsbGetJobInstanceLogResourceImpl(MessageI18nService i18nService, GseTaskL @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_job_instance_log"}) - public EsbResp> getJobInstanceLogUsingPost(String lang, - EsbGetJobInstanceLogRequest request) { + public EsbResp> getJobInstanceLogUsingPost(EsbGetJobInstanceLogRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance log request is illegal!"); @@ -147,13 +146,13 @@ private ValidateResult checkRequest(EsbGetJobInstanceLogRequest request) { } @Override - public EsbResp> getJobInstanceLog(String lang, String appCode, String username, + public EsbResp> getJobInstanceLog(String appCode, String username, Long appId, Long taskInstanceId) { EsbGetJobInstanceLogRequest req = new EsbGetJobInstanceLogRequest(); req.setAppCode(appCode); req.setUserName(username); req.setAppId(appId); req.setTaskInstanceId(taskInstanceId); - return getJobInstanceLogUsingPost(lang, req); + return getJobInstanceLogUsingPost(req); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java index 11f34776d8..29a667a671 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetJobInstanceStatusResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.execute.api.esb.v2.EsbGetJobInstanceStatusResource; import com.tencent.bk.job.execute.common.constants.RunStatusEnum; @@ -67,8 +67,7 @@ public EsbGetJobInstanceStatusResourceImpl(MessageI18nService i18nService, GseTa @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_job_instance_status"}) - public EsbResp getJobInstanceStatusUsingPost(String lang, - EsbGetJobInstanceStatusRequest request) { + public EsbResp getJobInstanceStatusUsingPost(EsbGetJobInstanceStatusRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance status request is illegal!"); @@ -177,13 +176,13 @@ private EsbJobInstanceStatusDTO buildEsbJobInstanceStatusDTO(TaskInstanceDTO tas } @Override - public EsbResp getJobInstanceStatus(String lang, String appCode, String username, + public EsbResp getJobInstanceStatus(String appCode, String username, Long appId, Long taskInstanceId) { EsbGetJobInstanceStatusRequest req = new EsbGetJobInstanceStatusRequest(); req.setAppCode(appCode); req.setUserName(username); req.setAppId(appId); req.setTaskInstanceId(taskInstanceId); - return getJobInstanceStatusUsingPost(lang, req); + return getJobInstanceStatusUsingPost(req); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java index 61f59bf380..ab660649d2 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbGetStepInstanceStatusResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.execute.api.esb.v2.EsbGetStepInstanceStatusResource; @@ -68,8 +68,7 @@ public EsbGetStepInstanceStatusResourceImpl(MessageI18nService i18nService, GseT @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_step_instance_status"}) - public EsbResp getJobStepInstanceStatus(String lang, - EsbGetStepInstanceStatusRequest request) { + public EsbResp getJobStepInstanceStatus(EsbGetStepInstanceStatusRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get step instance status request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateJobInstanceResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateJobInstanceResourceImpl.java index fb78c0da6b..378b575dfe 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateJobInstanceResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateJobInstanceResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.util.json.JsonUtils; @@ -58,7 +58,7 @@ public EsbOperateJobInstanceResourceImpl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_operate_job_instance"}) - public EsbResp operateJobInstance(String lang, EsbOperateJobInstanceRequest request) { + public EsbResp operateJobInstance(EsbOperateJobInstanceRequest request) { log.info("Operate task instance, request={}", JsonUtils.toJson(request)); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateStepInstanceResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateStepInstanceResourceImpl.java index c5fb5d1009..aa0ade85bd 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateStepInstanceResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbOperateStepInstanceResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.util.json.JsonUtils; @@ -59,7 +59,7 @@ public EsbOperateStepInstanceResourceImpl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_operate_step_instance"}) - public EsbResp operateStepInstance(String lang, EsbOperateStepInstanceRequest request) { + public EsbResp operateStepInstance(EsbOperateStepInstanceRequest request) { log.info("Operate step instance, request={}", JsonUtils.toJson(request)); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java index f80a43ac5d..8400850d1c 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbPushConfigFileResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -86,7 +86,7 @@ public EsbPushConfigFileResourceImpl(TaskExecuteService taskExecuteService, Mess @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_push_config_file"}) - public EsbResp pushConfigFile(String lang, EsbPushConfigFileRequest request) { + public EsbResp pushConfigFile(EsbPushConfigFileRequest request) { ValidateResult checkResult = checkPushConfigFileRequest(request); if (!checkResult.isPass()) { log.warn("Fast transfer file request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/JobQueryCommonProcessor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/JobQueryCommonProcessor.java index 22fcb7d3e7..06fc5cf1a7 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/JobQueryCommonProcessor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/JobQueryCommonProcessor.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3ResourceImpl.java new file mode 100644 index 0000000000..32fc11037d --- /dev/null +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbBatchGetJobInstanceIpLogV3ResourceImpl.java @@ -0,0 +1,251 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.api.esb.v3; + +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.model.ValidateResult; +import com.tencent.bk.job.common.model.dto.IpDTO; +import com.tencent.bk.job.common.util.date.DateUtils; +import com.tencent.bk.job.common.util.ip.IpUtils; +import com.tencent.bk.job.execute.common.constants.FileDistModeEnum; +import com.tencent.bk.job.execute.model.ScriptIpLogContent; +import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; +import com.tencent.bk.job.execute.model.TaskInstanceDTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbFileIpLogV3DTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbFileLogV3DTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbIpLogsV3DTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbScriptIpLogV3DTO; +import com.tencent.bk.job.execute.model.esb.v3.request.EsbBatchGetJobInstanceIpLogV3Request; +import com.tencent.bk.job.execute.service.LogService; +import com.tencent.bk.job.execute.service.TaskInstanceService; +import com.tencent.bk.job.logsvr.consts.LogTypeEnum; +import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogsDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.RestController; + +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +@Slf4j +public class EsbBatchGetJobInstanceIpLogV3ResourceImpl + extends JobQueryCommonV3Processor + implements EsbBatchGetJobInstanceIpLogV3Resource { + + private final TaskInstanceService taskInstanceService; + private final LogService logService; + private final MessageI18nService i18nService; + + public EsbBatchGetJobInstanceIpLogV3ResourceImpl(MessageI18nService i18nService, + LogService logService, + TaskInstanceService taskInstanceService) { + this.i18nService = i18nService; + this.logService = logService; + this.taskInstanceService = taskInstanceService; + } + + @Override + @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_batch_get_job_instance_ip_log"}) + public EsbResp batchGetJobInstanceIpLogs(EsbBatchGetJobInstanceIpLogV3Request request) { + ValidateResult checkResult = checkRequest(request); + if (!checkResult.isPass()) { + log.warn("Batch get job instance ip log request is illegal!"); + return EsbResp.buildCommonFailResp(i18nService, checkResult); + } + + long taskInstanceId = request.getTaskInstanceId(); + TaskInstanceDTO taskInstance = taskInstanceService.getTaskInstance(taskInstanceId); + if (taskInstance == null) { + return EsbResp.buildCommonFailResp(ErrorCode.TASK_INSTANCE_NOT_EXIST, i18nService); + } + + EsbResp authResult = authViewTaskInstance(request.getUserName(), + request.getAppId(), taskInstance); + if (!authResult.getCode().equals(EsbResp.SUCCESS_CODE)) { + return authResult; + } + + StepInstanceBaseDTO stepInstance = taskInstanceService.getBaseStepInstance(request.getStepInstanceId()); + if (stepInstance == null) { + return EsbResp.buildCommonFailResp(ErrorCode.TASK_INSTANCE_NOT_EXIST, i18nService); + } + + EsbIpLogsV3DTO ipLogs = new EsbIpLogsV3DTO(); + ipLogs.setTaskInstanceId(taskInstanceId); + ipLogs.setStepInstanceId(request.getStepInstanceId()); + + if (stepInstance.isScriptStep()) { + buildScriptLogs(ipLogs, stepInstance, request.getIpList()); + } else if (stepInstance.isFileStep()) { + buildFileLogs(ipLogs, stepInstance, request.getIpList()); + } + return EsbResp.buildSuccessResp(ipLogs); + } + + private ValidateResult checkRequest(EsbBatchGetJobInstanceIpLogV3Request request) { + if (request.getAppId() == null || request.getAppId() < 1) { + log.warn("App is empty or illegal, appId={}", request.getAppId()); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, "bk_biz_id"); + } + if (request.getTaskInstanceId() == null || request.getTaskInstanceId() < 1) { + log.warn("TaskInstanceId is empty or illegal, taskInstanceId={}", request.getTaskInstanceId()); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, "job_instance_id"); + } + if (request.getStepInstanceId() == null || request.getStepInstanceId() < 1) { + log.warn("StepInstanceId is empty or illegal, stepInstanceId={}", request.getStepInstanceId()); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, + "step_instance_id"); + } + + ValidateResult ipCheckResult = checkIps(request.getIpList()); + if (!ipCheckResult.isPass()) { + return ipCheckResult; + } + + int ipSize = request.getIpList().size(); + if (ipSize > 500) { + log.warn("IpList size is gt 500, stepInstanceId={}, size: {}", request.getStepInstanceId(), ipSize); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, + "ip_list"); + } + + return ValidateResult.pass(); + } + + private ValidateResult checkIps(List cloudIpList) { + if (CollectionUtils.isEmpty(cloudIpList)) { + log.warn("IpList is empty "); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, "ip_list"); + } + for (EsbIpDTO cloudIp : cloudIpList) { + if (cloudIp.getCloudAreaId() == null || cloudIp.getCloudAreaId() < 0) { + log.warn("CloudAreaId is empty or illegal, cloudAreaId={}", cloudIp.getCloudAreaId()); + return ValidateResult.fail(ErrorCode.MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME, + "bk_cloud_id"); + } + if (StringUtils.isBlank(cloudIp.getIp())) { + log.warn("Ip is empty"); + return ValidateResult.fail(ErrorCode.MISSING_PARAM_WITH_PARAM_NAME, "ip"); + } + if (!IpUtils.checkIp(cloudIp.getIp())) { + log.warn("Ip is illegal, ip={}", cloudIp.getIp()); + return ValidateResult.fail(ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME, "ip"); + } + } + return ValidateResult.pass(); + } + + private void buildScriptLogs(EsbIpLogsV3DTO ipLogs, StepInstanceBaseDTO stepInstance, + List ipList) { + ipLogs.setLogType(LogTypeEnum.SCRIPT.getValue()); + + String jobCreateDate = DateUtils.formatUnixTimestamp(stepInstance.getCreateTime(), ChronoUnit.MILLIS, + "yyyy_MM_dd", ZoneId.of("UTC")); + List ipLogContentList = logService.batchGetScriptIpLogContent(jobCreateDate, + stepInstance.getId(), stepInstance.getExecuteCount(), + ipList.stream().map(cloudIp -> new IpDTO(cloudIp.getCloudAreaId(), cloudIp.getIp())) + .collect(Collectors.toList())); + + if (CollectionUtils.isEmpty(ipLogContentList)) { + return; + } + + List scriptTaskLogs = ipLogContentList.stream().map(ipLogContent -> { + EsbScriptIpLogV3DTO scriptIpLog = new EsbScriptIpLogV3DTO(); + IpDTO cloudIp = IpUtils.transform(ipLogContent.getIp()); + scriptIpLog.setCloudAreaId(cloudIp.getCloudAreaId()); + scriptIpLog.setIp(cloudIp.getIp()); + scriptIpLog.setLogContent(ipLogContent.getContent()); + return scriptIpLog; + }).collect(Collectors.toList()); + ipLogs.setScriptTaskLogs(scriptTaskLogs); + } + + private void buildFileLogs(EsbIpLogsV3DTO esbIpLogs, StepInstanceBaseDTO stepInstance, + List ipList) { + esbIpLogs.setLogType(LogTypeEnum.FILE.getValue()); + + ServiceIpLogsDTO ipLogs = logService.batchGetFileIpLogContent( + stepInstance.getId(), stepInstance.getExecuteCount(), + ipList.stream().map(cloudIp -> new IpDTO(cloudIp.getCloudAreaId(), cloudIp.getIp())) + .collect(Collectors.toList())); + + if (ipLogs == null || CollectionUtils.isEmpty(ipLogs.getIpLogs())) { + return; + } + + List fileTaskLogs = ipLogs.getIpLogs().stream().map(ipLog -> { + List ipFileLogs = ipLog.getFileTaskLogs(); + EsbFileIpLogV3DTO esbFileIpLog = new EsbFileIpLogV3DTO(); + if (CollectionUtils.isNotEmpty(ipFileLogs)) { + IpDTO cloudIp = IpDTO.fromCloudAreaIdAndIpStr(ipLog.getIp()); + if (cloudIp != null) { + esbFileIpLog.setCloudAreaId(cloudIp.getCloudAreaId()); + esbFileIpLog.setIp(cloudIp.getIp()); + } + List esbFileLogs = ipFileLogs.stream() + .map(this::toEsbFileLogV3DTO).collect(Collectors.toList()); + esbFileIpLog.setFileLogs(esbFileLogs); + } + return esbFileIpLog; + }).collect(Collectors.toList()); + + esbIpLogs.setFileTaskLogs(fileTaskLogs); + } + + private EsbFileLogV3DTO toEsbFileLogV3DTO(ServiceFileTaskLogDTO fileTaskLog) { + EsbFileLogV3DTO fileLog = new EsbFileLogV3DTO(); + fileLog.setMode(fileTaskLog.getMode()); + if (StringUtils.isNotBlank(fileTaskLog.getDisplaySrcIp())) { + EsbIpDTO srcIp = EsbIpDTO.fromCloudIp(fileTaskLog.getDisplaySrcIp()); + if (srcIp != null) { + fileLog.setSrcIp(srcIp); + } + } + fileLog.setSrcPath(fileTaskLog.getDisplaySrcFile()); + if (FileDistModeEnum.DOWNLOAD.getValue().equals(fileTaskLog.getMode())) { + if (StringUtils.isNotBlank(fileTaskLog.getDestIp())) { + EsbIpDTO destIp = EsbIpDTO.fromCloudIp(fileTaskLog.getDestIp()); + if (destIp != null) { + fileLog.setDestIp(destIp); + } + } + fileLog.setDestPath(fileTaskLog.getDestFile()); + } + + fileLog.setLogContent(fileTaskLog.getContent()); + fileLog.setStatus(fileTaskLog.getStatus()); + return fileLog; + } +} diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3ResourceImpl.java index 76f0634e74..52c9c0a695 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbExecuteJobPlanV3ResourceImpl.java @@ -30,7 +30,7 @@ import com.tencent.bk.job.common.esb.model.job.v3.EsbGlobalVarV3DTO; import com.tencent.bk.job.common.esb.model.job.v3.EsbServerV3DTO; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -74,7 +74,7 @@ public EsbExecuteJobPlanV3ResourceImpl(TaskExecuteService taskExecuteService, Me @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_execute_job_plan"}) - public EsbResp executeJobPlan(String lang, EsbExecuteJobV3Request request) { + public EsbResp executeJobPlan(EsbExecuteJobV3Request request) { log.info("Execute task, request={}", JsonUtils.toJson(request)); ValidateResult checkResult = checkExecuteTaskRequest(request); if (!checkResult.isPass()) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3ResourceImpl.java index 7a240356ab..6c06f34aa6 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteSQLV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -73,7 +73,7 @@ public EsbFastExecuteSQLV3ResourceImpl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_fast_execute_sql"}) - public EsbResp fastExecuteSQL(String lang, EsbFastExecuteSQLV3Request request) { + public EsbResp fastExecuteSQL(EsbFastExecuteSQLV3Request request) { ValidateResult validateResult = checkFastExecuteSQLRequest(request); if (!validateResult.isPass()) { log.warn("Fast execute sql request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3ResourceImpl.java index d8c6a5f00e..0ae1f38818 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastExecuteScriptV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -73,7 +73,7 @@ public EsbFastExecuteScriptV3ResourceImpl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_fast_execute_script"}) - public EsbResp fastExecuteScript(String lang, EsbFastExecuteScriptV3Request request) { + public EsbResp fastExecuteScript(EsbFastExecuteScriptV3Request request) { ValidateResult checkResult = checkFastExecuteScriptRequest(request); if (!checkResult.isPass()) { log.warn("Fast execute script request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java index 0e9677c11f..73d2bb9004 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java @@ -31,14 +31,18 @@ import com.tencent.bk.job.common.esb.model.job.v3.EsbAccountV3BasicDTO; import com.tencent.bk.job.common.esb.model.job.v3.EsbFileSourceV3DTO; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.execute.client.FileSourceResourceClient; -import com.tencent.bk.job.execute.common.constants.*; +import com.tencent.bk.job.execute.common.constants.FileTransferModeEnum; +import com.tencent.bk.job.execute.common.constants.RunStatusEnum; +import com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum; +import com.tencent.bk.job.execute.common.constants.TaskStartupModeEnum; +import com.tencent.bk.job.execute.common.constants.TaskTypeEnum; import com.tencent.bk.job.execute.model.FileDetailDTO; import com.tencent.bk.job.execute.model.FileSourceDTO; import com.tencent.bk.job.execute.model.StepInstanceDTO; @@ -85,7 +89,7 @@ public EsbFastTransferFileV3ResourceImpl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_fast_transfer_file"}) - public EsbResp fastTransferFile(String lang, EsbFastTransferFileV3Request request) { + public EsbResp fastTransferFile(EsbFastTransferFileV3Request request) { ValidateResult checkResult = checkFastTransferFileRequest(request); if (!checkResult.isPass()) { log.warn("Fast transfer file request is illegal!"); @@ -104,6 +108,7 @@ public EsbResp fastTransferFile(String lang, EsbFastTransfer EsbJobExecuteV3DTO jobExecuteInfo = new EsbJobExecuteV3DTO(); jobExecuteInfo.setTaskInstanceId(taskInstanceId); + jobExecuteInfo.setStepInstanceId(stepInstance.getId()); jobExecuteInfo.setTaskName(stepInstance.getName()); return EsbResp.buildSuccessResp(jobExecuteInfo); } catch (InSufficientPermissionException e) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3ResourceImpl.java index c6866d3fc9..78e71bb33e 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceGlobalVarValueV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.execute.model.StepInstanceVariableValuesDTO; import com.tencent.bk.job.execute.model.TaskInstanceDTO; @@ -65,8 +65,9 @@ public EsbGetJobInstanceGlobalVarValueV3ResourceImpl(MessageI18nService i18nServ @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_instance_var_value"}) - public EsbResp getJobInstanceGlobalVarValue(String lang, - EsbGetJobInstanceGlobalVarValueV3Request request) { + public EsbResp getJobInstanceGlobalVarValueUsingPost( + EsbGetJobInstanceGlobalVarValueV3Request request) { + ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance global var value, request is illegal!"); @@ -122,4 +123,17 @@ private ValidateResult checkRequest(EsbGetJobInstanceGlobalVarValueV3Request req } return ValidateResult.pass(); } + + @Override + public EsbResp getJobInstanceGlobalVarValue(String username, + String appCode, + Long appId, + Long taskInstanceId) { + EsbGetJobInstanceGlobalVarValueV3Request request = new EsbGetJobInstanceGlobalVarValueV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setTaskInstanceId(taskInstanceId); + return getJobInstanceGlobalVarValueUsingPost(request); + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3ResourceImpl.java index 64c3d95106..6ae33d8ac2 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceIpLogV3ResourceImpl.java @@ -27,24 +27,36 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.common.util.ip.IpUtils; +import com.tencent.bk.job.execute.common.constants.FileDistModeEnum; +import com.tencent.bk.job.execute.model.FileIpLogContent; import com.tencent.bk.job.execute.model.ScriptIpLogContent; import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; import com.tencent.bk.job.execute.model.TaskInstanceDTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbFileLogV3DTO; import com.tencent.bk.job.execute.model.esb.v3.EsbIpLogV3DTO; import com.tencent.bk.job.execute.model.esb.v3.request.EsbGetJobInstanceIpLogV3Request; import com.tencent.bk.job.execute.service.LogService; import com.tencent.bk.job.execute.service.TaskInstanceService; +import com.tencent.bk.job.logsvr.consts.LogTypeEnum; +import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @RestController @Slf4j -public class EsbGetJobInstanceIpLogV3ResourceImpl extends JobQueryCommonV3Processor implements EsbGetJobInstanceIpLogV3Resource { +public class EsbGetJobInstanceIpLogV3ResourceImpl extends JobQueryCommonV3Processor + implements EsbGetJobInstanceIpLogV3Resource { private final TaskInstanceService taskInstanceService; private final LogService logService; @@ -60,7 +72,7 @@ public EsbGetJobInstanceIpLogV3ResourceImpl(MessageI18nService i18nService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_instance_ip_log"}) - public EsbResp getJobInstanceIpLog(String lang, EsbGetJobInstanceIpLogV3Request request) { + public EsbResp getJobInstanceIpLogUsingPost(EsbGetJobInstanceIpLogV3Request request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance ip log request is illegal!"); @@ -69,7 +81,12 @@ public EsbResp getJobInstanceIpLog(String lang, EsbGetJobInstance long taskInstanceId = request.getTaskInstanceId(); TaskInstanceDTO taskInstance = taskInstanceService.getTaskInstance(taskInstanceId); - EsbResp authResult = authViewTaskInstance(request.getUserName(), request.getAppId(), taskInstance); + if (taskInstance == null) { + return EsbResp.buildCommonFailResp(ErrorCode.TASK_INSTANCE_NOT_EXIST, i18nService); + } + + EsbResp authResult = authViewTaskInstance(request.getUserName(), + request.getAppId(), taskInstance); if (!authResult.getCode().equals(EsbResp.SUCCESS_CODE)) { return authResult; } @@ -83,14 +100,11 @@ public EsbResp getJobInstanceIpLog(String lang, EsbGetJobInstance ipLog.setCloudAreaId(request.getCloudAreaId()); ipLog.setIp(request.getIp()); if (stepInstance.isScriptStep()) { - ScriptIpLogContent logContent = logService.getScriptIpLogContent(request.getStepInstanceId(), - stepInstance.getExecuteCount(), - new IpDTO(request.getCloudAreaId(), request.getIp())); - if (logContent != null && StringUtils.isNotBlank(logContent.getContent())) { - ipLog.setLogContent(logContent.getContent()); - } + buildScriptLog(ipLog, request.getStepInstanceId(), stepInstance.getExecuteCount(), request.getCloudAreaId(), + request.getIp()); } else if (stepInstance.isFileStep()) { - // TODO + buildFileLog(ipLog, request.getStepInstanceId(), stepInstance.getExecuteCount(), request.getCloudAreaId(), + request.getIp()); } return EsbResp.buildSuccessResp(ipLog); } @@ -123,4 +137,89 @@ private ValidateResult checkRequest(EsbGetJobInstanceIpLogV3Request request) { return ValidateResult.pass(); } + + private void buildScriptLog(EsbIpLogV3DTO ipLog, Long stepInstanceId, Integer executeCount, + Long cloudAreaId, String ip) { + ipLog.setLogType(LogTypeEnum.SCRIPT.getValue()); + ScriptIpLogContent logContent = logService.getScriptIpLogContent(stepInstanceId, + executeCount, new IpDTO(cloudAreaId, ip)); + if (logContent != null && StringUtils.isNotBlank(logContent.getContent())) { + ipLog.setScriptLogContent(logContent.getContent()); + } + } + + private void buildFileLog(EsbIpLogV3DTO ipLog, Long stepInstanceId, Integer executeCount, + Long cloudAreaId, String ip) { + ipLog.setLogType(LogTypeEnum.FILE.getValue()); + FileIpLogContent downloadIpLog = logService.getFileIpLogContent(stepInstanceId, executeCount, + new IpDTO(cloudAreaId, ip), FileDistModeEnum.DOWNLOAD.getValue()); + List uploadTaskLogs = logService.batchGetFileSourceIpLogContent( + stepInstanceId, executeCount); + + List fileLogs = new ArrayList<>(); + fileLogs.addAll(buildDownloadFileLogs(downloadIpLog)); + fileLogs.addAll(buildUploadFileLogs(uploadTaskLogs)); + ipLog.setFileLogs(fileLogs); + } + + private List buildDownloadFileLogs(FileIpLogContent downloadIpLog) { + List downloadFileLogs = new ArrayList<>(); + if (downloadIpLog != null && CollectionUtils.isNotEmpty(downloadIpLog.getFileTaskLogs())) { + downloadFileLogs = downloadIpLog.getFileTaskLogs().stream().map(this::toEsbFileLogV3DTO) + .collect(Collectors.toList()); + } + return downloadFileLogs; + } + + private List buildUploadFileLogs(List uploadTaskLogs) { + List uploadFileLogs = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(uploadTaskLogs)) { + uploadFileLogs = uploadTaskLogs.stream().map(this::toEsbFileLogV3DTO).collect(Collectors.toList()); + } + return uploadFileLogs; + } + + private EsbFileLogV3DTO toEsbFileLogV3DTO(ServiceFileTaskLogDTO fileTaskLog) { + EsbFileLogV3DTO fileLog = new EsbFileLogV3DTO(); + fileLog.setMode(fileTaskLog.getMode()); + if (StringUtils.isNotBlank(fileTaskLog.getDisplaySrcIp())) { + EsbIpDTO srcIp = EsbIpDTO.fromCloudIp(fileTaskLog.getDisplaySrcIp()); + if (srcIp != null) { + fileLog.setSrcIp(srcIp); + } + } + fileLog.setSrcPath(fileTaskLog.getDisplaySrcFile()); + if (FileDistModeEnum.DOWNLOAD.getValue().equals(fileTaskLog.getMode())) { + if (StringUtils.isNotBlank(fileTaskLog.getDestIp())) { + EsbIpDTO destIp = EsbIpDTO.fromCloudIp(fileTaskLog.getDestIp()); + if (destIp != null) { + fileLog.setDestIp(destIp); + } + } + fileLog.setDestPath(fileTaskLog.getDestFile()); + } + + fileLog.setLogContent(fileTaskLog.getContent()); + fileLog.setStatus(fileTaskLog.getStatus()); + return fileLog; + } + + @Override + public EsbResp getJobInstanceIpLog(String username, + String appCode, + Long appId, + Long taskInstanceId, + Long stepInstanceId, + Long cloudAreaId, + String ip) { + EsbGetJobInstanceIpLogV3Request request = new EsbGetJobInstanceIpLogV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setTaskInstanceId(taskInstanceId); + request.setStepInstanceId(stepInstanceId); + request.setCloudAreaId(cloudAreaId); + request.setIp(ip); + return getJobInstanceIpLogUsingPost(request); + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java index 5a1ee3165f..ed2a50e3c5 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceListV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ValidateResult; @@ -64,8 +64,9 @@ public EsbGetJobInstanceListV3ResourceImpl(MessageI18nService i18nService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_instance_list"}) - public EsbResp> getJobInstanceList(String lang, - EsbGetJobInstanceListV3Request request) { + public EsbResp> getJobInstanceListUsingPost( + EsbGetJobInstanceListV3Request request) { + ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance ip log request is illegal!"); @@ -155,4 +156,37 @@ private ValidateResult checkRequest(EsbGetJobInstanceListV3Request request) { } return ValidateResult.pass(); } + + @Override + public EsbResp> getJobInstanceList(String username, + String appCode, + Long appId, + Long createTimeStart, + Long createTimeEnd, + Long taskInstanceId, + String operator, + String taskName, + Integer startupMode, + Integer taskType, + Integer taskStatus, + String ip, + Integer start, + Integer length) { + EsbGetJobInstanceListV3Request request = new EsbGetJobInstanceListV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setCreateTimeStart(createTimeStart); + request.setCreateTimeEnd(createTimeEnd); + request.setTaskInstanceId(taskInstanceId); + request.setOperator(operator); + request.setTaskName(taskName); + request.setStartupMode(startupMode); + request.setTaskType(taskType); + request.setTaskStatus(taskStatus); + request.setIp(ip); + request.setStart(start); + request.setLength(length); + return getJobInstanceListUsingPost(request); + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java index 6ca629010f..2ca523daf4 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbGetJobInstanceStatusV3ResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.execute.common.constants.RunStatusEnum; import com.tencent.bk.job.execute.model.GseTaskIpLogDTO; @@ -63,8 +63,7 @@ public EsbGetJobInstanceStatusV3ResourceImpl(MessageI18nService i18nService, Gse @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_instance_status"}) - public EsbResp getJobInstanceStatus(String lang, - EsbGetJobInstanceStatusV3Request request) { + public EsbResp getJobInstanceStatusUsingPost(EsbGetJobInstanceStatusV3Request request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job instance status request is illegal!"); @@ -74,7 +73,7 @@ public EsbResp getJobInstanceStatus(String lang, long taskInstanceId = request.getTaskInstanceId(); TaskInstanceDTO taskInstance = taskInstanceService.getTaskInstance(request.getTaskInstanceId()); - EsbResp authResult = authViewTaskInstance(request.getUserName(), request.getAppId(), taskInstance); + EsbResp authResult = authViewTaskInstance(request.getUserName(), request.getAppId(), taskInstance); if (!authResult.getCode().equals(EsbResp.SUCCESS_CODE)) { return authResult; } @@ -163,4 +162,19 @@ private EsbJobInstanceStatusV3DTO buildEsbJobInstanceStatusDTO(TaskInstanceDTO t return jobInstanceStatus; } + + @Override + public EsbResp getJobInstanceStatus(String username, + String appCode, + Long appId, + Long taskInstanceId, + boolean returnIpResult) { + EsbGetJobInstanceStatusV3Request request = new EsbGetJobInstanceStatusV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setTaskInstanceId(taskInstanceId); + request.setReturnIpResult(returnIpResult); + return getJobInstanceStatusUsingPost(request); + } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3ResourceImpl.java index 57358c0c61..4f55102862 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateJobInstanceV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.util.json.JsonUtils; @@ -57,7 +57,7 @@ public EsbOperateJobInstanceV3ResourceImpl(TaskExecuteService taskExecuteService @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_operate_job_instance"}) - public EsbResp operateJobInstance(String lang, EsbOperateJobInstanceV3Request request) { + public EsbResp operateJobInstance(EsbOperateJobInstanceV3Request request) { log.info("Operate task instance, request={}", JsonUtils.toJson(request)); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3ResourceImpl.java index 468014b1ce..7b94fa08a8 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbOperateStepInstanceV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.util.json.JsonUtils; @@ -58,7 +58,7 @@ public EsbOperateStepInstanceV3ResourceImpl(TaskExecuteService taskExecuteServic @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_operate_step_instance"}) - public EsbResp operateStepInstance(String lang, EsbOperateStepInstanceV3Request request) { + public EsbResp operateStepInstance(EsbOperateStepInstanceV3Request request) { log.info("Operate step instance, request={}", JsonUtils.toJson(request)); if (!checkRequest(request)) { return EsbResp.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM, i18nService); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java index cd7b24448a..f79bef205a 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbPushConfigFileResourceV3Impl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ValidateResult; @@ -86,7 +86,7 @@ public EsbPushConfigFileResourceV3Impl(TaskExecuteService taskExecuteService, @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_push_config_file"}) - public EsbResp pushConfigFile(String lang, EsbPushConfigFileV3Request request) { + public EsbResp pushConfigFile(EsbPushConfigFileV3Request request) { ValidateResult checkResult = checkPushConfigFileRequest(request); if (!checkResult.isPass()) { log.warn("Fast transfer file request is illegal!"); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/JobQueryCommonV3Processor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/JobQueryCommonV3Processor.java index e34bcfb8e7..8610df1695 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/JobQueryCommonV3Processor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/JobQueryCommonV3Processor.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.execute.model.TaskInstanceDTO; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java index 6b67b3f8ec..fe7f60dff3 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceExecuteTaskResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.WebAuthService; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResourceImpl.java index 4df715896f..164a279f77 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceTaskExecuteResultResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.execute.api.inner; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebExecuteTaskResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebExecuteTaskResourceImpl.java index ecba750d4f..83c83da5b7 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebExecuteTaskResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebExecuteTaskResourceImpl.java @@ -27,16 +27,19 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.WebAuthService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.IpDTO; -import com.tencent.bk.job.common.util.check.*; +import com.tencent.bk.job.common.util.check.IlegalCharChecker; +import com.tencent.bk.job.common.util.check.MaxLengthChecker; +import com.tencent.bk.job.common.util.check.NotEmptyChecker; +import com.tencent.bk.job.common.util.check.StringCheckHelper; +import com.tencent.bk.job.common.util.check.TrimChecker; import com.tencent.bk.job.common.util.check.exception.StringCheckException; import com.tencent.bk.job.common.util.date.DateUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.execute.api.web.WebExecuteTaskResource; import com.tencent.bk.job.execute.common.constants.RunStatusEnum; import com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum; @@ -44,9 +47,29 @@ import com.tencent.bk.job.execute.common.constants.TaskTypeEnum; import com.tencent.bk.job.execute.constants.StepOperationEnum; import com.tencent.bk.job.execute.engine.model.TaskVariableDTO; -import com.tencent.bk.job.execute.model.*; -import com.tencent.bk.job.execute.model.web.request.*; -import com.tencent.bk.job.execute.model.web.vo.*; +import com.tencent.bk.job.execute.model.DynamicServerGroupDTO; +import com.tencent.bk.job.execute.model.DynamicServerTopoNodeDTO; +import com.tencent.bk.job.execute.model.FileDetailDTO; +import com.tencent.bk.job.execute.model.FileSourceDTO; +import com.tencent.bk.job.execute.model.ServersDTO; +import com.tencent.bk.job.execute.model.StepInstanceDTO; +import com.tencent.bk.job.execute.model.StepOperationDTO; +import com.tencent.bk.job.execute.model.TaskExecuteParam; +import com.tencent.bk.job.execute.model.TaskInstanceDTO; +import com.tencent.bk.job.execute.model.web.request.RedoTaskRequest; +import com.tencent.bk.job.execute.model.web.request.WebFastExecuteScriptRequest; +import com.tencent.bk.job.execute.model.web.request.WebFastPushFileRequest; +import com.tencent.bk.job.execute.model.web.request.WebStepOperation; +import com.tencent.bk.job.execute.model.web.request.WebTaskExecuteRequest; +import com.tencent.bk.job.execute.model.web.vo.ExecuteFileDestinationInfoVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteFileSourceInfoVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteHostVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteServersVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteTargetVO; +import com.tencent.bk.job.execute.model.web.vo.ExecuteVariableVO; +import com.tencent.bk.job.execute.model.web.vo.StepExecuteVO; +import com.tencent.bk.job.execute.model.web.vo.StepOperationVO; +import com.tencent.bk.job.execute.model.web.vo.TaskExecuteVO; import com.tencent.bk.job.execute.service.TaskExecuteService; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskFileTypeEnum; @@ -61,11 +84,16 @@ import java.util.ArrayList; import java.util.List; -import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.*; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.ASSOCIATIVE_ARRAY; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.CIPHER; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.HOST_LIST; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.INDEX_ARRAY; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.NAMESPACE; +import static com.tencent.bk.job.common.constant.TaskVariableTypeEnum.STRING; @RestController @Slf4j -public class WebExecuteTaskResourceImpl extends AbstractJobController implements WebExecuteTaskResource { +public class WebExecuteTaskResourceImpl implements WebExecuteTaskResource { private final TaskExecuteService taskExecuteService; private final MessageI18nService i18nService; private final WebAuthService webAuthService; @@ -348,28 +376,28 @@ public ServiceResponse fastPushFile(String username, Long appId, private ServiceResponse createAndStartFastTask(boolean isRedoTask, TaskInstanceDTO taskInstance, StepInstanceDTO stepInstance) { - try { - long taskInstanceId; - if (!isRedoTask) { - taskInstanceId = taskExecuteService.createTaskInstanceFast(taskInstance, stepInstance); - } else { - taskInstanceId = taskExecuteService.createTaskInstanceForFastTaskRedo(taskInstance, stepInstance); - } - taskExecuteService.startTask(taskInstanceId); - StepExecuteVO stepExecuteVO = new StepExecuteVO(); - stepExecuteVO.setTaskInstanceId(taskInstanceId); - stepExecuteVO.setStepInstanceId(stepInstance.getId()); - stepExecuteVO.setStepName(stepInstance.getName()); - return ServiceResponse.buildSuccessResp(stepExecuteVO); - } catch (InSufficientPermissionException e) { - return handleInSufficientPermissionException(e); - } catch (ServiceException e) { - log.warn("Fail to start task", e); - return ServiceResponse.buildCommonFailResp(e, i18nService); - } catch (Exception e) { - log.warn("Fail to start task", e); - return ServiceResponse.buildCommonFailResp(ErrorCode.STARTUP_TASK_FAIL, i18nService); - } + long taskInstanceId; + if (!isRedoTask) { + taskInstanceId = taskExecuteService.createTaskInstanceFast(taskInstance, stepInstance); + } else { + taskInstanceId = taskExecuteService.createTaskInstanceForFastTaskRedo(taskInstance, stepInstance); + } + taskExecuteService.startTask(taskInstanceId); + StepExecuteVO stepExecuteVO = new StepExecuteVO(); + stepExecuteVO.setTaskInstanceId(taskInstanceId); + stepExecuteVO.setStepInstanceId(stepInstance.getId()); + stepExecuteVO.setStepName(stepInstance.getName()); + return ServiceResponse.buildSuccessResp(stepExecuteVO); +// try { +// } catch (InSufficientPermissionException e) { +// return handleInSufficientPermissionException(e); +// } catch (ServiceException e) { +// log.warn("Fail to start task", e); +// return ServiceResponse.buildCommonFailResp(e, i18nService); +// } catch (Exception e) { +// log.warn("Fail to start task", e); +// return ServiceResponse.buildCommonFailResp(ErrorCode.STARTUP_TASK_FAIL, i18nService); +// } } private ServiceResponse handleInSufficientPermissionException(InSufficientPermissionException e) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebPermissionResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebPermissionResourceImpl.java index 363dd935c9..0c4ed31076 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebPermissionResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebPermissionResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.execute.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.WebAuthService; import com.tencent.bk.job.common.model.ServiceResponse; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskExecutionResultResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskExecutionResultResourceImpl.java index 5d4005d445..309b37f467 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskExecutionResultResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskExecutionResultResourceImpl.java @@ -31,7 +31,7 @@ import com.tencent.bk.job.common.constant.Order; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; import com.tencent.bk.job.common.iam.model.AuthResult; import com.tencent.bk.job.common.iam.service.WebAuthService; @@ -146,6 +146,7 @@ public WebTaskExecutionResultResourceImpl(TaskResultService taskResultService, ExecuteAuthService executeAuthService, WebAuthService webAuthService, GseTaskLogService gseTaskLogService) { + super(webAuthService.getAuthService()); this.taskResultService = taskResultService; this.i18nService = i18nService; this.logService = logService; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java index de7772c8bb..cc0b6d938e 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskInstanceResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.NotExistPathHandlerEnum; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -37,7 +37,6 @@ import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.Base64Util; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.execute.api.web.WebTaskInstanceResource; import com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum; import com.tencent.bk.job.execute.common.constants.TaskStartupModeEnum; @@ -51,7 +50,7 @@ import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -61,7 +60,7 @@ @RestController @Slf4j -public class WebTaskInstanceResourceImpl extends AbstractJobController implements WebTaskInstanceResource { +public class WebTaskInstanceResourceImpl implements WebTaskInstanceResource { private final TaskInstanceService taskInstanceService; private final TaskInstanceVariableService taskInstanceVariableService; private final ServerService serverService; @@ -460,6 +459,11 @@ public ServiceResponse getTaskInstanceBasic(String username, Lon if (taskInstance == null) { return ServiceResponse.buildCommonFailResp(ErrorCode.TASK_INSTANCE_NOT_EXIST, i18nService); } + AuthResultVO authResultVO = webAuthService.auth(true, username, ActionId.LIST_BUSINESS, + ResourceTypeEnum.BUSINESS, taskInstance.getAppId().toString(), null); + if (!authResultVO.isPass()) { + return ServiceResponse.buildAuthFailResp(authResultVO); + } return ServiceResponse.buildSuccessResp(TaskInstanceConverter.convertToTaskInstanceVO(taskInstance, i18nService)); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskLogResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskLogResourceImpl.java index 1bb011c27f..6899628171 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskLogResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebTaskLogResourceImpl.java @@ -25,10 +25,9 @@ package com.tencent.bk.job.execute.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.date.DateUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.execute.api.web.WebTaskLogResource; import com.tencent.bk.job.execute.config.StorageSystemConfig; import com.tencent.bk.job.execute.engine.consts.FileDirTypeConf; @@ -55,7 +54,7 @@ @RestController @Slf4j -public class WebTaskLogResourceImpl extends AbstractJobController implements WebTaskLogResource { +public class WebTaskLogResourceImpl implements WebTaskLogResource { private final String logFileDir; private final MessageI18nService i18nService; private final TaskInstanceService taskInstanceService; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/WebExceptionControllerAdvice.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/WebExceptionControllerAdvice.java deleted file mode 100644 index deabf4291a..0000000000 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/WebExceptionControllerAdvice.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.execute.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; -import com.tencent.bk.job.common.iam.model.AuthResult; -import com.tencent.bk.job.common.iam.service.WebAuthService; -import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice({"com.tencent.bk.job.execute.api.web"}) -@Slf4j -public class WebExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - private final WebAuthService webAuthService; - - @Autowired - public WebExceptionControllerAdvice(MessageI18nService i18nService, WebAuthService webAuthService) { - this.i18nService = i18nService; - this.webAuthService = webAuthService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - String exceptionInfo = "Handle service exception, exception: " + ex.toString(); - log.warn(exceptionInfo, ex); - if (ex instanceof HttpStatusServiceException) { - HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException, i18nService), - httpStatusServiceException.getHttpStatus()); - } else if (ex instanceof InSufficientPermissionException) { - InSufficientPermissionException inSufficientPermissionException = (InSufficientPermissionException) ex; - AuthResult authResult = inSufficientPermissionException.getAuthResult(); - log.debug("Insufficient permission, authResult: {}", authResult); - if (StringUtils.isEmpty(authResult.getApplyUrl())) { - authResult.setApplyUrl(webAuthService.getApplyUrl(authResult.getRequiredActionResources())); - } - return new ResponseEntity<>(ServiceResponse.buildAuthFailResp( - webAuthService.toAuthResultVO(inSufficientPermissionException.getAuthResult())), HttpStatus.OK); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex, i18nService), - HttpStatus.OK); - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.warn("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } - -} diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/interceptor/UriPermissionInterceptor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/interceptor/UriPermissionInterceptor.java new file mode 100644 index 0000000000..a5c1b80256 --- /dev/null +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/interceptor/UriPermissionInterceptor.java @@ -0,0 +1,102 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.execute.common.interceptor; + +import com.tencent.bk.job.common.RequestIdLogger; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.util.JobContextUtil; +import com.tencent.bk.job.common.util.SimpleRequestIdLogger; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.List; + +/** + * Uri权限控制拦截 + */ +@Slf4j +@Component +public class UriPermissionInterceptor extends HandlerInterceptorAdapter { + private static final RequestIdLogger logger = + new SimpleRequestIdLogger(LoggerFactory.getLogger(UriPermissionInterceptor.class)); + private final String URI_PATTERN_DANGEROUS_RECORD = "/web/dangerous-record/**"; + private AuthService authService; + private PathMatcher pathMatcher; + + @Autowired + public UriPermissionInterceptor(AuthService authService) { + this.authService = authService; + this.pathMatcher = new AntPathMatcher(); + } + + public String[] getControlUriPatterns() { + Object[] rawArr = getControlUriPatternsList().toArray(); + String[] arr = new String[rawArr.length]; + for (int i = 0; i < rawArr.length; i++) { + arr[i] = (String) rawArr[i]; + } + return arr; + } + + private List getControlUriPatternsList() { + return Collections.singletonList( + // 高危语句拦截记录 + URI_PATTERN_DANGEROUS_RECORD + ); + } + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + String username = JobContextUtil.getUsername(); + String uri = request.getRequestURI(); + logger.infoWithRequestId("PermissionControlInterceptor.preHandle:username=" + username + ", uri=" + uri + ", " + + "controlUriPatterns=" + getControlUriPatternsList()); + if (pathMatcher.match(URI_PATTERN_DANGEROUS_RECORD, uri)) { + AuthResult authResult = authService.auth(true, username, ActionId.HIGH_RISK_DETECT_RECORD); + if (!authResult.isPass()) { + throw new InSufficientPermissionException(authResult); + } + } + return true; + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) + throws Exception { + + } +} diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/util/VariableResolver.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/util/VariableResolver.java index 65a58c8e41..abed7a2f67 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/util/VariableResolver.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/common/util/VariableResolver.java @@ -48,7 +48,11 @@ public static String resolve(String param, Map variableMap) { String paramName = paramTemplate.substring(2, paramTemplate.length() - 1); int varStart = m.start(); resolvedParam.append(param, notVarPartStart, varStart); - resolvedParam.append(variableMap.getOrDefault(paramName, paramTemplate)); + if (variableMap.containsKey(paramName)) { + resolvedParam.append(variableMap.get(paramName) == null ? "" : variableMap.get(paramName)); + } else { + resolvedParam.append(paramTemplate); + } notVarPartStart = m.end(); hasMatched = true; } @@ -59,33 +63,4 @@ public static String resolve(String param, Map variableMap) { } return resolvedParam.toString(); } - - private static String escape(String paramValues) { - String escapedStr = paramValues; - if (paramValues.contains("$")) { // 针对替换字符串中包含了$ 但没有转义的问题,会导致m.appendReplacement方法异常 - Pattern compile = Pattern.compile("[^\\\\]?\\$"); - Matcher matcher = compile.matcher(paramValues); - StringBuffer paramValuesBuf = new StringBuffer(); - while (matcher.find()) { - matcher.appendReplacement(paramValuesBuf, matcher.group().replace("$", "\\\\\\$")); - } - if (paramValuesBuf.length() > 0) { - matcher.appendTail(paramValuesBuf); - escapedStr = paramValuesBuf.toString(); - } - } - if (paramValues.contains("\\")) { // 针对替换字符串中包含了\ 但没有转义的问题,会导致m.appendReplacement方法异常 - Pattern compile = Pattern.compile("[^\\\\]?\\\\"); - Matcher matcher = compile.matcher(paramValues); - StringBuffer paramValuesBuf = new StringBuffer(); - while (matcher.find()) { - matcher.appendReplacement(paramValuesBuf, matcher.group().replace("\\", "\\\\\\\\")); - } - if (paramValuesBuf.length() > 0) { - matcher.appendTail(paramValuesBuf); - escapedStr = paramValuesBuf.toString(); - } - } - return escapedStr; - } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/JobExecuteConfig.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/JobExecuteConfig.java index 02d0ddbeed..56eb7fcb4d 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/JobExecuteConfig.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/config/JobExecuteConfig.java @@ -67,4 +67,7 @@ public class JobExecuteConfig { */ @Value("${job.encrypt.password}") private String encryptPassword; + + @Value("${job.execute.file-tasks-max:1000000}") + private Integer fileTasksMax; } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/StatisticsDAOImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/StatisticsDAOImpl.java index d5d657ae26..e1fe942797 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/StatisticsDAOImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/StatisticsDAOImpl.java @@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import lombok.var; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.conf.ParamType; import org.jooq.generated.tables.Statistics; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/TaskInstanceDAOImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/TaskInstanceDAOImpl.java index 063d932d90..9fd452d42b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/TaskInstanceDAOImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/dao/impl/TaskInstanceDAOImpl.java @@ -33,9 +33,18 @@ import com.tencent.bk.job.execute.dao.TaskInstanceDAO; import com.tencent.bk.job.execute.model.TaskInstanceDTO; import com.tencent.bk.job.execute.model.TaskInstanceQuery; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.jooq.*; +import org.jooq.Condition; +import org.jooq.DSLContext; +import org.jooq.Record; +import org.jooq.Record1; +import org.jooq.Result; +import org.jooq.SelectSeekStep1; +import org.jooq.SortField; +import org.jooq.UpdateSetMoreStep; +import org.jooq.conf.ParamType; import org.jooq.generated.tables.GseTaskIpLog; import org.jooq.generated.tables.StepInstance; import org.jooq.generated.tables.TaskInstance; @@ -52,6 +61,7 @@ /** * 作业执行实例DAO */ +@Slf4j @Repository public class TaskInstanceDAOImpl implements TaskInstanceDAO { private static final TaskInstance TABLE = TaskInstance.TASK_INSTANCE; @@ -360,9 +370,12 @@ public List listLatestCronTaskInstance(long appId, Long cronTas TABLE.IS_DEBUG_TASK, TABLE.APP_ID, TABLE.NAME, TABLE.OPERATOR, TABLE.STARTUP_MODE, TABLE.CURRENT_STEP_ID, TABLE.STATUS, TABLE.START_TIME, TABLE.END_TIME, TABLE.TOTAL_TIME, TABLE.CREATE_TIME, TABLE.CALLBACK_URL, TABLE.TYPE, TABLE.APP_CODE) - .from(TABLE.useIndex("idx_app_cron")) + .from(TABLE) .where(conditions) .orderBy(TABLE.CREATE_TIME.desc()); + if(log.isDebugEnabled()) { + log.debug("SQL=", select.getSQL(ParamType.INLINED)); + } Result result; if (limit != null && limit > 0) { result = select.limit(0, limit.intValue()).fetch(); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/AbstractGseTaskExecutor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/AbstractGseTaskExecutor.java index d2a2866732..8244043cff 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/AbstractGseTaskExecutor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/AbstractGseTaskExecutor.java @@ -43,7 +43,7 @@ import com.tencent.bk.job.execute.service.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.util.StopWatch; import java.util.*; @@ -263,7 +263,7 @@ protected GseTaskIpLogDTO buildGseTaskIpLog(String cloudAreaIdAndIp, IpStatus st protected Map buildReferenceGlobalVarValueMap(StepInstanceVariableValuesDTO stepInputVariables) { Map globalVarValueMap = new HashMap<>(); - if (CollectionUtils.isEmpty(stepInputVariables.getGlobalParams())) { + if (stepInputVariables == null || CollectionUtils.isEmpty(stepInputVariables.getGlobalParams())) { return globalVarValueMap; } stepInputVariables.getGlobalParams().forEach(globalParam -> { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileTaskExecutor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileTaskExecutor.java index d0518a526f..f1d78a1a96 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileTaskExecutor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/FileTaskExecutor.java @@ -40,17 +40,32 @@ import com.tencent.bk.job.execute.engine.model.GseTaskResponse; import com.tencent.bk.job.execute.engine.model.JobFile; import com.tencent.bk.job.execute.engine.result.FileResultHandleTask; -import com.tencent.bk.job.execute.engine.util.*; -import com.tencent.bk.job.execute.model.*; +import com.tencent.bk.job.execute.engine.util.FilePathUtils; +import com.tencent.bk.job.execute.engine.util.IpHelper; +import com.tencent.bk.job.execute.engine.util.JobSrcFileUtils; +import com.tencent.bk.job.execute.engine.util.MacroUtil; +import com.tencent.bk.job.execute.engine.util.NFSUtils; +import com.tencent.bk.job.execute.model.AccountDTO; +import com.tencent.bk.job.execute.model.FileDetailDTO; +import com.tencent.bk.job.execute.model.FileSourceDTO; +import com.tencent.bk.job.execute.model.GseTaskIpLogDTO; +import com.tencent.bk.job.execute.model.GseTaskLogDTO; +import com.tencent.bk.job.execute.model.StepInstanceDTO; +import com.tencent.bk.job.execute.model.TaskInstanceDTO; import com.tencent.bk.job.execute.monitor.metrics.GseTasksExceptionCounter; import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * GSE-文件分发执行 @@ -206,17 +221,17 @@ private void setAccountInfoForSourceFiles(Set sendFiles) { private void saveInitialFileTaskLogs(Map sourceDestPathMap) { try { log.debug("[{}] SourceDestPathMap: {}", stepInstanceId, sourceDestPathMap); - Map logs = new HashMap<>(); + Map logs = new HashMap<>(); for (JobFile file : sendFiles) { String fileSourceIp = file.isLocalUploadFile() ? IpHelper.fix1To0(localAgentIp) : file.getCloudAreaIdAndIp(); - ServiceLogDTO ipTaskLog = initServiceLogDTOIfAbsent(logs, stepInstanceId, executeCount, fileSourceIp); + ServiceIpLogDTO ipTaskLog = initServiceLogDTOIfAbsent(logs, stepInstanceId, executeCount, fileSourceIp); ipTaskLog.addFileTaskLog(new ServiceFileTaskLogDTO(FileDistModeEnum.UPLOAD.getValue(), null, null, fileSourceIp, fileSourceIp, file.getStandardFilePath(), file.getDisplayFilePath(), "--", FileDistStatusEnum.WAITING.getValue(), FileDistStatusEnum.WAITING.getName(), "--", "--", null)); } for (String fileTargetIp : jobIpSet) { - ServiceLogDTO ipTaskLog = initServiceLogDTOIfAbsent(logs, stepInstanceId, executeCount, fileTargetIp); + ServiceIpLogDTO ipTaskLog = initServiceLogDTOIfAbsent(logs, stepInstanceId, executeCount, fileTargetIp); for (JobFile file : sendFiles) { String fileSourceIp = file.isLocalUploadFile() ? IpHelper.fix1To0(localAgentIp) : file.getCloudAreaIdAndIp(); @@ -234,11 +249,11 @@ private void saveInitialFileTaskLogs(Map sourceDestPathMap) { } } - private ServiceLogDTO initServiceLogDTOIfAbsent(Map logs, long stepInstanceId, - int executeCount, String ip) { - ServiceLogDTO ipTaskLog = logs.get(ip); + private ServiceIpLogDTO initServiceLogDTOIfAbsent(Map logs, long stepInstanceId, + int executeCount, String ip) { + ServiceIpLogDTO ipTaskLog = logs.get(ip); if (ipTaskLog == null) { - ipTaskLog = new ServiceLogDTO(); + ipTaskLog = new ServiceIpLogDTO(); ipTaskLog.setStepInstanceId(stepInstanceId); ipTaskLog.setIp(ip); ipTaskLog.setExecuteCount(executeCount); @@ -247,7 +262,7 @@ private ServiceLogDTO initServiceLogDTOIfAbsent(Map logs, return ipTaskLog; } - private void writeLogs(Map executionLogs) { + private void writeLogs(Map executionLogs) { log.debug("Write file task initial logs, executionLogs: {}", executionLogs); logService.writeFileLogs(taskInstance.getCreateTime(), new ArrayList<>(executionLogs.values())); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/SQLScriptTaskExecutor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/SQLScriptTaskExecutor.java index 676cb59070..fdf9dc2128 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/SQLScriptTaskExecutor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/SQLScriptTaskExecutor.java @@ -31,7 +31,6 @@ import com.tencent.bk.job.common.exception.ServiceException; import com.tencent.bk.job.common.util.Base64Util; import com.tencent.bk.job.common.util.crypto.AESUtils; -import com.tencent.bk.job.execute.engine.consts.GseConstants; import com.tencent.bk.job.execute.engine.gse.GseRequestUtils; import com.tencent.bk.job.execute.engine.model.RunSQLScriptFile; import com.tencent.bk.job.execute.engine.util.TimeoutUtils; @@ -43,7 +42,7 @@ import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.io.InputStream; import java.io.StringWriter; @@ -62,8 +61,8 @@ public class SQLScriptTaskExecutor extends ScriptTaskExecutor { static { try { log.info("Init sql template!"); - try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("sqltask" + - "/mysql_exec_template.sh")) { + try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream( + "sqltask/mysql_exec_template.sh")) { StringWriter stringWriter = new StringWriter(); if (stream != null) { IOUtils.copy(stream, stringWriter, StandardCharsets.UTF_8); @@ -74,8 +73,8 @@ public class SQLScriptTaskExecutor extends ScriptTaskExecutor { throw new RuntimeException("Init sql task shell failed"); } } - try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("sqltask" + - "/oracle_exec_template.sh")) { + try (InputStream stream = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("sqltask/oracle_exec_template.sh")) { StringWriter stringWriter = new StringWriter(); if (stream != null) { IOUtils.copy(stream, stringWriter, StandardCharsets.UTF_8); @@ -86,8 +85,8 @@ public class SQLScriptTaskExecutor extends ScriptTaskExecutor { throw new RuntimeException("Init sql task shell failed"); } } - try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("sqltask" + - "/db2_exec_template.sh")) { + try (InputStream stream = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("sqltask/db2_exec_template.sh")) { StringWriter stringWriter = new StringWriter(); if (stream != null) { IOUtils.copy(stream, stringWriter, StandardCharsets.UTF_8); @@ -120,8 +119,7 @@ public SQLScriptTaskExecutor(String requestId, GseTasksExceptionCounter gseTasks protected api_script_request getScriptRequest(StepInstanceDTO stepInstance) { String sqlScriptContent = stepInstance.getScriptContent(); - String fileNamePre = (stepInstance.getStepId() > 0 ? "stepId_" + stepInstance.getStepId() : - "stepInstanceId_" + stepInstance.getId()); + String fileNamePre = buildScriptFileNamePrefix(stepInstance); String sqlScriptFileName = fileNamePre + ScriptTypeEnum.getExtByValue(stepInstance.getScriptType()); String publicScriptContent = sqlMap.get(stepInstance.getDbType()); @@ -130,7 +128,7 @@ protected api_script_request getScriptRequest(StepInstanceDTO stepInstance) { RunSQLScriptFile param = new RunSQLScriptFile(); param.setTimeout(timeout); - param.setDownloadPath(GseConstants.SCRIPT_PATH); + param.setDownloadPath(scriptFilePath); param.setPublicScriptContent(publicScriptContent); param.setPublicScriptName(publicScriptName); param.setSqlScriptContent(sqlScriptContent); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptTaskExecutor.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptTaskExecutor.java index 430067a41d..0aeeec2f94 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptTaskExecutor.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/executor/ScriptTaskExecutor.java @@ -45,7 +45,12 @@ import com.tencent.bk.job.execute.engine.variable.VariableResolveContext; import com.tencent.bk.job.execute.engine.variable.VariableResolveResult; import com.tencent.bk.job.execute.engine.variable.VariableResolveUtils; -import com.tencent.bk.job.execute.model.*; +import com.tencent.bk.job.execute.model.AccountDTO; +import com.tencent.bk.job.execute.model.GseTaskLogDTO; +import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; +import com.tencent.bk.job.execute.model.StepInstanceDTO; +import com.tencent.bk.job.execute.model.TaskInstanceDTO; +import com.tencent.bk.job.execute.model.VariableValueDTO; import com.tencent.bk.job.execute.monitor.metrics.GseTasksExceptionCounter; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import lombok.extern.slf4j.Slf4j; @@ -66,9 +71,9 @@ public class ScriptTaskExecutor extends AbstractGseTaskExecutor { /** * 下发到gse的脚本文件根目录 */ - private String scriptFilePath; + protected final String scriptFilePath; - private JobBuildInVariableResolver jobBuildInVariableResolver; + private final JobBuildInVariableResolver jobBuildInVariableResolver; /** * ScriptTaskExecutor Constructor @@ -120,7 +125,7 @@ protected api_script_request getScriptRequest(StepInstanceDTO stepInstance) { List agentList = GseRequestUtils.buildAgentList(jobIpSet, accountInfo.getAccount(), accountInfo.getPassword()); api_script_request request = GseRequestUtils.buildScriptRequest(agentList, scriptContent, scriptFileName, - GseConstants.SCRIPT_PATH, resolvedScriptParam, timeout); + scriptFilePath, resolvedScriptParam, timeout); request.setM_caller(buildTraceInfoMap()); return request; } @@ -130,11 +135,9 @@ private String buildScriptFileName(StepInstanceDTO stepInstance) { return scriptFileNamePrefix + ScriptTypeEnum.getExtByValue(stepInstance.getScriptType()); } - private String buildScriptFileNamePrefix(StepInstanceDTO stepInstance) { - StringBuilder sb = new StringBuilder("task_"); - sb.append(stepInstance.getTaskInstanceId()); - sb.append("_").append(stepInstance.getId()); - return sb.toString(); + public String buildScriptFileNamePrefix(StepInstanceDTO stepInstance) { + return "task_" + stepInstance.getTaskInstanceId() + + "_" + stepInstance.getId(); } /** @@ -234,8 +237,8 @@ private api_script_request buildRequestWithConstParamOnly(StepInstanceDTO stepIn //声明初始变量的脚本 String declareVarFileName = "stepInstanceId_" + stepInstance.getId() + "_params_input.env"; - String delcareVarScriptContent = buildConstVarDeclareScript(taskVars, importVariables); - builder.addScriptFile(scriptFilePath, declareVarFileName, delcareVarScriptContent); + String declareVarScriptContent = buildConstVarDeclareScript(taskVars, importVariables); + builder.addScriptFile(scriptFilePath, declareVarFileName, declareVarScriptContent); //封装用户脚本 String wrapperScriptFileName = scriptFileNamePrefix + "_wrapper.sh"; @@ -324,9 +327,8 @@ private void appendImportVariablesDeclareScript(StringBuffer sb, List { - appendStringVariableDeclareScript(sb, variableName, variableValue); - }); + variableValues.forEach((variableName, variableValue) -> + appendStringVariableDeclareScript(sb, variableName, variableValue)); } private String escapeSingleQuote(String value) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/gse/ScriptRequestBuilder.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/gse/ScriptRequestBuilder.java index d36ff84be2..f4f7986a63 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/gse/ScriptRequestBuilder.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/gse/ScriptRequestBuilder.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.execute.engine.gse; import com.tencent.bk.gse.taskapi.*; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepListener.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepListener.java index 8bc34c698e..91d3e2e55f 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepListener.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepListener.java @@ -35,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; -import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Component; @@ -60,12 +59,10 @@ public GseStepListener(GseTaskManager gseTaskManager, } @StreamListener(GseTaskProcessor.INPUT) - public void handleMessage(@Payload StepControlMessage gseStepControlMessage, - @Header("X-B3-TraceId") String traceId, @Header("X-B3-SpanId") String spanId) { - log.info("Receive gse step control message, stepInstanceId={}, action={}, requestId={}, msgSendTime={}, " + - "traceId={}, spanId={}", gseStepControlMessage.getStepInstanceId(), - gseStepControlMessage.getAction(), gseStepControlMessage.getRequestId(), gseStepControlMessage.getTime(), - traceId, spanId); + public void handleMessage(@Payload StepControlMessage gseStepControlMessage) { + log.info("Receive gse step control message, stepInstanceId={}, action={}, requestId={}, msgSendTime={}", + gseStepControlMessage.getStepInstanceId(), gseStepControlMessage.getAction(), + gseStepControlMessage.getRequestId(), gseStepControlMessage.getTime()); long stepInstanceId = gseStepControlMessage.getStepInstanceId(); String requestId = gseStepControlMessage.getRequestId(); try { @@ -81,14 +78,14 @@ public void handleMessage(@Payload StepControlMessage gseStepControlMessage, } else { log.error("Error gse step control action:{}", action); } - } catch (Exception e) { + } catch (Throwable e) { String errorMsg = "Handling gse step control message error,stepInstanceId:" + stepInstanceId; - log.warn(errorMsg, e); + log.error(errorMsg, e); handleException(e); } } - private void handleException(Exception e) throws MessageHandleException { + private void handleException(Throwable e) throws MessageHandleException { // 服务关闭,消息被拒绝,重新入队列 if (e instanceof MessageHandlerUnavailableException) { throw (MessageHandlerUnavailableException) e; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/StepListener.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/StepListener.java index 417c9de15b..46035ad381 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/StepListener.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/StepListener.java @@ -38,7 +38,7 @@ import com.tencent.bk.job.manage.common.consts.notify.ResourceTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/TaskListener.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/TaskListener.java index 79456cec90..0e89677f48 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/TaskListener.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/TaskListener.java @@ -44,7 +44,7 @@ import com.tencent.bk.job.manage.common.consts.notify.ExecuteStatusEnum; import com.tencent.bk.job.manage.common.consts.notify.ResourceTypeEnum; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java index 55f7a930d9..3a12a4f5a6 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/FileResultHandleTask.java @@ -39,7 +39,12 @@ import com.tencent.bk.job.execute.engine.gse.GseRequestUtils; import com.tencent.bk.job.execute.engine.gse.model.CopyFileRsp; import com.tencent.bk.job.execute.engine.gse.model.GSEFileTaskResult; -import com.tencent.bk.job.execute.engine.model.*; +import com.tencent.bk.job.execute.engine.model.FileTaskLog; +import com.tencent.bk.job.execute.engine.model.GseLog; +import com.tencent.bk.job.execute.engine.model.GseLogBatchPullResult; +import com.tencent.bk.job.execute.engine.model.GseTaskExecuteResult; +import com.tencent.bk.job.execute.engine.model.JobFile; +import com.tencent.bk.job.execute.engine.model.TaskVariablesAnalyzeResult; import com.tencent.bk.job.execute.engine.util.FilePathUtils; import com.tencent.bk.job.execute.engine.util.NFSUtils; import com.tencent.bk.job.execute.engine.util.Utils; @@ -49,13 +54,18 @@ import com.tencent.bk.job.execute.model.StepInstanceDTO; import com.tencent.bk.job.execute.model.TaskInstanceDTO; import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import java.text.DecimalFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.StringJoiner; import java.util.stream.Collectors; /** @@ -230,7 +240,7 @@ GseTaskExecuteResult analyseGseTaskLog(GseLog taskDetail) { long currentTime = DateUtils.currentTimeMillis(); Set> ipResults = taskDetail.getGseLog().getResult().entrySet(); // 执行日志, Map - Map executionLogs = new HashMap<>(); + Map executionLogs = new HashMap<>(); for (Map.Entry ipResult : ipResults) { CopyFileRsp copyFileRsp = parseCopyFileRspFromGSELog(ipResult); @@ -283,7 +293,7 @@ GseTaskExecuteResult analyseGseTaskLog(GseLog taskDetail) { return analyseExecuteResult(); } - private void analyseFileResult(String cloudIp, CopyFileRsp copyFileRsp, Map executionLogs, + private void analyseFileResult(String cloudIp, CopyFileRsp copyFileRsp, Map executionLogs, boolean isDownloadLog) { GseTaskIpLogDTO ipLog = this.ipLogMap.get(cloudIp); if (ipLog.getStartTime() == null) { @@ -555,7 +565,7 @@ private String guessFileSourceCloudIp(String intIp) { } - private void dealIpTaskFail(CopyFileRsp copyFileRsp, Map executionLogs) { + private void dealIpTaskFail(CopyFileRsp copyFileRsp, Map executionLogs) { GSEFileTaskResult taskResult = copyFileRsp.getGseFileTaskResult(); boolean isDownloadError = taskResult.isDownloadMode(); // 被该错误影响的ip @@ -651,7 +661,7 @@ private String concat(String... strArgs) { return sj.toString(); } - private void dealUploadFail(CopyFileRsp copyFileRsp, Map executionLogs, + private void dealUploadFail(CopyFileRsp copyFileRsp, Map executionLogs, Set affectIps) { GSEFileTaskResult taskResult = copyFileRsp.getGseFileTaskResult(); String sourceCloudIp = taskResult.getSourceCloudIp(); @@ -753,7 +763,7 @@ private void dealUploadIpFinished(String sourceCloudIp) { /* * 从执行结果生成执行日志 */ - private void parseExecutionLog(CopyFileRsp copyFileRsp, Map executionLogs) { + private void parseExecutionLog(CopyFileRsp copyFileRsp, Map executionLogs) { GSEFileTaskResult taskResult = copyFileRsp.getGseFileTaskResult(); if (null != taskResult) { Integer mode = taskResult.getMode(); @@ -871,11 +881,11 @@ private String formatSpeed(int speed) { return formatter.format(speed); } - private void addFileTaskLog(Map executionLogs, String ip, + private void addFileTaskLog(Map executionLogs, String ip, ServiceFileTaskLogDTO fileTaskLog) { - ServiceLogDTO ipExecutionLog = executionLogs.get(ip); + ServiceIpLogDTO ipExecutionLog = executionLogs.get(ip); if (ipExecutionLog == null) { - ipExecutionLog = new ServiceLogDTO(); + ipExecutionLog = new ServiceIpLogDTO(); ipExecutionLog.setStepInstanceId(stepInstanceId); ipExecutionLog.setIp(ip); ipExecutionLog.setExecuteCount(stepInstance.getExecuteCount()); @@ -884,7 +894,7 @@ private void addFileTaskLog(Map executionLogs, String ip, ipExecutionLog.addFileTaskLog(fileTaskLog); } - private void writeFileTaskLogContent(Map executionLogs) { + private void writeFileTaskLogContent(Map executionLogs) { executionLogs.forEach((ip, executionLog) -> { logService.writeFileLogWithTimestamp(taskInstance.getCreateTime(), stepInstanceId, stepInstance.getExecuteCount(), ip, executionLog, System.currentTimeMillis()); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ha/ResultHandleTaskKeepaliveManager.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ha/ResultHandleTaskKeepaliveManager.java index 071a381a2e..456fe06fad 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ha/ResultHandleTaskKeepaliveManager.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/ha/ResultHandleTaskKeepaliveManager.java @@ -26,7 +26,11 @@ import com.tencent.bk.job.common.util.ThreadUtils; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -35,7 +39,11 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingBatchResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingBatchResultHandleTask.java index ecb12886f8..8110213ddf 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingBatchResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingBatchResultHandleTask.java @@ -41,9 +41,9 @@ import com.tencent.bk.job.file_gateway.model.req.inner.StopBatchTaskReq; import com.tencent.bk.job.file_gateway.model.resp.inner.BatchTaskStatusDTO; import com.tencent.bk.job.file_gateway.model.resp.inner.FileSourceTaskStatusDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -159,7 +159,7 @@ public BatchTaskStatusDTO getFileSourceBatchTaskResults(StepInstanceDTO stepInst int maxLogSize = 0; // 写日志 for (FileSourceTaskStatusDTO fileSourceTaskStatusDTO : fileSourceTaskStatusInfoList) { - List logList = fileSourceTaskStatusDTO.getLogList(); + List logList = fileSourceTaskStatusDTO.getLogList(); if (logList != null && !logList.isEmpty()) { writeLogs(stepInstance, logList); if (logList.size() > maxLogSize) { @@ -190,10 +190,10 @@ public BatchTaskStatusDTO getFileSourceBatchTaskResults(StepInstanceDTO stepInst return batchTaskStatusDTO; } - private void writeLogs(StepInstanceDTO stepInstance, List logDTOList) { - for (ServiceLogDTO serviceLogDTO : logDTOList) { + private void writeLogs(StepInstanceDTO stepInstance, List logDTOList) { + for (ServiceIpLogDTO serviceIpLogDTO : logDTOList) { logService.writeFileLogWithTimestamp(stepInstance.getCreateTime(), stepInstance.getId(), - stepInstance.getExecuteCount(), serviceLogDTO.getIp(), serviceLogDTO, System.currentTimeMillis()); + stepInstance.getExecuteCount(), serviceIpLogDTO.getIp(), serviceIpLogDTO, System.currentTimeMillis()); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingResultHandleTask.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingResultHandleTask.java index 88e76a2beb..5f962af365 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingResultHandleTask.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/result/third/ThirdFilePullingResultHandleTask.java @@ -39,9 +39,9 @@ import com.tencent.bk.job.file_gateway.consts.TaskStatusEnum; import com.tencent.bk.job.file_gateway.model.req.inner.StopTaskReq; import com.tencent.bk.job.file_gateway.model.resp.inner.FileSourceTaskStatusDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -157,7 +157,7 @@ public List getFileSourceTaskResults(StepInstanceDTO st log.debug("resp={}", resp); FileSourceTaskStatusDTO fileSourceTaskStatusDTO = resp.getData(); // 写日志 - List logList = fileSourceTaskStatusDTO.getLogList(); + List logList = fileSourceTaskStatusDTO.getLogList(); if (logList != null && !logList.isEmpty()) { writeLogs(stepInstance, logList); logStart += logList.size(); @@ -192,10 +192,10 @@ public List getFileSourceTaskResults(StepInstanceDTO st return resultList; } - private void writeLogs(StepInstanceDTO stepInstance, List logDTOList) { - for (ServiceLogDTO serviceLogDTO : logDTOList) { + private void writeLogs(StepInstanceDTO stepInstance, List logDTOList) { + for (ServiceIpLogDTO serviceIpLogDTO : logDTOList) { logService.writeFileLogWithTimestamp(stepInstance.getCreateTime(), stepInstance.getId(), - stepInstance.getExecuteCount(), serviceLogDTO.getIp(), serviceLogDTO, System.currentTimeMillis()); + stepInstance.getExecuteCount(), serviceIpLogDTO.getIp(), serviceIpLogDTO, System.currentTimeMillis()); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/third/FileSourceBatchTaskManagerImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/third/FileSourceBatchTaskManagerImpl.java index 076613dbbc..7785cefa45 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/third/FileSourceBatchTaskManagerImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/third/FileSourceBatchTaskManagerImpl.java @@ -45,7 +45,7 @@ import com.tencent.bk.job.file_gateway.model.resp.inner.TaskInfoDTO; import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/MacroUtil.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/MacroUtil.java index 2092411fdd..e141d72f68 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/MacroUtil.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/util/MacroUtil.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.execute.engine.gse.Strftime; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.time.ZoneId; import java.time.temporal.ChronoUnit; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/converter/TaskInstanceConverter.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/converter/TaskInstanceConverter.java index 71a8532482..de68a5be7b 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/converter/TaskInstanceConverter.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/model/converter/TaskInstanceConverter.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.execute.model.converter; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.execute.common.constants.RunStatusEnum; import com.tencent.bk.job.execute.common.constants.TaskStartupModeEnum; import com.tencent.bk.job.execute.common.constants.TaskTypeEnum; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/LogService.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/LogService.java index 58b9213f01..b036225931 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/LogService.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/LogService.java @@ -29,7 +29,8 @@ import com.tencent.bk.job.execute.model.FileIpLogContent; import com.tencent.bk.job.execute.model.ScriptIpLogContent; import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogsDTO; import com.tencent.bk.job.logsvr.model.service.ServiceScriptLogDTO; import java.util.List; @@ -177,6 +178,18 @@ List getFileLogContentByTaskIds(long stepInstanceId, int List batchGetFileSourceIpLogContent(long stepInstanceId, int executeCount) throws ServiceException; + /** + * 获取文件任务文件源日志 + * + * @param stepInstanceId 步骤实例 ID + * @param executeCount 执行次数 + * @param ips 服务器列表 + * @return 日志内容 + * @throws ServiceException + */ + ServiceIpLogsDTO batchGetFileIpLogContent(long stepInstanceId, + int executeCount, List ips) throws ServiceException; + /** * 根据关键字获取对应的ip * @@ -200,7 +213,7 @@ List batchGetFileSourceIpLogContent(long stepInstanceId, * @throws ServiceException 写入失败,返回ServiceException */ void writeFileLogWithTimestamp(long jobCreateTime, long stepInstanceId, int executeCount, - String cloudAreaIdAndIp, ServiceLogDTO executionLog, + String cloudAreaIdAndIp, ServiceIpLogDTO executionLog, Long logTimeInMillSeconds) throws ServiceException; /** @@ -209,6 +222,6 @@ void writeFileLogWithTimestamp(long jobCreateTime, long stepInstanceId, int exec * @param jobCreateTime 任务创建时间 * @param fileLogs 文件任务执行日志 */ - void writeFileLogs(long jobCreateTime, List fileLogs); + void writeFileLogs(long jobCreateTime, List fileLogs); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AccountServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AccountServiceImpl.java index 5f42723681..733c17472d 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AccountServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AccountServiceImpl.java @@ -36,7 +36,7 @@ import com.tencent.bk.job.manage.common.consts.account.AccountTypeEnum; import com.tencent.bk.job.manage.model.inner.ServiceAccountDTO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java index b91a5dec01..0c78259896 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/AgentServiceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.execute.engine.consts.Consts; import com.tencent.bk.job.execute.service.AgentService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/DangerousScriptCheckServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/DangerousScriptCheckServiceImpl.java index 6f003cdfa1..8490214781 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/DangerousScriptCheckServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/DangerousScriptCheckServiceImpl.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.execute.service.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.ApplicationInfoDTO; import com.tencent.bk.job.execute.client.ScriptCheckResourceClient; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java index e680230ac5..eb3bbdc8bc 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/LogServiceImpl.java @@ -28,7 +28,6 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.common.util.date.DateUtils; -import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.execute.client.LogServiceResourceClient; import com.tencent.bk.job.execute.common.constants.FileDistModeEnum; import com.tencent.bk.job.execute.common.constants.FileDistStatusEnum; @@ -41,7 +40,14 @@ import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; import com.tencent.bk.job.execute.service.LogService; import com.tencent.bk.job.logsvr.consts.LogTypeEnum; -import com.tencent.bk.job.logsvr.model.service.*; +import com.tencent.bk.job.logsvr.model.service.BatchSaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.FileLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.SaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.ScriptLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogsDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceScriptLogDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -96,14 +102,14 @@ public void batchWriteJobSystemScriptLog(long jobCreateTime, long stepInstanceId request.setJobCreateDate(DateUtils.formatUnixTimestamp(jobCreateTime, ChronoUnit.MILLIS, "yyyy_MM_dd", ZoneId.of("UTC"))); request.setLogType(LogTypeEnum.SCRIPT.getValue()); - List logs = new ArrayList<>(ipsAndOffset.size()); + List logs = new ArrayList<>(ipsAndOffset.size()); ipsAndOffset.forEach((cloudIp, offset) -> logs.add(buildServiceLogDTO(stepInstanceId, executeCount, new ServiceScriptLogDTO(cloudIp, offset, content)))); request.setLogs(logs); ServiceResponse resp = logServiceResourceClient.saveLogs(request); if (!resp.isSuccess()) { - log.warn("Batch write system script log content fail, stepInstanceId:{}, executeCount:{}", stepInstanceId + log.error("Batch write system script log content fail, stepInstanceId:{}, executeCount:{}", stepInstanceId , executeCount); throw new ServiceException(resp.getCode()); } @@ -142,7 +148,7 @@ public void writeScriptLog(String jobCreateDate, long stepInstanceId, int execut request.setLogType(LogTypeEnum.SCRIPT.getValue()); ServiceResponse resp = logServiceResourceClient.saveLog(request); if (!resp.isSuccess()) { - log.warn("Write log content fail, stepInstanceId:{}, executeCount:{}, ip:{}", stepInstanceId, executeCount, + log.error("Write log content fail, stepInstanceId:{}, executeCount:{}, ip:{}", stepInstanceId, executeCount, scriptLog.getCloudIp()); throw new ServiceException(resp.getCode()); } @@ -157,18 +163,18 @@ public void batchWriteScriptLog(String jobCreateDate, long stepInstanceId, int e BatchSaveLogRequest request = new BatchSaveLogRequest(); request.setJobCreateDate(jobCreateDate); request.setLogType(LogTypeEnum.SCRIPT.getValue()); - List logs = scriptLogs.stream().map(scriptLog -> buildServiceLogDTO(stepInstanceId, + List logs = scriptLogs.stream().map(scriptLog -> buildServiceLogDTO(stepInstanceId, executeCount, scriptLog)).collect(Collectors.toList()); request.setLogs(logs); ServiceResponse resp = logServiceResourceClient.saveLogs(request); if (!resp.isSuccess()) { - log.warn("Batch write log content fail, stepInstanceId:{}, executeCount:{}", stepInstanceId, executeCount); + log.error("Batch write log content fail, stepInstanceId:{}, executeCount:{}", stepInstanceId, executeCount); throw new ServiceException(resp.getCode()); } } - private ServiceLogDTO buildServiceLogDTO(long stepInstanceId, int executeCount, ServiceScriptLogDTO scriptLog) { - ServiceLogDTO logDTO = new ServiceLogDTO(); + private ServiceIpLogDTO buildServiceLogDTO(long stepInstanceId, int executeCount, ServiceScriptLogDTO scriptLog) { + ServiceIpLogDTO logDTO = new ServiceIpLogDTO(); logDTO.setStepInstanceId(stepInstanceId); logDTO.setExecuteCount(executeCount); logDTO.setIp(scriptLog.getCloudIp()); @@ -191,18 +197,18 @@ public ScriptIpLogContent getScriptIpLogContent(long stepInstanceId, int execute } String taskCreateDateStr = DateUtils.formatUnixTimestamp(stepInstance.getCreateTime(), ChronoUnit.MILLIS, "yyyy_MM_dd", ZoneId.of("UTC")); - ServiceResponse resp = logServiceResourceClient.getScriptIpLogContent(stepInstanceId, + ServiceResponse resp = logServiceResourceClient.getScriptIpLogContent(stepInstanceId, actualExecuteCount, ip.convertToStrIp(), taskCreateDateStr); if (!resp.isSuccess()) { - log.warn("Get script log content by ip error, stepInstanceId={}, executeCount={}, ip={}", stepInstanceId, + log.error("Get script log content by ip error, stepInstanceId={}, executeCount={}, ip={}", stepInstanceId, actualExecuteCount, ip); throw new ServiceException(resp.getCode(), resp.getErrorMsg()); } return convertToScriptIpLogContent(resp.getData(), gseTaskIpLog); } - private ScriptIpLogContent convertToScriptIpLogContent(ServiceLogDTO logDTO, GseTaskIpLogDTO gseTaskIpLog) { + private ScriptIpLogContent convertToScriptIpLogContent(ServiceIpLogDTO logDTO, GseTaskIpLogDTO gseTaskIpLog) { if (logDTO == null) { return null; } @@ -221,10 +227,10 @@ public List batchGetScriptIpLogContent(String jobCreateDateS ScriptLogQueryRequest query = new ScriptLogQueryRequest(); query.setIps(ips.stream().map(IpDTO::convertToStrIp).collect(Collectors.toList())); - ServiceResponse> resp = + ServiceResponse> resp = logServiceResourceClient.batchGetScriptLogContent(stepInstanceId, executeCount, jobCreateDateStr, query); if (!resp.isSuccess()) { - log.warn("Get script log content by ips error, stepInstanceId={}, executeCount={}, ips={}", stepInstanceId, + log.error("Get script log content by ips error, stepInstanceId={}, executeCount={}, ips={}", stepInstanceId, executeCount, ips); throw new ServiceException(resp.getCode(), resp.getErrorMsg()); } @@ -256,11 +262,11 @@ public FileIpLogContent getFileIpLogContent(long stepInstanceId, int executeCoun String taskCreateDateStr = DateUtils.formatUnixTimestamp(stepInstance.getCreateTime(), ChronoUnit.MILLIS, "yyyy_MM_dd", ZoneId.of("UTC")); - ServiceResponse resp = logServiceResourceClient.getFileIpLogContent(stepInstanceId, + ServiceResponse resp = logServiceResourceClient.getFileIpLogContent(stepInstanceId, actualExecuteCount, ip.convertToStrIp(), taskCreateDateStr, mode); if (!resp.isSuccess()) { - log.info("Get file log content by ip error, stepInstanceId={}, executeCount={}, ip={}", stepInstanceId, + log.error("Get file log content by ip error, stepInstanceId={}, executeCount={}, ip={}", stepInstanceId, actualExecuteCount, ip); throw new ServiceException(resp.getCode(), resp.getErrorMsg()); } @@ -293,11 +299,11 @@ public List getFileLogContentByTaskIds(long stepInstanceI StepInstanceBaseDTO stepInstance = stepInstanceDAO.getStepInstanceBase(stepInstanceId); String taskCreateDateStr = DateUtils.formatUnixTimestamp(stepInstance.getCreateTime(), ChronoUnit.MILLIS, "yyyy_MM_dd", ZoneId.of("UTC")); - ServiceResponse resp = logServiceResourceClient.getFileLogContentListByTaskIds(stepInstanceId, + ServiceResponse resp = logServiceResourceClient.getFileLogContentListByTaskIds(stepInstanceId, executeCount, taskCreateDateStr, taskIds); if (!resp.isSuccess()) { - log.info("Get file log content by ids error, stepInstanceId={}, executeCount={}, taskIds={}", + log.error("Get file log content by ids error, stepInstanceId={}, executeCount={}, taskIds={}", stepInstanceId, executeCount, taskIds); throw new ServiceException(resp.getCode(), resp.getErrorMsg()); } @@ -316,13 +322,33 @@ public List batchGetFileSourceIpLogContent(long stepInsta ServiceResponse> resp = logServiceResourceClient.getFileLogContent(stepInstanceId, executeCount, taskCreateDateStr, FileDistModeEnum.UPLOAD.getValue(), null); if (!resp.isSuccess()) { - log.info("Get file source log content error, stepInstanceId={}, executeCount={}", stepInstanceId, + log.error("Get file source log content error, stepInstanceId={}, executeCount={}", stepInstanceId, executeCount); return Collections.emptyList(); } return resp.getData(); } + @Override + public ServiceIpLogsDTO batchGetFileIpLogContent(long stepInstanceId, int executeCount, + List ips) throws ServiceException { + StepInstanceBaseDTO stepInstance = stepInstanceDAO.getStepInstanceBase(stepInstanceId); + String taskCreateDateStr = DateUtils.formatUnixTimestamp(stepInstance.getCreateTime(), ChronoUnit.MILLIS, + "yyyy_MM_dd", ZoneId.of("UTC")); + FileLogQueryRequest request = new FileLogQueryRequest(); + request.setStepInstanceId(stepInstanceId); + request.setExecuteCount(executeCount); + request.setJobCreateDate(taskCreateDateStr); + request.setIps(ips.stream().map(IpDTO::convertToStrIp).collect(Collectors.toList())); + + ServiceResponse resp = logServiceResourceClient.getFileLogContent(request); + if (!resp.isSuccess()) { + log.error("Get file log content error, request={}", request); + return null; + } + return resp.getData(); + } + @Override public List getIpsByContentKeyword(long stepInstanceId, int executeCount, String keyword) throws ServiceException { @@ -331,9 +357,9 @@ public List getIpsByContentKeyword(long stepInstanceId, int executeCount, "yyyy_MM_dd", ZoneId.of("UTC")); ServiceResponse> resp = logServiceResourceClient.getIpsByKeyword(stepInstanceId, executeCount, taskCreateDateStr, keyword); - log.info("getIpsByContentKeyword->resp:{}", JsonUtils.toJson(resp)); + if (!resp.isSuccess()) { - log.info("Search ips by keyword error, stepInstanceId={}, executeCount={}, keyword={}", stepInstanceId, + log.error("Search ips by keyword error, stepInstanceId={}, executeCount={}, keyword={}", stepInstanceId, executeCount, keyword); throw new ServiceException(resp.getCode(), resp.getErrorMsg()); } @@ -343,7 +369,7 @@ public List getIpsByContentKeyword(long stepInstanceId, int executeCount, @Override public void writeFileLogWithTimestamp(long jobCreateTime, long stepInstanceId, int executeCount, String cloudAreaIdAndIp, - ServiceLogDTO executionLog, + ServiceIpLogDTO executionLog, Long logTimeInMillSeconds) throws ServiceException { String logDateTime = "["; @@ -370,7 +396,7 @@ public void writeFileLogWithTimestamp(long jobCreateTime, long stepInstanceId, i } @Override - public void writeFileLogs(long jobCreateTime, List fileLogs) throws ServiceException { + public void writeFileLogs(long jobCreateTime, List fileLogs) throws ServiceException { BatchSaveLogRequest request = new BatchSaveLogRequest(); request.setJobCreateDate(DateUtils.formatUnixTimestamp(jobCreateTime, ChronoUnit.MILLIS, "yyyy_MM_dd", ZoneId.of("UTC"))); diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java index 26a95b34d7..cd0e128204 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/NotifyServiceImpl.java @@ -24,8 +24,8 @@ package com.tencent.bk.job.execute.service.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.dto.ApplicationInfoDTO; import com.tencent.bk.job.common.model.dto.UserRoleInfoDTO; import com.tencent.bk.job.common.util.JobContextUtil; @@ -51,7 +51,7 @@ import com.tencent.bk.job.manage.model.inner.ServiceTemplateNotificationDTO; import com.tencent.bk.job.manage.model.inner.ServiceTriggerTemplateNotificationDTO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceVariableValueServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceVariableValueServiceImpl.java index 5767aea071..1a2b8dbd62 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceVariableValueServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/StepInstanceVariableValueServiceImpl.java @@ -41,7 +41,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Service @@ -72,6 +76,7 @@ public List computeOutputVariableValuesForAllStep List stepInstanceList = taskInstanceService.listStepInstanceByTaskInstanceId(taskInstanceId); if (CollectionUtils.isEmpty(stepInstanceList)) { + log.info("Step instance is empty! taskInstanceId: {}", taskInstanceId); return resultStepInstanceVariableValuesList; } @@ -94,9 +99,10 @@ public List computeOutputVariableValuesForAllStep resultStepInstanceVariableValues.setExecuteCount(stepInstance.getExecuteCount()); List globalVarValues = new ArrayList<>(); List variableValuesForStep = stepInstanceVariableValuesList.stream() - .filter(stepInstanceVariableValues -> stepInstanceVariableValues.getStepInstanceId() == stepInstance.getId()) - .sorted(Comparator.comparingInt(StepInstanceVariableValuesDTO::getExecuteCount)).collect(Collectors.toList()); - log.info("variableValuesForStep->{}", variableValuesForStep); + .filter(stepInstanceVariableValues -> + stepInstanceVariableValues.getStepInstanceId() == stepInstance.getId()) + .sorted(Comparator.comparingInt(StepInstanceVariableValuesDTO::getExecuteCount)) + .collect(Collectors.toList()); variableValuesForStep.forEach(variableValues -> { if (CollectionUtils.isNotEmpty(variableValues.getGlobalParams())) { variableValues.getGlobalParams().forEach(globalVar -> globalVarValueMap.put(globalVar.getName(), diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java index 64cff851ce..309c81a994 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/TaskExecuteServiceImpl.java @@ -26,7 +26,6 @@ import brave.Tracing; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.tencent.bk.job.common.cc.model.CcInstanceDTO; import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.constant.ErrorCode; @@ -53,17 +52,53 @@ import com.tencent.bk.job.execute.constants.UserOperationEnum; import com.tencent.bk.job.execute.engine.TaskExecuteControlMsgSender; import com.tencent.bk.job.execute.engine.model.TaskVariableDTO; -import com.tencent.bk.job.execute.model.*; +import com.tencent.bk.job.execute.model.AccountDTO; +import com.tencent.bk.job.execute.model.DynamicServerGroupDTO; +import com.tencent.bk.job.execute.model.DynamicServerTopoNodeDTO; +import com.tencent.bk.job.execute.model.FileDetailDTO; +import com.tencent.bk.job.execute.model.FileSourceDTO; +import com.tencent.bk.job.execute.model.OperationLogDTO; +import com.tencent.bk.job.execute.model.ServersDTO; +import com.tencent.bk.job.execute.model.StepInstanceDTO; +import com.tencent.bk.job.execute.model.StepOperationDTO; +import com.tencent.bk.job.execute.model.TaskExecuteParam; +import com.tencent.bk.job.execute.model.TaskInfo; +import com.tencent.bk.job.execute.model.TaskInstanceDTO; import com.tencent.bk.job.execute.model.db.CacheAppDO; -import com.tencent.bk.job.execute.service.*; +import com.tencent.bk.job.execute.service.AccountService; +import com.tencent.bk.job.execute.service.ApplicationService; +import com.tencent.bk.job.execute.service.DangerousScriptCheckService; +import com.tencent.bk.job.execute.service.ExecuteAuthService; +import com.tencent.bk.job.execute.service.HostService; +import com.tencent.bk.job.execute.service.ScriptService; +import com.tencent.bk.job.execute.service.ServerService; +import com.tencent.bk.job.execute.service.TaskExecuteService; +import com.tencent.bk.job.execute.service.TaskInstanceService; +import com.tencent.bk.job.execute.service.TaskInstanceVariableService; +import com.tencent.bk.job.execute.service.TaskOperationLogService; +import com.tencent.bk.job.execute.service.TaskPlanService; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; +import com.tencent.bk.job.manage.common.consts.notify.JobRoleEnum; import com.tencent.bk.job.manage.common.consts.notify.ResourceTypeEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskFileTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum; import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; -import com.tencent.bk.job.manage.model.inner.*; +import com.tencent.bk.job.manage.model.inner.ServiceAccountDTO; +import com.tencent.bk.job.manage.model.inner.ServiceHostInfoDTO; +import com.tencent.bk.job.manage.model.inner.ServiceScriptCheckResultItemDTO; +import com.tencent.bk.job.manage.model.inner.ServiceScriptDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskApprovalStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskFileInfoDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskFileStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskHostNodeDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskNodeInfoDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskPlanDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskScriptStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskTargetDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskVariableDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -74,11 +109,28 @@ import org.springframework.util.StopWatch; import javax.validation.constraints.NotNull; -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import static com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum.*; +import static com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum.EXECUTE_SCRIPT; +import static com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum.EXECUTE_SQL; +import static com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum.MANUAL_CONFIRM; +import static com.tencent.bk.job.execute.common.constants.StepExecuteTypeEnum.SEND_FILE; @Service @Slf4j @@ -98,6 +150,7 @@ public class TaskExecuteServiceImpl implements TaskExecuteService { private final ExecuteAuthService executeAuthService; private final ExecutorService GET_HOSTS_BY_TOPO_EXECUTOR; private final DangerousScriptCheckService dangerousScriptCheckService; + private final JobExecuteConfig jobExecuteConfig; @Autowired public TaskExecuteServiceImpl(ApplicationService applicationService, @@ -132,6 +185,7 @@ public TaskExecuteServiceImpl(ApplicationService applicationService, this.GET_HOSTS_BY_TOPO_EXECUTOR = new TraceableExecutorService(new ThreadPoolExecutor(50, 100, 60, TimeUnit.SECONDS, new LinkedBlockingQueue()), tracing); this.dangerousScriptCheckService = dangerousScriptCheckService; + this.jobExecuteConfig = jobExecuteConfig; } private static List getHostsContainsNotAllowedAction(Map> hostBindActions, @@ -173,6 +227,11 @@ public Long createTaskInstanceFast(TaskInstanceDTO taskInstance, checkHosts(stepInstance, shouldIgnoreInvalidHost(taskInstance)); watch.stop(); + // 检查步骤约束 + watch.start("checkStepInstanceConstraint"); + checkStepInstanceConstraint(Collections.singletonList(stepInstance)); + watch.stop(); + watch.start("authFastExecute"); authFastExecute(taskInstance, stepInstance); watch.stop(); @@ -504,7 +563,6 @@ private void setServerInfoFastJob(StepInstanceDTO stepInstance) { if (stepInstance.getExecuteType() == TaskStepTypeEnum.FILE.getValue()) { List fileSources = stepInstance.getFileSourceList(); for (FileSourceDTO fileSource : fileSources) { - Integer fileSourceId = fileSource.getFileSourceId(); ServersDTO servers = fileSource.getServers(); if (servers != null && !fileSource.isLocalUpload()) { // 服务器文件的处理 @@ -743,25 +801,54 @@ private Collection checkHostsNotInApp(CacheAppDO cacheApp, Collection notInAppHosts = new ArrayList<>(); - // 对于其他业务下的主机,重新去CMDB查是否已转移到当前业务下 - hostsNotInCache.addAll(hostsInOtherApp); - // 普通业务,再次去cmdb确认该host if (isNormalApp) { - List notInCmdbAppHosts = hostService.checkHostsNotInAppByCmdb(cacheApp.getId(), hostsNotInCache); + // 普通业务,再次去cmdb实时检查 + List recheckedHosts = new ArrayList<>(); + recheckedHosts.addAll((hostsInOtherApp)); + recheckedHosts.addAll((hostsNotInCache)); + List notInCmdbAppHosts = hostService.checkHostsNotInAppByCmdb(cacheApp.getId(), recheckedHosts); log.info("Check host from cmdb, appId:{}, hostsNotInCache:{}, notInCmdbAppHosts:{}", cacheApp.getId(), - hostsNotInCache, notInCmdbAppHosts); + recheckedHosts, notInCmdbAppHosts); if (notInCmdbAppHosts != null && !notInCmdbAppHosts.isEmpty()) { notInAppHosts.addAll(notInCmdbAppHosts); } + } else { + notInAppHosts.addAll((hostsInOtherApp)); + notInAppHosts.addAll((hostsNotInCache)); } - if (notInAppHosts.isEmpty()) { - return Collections.emptyList(); - } log.info("Check host, appId:{}, not in current app hosts:{}", cacheApp.getId(), notInAppHosts); return notInAppHosts; } + private void checkStepInstanceConstraint(List stepInstanceList) { + for (StepInstanceDTO stepInstance : stepInstanceList) { + if (stepInstance.isFileStep()) { + int targetServerSize = stepInstance.getTargetServerTotalCount(); + int totalSourceFileSize = 0; + for (FileSourceDTO fileSource : stepInstance.getFileSourceList()) { + int sourceServerSize = 1; + Integer fileType = fileSource.getFileType(); + if (fileType == TaskFileTypeEnum.SERVER.getType() && fileSource.getServers() != null) { + sourceServerSize = CollectionUtils.size(fileSource.getServers().getIpList()); + } + int sourceFileSize = CollectionUtils.size(fileSource.getFiles()); + totalSourceFileSize += sourceServerSize * sourceFileSize; + } + int totalFileTaskSize = totalSourceFileSize * targetServerSize; + if (totalFileTaskSize > 10000) { + log.warn("Step contains a large number of file tasks, size: {}, step: {}", + totalFileTaskSize, stepInstance); + } + if (totalFileTaskSize > jobExecuteConfig.getFileTasksMax()) { + log.warn("Too much file tasks, reject the task. step: {}, size: {}, maxAllowedSize: {}", + stepInstance, totalFileTaskSize, jobExecuteConfig.getFileTasksMax()); + throw new ServiceException(ErrorCode.FILE_TASKS_EXCEEDS_LIMIT, jobExecuteConfig.getFileTasksMax()); + } + } + } + } + @Override public Long createTaskInstanceForFastTaskRedo(TaskInstanceDTO taskInstance, StepInstanceDTO stepInstance) throws ServiceException { @@ -807,6 +894,11 @@ public TaskInstanceDTO createTaskInstanceForTask(TaskExecuteParam executeParam) checkHosts(stepInstanceList, shouldIgnoreInvalidHost(taskInstance)); watch.stop(); + // 检查步骤约束 + watch.start("checkStepInstanceConstraint"); + checkStepInstanceConstraint(stepInstanceList); + watch.stop(); + if (!executeParam.isSkipAuth()) { watch.start("auth-execute-job"); authExecuteJobPlan(executeParam.getOperator(), executeParam.getAppId(), jobPlan, stepInstanceList); @@ -1146,6 +1238,9 @@ public TaskInstanceDTO createTaskInstanceForRedo(Long appId, Long taskInstanceId // 检查主机合法性 checkHosts(stepInstanceList, shouldIgnoreInvalidHost(taskInstance)); + // 检查步骤约束 + checkStepInstanceConstraint(stepInstanceList); + authRedoJob(operator, appId, originTaskInstance); saveTaskInstance(taskInstance, stepInstanceList, finalVariableValueMap); @@ -1774,23 +1869,27 @@ private void confirmRestart(StepInstanceDTO stepInstance, String operator) { private void checkConfirmUser(TaskInstanceDTO taskInstance, StepInstanceDTO stepInstance, String operator) throws ServiceException { // 人工确认步骤,需要判断操作者 - Set receivers = new HashSet<>(); - if (stepInstance.getConfirmUsers() != null && !stepInstance.getConfirmUsers().isEmpty()) { - receivers.addAll(stepInstance.getConfirmUsers()); + if (CollectionUtils.isNotEmpty(stepInstance.getConfirmUsers()) + && stepInstance.getConfirmUsers().contains(operator)) { + return; } + + Set confirmUsers = new HashSet<>(); if (stepInstance.getConfirmRoles() != null && !stepInstance.getConfirmRoles().isEmpty()) { - try { + if (stepInstance.getConfirmRoles().contains(JobRoleEnum.JOB_RESOURCE_TRIGGER_USER.name())) { + confirmUsers.add(taskInstance.getOperator()); + } else { + Set roles = new HashSet<>(stepInstance.getConfirmRoles()); + // JOB_RESOURCE_TRIGGER_USER should remove + roles.remove(JobRoleEnum.JOB_RESOURCE_TRIGGER_USER.name()); ServiceResponse> resp = userResource.getUsersByRoles(stepInstance.getAppId(), operator, - ResourceTypeEnum.JOB.getType(), "" + taskInstance.getTaskId(), - Sets.newHashSet(stepInstance.getConfirmRoles())); + ResourceTypeEnum.JOB.getType(), String.valueOf(taskInstance.getTaskId()), roles); if (resp.isSuccess() && resp.getData() != null) { - receivers.addAll(resp.getData()); + confirmUsers.addAll(resp.getData()); } - } catch (Exception e) { - log.warn("Get users by role fail", e); } } - if (receivers.isEmpty() || !receivers.contains(operator)) { + if (confirmUsers.isEmpty() || !confirmUsers.contains(operator)) { throw new ServiceException(ErrorCode.NOT_IN_CONFIRM_USER_LIST); } } diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/common/util/VariableResolverTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/common/util/VariableResolverTest.java index d69bb1e5bd..8e7278f274 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/common/util/VariableResolverTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/common/util/VariableResolverTest.java @@ -44,7 +44,7 @@ void testResolve() { } @Test - void testResolveNonExistVar() { + void whenVarIsNotExistThenRemainOrigin() { Map vars = new HashMap<>(); vars.put("var1", "var1"); String param = "${var1} ${var2}"; @@ -64,6 +64,17 @@ void testResolveNoVarParamThenReturnOrigin() { assertThat(resolvedParam).isEqualTo("/tmp/"); } + @Test + void whenVarValueNullThenResolvedAsEmptyStr() { + Map vars = new HashMap<>(); + vars.put("var1", "var1"); + vars.put("var2", null); + String param = "--test=${var1} --name=${var2}"; + + String resolvedParam = VariableResolver.resolve(param, vars); + assertThat(resolvedParam).isEqualTo("--test=var1 --name="); + } + @Test void testResolveVarValueContainsVarPattern() { Map vars = new HashMap<>(); diff --git a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java index 3bce4e6390..b7b15bf4ce 100644 --- a/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java +++ b/src/backend/job-execute/service-job-execute/src/test/java/com/tencent/bk/job/execute/engine/util/MacroUtilTest.java @@ -26,6 +26,9 @@ import org.junit.jupiter.api.Test; +import java.time.ZoneId; +import java.time.ZoneOffset; + import static org.assertj.core.api.Assertions.assertThat; public class MacroUtilTest { @@ -34,21 +37,26 @@ void testResolveDate() { String str = "/tmp/[DATE:yyyy-MM-dd]/test/"; // 2021-01-01 12:01:01 long timestamp = 1609473661000L; - String result = MacroUtil.resolveDate(str, timestamp); - assertThat(result).isEqualTo("/tmp/2021-01-01/test/"); + ZoneId zoneId = ZoneOffset.systemDefault(); + String zoneIdStr = zoneId.getId(); + System.out.println("systemDefault zoneId=" + zoneIdStr); + String result = null; + if ("Asia/Shanghai".equals(zoneIdStr)) { + result = MacroUtil.resolveDate(str, timestamp); + assertThat(result).isEqualTo("/tmp/2021-01-01/test/"); - str = "/tmp/[DATE:YYYY-MM-dd]/test/"; - result = MacroUtil.resolveDate(str, timestamp); - assertThat(result).isEqualTo("/tmp/2021-01-01/test/"); + str = "/tmp/[DATE:YYYY-MM-dd]/test/"; + result = MacroUtil.resolveDate(str, timestamp); + assertThat(result).isEqualTo("/tmp/2021-01-01/test/"); - str = "/tmp/[DATE:yyyy-MM-dd_HH:mm:ss]/test/"; - result = MacroUtil.resolveDate(str, timestamp); - assertThat(result).isEqualTo("/tmp/2021-01-01_12:01:01/test/"); - - str = "/tmp/[DATE:yyyy-MM-dd]/[DATE:HH:mm:ss]/test/"; - result = MacroUtil.resolveDate(str, timestamp); - assertThat(result).isEqualTo("/tmp/2021-01-01/12:01:01/test/"); + str = "/tmp/[DATE:yyyy-MM-dd_HH:mm:ss]/test/"; + result = MacroUtil.resolveDate(str, timestamp); + assertThat(result).isEqualTo("/tmp/2021-01-01_12:01:01/test/"); + str = "/tmp/[DATE:yyyy-MM-dd]/[DATE:HH:mm:ss]/test/"; + result = MacroUtil.resolveDate(str, timestamp); + assertThat(result).isEqualTo("/tmp/2021-01-01/12:01:01/test/"); + } str = "/tmp/test/"; result = MacroUtil.resolveDate(str, timestamp); assertThat(result).isEqualTo("/tmp/test/"); diff --git a/src/backend/job-file-gateway/api-job-file-gateway-worker/build.gradle b/src/backend/job-file-gateway/api-job-file-gateway-worker/build.gradle index 608dd303df..80df30df7a 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway-worker/build.gradle +++ b/src/backend/job-file-gateway/api-job-file-gateway-worker/build.gradle @@ -23,8 +23,8 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') + api project(':commons:common') + api project(':commons:common-i18n') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation 'com.fasterxml.jackson.core:jackson-core' diff --git a/src/backend/job-file-gateway/api-job-file-gateway/build.gradle b/src/backend/job-file-gateway/api-job-file-gateway/build.gradle index 7ea1a301b6..7ba1885fe6 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/build.gradle +++ b/src/backend/job-file-gateway/api-job-file-gateway/build.gradle @@ -23,11 +23,12 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') - compile project(':commons:common-iam') - compile project(":job-logsvr:api-job-logsvr") - compile project(":job-file-gateway:api-job-file-gateway-worker") + api project(':commons:common') + api project(':commons:common-i18n') + api project(':commons:common-iam') + api project(':commons:esb-sdk') + api project(":job-logsvr:api-job-logsvr") + api project(":job-file-gateway:api-job-file-gateway-worker") implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation 'com.fasterxml.jackson.core:jackson-core' diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java new file mode 100644 index 0000000000..72c1df8d03 --- /dev/null +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.file_gateway.api.esb; + +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbCreateOrUpdateFileSourceV3Req; +import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceSimpleInfoV3DTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 文件源API-V3 + */ +@RequestMapping("/esb/api/v3") +@RestController +@EsbAPI +public interface EsbFileSourceV3Resource { + + @PostMapping("/create_file_source") + EsbResp createFileSource( + @RequestBody EsbCreateOrUpdateFileSourceV3Req req); + + @PostMapping("/update_file_source") + EsbResp updateFileSource( + @RequestBody EsbCreateOrUpdateFileSourceV3Req req); + +} diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java index 3e4ee022b3..2aef8ee3d2 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.file_gateway.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -36,6 +37,7 @@ @Api(tags = {"job-file-gateway:service:FileSource"}) @RequestMapping("/service/fileSource/") @RestController +@InternalAPI public interface ServiceFileSourceResource { @ApiOperation(value = "获取文件源ID", produces = "application/json") diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceTaskResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceTaskResource.java index 449d8109cb..1fba372d96 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceTaskResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceTaskResource.java @@ -24,8 +24,14 @@ package com.tencent.bk.job.file_gateway.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.file_gateway.model.req.inner.*; +import com.tencent.bk.job.file_gateway.model.req.inner.ClearBatchTaskFilesReq; +import com.tencent.bk.job.file_gateway.model.req.inner.ClearTaskFilesReq; +import com.tencent.bk.job.file_gateway.model.req.inner.FileSourceBatchDownloadTaskReq; +import com.tencent.bk.job.file_gateway.model.req.inner.FileSourceDownloadTaskReq; +import com.tencent.bk.job.file_gateway.model.req.inner.StopBatchTaskReq; +import com.tencent.bk.job.file_gateway.model.req.inner.StopTaskReq; import com.tencent.bk.job.file_gateway.model.resp.inner.BatchTaskInfoDTO; import com.tencent.bk.job.file_gateway.model.resp.inner.BatchTaskStatusDTO; import com.tencent.bk.job.file_gateway.model.resp.inner.FileSourceTaskStatusDTO; @@ -33,12 +39,20 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-file-gateway:service:FileSourceTask"}) @RequestMapping("/service/fileSource/filetask") @RestController +@InternalAPI public interface ServiceFileSourceTaskResource { // 直接转发至FileWorker的请求,URL子路径保持一致 diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileResource.java index 485a308dee..ac36f0d188 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileResource.java @@ -24,17 +24,26 @@ package com.tencent.bk.job.file_gateway.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file_gateway.model.req.common.ExecuteActionReq; import com.tencent.bk.job.file_gateway.model.resp.common.FileNodesVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-file-gateway:web:File"}) @RequestMapping("/web/file/app/{appId}/fileSourceIds/{fileSourceId}") @RestController +@WebAPI public interface WebFileResource { // 子路径与FileWorker子路径保持一致 diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResource.java index 6e412d8fb7..ad5233fae7 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.file_gateway.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file_gateway.model.req.common.FileSourceStaticParam; @@ -32,13 +33,23 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-file-gateway:web:FileSource"}) @RequestMapping("/web/fileSource/app/{appId}") @RestController +@WebAPI public interface WebFileSourceResource { @ApiOperation(value = "检查文件源别名是否已存在(可用返回true)", produces = "application/json") diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResource.java index 6c3a5fae45..61396b8805 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResource.java @@ -24,18 +24,25 @@ package com.tencent.bk.job.file_gateway.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file_gateway.model.resp.web.FileSourceTypeVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-file-gateway:web:FileSourceType"}) @RequestMapping("/web/fileSourceType/app/{appId}") @RestController +@WebAPI public interface WebFileSourceTypeResource { @ApiOperation(value = "获取文件源类型列表", produces = "application/json") diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResource.java index 2cb352f1a5..72e43f47d2 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResource.java @@ -24,19 +24,26 @@ package com.tencent.bk.job.file_gateway.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file_gateway.consts.WorkerSelectScopeEnum; import com.tencent.bk.job.file_gateway.model.resp.web.FileWorkerVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-file-gateway:web:FileWorker"}) @RequestMapping("/web/fileWorker") @RestController +@WebAPI public interface WebFileWorkerResource { @ApiOperation(value = "获取文件接入点列表", produces = "application/json") diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResource.java index 3a0990bea5..34794cdb08 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResource.java @@ -24,17 +24,25 @@ package com.tencent.bk.job.file_gateway.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.file_gateway.model.req.web.OperationPermissionReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-file-gateway:web:Permission"}) @RequestMapping("/web/permission/") @RestController +@WebAPI public interface WebPermissionResource { /** * 获取权限申请URL diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbCreateOrUpdateFileSourceV3Req.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbCreateOrUpdateFileSourceV3Req.java new file mode 100644 index 0000000000..149a8769fa --- /dev/null +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbCreateOrUpdateFileSourceV3Req.java @@ -0,0 +1,56 @@ +package com.tencent.bk.job.file_gateway.model.req.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.esb.model.EsbReq; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Map; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbCreateOrUpdateFileSourceV3Req extends EsbReq { + /** + * 业务ID + */ + @JsonProperty("bk_biz_id") + private Long appId; + + @ApiModelProperty(value = "ID,更新文件源的时候需要传入,新建文件源不需要") + private Integer id; + /** + * 文件源Code + */ + @ApiModelProperty(value = "文件源Code") + private String code; + /** + * 文件源别名 + */ + @ApiModelProperty(value = "文件源名称") + private String alias; + /** + * 文件源类型 + */ + @ApiModelProperty(value = "文件源类型") + private String type; + + /** + * 文件源信息Map + */ + @ApiModelProperty(value = "文件源信息Map") + @JsonProperty(value = "access_params") + private Map accessParams; + /** + * 文件源凭证Id + */ + @ApiModelProperty(value = "文件源凭证Id") + @JsonProperty(value = "credential_id") + private String credentialId; + /** + * 文件前缀 + */ + @ApiModelProperty(value = "文件前缀:后台自动生成UUID传${UUID},自定义字符串直接传") + @JsonProperty(value = "file_prefix") + private String filePrefix; +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/CompositeExpression.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceSimpleInfoV3DTO.java similarity index 90% rename from src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/CompositeExpression.java rename to src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceSimpleInfoV3DTO.java index 37e9955d19..aee7669c92 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/CompositeExpression.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceSimpleInfoV3DTO.java @@ -22,18 +22,17 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.upgrader.model; +package com.tencent.bk.job.file_gateway.model.resp.esb.v3; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - +@Data @NoArgsConstructor @AllArgsConstructor -@Data -public class CompositeExpression { - private String op; - private List content; +public class EsbFileSourceSimpleInfoV3DTO { + + private Integer id; + } diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/inner/FileSourceTaskStatusDTO.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/inner/FileSourceTaskStatusDTO.java index a6d12a5043..16c2c82ed7 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/inner/FileSourceTaskStatusDTO.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/inner/FileSourceTaskStatusDTO.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.file_gateway.model.resp.inner; import com.tencent.bk.job.file_gateway.consts.TaskStatusEnum; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -47,7 +47,7 @@ public class FileSourceTaskStatusDTO { * 文件源文件路径->文件在机器上的真实路径 */ Map filePathMap; - List logList; + List logList; Boolean logEnd; public boolean isDone() { diff --git a/src/backend/job-file-gateway/boot-job-file-gateway/build.gradle b/src/backend/job-file-gateway/boot-job-file-gateway/build.gradle index 86870e48c0..d0009da8ef 100644 --- a/src/backend/job-file-gateway/boot-job-file-gateway/build.gradle +++ b/src/backend/job-file-gateway/boot-job-file-gateway/build.gradle @@ -25,8 +25,8 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":commons:common-redis") - compile project(":job-file-gateway:service-job-file-gateway") + api project(":commons:common-redis") + api project(":job-file-gateway:service-job-file-gateway") implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-jdbc' @@ -34,13 +34,14 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' implementation 'org.springframework:spring-webmvc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' runtimeOnly('mysql:mysql-connector-java') } springBoot { - mainClassName = "com.tencent.bk.job.file_gateway.JobFileGatewayBootApplication" + mainClass = "com.tencent.bk.job.file_gateway.JobFileGatewayBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/I18nConfig.java b/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/I18nConfig.java deleted file mode 100644 index 026a813183..0000000000 --- a/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/I18nConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.file_gateway.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/InterceptorConfiguration.java b/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/InterceptorConfiguration.java index dc56287fb7..3e375c4f45 100644 --- a/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/InterceptorConfiguration.java +++ b/src/backend/job-file-gateway/boot-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/InterceptorConfiguration.java @@ -24,7 +24,9 @@ package com.tencent.bk.job.file_gateway.config; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; +import com.tencent.bk.job.common.web.interceptor.EsbReqRewriteInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import com.tencent.bk.job.file_gateway.interceptor.UriPermissionInterceptor; @@ -37,17 +39,25 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final EsbApiLogInterceptor esbApiLogInterceptor; + private final EsbReqRewriteInterceptor esbReqRewriteInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; private final UriPermissionInterceptor uriPermissionInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - EsbApiLogInterceptor esbApiLogInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor, - UriPermissionInterceptor uriPermissionInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + EsbApiLogInterceptor esbApiLogInterceptor, + EsbReqRewriteInterceptor esbReqRewriteInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor, + UriPermissionInterceptor uriPermissionInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; + this.authAppInterceptor = authAppInterceptor; this.esbApiLogInterceptor = esbApiLogInterceptor; + this.esbReqRewriteInterceptor = esbReqRewriteInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; this.uriPermissionInterceptor = uriPermissionInterceptor; } @@ -60,5 +70,7 @@ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(uriPermissionInterceptor) .addPathPatterns(uriPermissionInterceptor.getControlUriPatternsList()).order(2); registry.addInterceptor(esbApiLogInterceptor).addPathPatterns("/esb/api/**").order(10); + registry.addInterceptor(esbReqRewriteInterceptor).addPathPatterns("/esb/api/**").order(11); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(12); } } diff --git a/src/backend/job-file-gateway/build.gradle b/src/backend/job-file-gateway/build.gradle index 9d10893555..91a496e8d4 100644 --- a/src/backend/job-file-gateway/build.gradle +++ b/src/backend/job-file-gateway/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobFileGatewayVersion")) { set("jobFileGatewayVersion", System.getProperty("jobFileGatewayVersion")) + } else if (System.getProperty("version")) { + set("jobFileGatewayVersion", System.getProperty("version")) } else { set("jobFileGatewayVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobFileGatewayVersion}" subprojects { version "${jobFileGatewayVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/build.gradle b/src/backend/job-file-gateway/service-job-file-gateway/build.gradle index 5a7ab65137..8b1d1bea0b 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/build.gradle +++ b/src/backend/job-file-gateway/service-job-file-gateway/build.gradle @@ -23,14 +23,14 @@ */ dependencies { - compile project(":commons:common-web") - compile project(":commons:common-redis") - compile project(":job-ticket:api-job-ticket") - compile project(":job-manage:api-job-manage") - compile project(":job-execute:api-job-execute") - compile project(":job-file-worker-sdk:api-job-file-worker-sdk") - compile project(":job-file-gateway:api-job-file-gateway") - compile project(":job-file-gateway:model-job-file-gateway") + api project(":commons:common-web") + api project(":commons:common-redis") + api project(":job-ticket:api-job-ticket") + api project(":job-manage:api-job-manage") + api project(":job-execute:api-job-execute") + api project(":job-file-worker-sdk:api-job-file-worker-sdk") + api project(":job-file-gateway:api-job-file-gateway") + api project(":job-file-gateway:model-job-file-gateway") implementation group: 'org.apache.httpcomponents', name: 'httpclient' implementation "org.springframework.boot:spring-boot-starter-web" implementation "org.springframework.cloud:spring-cloud-starter-sleuth" diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java new file mode 100644 index 0000000000..8f14b8929c --- /dev/null +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java @@ -0,0 +1,163 @@ +package com.tencent.bk.job.file_gateway.api.esb; + +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.common.exception.InvalidParamException; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.file_gateway.consts.WorkerSelectModeEnum; +import com.tencent.bk.job.file_gateway.consts.WorkerSelectScopeEnum; +import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; +import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbCreateOrUpdateFileSourceV3Req; +import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceSimpleInfoV3DTO; +import com.tencent.bk.job.file_gateway.service.FileSourceService; +import com.tencent.bk.sdk.iam.util.PathBuilder; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collections; + +@RestController +@Slf4j +public class EsbFileSourceV3ResourceImpl implements EsbFileSourceV3Resource { + + private final AuthService authService; + private final FileSourceService fileSourceService; + + @Autowired + public EsbFileSourceV3ResourceImpl(AuthService authService, FileSourceService fileSourceService) { + this.authService = authService; + this.fileSourceService = fileSourceService; + } + + @Override + public EsbResp createFileSource(EsbCreateOrUpdateFileSourceV3Req req) { + Long appId = req.getAppId(); + String username = req.getUserName(); + AuthResult authResult = checkCreateFileSourcePermission(username, appId); + if (!authResult.isPass()) { + return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources()); + } + checkCreateParam(req); + FileSourceDTO fileSourceDTO = buildFileSourceDTO(req.getUserName(), appId, req); + Integer fileSourceId = fileSourceService.saveFileSource(appId, fileSourceDTO); + boolean registerResult = authService.registerResource("" + fileSourceId, fileSourceDTO.getAlias(), + ResourceId.FILE_SOURCE, username, null); + if (!registerResult) { + log.warn("Fail to register file_source to iam:({},{})", fileSourceId, fileSourceDTO.getAlias()); + } + return EsbResp.buildSuccessResp(new EsbFileSourceSimpleInfoV3DTO(fileSourceId)); + } + + @Override + public EsbResp updateFileSource(EsbCreateOrUpdateFileSourceV3Req req) { + checkUpdateParam(req); + Long appId = req.getAppId(); + String username = req.getUserName(); + Integer id = req.getId(); + AuthResult authResult = checkManageFileSourcePermission(username, appId, id); + if (!authResult.isPass()) { + return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources()); + } + FileSourceDTO fileSourceDTO = buildFileSourceDTO(req.getUserName(), appId, req); + Integer fileSourceId = fileSourceService.updateFileSourceById(appId, fileSourceDTO); + return EsbResp.buildSuccessResp(new EsbFileSourceSimpleInfoV3DTO(fileSourceId)); + } + + private void checkAppId(EsbCreateOrUpdateFileSourceV3Req req) { + if (req.getAppId() == null) { + throw new InvalidParamException("bk_biz_id", "bk_biz_id cannot be null"); + } + } + + private void checkCreateParam(EsbCreateOrUpdateFileSourceV3Req req) { + checkAppId(req); + String code = req.getCode(); + if (StringUtils.isBlank(code)) { + throw new InvalidParamException("code", "code cannot be null or blank"); + } + if (fileSourceService.existsCode(code)) { + throw new InvalidParamException("code", String.format("code [%s] already exists", code)); + } + if (StringUtils.isBlank(req.getAlias())) { + throw new InvalidParamException("alias", "alias cannot be null or blank"); + } + if (StringUtils.isBlank(req.getType())) { + throw new InvalidParamException("type", "type cannot be null or blank"); + } + if (StringUtils.isBlank(req.getCredentialId())) { + throw new InvalidParamException("credential_id", "credential_id cannot be null or blank"); + } + } + + private void checkUpdateParam(EsbCreateOrUpdateFileSourceV3Req req) { + checkAppId(req); + Long appId = req.getAppId(); + Integer id = req.getId(); + String code = req.getCode(); + if (id == null && StringUtils.isBlank(code)) { + throw new InvalidParamException("id/code", "id and code cannot be null/blank simultaneously"); + } + if (id == null) { + id = fileSourceService.getFileSourceIdByCode(appId, code); + if (id == null) { + throw new InvalidParamException("code", String.format("cannot find fileSource by code [%s]", code)); + } + } + req.setId(id); + if (!fileSourceService.existsFileSource(appId, id)) { + throw new InvalidParamException( + "bk_biz_id/id", + String.format("fileSource [%s] not exists in biz [%s]", id, appId) + ); + } + } + + private FileSourceDTO buildFileSourceDTO(String username, Long appId, + EsbCreateOrUpdateFileSourceV3Req fileSourceCreateUpdateReq) { + FileSourceDTO fileSourceDTO = new FileSourceDTO(); + fileSourceDTO.setAppId(appId); + fileSourceDTO.setId(fileSourceCreateUpdateReq.getId()); + fileSourceDTO.setCode(fileSourceCreateUpdateReq.getCode()); + fileSourceDTO.setAlias(fileSourceCreateUpdateReq.getAlias()); + fileSourceDTO.setStatus(null); + fileSourceDTO.setFileSourceType( + fileSourceService.getFileSourceTypeByCode( + fileSourceCreateUpdateReq.getType() + ) + ); + fileSourceDTO.setFileSourceInfoMap(fileSourceCreateUpdateReq.getAccessParams()); + fileSourceDTO.setPublicFlag(false); + fileSourceDTO.setSharedAppIdList(Collections.emptyList()); + fileSourceDTO.setShareToAllApp(false); + fileSourceDTO.setCredentialId(fileSourceCreateUpdateReq.getCredentialId()); + fileSourceDTO.setFilePrefix(fileSourceCreateUpdateReq.getFilePrefix()); + fileSourceDTO.setWorkerSelectScope(WorkerSelectScopeEnum.PUBLIC.name()); + fileSourceDTO.setWorkerSelectMode(WorkerSelectModeEnum.AUTO.name()); + fileSourceDTO.setWorkerId(null); + // 文件源默认开启状态 + fileSourceDTO.setEnable(true); + fileSourceDTO.setCreator(username); + fileSourceDTO.setCreateTime(System.currentTimeMillis()); + fileSourceDTO.setLastModifyUser(username); + fileSourceDTO.setLastModifyTime(System.currentTimeMillis()); + return fileSourceDTO; + } + + public AuthResult checkCreateFileSourcePermission(String username, Long appId) { + // 需要拥有在业务下创建文件源的权限 + return authService.auth(true, username, ActionId.CREATE_FILE_SOURCE, ResourceTypeEnum.BUSINESS, + appId.toString(), null); + } + + public AuthResult checkManageFileSourcePermission(String username, Long appId, Integer fileSourceId) { + // 需要拥有在业务下管理某个具体文件源的权限 + return authService.auth(true, username, ActionId.MANAGE_FILE_SOURCE, ResourceTypeEnum.FILE_SOURCE, + fileSourceId.toString(), + PathBuilder.newBuilder(ResourceTypeEnum.BUSINESS.getId(), appId.toString()).build()); + } +} diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/iam/IamFileSourceCallbackResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/iam/IamFileSourceCallbackResourceImpl.java index a5a6b7c591..36191533b4 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/iam/IamFileSourceCallbackResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/iam/IamFileSourceCallbackResourceImpl.java @@ -24,11 +24,21 @@ package com.tencent.bk.job.file_gateway.api.iam; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; +import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; import com.tencent.bk.job.file_gateway.service.FileSourceService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -39,7 +49,8 @@ @RestController @Slf4j -public class IamFileSourceCallbackResourceImpl implements IamFileSourceCallbackResource { +public class IamFileSourceCallbackResourceImpl extends BaseIamCallbackService + implements IamFileSourceCallbackResource { private final FileSourceService fileSourceService; @@ -48,95 +59,146 @@ public IamFileSourceCallbackResourceImpl(FileSourceService fileSourceService) { this.fileSourceService = fileSourceService; } + @Data + static class FileSourceSearchCondition { + List appIdList; + List idStrList; + List fileSourceIdList; + int start; + int length; + String keyword; + + FileSourceSearchCondition( + List appIdList, + List idStrList, + List fileSourceIdList, + int start, + int length, + String keyword + ) { + this.appIdList = appIdList; + this.idStrList = idStrList; + this.fileSourceIdList = fileSourceIdList; + this.start = start; + this.length = length; + this.keyword = keyword; + } + } + + private FileSourceSearchCondition getSearchCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + // 文件源列表实现 + List appIdList = searchCondition.getAppIdList(); + List idStrList = searchCondition.getIdList(); + List fileSourceIdList = null; + if (idStrList != null) { + fileSourceIdList = idStrList.parallelStream().map(Integer::parseInt).collect(Collectors.toList()); + } + + int start = searchCondition.getStart().intValue(); + int length = searchCondition.getLength().intValue(); + + String keyword = callbackRequest.getFilter().getKeyword(); + return new FileSourceSearchCondition( + appIdList, idStrList, fileSourceIdList, start, length, keyword + ); + } + + private InstanceInfoDTO convert(FileSourceDTO fileSourceDTO) { + InstanceInfoDTO tmpInstanceInfo = new InstanceInfoDTO(); + tmpInstanceInfo.setId(fileSourceDTO.getId().toString()); + tmpInstanceInfo.setDisplayName(fileSourceDTO.getAlias()); + return tmpInstanceInfo; + } + @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + FileSourceSearchCondition searchCondition = getSearchCondition(callbackRequest); + + List fileSourceDTOList = fileSourceService.listWorkTableFileSource( + searchCondition.getAppIdList(), + searchCondition.getFileSourceIdList(), + searchCondition.getStart(), + searchCondition.getLength() + ); + Long totalCount = fileSourceService.countWorkTableFileSource( + searchCondition.getAppIdList(), searchCondition.getFileSourceIdList() + ).longValue(); + PageData fileSourceDTOPageData = new PageData<>( + searchCondition.getStart(), + searchCondition.getLength(), + totalCount, + fileSourceDTOList + ); + return IamRespUtil.getListInstanceRespFromPageData(fileSourceDTOPageData, this::convert); + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + FileSourceSearchCondition searchCondition = getSearchCondition(callbackRequest); + + List fileSourceDTOList = fileSourceService.listWorkTableFileSource( + searchCondition.getAppIdList().get(0), + null, + searchCondition.getKeyword(), + searchCondition.getStart(), + searchCondition.getLength() + ); + + Long totalCount = fileSourceService.countWorkTableFileSource( + searchCondition.getAppIdList(), searchCondition.getFileSourceIdList() + ).longValue(); + PageData fileSourceDTOPageData = new PageData<>( + searchCondition.getStart(), + searchCondition.getLength(), + totalCount, + fileSourceDTOList + ); + return IamRespUtil.getSearchInstanceRespFromPageData(fileSourceDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - // 文件源列表实现 - List appIdList = searchCondition.getAppIdList(); - List idStrList = searchCondition.getIdList(); - List fileSourceIdList = null; - if (idStrList != null) { - fileSourceIdList = idStrList.parallelStream().map(Integer::parseInt).collect(Collectors.toList()); + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + // 文件源详情查询实现 + FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceById(Integer.parseInt(instanceId)); + if (fileSourceDTO == null) { + return getNotFoundRespById(instanceId); } - List fileSourceDTOList = fileSourceService.listWorkTableFileSource( - appIdList, - fileSourceIdList, - searchCondition.getStart().intValue(), - searchCondition.getLength().intValue()); - Long totalCount = fileSourceService.countWorkTableFileSource(appIdList, fileSourceIdList).longValue(); - List instanceInfoList = fileSourceDTOList.parallelStream().map(fileSourceDTO -> { - InstanceInfoDTO tmpInstanceInfo = new InstanceInfoDTO(); - tmpInstanceInfo.setId(fileSourceDTO.getId().toString()); - tmpInstanceInfo.setDisplayName(fileSourceDTO.getAlias()); - return tmpInstanceInfo; - }).collect(Collectors.toList()); - - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - baseDataResponse.setResult(instanceInfoList); - baseDataResponse.setCount(totalCount); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - // 文件源详情查询实现 - FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceById(Integer.parseInt(instanceId)); - if (fileSourceDTO == null) { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected fileSourceId:{} passed by iam", instanceId); - } else { - instanceInfo.setDisplayName(fileSourceDTO.getAlias()); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(fileSourceDTO.getAppId().toString()); + PathInfoDTO fileSourceNode = new PathInfoDTO(); + fileSourceNode.setType(ResourceId.FILE_SOURCE); + fileSourceNode.setId(fileSourceDTO.getId().toString()); + rootNode.setChild(fileSourceNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(fileSourceDTO.getAlias()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } } - return response; + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); } } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResourceImpl.java index db2bbe47fa..d51dc67910 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceResourceImpl.java @@ -60,8 +60,11 @@ public class WebFileSourceResourceImpl implements WebFileSourceResource { private final FileSourceService fileSourceService; @Autowired - public WebFileSourceResourceImpl(WebAuthService authService, FileSourceService fileSourceService) { - this.authService = authService; + public WebFileSourceResourceImpl( + WebAuthService webAuthService, + FileSourceService fileSourceService + ) { + this.authService = webAuthService; this.fileSourceService = fileSourceService; } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResourceImpl.java index b8b9668b9a..f6ad197bd3 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileSourceTypeResourceImpl.java @@ -43,7 +43,9 @@ public class WebFileSourceTypeResourceImpl implements WebFileSourceTypeResource private final FileSourceService fileSourceService; @Autowired - public WebFileSourceTypeResourceImpl(FileSourceService fileSourceService) { + public WebFileSourceTypeResourceImpl( + FileSourceService fileSourceService + ) { this.fileSourceService = fileSourceService; } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResourceImpl.java index d1c6c9a2cb..3419d6d27b 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebFileWorkerResourceImpl.java @@ -45,7 +45,9 @@ public class WebFileWorkerResourceImpl implements WebFileWorkerResource { private final FileWorkerService fileWorkerService; @Autowired - public WebFileWorkerResourceImpl(FileWorkerService fileWorkerService) { + public WebFileWorkerResourceImpl( + FileWorkerService fileWorkerService + ) { this.fileWorkerService = fileWorkerService; } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResourceImpl.java index ce8c28ad6a..3eedd584cd 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/web/WebPermissionResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.file_gateway.api.web; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.service.WebAuthService; diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java index 40b4020565..2e1b27a3de 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java @@ -62,4 +62,10 @@ List listWorkTableFileSource(DSLContext dslContext, Long appId, S List listWorkTableFileSource(DSLContext dslContext, List appIdList, List idList, Integer start, Integer pageSize); + + boolean existsCode(String code); + + boolean existsFileSource(Long appId, Integer id); + + Integer getFileSourceIdByCode(Long appId, String code); } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java index c1da5f1946..a0ddc809f9 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java @@ -416,6 +416,45 @@ public List listWorkTableFileSource(DSLContext dslContext, List 0; + } + + @Override + public boolean existsFileSource(Long appId, Integer id) { + val query = defaultContext.selectZero().from(defaultTable) + .where(defaultTable.APP_ID.eq(appId)) + .and(defaultTable.ID.eq(id)) + .limit(1); + return query.fetch().size() > 0; + } + + @Override + public Integer getFileSourceIdByCode(Long appId, String code) { + List conditions = new ArrayList<>(); + if (appId != null) { + conditions.add(defaultTable.APP_ID.eq(appId)); + } + if (code != null) { + conditions.add(defaultTable.CODE.eq(code)); + } + val query = defaultContext.select( + defaultTable.ID + ).from(defaultTable) + .where(conditions); + val result = query.fetch(); + if (result.size() > 0) { + if (result.size() > 1) { + log.warn("{} records found when get id by code, use first one", result.size()); + } + return result.get(0).get(defaultTable.ID); + } + return null; + } + private List listFileSourceByConditions(DSLContext dslContext, Collection conditions, Integer start, Integer pageSize) { val query = dslContext.select( diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileWorkerDTO.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileWorkerDTO.java index 02d8b9a3ce..4dd93d4b57 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileWorkerDTO.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileWorkerDTO.java @@ -35,7 +35,6 @@ import com.tencent.bk.job.file_gateway.model.resp.web.FileWorkerVO; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.*; @@ -44,7 +43,6 @@ * 文件Worker */ @Data -@EqualsAndHashCode @NoArgsConstructor @AllArgsConstructor public class FileWorkerDTO { diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java index e4622f4a84..21eb8886f2 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.file_gateway.service; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; public interface CredentialService { @@ -34,5 +34,5 @@ public interface CredentialService { * @param id * @return */ - CommonCredentialDTO getCredentialById(Long appId, String id); + CommonCredential getCredentialById(Long appId, String id); } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileService.java index e8dc9b31fb..f6de456397 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileService.java @@ -29,6 +29,8 @@ public interface FileService { + boolean isFileAvailable(String username, Long appId, Integer fileSourceId); + FileNodesVO listFileNode(String username, Long appId, Integer fileSourceId, String path, String name, Integer start, Integer pageSize); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java index b8207d9672..b95df01f8e 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java @@ -43,14 +43,28 @@ public interface FileSourceService { Integer countWorkTableFileSource(List appIdList, List idList); - List listAvailableFileSource(Long appId, String credentialId, String alias, Integer start, - Integer pageSize); - - List listWorkTableFileSource(Long appId, String credentialId, String alias, Integer start, - Integer pageSize); - - List listWorkTableFileSource(List appIdList, List idList, Integer start, - Integer pageSize); + List listAvailableFileSource( + Long appId, + String credentialId, + String alias, + Integer start, + Integer pageSize + ); + + List listWorkTableFileSource( + Long appId, + String credentialId, + String alias, + Integer start, + Integer pageSize + ); + + List listWorkTableFileSource( + List appIdList, + List idList, + Integer start, + Integer pageSize + ); Integer saveFileSource(Long appId, FileSourceDTO fileSourceDTO); @@ -75,4 +89,10 @@ List listWorkTableFileSource(List appIdList, List List getFileSourceParams(Long appId, String fileSourceTypeCode); Boolean checkFileSourceAlias(Long appId, String alias, Integer fileSourceId); + + boolean existsCode(String code); + + boolean existsFileSource(Long appId, Integer id); + + Integer getFileSourceIdByCode(Long appId, String code); } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/CredentialServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/CredentialServiceImpl.java index 5af544e422..b368646af8 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/CredentialServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/CredentialServiceImpl.java @@ -25,10 +25,9 @@ package com.tencent.bk.job.file_gateway.service.impl; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.file_gateway.client.ServiceCredentialResourceClient; import com.tencent.bk.job.file_gateway.service.CredentialService; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import com.tencent.bk.job.ticket.model.inner.resp.ServiceCredentialDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -46,7 +45,7 @@ public CredentialServiceImpl(ServiceCredentialResourceClient credentialService) } @Override - public CommonCredentialDTO getCredentialById(Long appId, String id) { + public CommonCredential getCredentialById(Long appId, String id) { ServiceResponse credentialServiceResponse = credentialService.getCredentialById(appId, id); ServiceCredentialDTO credentialDTO = credentialServiceResponse.getData(); @@ -54,11 +53,10 @@ public CommonCredentialDTO getCredentialById(Long appId, String id) { return null; } try { - CommonCredentialDTO commonCredentialDTO = JsonUtils.fromJson(credentialDTO.getValue(), - CommonCredentialDTO.class); + CommonCredential commonCredential = credentialDTO.getCredential(); // Type补全 - commonCredentialDTO.setType(credentialDTO.getType()); - return commonCredentialDTO; + commonCredential.setType(credentialDTO.getType()); + return commonCredential; } catch (Exception e) { log.error("credential not valid:{}", credentialDTO); return null; diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileServiceImpl.java index 063c62defc..f58212d09c 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileServiceImpl.java @@ -69,6 +69,33 @@ private FileWorkerDTO getFileWorker(Long appId, FileSourceDTO fileSourceDTO) { return dispatchService.findBestFileWorker(fileSourceDTO); } + @Override + public boolean isFileAvailable(String username, Long appId, Integer fileSourceId) { + FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceById(appId, fileSourceId); + FileWorkerDTO fileWorkerDTO = getFileWorker(appId, fileSourceDTO); + if (fileWorkerDTO == null) { + throw new ServiceException(ErrorCode.CAN_NOT_FIND_AVAILABLE_FILE_WORKER); + } + log.info("choose file worker:" + fileWorkerDTO); + // 访问文件Worker接口,拿到available状态信息 + HttpReq fileAvailableReq = fileSourceReqGenService.genFileAvailableReq(appId, fileWorkerDTO, fileSourceDTO); + String respStr = null; + log.info(String.format("url=%s,body=%s,headers=%s", fileAvailableReq.getUrl(), fileAvailableReq.getBody(), + JsonUtils.toJson(fileAvailableReq.getHeaders()))); + try { + respStr = fileWorkerHttpHelper.post(fileAvailableReq.getUrl(), fileAvailableReq.getBody(), + fileAvailableReq.getHeaders()); + log.info(String.format("respStr=%s", respStr)); + ServiceResponse resp = JsonUtils.fromJson(respStr, + new TypeReference>() { + }); + return resp.getData(); + } catch (Exception e) { + log.error("Fail to request remote worker:", e); + return false; + } + } + @Override public FileNodesVO listFileNode(String username, Long appId, Integer fileSourceId, String path, String name, Integer start, Integer pageSize) { @@ -91,7 +118,7 @@ public FileNodesVO listFileNode(String username, Long appId, Integer fileSourceI listFileNodeReq.getHeaders()); } catch (Exception e) { log.error("Fail to request remote worker:", e); - throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_LIST_BUCKET, new String[]{e.getMessage()}); + throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_LIST_FILE_NODE, new String[]{e.getMessage()}); } log.info(String.format("respStr=%s", respStr)); FileNodesDTO fileNodesDTO = parseFileNodesDTO(respStr); @@ -127,7 +154,7 @@ public Boolean executeAction(String username, Long appId, Integer fileSourceId, throw (ServiceException) e; } else { log.error("Fail to request remote worker:", e); - throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_DELETE_BUCKET, + throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_EXECUTE_ACTION, new String[]{e.getMessage()}); } } @@ -140,7 +167,7 @@ private FileNodesDTO parseFileNodesDTO(String respStr) { }); } catch (Exception e) { log.error("Fail to parse bucket from response={}", respStr, e); - throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_LIST_BUCKET, e.getMessage()); + throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_LIST_FILE_NODE, e.getMessage()); } if (resp.isSuccess()) { return resp.getData(); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java index 686b896412..0f6ed59c6b 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java @@ -183,7 +183,7 @@ public List getFileSourceParams(Long appId, String fileSo FileWorkerDTO fileWorkerDTO = fileWorkerDAO.getFileWorkerById(dslContext, workerId); FileWorkerConfig fileWorkerConfig = JsonUtils.fromJson(fileWorkerDTO.getConfigStr(), new TypeReference() { - }); + }); List fileSourceMetaDataList = fileWorkerConfig.getFileSourceMetaDataList(); for (FileSourceMetaData fileSourceMetaData : fileSourceMetaDataList) { if (StringUtils.isNotBlank(fileSourceTypeCode) @@ -208,4 +208,19 @@ public Boolean checkFileSourceAlias(Long appId, String alias, Integer fileSource } return false; } + + @Override + public boolean existsCode(String code) { + return fileSourceDAO.existsCode(code); + } + + @Override + public boolean existsFileSource(Long appId, Integer id) { + return fileSourceDAO.existsFileSource(appId, id); + } + + @Override + public Integer getFileSourceIdByCode(Long appId, String code) { + return fileSourceDAO.getFileSourceIdByCode(appId, code); + } } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceTaskServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceTaskServiceImpl.java index 72a7b2d385..f6d6b3b7c7 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceTaskServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceTaskServiceImpl.java @@ -55,14 +55,19 @@ import com.tencent.bk.job.file_gateway.service.listener.FileTaskStatusChangeListener; import com.tencent.bk.job.file_gateway.service.remote.FileSourceTaskReqGenService; import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; -import com.tencent.bk.job.logsvr.model.service.ServiceLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; import lombok.extern.slf4j.Slf4j; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Slf4j @Service @@ -182,11 +187,11 @@ private void writeLog(FileSourceTaskDTO fileSourceTaskDTO, FileWorkerDTO fileWor String downloadPath, Long fileSize, String speed, Integer progress, String content) { String taskId = fileSourceTaskDTO.getId(); String fileSizeStr = FileSizeUtil.getFileSizeStr(fileSize); - ServiceLogDTO serviceLogDTO = new ServiceLogDTO(); - serviceLogDTO.setStepInstanceId(fileSourceTaskDTO.getStepInstanceId()); - serviceLogDTO.setExecuteCount(fileSourceTaskDTO.getExecuteCount()); + ServiceIpLogDTO serviceIpLogDTO = new ServiceIpLogDTO(); + serviceIpLogDTO.setStepInstanceId(fileSourceTaskDTO.getStepInstanceId()); + serviceIpLogDTO.setExecuteCount(fileSourceTaskDTO.getExecuteCount()); String sourceIp = fileWorkerDTO.getCloudAreaId().toString() + ":" + fileWorkerDTO.getInnerIp(); - serviceLogDTO.setIp(sourceIp); + serviceIpLogDTO.setIp(sourceIp); // 追加文件源名称 // 日志定位坐标:(文件源,文件路径),需要区分不同文件源下相同文件路径的日志 FileSourceDTO fileSourceDTO = fileSourceDAO.getFileSourceById(dslContext, fileSourceTaskDTO.getFileSourceId()); @@ -206,9 +211,9 @@ private void writeLog(FileSourceTaskDTO fileSourceTaskDTO, FileWorkerDTO fileWor serviceFileTaskLogDTO.setStatus(FileDistStatusEnum.PULLING.getValue()); serviceFileTaskLogDTO.setStatusDesc(FileDistStatusEnum.PULLING.getName()); fileTaskLogs.add(serviceFileTaskLogDTO); - serviceLogDTO.setFileTaskLogs(fileTaskLogs); + serviceIpLogDTO.setFileTaskLogs(fileTaskLogs); // 写入Redis - redisTemplate.opsForList().rightPush(PREFIX_REDIS_TASK_LOG + taskId, serviceLogDTO); + redisTemplate.opsForList().rightPush(PREFIX_REDIS_TASK_LOG + taskId, serviceIpLogDTO); // 一小时后过期 redisTemplate.expireAt(PREFIX_REDIS_TASK_LOG + taskId, new Date(System.currentTimeMillis() + 3600 * 1000)); } @@ -320,7 +325,7 @@ public FileSourceTaskStatusDTO getFileSourceTaskStatusAndLogs(String taskId, Lon logEnd = logSize; } log.debug("logStart={},logEnd={}", logStart, logEnd); - List logDTOList = redisTemplate.opsForList().range(PREFIX_REDIS_TASK_LOG + taskId, logStart, + List logDTOList = redisTemplate.opsForList().range(PREFIX_REDIS_TASK_LOG + taskId, logStart, logEnd); log.debug("logDTOList={}", logDTOList); fileSourceTaskStatusDTO.setLogList(logDTOList); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/FileSourceReqGenService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/FileSourceReqGenService.java index 35131fa337..85988d99a7 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/FileSourceReqGenService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/FileSourceReqGenService.java @@ -34,15 +34,21 @@ * 远程文件源请求生成 */ public interface FileSourceReqGenService { + + /** + * 生成FileAvailable请求 + */ + HttpReq genFileAvailableReq(Long appId, FileWorkerDTO fileWorkerDTO, FileSourceDTO fileSourceDTO); + /** - * 生成ListBucket请求 - * - * @param fileWorkerDTO - * @return + * 生成ListFileNode请求 */ HttpReq genListFileNodeReq(Long appId, String path, String name, Integer start, Integer pageSize, FileWorkerDTO fileWorkerDTO, FileSourceDTO fileSourceDTO); + /** + * 生成ExecuteAction请求 + */ HttpReq genExecuteActionReq(Long appId, String actionCode, Map actionParams, FileWorkerDTO fileWorkerDTO, FileSourceDTO fileSourceDTO); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/BaseRemoteFileReqGenServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/BaseRemoteFileReqGenServiceImpl.java index c5c7c12fb9..0fdbbddeb8 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/BaseRemoteFileReqGenServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/BaseRemoteFileReqGenServiceImpl.java @@ -30,7 +30,7 @@ import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; import com.tencent.bk.job.file_gateway.model.dto.FileWorkerDTO; import com.tencent.bk.job.file_gateway.service.CredentialService; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -55,14 +55,14 @@ protected String fillBaseReqGetUrl(BaseReq req, Long appId, FileWorkerDTO fileWo FileSourceDTO fileSourceDTO, String url) { String completeUrl = getCompleteUrl(fileWorkerDTO, url); String credentialId = fileSourceDTO.getCredentialId(); - CommonCredentialDTO commonCredentialDTO = null; + CommonCredential commonCredential = null; if (StringUtils.isNotBlank(credentialId)) { - commonCredentialDTO = credentialService.getCredentialById(fileSourceDTO.getAppId(), + commonCredential = credentialService.getCredentialById(fileSourceDTO.getAppId(), fileSourceDTO.getCredentialId()); } - if (commonCredentialDTO != null) { - req.setCredential(commonCredentialDTO); - log.debug("Credential of id {} is {}", credentialId, commonCredentialDTO); + if (commonCredential != null) { + req.setCredential(commonCredential); + log.debug("Credential of id {} is {}", credentialId, commonCredential); } else if (StringUtils.isNotBlank(credentialId)) { log.warn("Cannot find credential by id {}", credentialId); } diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/FileSourceReqGenServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/FileSourceReqGenServiceImpl.java index ccf7837637..dc47f5b09e 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/FileSourceReqGenServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/remote/impl/FileSourceReqGenServiceImpl.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.file_gateway.service.remote.impl; import com.tencent.bk.job.common.model.http.HttpReq; +import com.tencent.bk.job.file.worker.model.req.BaseReq; import com.tencent.bk.job.file.worker.model.req.ExecuteActionReq; import com.tencent.bk.job.file.worker.model.req.ListFileNodeReq; import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; @@ -45,6 +46,13 @@ public FileSourceReqGenServiceImpl(CredentialService credentialService) { super(credentialService); } + @Override + public HttpReq genFileAvailableReq(Long appId, FileWorkerDTO fileWorkerDTO, FileSourceDTO fileSourceDTO) { + BaseReq req = new BaseReq(); + String url = fillBaseReqGetUrl(req, appId, fileWorkerDTO, fileSourceDTO, "/file/available"); + return genRemoteFileReq(url, req); + } + @Override public HttpReq genListFileNodeReq(Long appId, String path, String name, Integer start, Integer pageSize, FileWorkerDTO fileWorkerDTO, FileSourceDTO fileSourceDTO) { diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/task/filesource/FileSourceStatusUpdateTask.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/task/filesource/FileSourceStatusUpdateTask.java index 2deab3bcfe..ecbc9419c6 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/task/filesource/FileSourceStatusUpdateTask.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/task/filesource/FileSourceStatusUpdateTask.java @@ -57,7 +57,13 @@ public void run() { int start = 0; int pageSize = 20; do { - fileSourceDTOList = fileSourceService.listWorkTableFileSource(null, null, null, start, pageSize); + fileSourceDTOList = fileSourceService.listWorkTableFileSource( + null, + null, + null, + start, + pageSize + ); for (FileSourceDTO fileSourceDTO : fileSourceDTOList) { FileWorkerDTO fileWorkerDTO = dispatchService.findBestFileWorker(fileSourceDTO); int status; @@ -70,9 +76,12 @@ public void run() { } else { // 通过Worker调用listFileNode接口,OK的才算正常 try { - fileService.listFileNode(fileSourceDTO.getCreator(), fileSourceDTO.getAppId(), - fileSourceDTO.getId(), null, null, 0, 1); - status = 1; + if (fileService.isFileAvailable(fileSourceDTO.getCreator(), fileSourceDTO.getAppId(), + fileSourceDTO.getId())) { + status = 1; + } else { + status = 0; + } } catch (Throwable t) { status = 0; } diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/build.gradle b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/build.gradle index d2c0e85ecb..141296cda1 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/build.gradle +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/build.gradle @@ -23,9 +23,9 @@ */ dependencies { - compile project(':commons:common') - compile project(':job-ticket:api-job-ticket-pojo') - compile project(':job-file-gateway:api-job-file-gateway-worker') + api project(':commons:common') + api project(':job-ticket:api-job-ticket-pojo') + api project(':job-file-gateway:api-job-file-gateway-worker') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" } diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResource.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResource.java index 80dc810e6c..bae8a170eb 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResource.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResource.java @@ -24,7 +24,9 @@ package com.tencent.bk.job.file.worker.api; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.file.worker.model.req.BaseReq; import com.tencent.bk.job.file.worker.model.req.ExecuteActionReq; import com.tencent.bk.job.file.worker.model.req.ListFileNodeReq; import com.tencent.bk.job.file_gateway.model.resp.common.FileNodesDTO; @@ -40,8 +42,14 @@ @Api(tags = {"job-file-worker:api:File"}) @RequestMapping("/worker/api/file") @RestController +@InternalAPI public interface FileResource { + @ApiOperation(value = "测试文件源是否可用", produces = "application/json") + @PostMapping("/available") + ServiceResponse isFileAvailable( + @ApiParam(value = "文件源是否可用", required = true) @RequestBody BaseReq req); + @ApiOperation(value = "获取文件源/FileNode下的子FileNode列表", produces = "application/json") @PostMapping("/listFileNode") ServiceResponse listFileNode( diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileTaskResource.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileTaskResource.java index be5d3f49c5..d3daeb6687 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileTaskResource.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileTaskResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.file.worker.api; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file.worker.model.req.ClearTaskFilesReq; import com.tencent.bk.job.file.worker.model.req.DownloadFilesTaskReq; @@ -39,6 +40,7 @@ @Api(tags = {"job-file-worker:api:FileTask"}) @RequestMapping("/worker/api/filetask") @RestController +@InternalAPI public interface FileTaskResource { // 子路径与gateway转发请求子路径保持一致 diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/OpResource.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/OpResource.java index b4a238359a..9b5bb3adeb 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/OpResource.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/OpResource.java @@ -24,18 +24,24 @@ package com.tencent.bk.job.file.worker.api; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.file.worker.model.req.WorkerOffLineReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-file-worker:api:OP"}) @RequestMapping("/worker/api/op") @RestController +@InternalAPI public interface OpResource { @ApiOperation(value = "Worker下线", produces = "application/json") diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java index 322eeb8b3c..dc4e2ab5a9 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.file.worker.model.req; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import lombok.Data; import lombok.EqualsAndHashCode; @@ -38,7 +38,7 @@ public class BaseReq { String fileSourceTypeCode; // 凭据信息 - CommonCredentialDTO credential; + CommonCredential credential; // 文件源信息Map Map fileSourceInfoMap; diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/ListFileNodeReq.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/ListFileNodeReq.java index 444d4b3e4f..3257cce07d 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/ListFileNodeReq.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/ListFileNodeReq.java @@ -42,4 +42,10 @@ public class ListFileNodeReq extends BaseReq { String name; Integer start; Integer pageSize; + + public ListFileNodeReq(BaseReq req) { + this.setCredential(req.getCredential()); + this.setFileSourceTypeCode(req.getFileSourceTypeCode()); + this.setFileSourceInfoMap(req.getFileSourceInfoMap()); + } } diff --git a/src/backend/job-file-worker-sdk/boot-job-file-worker-sdk/build.gradle b/src/backend/job-file-worker-sdk/boot-job-file-worker-sdk/build.gradle index ee457e78e3..f843f373b9 100644 --- a/src/backend/job-file-worker-sdk/boot-job-file-worker-sdk/build.gradle +++ b/src/backend/job-file-worker-sdk/boot-job-file-worker-sdk/build.gradle @@ -30,7 +30,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' } springBoot { - mainClassName = "com.tencent.bk.job.file.worker.JobFileWorkerBootApplication" + mainClass = "com.tencent.bk.job.file.worker.JobFileWorkerBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-file-worker-sdk/build.gradle b/src/backend/job-file-worker-sdk/build.gradle index 552871b9b7..7f2da7c49f 100644 --- a/src/backend/job-file-worker-sdk/build.gradle +++ b/src/backend/job-file-worker-sdk/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobFileWorkerSdkVersion")) { set("jobFileWorkerSdkVersion", System.getProperty("jobFileWorkerSdkVersion")) + } else if (System.getProperty("version")) { + set("jobFileWorkerSdkVersion", System.getProperty("version")) } else { set("jobFileWorkerSdkVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobFileWorkerSdkVersion}" subprojects { version "${jobFileWorkerSdkVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/build.gradle b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/build.gradle index 91234bb2ce..ea9575398e 100644 --- a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/build.gradle +++ b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/build.gradle @@ -23,8 +23,8 @@ */ dependencies { - compile project(":commons:common-i18n") - compile project(":job-file-worker-sdk:api-job-file-worker-sdk") + api project(":commons:common-i18n") + api project(":job-file-worker-sdk:api-job-file-worker-sdk") implementation "org.springframework.boot:spring-boot-starter-web" implementation "ch.qos.logback:logback-core" implementation "ch.qos.logback:logback-classic" diff --git a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceImpl.java b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceImpl.java index 84b1a21b60..272e0d8f4c 100644 --- a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceImpl.java +++ b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceImpl.java @@ -26,6 +26,7 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.job.file.worker.model.req.BaseReq; import com.tencent.bk.job.file.worker.model.req.ExecuteActionReq; import com.tencent.bk.job.file.worker.model.req.ListFileNodeReq; import com.tencent.bk.job.file_gateway.model.resp.common.FileNodesDTO; @@ -45,6 +46,11 @@ protected FileResourceImpl(IFileResource fileResource) { this.fileResource = fileResource; } + @Override + public ServiceResponse isFileAvailable(BaseReq req) { + return fileResource.isFileAvailable(req); + } + @Override public ServiceResponse listFileNode(ListFileNodeReq req) { log.info("req={}", JsonUtils.toJson(req)); diff --git a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/IFileResource.java b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/IFileResource.java index 3afcc64f01..ee19270f40 100644 --- a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/IFileResource.java +++ b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/api/IFileResource.java @@ -35,6 +35,8 @@ public interface IFileResource { RemoteClient getRemoteClient(BaseReq req); + ServiceResponse isFileAvailable(BaseReq req); + ServiceResponse listFileNode(ListFileNodeReq req); ServiceResponse executeAction(ExecuteActionReq req); diff --git a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/config/ExceptionControllerAdvice.java b/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/config/ExceptionControllerAdvice.java deleted file mode 100644 index 9398f32b7f..0000000000 --- a/src/backend/job-file-worker-sdk/service-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/config/ExceptionControllerAdvice.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.file.worker.config; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.model.ServiceResponse; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MaxUploadSizeExceededException; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice({"com.tencent.bk.job.file.worker.api"}) -@Slf4j -public class ExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - - @Autowired - public ExceptionControllerAdvice(MessageI18nService i18nService) { - this.i18nService = i18nService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.error("Handle service exception", ex); - if (ex != null) { - if (ex.getErrorCode() > 0) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorCode(), - ex.getErrorParams(), i18nService), HttpStatus.OK); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorMsg()), HttpStatus.OK); - } - } else { - // 通用处理 - HttpStatus commonStatus = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), commonStatus); - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.error("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - @ExceptionHandler(MaxUploadSizeExceededException.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, MaxUploadSizeExceededException ex) { - log.error("Handle MaxUploadSizeExceededException, maxFileSize:{}", ex.getMaxUploadSize()); - long maxFileSize = ex.getMaxUploadSize(); - String fileSizeDesc = (maxFileSize << 20) + "G"; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.UPLOAD_FILE_MAX_SIZE_EXCEEDED, - new String[]{fileSizeDesc}, i18nService), - HttpStatus.OK); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } -} diff --git a/src/backend/job-file-worker/api-job-file-worker/build.gradle b/src/backend/job-file-worker/api-job-file-worker/build.gradle index 3912b3643b..0bad34da0e 100644 --- a/src/backend/job-file-worker/api-job-file-worker/build.gradle +++ b/src/backend/job-file-worker/api-job-file-worker/build.gradle @@ -23,8 +23,8 @@ */ dependencies { - compile project(':commons:common') - compile project(':job-file-gateway:api-job-file-gateway-worker') + api project(':commons:common') + api project(':job-file-gateway:api-job-file-gateway-worker') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" } diff --git a/src/backend/job-file-worker/boot-job-file-worker/build.gradle b/src/backend/job-file-worker/boot-job-file-worker/build.gradle index 083cd8b67c..f1a2dc21e2 100644 --- a/src/backend/job-file-worker/boot-job-file-worker/build.gradle +++ b/src/backend/job-file-worker/boot-job-file-worker/build.gradle @@ -29,9 +29,10 @@ dependencies { implementation project(":job-file-worker-sdk:boot-job-file-worker-sdk") implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' } springBoot { - mainClassName = "com.tencent.bk.job.file.worker.JobFileWorkerBootApplication" + mainClass = "com.tencent.bk.job.file.worker.JobFileWorkerBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-file-worker/boot-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/I18nConfig.java b/src/backend/job-file-worker/boot-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/I18nConfig.java deleted file mode 100644 index 685ac7fb2a..0000000000 --- a/src/backend/job-file-worker/boot-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/I18nConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.file.worker; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import com.tencent.bk.job.common.i18n.locale.LocaleUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName(LocaleUtils.COMMON_LANG_HEADER); - return interceptor; - } - -} diff --git a/src/backend/job-file-worker/boot-job-file-worker/src/main/resources/FileWorkerConfig.json b/src/backend/job-file-worker/boot-job-file-worker/src/main/resources/FileWorkerConfig.json index 420f318c78..8a721a2fdb 100644 --- a/src/backend/job-file-worker/boot-job-file-worker/src/main/resources/FileWorkerConfig.json +++ b/src/backend/job-file-worker/boot-job-file-worker/src/main/resources/FileWorkerConfig.json @@ -8,14 +8,14 @@ "iconPath": "tencent_cloud.png", "staticParamList": [ { - "name": "endPointDomain", + "name": "end_point_domain", "label": "EndPoint", "required": true, "type": "TextInput", "default": "" }, { - "name": "appId", + "name": "app_id", "label": "APPID", "required": true, "type": "TextInput", @@ -170,7 +170,7 @@ "iconPath": "bk_artifactory.png", "staticParamList": [ { - "name": "baseUrl", + "name": "base_url", "label": "制品库根地址", "required": true, "type": "TextInput", diff --git a/src/backend/job-file-worker/build.gradle b/src/backend/job-file-worker/build.gradle index 86707533a7..7f0946fb86 100644 --- a/src/backend/job-file-worker/build.gradle +++ b/src/backend/job-file-worker/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobFileWorkerVersion")) { set("jobFileWorkerVersion", System.getProperty("jobFileWorkerVersion")) + } else if (System.getProperty("version")) { + set("jobFileWorkerVersion", System.getProperty("version")) } else { set("jobFileWorkerVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobFileWorkerVersion}" subprojects { version "${jobFileWorkerVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-file-worker/service-job-file-worker/build.gradle b/src/backend/job-file-worker/service-job-file-worker/build.gradle index 8b162e1871..37918e9594 100644 --- a/src/backend/job-file-worker/service-job-file-worker/build.gradle +++ b/src/backend/job-file-worker/service-job-file-worker/build.gradle @@ -23,10 +23,10 @@ */ dependencies { - compile(files("libs/innercos-java-sdk-5.6.9.jar")) - compile project(":job-file-worker:api-job-file-worker") - compile project(":job-file-worker-sdk:api-job-file-worker-sdk") - compile project(":job-file-worker-sdk:service-job-file-worker-sdk") + api(files("libs/innercos-java-sdk-5.6.9.jar")) + api project(":job-file-worker:api-job-file-worker") + api project(":job-file-worker-sdk:api-job-file-worker-sdk") + api project(":job-file-worker-sdk:service-job-file-worker-sdk") implementation "org.springframework.boot:spring-boot-starter-web" implementation "ch.qos.logback:logback-core" implementation "ch.qos.logback:logback-classic" diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceProxy.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceProxy.java index ca59790ac4..2996956412 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceProxy.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/api/FileResourceProxy.java @@ -69,6 +69,11 @@ public RemoteClient getRemoteClient(BaseReq req) { return chooseFileResource(req).getRemoteClient(req); } + @Override + public ServiceResponse isFileAvailable(BaseReq req) { + return chooseFileResource(req).isFileAvailable(req); + } + @Override public ServiceResponse listFileNode(ListFileNodeReq req) { return chooseFileResource(req).listFileNode(req); diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/impl/ArtifactoryFileResourceImpl.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/impl/ArtifactoryFileResourceImpl.java index b3c66675b6..f8225a55ab 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/impl/ArtifactoryFileResourceImpl.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/impl/ArtifactoryFileResourceImpl.java @@ -75,6 +75,12 @@ public RemoteClient getRemoteClient(BaseReq req) { return baseService.getArtifactoryClientFromBaseReq(req); } + @Override + public ServiceResponse isFileAvailable(BaseReq req) { + ArtifactoryRemoteClient client = baseService.getArtifactoryClientFromBaseReq(req); + return ServiceResponse.buildSuccessResp(client.isAvailable()); + } + private String parseParentNodeTypeByPath(String path) { if (StringUtils.isBlank(path)) return ArtifactoryNodeTypeEnum.FILE_SOURCE.name(); path = StringUtil.removePrefix(path, "/"); diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/model/req/DeleteRepoReq.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/model/req/DeleteRepoReq.java index 5fb9e50ea9..0c618c6acc 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/model/req/DeleteRepoReq.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/model/req/DeleteRepoReq.java @@ -25,8 +25,10 @@ package com.tencent.bk.job.file.worker.artifactory.model.req; import lombok.Data; +import lombok.EqualsAndHashCode; @Data +@EqualsAndHashCode(callSuper=false) public class DeleteRepoReq extends ArtifactoryReq { // 必传,项目Id String projectId; diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryBaseService.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryBaseService.java index 14055554db..992dcb2307 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryBaseService.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryBaseService.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.file.worker.artifactory.service; import com.tencent.bk.job.file.worker.model.req.BaseReq; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,9 +43,9 @@ public ArtifactoryBaseService(MeterRegistry meterRegistry) { } public ArtifactoryRemoteClient getArtifactoryClientFromBaseReq(BaseReq req) { - CommonCredentialDTO credential = req.getCredential(); + CommonCredential credential = req.getCredential(); Map fileSourceInfoMap = req.getFileSourceInfoMap(); - return new ArtifactoryRemoteClient((String) fileSourceInfoMap.get("baseUrl"), credential.getUsername(), + return new ArtifactoryRemoteClient((String) fileSourceInfoMap.get("base_url"), credential.getUsername(), credential.getPassword(), meterRegistry); } } diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryRemoteClient.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryRemoteClient.java index 31723c8f77..c513fe83b1 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryRemoteClient.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/artifactory/service/ArtifactoryRemoteClient.java @@ -34,8 +34,19 @@ import com.tencent.bk.job.common.util.http.LongRetryableHttpHelper; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.file.worker.artifactory.consts.ArtifactoryInterfaceConsts; -import com.tencent.bk.job.file.worker.artifactory.model.dto.*; -import com.tencent.bk.job.file.worker.artifactory.model.req.*; +import com.tencent.bk.job.file.worker.artifactory.model.dto.ArtifactoryResp; +import com.tencent.bk.job.file.worker.artifactory.model.dto.NodeDTO; +import com.tencent.bk.job.file.worker.artifactory.model.dto.PageData; +import com.tencent.bk.job.file.worker.artifactory.model.dto.ProjectDTO; +import com.tencent.bk.job.file.worker.artifactory.model.dto.RepoDTO; +import com.tencent.bk.job.file.worker.artifactory.model.req.ArtifactoryReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.DeleteNodeReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.DeleteRepoReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.DownloadGenericFileReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.ListNodePageReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.ListProjectReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.ListRepoPageReq; +import com.tencent.bk.job.file.worker.artifactory.model.req.QueryNodeDetailReq; import com.tencent.bk.job.file.worker.cos.service.RemoteClient; import com.tencent.bk.job.file.worker.model.FileMetaData; import io.micrometer.core.instrument.MeterRegistry; @@ -52,11 +63,13 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; @Slf4j public class ArtifactoryRemoteClient implements RemoteClient { + public static final String URL_ACTUATOR_INFO = "/repository/actuator/info"; public static final String URL_LIST_PROJECT = "/repository/api/project/list"; public static final String URL_LIST_REPO_PAGE = "/repository/api/repo/page/{projectId}/{pageNumber}/{pageSize}"; public static final String URL_LIST_NODE_PAGE = "/repository/api/node/page/{projectId}/{repoName}/{fullPath}"; @@ -154,34 +167,36 @@ private R getArtifactoryRespByReq( log.debug("success|method={}|url={}|reqStr={}|respStr={}", method, url, reqStr, respStr); } R result = JsonUtils.fromJson(respStr, typeReference); - ArtifactoryResp artifactoryResp = (ArtifactoryResp) result; - if (artifactoryResp == null) { - log.error("fail:artifactoryResp is null after parse|method={}|url={}|reqStr={}|respStr={}", method, - url, reqStr, respStr); - status = "error"; - throw new ServiceException(ErrorCode.ARTIFACTORY_API_DATA_ERROR, "artifactoryResp is null after parse"); - } else if (artifactoryResp.getCode() != ArtifactoryInterfaceConsts.RESULT_CODE_OK) { - log.error( - "fail:artifactoryResp code!={}|artifactoryResp.requestId={}|artifactoryResp" + - ".code={}|artifactoryResp.message={}|method={}|url={}|reqStr={}|respStr={}" - , ArtifactoryInterfaceConsts.RESULT_CODE_OK - , artifactoryResp.getTraceId() - , artifactoryResp.getCode() - , artifactoryResp.getMessage() - , method, url, reqStr, respStr - ); - status = "error"; - throw new ServiceException(ErrorCode.ARTIFACTORY_API_DATA_ERROR, "artifactoryResp code!=0"); - } - if (artifactoryResp.getData() == null) { - log.warn( - "warn:artifactoryResp.getData() == null|artifactoryResp.requestId={}|artifactoryResp" + - ".code={}|artifactoryResp.message={}|method={}|url={}|reqStr={}|respStr={}" - , artifactoryResp.getTraceId() - , artifactoryResp.getCode() - , artifactoryResp.getMessage() - , method, url, reqStr, respStr - ); + if (result instanceof ArtifactoryResp) { + ArtifactoryResp artifactoryResp = (ArtifactoryResp) result; + if (artifactoryResp == null) { + log.error("fail:artifactoryResp is null after parse|method={}|url={}|reqStr={}|respStr={}", method, + url, reqStr, respStr); + status = "error"; + throw new ServiceException(ErrorCode.ARTIFACTORY_API_DATA_ERROR, "artifactoryResp is null after parse"); + } else if (artifactoryResp.getCode() != ArtifactoryInterfaceConsts.RESULT_CODE_OK) { + log.error( + "fail:artifactoryResp code!={}|artifactoryResp.requestId={}|artifactoryResp" + + ".code={}|artifactoryResp.message={}|method={}|url={}|reqStr={}|respStr={}" + , ArtifactoryInterfaceConsts.RESULT_CODE_OK + , artifactoryResp.getTraceId() + , artifactoryResp.getCode() + , artifactoryResp.getMessage() + , method, url, reqStr, respStr + ); + status = "error"; + throw new ServiceException(ErrorCode.ARTIFACTORY_API_DATA_ERROR, "artifactoryResp code!=0"); + } + if (artifactoryResp.getData() == null) { + log.warn( + "warn:artifactoryResp.getData() == null|artifactoryResp.requestId={}|artifactoryResp" + + ".code={}|artifactoryResp.message={}|method={}|url={}|reqStr={}|respStr={}" + , artifactoryResp.getTraceId() + , artifactoryResp.getCode() + , artifactoryResp.getMessage() + , method, url, reqStr, respStr + ); + } } status = "ok"; return result; @@ -198,10 +213,21 @@ private R getArtifactoryRespByReq( } } + public boolean isAvailable() { + try { + getArtifactoryRespByReq(HttpGet.METHOD_NAME, URL_ACTUATOR_INFO, + new ArtifactoryReq(), new TypeReference>() { + }, httpHelper); + return true; + } catch (Throwable t) { + return false; + } + } + public List listProject() { ArtifactoryResp> resp = getArtifactoryRespByReq(HttpGet.METHOD_NAME, URL_LIST_PROJECT, new ListProjectReq(), new TypeReference>>() { - }, httpHelper); + }, httpHelper); return resp.getData(); } @@ -213,7 +239,7 @@ public PageData listRepo(String projectId, String name, int pageNumber, req.setPageSize(pageSize); ArtifactoryResp> resp = getArtifactoryRespByReq(HttpGet.METHOD_NAME, URL_LIST_REPO_PAGE, req, new TypeReference>>() { - }, httpHelper); + }, httpHelper); return resp.getData(); } @@ -227,7 +253,7 @@ public PageData listNode(String projectId, String repoName, String full req.setPageSize(pageSize); ArtifactoryResp> resp = getArtifactoryRespByReq(HttpGet.METHOD_NAME, URL_LIST_NODE_PAGE, req, new TypeReference>>() { - }, httpHelper); + }, httpHelper); return resp.getData(); } @@ -238,7 +264,7 @@ public NodeDTO queryNodeDetail(String projectId, String repoName, String fullPat req.setFullPath(fullPath); ArtifactoryResp resp = getArtifactoryRespByReq(HttpGet.METHOD_NAME, URL_QUERY_NODE_DETAIL, req, new TypeReference>() { - }, httpHelper); + }, httpHelper); return resp.getData(); } @@ -253,7 +279,7 @@ public Boolean deleteRepo(String projectId, String repoName, Boolean forced) { req.setForced(forced); ArtifactoryResp resp = getArtifactoryRespByReq(HttpDelete.METHOD_NAME, URL_DELETE_REPO, req, new TypeReference>() { - }, httpHelper); + }, httpHelper); return resp.getCode() == 0; } @@ -264,7 +290,7 @@ public Boolean deleteNode(String projectId, String repoName, String fullPath) { req.setFullPath(fullPath); ArtifactoryResp resp = getArtifactoryRespByReq(HttpDelete.METHOD_NAME, URL_DELETE_NODE, req, new TypeReference>() { - }, httpHelper); + }, httpHelper); return resp.getCode() == 0; } diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/impl/COSFileResourceImpl.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/impl/COSFileResourceImpl.java index 84a5afa26b..0446d8c032 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/impl/COSFileResourceImpl.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/impl/COSFileResourceImpl.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.file.worker.cos.impl; -import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; import com.tencent.bk.job.common.model.ServiceResponse; @@ -32,7 +31,6 @@ import com.tencent.bk.job.common.util.StringUtil; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.common.util.file.PathUtil; -import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.file.worker.api.IFileResource; import com.tencent.bk.job.file.worker.cos.JobTencentInnerCOSClient; import com.tencent.bk.job.file.worker.cos.consts.COSActionCodeEnum; @@ -48,7 +46,6 @@ import com.tencent.bk.job.file.worker.model.req.ListFileNodeReq; import com.tencent.bk.job.file_gateway.model.resp.common.FileNodesDTO; import com.tencent.bk.job.file_gateway.model.resp.common.FileTreeNodeDef; -import com.tencent.bk.job.file_gateway.model.resp.common.FileVO; import com.tencent.cos.model.Bucket; import com.tencent.cos.model.COSObjectSummary; import io.micrometer.core.instrument.util.StringUtils; @@ -207,6 +204,21 @@ public RemoteClient getRemoteClient(BaseReq req) { return new COSRemoteClient(jobTencentInnerCOSClient); } + @Override + public ServiceResponse isFileAvailable(BaseReq req) { + try { + ListFileNodeReq listFileNodeReq = new ListFileNodeReq(req); + listFileNodeReq.setPath(""); + listFileNodeReq.setName(""); + listFileNodeReq.setStart(0); + listFileNodeReq.setPageSize(1); + listBucket(listFileNodeReq); + return ServiceResponse.buildSuccessResp(true); + } catch (Throwable t) { + return ServiceResponse.buildSuccessResp(false); + } + } + private String getTypeFromFileName(String fileName) { if (StringUtils.isBlank(fileName)) { return "UNKNOWN"; @@ -233,39 +245,6 @@ private Boolean isDir(String fileName) { return fileName.endsWith("/"); } - private List parseBucketFileList(String bucketName, String path, String respStr) { - ServiceResponse> resp = null; - if (path == null) { - path = ""; - } - try { - resp = JsonUtils.fromJson(respStr, new TypeReference>>() { - }); - } catch (Exception e) { - log.error("Fail to parse bucket file from response={}", respStr, e); - throw new ServiceException(ErrorCode.FAIL_TO_REQUEST_FILE_WORKER_LIST_OBJECTS, resp.getErrorMsg()); - } - if (resp.isSuccess()) { - List fileVOList = new ArrayList<>(); - List fileDTOList = resp.getData(); - for (FileDTO fileDTO : fileDTOList) { - FileVO fileVO = new FileVO(); - fileVO.setName(fileDTO.getKey()); - fileVO.setCompletePath(bucketName + "/" + path + fileDTO.getKey()); - fileVO.setSize(fileDTO.getSize()); - fileVO.setDir(isDir(fileDTO.getKey())); - fileVO.setType(getTypeFromFileName(fileDTO.getKey())); - fileVO.setDownloadUrl(fileDTO.getDownloadUrl()); - fileVO.setLastModifyTime(fileDTO.getLastModified()); - fileVOList.add(fileVO); - } - return fileVOList; - } else { - log.error("get failed bucket file response={}", respStr); - throw new ServiceException(resp.getCode(), resp.getErrorMsg()); - } - } - private int getSlashNum(String str) { if (StringUtils.isBlank(str)) return 0; int count = 0; @@ -342,7 +321,7 @@ private void fillFileFileNodesDTO(FileNodesDTO fileNodesDTO, ListFileNodeReq req Map map = new HashMap<>(); String fileName = fileDTO.getKey(); map.put("name", fileName); - map.put("type", "文本文件"); + map.put("type", getTypeFromFileName(fileName)); map.put("updateTime", DateUtils.formatUnixTimestamp(fileDTO.getLastModified(), ChronoUnit.MILLIS)); map.put("completePath", PathUtil.joinFilePath(req.getPath(), fileName)); map.put("dir", isDir(fileName)); diff --git a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/service/COSBaseService.java b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/service/COSBaseService.java index c9c9402d6d..53059afced 100644 --- a/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/service/COSBaseService.java +++ b/src/backend/job-file-worker/service-job-file-worker/src/main/java/com/tencent/bk/job/file/worker/cos/service/COSBaseService.java @@ -26,25 +26,28 @@ import com.tencent.bk.job.file.worker.cos.JobTencentInnerCOSClient; import com.tencent.bk.job.file.worker.model.req.BaseReq; -import com.tencent.bk.job.ticket.model.credential.CommonCredentialDTO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Map; +@Slf4j @Service public class COSBaseService { public JobTencentInnerCOSClient getCOSClientFromBaseReq(BaseReq req) { // endPointDomain // appId - CommonCredentialDTO credential = req.getCredential(); + CommonCredential credential = req.getCredential(); Map fileSourceInfoMap = req.getFileSourceInfoMap(); + log.debug("req={}", req); return new JobTencentInnerCOSClient(credential.getAccessKey(), credential.getSecretKey(), - getEndPointDomain(req), fileSourceInfoMap.get("appId").toString()); + getEndPointDomain(req), fileSourceInfoMap.get("app_id").toString()); } public String getEndPointDomain(BaseReq req) { Map fileSourceInfoMap = req.getFileSourceInfoMap(); - return (String) (fileSourceInfoMap.get("endPointDomain")); + return (String) (fileSourceInfoMap.get("end_point_domain")); } } diff --git a/src/backend/job-gateway/build.gradle b/src/backend/job-gateway/build.gradle index f01e54c7d8..51e146759d 100644 --- a/src/backend/job-gateway/build.gradle +++ b/src/backend/job-gateway/build.gradle @@ -25,17 +25,19 @@ ext { if (System.getProperty("jobGatewayVersion")) { set("jobGatewayVersion", System.getProperty("jobGatewayVersion")) + } else if (System.getProperty("version")) { + set("jobGatewayVersion", System.getProperty("version")) } else { set("jobGatewayVersion", "1.0.0") } } version "${jobGatewayVersion}" dependencies { - compile project(':commons:common') - compile project(":commons:common-i18n") - compile project(":commons:common-security") - compile project(":commons:common-spring-ext") - compile project(":commons:paas-sdk") + api project(':commons:common') + api project(":commons:common-i18n") + api project(":commons:common-security") + api project(":commons:common-spring-ext") + api project(":commons:paas-sdk") implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation("org.springframework.boot:spring-boot-autoconfigure") @@ -47,6 +49,7 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation 'org.springframework.cloud:spring-cloud-starter-sleuth' implementation 'com.fasterxml.jackson.core:jackson-core' implementation 'com.fasterxml.jackson.core:jackson-databind' @@ -55,18 +58,27 @@ dependencies { implementation 'commons-io:commons-io' implementation 'io.jsonwebtoken:jjwt' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'joda-time:joda-time' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } apply plugin: 'org.springframework.boot' springBoot { - mainClassName = "com.tencent.bk.job.gateway.JobGatewayBootApplication" + mainClass = "com.tencent.bk.job.gateway.JobGatewayBootApplication" buildInfo() } test { useJUnitPlatform() } apply from: "$rootDir/task_job_package.gradle" +task copyToLatestJar(type: Copy) { + group = "local" + from('build/libs') + include "job-gateway-${version}.jar" + destinationDir file('build/libs/') + rename "job-gateway-${version}.jar", "job-gateway.jar" +} +copyToLatestJar.dependsOn assemble diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/JobGatewayBootApplication.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/JobGatewayBootApplication.java index 6ddbcae2b9..44fdc02779 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/JobGatewayBootApplication.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/JobGatewayBootApplication.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.gateway; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -43,8 +45,9 @@ @SpringBootApplication(scanBasePackages = "com.tencent.bk.job") @EnableDiscoveryClient @EnableFeignClients +@Slf4j public class JobGatewayBootApplication { - private final HttpHandler httpHandler; + private HttpHandler httpHandler; private WebServer httpWebServer; @@ -54,8 +57,7 @@ public class JobGatewayBootApplication { @Value("${server.http.port:}") private Integer httpPort; - - public JobGatewayBootApplication(HttpHandler httpHandler) { + public JobGatewayBootApplication(@Autowired HttpHandler httpHandler) { this.httpHandler = httpHandler; } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/common/exception/JsonExceptionHandler.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/common/exception/JsonExceptionHandler.java index 5ae80c7a88..e89e113c31 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/common/exception/JsonExceptionHandler.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/common/exception/JsonExceptionHandler.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.gateway.common.exception; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.json.JsonUtils; import lombok.extern.slf4j.Slf4j; diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/LocaleSupportConfig.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/LocaleSupportConfig.java new file mode 100644 index 0000000000..b081a902b3 --- /dev/null +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/LocaleSupportConfig.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.gateway.config; + +import com.tencent.bk.job.gateway.i18n.JobLangHeaderLocaleContextResolver; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration; +import org.springframework.web.server.i18n.LocaleContextResolver; + +import java.util.Locale; + +@Configuration +public class LocaleSupportConfig extends DelegatingWebFluxConfiguration { + @Bean("localeContextResolver") + @ConditionalOnClass(LocaleContextResolver.class) + public JobLangHeaderLocaleContextResolver localeContextResolver() { + JobLangHeaderLocaleContextResolver resolver = new JobLangHeaderLocaleContextResolver(); + resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); + return resolver; + } + + @Override + protected LocaleContextResolver createLocaleContextResolver() { + return localeContextResolver(); + } +} diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/RouteConfig.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/RouteConfig.java index ba2137f2f1..c5ed1b2114 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/RouteConfig.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/config/RouteConfig.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.gateway.config; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.BkUserDTO; import com.tencent.bk.job.gateway.web.service.LoginService; diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactory.java deleted file mode 100644 index 393c874e3a..0000000000 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.gateway.filter; - -import com.tencent.bk.job.gateway.service.LicenseCheckService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; -import reactor.core.publisher.Mono; - -/** - * 用户token校验 - */ -@Slf4j -@Component -public class LicenseCheckGatewayFilterFactory - extends AbstractGatewayFilterFactory { - - private final LicenseCheckService licenseCheckService; - - @Autowired - public LicenseCheckGatewayFilterFactory(LicenseCheckService licenseCheckService) { - super(Config.class); - this.licenseCheckService = licenseCheckService; - } - - @Override - public GatewayFilter apply(Config config) { - return this::filter; - } - - public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { - ServerHttpResponse response = exchange.getResponse(); - if (!licenseCheckService.checkLicense().isOk()) { - log.error("Invalid license, reject response!"); - response.setStatusCode(HttpStatus.UNAUTHORIZED); - return response.setComplete(); - } - return chain.filter(exchange); - } - - public static class Config { - } - -} diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbLangHeaderGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbLangHeaderGatewayFilterFactory.java index 40be062817..7a0682533a 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbLangHeaderGatewayFilterFactory.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/AddEsbLangHeaderGatewayFilterFactory.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.gateway.filter.esb; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; import com.tencent.bk.job.common.util.RequestUtil; import com.tencent.bk.job.gateway.common.consts.EsbLangHeader; @@ -55,7 +56,7 @@ public GatewayFilter apply(Config config) { return (exchange, chain) -> { ServerHttpRequest request = exchange.getRequest(); // 从header中获取esb传过来的客户端lang,header名称:Blueking-Language - String esbLangHeaderValue = RequestUtil.getHeaderValue(request, "Blueking-Language"); + String esbLangHeaderValue = RequestUtil.getHeaderValue(request, JobCommonHeaders.BK_GATEWAY_LANG); String commonLang = LocaleUtils.LANG_ZH_CN; if (!StringUtils.isEmpty(esbLangHeaderValue)) { if (esbLangHeaderValue.equalsIgnoreCase(EsbLangHeader.EN)) { diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/CheckEsbJwtGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/CheckEsbJwtGatewayFilterFactory.java index 6dc911d290..216aff2410 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/CheckEsbJwtGatewayFilterFactory.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/CheckEsbJwtGatewayFilterFactory.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.gateway.filter.esb; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.util.RequestUtil; import com.tencent.bk.job.gateway.model.esb.EsbJwtInfo; import com.tencent.bk.job.gateway.service.EsbJwtService; @@ -38,7 +39,7 @@ import org.springframework.stereotype.Component; /** - * ESB JWT 校验,用于确认ESB-API调用方式来自于ESB + * ESB JWT 解析与校验,用于确认ESB-API调用方式来自于ESB */ @Slf4j @Component @@ -57,7 +58,7 @@ public GatewayFilter apply(Config config) { return (exchange, chain) -> { ServerHttpResponse response = exchange.getResponse(); ServerHttpRequest request = exchange.getRequest(); - String token = RequestUtil.getHeaderValue(request, "X-Bkapi-JWT"); + String token = RequestUtil.getHeaderValue(request, JobCommonHeaders.BK_GATEWAY_JWT); if (StringUtils.isEmpty(token)) { log.warn("Esb token is empty!"); response.setStatusCode(HttpStatus.UNAUTHORIZED); @@ -66,10 +67,14 @@ public GatewayFilter apply(Config config) { EsbJwtInfo authInfo = esbJwtService.extractFromJwt(token); if (authInfo == null) { log.warn("Untrusted esb request, request-id:{}", RequestUtil.getHeaderValue(request, - "X-Bkapi-Request-Id")); + JobCommonHeaders.BK_GATEWAY_REQUEST_ID)); response.setStatusCode(HttpStatus.UNAUTHORIZED); return response.setComplete(); } + + // set app code header + request.mutate().header(JobCommonHeaders.APP_CODE, new String[]{authInfo.getAppCode()}).build(); + request.mutate().header(JobCommonHeaders.USERNAME, new String[]{authInfo.getUsername()}).build(); return chain.filter(exchange.mutate().request(request).build()); }; } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/RecordEsbAccessLogGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/RecordEsbAccessLogGatewayFilterFactory.java index e730ae9ad9..604b7c5983 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/RecordEsbAccessLogGatewayFilterFactory.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/esb/RecordEsbAccessLogGatewayFilterFactory.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.gateway.filter.esb; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.util.RequestUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +43,8 @@ public class RecordEsbAccessLogGatewayFilterFactory extends AbstractGatewayFilterFactory { + private static final String ATTR_START_TIME = "start_time"; + @Autowired public RecordEsbAccessLogGatewayFilterFactory() { super(RecordEsbAccessLogGatewayFilterFactory.Config.class); @@ -51,15 +54,15 @@ public RecordEsbAccessLogGatewayFilterFactory() { public GatewayFilter apply(Config config) { return (exchange, chain) -> { ServerHttpRequest request = exchange.getRequest(); - String appCode = RequestUtil.getHeaderValue(request, "Bk-App-Code"); - String username = RequestUtil.getHeaderValue(request, "Bk-Username"); + String appCode = RequestUtil.getHeaderValue(request, JobCommonHeaders.APP_CODE); + String username = RequestUtil.getHeaderValue(request, JobCommonHeaders.USERNAME); String uri = exchange.getRequest().getURI().getPath(); String apiName = getApiNameFromUri(uri); - exchange.getAttributes().put("start_time", System.currentTimeMillis()); + exchange.getAttributes().put(ATTR_START_TIME, System.currentTimeMillis()); return chain.filter(exchange).then(Mono.fromRunnable(() -> { - Long startTime = exchange.getAttribute("start_time"); + Long startTime = exchange.getAttribute(ATTR_START_TIME); long costTime = 0L; if (startTime != null) { diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddJwtHeaderGlobalFilter.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddJwtHeaderGlobalFilter.java index d521c5b086..cb7e6e0a3f 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddJwtHeaderGlobalFilter.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddJwtHeaderGlobalFilter.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.gateway.filter.global; -import com.tencent.bk.job.common.security.jwt.JwtManager; +import com.tencent.bk.job.common.util.jwt.JwtManager; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilterChain; diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddTraceResponseHeaderGlobalFilter.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddTraceResponseHeaderGlobalFilter.java index ff102e260a..b2fe64675b 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddTraceResponseHeaderGlobalFilter.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/global/AddTraceResponseHeaderGlobalFilter.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.gateway.filter.global; import brave.Tracer; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilterChain; @@ -51,7 +52,7 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { String traceId = tracer.currentSpan().context().traceIdString(); ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse response = exchange.getResponse(); - response.getHeaders().add("request-id", traceId); + response.getHeaders().add(JobCommonHeaders.REQUEST_ID, traceId); return chain.filter(exchange.mutate().request(request).build()); } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/AuthorizeGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/AuthorizeGatewayFilterFactory.java similarity index 98% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/AuthorizeGatewayFilterFactory.java rename to src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/AuthorizeGatewayFilterFactory.java index 126cdb78b5..cab36a47cb 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/AuthorizeGatewayFilterFactory.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/AuthorizeGatewayFilterFactory.java @@ -22,7 +22,7 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.filter; +package com.tencent.bk.job.gateway.filter.web; import com.tencent.bk.job.common.model.dto.BkUserDTO; import com.tencent.bk.job.common.util.RequestUtil; diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactory.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/CsrfCheckGatewayFilterFactory.java similarity index 98% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactory.java rename to src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/CsrfCheckGatewayFilterFactory.java index 623220038f..0aae07f4ae 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactory.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/filter/web/CsrfCheckGatewayFilterFactory.java @@ -22,14 +22,14 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.filter; +package com.tencent.bk.job.gateway.filter.web; import com.tencent.bk.job.common.util.RequestUtil; import com.tencent.bk.job.gateway.common.util.UrlUtil; import com.tencent.bk.job.gateway.config.BkConfig; import com.tencent.bk.job.gateway.web.service.LoginService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilter; import org.springframework.cloud.gateway.filter.GatewayFilterChain; diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/i18n/JobLangHeaderLocaleContextResolver.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/i18n/JobLangHeaderLocaleContextResolver.java new file mode 100644 index 0000000000..e485a249b5 --- /dev/null +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/i18n/JobLangHeaderLocaleContextResolver.java @@ -0,0 +1,78 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.gateway.i18n; + +import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContext; +import org.springframework.context.i18n.SimpleLocaleContext; +import org.springframework.http.HttpHeaders; +import org.springframework.lang.Nullable; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.i18n.LocaleContextResolver; + +import java.util.Locale; + +/** + * Job 自定义国际化LocaleContextResolver + */ +@Slf4j +public class JobLangHeaderLocaleContextResolver implements LocaleContextResolver { + + private Locale defaultLocale; + + public JobLangHeaderLocaleContextResolver() { + } + + private LocaleContext getDefaultLocaleContext() { + return new SimpleLocaleContext(this.defaultLocale); + } + + public void setDefaultLocale(@Nullable Locale defaultLocale) { + this.defaultLocale = defaultLocale; + } + + @Override + public LocaleContext resolveLocaleContext(ServerWebExchange exchange) { + HttpHeaders httpHeaders = exchange.getRequest().getHeaders(); + String lang = httpHeaders.getFirst(LocaleUtils.COMMON_LANG_HEADER); + if (StringUtils.isNotBlank((lang))) { + Locale locale = LocaleUtils.getLocale(lang); + if (locale == null) { + return getDefaultLocaleContext(); + } + return new SimpleLocaleContext(locale); + } else { + return getDefaultLocaleContext(); + } + } + + @Override + public void setLocaleContext(ServerWebExchange exchange, LocaleContext localeContext) { + throw new UnsupportedOperationException( + "Cannot change HTTP accept header - use a different locale resolution strategy"); + } +} diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/impl/LicenseCheckServiceImpl.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/runner/LicenseCheckRunner.java similarity index 73% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/impl/LicenseCheckServiceImpl.java rename to src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/runner/LicenseCheckRunner.java index af5e852006..33bdd53132 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/impl/LicenseCheckServiceImpl.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/runner/LicenseCheckRunner.java @@ -22,13 +22,12 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.service.impl; +package com.tencent.bk.job.gateway.runner; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.gateway.config.BkConfig; import com.tencent.bk.job.gateway.model.LicenseCheckResultDTO; -import com.tencent.bk.job.gateway.service.LicenseCheckService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -41,10 +40,14 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.joda.time.DateTime; -import org.springframework.stereotype.Service; +import org.springframework.beans.BeansException; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; @@ -52,49 +55,27 @@ import java.io.File; import java.io.IOException; import java.security.cert.X509Certificate; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -@Service +@Component @Slf4j @SuppressWarnings("all") -public class LicenseCheckServiceImpl implements LicenseCheckService { +public class LicenseCheckRunner implements CommandLineRunner, ApplicationContextAware { + + private ApplicationContext context; private final BkConfig bkConfig; private CloseableHttpClient httpClient; - private Thread checkLicenseThread; - - private boolean run = true; - private volatile LicenseCheckResultDTO licenseCheckResult; - public LicenseCheckServiceImpl(BkConfig bkConfig) { + public LicenseCheckRunner(BkConfig bkConfig) { this.bkConfig = bkConfig; } - @Override - public LicenseCheckResultDTO checkLicense() { - if (licenseCheckResult == null) { - synchronized (LicenseCheckServiceImpl.class) { - if (licenseCheckResult == null) { - licenseCheckResult = getLicenceCheckResult(); - } - } - } - return licenseCheckResult; - } - - - @PreDestroy - public void destroy() { - run = false; - checkLicenseThread.interrupt(); - } - @PostConstruct public void init() throws Exception { if (httpClient == null) { @@ -142,41 +123,18 @@ public X509Certificate[] getAcceptedIssuers() { log.error("Init license check http client fail", e); throw e; } - startCheckLicenceThread(); } } - private void startCheckLicenceThread() { - if (checkLicenseThread == null || !checkLicenseThread.isAlive()) { - checkLicenseThread = new Thread("Check-License") { - - @Override - public void run() { - long minCheckInterval = 60 * 1000L; - long maxCheckInterval = 2 * 3600 * 1000L; - long sleepTime = minCheckInterval; - while (run) { - licenseCheckResult = getLicenceCheckResult(); - if (licenseCheckResult != null && licenseCheckResult.isOk()) { - // 检查下次要再向LicenceServer通信的时间,根据有效期来定 - if (licenseCheckResult.getValidEndTime() != null) { - sleepTime = licenseCheckResult.getValidEndTime().getTime() - System.currentTimeMillis(); - } - } else { //错误情况下,每分钟都会尝试去连接验证Licence,以求最快速度恢复系统服务 - sleepTime = minCheckInterval; - } - - if (sleepTime > maxCheckInterval) { - sleepTime = maxCheckInterval; - } - try { - Thread.sleep(sleepTime); - } catch (InterruptedException ignored) { - } - } - } - }; - checkLicenseThread.start(); + private void checkLicence() { + licenseCheckResult = getLicenceCheckResult(); + if (licenseCheckResult != null && licenseCheckResult.isOk()) { + // License有效,一直保持至下次重启进程 + log.info("Check license on start finished, license is ok"); + } else { + log.error("Fail to check license, please check whether the license server is avaliable"); + ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) context; + ctx.close(); } } @@ -198,6 +156,9 @@ private LicenseCheckResultDTO getLicenceCheckResult() { log.info("Check license, resp={}", responseBody); if (StringUtils.isNotBlank(responseBody)) { licenseCheckResult = JsonUtils.fromJson(responseBody, LicenseCheckResultDTO.class); + if (licenseCheckResult != null && !licenseCheckResult.isStatus()) { + log.error("license is invalid, please check license server configuration"); + } } else { createFailCheck(licenseCheckResult); } @@ -227,11 +188,9 @@ private LicenseCheckResultDTO getLicenceCheckResult() { } private void createFailCheck(LicenseCheckResultDTO licenseCheckDto) { - licenseCheckDto.setStatus(true); + licenseCheckDto.setStatus(false); licenseCheckDto.setMessage("License Server unreachable"); - licenseCheckDto.setResult(ErrorCode.RESULT_OK); - licenseCheckDto.setValidStartTime(new Date()); - licenseCheckDto.setValidEndTime(new Date(DateTime.now().plusDays(100).getMillis())); + licenseCheckDto.setResult(ErrorCode.LICENSE_ERROR); } private String buildCheckRequestBody() throws IOException { @@ -244,4 +203,14 @@ private String buildCheckRequestBody() throws IOException { requestParams.put("certificate", certContent); return JsonUtils.toJson(requestParams); } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.context = applicationContext; + } + + @Override + public void run(String... args) throws Exception { + checkLicence(); + } } diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java index 9eed90d120..53990cbec9 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java +++ b/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/web/service/impl/LoginServiceImpl.java @@ -34,7 +34,7 @@ import com.tencent.bk.job.gateway.config.BkConfig; import com.tencent.bk.job.gateway.web.service.LoginService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/backend/job-gateway/src/main/resources/application.yml b/src/backend/job-gateway/src/main/resources/application.yml index 97523243f9..72bc9f56d1 100644 --- a/src/backend/job-gateway/src/main/resources/application.yml +++ b/src/backend/job-gateway/src/main/resources/application.yml @@ -1,4 +1,6 @@ spring: + main: + allow-bean-definition-overriding: true cloud: ssl: useInsecureTrustManager: true @@ -20,7 +22,6 @@ spring: - Path= /job-manage/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -30,7 +31,6 @@ spring: - Path= /job-crontab/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -40,7 +40,6 @@ spring: - Path= /job-execute/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -50,7 +49,6 @@ spring: - Path= /job-backup/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -60,7 +58,6 @@ spring: - Path= /job-file-gateway/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -70,7 +67,6 @@ spring: - Path= /job-ticket/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -80,7 +76,6 @@ spring: - Path= /job-analysis/web/** filters: - Authorize - - LicenseCheck - CsrfCheck - StripPrefix=1 - AddWebLangHeader @@ -98,7 +93,6 @@ spring: predicates: - JobEsbV2Path=/api/job/v2/job-manage/{api_name} filters: - - LicenseCheck - CheckEsbJwt - SetPath=/esb/api/v2/{api_name} - RecordEsbAccessLog @@ -109,7 +103,6 @@ spring: predicates: - Path=/api/job/v3/job-manage/{api_name} filters: - - LicenseCheck - CheckEsbJwt - SetPath=/esb/api/v3/{api_name} - RecordEsbAccessLog @@ -120,7 +113,6 @@ spring: predicates: - JobEsbV2Path=/api/job/v2/job-crontab/{api_name} filters: - - LicenseCheck - CheckEsbJwt - SetPath=/esb/api/v2/{api_name} - RecordEsbAccessLog @@ -131,7 +123,6 @@ spring: predicates: - JobEsbV2Path=/api/job/v3/job-crontab/{api_name} filters: - - LicenseCheck - CheckEsbJwt - SetPath=/esb/api/v3/{api_name} - RecordEsbAccessLog @@ -142,7 +133,6 @@ spring: predicates: - JobEsbV2Path=/api/job/v2/job-execute/{api_name} filters: - - LicenseCheck - CheckEsbJwt - SetPath=/esb/api/v2/{api_name} - RecordEsbAccessLog @@ -153,7 +143,16 @@ spring: predicates: - JobEsbV2Path=/api/job/v3/job-execute/{api_name} filters: - - LicenseCheck + - CheckEsbJwt + - SetPath=/esb/api/v3/{api_name} + - RecordEsbAccessLog + - AddEsbLangHeader + + - id: job-file-gateway-esb-v3 + uri: lb://job-file-gateway + predicates: + - JobEsbV2Path=/api/job/v3/job-file-gateway/{api_name} + filters: - CheckEsbJwt - SetPath=/esb/api/v3/{api_name} - RecordEsbAccessLog @@ -230,4 +229,4 @@ job: service: private-key-base64: ${job.security.private-key-base64} public-key-base64: ${job.security.public-key-base64} - edition: ee + edition: ce diff --git a/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactoryTest.java b/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactoryTest.java index 1f71c22601..872ad28205 100644 --- a/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactoryTest.java +++ b/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/CsrfCheckGatewayFilterFactoryTest.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.gateway.filter; import com.tencent.bk.job.gateway.config.BkConfig; +import com.tencent.bk.job.gateway.filter.web.CsrfCheckGatewayFilterFactory; import com.tencent.bk.job.gateway.web.service.LoginService; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -41,7 +42,13 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class CsrfCheckGatewayFilterFactoryTest { private static final String COOKIE_CSRF_KEY_NAME = "job_csrf_key"; diff --git a/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactoryTest.java b/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactoryTest.java deleted file mode 100644 index 6dbef8cc74..0000000000 --- a/src/backend/job-gateway/src/test/java/com/tencent/bk/job/gateway/filter/LicenseCheckGatewayFilterFactoryTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.gateway.filter; - -import com.tencent.bk.job.gateway.model.LicenseCheckResultDTO; -import com.tencent.bk.job.gateway.service.LicenseCheckService; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; -import org.springframework.http.HttpStatus; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.web.server.ServerWebExchange; - -import static org.mockito.Mockito.*; - -public class LicenseCheckGatewayFilterFactoryTest { - @Test - public void whenLicenseCheckPassThenForwardFilter() { - ServerWebExchange mockExchange = spy(ServerWebExchange.class); - ServerHttpRequest mockRequest = mock(ServerHttpRequest.class); - ServerHttpResponse mockResponse = mock(ServerHttpResponse.class); - GatewayFilterChain mockChain = mock(GatewayFilterChain.class); - - when(mockExchange.getResponse()).thenReturn(mockResponse); - when(mockExchange.getRequest()).thenReturn(mockRequest); - - LicenseCheckService mockLicenseService = mock(LicenseCheckService.class); - LicenseCheckResultDTO checkPassResult = new LicenseCheckResultDTO(); - checkPassResult.setOk(true); - when(mockLicenseService.checkLicense()).thenReturn(checkPassResult); - - LicenseCheckGatewayFilterFactory factory = new LicenseCheckGatewayFilterFactory(mockLicenseService); - factory.filter(mockExchange, mockChain); - - verify(mockResponse, never()).setStatusCode(HttpStatus.UNAUTHORIZED); - verify(mockChain, times(1)).filter(mockExchange); - } - - @DisplayName("证书不合法返回401") - @Test - public void whenLicenseIsInvalidThenReturnUnauthorizedResponseStatus() { - ServerWebExchange mockExchange = spy(ServerWebExchange.class); - ServerHttpRequest mockRequest = mock(ServerHttpRequest.class); - ServerHttpResponse mockResponse = mock(ServerHttpResponse.class); - GatewayFilterChain mockChain = mock(GatewayFilterChain.class); - - when(mockExchange.getResponse()).thenReturn(mockResponse); - when(mockExchange.getRequest()).thenReturn(mockRequest); - - LicenseCheckService mockLicenseService = mock(LicenseCheckService.class); - LicenseCheckResultDTO checkPassResult = new LicenseCheckResultDTO(); - checkPassResult.setOk(false); - when(mockLicenseService.checkLicense()).thenReturn(checkPassResult); - - LicenseCheckGatewayFilterFactory factory = new LicenseCheckGatewayFilterFactory(mockLicenseService); - factory.filter(mockExchange, mockChain); - - verify(mockChain, never()).filter(any(ServerWebExchange.class)); - verify(mockResponse, times(1)).setStatusCode(HttpStatus.UNAUTHORIZED); - - } -} diff --git a/src/backend/job-logsvr/api-job-logsvr/build.gradle b/src/backend/job-logsvr/api-job-logsvr/build.gradle index 175bb80d89..20a438d661 100644 --- a/src/backend/job-logsvr/api-job-logsvr/build.gradle +++ b/src/backend/job-logsvr/api-job-logsvr/build.gradle @@ -23,8 +23,8 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') + api project(':commons:common') + api project(':commons:common-i18n') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" } diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/ServiceLogResource.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/ServiceLogResource.java index c18e3b4507..b63e500e57 100644 --- a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/ServiceLogResource.java +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/ServiceLogResource.java @@ -24,13 +24,27 @@ package com.tencent.bk.job.logsvr.api; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.IpDTO; -import com.tencent.bk.job.logsvr.model.service.*; +import com.tencent.bk.job.logsvr.model.service.BatchSaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.FileLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.SaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.ScriptLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogsDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -40,23 +54,24 @@ @Api(tags = {"Log"}) @RequestMapping("/service/log") @RestController +@InternalAPI public interface ServiceLogResource { @ApiOperation("保存执行日志") @PostMapping - ServiceResponse saveLog( + ServiceResponse saveLog( @ApiParam("保存日志请求报文") @RequestBody SaveLogRequest request); @ApiOperation("保存执行日志") @PostMapping("/batch") - ServiceResponse saveLogs( + ServiceResponse saveLogs( @ApiParam("批量保存日志请求报文") @RequestBody BatchSaveLogRequest request); - @ApiOperation("获取agent对应的执行日志") + @ApiOperation("根据服务器IP获取对应的执行日志") @GetMapping("/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}/ip/{ip}") - ServiceResponse getIpLogContent( + ServiceResponse getIpLogContent( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") @@ -68,9 +83,9 @@ ServiceResponse getIpLogContent( @ApiParam("日志类型") @RequestParam("logType") Integer logType); - @ApiOperation("获取脚本任务agent对应的执行日志") + @ApiOperation("根据目标服务器IP获取脚本任务对应的执行日志") @GetMapping("/script/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}/ip/{ip}") - ServiceResponse getScriptIpLogContent( + ServiceResponse getScriptIpLogContent( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") @@ -80,9 +95,9 @@ ServiceResponse getScriptIpLogContent( @ApiParam("作业创建时间") @PathVariable("jobCreateDate") String jobCreateDate); - @ApiOperation("批量获取脚本任务agent对应的执行日志") + @ApiOperation("批量获取脚本任务对应的执行日志") @PostMapping("/script/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}") - ServiceResponse> batchGetScriptLogContent( + ServiceResponse> batchGetScriptLogContent( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") @@ -94,7 +109,7 @@ ServiceResponse> batchGetScriptLogContent( @ApiOperation("按照IP获取文件任务对应的执行日志") @GetMapping("/file/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}/ip/{ip}") - ServiceResponse getFileIpLogContent( + ServiceResponse getFileIpLogContent( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") @@ -122,7 +137,7 @@ ServiceResponse> getFileLogContent( @ApiOperation("获取文件任务agent对应的执行日志") @PostMapping("/file/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}/queryByTaskIds") - ServiceResponse getFileLogContentListByTaskIds( + ServiceResponse getFileLogContentListByTaskIds( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") @@ -132,9 +147,13 @@ ServiceResponse getFileLogContentListByTaskIds( @ApiParam("文件任务ID列表,多个任务ID以;分隔") @RequestBody List taskIds); + @ApiOperation("获取文件任务对应的执行日志") + @PostMapping("/file") + ServiceResponse getFileLogContent(@RequestBody FileLogQueryRequest request); + @ApiOperation("删除执行日志") @DeleteMapping("/jobCreateDate/{jobCreateDate}/step/{stepInstanceId}/retry/{executeCount}") - ServiceResponse deleteStepContent( + ServiceResponse deleteStepContent( @ApiParam("步骤ID") @PathVariable("stepInstanceId") Long stepInstanceId, @ApiParam("执行次数") diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/BatchSaveLogRequest.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/BatchSaveLogRequest.java index 377039ea0a..ae7dbb476a 100644 --- a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/BatchSaveLogRequest.java +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/BatchSaveLogRequest.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.StringJoiner; -import java.util.stream.Collectors; /** * 批量保存执行日志请求 @@ -49,7 +48,7 @@ public class BatchSaveLogRequest { * 执行日志 */ @ApiModelProperty(value = "执行日志", required = true) - private List logs; + private List logs; /** * 日志类型 @@ -61,7 +60,7 @@ public String toString() { return new StringJoiner(", ", BatchSaveLogRequest.class.getSimpleName() + "[", "]") .add("jobCreateDate='" + jobCreateDate + "'") .add("logType='" + logType + "'") - .add("logs=" + logs.stream().map(ServiceLogDTO::toStringBasic).collect(Collectors.toList())) + .add("logs=" + logs) .toString(); } } diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/FileLogQueryRequest.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/FileLogQueryRequest.java new file mode 100644 index 0000000000..d6c6481de6 --- /dev/null +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/FileLogQueryRequest.java @@ -0,0 +1,61 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.logsvr.model.service; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +/** + * 文件任务执行日志查询请求 + */ +@Getter +@Setter +@ToString +public class FileLogQueryRequest { + @ApiModelProperty(value = "作业实例创建时间,格式为yyyy_MM_dd", required = true) + private String jobCreateDate; + + @ApiModelProperty(value = "步骤实例ID", required = true) + private Long stepInstanceId; + + @ApiModelProperty(value = "执行次数", required = true) + private Integer executeCount; + + @ApiModelProperty("服务器IP列表;如果ips参数不为空,那么忽略ip参数") + private List ips; + + @ApiModelProperty("服务器IP") + private String ip; + + /** + * @see com.tencent.bk.job.logsvr.consts.FileTaskModeEnum + */ + @ApiModelProperty("分发模式,0:upload,1:download") + private Integer mode; +} diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceFileTaskLogDTO.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceFileTaskLogDTO.java index 56a7c61e67..afe69518df 100644 --- a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceFileTaskLogDTO.java +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceFileTaskLogDTO.java @@ -107,6 +107,7 @@ public class ServiceFileTaskLogDTO { */ @JsonProperty("content") private String content; + public ServiceFileTaskLogDTO(Integer mode, String destIp, String destFile, String srcIp, String displaySrcIp, String srcFile, String displaySrcFile, String size, Integer status, String statusDesc, String speed, String process, String content) { diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceLogDTO.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogDTO.java similarity index 92% rename from src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceLogDTO.java rename to src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogDTO.java index 96377b5f74..5fd399d1b4 100644 --- a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceLogDTO.java +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogDTO.java @@ -34,10 +34,10 @@ import java.util.List; import java.util.StringJoiner; -@ApiModel("执行日志") +@ApiModel("主机执行日志") @Data @JsonInclude(JsonInclude.Include.NON_EMPTY) -public class ServiceLogDTO { +public class ServiceIpLogDTO { /** * 作业步骤实例ID */ @@ -73,12 +73,13 @@ public void addFileTaskLog(ServiceFileTaskLogDTO fileTaskDetailLog) { fileTaskLogs.add(fileTaskDetailLog); } - public String toStringBasic() { - StringJoiner joiner = new StringJoiner(", ", ServiceLogDTO.class.getSimpleName() + "[", "]") + @Override + public String toString() { + StringJoiner joiner = new StringJoiner(", ", ServiceIpLogDTO.class.getSimpleName() + "[", "]") .add("stepInstanceId=" + stepInstanceId) .add("ip='" + ip + "'") .add("executeCount=" + executeCount) - .add("scriptLog=" + scriptLog) + .add("scriptLog=" + scriptLog) .add("fileTaskLogSize=" + (fileTaskLogs == null ? 0 : fileTaskLogs.size())); return joiner.toString(); } diff --git a/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogsDTO.java b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogsDTO.java new file mode 100644 index 0000000000..7903217911 --- /dev/null +++ b/src/backend/job-logsvr/api-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/service/ServiceIpLogsDTO.java @@ -0,0 +1,69 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.logsvr.model.service; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.StringJoiner; + +@ApiModel("主机执行日志-批量") +@Getter +@Setter +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class ServiceIpLogsDTO { + /** + * 作业步骤实例ID + */ + @ApiModelProperty("步骤实例ID") + private Long stepInstanceId; + + /** + * 执行次数 + */ + @ApiModelProperty("执行次数") + private Integer executeCount; + + /** + * 主机执行日志列表 + */ + @ApiModelProperty(value = "主机执行日志") + @JsonProperty("ipLogs") + private List ipLogs; + + @Override + public String toString() { + return new StringJoiner(", ", ServiceIpLogsDTO.class.getSimpleName() + "[", "]") + .add("stepInstanceId=" + stepInstanceId) + .add("executeCount=" + executeCount) + .add("ipLogs=" + ipLogs) + .toString(); + } +} diff --git a/src/backend/job-logsvr/boot-job-logsvr/build.gradle b/src/backend/job-logsvr/boot-job-logsvr/build.gradle index 495b6606c4..4cbec231fc 100644 --- a/src/backend/job-logsvr/boot-job-logsvr/build.gradle +++ b/src/backend/job-logsvr/boot-job-logsvr/build.gradle @@ -25,8 +25,8 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-logsvr:service-job-logsvr") - compile project(":commons:common-i18n") + api project(":job-logsvr:service-job-logsvr") + api project(":commons:common-i18n") implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' implementation 'org.springframework.cloud:spring-cloud-starter-config' @@ -34,11 +34,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo' } springBoot { - mainClassName = "com.tencent.bk.job.logsvr.JobLogBootApplication" + mainClass = "com.tencent.bk.job.logsvr.JobLogBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-logsvr/boot-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/config/I18nConfig.java b/src/backend/job-logsvr/boot-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/config/I18nConfig.java deleted file mode 100644 index b28ef69c86..0000000000 --- a/src/backend/job-logsvr/boot-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/config/I18nConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.logsvr.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import com.tencent.bk.job.common.i18n.locale.LocaleUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; - -/** - * @date 2019/09/19 - */ -@Configuration -public class I18nConfig { - -// @Bean("localeResolver") -// public LocaleResolver localeResolver() { -// JobLangHeaderLocaleResolver resolver = new JobLangHeaderLocaleResolver(); -// resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); -// return resolver; -// } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName(LocaleUtils.COMMON_LANG_HEADER); - return interceptor; - } - -} diff --git a/src/backend/job-logsvr/build.gradle b/src/backend/job-logsvr/build.gradle index e09f019080..b0e826fe82 100644 --- a/src/backend/job-logsvr/build.gradle +++ b/src/backend/job-logsvr/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobLogVersion")) { set("jobLogVersion", System.getProperty("jobLogVersion")) + } else if (System.getProperty("version")) { + set("jobLogVersion", System.getProperty("version")) } else { set("jobLogVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobLogVersion}" subprojects { version "${jobLogVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -41,7 +43,7 @@ subprojects { implementation 'ch.qos.logback:logback-classic' implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-logsvr/service-job-logsvr/build.gradle b/src/backend/job-logsvr/service-job-logsvr/build.gradle index 9a117ed050..91392a673f 100644 --- a/src/backend/job-logsvr/service-job-logsvr/build.gradle +++ b/src/backend/job-logsvr/service-job-logsvr/build.gradle @@ -24,13 +24,13 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-logsvr:api-job-logsvr") - compile project(':commons:common-security') - compile project(':commons:common-web') - compile("org.springframework.boot:spring-boot-starter-web") - compile("org.springframework.boot:spring-boot-starter-data-mongodb") - compile("org.springframework.cloud:spring-cloud-starter-consul-discovery") - compile("org.springframework.cloud:spring-cloud-starter-sleuth") + api project(":job-logsvr:api-job-logsvr") + api project(':commons:common-security') + api project(':commons:common-web') + api("org.springframework.boot:spring-boot-starter-web") + api("org.springframework.boot:spring-boot-starter-data-mongodb") + api("org.springframework.cloud:spring-cloud-starter-consul-discovery") + api("org.springframework.cloud:spring-cloud-starter-sleuth") implementation 'org.apache.commons:commons-collections4' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo' diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/service/impl/ServiceLogResourceImpl.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/service/impl/ServiceLogResourceImpl.java index b09fbad296..947b0ff913 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/service/impl/ServiceLogResourceImpl.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/api/service/impl/ServiceLogResourceImpl.java @@ -25,21 +25,36 @@ package com.tencent.bk.job.logsvr.api.service.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.logsvr.api.ServiceLogResource; +import com.tencent.bk.job.logsvr.consts.FileTaskModeEnum; import com.tencent.bk.job.logsvr.consts.LogTypeEnum; -import com.tencent.bk.job.logsvr.model.*; -import com.tencent.bk.job.logsvr.model.service.*; +import com.tencent.bk.job.logsvr.model.FileLogQuery; +import com.tencent.bk.job.logsvr.model.FileTaskLog; +import com.tencent.bk.job.logsvr.model.ScriptLogQuery; +import com.tencent.bk.job.logsvr.model.ScriptTaskLog; +import com.tencent.bk.job.logsvr.model.TaskIpLog; +import com.tencent.bk.job.logsvr.model.service.BatchSaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.FileLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.SaveLogRequest; +import com.tencent.bk.job.logsvr.model.service.ScriptLogQueryRequest; +import com.tencent.bk.job.logsvr.model.service.ServiceFileTaskLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceIpLogsDTO; +import com.tencent.bk.job.logsvr.model.service.ServiceScriptLogDTO; import com.tencent.bk.job.logsvr.service.LogService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static com.tencent.bk.job.common.constant.ErrorCode.DELETE_JOB_EXECUTION_LOG_FAIL; @@ -58,7 +73,7 @@ public ServiceLogResourceImpl(LogService logService, MessageI18nService i18nServ } @Override - public ServiceResponse saveLog(SaveLogRequest request) { + public ServiceResponse saveLog(SaveLogRequest request) { TaskIpLog taskIpLog = convertToTaskLog(request.getLogType(), request.getJobCreateDate(), request.getStepInstanceId(), request.getExecuteCount(), request.getIp(), request.getScriptLog(), request.getFileTaskLogs()); @@ -94,7 +109,7 @@ private TaskIpLog convertToTaskLog(Integer logType, String jobCreateDate, long s } @Override - public ServiceResponse saveLogs(BatchSaveLogRequest request) { + public ServiceResponse saveLogs(BatchSaveLogRequest request) { try { List taskIpLogs = request.getLogs().parallelStream().map(log -> convertToTaskLog(request.getLogType(), @@ -112,8 +127,8 @@ public ServiceResponse saveLogs(BatchSaveLogRequest request) { } @Override - public ServiceResponse getIpLogContent(Long stepInstanceId, Integer executeCount, String ip, - String jobCreateDate, Integer logType) { + public ServiceResponse getIpLogContent(Long stepInstanceId, Integer executeCount, String ip, + String jobCreateDate, Integer logType) { if (LogTypeEnum.SCRIPT.getValue().equals(logType)) { return getScriptIpLogContent(stepInstanceId, executeCount, ip, jobCreateDate); } else if (LogTypeEnum.FILE.getValue().equals(logType)) { @@ -124,12 +139,12 @@ public ServiceResponse getIpLogContent(Long stepInstanceId, Integ } @Override - public ServiceResponse getScriptIpLogContent(Long stepInstanceId, Integer executeCount, String ip, - String jobCreateDate) { + public ServiceResponse getScriptIpLogContent(Long stepInstanceId, Integer executeCount, String ip, + String jobCreateDate) { ScriptLogQuery query = new ScriptLogQuery(jobCreateDate, stepInstanceId, ip, executeCount); try { TaskIpLog taskIpLog = logService.getScriptLogByIp(query); - ServiceLogDTO result = toServiceLogDTO(taskIpLog); + ServiceIpLogDTO result = toServiceLogDTO(taskIpLog); return ServiceResponse.buildSuccessResp(result); } catch (Throwable e) { String errorMsg = @@ -139,8 +154,8 @@ public ServiceResponse getScriptIpLogContent(Long stepInstanceId, } } - private ServiceLogDTO toServiceLogDTO(TaskIpLog taskIpLog) { - ServiceLogDTO result = new ServiceLogDTO(); + private ServiceIpLogDTO toServiceLogDTO(TaskIpLog taskIpLog) { + ServiceIpLogDTO result = new ServiceIpLogDTO(); if (taskIpLog != null) { result.setStepInstanceId(taskIpLog.getStepInstanceId()); result.setExecuteCount(taskIpLog.getExecuteCount()); @@ -151,22 +166,23 @@ private ServiceLogDTO toServiceLogDTO(TaskIpLog taskIpLog) { } @Override - public ServiceResponse> batchGetScriptLogContent(Long stepInstanceId, Integer executeCount, - String jobCreateDate, - ScriptLogQueryRequest query) { + public ServiceResponse> batchGetScriptLogContent(Long stepInstanceId, Integer executeCount, + String jobCreateDate, + ScriptLogQueryRequest query) { ScriptLogQuery scriptLogQuery = new ScriptLogQuery(jobCreateDate, stepInstanceId, query.getIps(), executeCount); List taskIpLogs = logService.batchGetScriptLogByIps(scriptLogQuery); - List scriptLogs = taskIpLogs.stream().map(this::toServiceLogDTO).collect(Collectors.toList()); + List scriptLogs = taskIpLogs.stream().map(this::toServiceLogDTO).collect(Collectors.toList()); return ServiceResponse.buildSuccessResp(scriptLogs); } @Override - public ServiceResponse getFileIpLogContent(Long stepInstanceId, Integer executeCount, String ip, - String jobCreateDate, Integer mode) { - FileLogQuery query = new FileLogQuery(jobCreateDate, stepInstanceId, ip, executeCount, mode); + public ServiceResponse getFileIpLogContent(Long stepInstanceId, Integer executeCount, String ip, + String jobCreateDate, Integer mode) { + FileLogQuery query = FileLogQuery.builder().stepInstanceId(stepInstanceId) + .executeCount(executeCount).jobCreateDate(jobCreateDate).mode(mode).ip(ip).build(); try { TaskIpLog taskIpLog = logService.getFileLogByIp(query); - ServiceLogDTO result = new ServiceLogDTO(); + ServiceIpLogDTO result = new ServiceIpLogDTO(); result.setStepInstanceId(stepInstanceId); result.setExecuteCount(executeCount); result.setIp(ip); @@ -191,7 +207,8 @@ public ServiceResponse> getFileLogContent(Long stepI String jobCreateDate, Integer mode, String ip) { - FileLogQuery query = new FileLogQuery(jobCreateDate, stepInstanceId, ip, executeCount, mode); + FileLogQuery query = FileLogQuery.builder().stepInstanceId(stepInstanceId) + .executeCount(executeCount).jobCreateDate(jobCreateDate).mode(mode).ip(ip).build(); List fileTaskLogs = logService.getFileLogs(query); if (CollectionUtils.isEmpty(fileTaskLogs)) { return ServiceResponse.buildSuccessResp(Collections.emptyList()); @@ -202,9 +219,9 @@ public ServiceResponse> getFileLogContent(Long stepI } @Override - public ServiceResponse getFileLogContentListByTaskIds(Long stepInstanceId, Integer executeCount, - String jobCreateDate, List taskIds) { - ServiceLogDTO result = new ServiceLogDTO(); + public ServiceResponse getFileLogContentListByTaskIds(Long stepInstanceId, Integer executeCount, + String jobCreateDate, List taskIds) { + ServiceIpLogDTO result = new ServiceIpLogDTO(); result.setStepInstanceId(stepInstanceId); result.setExecuteCount(executeCount); if (CollectionUtils.isEmpty(taskIds)) { @@ -220,7 +237,55 @@ public ServiceResponse getFileLogContentListByTaskIds(Long stepIn } @Override - public ServiceResponse deleteStepContent(Long stepInstanceId, Integer executeCount, String jobCreateDate) { + public ServiceResponse getFileLogContent(FileLogQueryRequest request) { + FileLogQuery query = FileLogQuery.builder() + .stepInstanceId(request.getStepInstanceId()) + .executeCount(request.getExecuteCount()) + .jobCreateDate(request.getJobCreateDate()) + .mode(request.getMode()) + .ip(request.getIp()) + .ips(request.getIps()) + .build(); + + ServiceIpLogsDTO ipLogsResult = new ServiceIpLogsDTO(); + ipLogsResult.setStepInstanceId(request.getStepInstanceId()); + ipLogsResult.setExecuteCount(request.getExecuteCount()); + + List fileTaskLogs = logService.getFileLogs(query); + if (CollectionUtils.isEmpty(fileTaskLogs)) { + return ServiceResponse.buildSuccessResp(ipLogsResult); + } + + List fileLogs = fileTaskLogs.stream().map(FileTaskLog::toServiceFileTaskLogDTO) + .collect(Collectors.toList()); + + Map> cloudIpAndLogs = new HashMap<>(); + fileLogs.forEach(fileLog -> { + String cloudIp = (FileTaskModeEnum.DOWNLOAD.getValue().equals(fileLog.getMode()) ? + fileLog.getDestIp() : fileLog.getSrcIp()); + cloudIpAndLogs.compute(cloudIp, (k, logs) -> { + if (logs == null) { + logs = new ArrayList<>(); + } + logs.add(fileLog); + return logs; + }); + }); + + List ipLogs = new ArrayList<>(); + ipLogsResult.setIpLogs(ipLogs); + cloudIpAndLogs.forEach((cloudIp, logs) -> { + ServiceIpLogDTO ipLog = new ServiceIpLogDTO(); + ipLog.setIp(cloudIp); + ipLog.setFileTaskLogs(logs); + ipLogs.add(ipLog); + }); + + return ServiceResponse.buildSuccessResp(ipLogsResult); + } + + @Override + public ServiceResponse deleteStepContent(Long stepInstanceId, Integer executeCount, String jobCreateDate) { try { long deleteCount = logService.deleteStepContent(stepInstanceId, executeCount, jobCreateDate); return ServiceResponse.buildSuccessResp(deleteCount); diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/common/ExceptionControllerAdvice.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/common/ExceptionControllerAdvice.java deleted file mode 100644 index 7aea477c3b..0000000000 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/common/ExceptionControllerAdvice.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.logsvr.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice({"com.tencent.bk.job.logsvr"}) -@Slf4j -public class ExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - - @Autowired - public ExceptionControllerAdvice(MessageI18nService i18nService) { - this.i18nService = i18nService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.error("Handle service exception", ex); - if (ex instanceof HttpStatusServiceException) { - HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException.getErrorCode() - , i18nService), httpStatusServiceException.getHttpStatus()); - } else { - log.info("exception:{}", JsonUtils.toJson(ex)); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorCode(), ex.getErrorParams(), - i18nService), HttpStatus.OK); - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.error("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } - -} diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/FileLogQuery.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/FileLogQuery.java index e2e120b647..6eccd2ddac 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/FileLogQuery.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/FileLogQuery.java @@ -24,13 +24,16 @@ package com.tencent.bk.job.logsvr.model; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import java.util.List; import java.util.StringJoiner; -@Data -@NoArgsConstructor +@Getter +@Setter +@Builder public class FileLogQuery { /** * 作业实例创建时间,格式yyyy_MM_dd @@ -44,6 +47,10 @@ public class FileLogQuery { * 执行任务的主机ip */ private String ip; + /** + * 执行任务的主机ip列表 + */ + private List ips; /** * 执行次数 */ @@ -55,20 +62,13 @@ public class FileLogQuery { */ private Integer mode; - public FileLogQuery(String jobCreateDate, Long stepInstanceId, String ip, Integer executeCount, Integer mode) { - this.jobCreateDate = jobCreateDate; - this.stepInstanceId = stepInstanceId; - this.ip = ip; - this.executeCount = executeCount; - this.mode = mode; - } - @Override public String toString() { return new StringJoiner(", ", FileLogQuery.class.getSimpleName() + "[", "]") .add("jobCreateDate='" + jobCreateDate + "'") .add("stepInstanceId=" + stepInstanceId) .add("ip='" + ip + "'") + .add("ips='" + ips + "'") .add("executeCount=" + executeCount) .add("mode=" + mode) .toString(); diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/ScriptLogQuery.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/ScriptLogQuery.java index 7307645905..05f931607a 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/ScriptLogQuery.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/model/ScriptLogQuery.java @@ -42,7 +42,7 @@ public class ScriptLogQuery { */ private Long stepInstanceId; /** - * 执行任务的主机ip, 最大支持1000 + * 执行任务的主机ip */ private List ips; /** diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/CollectionLoaderBase.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/CollectionLoaderBase.java index ff6d893515..3ce525b0e8 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/CollectionLoaderBase.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/CollectionLoaderBase.java @@ -35,6 +35,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; @Slf4j @Component @@ -45,6 +47,8 @@ public class CollectionLoaderBase implements CollectionLoader { @Value("${job.logsvr.mongodb.shard.enabled:false}") protected boolean enableSharding; + private Map collectionShardStatusMap = new ConcurrentHashMap<>(); + @Override public MongoCollection load(MongoTemplate mongoTemplate, String collectionName) { return null; @@ -63,6 +67,12 @@ protected List getIndexesNames(MongoCollection collection) { protected void shardCollectionIfShardingEnable(MongoTemplate mongoTemplate, String collectionName) { if (enableSharding) { + Boolean isCollectionSharded = collectionShardStatusMap.get(collectionName); + if (isCollectionSharded != null && isCollectionSharded) { + log.info("Collection: {} is already sharded!", collectionName); + return; + } + log.info("Shard collection {} start...", collectionName); MongoDatabase adminDB = mongoTemplate.getMongoDbFactory().getMongoDatabase("admin"); String collection = logDb + "." + collectionName; @@ -70,6 +80,8 @@ protected void shardCollectionIfShardingEnable(MongoTemplate mongoTemplate, Stri Document shardCmd = new Document("shardCollection", collection) .append("key", new Document("stepId", "hashed")); adminDB.runCommand(shardCmd); + + collectionShardStatusMap.put(collectionName, true); log.info("Shard collection successfully, collectionName: {}", collectionName); } } diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/FileLogsCollectionLoader.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/FileLogsCollectionLoader.java index adbde0672f..aeadea6a05 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/FileLogsCollectionLoader.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/FileLogsCollectionLoader.java @@ -49,11 +49,7 @@ public MongoCollection load(MongoTemplate mongoTemplate, String collec MongoCollection collection = mongoTemplate.getCollection(collectionName); List indexes = getIndexesNames(collection); createIndexIfUnavailable(collection, indexes, collectionName); - - if (!indexes.contains(IDX_STEP_COUNT_MODE_IP) || !indexes.contains(IDX_STEP_COUNT_TASK_ID) - || !indexes.contains(IDX_STEP_ID_HASHED)) { - shardCollectionIfShardingEnable(mongoTemplate, collectionName); - } + shardCollectionIfShardingEnable(mongoTemplate, collectionName); return collection; } diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/LogCollectionFactory.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/LogCollectionFactory.java index abe8f93362..ccaa04941e 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/LogCollectionFactory.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/LogCollectionFactory.java @@ -31,7 +31,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; @@ -51,7 +51,7 @@ public class LogCollectionFactory { private final LoadingCache> collectionCache = - CacheBuilder.newBuilder().maximumSize(365).expireAfterAccess(2, TimeUnit.HOURS).build(new CacheLoader>() { @Override public MongoCollection load(String collectionName) { diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/ScriptLogsCollectionLoader.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/ScriptLogsCollectionLoader.java index 3f80a82bc1..d6f8c7baf2 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/ScriptLogsCollectionLoader.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/mongo/ScriptLogsCollectionLoader.java @@ -47,29 +47,32 @@ public class ScriptLogsCollectionLoader extends CollectionLoaderBase { public MongoCollection load(MongoTemplate mongoTemplate, String collectionName) { MongoCollection collection = mongoTemplate.getCollection(collectionName); List indexes = getIndexesNames(collection); - // 是否初始化collection,创建索引 - boolean isInitialed = indexes.contains(IDX_STEP_ID_HASHED) && indexes.contains(IDX_STEP_EXECUTE_COUNT_IP); - - if (!isInitialed) { - createIndex(collection, collectionName); - shardCollectionIfShardingEnable(mongoTemplate, collectionName); - } + createIndexIfUnavailable(collection, indexes, collectionName); + shardCollectionIfShardingEnable(mongoTemplate, collectionName); return collection; } - private void createIndex(MongoCollection collection, String collectionName) { - log.info("Create index stepId_hashed for collection: {}start...", collectionName); - IndexOptions indexOptions1 = new IndexOptions(); - indexOptions1.background(false); - indexOptions1.name(IDX_STEP_ID_HASHED); - collection.createIndex(Document.parse("{\"stepId\":\"hashed\"}"), indexOptions1); - log.info("Create index stepId_hashed for collection: {} successfully!", collectionName); + private void createIndexIfUnavailable(MongoCollection collection, List indexes, String collectionName) { + log.info("Create index for collection: {} start...", collectionName); + if (!indexes.contains(IDX_STEP_ID_HASHED)) { + log.info("Create index stepId_hashed for collection: {}start...", collectionName); + IndexOptions indexOptions1 = new IndexOptions(); + indexOptions1.background(false); + indexOptions1.name(IDX_STEP_ID_HASHED); + collection.createIndex(Document.parse("{\"stepId\":\"hashed\"}"), indexOptions1); + log.info("Create index stepId_hashed for collection: {} successfully!", collectionName); + } + + if (!indexes.contains(IDX_STEP_EXECUTE_COUNT_IP)) { + log.info("Create index stepId_1_executeCount_1_ip_1 for collection: {} start...", collectionName); + IndexOptions indexOption2 = new IndexOptions(); + indexOption2.background(false); + indexOption2.name(IDX_STEP_EXECUTE_COUNT_IP); + collection.createIndex(Document.parse("{\"stepId\":1,\"executeCount\":1,\"ip\":1}"), indexOption2); + log.info("Create index stepId_1_executeCount_1_ip_1 for collection: {} successfully!", collectionName); + } + + log.info("Create index for collection : {} successfully!", collectionName); - log.info("Create index stepId_1_executeCount_1_ip_1 for collection: {} start...", collectionName); - IndexOptions indexOption2 = new IndexOptions(); - indexOption2.background(false); - indexOption2.name(IDX_STEP_EXECUTE_COUNT_IP); - collection.createIndex(Document.parse("{\"stepId\":1,\"executeCount\":1,\"ip\":1}"), indexOption2); - log.info("Create index stepId_1_executeCount_1_ip_1 for collection: {} successfully!", collectionName); } } diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/LogService.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/LogService.java index e1ad3ebe9e..a44f8f9c84 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/LogService.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/LogService.java @@ -98,6 +98,7 @@ public interface LogService { List getFileLogsByTaskIds(String jobCreateDate, long stepInstanceId, int executeCount, List taskIds); + /** * 删除步骤日志 * diff --git a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImpl.java b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImpl.java index 35a6ef6667..4873d6cca3 100644 --- a/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImpl.java +++ b/src/backend/job-logsvr/service-job-logsvr/src/main/java/com/tencent/bk/job/logsvr/service/impl/LogServiceImpl.java @@ -25,13 +25,21 @@ package com.tencent.bk.job.logsvr.service.impl; import com.mongodb.BasicDBObject; -import com.mongodb.client.model.*; +import com.mongodb.client.model.BulkWriteOptions; +import com.mongodb.client.model.InsertManyOptions; +import com.mongodb.client.model.UpdateOneModel; +import com.mongodb.client.model.UpdateOptions; +import com.mongodb.client.model.WriteModel; import com.mongodb.client.result.DeleteResult; import com.tencent.bk.job.common.exception.ServiceException; import com.tencent.bk.job.common.model.dto.IpDTO; import com.tencent.bk.job.common.util.BatchUtil; import com.tencent.bk.job.logsvr.consts.LogTypeEnum; -import com.tencent.bk.job.logsvr.model.*; +import com.tencent.bk.job.logsvr.model.FileLogQuery; +import com.tencent.bk.job.logsvr.model.FileTaskLog; +import com.tencent.bk.job.logsvr.model.ScriptLogQuery; +import com.tencent.bk.job.logsvr.model.ScriptTaskLog; +import com.tencent.bk.job.logsvr.model.TaskIpLog; import com.tencent.bk.job.logsvr.mongo.LogCollectionFactory; import com.tencent.bk.job.logsvr.service.LogService; import lombok.extern.slf4j.Slf4j; @@ -44,7 +52,11 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -309,7 +321,6 @@ public List getFileLogs(FileLogQuery getLogRequest) { String collectionName = buildLogCollectionName(getLogRequest.getJobCreateDate(), LogTypeEnum.FILE); long stepInstanceId = getLogRequest.getStepInstanceId(); int executeCount = getLogRequest.getExecuteCount(); - String ip = getLogRequest.getIp(); long start = System.currentTimeMillis(); try { @@ -319,9 +330,12 @@ public List getFileLogs(FileLogQuery getLogRequest) { if (getLogRequest.getMode() != null) { query.addCriteria(Criteria.where("mode").is(getLogRequest.getMode())); } - if (StringUtils.isNotEmpty(getLogRequest.getIp())) { - query.addCriteria(Criteria.where("ip").is(ip)); + if (CollectionUtils.isNotEmpty(getLogRequest.getIps())) { + query.addCriteria(Criteria.where("ip").in(getLogRequest.getIps())); + } else if (StringUtils.isNotEmpty(getLogRequest.getIp())) { + query.addCriteria(Criteria.where("ip").is(getLogRequest.getIp())); } + List fileTaskLogs = mongoTemplate.find(query, FileTaskLog.class, collectionName); if (CollectionUtils.isNotEmpty(fileTaskLogs)) { fileTaskLogs.forEach(fileTaskLog -> @@ -330,8 +344,7 @@ public List getFileLogs(FileLogQuery getLogRequest) { return fileTaskLogs; } finally { long cost = (System.currentTimeMillis() - start); - - if (cost > 10L) { + if (cost > 50L) { log.warn("Get file log slow, query: {}, cost: {} ms", getLogRequest, cost); } } @@ -382,7 +395,6 @@ private List getScriptTaskLogByIps(ScriptLogQuery getLogRequest) { query.addCriteria(Criteria.where("stepId").is(stepInstanceId)); query.addCriteria(Criteria.where("executeCount").is(executeCount)); query.addCriteria(Criteria.where("ip").in(ips)); - query.limit(1000); List scriptLogs = mongoTemplate.find(query, ScriptTaskLog.class, collectionName); if (CollectionUtils.isEmpty(scriptLogs)) { diff --git a/src/backend/job-manage/api-job-manage/build.gradle b/src/backend/job-manage/api-job-manage/build.gradle index 08048a11e1..c7588c50c3 100644 --- a/src/backend/job-manage/api-job-manage/build.gradle +++ b/src/backend/job-manage/api-job-manage/build.gradle @@ -23,11 +23,11 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-i18n') - compile project(':commons:cmdb-sdk') - compile project(':commons:common-iam') - compile project(':job-execute:api-job-execute') + api project(':commons:common') + api project(':commons:common-i18n') + api project(':commons:cmdb-sdk') + api project(':commons:common-iam') + api project(':job-execute:api-job-execute') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation("org.apache.commons:commons-collections4") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetDBAccountListResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetDBAccountListResource.java index 553bea2bdc..a26f20fe0b 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetDBAccountListResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetDBAccountListResource.java @@ -24,25 +24,27 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbDBAccountDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetDBAccountListRequest; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * 查询用户有权限的DB帐号列表API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetDBAccountListResource { @PostMapping("/get_own_db_account_list") EsbResp> getUserOwnDbAccountList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetDBAccountListRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobDetailResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobDetailResource.java index 10686a7c59..cd90275972 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobDetailResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobDetailResource.java @@ -24,22 +24,24 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbJobDetailDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetJobDetailRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 查询业务下的执行方案详情-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetJobDetailResource { @PostMapping("/get_job_detail") EsbResp getJobDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetJobDetailRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobListResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobListResource.java index 0a8aad0ee3..5e86f3b2d7 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobListResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetJobListResource.java @@ -24,24 +24,26 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbJobBasicInfoDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetJobListRequest; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * 查询业务下的执行方案列表-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetJobListResource { @PostMapping("/get_job_list") EsbResp> getJobList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetJobListRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetOSAccountResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetOSAccountResource.java index 2b3d21071a..f8bf7e84f2 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetOSAccountResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetOSAccountResource.java @@ -24,25 +24,27 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbAccountDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetOSAccountListRequest; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; - /** * 查询业务下的系统执行账号API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetOSAccountResource { @PostMapping("/get_os_account") EsbResp> getAppOsAccountList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetOSAccountListRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetPublicScriptListResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetPublicScriptListResource.java index aced8f010a..6301745b5d 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetPublicScriptListResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetPublicScriptListResource.java @@ -24,24 +24,26 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbPageData; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbScriptDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetPublicScriptListRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 获取公共脚本列表API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetPublicScriptListResource { @PostMapping("/get_public_script_list") EsbResp> getPublicScriptList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetPublicScriptListRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptDetailResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptDetailResource.java index 67de9bfcaf..bec48dc0c6 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptDetailResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptDetailResource.java @@ -24,23 +24,25 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbScriptDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetScriptDetailRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 获取脚本详情API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetScriptDetailResource { @PostMapping("/get_script_detail") EsbResp getScriptDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetScriptDetailRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptListResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptListResource.java index d772637785..c920fb555a 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptListResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/EsbGetScriptListResource.java @@ -24,24 +24,26 @@ package com.tencent.bk.job.manage.api.esb; +import com.tencent.bk.job.common.annotation.EsbAPI; import com.tencent.bk.job.common.esb.model.EsbPageData; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.EsbScriptDTO; import com.tencent.bk.job.manage.model.esb.request.EsbGetScriptListRequest; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 获取脚本列表API-V2 */ @RequestMapping("/esb/api/v2") @RestController +@EsbAPI public interface EsbGetScriptListResource { @PostMapping("/get_script_list") EsbResp> getScriptList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, @RequestBody EsbGetScriptListRequest request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbAccountV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbAccountV3Resource.java index ad577a61be..837354ffc6 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbAccountV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbAccountV3Resource.java @@ -24,24 +24,39 @@ package com.tencent.bk.job.manage.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetAccountListV3Req; import com.tencent.bk.job.manage.model.esb.v3.response.EsbAccountV3DTO; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 账号API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbAccountV3Resource { @PostMapping("/get_account_list") - EsbResp> getAccountList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp> getAccountListUsingPost( @RequestBody EsbGetAccountListV3Req request); + @GetMapping("/get_account_list") + EsbResp> getAccountList( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "category", required = false) Integer category, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java new file mode 100644 index 0000000000..8776ae0df4 --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.api.esb.v3; + +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialSimpleInfoV3DTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 凭据API-V3 + */ +@RequestMapping("/esb/api/v3") +@RestController +@EsbAPI +public interface EsbCredentialV3Resource { + + @PostMapping("/create_credential") + EsbResp createCredential( + @RequestBody EsbCreateOrUpdateCredentialV3Req req); + + @PostMapping("/update_credential") + EsbResp updateCredential( + @RequestBody EsbCreateOrUpdateCredentialV3Req req); + +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPlanV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPlanV3Resource.java index 88732e9f59..6bbf30dbc9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPlanV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPlanV3Resource.java @@ -24,29 +24,58 @@ package com.tencent.bk.job.manage.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetPlanDetailV3Request; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetPlanListV3Request; import com.tencent.bk.job.manage.model.esb.v3.response.EsbPlanBasicInfoV3DTO; import com.tencent.bk.job.manage.model.esb.v3.response.EsbPlanInfoV3DTO; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @since 15/10/2020 16:20 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbPlanV3Resource { - @PostMapping("/get_job_plan_list") + + @GetMapping("/get_job_plan_list") EsbResp> getPlanList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "job_template_id", required = false) Long templateId, + @RequestParam(value = "creator", required = false) String creator, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "create_time_start", required = false) Long createTimeStart, + @RequestParam(value = "create_time_end", required = false) Long createTimeEnd, + @RequestParam(value = "last_modify_user", required = false) String lastModifyUser, + @RequestParam(value = "last_modify_time_start", required = false) Long lastModifyTimeStart, + @RequestParam(value = "last_modify_time_end", required = false) Long lastModifyTimeEnd, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_job_plan_detail") + EsbResp getPlanDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "job_plan_id") Long planId); + + @PostMapping("/get_job_plan_list") + EsbResp> getPlanListUsingPost( @RequestBody EsbGetPlanListV3Request request); @PostMapping("/get_job_plan_detail") - EsbResp getPlanDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getPlanDetailUsingPost( @RequestBody EsbGetPlanDetailV3Request request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPublicScriptV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPublicScriptV3Resource.java index 6515709495..268b406453 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPublicScriptV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbPublicScriptV3Resource.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.manage.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptListV3Req; @@ -31,30 +33,59 @@ import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptVersionListV3Req; import com.tencent.bk.job.manage.model.esb.v3.response.EsbScriptV3DTO; import com.tencent.bk.job.manage.model.esb.v3.response.EsbScriptVersionDetailV3DTO; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 公共脚本相关API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbPublicScriptV3Resource { - @PostMapping("/get_public_script_list") + @GetMapping("/get_public_script_list") EsbResp> getPublicScriptList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "script_language", required = false) Integer scriptLanguage, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_public_script_version_list") + EsbResp> getPublicScriptVersionList( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "script_id") String scriptId, + @RequestParam(value = "return_script_content", required = false, defaultValue = "false") + boolean returnScriptContent, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_public_script_version_detail") + EsbResp getPublicScriptVersionDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "id", required = false) Long scriptVersionId, + @RequestParam(value = "script_id", required = false) String scriptId, + @RequestParam(value = "version", required = false) String version); + + @PostMapping("/get_public_script_list") + EsbResp> getPublicScriptListUsingPost( @RequestBody EsbGetScriptListV3Req request); @PostMapping("/get_public_script_version_list") - EsbResp> getPublicScriptVersionList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp> getPublicScriptVersionListUsingPost( @RequestBody EsbGetScriptVersionListV3Req request); @PostMapping("/get_public_script_version_detail") - EsbResp getPublicScriptVersionDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getPublicScriptVersionDetailUsingPost( @RequestBody EsbGetScriptVersionDetailV3Req request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbScriptV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbScriptV3Resource.java index 5150b35fc7..b93ba00e16 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbScriptV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbScriptV3Resource.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.manage.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptListV3Req; @@ -31,30 +33,62 @@ import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptVersionListV3Req; import com.tencent.bk.job.manage.model.esb.v3.response.EsbScriptV3DTO; import com.tencent.bk.job.manage.model.esb.v3.response.EsbScriptVersionDetailV3DTO; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * 脚本相关API-V3 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbScriptV3Resource { - @PostMapping("/get_script_list") + @GetMapping("/get_script_list") EsbResp> getScriptList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "script_language", required = false) Integer scriptLanguage, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_script_version_list") + EsbResp> getScriptVersionList( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "script_id") String scriptId, + @RequestParam(value = "return_script_content", required = false, defaultValue = "false") + boolean returnScriptContent, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @GetMapping("/get_script_version_detail") + EsbResp getScriptVersionDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "id", required = false) Long scriptVersionId, + @RequestParam(value = "script_id", required = false) String scriptId, + @RequestParam(value = "version", required = false) String version); + + @PostMapping("/get_script_list") + EsbResp> getScriptListUsingPost( @RequestBody EsbGetScriptListV3Req request); @PostMapping("/get_script_version_list") - EsbResp> getScriptVersionList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp> getScriptVersionListUsingPost( @RequestBody EsbGetScriptVersionListV3Req request); @PostMapping("/get_script_version_detail") - EsbResp getScriptVersionDetail( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + EsbResp getScriptVersionDetailUsingPost( @RequestBody EsbGetScriptVersionDetailV3Req request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbTemplateV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbTemplateV3Resource.java index 5f7c91a1fd..ed8bdf0acb 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbTemplateV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbTemplateV3Resource.java @@ -24,22 +24,44 @@ package com.tencent.bk.job.manage.api.esb.v3; +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetTemplateListV3Request; import com.tencent.bk.job.manage.model.esb.v3.response.EsbTemplateBasicInfoV3DTO; -import org.springframework.web.bind.annotation.*; - -import static com.tencent.bk.job.common.i18n.locale.LocaleUtils.COMMON_LANG_HEADER; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @since 15/10/2020 16:19 */ @RequestMapping("/esb/api/v3") @RestController +@EsbAPI public interface EsbTemplateV3Resource { - @PostMapping("/get_job_template_list") + + @GetMapping("/get_job_template_list") EsbResp> getTemplateList( - @RequestHeader(value = COMMON_LANG_HEADER, required = false) String lang, + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id") Long appId, + @RequestParam(value = "creator", required = false) String creator, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "create_time_start", required = false) Long createTimeStart, + @RequestParam(value = "create_time_end", required = false) Long createTimeEnd, + @RequestParam(value = "last_modify_user", required = false) String lastModifyUser, + @RequestParam(value = "last_modify_time_start", required = false) Long lastModifyTimeStart, + @RequestParam(value = "last_modify_time_end", required = false) Long lastModifyTimeEnd, + @RequestParam(value = "start", required = false) Integer start, + @RequestParam(value = "length", required = false) Integer length); + + @PostMapping("/get_job_template_list") + EsbResp> getTemplateListUsingPost( @RequestBody EsbGetTemplateListV3Request request); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskCallbackResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskPlanCallbackResource.java similarity index 83% rename from src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskCallbackResource.java rename to src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskPlanCallbackResource.java index b115ba43b1..e3dfae48df 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskCallbackResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskPlanCallbackResource.java @@ -30,14 +30,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -/** - * @since 15/6/2020 15:40 - */ -@RequestMapping("/iam/api/v1/resources/task") -public interface IamTaskCallbackResource { - @PostMapping("/template") - CallbackBaseResponseDTO templateCallback(@RequestBody CallbackRequestDTO callbackRequest); +@RequestMapping("/iam/api/v1/resources/task/plan") +public interface IamTaskPlanCallbackResource { - @PostMapping("/plan") - CallbackBaseResponseDTO planCallback(@RequestBody CallbackRequestDTO callbackRequest); + @PostMapping + CallbackBaseResponseDTO callback(@RequestBody CallbackRequestDTO callbackRequest); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskTemplateCallbackResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskTemplateCallbackResource.java new file mode 100644 index 0000000000..ab8351bf94 --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/IamTaskTemplateCallbackResource.java @@ -0,0 +1,37 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.api.iam; + +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; + +@RequestMapping("/iam/api/v1/resources/task/template") +public interface IamTaskTemplateCallbackResource { + @PostMapping + CallbackBaseResponseDTO callback(@RequestBody CallbackRequestDTO callbackRequest); +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAccountResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAccountResource.java index 6012279643..44e75fc29c 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAccountResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAccountResource.java @@ -24,13 +24,20 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceAccountDTO; import com.tencent.bk.job.manage.model.web.request.AccountCreateUpdateReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 账号服务 @@ -38,6 +45,7 @@ @RequestMapping("/service/account") @Api(tags = {"job-manage:service:Account_Management"}) @RestController +@InternalAPI public interface ServiceAccountResource { /** * 根据账号id获取账号信息 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAppSetResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAppSetResource.java index 8f7193491c..ca211aacd9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAppSetResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceAppSetResource.java @@ -24,18 +24,26 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; import com.tencent.bk.job.manage.model.inner.request.ServiceAddAppSetRequest; import com.tencent.bk.job.manage.model.inner.request.ServiceUpdateAppSetRequest; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @RequestMapping("/service/app-set") @Api(tags = {"job-manage:service:App_Set_Management"}) @RestController +@InternalAPI public interface ServiceAppSetResource { @GetMapping("/{appId}") ServiceResponse queryAppSetById(@PathVariable("appId") Long appId); @@ -44,8 +52,8 @@ public interface ServiceAppSetResource { ServiceResponse> listAppSet(); -// @DeleteMapping("/{appId}") -// ServiceResponse deleteAppSet(@PathVariable("appId") Long appId); + @DeleteMapping("/{appId}") + ServiceResponse deleteAppSet(@PathVariable("appId") Long appId); @PutMapping ServiceResponse addAppSet(@RequestBody ServiceAddAppSetRequest request); diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java index 5b90837300..7afbffbda3 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceApplicationResource.java @@ -24,7 +24,9 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.manage.model.inner.ServiceAppBaseInfoDTO; import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; import com.tencent.bk.job.manage.model.inner.ServiceHostStatusDTO; import com.tencent.bk.job.manage.model.inner.request.ServiceGetHostStatusByDynamicGroupReq; @@ -32,14 +34,30 @@ import com.tencent.bk.job.manage.model.inner.request.ServiceGetHostStatusByNodeReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @RequestMapping("/service/app") @Api(tags = {"job-manage:service:App_Management"}) @RestController +@InternalAPI public interface ServiceApplicationResource { + /** + * 查询CMDB中的常规业务列表 + * + * @return + */ + @RequestMapping("/list/normal") + ServiceResponse> listNormalApps(); + /** * 根据业务id查询业务 * diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCheckScriptResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCheckScriptResource.java index 258300819b..545a400136 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCheckScriptResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCheckScriptResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceScriptCheckResultItemDTO; import com.tencent.bk.job.manage.model.inner.request.ServiceCheckScriptRequest; @@ -41,6 +42,7 @@ @RequestMapping("/service/script/check") @Api(tags = {"job-manage:service:Script_Check"}) @RestController +@InternalAPI public interface ServiceCheckScriptResource { @PostMapping diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCrontabCallbackResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCrontabCallbackResource.java index f6f3d19536..728ec0dd54 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCrontabCallbackResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCrontabCallbackResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -34,6 +35,7 @@ @Api(tags = {"job-manage:service:CrontabCallback"}) @RequestMapping("/service/callback/crontab") @RestController +@InternalAPI public interface ServiceCrontabCallbackResource { @ApiOperation(value = "同步业务", produces = "application/json") @GetMapping("/syncApp") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java index 7e97d5d535..47e61eaaaa 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceGlobalSettingsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -34,6 +35,7 @@ @Api(tags = {"job-manage:service:GlobalSettings"}) @RequestMapping("/service/globalSettings") @RestController +@InternalAPI public interface ServiceGlobalSettingsResource { @ApiOperation(value = "获取文档中心基础Url", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java index 4d4fe23e86..4b7c1520b3 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceHostResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -36,6 +37,7 @@ @RequestMapping("/service/host") @Api(tags = {"job-manage:service:Host_Management"}) @RestController +@InternalAPI public interface ServiceHostResource { @ApiOperation(value = "判断主机是否存在", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceMetricsResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceMetricsResource.java index 7948f7ec55..470ce391fc 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceMetricsResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceMetricsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.account.AccountTypeEnum; @@ -34,11 +35,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-manage:service:Metrics"}) @RequestMapping("/service/metrics") @RestController +@InternalAPI public interface ServiceMetricsResource { @ApiOperation(value = "接入业务总量", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceNotificationResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceNotificationResource.java index 8d957ef700..dce3fdbf76 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceNotificationResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceNotificationResource.java @@ -24,18 +24,30 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.manage.model.inner.*; +import com.tencent.bk.job.manage.model.inner.ServiceAppRoleDTO; +import com.tencent.bk.job.manage.model.inner.ServiceNotificationMessage; +import com.tencent.bk.job.manage.model.inner.ServiceNotifyChannelDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTemplateNotificationDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTriggerTemplateNotificationDTO; +import com.tencent.bk.job.manage.model.inner.ServiceUserNotificationDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:service:Notification"}) @RequestMapping("/service/notification") @RestController +@InternalAPI public interface ServiceNotificationResource { @ApiOperation(value = "发送通知给用户(渠道在配置文件中配置,默认所有渠道)", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceScriptResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceScriptResource.java index 9a8f1853dc..6148a11f43 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceScriptResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceScriptResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceScriptDTO; import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq; @@ -31,11 +32,18 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.tuple.Pair; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-manage:service:Script_Management"}) @RequestMapping("/service/script") @RestController +@InternalAPI public interface ServiceScriptResource { @ApiOperation(value = "根据业务ID、脚本版本ID获取脚本", produces = "application/json") @GetMapping("/app/{appId}/scriptVersion/{scriptVersionId}") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceSyncResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceSyncResource.java index 99463480ca..6fe0093249 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceSyncResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceSyncResource.java @@ -24,13 +24,18 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; import com.tencent.bk.job.manage.model.inner.ServiceHostInfoDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -40,6 +45,7 @@ @RequestMapping("/service/sync") @Api(tags = {"job-manage:service:App_Management"}) @RestController +@InternalAPI public interface ServiceSyncResource { /** * 查询所有业务 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTagResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTagResource.java index 79cf92e2d5..52efb18c88 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTagResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTagResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceTagDTO; import io.swagger.annotations.Api; @@ -39,6 +40,7 @@ @Api(tags = {"job-manage:Service:Tag"}) @RequestMapping("/service/tag") @RestController +@InternalAPI public interface ServiceTagResource { @ApiOperation(value = "获取业务下的所有标签", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskPlanResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskPlanResource.java index 8ac71e98dd..e54494d076 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskPlanResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskPlanResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceIdNameCheckDTO; import com.tencent.bk.job.manage.model.inner.ServiceTaskPlanDTO; @@ -32,13 +33,21 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:service:Task_Plan_Management"}) @RequestMapping("/service") @RestController +@InternalAPI public interface ServiceTaskPlanResource { @ApiOperation(value = "根据执行方案ID获取执行方案信息", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskTemplateResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskTemplateResource.java index 0efee6a3e8..4de7db43d8 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskTemplateResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceTaskTemplateResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceIdNameCheckDTO; @@ -34,13 +35,22 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:service:Task_Template_Management"}) @RequestMapping("/service") @RestController +@InternalAPI public interface ServiceTaskTemplateResource { @ApiOperation(value = "同步脚本更新消息", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceUserResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceUserResource.java index 57ee2facff..b5c9ed21ce 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceUserResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceUserResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -38,6 +39,7 @@ @Api(tags = {"job-manage:service:User"}) @RequestMapping("/service/user") @RestController +@InternalAPI public interface ServiceUserResource { @ApiOperation(value = "根据业务Id与角色获取用户信息", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceWhiteIPResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceWhiteIPResource.java index e9b58eb3c6..828015c5b3 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceWhiteIPResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceWhiteIPResource.java @@ -24,19 +24,27 @@ package com.tencent.bk.job.manage.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceWhiteIPInfo; import com.tencent.bk.job.manage.model.web.request.whiteip.WhiteIPRecordCreateUpdateReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:service:WhiteIP"}) @RequestMapping("/service/whiteip") @RestController +@InternalAPI public interface ServiceWhiteIPResource { @ApiOperation(value = "获取指定IP在白名单中的生效范围(脚本执行:SCRIPT_EXECUTE/文件分发:FILE_DISTRIBUTION)", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/MigrationResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/MigrationResource.java index 231634c201..a66865dc98 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/MigrationResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/MigrationResource.java @@ -25,12 +25,12 @@ package com.tencent.bk.job.manage.api.migration; import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.manage.model.migration.EncryptDbAccountPasswordReq; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * 微服务升级 */ @@ -38,6 +38,11 @@ @RestController public interface MigrationResource { + /** + * 对DB账号的密码进行加密 + * + * @return + */ @PostMapping("/action/encryptDbAccountPassword") - ServiceResponse encryptDbAccountPassword(@RequestBody EncryptDbAccountPasswordReq req); + ServiceResponse> encryptDbAccountPassword(); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/op/FlowControlOpResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/op/FlowControlOpResource.java index 883b334ec4..00484e1116 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/op/FlowControlOpResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/op/FlowControlOpResource.java @@ -29,7 +29,13 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.Map; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpAppAccountResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpAppAccountResource.java index 89da3733d0..e371178439 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpAppAccountResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpAppAccountResource.java @@ -29,7 +29,12 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @Api(tags = {"job-manage:tmp:App_Account"}) diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpMigrationResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpMigrationResource.java index 2d8a3eb868..2ee03b6e1e 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpMigrationResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/TmpMigrationResource.java @@ -29,7 +29,11 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppAccountResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppAccountResource.java index 8b98ac09d3..018308774e 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppAccountResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppAccountResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.AccountCreateUpdateReq; @@ -31,7 +32,15 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -40,6 +49,7 @@ */ @Api(tags = {"job-manage:web:App_Account"}) @RequestMapping("/web/account/app/{appId}") +@WebAPI public interface WebAppAccountResource { @ApiOperation(value = "新增账号", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppResource.java index 74102372f0..1e2497b7a1 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebAppResource.java @@ -24,20 +24,33 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.vo.HostInfoVO; import com.tencent.bk.job.common.model.vo.TargetNodeVO; import com.tencent.bk.job.manage.model.web.request.AgentStatisticsReq; import com.tencent.bk.job.manage.model.web.request.FavorAppReq; +import com.tencent.bk.job.manage.model.web.request.IpCheckReq; import com.tencent.bk.job.manage.model.web.request.ipchooser.AppTopologyTreeNode; import com.tencent.bk.job.manage.model.web.request.ipchooser.ListHostByBizTopologyNodesReq; -import com.tencent.bk.job.manage.model.web.vo.*; +import com.tencent.bk.job.manage.model.web.vo.AppVO; +import com.tencent.bk.job.manage.model.web.vo.CcTopologyNodeVO; +import com.tencent.bk.job.manage.model.web.vo.DynamicGroupInfoVO; +import com.tencent.bk.job.manage.model.web.vo.NodeInfoVO; +import com.tencent.bk.job.manage.model.web.vo.PageDataWithAvailableIdList; import com.tencent.bk.job.manage.model.web.vo.index.AgentStatistics; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -49,6 +62,7 @@ @Api(tags = {"job-manage:web:App_Management"}) @RequestMapping("/web/app") @RestController +@WebAPI public interface WebAppResource { @Deprecated @@ -177,7 +191,7 @@ ServiceResponse> listAppDynamicGroupWithoutHosts( ServiceResponse> listHostByIp( @ApiParam(value = "用户名,网关自动传入", required = true) @RequestHeader("username") String username, @ApiParam(value = "业务 ID", required = true) @PathVariable("appId") Long appId, - @ApiParam(value = "用户输入的 IP 列表", required = true) @RequestBody List checkIpList); + @ApiParam(value = "用户输入的 IP 列表", required = true) @RequestBody IpCheckReq req); @ApiOperation(value = "查询主机统计信息") @PostMapping("/{appId}/host/statistics") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCustomSettingsResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCustomSettingsResource.java index b97abc92b8..31d1c8ece8 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCustomSettingsResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCustomSettingsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.customsetting.ScriptTemplateCreateUpdateReq; import com.tencent.bk.job.manage.model.web.request.customsetting.ScriptTemplateRenderReq; @@ -32,13 +33,20 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:CustomSettings_ScriptTemplate"}) @RequestMapping("/web/customSettings/scriptTemplate") @RestController +@WebAPI public interface WebCustomSettingsResource { @ApiOperation(value = "获取用户自定义的脚本模板", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebDangerousRuleResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebDangerousRuleResource.java index b6fbb32960..d9de1c2828 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebDangerousRuleResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebDangerousRuleResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.globalsetting.AddOrUpdateDangerousRuleReq; import com.tencent.bk.job.manage.model.web.request.globalsetting.MoveDangerousRuleReq; @@ -31,13 +32,22 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:DangerousRule"}) @RequestMapping("/web/dangerousRule") @RestController +@WebAPI public interface WebDangerousRuleResource { @ApiOperation(value = "获取高危语句规则列表", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebFileUploadResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebFileUploadResource.java index 73fb38dea5..5519fa3de6 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebFileUploadResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebFileUploadResource.java @@ -24,12 +24,17 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.vo.UploadLocalFileResultVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -40,6 +45,7 @@ @Api(tags = {"job-manage:web:File_Upload_Management"}) @RequestMapping("/web/upload") @RestController +@WebAPI public interface WebFileUploadResource { @ApiOperation(value = "上传本地文件", produces = "application/json") @PostMapping("/localFile") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsQueryResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsQueryResource.java index 3f8aff519a..b379578c8d 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsQueryResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsQueryResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.vo.globalsetting.AccountNameRulesWithDefaultVO; import com.tencent.bk.job.manage.model.web.vo.globalsetting.NotifyChannelWithIconVO; @@ -31,7 +32,12 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @@ -39,6 +45,7 @@ @Api(tags = {"job-manage:web:GlobalSettings"}) @RequestMapping("/web/queryGlobalSettings") @RestController +@WebAPI public interface WebGlobalSettingsQueryResource { @ApiOperation(value = "获取通知渠道列表及生效状态", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsResource.java index 3dc6a7dc09..88f992b8f8 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebGlobalSettingsResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.globalsetting.AccountNameRulesReq; import com.tencent.bk.job.manage.model.web.request.globalsetting.FileUploadSettingReq; @@ -44,13 +45,20 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:GlobalSettings"}) @RequestMapping("/web/globalSettings") @RestController +@WebAPI public interface WebGlobalSettingsResource { @ApiOperation(value = "获取通知渠道列表及生效状态", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebIndexResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebIndexResource.java index 27c355537f..a789cd5607 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebIndexResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebIndexResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.vo.HostInfoVO; @@ -34,13 +35,19 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:Index"}) @RequestMapping("/web/index/app/{appId}") @RestController +@WebAPI public interface WebIndexResource { @Deprecated diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebNotifyResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebNotifyResource.java index 9d891531d4..d7b64b92e8 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebNotifyResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebNotifyResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.inner.ServiceNotificationDTO; import com.tencent.bk.job.manage.model.web.request.notify.NotifyPoliciesCreateUpdateReq; @@ -34,13 +35,21 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:Notify"}) @RequestMapping("/web/notify") @RestController +@WebAPI public interface WebNotifyResource { @ApiOperation(value = "获取业务通知策略列表", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPermissionResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPermissionResource.java index af77bcaaaf..c01219b489 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPermissionResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPermissionResource.java @@ -24,17 +24,25 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.manage.model.web.request.OperationPermissionReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-manage:web:Permission"}) @RequestMapping("/web/permission/") @RestController +@WebAPI public interface WebPermissionResource { /** * 获取权限申请URL diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicScriptResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicScriptResource.java index 8877cf7e7b..cfedc0bba9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicScriptResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicScriptResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq; @@ -38,7 +39,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -48,6 +58,7 @@ @Api(value = "公共脚本管理", tags = {"job-manage:web:Public_Script_Management"}) @RequestMapping("/web/public_script") @RestController +@WebAPI public interface WebPublicScriptResource { @ApiOperation(value = "根据脚本版本ID获取脚本版本详情", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicTagResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicTagResource.java index bdee9afbed..fda9124015 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicTagResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebPublicTagResource.java @@ -24,12 +24,17 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.vo.TagVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -39,6 +44,7 @@ @Api(tags = {"job-manage:web:Public_Tag_Management"}) @RequestMapping("/web/public_tag") @RestController +@WebAPI public interface WebPublicTagResource { @ApiOperation(value = "根据条件获取业务下的所有标签", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebScriptResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebScriptResource.java index 57fd619546..171a1f7197 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebScriptResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebScriptResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.ScriptCheckReq; @@ -40,7 +41,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -53,6 +63,7 @@ @Api(value = "脚本管理", tags = {"job-manage:web:Script_Management"}) @RequestMapping("/web/script") @RestController +@WebAPI public interface WebScriptResource { @ApiOperation(value = "根据脚本版本ID获取脚本版本详情", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebServiceInfoResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebServiceInfoResource.java index e8d3c1f1d9..b56c0b5cdb 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebServiceInfoResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebServiceInfoResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.vo.serviceinfo.ServiceInfoVO; import io.swagger.annotations.Api; @@ -39,6 +40,7 @@ @Api(tags = {"job-manage:web:ServiceInfo"}) @RequestMapping("/web/serviceInfo") @RestController +@WebAPI public interface WebServiceInfoResource { @ApiOperation(value = "获取所有服务信息", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTagResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTagResource.java index c676dc6296..2c17ec328f 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTagResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTagResource.java @@ -24,13 +24,22 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.TagCreateReq; import com.tencent.bk.job.manage.model.web.vo.TagVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -42,6 +51,7 @@ @Api(tags = {"job-manage:web:Tag_Management"}) @RequestMapping("/web/tag/app/{appId}") @RestController +@WebAPI public interface WebTagResource { @ApiOperation(value = "根据条件获取业务下的所有标签", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskPlanResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskPlanResource.java index 839fc43347..f10a03db12 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskPlanResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskPlanResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.TaskPlanCreateUpdateReq; @@ -33,7 +34,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.ws.rs.QueryParam; import java.util.List; @@ -44,6 +54,7 @@ @Api(tags = {"job-manage:web:Task_Plan_Management"}) @RequestMapping("/web") @RestController +@WebAPI public interface WebTaskPlanResource { @ApiOperation(value = "获取业务下的执行方案列表", produces = "application/json") @@ -82,6 +93,16 @@ ServiceResponse> listPlans( @PathVariable(value = "templateId") Long templateId ); + @ApiOperation(value = "批量获取执行方案基本信息", produces = "application/json") + @GetMapping("/app/{appId}/task/plan:batchGet") + ServiceResponse> batchGetPlans( + @ApiParam(value = "用户名,网关自动传入") + @RequestHeader("username") String username, + @ApiParam(value = "业务 ID", required = true, example = "2") + @PathVariable("appId") Long appId, + @ApiParam(value = "模板ID列表,用英文逗号分隔", required = true) + @RequestParam(value = "templateIds") String templateIds); + @ApiOperation(value = "根据执行方案 ID 获取执行方案信息", produces = "application/json") @GetMapping("/app/{appId}/task/plan/{templateId}/{planId}") ServiceResponse getPlanById( diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskTemplateResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskTemplateResource.java index 14b0ee41ce..6abe830ea9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskTemplateResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebTaskTemplateResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.model.web.request.TaskTemplateCreateUpdateReq; @@ -33,7 +34,15 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -43,6 +52,7 @@ @Api(tags = {"job-manage:web:Task_Template_Management"}) @RequestMapping("/web/app/{appId}/task/template") @RestController +@WebAPI public interface WebTaskTemplateResource { @ApiOperation(value = "获取模版基本信息列表", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebWhiteIPResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebWhiteIPResource.java index 4437a43ad2..336f48b134 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebWhiteIPResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebWhiteIPResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.manage.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageDataWithManagePermission; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.vo.CloudAreaInfoVO; @@ -33,13 +34,22 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @Api(tags = {"job-manage:web:WhiteIP"}) @RequestMapping("/web/whiteIP") @RestController +@WebAPI public interface WebWhiteIPResource { @ApiOperation(value = "获取IP白名单列表", produces = "application/json") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbAccountDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbAccountDTO.java index cb001543ea..3e9abc6d42 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbAccountDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbAccountDTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbAccountDTO { private Long id; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbDBAccountDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbDBAccountDTO.java index 7ab95b53de..7c3eaca42f 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbDBAccountDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbDBAccountDTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbDBAccountDTO { @JsonProperty("db_account_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobBasicInfoDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobBasicInfoDTO.java index 3868425929..295c2857b7 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobBasicInfoDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobBasicInfoDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -32,7 +31,6 @@ * 作业执行方案基本信息 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbJobBasicInfoDTO { @JsonProperty("bk_job_id") private Long id; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobDetailDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobDetailDTO.java index 92088697e5..50a5885fa9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobDetailDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbJobDetailDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.Getter; @@ -86,12 +85,10 @@ public class EsbJobDetailDTO { * 作业的步骤 */ @JsonProperty("steps") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List steps; /** * 全局变量 */ @JsonProperty("global_vars") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List variables; } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbScriptDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbScriptDTO.java index 618ad9b5b4..9af5e71528 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbScriptDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbScriptDTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbScriptDTO { private Long id; @JsonProperty("bk_biz_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbStepDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbStepDTO.java index 37189574ce..aa0c4cbf70 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbStepDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbStepDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.EsbFileSourceDTO; import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; @@ -35,7 +34,6 @@ @Setter @Getter -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbStepDTO { @JsonProperty("step_id") private Long id; @@ -70,11 +68,9 @@ public class EsbStepDTO { private String fileTargetPath; @JsonProperty("file_source") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List fileSources; @JsonProperty("ip_list") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List ipList; @JsonProperty("custom_query_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbTaskVariableDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbTaskVariableDTO.java index 91fc2a9a31..2bc1ac0ae6 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbTaskVariableDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/EsbTaskVariableDTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; import lombok.Getter; @@ -34,7 +33,6 @@ @Setter @Getter -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbTaskVariableDTO { /** * 全局变量类型 @@ -62,12 +60,10 @@ public class EsbTaskVariableDTO { * IP对象数组,category=2时有这个参数 */ @JsonProperty("ip_list") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List ipList; /** * 配置平台上的动态分组id列表, 当category=3时有这个参数 */ @JsonProperty("custom_query_id") - @JsonInclude(JsonInclude.Include.NON_EMPTY) private List customQueryId; } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java new file mode 100644 index 0000000000..594011defa --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java @@ -0,0 +1,87 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.model.esb.v3.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.esb.model.EsbReq; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 新建凭据请求 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbCreateOrUpdateCredentialV3Req extends EsbReq { + /** + * 业务ID + */ + @JsonProperty("bk_biz_id") + private Long appId; + + /** + * 凭据ID + */ + private String id; + + /** + * 凭据名称 + */ + private String name; + + /** + * 凭据类型 + */ + private String type; + + /** + * 描述 + */ + private String description; + + /** + * AccessKey + */ + @JsonProperty("credential_access_key") + private String credentialAccessKey; + + /** + * SecretKey + */ + @JsonProperty("credential_secret_key") + private String credentialSecretKey; + + /** + * Username + */ + @JsonProperty("credential_username") + private String credentialUsername; + + /** + * Password + */ + @JsonProperty("credential_password") + private String credentialPassword; +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbAccountV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbAccountV3DTO.java index c84cb29055..9f617d0fce 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbAccountV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbAccountV3DTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbAccountV3DTO { private Long id; @JsonProperty("bk_biz_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbApprovalStepV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbApprovalStepV3DTO.java index cb05f0d0db..d8ba3ce716 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbApprovalStepV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbApprovalStepV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import java.util.List; @@ -35,7 +34,6 @@ * @since 17/11/2020 20:38 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbApprovalStepV3DTO { /** diff --git a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/LicenseCheckService.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialSimpleInfoV3DTO.java similarity index 84% rename from src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/LicenseCheckService.java rename to src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialSimpleInfoV3DTO.java index dbaa598773..f119357a6d 100644 --- a/src/backend/job-gateway/src/main/java/com/tencent/bk/job/gateway/service/LicenseCheckService.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialSimpleInfoV3DTO.java @@ -22,10 +22,17 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.gateway.service; +package com.tencent.bk.job.manage.model.esb.v3.response; -import com.tencent.bk.job.gateway.model.LicenseCheckResultDTO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class EsbCredentialSimpleInfoV3DTO { + + private String id; -public interface LicenseCheckService { - LicenseCheckResultDTO checkLicense(); } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbFileStepV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbFileStepV3DTO.java index 3ec2e22709..13b953ff81 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbFileStepV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbFileStepV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.v3.EsbFileDestinationV3DTO; import com.tencent.bk.job.common.esb.model.job.v3.EsbFileSourceV3DTO; @@ -38,7 +37,6 @@ * @since 17/11/2020 20:37 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbFileStepV3DTO { /** * 源文件列表 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanBasicInfoV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanBasicInfoV3DTO.java index c0c9766b1b..c121e1d56d 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanBasicInfoV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanBasicInfoV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -34,7 +33,6 @@ * @since 15/10/2020 17:54 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbPlanBasicInfoV3DTO { /** * 执行方案 ID diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanInfoV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanInfoV3DTO.java index 0c68162152..e2fc67ad8b 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanInfoV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbPlanInfoV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.v3.EsbGlobalVarV3DTO; import lombok.Data; @@ -37,7 +36,6 @@ */ @Data @EqualsAndHashCode(callSuper = true) -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbPlanInfoV3DTO extends EsbPlanBasicInfoV3DTO { /** diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptStepV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptStepV3DTO.java index dd6790953b..5e8f194d20 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptStepV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptStepV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.tencent.bk.job.common.esb.model.job.v3.EsbAccountV3BasicDTO; import com.tencent.bk.job.common.esb.model.job.v3.EsbServerV3DTO; @@ -34,7 +33,6 @@ * @since 17/11/2020 20:37 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbScriptStepV3DTO { @JsonProperty("script_type") private Integer type; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptV3DTO.java index 08966b1260..fbad16fff9 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptV3DTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbScriptV3DTO { private String id; @JsonProperty("bk_biz_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptVersionDetailV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptVersionDetailV3DTO.java index 4f0cbf787f..8b61508775 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptVersionDetailV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbScriptVersionDetailV3DTO.java @@ -24,12 +24,10 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbScriptVersionDetailV3DTO { private Long id; @JsonProperty("bk_biz_id") diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbStepV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbStepV3DTO.java index 4e1b66b978..d0312d589f 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbStepV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbStepV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -32,7 +31,6 @@ * @since 17/11/2020 16:41 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbStepV3DTO { private Long id; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbTemplateBasicInfoV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbTemplateBasicInfoV3DTO.java index d8bbe15a71..b999842be5 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbTemplateBasicInfoV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbTemplateBasicInfoV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -34,7 +33,6 @@ * @since 15/10/2020 17:54 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbTemplateBasicInfoV3DTO { /** diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbUserRoleInfoV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbUserRoleInfoV3DTO.java index 0d79db83d7..7418ceaa96 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbUserRoleInfoV3DTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbUserRoleInfoV3DTO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.esb.v3.response; -import com.fasterxml.jackson.annotation.JsonInclude; import com.tencent.bk.job.common.model.dto.UserRoleInfoDTO; import lombok.Data; @@ -36,7 +35,6 @@ * @since 17/11/2020 21:51 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) public class EsbUserRoleInfoV3DTO { /** * 用户名列表 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/ServiceAppBaseInfoDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/ServiceAppBaseInfoDTO.java new file mode 100644 index 0000000000..5a8db05f8b --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/ServiceAppBaseInfoDTO.java @@ -0,0 +1,46 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.model.inner; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 业务 + */ +@Data +@ApiModel("业务") +public class ServiceAppBaseInfoDTO { + + @ApiModelProperty("业务ID") + private Long id; + + /** + * 业务名称 + */ + @ApiModelProperty("业务名称") + private String name; +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/BatchGetPlanReq.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/BatchGetPlanReq.java new file mode 100644 index 0000000000..ecd07eff09 --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/BatchGetPlanReq.java @@ -0,0 +1,46 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.model.web.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel("批量获取执行方案请求报文") +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BatchGetPlanReq { + /** + * 作业模板ID列表 + */ + @ApiModelProperty(value = "作业模板ID列表", required = true) + @JsonProperty("templateIdList") + private List templateIdList; + +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/IpCheckReq.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/IpCheckReq.java new file mode 100644 index 0000000000..089a297dcd --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/IpCheckReq.java @@ -0,0 +1,46 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.model.web.request; + +import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel("IP检查请求报文") +public class IpCheckReq { + + @ApiModelProperty(value = "应用场景:脚本执行/文件分发", required = false) + ActionScopeEnum actionScope; + + @ApiModelProperty(value = "IP列表,单个IP格式:cloudAreaId:ip", required = true) + List ipList; + +} + + diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/TaskTemplateCreateUpdateReq.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/TaskTemplateCreateUpdateReq.java index bc8bc1aa6b..4565ba32dd 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/TaskTemplateCreateUpdateReq.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/TaskTemplateCreateUpdateReq.java @@ -25,7 +25,11 @@ package com.tencent.bk.job.manage.model.web.request; import com.tencent.bk.job.common.util.JobContextUtil; -import com.tencent.bk.job.common.util.check.*; +import com.tencent.bk.job.common.util.check.IlegalCharChecker; +import com.tencent.bk.job.common.util.check.MaxLengthChecker; +import com.tencent.bk.job.common.util.check.NotEmptyChecker; +import com.tencent.bk.job.common.util.check.StringCheckHelper; +import com.tencent.bk.job.common.util.check.TrimChecker; import com.tencent.bk.job.common.util.check.exception.StringCheckException; import com.tencent.bk.job.manage.model.web.vo.task.TaskStepVO; import com.tencent.bk.job.manage.model.web.vo.task.TaskVariableVO; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailVO.java index 72a79e10ce..fb61c3dbfc 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailVO.java @@ -27,7 +27,11 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; import io.swagger.annotations.ApiModelProperty; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; /** * 消息模板详情 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailWithDefaultVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailWithDefaultVO.java index 3234823fb9..08520f42cb 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailWithDefaultVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateDetailWithDefaultVO.java @@ -24,7 +24,11 @@ package com.tencent.bk.job.manage.model.web.vo.notify; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; /** * 消息模板详情 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateStatusVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateStatusVO.java index c19825ddfd..9f3f4f27d7 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateStatusVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ChannelTemplateStatusVO.java @@ -25,7 +25,11 @@ package com.tencent.bk.job.manage.model.web.vo.notify; import io.swagger.annotations.ApiModelProperty; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import java.util.List; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/NotifyBlackUserInfoVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/NotifyBlackUserInfoVO.java index 37fc515246..d54eb77229 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/NotifyBlackUserInfoVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/NotifyBlackUserInfoVO.java @@ -26,7 +26,11 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; /** * 通知黑名单用户信息VO diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ResourceStatusChannelVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ResourceStatusChannelVO.java index b8946b85e4..1aad8cc822 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ResourceStatusChannelVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/notify/ResourceStatusChannelVO.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.manage.model.web.vo.notify; -import com.tencent.bk.job.common.model.vo.NotifyChannelVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/task/TaskPlanVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/task/TaskPlanVO.java index 1991d7a779..e5feb40f51 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/task/TaskPlanVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/task/TaskPlanVO.java @@ -27,7 +27,11 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.util.JobContextUtil; -import com.tencent.bk.job.common.util.check.*; +import com.tencent.bk.job.common.util.check.IlegalCharChecker; +import com.tencent.bk.job.common.util.check.MaxLengthChecker; +import com.tencent.bk.job.common.util.check.NotEmptyChecker; +import com.tencent.bk.job.common.util.check.StringCheckHelper; +import com.tencent.bk.job.common.util.check.TrimChecker; import com.tencent.bk.job.common.util.check.exception.StringCheckException; import com.tencent.bk.job.common.util.json.LongTimestampDeserializer; import com.tencent.bk.job.common.util.json.LongTimestampSerializer; diff --git a/src/backend/job-manage/boot-job-manage/build.gradle b/src/backend/job-manage/boot-job-manage/build.gradle index 89876a2799..e41dffe2a1 100644 --- a/src/backend/job-manage/boot-job-manage/build.gradle +++ b/src/backend/job-manage/boot-job-manage/build.gradle @@ -25,9 +25,9 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-manage:service-job-manage") - compile project(":commons:common-redis") - compile project(":commons:common-i18n") + api project(":job-manage:service-job-manage") + api project(":commons:common-redis") + api project(":commons:common-i18n") implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp' implementation 'org.springframework:spring-webmvc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis') implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.micrometer:micrometer-registry-prometheus' @@ -45,7 +46,7 @@ dependencies { testImplementation("com.h2database:h2") } springBoot { - mainClassName = "com.tencent.bk.job.manage.JobManageBootApplication" + mainClass = "com.tencent.bk.job.manage.JobManageBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/FilterConfig.java b/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/FilterConfig.java index dbc9c022da..de0003b896 100644 --- a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/FilterConfig.java +++ b/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/FilterConfig.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.manage.config; -import com.tencent.bk.job.common.web.filter.RepeatableReadServletRequestResponseFilter; +import com.tencent.bk.job.common.web.filter.RepeatableReadWriteServletRequestResponseFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,7 +33,7 @@ public class FilterConfig { @Bean public FilterRegistrationBean repeatableRSRRFilterRegister() { - FilterRegistrationBean registration = + FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(repeatableRRRFilter()); registration.addUrlPatterns("/esb/api/*"); @@ -43,7 +43,7 @@ public FilterRegistrationBean repeatableRSRRFilterRegister() { } @Bean(name = "repeatableReadRequestResponseFilter") - public RepeatableReadServletRequestResponseFilter repeatableRRRFilter() { - return new RepeatableReadServletRequestResponseFilter(); + public RepeatableReadWriteServletRequestResponseFilter repeatableRRRFilter() { + return new RepeatableReadWriteServletRequestResponseFilter(); } } diff --git a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/I18nConfig.java b/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/I18nConfig.java deleted file mode 100644 index 37b681e48f..0000000000 --- a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/I18nConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.manage.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -/** - * @date 2019/09/19 - */ -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/InterceptorConfiguration.java b/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/InterceptorConfiguration.java index dc18a650e5..045d0e8b0d 100644 --- a/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/InterceptorConfiguration.java +++ b/src/backend/job-manage/boot-job-manage/src/main/java/com/tencent/bk/job/manage/config/InterceptorConfiguration.java @@ -24,7 +24,10 @@ package com.tencent.bk.job.manage.config; +import com.tencent.bk.job.common.iam.interceptor.AuthAppInterceptor; +import com.tencent.bk.job.common.iam.interceptor.JobIamInterceptor; import com.tencent.bk.job.common.web.interceptor.EsbApiLogInterceptor; +import com.tencent.bk.job.common.web.interceptor.EsbReqRewriteInterceptor; import com.tencent.bk.job.common.web.interceptor.JobCommonInterceptor; import com.tencent.bk.job.common.web.interceptor.ServiceSecurityInterceptor; import com.tencent.bk.job.manage.common.interceptor.UriPermissionInterceptor; @@ -40,19 +43,30 @@ public class InterceptorConfiguration implements WebMvcConfigurer { private final JobCommonInterceptor jobCommonInterceptor; + private final AuthAppInterceptor authAppInterceptor; private final UriPermissionInterceptor uriPermissionInterceptor; private final EsbApiLogInterceptor esbApiLogInterceptor; + private final EsbReqRewriteInterceptor esbReqRewriteInterceptor; private final ServiceSecurityInterceptor serviceSecurityInterceptor; + private final JobIamInterceptor iamInterceptor; @Autowired - public InterceptorConfiguration(JobCommonInterceptor jobCommonInterceptor, - UriPermissionInterceptor uriPermissionInterceptor, - EsbApiLogInterceptor esbApiLogInterceptor, - ServiceSecurityInterceptor serviceSecurityInterceptor) { + public InterceptorConfiguration( + JobCommonInterceptor jobCommonInterceptor, + AuthAppInterceptor authAppInterceptor, + UriPermissionInterceptor uriPermissionInterceptor, + EsbApiLogInterceptor esbApiLogInterceptor, + EsbReqRewriteInterceptor esbReqRewriteInterceptor, + ServiceSecurityInterceptor serviceSecurityInterceptor, + JobIamInterceptor iamInterceptor + ) { this.jobCommonInterceptor = jobCommonInterceptor; + this.authAppInterceptor = authAppInterceptor; this.uriPermissionInterceptor = uriPermissionInterceptor; this.esbApiLogInterceptor = esbApiLogInterceptor; + this.esbReqRewriteInterceptor = esbReqRewriteInterceptor; this.serviceSecurityInterceptor = serviceSecurityInterceptor; + this.iamInterceptor = iamInterceptor; } @Override @@ -64,6 +78,9 @@ public void addInterceptors(InterceptorRegistry registry) { .addPathPatterns( uriPermissionInterceptor.getControlUriPatterns() ).order(2); + registry.addInterceptor(iamInterceptor).addPathPatterns("/iam/api/v1/resources/**").order(3); registry.addInterceptor(esbApiLogInterceptor).addPathPatterns("/esb/api/**").order(10); + registry.addInterceptor(esbReqRewriteInterceptor).addPathPatterns("/esb/api/**").order(11); + registry.addInterceptor(authAppInterceptor).addPathPatterns("/web/**", "/esb/api/**").order(12); } } diff --git a/src/backend/job-manage/boot-job-manage/src/main/resources/application.yml b/src/backend/job-manage/boot-job-manage/src/main/resources/application.yml index a0910febd3..21043fc5fa 100644 --- a/src/backend/job-manage/boot-job-manage/src/main/resources/application.yml +++ b/src/backend/job-manage/boot-job-manage/src/main/resources/application.yml @@ -55,7 +55,7 @@ job: service: private-key-base64: ${job.security.private-key-base64} public-key-base64: ${job.security.public-key-base64} - edition: ee + edition: ce diff --git a/src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplTest.java b/src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplIntegrationTest.java similarity index 98% rename from src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplTest.java rename to src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplIntegrationTest.java index 06d24ef3fb..ad22973830 100644 --- a/src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplTest.java +++ b/src/backend/job-manage/boot-job-manage/src/test/java/com/tencent/bk/job/manage/dao/globalsetting/impl/DangerousRuleDAOImplIntegrationTest.java @@ -47,7 +47,7 @@ @TestPropertySource(locations = "classpath:test.properties") @Sql(value = {"/init_dangerous_rule_data.sql"}) @SqlConfig(encoding = "utf-8") -class DangerousRuleDAOImplTest { +class DangerousRuleDAOImplIntegrationTest { @Autowired private DangerousRuleDAO dangerousRuleDAO; diff --git a/src/backend/job-manage/build.gradle b/src/backend/job-manage/build.gradle index b5f5d3622e..2ccd08470f 100644 --- a/src/backend/job-manage/build.gradle +++ b/src/backend/job-manage/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobManageVersion")) { set("jobManageVersion", System.getProperty("jobManageVersion")) + } else if (System.getProperty("version")) { + set("jobManageVersion", System.getProperty("version")) } else { set("jobManageVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobManageVersion}" subprojects { version "${jobManageVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-manage/service-job-manage/build.gradle b/src/backend/job-manage/service-job-manage/build.gradle index 40da634964..a3834cd04f 100644 --- a/src/backend/job-manage/service-job-manage/build.gradle +++ b/src/backend/job-manage/service-job-manage/build.gradle @@ -24,19 +24,20 @@ apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":commons:common-spring-ext") - compile project(":commons:common-web") - compile project(":job-manage:api-job-manage") - compile project(":job-manage:model-job-manage") - compile project(":job-crontab:api-job-crontab") - compile project(":job-analysis:api-job-analysis") - compile project(":commons:common") - compile project(":commons:common-security") - compile project(":commons:common-redis") - compile project(":commons:cmdb-sdk-ext") - compile project(":commons:paas-sdk") - compile project(":commons:esb-sdk") - compile project(":commons:gse-sdk") + api project(":commons:common-spring-ext") + api project(":commons:common-web") + api project(":job-manage:api-job-manage") + api project(":job-manage:model-job-manage") + api project(":job-crontab:api-job-crontab") + api project(":job-analysis:api-job-analysis") + api project(":job-ticket:api-job-ticket") + api project(":commons:common") + api project(":commons:common-security") + api project(":commons:common-redis") + api project(":commons:cmdb-sdk-ext") + api project(":commons:paas-sdk") + api project(":commons:esb-sdk") + api project(":commons:gse-sdk") implementation "org.springframework.boot:spring-boot-starter-web" implementation "org.springframework.boot:spring-boot-starter-jdbc" implementation "org.springframework.boot:spring-boot-starter-jooq" @@ -54,4 +55,5 @@ dependencies { implementation "commons-codec:commons-codec" testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.apache.commons:commons-lang3' + implementation 'joda-time:joda-time' } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/common/ScriptDTOBuilder.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/common/ScriptDTOBuilder.java index 6a9c33fb6d..5665bef6a0 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/common/ScriptDTOBuilder.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/common/ScriptDTOBuilder.java @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.List; -import static com.tencent.bk.job.manage.common.constants.JobManageConstants.PUBLIC_APP_ID; +import static com.tencent.bk.job.common.constant.JobConstants.PUBLIC_APP_ID; @Service public class ScriptDTOBuilder { diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetDBAccountListResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetDBAccountListResourceImpl.java index 9e4ccc9ad9..5f006223cc 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetDBAccountListResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetDBAccountListResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.manage.api.esb.EsbGetDBAccountListResource; @@ -61,7 +61,7 @@ public EsbGetDBAccountListResourceImpl(AccountService accountService, MessageI18 @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_own_db_account_list"}) - public EsbResp> getUserOwnDbAccountList(String lang, EsbGetDBAccountListRequest request) { + public EsbResp> getUserOwnDbAccountList(EsbGetDBAccountListRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get db account list, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobDetailResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobDetailResourceImpl.java index ac5b9ff82b..28651f882f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobDetailResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobDetailResourceImpl.java @@ -30,7 +30,7 @@ import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.EsbFileSourceDTO; import com.tencent.bk.job.common.esb.model.job.EsbIpDTO; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -85,7 +85,7 @@ public EsbGetJobDetailResourceImpl(TaskPlanService taskPlanService, ScriptServic @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_job_detail"}) - public EsbResp getJobDetail(String lang, EsbGetJobDetailRequest request) { + public EsbResp getJobDetail(EsbGetJobDetailRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job detail, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobListResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobListResourceImpl.java index 610c3f9a6c..0de1b63024 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobListResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetJobListResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -69,7 +69,7 @@ public EsbGetJobListResourceImpl(TaskPlanService taskPlanService, MessageI18nSer @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_job_list"}) - public EsbResp> getJobList(String lang, EsbGetJobListRequest request) { + public EsbResp> getJobList(EsbGetJobListRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get job list, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetOSAccountResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetOSAccountResourceImpl.java index 9bf0305da8..4d6dd91760 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetOSAccountResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetOSAccountResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.manage.api.esb.EsbGetOSAccountResource; @@ -63,7 +63,7 @@ public EsbGetOSAccountResourceImpl(AccountService accountService, MessageI18nSer @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_os_account"}) - public EsbResp> getAppOsAccountList(String lang, EsbGetOSAccountListRequest request) { + public EsbResp> getAppOsAccountList(EsbGetOSAccountListRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get system account list, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetPublicScriptListResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetPublicScriptListResourceImpl.java index 9eb76e4e80..1e3afd7b61 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetPublicScriptListResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetPublicScriptListResourceImpl.java @@ -28,13 +28,13 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbPageData; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.manage.api.esb.EsbGetPublicScriptListResource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.model.dto.ScriptDTO; @@ -65,7 +65,7 @@ public EsbGetPublicScriptListResourceImpl(ScriptService scriptService, MessageI1 @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_public_script_list"}) - public EsbResp> getPublicScriptList(String lang, EsbGetPublicScriptListRequest request) { + public EsbResp> getPublicScriptList(EsbGetPublicScriptListRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get public script list, request is illegal!"); @@ -74,7 +74,7 @@ public EsbResp> getPublicScriptList(String lang, EsbGe boolean returnScriptContent = (request.getReturnScriptContent() != null && request.getReturnScriptContent()); - long appId = JobManageConstants.PUBLIC_APP_ID; + long appId = JobConstants.PUBLIC_APP_ID; ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); scriptQuery.setAppId(appId); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptDetailResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptDetailResourceImpl.java index 1bd9becb2a..62c2cdb43f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptDetailResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptDetailResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -61,7 +61,7 @@ public EsbGetScriptDetailResourceImpl(ScriptService scriptService, MessageI18nSe @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_script_detail"}) - public EsbResp getScriptDetail(String lang, EsbGetScriptDetailRequest request) { + public EsbResp getScriptDetail(EsbGetScriptDetailRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get script detail, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptListResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptListResourceImpl.java index 537cd24d7a..9bbf9588f1 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptListResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/EsbGetScriptListResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbPageData; import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.model.BaseSearchCondition; @@ -36,7 +36,7 @@ import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.manage.api.esb.EsbGetScriptListResource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.model.dto.ScriptDTO; @@ -70,7 +70,7 @@ public EsbGetScriptListResourceImpl(ScriptService scriptService, MessageI18nServ @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v2_get_script_list"}) - public EsbResp> getScriptList(String lang, EsbGetScriptListRequest request) { + public EsbResp> getScriptList(EsbGetScriptListRequest request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get script list, request is illegal!"); @@ -82,7 +82,7 @@ public EsbResp> getScriptList(String lang, EsbGetScrip long appId = request.getAppId(); if (isQueryPublicScript) { - appId = JobManageConstants.PUBLIC_APP_ID; + appId = JobConstants.PUBLIC_APP_ID; } ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbAccountResourceV3Impl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbAccountResourceV3Impl.java index 52db8e18ea..2e396f53e2 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbAccountResourceV3Impl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbAccountResourceV3Impl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.manage.api.esb.v3.EsbAccountV3Resource; @@ -61,7 +61,7 @@ public EsbAccountResourceV3Impl(AccountService accountService, MessageI18nServic @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_account_list"}) - public EsbResp> getAccountList(String lang, EsbGetAccountListV3Req request) { + public EsbResp> getAccountListUsingPost(EsbGetAccountListV3Req request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get account list, request is illegal!"); @@ -122,4 +122,16 @@ private ValidateResult checkRequest(EsbGetAccountListV3Req request) { return ValidateResult.pass(); } + @Override + public EsbResp> getAccountList(String username, String appCode, Long appId, + Integer category, Integer start, Integer length) { + EsbGetAccountListV3Req request = new EsbGetAccountListV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setCategory(category); + request.setStart(start); + request.setLength(length); + return getAccountListUsingPost(request); + } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java new file mode 100644 index 0000000000..ad3b8f5d9f --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java @@ -0,0 +1,162 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.api.esb.impl.v3; + +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.common.exception.InvalidParamException; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; +import com.tencent.bk.job.common.iam.service.AuthService; +import com.tencent.bk.job.common.web.model.InnerServiceResponse; +import com.tencent.bk.job.manage.api.esb.v3.EsbCredentialV3Resource; +import com.tencent.bk.job.manage.client.ServiceCredentialResourceClient; +import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialSimpleInfoV3DTO; +import com.tencent.bk.job.ticket.consts.CredentialTypeEnum; +import com.tencent.bk.job.ticket.model.inner.resp.ServiceBasicCredentialDTO; +import com.tencent.bk.job.ticket.model.web.req.CredentialCreateUpdateReq; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.APP_ID_SECRET_KEY; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.PASSWORD; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.SECRET_KEY; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.USERNAME_PASSWORD; + +@RestController +@Slf4j +public class EsbCredentialResourceV3Impl implements EsbCredentialV3Resource { + private final ServiceCredentialResourceClient credentialService; + private final AuthService authService; + private final MessageI18nService i18nService; + + @Autowired + public EsbCredentialResourceV3Impl(ServiceCredentialResourceClient credentialService, AuthService authService, MessageI18nService i18nService) { + this.credentialService = credentialService; + this.authService = authService; + this.i18nService = i18nService; + } + + @Override + public EsbResp createCredential(EsbCreateOrUpdateCredentialV3Req req) { + checkCreateParam(req); + return saveCredential(req); + } + + @Override + public EsbResp updateCredential(EsbCreateOrUpdateCredentialV3Req req) { + checkUpdateParam(req); + return saveCredential(req); + } + + private void checkAppId(Long appId) { + if (appId == null) { + throw new InvalidParamException("bk_biz_id", "bk_biz_id cannot be null"); + } + } + + private void checkCreateParam(EsbCreateOrUpdateCredentialV3Req req) { + checkAppId(req.getAppId()); + String name = req.getName(); + String type = req.getType(); + if (StringUtils.isBlank(name)) { + throw new InvalidParamException("name", "name cannot be null or blank"); + } + if (StringUtils.isBlank(type)) { + throw new InvalidParamException("type", "type cannot be null or blank"); + } + } + + private void checkUpdateParam(EsbCreateOrUpdateCredentialV3Req req) { + checkAppId(req.getAppId()); + if (StringUtils.isBlank(req.getId())) { + throw new InvalidParamException("id", "id cannot be null or blank"); + } + } + + private EsbResp saveCredential(EsbCreateOrUpdateCredentialV3Req req) { + CredentialCreateUpdateReq createUpdateReq = convertToCreateUpdateReq(req); + InnerServiceResponse resp; + if (req.getId() == null) { + resp = credentialService.createCredential( + req.getUserName(), + req.getAppId(), + createUpdateReq + ); + } else { + resp = credentialService.updateCredential( + req.getUserName(), + req.getAppId(), + createUpdateReq + ); + } + if (resp.getAuthResult() != null) { + return authService.buildEsbAuthFailResp( + resp.getAuthResult().getRequiredActionResources() + ); + } else if (!resp.isSuccess()) { + return EsbResp.buildCommonFailResp( + resp.getCode(), + resp.getErrorDetail(), + i18nService + ); + } + ServiceBasicCredentialDTO data = resp.getData(); + return EsbResp.buildSuccessResp(new EsbCredentialSimpleInfoV3DTO(data.getId())); + } + + private CredentialCreateUpdateReq convertToCreateUpdateReq( + EsbCreateOrUpdateCredentialV3Req req + ) { + String type = req.getType(); + CredentialCreateUpdateReq createUpdateReq = new CredentialCreateUpdateReq(); + createUpdateReq.setId(req.getId()); + createUpdateReq.setName(req.getName()); + createUpdateReq.setType(CredentialTypeEnum.valueOf(req.getType())); + createUpdateReq.setDescription(req.getDescription()); + if (SECRET_KEY.name().equals(type)) { + createUpdateReq.setValue1(req.getCredentialSecretKey()); + } else if (PASSWORD.name().equals(type)) { + createUpdateReq.setValue1(req.getCredentialPassword()); + } else if (APP_ID_SECRET_KEY.name().equals(type)) { + createUpdateReq.setValue1(req.getCredentialAccessKey()); + createUpdateReq.setValue2(req.getCredentialSecretKey()); + } else if (USERNAME_PASSWORD.name().equals(type)) { + createUpdateReq.setValue1(req.getCredentialUsername()); + createUpdateReq.setValue2(req.getCredentialPassword()); + } else { + throw new InvalidParamException( + "type", + String.format( + "Unsupported type:%s, supported types:%s", + type, + CredentialTypeEnum.getAllNameStr() + ) + ); + } + return createUpdateReq; + } +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPlanV3ResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPlanV3ResourceImpl.java index 817c0814fe..e5501c1fbd 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPlanV3ResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPlanV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -68,9 +68,50 @@ public EsbPlanV3ResourceImpl(TaskPlanService taskPlanService, MessageI18nService this.authService = authService; } + @Override + public EsbResp> getPlanList(String username, + String appCode, + Long appId, + Long templateId, + String creator, + String name, + Long createTimeStart, + Long createTimeEnd, + String lastModifyUser, + Long lastModifyTimeStart, + Long lastModifyTimeEnd, + Integer start, + Integer length) { + EsbGetPlanListV3Request request = new EsbGetPlanListV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setTemplateId(templateId); + request.setCreator(creator); + request.setName(name); + request.setCreateTimeStart(createTimeStart); + request.setCreateTimeEnd(createTimeEnd); + request.setLastModifyUser(lastModifyUser); + request.setLastModifyTimeStart(lastModifyTimeStart); + request.setLastModifyTimeEnd(lastModifyTimeEnd); + request.setStart(start); + request.setLength(length); + return getPlanListUsingPost(request); + } + + @Override + public EsbResp getPlanDetail(String username, String appCode, Long appId, Long planId) { + EsbGetPlanDetailV3Request request = new EsbGetPlanDetailV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setPlanId(planId); + return getPlanDetailUsingPost(request); + } + @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_plan_list"}) - public EsbResp> getPlanList(String lang, EsbGetPlanListV3Request request) { + public EsbResp> getPlanListUsingPost(EsbGetPlanListV3Request request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get plan list, request is illegal!"); @@ -118,7 +159,7 @@ public EsbResp> getPlanList(String lang, Es @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_plan_detail"}) - public EsbResp getPlanDetail(String lang, EsbGetPlanDetailV3Request request) { + public EsbResp getPlanDetailUsingPost(EsbGetPlanDetailV3Request request) { ValidateResult validateResult = request.validate(); if (validateResult.isPass()) { TaskPlanInfoDTO taskPlanInfo = taskPlanService.getTaskPlanById(request.getAppId(), request.getPlanId()); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPublicScriptResourceV3Impl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPublicScriptResourceV3Impl.java index fb65605b97..edae93bb13 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPublicScriptResourceV3Impl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbPublicScriptResourceV3Impl.java @@ -29,7 +29,7 @@ import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; import com.tencent.bk.job.manage.api.esb.v3.EsbPublicScriptV3Resource; import com.tencent.bk.job.manage.api.esb.v3.EsbScriptV3Resource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptListV3Req; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptVersionDetailV3Req; import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetScriptVersionListV3Req; @@ -49,29 +49,75 @@ public EsbPublicScriptResourceV3Impl(EsbScriptV3Resource esbScriptV3Resource) { this.esbScriptV3Resource = esbScriptV3Resource; } + @Override + public EsbResp> getPublicScriptList(String username, + String appCode, + String name, + Integer scriptLanguage, + Integer start, + Integer length) { + EsbGetScriptListV3Req request = new EsbGetScriptListV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setName(name); + request.setScriptLanguage(scriptLanguage); + request.setStart(start); + request.setLength(length); + return getPublicScriptListUsingPost(request); + } + + @Override + public EsbResp> getPublicScriptVersionList(String username, + String appCode, + String scriptId, + boolean returnScriptContent, + Integer start, + Integer length) { + EsbGetScriptVersionListV3Req request = new EsbGetScriptVersionListV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setScriptId(scriptId); + request.setReturnScriptContent(returnScriptContent); + request.setStart(start); + request.setLength(length); + return getPublicScriptVersionListUsingPost(request); + } + + @Override + public EsbResp getPublicScriptVersionDetail(String username, + String appCode, + Long scriptVersionId, + String scriptId, + String version) { + EsbGetScriptVersionDetailV3Req request = new EsbGetScriptVersionDetailV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setId(scriptVersionId); + request.setScriptId(scriptId); + request.setVersion(version); + return getPublicScriptVersionDetailUsingPost(request); + } @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_public_script_list"}) - public EsbResp> getPublicScriptList(String lang, EsbGetScriptListV3Req request) { - request.setAppId(JobManageConstants.PUBLIC_APP_ID); - return esbScriptV3Resource.getScriptList(lang, request); + public EsbResp> getPublicScriptListUsingPost(EsbGetScriptListV3Req request) { + request.setAppId(JobConstants.PUBLIC_APP_ID); + return esbScriptV3Resource.getScriptListUsingPost(request); } @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_public_script_version_list"}) - public EsbResp> getPublicScriptVersionList( - String lang, + public EsbResp> getPublicScriptVersionListUsingPost( EsbGetScriptVersionListV3Req request ) { - request.setAppId(JobManageConstants.PUBLIC_APP_ID); - return esbScriptV3Resource.getScriptVersionList(lang, request); + request.setAppId(JobConstants.PUBLIC_APP_ID); + return esbScriptV3Resource.getScriptVersionListUsingPost(request); } @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_public_script_version_detail"}) - public EsbResp getPublicScriptVersionDetail(String lang, - EsbGetScriptVersionDetailV3Req request) { - request.setAppId(JobManageConstants.PUBLIC_APP_ID); - return esbScriptV3Resource.getScriptVersionDetail(lang, request); + public EsbResp getPublicScriptVersionDetailUsingPost(EsbGetScriptVersionDetailV3Req request) { + request.setAppId(JobConstants.PUBLIC_APP_ID); + return esbScriptV3Resource.getScriptVersionDetailUsingPost(request); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbScriptResourceV3Impl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbScriptResourceV3Impl.java index 7791c42446..7a5b5f8686 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbScriptResourceV3Impl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbScriptResourceV3Impl.java @@ -28,14 +28,14 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.manage.api.esb.v3.EsbScriptV3Resource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.model.dto.ScriptDTO; @@ -51,7 +51,11 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @RestController @@ -69,16 +73,71 @@ public EsbScriptResourceV3Impl(ScriptService scriptService, MessageI18nService i } + @Override + public EsbResp> getScriptList(String username, + String appCode, + Long appId, + String name, + Integer scriptLanguage, + Integer start, + Integer length) { + EsbGetScriptListV3Req request = new EsbGetScriptListV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setName(name); + request.setScriptLanguage(scriptLanguage); + request.setStart(start); + request.setLength(length); + return getScriptListUsingPost(request); + } + + @Override + public EsbResp> getScriptVersionList(String username, + String appCode, + Long appId, + String scriptId, + boolean returnScriptContent, + Integer start, + Integer length) { + EsbGetScriptVersionListV3Req request = new EsbGetScriptVersionListV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setScriptId(scriptId); + request.setReturnScriptContent(returnScriptContent); + request.setStart(start); + request.setLength(length); + return getScriptVersionListUsingPost(request); + } + + @Override + public EsbResp getScriptVersionDetail(String username, + String appCode, + Long appId, + Long scriptVersionId, + String scriptId, + String version) { + EsbGetScriptVersionDetailV3Req request = new EsbGetScriptVersionDetailV3Req(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setId(scriptVersionId); + request.setScriptId(scriptId); + request.setVersion(version); + return getScriptVersionDetailUsingPost(request); + } + @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_script_list"}) - public EsbResp> getScriptList(String lang, EsbGetScriptListV3Req request) { + public EsbResp> getScriptListUsingPost(EsbGetScriptListV3Req request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get script list, request is illegal!"); return EsbResp.buildCommonFailResp(i18nService, checkResult); } - boolean isQueryPublicScript = request.getAppId() == JobManageConstants.PUBLIC_APP_ID; + boolean isQueryPublicScript = request.getAppId() == JobConstants.PUBLIC_APP_ID; long appId = request.getAppId(); @@ -267,8 +326,7 @@ private ValidateResult checkRequest(EsbGetScriptVersionListV3Req request) { @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_script_version_list"}) - public EsbResp> getScriptVersionList( - String lang, + public EsbResp> getScriptVersionListUsingPost( EsbGetScriptVersionListV3Req request ) { ValidateResult checkResult = checkRequest(request); @@ -277,7 +335,7 @@ public EsbResp> getScriptVersionList( return EsbResp.buildCommonFailResp(i18nService, checkResult); } - boolean isQueryPublicScript = request.getAppId() == JobManageConstants.PUBLIC_APP_ID; + boolean isQueryPublicScript = request.getAppId() == JobConstants.PUBLIC_APP_ID; long appId = request.getAppId(); @@ -346,8 +404,7 @@ private ValidateResult checkRequest(EsbGetScriptVersionDetailV3Req request) { @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_script_version_detail"}) - public EsbResp getScriptVersionDetail(String lang, - EsbGetScriptVersionDetailV3Req request) { + public EsbResp getScriptVersionDetailUsingPost(EsbGetScriptVersionDetailV3Req request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get scriptVersion list, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbTemplateV3ResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbTemplateV3ResourceImpl.java index dc6fb24831..02abb88980 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbTemplateV3ResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbTemplateV3ResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.AuthResult; @@ -63,10 +63,38 @@ public EsbTemplateV3ResourceImpl(TaskTemplateService taskTemplateService, Messag this.authService = authService; } + @Override + public EsbResp> getTemplateList(String username, + String appCode, + Long appId, + String creator, + String name, + Long createTimeStart, + Long createTimeEnd, + String lastModifyUser, + Long lastModifyTimeStart, + Long lastModifyTimeEnd, + Integer start, + Integer length) { + EsbGetTemplateListV3Request request = new EsbGetTemplateListV3Request(); + request.setUserName(username); + request.setAppCode(appCode); + request.setAppId(appId); + request.setCreator(creator); + request.setName(name); + request.setCreateTimeStart(createTimeStart); + request.setLastModifyUser(lastModifyUser); + request.setCreateTimeEnd(createTimeEnd); + request.setLastModifyTimeEnd(lastModifyTimeEnd); + request.setLastModifyTimeStart(lastModifyTimeStart); + request.setStart(start); + request.setLength(length); + return getTemplateListUsingPost(request); + } + @Override @EsbApiTimed(value = "esb.api", extraTags = {"api_name", "v3_get_job_template_list"}) - public EsbResp> getTemplateList(String lang, - EsbGetTemplateListV3Request request) { + public EsbResp> getTemplateListUsingPost(EsbGetTemplateListV3Request request) { ValidateResult checkResult = checkRequest(request); if (!checkResult.isPass()) { log.warn("Get template list, request is illegal!"); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamAccountCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamAccountCallbackResourceImpl.java index b1e678d637..9c7ebcc51e 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamAccountCallbackResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamAccountCallbackResourceImpl.java @@ -24,25 +24,33 @@ package com.tencent.bk.job.manage.api.iam.impl; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.api.iam.IamAccountCallbackResource; import com.tencent.bk.job.manage.model.dto.AccountDTO; import com.tencent.bk.job.manage.service.AccountService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @RestController @Slf4j -public class IamAccountCallbackResourceImpl implements IamAccountCallbackResource { +public class IamAccountCallbackResourceImpl extends BaseIamCallbackService implements IamAccountCallbackResource { private final AccountService accountService; @Autowired @@ -50,93 +58,92 @@ public IamAccountCallbackResourceImpl(AccountService accountService) { this.accountService = accountService; } + private Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); + + AccountDTO accountQuery = new AccountDTO(); + accountQuery.setAppId(searchCondition.getAppIdList().get(0)); + return Pair.of(accountQuery, baseSearchCondition); + } + + private InstanceInfoDTO convert(AccountDTO accountDTO) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(accountDTO.getId())); + instanceInfo.setDisplayName(accountDTO.getAlias()); + return instanceInfo; + } + @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + + AccountDTO accountQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + PageData accountDTOPageData = accountService.listPageAccount(accountQuery, + baseSearchCondition); + + return IamRespUtil.getListInstanceRespFromPageData(accountDTOPageData, this::convert); + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + AccountDTO accountQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + accountQuery.setAlias(callbackRequest.getFilter().getKeyword()); + PageData accountDTOPageData = accountService.listPageAccount(accountQuery, + baseSearchCondition); + + return IamRespUtil.getSearchInstanceRespFromPageData(accountDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - AccountDTO accountQuery = new AccountDTO(); - accountQuery.setAppId(searchCondition.getAppIdList().get(0)); - PageData accountDTOPageData = accountService.listPageAccount(accountQuery, - baseSearchCondition); - - List instanceInfoList = - accountDTOPageData.getData().parallelStream().map(accountDTO -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(accountDTO.getId())); - instanceInfo.setDisplayName(accountDTO.getAlias()); - return instanceInfo; - }).collect(Collectors.toList()); - - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - baseDataResponse.setResult(instanceInfoList); - baseDataResponse.setCount(accountDTOPageData.getTotal()); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - long id = Long.parseLong(instanceId); - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - AccountDTO accountDTO = accountService.getAccountById(id); - if (accountDTO != null) { - instanceInfo.setDisplayName(accountDTO.getAlias()); - } else { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected accountId:{} passed by iam", id); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + long id = Long.parseLong(instanceId); + AccountDTO accountDTO = accountService.getAccountById(id); + if (accountDTO == null) { + return getNotFoundRespById(instanceId); } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(accountDTO.getAppId().toString()); + PathInfoDTO accountNode = new PathInfoDTO(); + accountNode.setType(ResourceId.ACCOUNT); + accountNode.setId(accountDTO.getId().toString()); + rootNode.setChild(accountNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(accountDTO.getAlias()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } } - return response; + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamPublicScriptCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamPublicScriptCallbackResourceImpl.java index 3502c5eac9..7b3a9612bc 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamPublicScriptCallbackResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamPublicScriptCallbackResourceImpl.java @@ -25,116 +25,50 @@ package com.tencent.bk.job.manage.api.iam.impl; import com.tencent.bk.job.common.model.BaseSearchCondition; -import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.api.iam.IamPublicScriptCallbackResource; -import com.tencent.bk.job.manage.model.dto.ScriptDTO; import com.tencent.bk.job.manage.model.dto.ScriptQueryDTO; import com.tencent.bk.job.manage.service.ScriptService; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - @RestController @Slf4j public class IamPublicScriptCallbackResourceImpl implements IamPublicScriptCallbackResource { - private ScriptService scriptService; + private ScriptCallbackHelper scriptCallbackHelper; @Autowired public IamPublicScriptCallbackResourceImpl(ScriptService scriptService) { - this.scriptService = scriptService; + this.scriptCallbackHelper = new ScriptCallbackHelper(scriptService, new ScriptCallbackHelper.IGetBasicInfo() { + @Override + public Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + return getBasicQueryConditionImpl(callbackRequest); + } + + @Override + public boolean isPublicScript() { + return true; + } + }); } - @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + private Pair getBasicQueryConditionImpl(CallbackRequestDTO callbackRequest) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); - scriptQuery.setPublicScript(true); - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - PageData scriptPageData = - scriptService.listPageScript(scriptQuery, baseSearchCondition); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); - List instanceInfoList = - scriptPageData.getData().parallelStream().map(script -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(script.getId())); - instanceInfo.setDisplayName(script.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - baseDataResponse.setResult(instanceInfoList); - baseDataResponse.setCount(scriptPageData.getTotal()); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - ScriptDTO scriptDTO = scriptService.getScriptByScriptId(instanceId); - if (scriptDTO != null) { - instanceInfo.setDisplayName(scriptDTO.getName()); - } else { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected scriptId:{} passed by iam", instanceId); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); + scriptQuery.setPublicScript(true); + return Pair.of(scriptQuery, baseSearchCondition); + } - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); - } - return response; + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return scriptCallbackHelper.doCallback(callbackRequest); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamScriptCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamScriptCallbackResourceImpl.java index 7edeb31e4f..e5c4dd645d 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamScriptCallbackResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamScriptCallbackResourceImpl.java @@ -25,116 +25,50 @@ package com.tencent.bk.job.manage.api.iam.impl; import com.tencent.bk.job.common.model.BaseSearchCondition; -import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.api.iam.IamScriptCallbackResource; -import com.tencent.bk.job.manage.model.dto.ScriptDTO; import com.tencent.bk.job.manage.model.dto.ScriptQueryDTO; import com.tencent.bk.job.manage.service.ScriptService; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - @RestController @Slf4j public class IamScriptCallbackResourceImpl implements IamScriptCallbackResource { - private ScriptService scriptService; + private ScriptCallbackHelper scriptCallbackHelper; @Autowired public IamScriptCallbackResourceImpl(ScriptService scriptService) { - this.scriptService = scriptService; + this.scriptCallbackHelper = new ScriptCallbackHelper(scriptService, new ScriptCallbackHelper.IGetBasicInfo() { + @Override + public Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + return getBasicQueryConditionImpl(callbackRequest); + } + + @Override + public boolean isPublicScript() { + return false; + } + }); } - @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + private Pair getBasicQueryConditionImpl(CallbackRequestDTO callbackRequest) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); - scriptQuery.setAppId(searchCondition.getAppIdList().get(0)); - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - PageData scriptPageData = - scriptService.listPageScript(scriptQuery, baseSearchCondition); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); - List instanceInfoList = - scriptPageData.getData().parallelStream().map(script -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(script.getId())); - instanceInfo.setDisplayName(script.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - baseDataResponse.setResult(instanceInfoList); - baseDataResponse.setCount(scriptPageData.getTotal()); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - ScriptDTO scriptDTO = scriptService.getScriptByScriptId(instanceId); - if (scriptDTO != null) { - instanceInfo.setDisplayName(scriptDTO.getName()); - } else { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected scriptId:{} passed by iam", instanceId); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + ScriptQueryDTO scriptQuery = new ScriptQueryDTO(); + scriptQuery.setAppId(searchCondition.getAppIdList().get(0)); + return Pair.of(scriptQuery, baseSearchCondition); + } - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); - } - return response; + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return scriptCallbackHelper.doCallback(callbackRequest); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTagCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTagCallbackResourceImpl.java index c4fd125120..1a4947780c 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTagCallbackResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTagCallbackResourceImpl.java @@ -24,130 +24,122 @@ package com.tencent.bk.job.manage.api.iam.impl; +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.api.iam.IamTagCallbackResource; -import com.tencent.bk.job.manage.dao.TagDAO; import com.tencent.bk.job.manage.model.dto.TagDTO; import com.tencent.bk.job.manage.service.TagService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; @RestController @Slf4j -public class IamTagCallbackResourceImpl implements IamTagCallbackResource { +public class IamTagCallbackResourceImpl extends BaseIamCallbackService implements IamTagCallbackResource { private final TagService tagService; @Autowired - public IamTagCallbackResourceImpl(TagDAO tagDAO, TagService tagService) { + public IamTagCallbackResourceImpl(TagService tagService) { this.tagService = tagService; } + private Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); + + TagDTO tagQuery = new TagDTO(); + tagQuery.setAppId(searchCondition.getAppIdList().get(0)); + return Pair.of(tagQuery, baseSearchCondition); + } + + private InstanceInfoDTO convert(TagDTO tagDTO) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(tagDTO.getId())); + instanceInfo.setDisplayName(tagDTO.getName()); + return instanceInfo; + } + @Override - public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + + TagDTO tagQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + tagQuery.setName(callbackRequest.getFilter().getKeyword()); + PageData tagDTOPageData = tagService.listTags(tagQuery, baseSearchCondition); + + return IamRespUtil.getSearchInstanceRespFromPageData(tagDTOPageData, this::convert); + } + + @Override + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = getBasicQueryCondition(callbackRequest); + + TagDTO tagQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + PageData tagDTOPageData = tagService.listTags(tagQuery, baseSearchCondition); + + return IamRespUtil.getListInstanceRespFromPageData(tagDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp(CallbackRequestDTO callbackRequest) { IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - - int start = searchCondition.getStart().intValue(); - int length = searchCondition.getLength().intValue(); - - List tagDTOList = tagService.listTagsByAppId(searchCondition.getAppIdList().get(0)); - - List instanceInfoList = - tagDTOList.parallelStream().map(tagDTO -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(tagDTO.getId())); - instanceInfo.setDisplayName(tagDTO.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO baseDataResponse = new BaseDataResponseDTO<>(); - int size = instanceInfoList.size(); - List finalList = Collections.emptyList(); - if (size > 0) { - if (start < 0 || start >= size) { - start = 0; - } - if (length < 0) { - length = 0; - } - int end = start + length; - if (end > size) { - end = size; - } - finalList = instanceInfoList.subList(start, end); - } - baseDataResponse.setResult(finalList); - baseDataResponse.setCount((long) size); - instanceResponse.setData(baseDataResponse); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - Long tagId = Long.parseLong(instanceId); - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - TagDTO tagDTO = tagService.getTagInfoById(tagId); - if (tagDTO != null) { - instanceInfo.setDisplayName(tagDTO.getName()); - } else { - instanceInfo.setDisplayName("Unknown(may be deleted)"); - log.warn("Unexpected tagId:{} passed by iam", instanceId); - } - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + Long tagId = Long.parseLong(instanceId); + TagDTO tagDTO = tagService.getTagInfoById(tagId); + if (tagDTO == null) { + return getNotFoundRespById(instanceId); } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(tagDTO.getAppId().toString()); + PathInfoDTO tagNode = new PathInfoDTO(); + tagNode.setType(ResourceId.TAG); + tagNode.setId(tagDTO.getId().toString()); + rootNode.setChild(tagNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(tagDTO.getName()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } } - return response; + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskCallbackResourceImpl.java deleted file mode 100644 index b40c71210a..0000000000 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskCallbackResourceImpl.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.manage.api.iam.impl; - -import com.tencent.bk.job.common.iam.constant.ResourceId; -import com.tencent.bk.job.common.iam.controller.AbstractIamController; -import com.tencent.bk.job.common.model.BaseSearchCondition; -import com.tencent.bk.job.common.model.PageData; -import com.tencent.bk.job.manage.api.iam.IamTaskCallbackResource; -import com.tencent.bk.job.manage.model.dto.TaskPlanQueryDTO; -import com.tencent.bk.job.manage.model.dto.task.TaskPlanInfoDTO; -import com.tencent.bk.job.manage.model.dto.task.TaskTemplateInfoDTO; -import com.tencent.bk.job.manage.service.plan.TaskPlanService; -import com.tencent.bk.job.manage.service.template.TaskTemplateService; -import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; -import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; -import com.tencent.bk.sdk.iam.dto.callback.response.*; -import com.tencent.bk.sdk.iam.helper.AuthHelper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RestController; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @since 15/6/2020 15:41 - */ -@Slf4j -@RestController -public class IamTaskCallbackResourceImpl extends AbstractIamController implements IamTaskCallbackResource { - - private final TaskTemplateService templateService; - private final TaskPlanService planService; - - @Autowired - public IamTaskCallbackResourceImpl(TaskTemplateService templateService, TaskPlanService planService, - AuthHelper authHelper) { - super(authHelper); - this.templateService = templateService; - this.planService = planService; - } - - @Override - public CallbackBaseResponseDTO templateCallback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; - IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - TaskTemplateInfoDTO condition = new TaskTemplateInfoDTO(); - condition.setAppId(searchCondition.getAppIdList().get(0)); - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - PageData templateInfoPageData = - templateService.listPageTaskTemplatesBasicInfo(condition, baseSearchCondition, null); - - List instanceInfoList = - templateInfoPageData.getData().parallelStream().map(templateInfo -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(templateInfo.getId())); - instanceInfo.setDisplayName(templateInfo.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO listInstanceResponseData = new BaseDataResponseDTO<>(); - listInstanceResponseData.setResult(instanceInfoList); - listInstanceResponseData.setCount(templateInfoPageData.getTotal()); - instanceResponse.setData(listInstanceResponseData); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - long id = Long.parseLong(instanceId); - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - instanceInfo.setDisplayName(templateService.getTemplateName(id)); - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); - } - return response; - } - - @Override - public CallbackBaseResponseDTO planCallback(CallbackRequestDTO callbackRequest) { - log.debug("Receive iam callback|{}", callbackRequest); - CallbackBaseResponseDTO response; - IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); - switch (callbackRequest.getMethod()) { - case LIST_INSTANCE: - log.debug("List instance request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - TaskPlanQueryDTO condition = new TaskPlanQueryDTO(); - condition.setTemplateId(Long.valueOf(searchCondition.getAttribute().get(ResourceId.TEMPLATE).get(0))); - BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); - baseSearchCondition.setStart(searchCondition.getStart().intValue()); - baseSearchCondition.setLength(searchCondition.getLength().intValue()); - - PageData planInfoPageData = - planService.listPageTaskPlansBasicInfo(condition, baseSearchCondition, null); - - List instanceInfoList = planInfoPageData.getData().parallelStream().map(planInfo -> { - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(String.valueOf(planInfo.getId())); - instanceInfo.setDisplayName(planInfo.getName()); - return instanceInfo; - }).collect(Collectors.toList()); - ListInstanceResponseDTO instanceResponse = new ListInstanceResponseDTO(); - instanceResponse.setCode(0L); - BaseDataResponseDTO listInstanceResponseData = new BaseDataResponseDTO<>(); - listInstanceResponseData.setResult(instanceInfoList); - listInstanceResponseData.setCount(planInfoPageData.getTotal()); - instanceResponse.setData(listInstanceResponseData); - response = instanceResponse; - break; - case FETCH_INSTANCE_INFO: - log.debug("Fetch instance info request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - - List instanceAttributeInfoList = new ArrayList<>(); - for (String instanceId : searchCondition.getIdList()) { - try { - long id = Long.parseLong(instanceId); - InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); - instanceInfo.setId(instanceId); - instanceInfo.setDisplayName(planService.getPlanName(id)); - instanceAttributeInfoList.add(instanceInfo); - } catch (NumberFormatException e) { - log.error("Parse object id failed!|{}", instanceId, e); - } - } - - FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); - fetchInstanceInfoResponse.setCode(0L); - fetchInstanceInfoResponse.setData(instanceAttributeInfoList); - - response = fetchInstanceInfoResponse; - break; - case LIST_ATTRIBUTE: - log.debug("List attribute request!|{}|{}|{}", callbackRequest.getType(), callbackRequest.getFilter(), - callbackRequest.getPage()); - response = new ListAttributeResponseDTO(); - response.setCode(0L); - break; - case LIST_ATTRIBUTE_VALUE: - log.debug("List attribute value request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListAttributeValueResponseDTO(); - response.setCode(0L); - break; - case LIST_INSTANCE_BY_POLICY: - log.debug("List instance by policy request!|{}|{}|{}", callbackRequest.getType(), - callbackRequest.getFilter(), callbackRequest.getPage()); - response = new ListInstanceByPolicyResponseDTO(); - response.setCode(0L); - break; - default: - log.error("Unknown callback method!|{}|{}|{}|{}", callbackRequest.getMethod(), - callbackRequest.getType(), callbackRequest.getFilter(), callbackRequest.getPage()); - response = new CallbackBaseResponseDTO(); - } - return response; - } -} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskPlanCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskPlanCallbackResourceImpl.java new file mode 100644 index 0000000000..fc6e51bbe2 --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskPlanCallbackResourceImpl.java @@ -0,0 +1,158 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.api.iam.impl; + +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; +import com.tencent.bk.job.manage.api.iam.IamTaskPlanCallbackResource; +import com.tencent.bk.job.manage.model.dto.TaskPlanQueryDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskPlanInfoDTO; +import com.tencent.bk.job.manage.service.plan.TaskPlanService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestController +public class IamTaskPlanCallbackResourceImpl extends BaseIamCallbackService + implements IamTaskPlanCallbackResource { + + private final TaskPlanService planService; + + @Autowired + public IamTaskPlanCallbackResourceImpl(TaskPlanService planService) { + this.planService = planService; + } + + private InstanceInfoDTO convert(TaskPlanInfoDTO planInfoDTO) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(planInfoDTO.getId())); + instanceInfo.setDisplayName(planInfoDTO.getName()); + return instanceInfo; + } + + private Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); + + TaskPlanQueryDTO planQuery = new TaskPlanQueryDTO(); + planQuery.setTemplateId(Long.parseLong(callbackRequest.getFilter().getParent().getId())); + return Pair.of(planQuery, baseSearchCondition); + } + + @Override + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = + getBasicQueryCondition(callbackRequest); + + TaskPlanQueryDTO planQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + PageData planDTOPageData = planService.listPageTaskPlansBasicInfo(planQuery, + baseSearchCondition, null); + + return IamRespUtil.getListInstanceRespFromPageData(planDTOPageData, this::convert); + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = + getBasicQueryCondition(callbackRequest); + + TaskPlanQueryDTO planQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + planQuery.setName(callbackRequest.getFilter().getKeyword()); + PageData planDTOPageData = planService.listPageTaskPlansBasicInfo(planQuery, + baseSearchCondition, null); + + return IamRespUtil.getSearchInstanceRespFromPageData(planDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + long id = Long.parseLong(instanceId); + TaskPlanInfoDTO planInfoDTO = planService.getTaskPlanById(id); + if (planInfoDTO == null) { + return getNotFoundRespById(instanceId); + } + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(planInfoDTO.getAppId().toString()); + PathInfoDTO templateNode = new PathInfoDTO(); + templateNode.setType(ResourceId.TEMPLATE); + templateNode.setId(planInfoDTO.getTemplateId().toString()); + rootNode.setChild(templateNode); + PathInfoDTO planNode = new PathInfoDTO(); + planNode.setType(ResourceId.PLAN); + planNode.setId(planInfoDTO.getId().toString()); + templateNode.setChild(planNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(planInfoDTO.getName()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } + } + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); + } +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskTemplateCallbackResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskTemplateCallbackResourceImpl.java new file mode 100644 index 0000000000..f3c3750ea0 --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/IamTaskTemplateCallbackResourceImpl.java @@ -0,0 +1,156 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.api.iam.impl; + +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; +import com.tencent.bk.job.manage.api.iam.IamTaskTemplateCallbackResource; +import com.tencent.bk.job.manage.model.dto.task.TaskTemplateInfoDTO; +import com.tencent.bk.job.manage.service.template.TaskTemplateService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestController +public class IamTaskTemplateCallbackResourceImpl extends BaseIamCallbackService + implements IamTaskTemplateCallbackResource { + + private final TaskTemplateService templateService; + + @Autowired + public IamTaskTemplateCallbackResourceImpl(TaskTemplateService templateService) { + this.templateService = templateService; + } + + private InstanceInfoDTO convert(TaskTemplateInfoDTO templateInfo) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(templateInfo.getId())); + instanceInfo.setDisplayName(templateInfo.getName()); + return instanceInfo; + } + + private Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + BaseSearchCondition baseSearchCondition = new BaseSearchCondition(); + baseSearchCondition.setStart(searchCondition.getStart().intValue()); + baseSearchCondition.setLength(searchCondition.getLength().intValue()); + + TaskTemplateInfoDTO templateQuery = new TaskTemplateInfoDTO(); + templateQuery.setAppId(searchCondition.getAppIdList().get(0)); + return Pair.of(templateQuery, baseSearchCondition); + } + + @Override + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = + getBasicQueryCondition(callbackRequest); + + TaskTemplateInfoDTO templateQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + PageData templateDTOPageData = templateService.listPageTaskTemplatesBasicInfo( + templateQuery, + baseSearchCondition, + null + ); + + return IamRespUtil.getListInstanceRespFromPageData(templateDTOPageData, this::convert); + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = + getBasicQueryCondition(callbackRequest); + + TaskTemplateInfoDTO templateQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + templateQuery.setName(callbackRequest.getFilter().getKeyword()); + PageData templateDTOPageData = templateService.listPageTaskTemplatesBasicInfo(templateQuery, + baseSearchCondition, null); + + return IamRespUtil.getSearchInstanceRespFromPageData(templateDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + long id = Long.parseLong(instanceId); + TaskTemplateInfoDTO templateInfoDTO = templateService.getTaskTemplateBasicInfoById(id); + if (templateInfoDTO == null) { + return getNotFoundRespById(instanceId); + } + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + rootNode.setType(ResourceId.APP); + rootNode.setId(templateInfoDTO.getAppId().toString()); + PathInfoDTO templateNode = new PathInfoDTO(); + templateNode.setType(ResourceId.TEMPLATE); + templateNode.setId(templateInfoDTO.getId().toString()); + rootNode.setChild(templateNode); + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(templateInfoDTO.getName()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } + } + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + @Override + public CallbackBaseResponseDTO callback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); + } +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/ScriptCallbackHelper.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/ScriptCallbackHelper.java new file mode 100644 index 0000000000..0244f2a669 --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/iam/impl/ScriptCallbackHelper.java @@ -0,0 +1,129 @@ +package com.tencent.bk.job.manage.api.iam.impl; + +import com.tencent.bk.job.common.iam.constant.ResourceId; +import com.tencent.bk.job.common.iam.service.BaseIamCallbackService; +import com.tencent.bk.job.common.iam.util.IamRespUtil; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; +import com.tencent.bk.job.manage.model.dto.ScriptDTO; +import com.tencent.bk.job.manage.model.dto.ScriptQueryDTO; +import com.tencent.bk.job.manage.service.ScriptService; +import com.tencent.bk.sdk.iam.dto.PathInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO; +import com.tencent.bk.sdk.iam.dto.callback.request.IamSearchCondition; +import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.FetchInstanceInfoResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.InstanceInfoDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.ListInstanceResponseDTO; +import com.tencent.bk.sdk.iam.dto.callback.response.SearchInstanceResponseDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ScriptCallbackHelper extends BaseIamCallbackService { + private ScriptService scriptService; + private IGetBasicInfo basicInfoInterface; + + public ScriptCallbackHelper( + ScriptService scriptService, + IGetBasicInfo basicInfoInterface + ) { + this.scriptService = scriptService; + this.basicInfoInterface = basicInfoInterface; + } + + public interface IGetBasicInfo { + Pair getBasicQueryCondition(CallbackRequestDTO callbackRequest); + + boolean isPublicScript(); + } + + + private InstanceInfoDTO convert(ScriptDTO script) { + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(String.valueOf(script.getId())); + instanceInfo.setDisplayName(script.getName()); + return instanceInfo; + } + + @Override + protected ListInstanceResponseDTO listInstanceResp(CallbackRequestDTO callbackRequest) { + Pair basicQueryCond = + basicInfoInterface.getBasicQueryCondition(callbackRequest); + + ScriptQueryDTO scriptQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + PageData accountDTOPageData = scriptService.listPageScript(scriptQuery, + baseSearchCondition); + + return IamRespUtil.getListInstanceRespFromPageData(accountDTOPageData, this::convert); + } + + @Override + protected SearchInstanceResponseDTO searchInstanceResp(CallbackRequestDTO callbackRequest) { + + Pair basicQueryCond = + basicInfoInterface.getBasicQueryCondition(callbackRequest); + ScriptQueryDTO scriptQuery = basicQueryCond.getLeft(); + BaseSearchCondition baseSearchCondition = basicQueryCond.getRight(); + + scriptQuery.setName(callbackRequest.getFilter().getKeyword()); + PageData accountDTOPageData = scriptService.listPageScript(scriptQuery, + baseSearchCondition); + + return IamRespUtil.getSearchInstanceRespFromPageData(accountDTOPageData, this::convert); + } + + @Override + protected CallbackBaseResponseDTO fetchInstanceResp( + CallbackRequestDTO callbackRequest + ) { + IamSearchCondition searchCondition = IamSearchCondition.fromReq(callbackRequest); + List instanceAttributeInfoList = new ArrayList<>(); + for (String instanceId : searchCondition.getIdList()) { + try { + ScriptDTO scriptDTO = scriptService.getScriptByScriptId(instanceId); + if (scriptDTO == null || scriptDTO.isPublicScript() != basicInfoInterface.isPublicScript()) { + return getNotFoundRespById(instanceId); + } + // 拓扑路径构建 + List path = new ArrayList<>(); + PathInfoDTO rootNode = new PathInfoDTO(); + if (basicInfoInterface.isPublicScript()) { + // 公共脚本 + rootNode.setType(ResourceId.PUBLIC_SCRIPT); + rootNode.setId(scriptDTO.getId()); + } else { + // 业务脚本 + rootNode.setType(ResourceId.APP); + rootNode.setId(scriptDTO.getAppId().toString()); + PathInfoDTO scriptNode = new PathInfoDTO(); + scriptNode.setType(ResourceId.SCRIPT); + scriptNode.setId(scriptDTO.getId()); + rootNode.setChild(scriptNode); + } + path.add(rootNode); + // 实例组装 + InstanceInfoDTO instanceInfo = new InstanceInfoDTO(); + instanceInfo.setId(instanceId); + instanceInfo.setDisplayName(scriptDTO.getName()); + instanceInfo.setPath(path); + instanceAttributeInfoList.add(instanceInfo); + } catch (NumberFormatException e) { + log.error("Parse object id failed!|{}", instanceId, e); + } + } + + FetchInstanceInfoResponseDTO fetchInstanceInfoResponse = new FetchInstanceInfoResponseDTO(); + fetchInstanceInfoResponse.setCode(0L); + fetchInstanceInfoResponse.setData(instanceAttributeInfoList); + return fetchInstanceInfoResponse; + } + + public CallbackBaseResponseDTO doCallback(CallbackRequestDTO callbackRequest) { + return baseCallback(callbackRequest); + } +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAccountResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAccountResourceImpl.java index aa952c7b29..265f739e72 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAccountResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAccountResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.manage.api.inner.ServiceAccountResource; @@ -47,7 +47,8 @@ public class ServiceAccountResourceImpl implements ServiceAccountResource { private final MessageI18nService i18nService; @Autowired - public ServiceAccountResourceImpl(AccountService accountService, MessageI18nService i18nService) { + public ServiceAccountResourceImpl(AccountService accountService, + MessageI18nService i18nService) { this.accountService = accountService; this.i18nService = i18nService; } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAppSetResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAppSetResourceImpl.java index 51bb755df5..eab1ab7898 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAppSetResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceAppSetResourceImpl.java @@ -37,11 +37,14 @@ import com.tencent.bk.job.manage.service.ApplicationService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import java.util.StringJoiner; import java.util.stream.Collectors; @@ -53,13 +56,17 @@ public class ServiceAppSetResourceImpl implements ServiceAppSetResource { private final ApplicationInfoDAO applicationDAO; private final ApplicationService applicationService; private final EsbUserInfoDAO userDAO; + private final DSLContext dslContext; @Autowired - public ServiceAppSetResourceImpl(ApplicationInfoDAO applicationDAO, ApplicationService applicationService, - EsbUserInfoDAO userDAO) { + public ServiceAppSetResourceImpl(ApplicationInfoDAO applicationDAO, + ApplicationService applicationService, + EsbUserInfoDAO userDAO, + @Qualifier("job-manage-dsl-context") DSLContext dslContext) { this.applicationDAO = applicationDAO; this.applicationService = applicationService; this.userDAO = userDAO; + this.dslContext = dslContext; } @@ -75,13 +82,42 @@ public ServiceResponse queryAppSetById(Long appId) { @Override public ServiceResponse> listAppSet() { List appSetList = applicationDAO.listAppInfoByType(AppTypeEnum.APP_SET); - if (appSetList == null || appSetList.isEmpty()) { - return ServiceResponse.buildSuccessResp(null); + List allAppSetList = applicationDAO.listAppInfoByType(AppTypeEnum.ALL_APP); + + List results = new ArrayList<>(); + if (appSetList != null && !appSetList.isEmpty()) { + results.addAll(appSetList); + } + if (allAppSetList != null && !allAppSetList.isEmpty()) { + results.addAll(allAppSetList); + } + if (!results.isEmpty()) { + results = results.stream().sorted((Comparator.comparing(ApplicationInfoDTO::getId))) + .collect(Collectors.toList()); } - return ServiceResponse.buildSuccessResp(appSetList.stream().map(this::convertToServiceApp) + return ServiceResponse.buildSuccessResp(results.stream().map(this::convertToServiceApp) .collect(Collectors.toList())); } + @Override + public ServiceResponse deleteAppSet(Long appId) { + checkAppSetId(appId); + ApplicationInfoDTO app = applicationDAO.getAppInfoById(appId); + if (app == null) { + log.warn("App-set is not exist!"); + return ServiceResponse.buildCommonFailResp("App-Set is not exist"); + } + applicationDAO.deleteAppInfoById(dslContext, appId); + return ServiceResponse.buildSuccessResp(null); + } + + private void checkAppSetId(Long appId) { + // appSet id should between 8000000 and 9999999 + if (appId == null || appId < 8000000 || appId > 9999999) { + throw new ServiceException("Invalid appId"); + } + } + private ServiceApplicationDTO getAppSet(Long appId) { ApplicationInfoDTO appInfo = applicationDAO.getAppInfoById(appId); if (appInfo == null) { @@ -120,7 +156,6 @@ public ServiceResponse addAppSet(ServiceAddAppSetRequest appInfo.setBkSupplierAccount("tencent"); appInfo.setAppType(AppTypeEnum.APP_SET); appInfo.setMaintainers(request.getMaintainers()); - appInfo.setOperateDeptId(request.getDeptId()); if (request.isDynamicAppSet()) { appInfo.setOperateDeptId(request.getDeptId()); } else { diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java index 6546df7dca..5d28d69f36 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceApplicationResourceImpl.java @@ -31,6 +31,7 @@ import com.tencent.bk.job.common.model.vo.HostInfoVO; import com.tencent.bk.job.manage.api.inner.ServiceApplicationResource; import com.tencent.bk.job.manage.dao.ApplicationInfoDAO; +import com.tencent.bk.job.manage.model.inner.ServiceAppBaseInfoDTO; import com.tencent.bk.job.manage.model.inner.ServiceApplicationDTO; import com.tencent.bk.job.manage.model.inner.ServiceHostStatusDTO; import com.tencent.bk.job.manage.model.inner.request.ServiceGetHostStatusByDynamicGroupReq; @@ -60,6 +61,14 @@ public ServiceApplicationResourceImpl(ApplicationService applicationService, this.applicationInfoDAO = applicationInfoDAO; } + @Override + public ServiceResponse> listNormalApps() { + List applicationInfoDTOList = applicationInfoDAO.listAppInfoByType(AppTypeEnum.NORMAL); + List resultList = + applicationInfoDTOList.parallelStream().map(this::convertToServiceAppBaseInfo).collect(Collectors.toList()); + return ServiceResponse.buildSuccessResp(resultList); + } + @Override public ServiceApplicationDTO queryAppById(Long appId) { ApplicationInfoDTO appInfo = applicationService.getAppInfoById(appId); @@ -83,6 +92,12 @@ private ServiceApplicationDTO convertToServiceApp(ApplicationInfoDTO appInfo) { return app; } + private ServiceAppBaseInfoDTO convertToServiceAppBaseInfo(ApplicationInfoDTO appInfo) { + ServiceAppBaseInfoDTO appBaseInfoDTO = new ServiceAppBaseInfoDTO(); + appBaseInfoDTO.setId(appInfo.getId()); + appBaseInfoDTO.setName(appInfo.getName()); + return appBaseInfoDTO; + } @Override public ServiceResponse checkAppPermission(Long appId, String username) { @@ -164,7 +179,7 @@ public ServiceResponse> getHostStatusByDynamicGroup( public ServiceResponse> getHostStatusByIp(Long appId, String username, ServiceGetHostStatusByIpReq req) { List ipList = req.getIpList(); - List hostInfoVOList = applicationService.getHostsByIp(username, appId, ipList); + List hostInfoVOList = applicationService.getHostsByIp(username, appId, null, ipList); List hostStatusDTOList = new ArrayList<>(); hostInfoVOList.forEach(hostInfoVO -> { ServiceHostStatusDTO serviceHostStatusDTO = new ServiceHostStatusDTO(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceScriptResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceScriptResourceImpl.java index 1bb14ce781..60b4c2c7ed 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceScriptResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceScriptResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.api.common.ScriptDTOBuilder; import com.tencent.bk.job.manage.api.inner.ServiceScriptResource; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTagResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTagResourceImpl.java index 35067d907e..6e1b7bca45 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTagResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTagResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.api.inner.ServiceTagResource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.model.dto.TagDTO; import com.tencent.bk.job.manage.model.inner.ServiceTagDTO; import com.tencent.bk.job.manage.service.TagService; @@ -62,7 +62,7 @@ public ServiceResponse> listTags(Long appId) { @Override public ServiceResponse> listPublicTags() { - List tags = tagService.listTags(JobManageConstants.PUBLIC_APP_ID, null); + List tags = tagService.listTags(JobConstants.PUBLIC_APP_ID, null); return ServiceResponse.buildSuccessResp(tags.parallelStream().map(this::convert).collect(Collectors.toList())); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTaskPlanResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTaskPlanResourceImpl.java index d0e5a15a14..6970290b5b 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTaskPlanResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/impl/ServiceTaskPlanResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.constant.TaskVariableTypeEnum; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.json.JsonUtils; @@ -38,8 +38,24 @@ import com.tencent.bk.job.manage.model.dto.ScriptDTO; import com.tencent.bk.job.manage.model.dto.converter.TaskStepConverter; import com.tencent.bk.job.manage.model.dto.converter.TaskVariableConverter; -import com.tencent.bk.job.manage.model.dto.task.*; -import com.tencent.bk.job.manage.model.inner.*; +import com.tencent.bk.job.manage.model.dto.task.TaskApprovalStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskFileInfoDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskFileStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskPlanInfoDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskScriptStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskTargetDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskVariableDTO; +import com.tencent.bk.job.manage.model.inner.ServiceAccountDTO; +import com.tencent.bk.job.manage.model.inner.ServiceIdNameCheckDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskApprovalStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskApprovalUserDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskFileInfoDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskFileStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskPlanDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskScriptStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskStepDTO; +import com.tencent.bk.job.manage.model.inner.ServiceTaskVariableDTO; import com.tencent.bk.job.manage.model.web.vo.task.TaskPlanVO; import com.tencent.bk.job.manage.service.AbstractTaskVariableService; import com.tencent.bk.job.manage.service.AccountService; @@ -52,7 +68,11 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Slf4j @@ -222,7 +242,7 @@ public ServiceResponse> getPlanVariable(String user @Override public ServiceResponse> listPlans(String username, Long appId, Long templateId) { - List taskPlanInfoDTOList = taskPlanService.listPageTaskPlansBasicInfo(appId, templateId); + List taskPlanInfoDTOList = taskPlanService.listTaskPlansBasicInfo(appId, templateId); List resultList = taskPlanInfoDTOList.parallelStream().map(it -> { ServiceTaskPlanDTO serviceTaskPlanDTO = new ServiceTaskPlanDTO(); serviceTaskPlanDTO.setId(it.getId()); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/impl/MigrationResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/impl/MigrationResourceImpl.java index 146ec624f8..95fd16d21a 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/impl/MigrationResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/migration/impl/MigrationResourceImpl.java @@ -26,36 +26,26 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.api.migration.MigrationResource; -import com.tencent.bk.job.manage.model.migration.EncryptDbAccountPasswordReq; -import com.tencent.bk.job.manage.service.MigrationService; +import com.tencent.bk.job.manage.migration.EncryptDbAccountPasswordMigrationTask; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @Slf4j @RestController public class MigrationResourceImpl implements MigrationResource { - private final MigrationService migrationService; + private final EncryptDbAccountPasswordMigrationTask encryptDbAccountPasswordMigrationTask; @Autowired - public MigrationResourceImpl(MigrationService migrationService) { - this.migrationService = migrationService; + public MigrationResourceImpl( + EncryptDbAccountPasswordMigrationTask encryptDbAccountPasswordMigrationTask) { + this.encryptDbAccountPasswordMigrationTask = encryptDbAccountPasswordMigrationTask; } @Override - public ServiceResponse encryptDbAccountPassword(EncryptDbAccountPasswordReq req) { - log.info("Encrypt db password start ..."); - if (StringUtils.isBlank(req.getKey())) { - log.error("Encrypt key is blank"); - return ServiceResponse.buildCommonFailResp("Encrypt key is blank"); - } - boolean success = migrationService.encryptDbAccountPassword(req.getKey()); - if (success) { - log.info("Encrypt db password successfully"); - return ServiceResponse.buildSuccessResp(null); - } else { - return ServiceResponse.buildCommonFailResp("Encrypt db account password failed"); - } + public ServiceResponse> encryptDbAccountPassword() { + return encryptDbAccountPasswordMigrationTask.encryptDbAccountPassword(); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/impl/TmpAppAccountResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/impl/TmpAppAccountResourceImpl.java index 8f89f47aeb..3aea3adfe5 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/impl/TmpAppAccountResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/tmp/impl/TmpAppAccountResourceImpl.java @@ -26,11 +26,10 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.Utils; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.tmp.TmpAppAccountResource; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; import com.tencent.bk.job.manage.common.consts.account.AccountTypeEnum; @@ -45,7 +44,7 @@ @Slf4j @RestController -public class TmpAppAccountResourceImpl extends AbstractJobController implements TmpAppAccountResource { +public class TmpAppAccountResourceImpl implements TmpAppAccountResource { private AccountService accountService; private MessageI18nService i18nService; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppAccountResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppAccountResourceImpl.java index 69af4cc725..9d09b724a7 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppAccountResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppAccountResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.constant.FeatureToggleModeEnum; import com.tencent.bk.job.common.exception.InvalidParamException; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; @@ -41,7 +41,6 @@ import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.Utils; import com.tencent.bk.job.common.util.date.DateUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.web.WebAppAccountResource; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; import com.tencent.bk.job.manage.common.consts.account.AccountTypeEnum; @@ -58,7 +57,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -66,7 +69,7 @@ */ @Slf4j @RestController -public class WebAppAccountResourceImpl extends AbstractJobController implements WebAppAccountResource { +public class WebAppAccountResourceImpl implements WebAppAccountResource { private AccountService accountService; private MessageI18nService i18nService; private WebAuthService authService; @@ -75,11 +78,11 @@ public class WebAppAccountResourceImpl extends AbstractJobController implements @Autowired public WebAppAccountResourceImpl(AccountService accountService, MessageI18nService i18nService, - WebAuthService authService, ApplicationService applicationService, + WebAuthService webAuthService, ApplicationService applicationService, JobManageConfig jobManageConfig) { this.accountService = accountService; this.i18nService = i18nService; - this.authService = authService; + this.authService = webAuthService; this.applicationService = applicationService; this.jobManageConfig = jobManageConfig; } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppResourceImpl.java index 3533230b69..4df2043450 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebAppResourceImpl.java @@ -39,15 +39,19 @@ import com.tencent.bk.job.common.util.CompareUtil; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.PageUtil; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.web.WebAppResource; import com.tencent.bk.job.manage.common.TopologyHelper; import com.tencent.bk.job.manage.model.dto.ApplicationFavorDTO; import com.tencent.bk.job.manage.model.web.request.AgentStatisticsReq; import com.tencent.bk.job.manage.model.web.request.FavorAppReq; +import com.tencent.bk.job.manage.model.web.request.IpCheckReq; import com.tencent.bk.job.manage.model.web.request.ipchooser.AppTopologyTreeNode; import com.tencent.bk.job.manage.model.web.request.ipchooser.ListHostByBizTopologyNodesReq; -import com.tencent.bk.job.manage.model.web.vo.*; +import com.tencent.bk.job.manage.model.web.vo.AppVO; +import com.tencent.bk.job.manage.model.web.vo.CcTopologyNodeVO; +import com.tencent.bk.job.manage.model.web.vo.DynamicGroupInfoVO; +import com.tencent.bk.job.manage.model.web.vo.NodeInfoVO; +import com.tencent.bk.job.manage.model.web.vo.PageDataWithAvailableIdList; import com.tencent.bk.job.manage.model.web.vo.index.AgentStatistics; import com.tencent.bk.job.manage.service.ApplicationService; import com.tencent.bk.job.manage.service.impl.ApplicationFavorService; @@ -63,7 +67,7 @@ @RestController @Slf4j -public class WebAppResourceImpl extends AbstractJobController implements WebAppResource { +public class WebAppResourceImpl implements WebAppResource { private final ApplicationService applicationService; private final ApplicationFavorService applicationFavorService; @@ -272,12 +276,12 @@ public ServiceResponse> getNodeDetail(String username, JobContextUtil.setAppId(appId); List treeNodeList = applicationService.getAppTopologyTreeNodeDetail(username, appId, targetNodeVOList.stream().map(it -> new AppTopologyTreeNode( - it.getType(), - "", - it.getId(), - "", - null - )).collect(Collectors.toList())); + it.getType(), + "", + it.getId(), + "", + null + )).collect(Collectors.toList())); return ServiceResponse.buildSuccessResp(treeNodeList); } @@ -286,11 +290,11 @@ public ServiceResponse>> queryNodePaths(String usern List targetNodeVOList) { List> pathList = applicationService.queryNodePaths(username, appId, targetNodeVOList.stream().map(it -> { - InstanceTopologyDTO instanceTopologyDTO = new InstanceTopologyDTO(); - instanceTopologyDTO.setObjectId(it.getType()); - instanceTopologyDTO.setInstanceId(it.getId()); - return instanceTopologyDTO; - }).collect(Collectors.toList())); + InstanceTopologyDTO instanceTopologyDTO = new InstanceTopologyDTO(); + instanceTopologyDTO.setObjectId(it.getType()); + instanceTopologyDTO.setInstanceId(it.getId()); + return instanceTopologyDTO; + }).collect(Collectors.toList())); List> resultList = new ArrayList<>(); for (List instanceTopologyDTOS : pathList) { if (instanceTopologyDTOS == null) { @@ -315,12 +319,12 @@ public ServiceResponse> listHostByNode(String username, Long ap JobContextUtil.setAppId(appId); List moduleHostInfoList = applicationService.getHostsByNode(username, appId, targetNodeVOList.stream().map(it -> new AppTopologyTreeNode( - it.getType(), - "", - it.getId(), - "", - null - )).collect(Collectors.toList())); + it.getType(), + "", + it.getId(), + "", + null + )).collect(Collectors.toList())); return ServiceResponse.buildSuccessResp(moduleHostInfoList); } @@ -364,8 +368,13 @@ public ServiceResponse> listAppDynamicGroupWithoutHosts } @Override - public ServiceResponse> listHostByIp(String username, Long appId, List checkIpList) { - return ServiceResponse.buildSuccessResp(applicationService.getHostsByIp(username, appId, checkIpList)); + public ServiceResponse> listHostByIp(String username, Long appId, IpCheckReq req) { + return ServiceResponse.buildSuccessResp(applicationService.getHostsByIp( + username, + appId, + req.getActionScope(), + req.getIpList()) + ); } @Override diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebCustomSettingsResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebCustomSettingsResourceImpl.java index 4dd8bdf310..09ff9cad07 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebCustomSettingsResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebCustomSettingsResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.manage.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.common.util.Base64Util; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebDangerousRuleResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebDangerousRuleResourceImpl.java index ab248fc3f7..a020db531d 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebDangerousRuleResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebDangerousRuleResourceImpl.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.manage.api.web.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.ValidateResult; import com.tencent.bk.job.manage.api.web.WebDangerousRuleResource; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebGlobalSettingsQueryResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebGlobalSettingsQueryResourceImpl.java index 4b14b84a90..8503e3e69d 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebGlobalSettingsQueryResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebGlobalSettingsQueryResourceImpl.java @@ -96,10 +96,14 @@ public ServiceResponse getAccountNameRules(String @Override public ServiceResponse isAdmin(String username) { AtomicBoolean flag = new AtomicBoolean(false); - CountDownLatch latch = new CountDownLatch(7); + CountDownLatch latch = new CountDownLatch(9); executor.submit(() -> { try { - AuthResult createWhiteListAuthResultVO = authService.auth(false, username, ActionId.CREATE_WHITELIST); + AuthResult createWhiteListAuthResultVO = authService.auth( + false, + username, + ActionId.CREATE_WHITELIST + ); flag.set(flag.get() || createWhiteListAuthResultVO.isPass()); } catch (Throwable t) { log.error("Fail to auth {} to {}", ActionId.CREATE_WHITELIST, username, t); @@ -109,7 +113,11 @@ public ServiceResponse isAdmin(String username) { }); executor.submit(() -> { try { - AuthResult manageWhiteListAuthResultVO = authService.auth(false, username, ActionId.MANAGE_WHITELIST); + AuthResult manageWhiteListAuthResultVO = authService.auth( + false, + username, + ActionId.MANAGE_WHITELIST + ); flag.set(flag.get() || manageWhiteListAuthResultVO.isPass()); } catch (Throwable t) { log.error("Fail to auth {} to {}", ActionId.MANAGE_WHITELIST, username, t); @@ -119,8 +127,11 @@ public ServiceResponse isAdmin(String username) { }); executor.submit(() -> { try { - AuthResult createPublicScriptAuthResultVO = authService.auth(false, username, - ActionId.CREATE_PUBLIC_SCRIPT); + AuthResult createPublicScriptAuthResultVO = authService.auth( + false, + username, + ActionId.CREATE_PUBLIC_SCRIPT + ); flag.set(flag.get() || createPublicScriptAuthResultVO.isPass()); } catch (Throwable t) { log.error("Fail to auth {} to {}", ActionId.CREATE_PUBLIC_SCRIPT, username, t); @@ -130,8 +141,11 @@ public ServiceResponse isAdmin(String username) { }); executor.submit(() -> { try { - AuthResult managePublicScriptAuthResultVO = authService.auth(false, username, - ActionId.MANAGE_PUBLIC_SCRIPT_INSTANCE); + AuthResult managePublicScriptAuthResultVO = authService.auth( + false, + username, + ActionId.MANAGE_PUBLIC_SCRIPT_INSTANCE + ); flag.set(flag.get() || managePublicScriptAuthResultVO.isPass()); } catch (Throwable t) { log.error("Fail to auth {} to {}", ActionId.MANAGE_PUBLIC_SCRIPT_INSTANCE, username, t); @@ -165,7 +179,11 @@ public ServiceResponse isAdmin(String username) { }); executor.submit(() -> { try { - AuthResult serviceInfoAuthResultVO = authService.auth(false, username, ActionId.SERVICE_STATE_ACCESS); + AuthResult serviceInfoAuthResultVO = authService.auth( + false, + username, + ActionId.SERVICE_STATE_ACCESS + ); flag.set(flag.get() || serviceInfoAuthResultVO.isPass()); } catch (Throwable t) { log.error("Fail to auth {} to {}", ActionId.SERVICE_STATE_ACCESS, username, t); @@ -173,6 +191,34 @@ public ServiceResponse isAdmin(String username) { latch.countDown(); } }); + executor.submit(() -> { + try { + AuthResult highRiskRuleAuthResultVO = authService.auth( + false, + username, + ActionId.HIGH_RISK_DETECT_RULE + ); + flag.set(flag.get() || highRiskRuleAuthResultVO.isPass()); + } catch (Throwable t) { + log.error("Fail to auth {} to {}", ActionId.SERVICE_STATE_ACCESS, username, t); + } finally { + latch.countDown(); + } + }); + executor.submit(() -> { + try { + AuthResult highRiskRecordAuthResultVO = authService.auth( + false, + username, + ActionId.HIGH_RISK_DETECT_RECORD + ); + flag.set(flag.get() || highRiskRecordAuthResultVO.isPass()); + } catch (Throwable t) { + log.error("Fail to auth {} to {}", ActionId.SERVICE_STATE_ACCESS, username, t); + } finally { + latch.countDown(); + } + }); try { latch.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebIndexResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebIndexResourceImpl.java index 389a085b94..9ba7467d9f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebIndexResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebIndexResourceImpl.java @@ -27,7 +27,6 @@ import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.vo.HostInfoVO; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.web.WebIndexResource; import com.tencent.bk.job.manage.model.web.vo.index.AgentStatistics; import com.tencent.bk.job.manage.model.web.vo.index.GreetingVO; @@ -43,7 +42,7 @@ @RestController @Slf4j -public class WebIndexResourceImpl extends AbstractJobController implements WebIndexResource { +public class WebIndexResourceImpl implements WebIndexResource { private final IndexService indexService; private final TaskTemplateAuthService taskTemplateAuthService; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebNotifyResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebNotifyResourceImpl.java index 1c14abc30c..89288eca55 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebNotifyResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebNotifyResourceImpl.java @@ -56,10 +56,10 @@ public class WebNotifyResourceImpl implements WebNotifyResource { @Autowired public WebNotifyResourceImpl(NotifyService notifyService, LocalPermissionService localPermissionService, - WebAuthService authService) { + WebAuthService webAuthService) { this.notifyService = notifyService; this.localPermissionService = localPermissionService; - this.authService = authService; + this.authService = webAuthService; } @Override diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java index fc05be4d69..a2232dcf8a 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.manage.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.model.PermissionActionResource; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicScriptResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicScriptResourceImpl.java index 4056fd2ef3..d82c5a66c3 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicScriptResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicScriptResourceImpl.java @@ -28,7 +28,7 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.api.web.WebPublicScriptResource; import com.tencent.bk.job.manage.api.web.WebScriptResource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq; import com.tencent.bk.job.manage.model.web.request.ScriptInfoUpdateReq; import com.tencent.bk.job.manage.model.web.request.ScriptSyncReq; @@ -48,7 +48,7 @@ @RestController @Slf4j public class WebPublicScriptResourceImpl implements WebPublicScriptResource { - private static final Long PUBLIC_APP_ID = JobManageConstants.PUBLIC_APP_ID; + private static final Long PUBLIC_APP_ID = JobConstants.PUBLIC_APP_ID; /** * 脚本处理的通用服务,与普通脚本不同的是,公共脚本的业务ID=0 * 鉴权在通用脚本逻辑中处理 diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicTagResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicTagResourceImpl.java index 2af6f47dbe..6f5bdc0822 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicTagResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPublicTagResourceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.manage.api.web.WebPublicTagResource; import com.tencent.bk.job.manage.api.web.WebTagResource; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.manage.model.web.vo.TagVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +40,7 @@ @Slf4j public class WebPublicTagResourceImpl implements WebPublicTagResource { - private static final Long PUBLIC_APP_ID = JobManageConstants.PUBLIC_APP_ID; + private static final Long PUBLIC_APP_ID = JobConstants.PUBLIC_APP_ID; private final WebTagResource tagResourceProxy; @Autowired diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebScriptResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebScriptResourceImpl.java index 86b3f15b76..374e5bc65c 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebScriptResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebScriptResourceImpl.java @@ -26,7 +26,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; @@ -37,16 +37,26 @@ import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.Base64Util; import com.tencent.bk.job.common.util.JobContextUtil; -import com.tencent.bk.job.common.util.check.*; +import com.tencent.bk.job.common.util.check.IlegalCharChecker; +import com.tencent.bk.job.common.util.check.MaxLengthChecker; +import com.tencent.bk.job.common.util.check.NotEmptyChecker; +import com.tencent.bk.job.common.util.check.StringCheckHelper; +import com.tencent.bk.job.common.util.check.TrimChecker; +import com.tencent.bk.job.common.util.check.WhiteCharChecker; import com.tencent.bk.job.common.util.check.exception.StringCheckException; import com.tencent.bk.job.common.util.file.CharsetDetectHelper; import com.tencent.bk.job.common.util.file.EncodingUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.common.ScriptDTOBuilder; import com.tencent.bk.job.manage.api.web.WebScriptResource; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; -import com.tencent.bk.job.manage.model.dto.*; +import com.tencent.bk.job.manage.model.dto.ScriptCheckResultItemDTO; +import com.tencent.bk.job.manage.model.dto.ScriptDTO; +import com.tencent.bk.job.manage.model.dto.ScriptQueryDTO; +import com.tencent.bk.job.manage.model.dto.ScriptSyncTemplateStepDTO; +import com.tencent.bk.job.manage.model.dto.SyncScriptResultDTO; +import com.tencent.bk.job.manage.model.dto.TagDTO; +import com.tencent.bk.job.manage.model.dto.TemplateStepIDDTO; import com.tencent.bk.job.manage.model.dto.converter.ScriptConverter; import com.tencent.bk.job.manage.model.dto.converter.ScriptRelatedTemplateStepConverter; import com.tencent.bk.job.manage.model.dto.script.ScriptCitedTaskPlanDTO; @@ -55,7 +65,12 @@ import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq; import com.tencent.bk.job.manage.model.web.request.ScriptInfoUpdateReq; import com.tencent.bk.job.manage.model.web.request.ScriptSyncReq; -import com.tencent.bk.job.manage.model.web.vo.*; +import com.tencent.bk.job.manage.model.web.vo.BasicScriptVO; +import com.tencent.bk.job.manage.model.web.vo.ScriptCheckResultItemVO; +import com.tencent.bk.job.manage.model.web.vo.ScriptCitedTaskPlanVO; +import com.tencent.bk.job.manage.model.web.vo.ScriptCitedTemplateVO; +import com.tencent.bk.job.manage.model.web.vo.ScriptVO; +import com.tencent.bk.job.manage.model.web.vo.TagVO; import com.tencent.bk.job.manage.model.web.vo.script.ScriptCiteCountVO; import com.tencent.bk.job.manage.model.web.vo.script.ScriptCiteInfoVO; import com.tencent.bk.job.manage.model.web.vo.script.ScriptRelatedTemplateStepVO; @@ -80,11 +95,11 @@ import java.util.Map; import java.util.stream.Collectors; -import static com.tencent.bk.job.manage.common.constants.JobManageConstants.PUBLIC_APP_ID; +import static com.tencent.bk.job.common.constant.JobConstants.PUBLIC_APP_ID; @RestController @Slf4j -public class WebScriptResourceImpl extends AbstractJobController implements WebScriptResource { +public class WebScriptResourceImpl implements WebScriptResource { private final ScriptService scriptService; @@ -102,13 +117,13 @@ public WebScriptResourceImpl( MessageI18nService i18nService, ScriptCheckService scriptCheckService, ScriptDTOBuilder scriptDTOBuilder, - WebAuthService authService + WebAuthService webAuthService ) { this.scriptService = scriptService; this.i18nService = i18nService; this.scriptCheckService = scriptCheckService; this.scriptDTOBuilder = scriptDTOBuilder; - this.authService = authService; + this.authService = webAuthService; } @Override @@ -137,12 +152,46 @@ public ServiceResponse getScriptVersionDetail(String username, Long ap } ScriptVO scriptVO = ScriptConverter.convertToScriptVO(script); + + if (!checkPublicScriptVersionViewPermission(username, scriptVO)) { + return ServiceResponse.buildSuccessResp(null); + } + scriptVO.setTypeName(ScriptTypeEnum.getName(scriptVO.getType())); // 给前端的脚本内容需要base64编码 scriptVO.setContent(Base64Util.encodeContentToStr(script.getContent())); return ServiceResponse.buildSuccessResp(scriptVO); } + private boolean checkPublicScriptVersionViewPermission(String username, ScriptVO script) { + if (script.getPublicScript() != null && !script.getPublicScript()) { + return true; + } + + AuthResultVO authResultVO = checkScriptManagePermission(username, script.getAppId(), script.getId()); + if (authResultVO.isPass()) { + return true; + } else { + // if user does not have public script management permission, only return online public script version list + return script.getStatus() == JobResourceStatusEnum.ONLINE.getValue(); + } + } + + private List excludeNotOnlinePublicScriptVersion(String username, + Long appId, + String scriptId, + List scriptVersions) { + AuthResultVO authResultVO = checkScriptManagePermission(username, appId, scriptId); + if (authResultVO.isPass()) { + return scriptVersions; + } else { + // if user does not have public script management permission, only return online public script version list + return scriptVersions.stream().filter(scriptVersion -> + scriptVersion.getStatus() == JobResourceStatusEnum.ONLINE.getValue()) + .collect(Collectors.toList()); + } + } + @Override public ServiceResponse getScript(String username, Long appId, String scriptId) { ScriptDTO script = scriptService.getScript(username, appId, scriptId); @@ -465,6 +514,8 @@ public ServiceResponse> listScriptVersion(String username, Long a } } + + resultVOS = excludeNotOnlinePublicScriptVersion(username, appId, scriptId, resultVOS); return ServiceResponse.buildSuccessResp(resultVOS); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTagResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTagResourceImpl.java index 267eeb82ae..0981bdeb3f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTagResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTagResourceImpl.java @@ -30,7 +30,6 @@ import com.tencent.bk.job.common.iam.service.WebAuthService; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.web.WebTagResource; import com.tencent.bk.job.manage.model.dto.TagDTO; import com.tencent.bk.job.manage.model.web.request.TagCreateReq; @@ -47,14 +46,14 @@ @RestController @Slf4j -public class WebTagResourceImpl extends AbstractJobController implements WebTagResource { +public class WebTagResourceImpl implements WebTagResource { private final TagService tagService; private final WebAuthService authService; @Autowired - public WebTagResourceImpl(TagService tagService, WebAuthService authService) { + public WebTagResourceImpl(TagService tagService, WebAuthService webAuthService) { this.tagService = tagService; - this.authService = authService; + this.authService = webAuthService; } @Override diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskPlanResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskPlanResourceImpl.java index 4fb82ec210..7c1360f8e5 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskPlanResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskPlanResourceImpl.java @@ -25,7 +25,8 @@ package com.tencent.bk.job.manage.api.web.impl; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.exception.ServiceException; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; @@ -37,7 +38,6 @@ import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.check.*; import com.tencent.bk.job.common.util.check.exception.StringCheckException; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.crontab.model.CronJobVO; import com.tencent.bk.job.manage.api.web.WebTaskPlanResource; import com.tencent.bk.job.manage.common.util.IamPathUtil; @@ -57,7 +57,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RestController; @@ -70,7 +70,7 @@ */ @Slf4j @RestController -public class WebTaskPlanResourceImpl extends AbstractJobController implements WebTaskPlanResource { +public class WebTaskPlanResourceImpl implements WebTaskPlanResource { private final TaskPlanService planService; private final TaskTemplateService templateService; @@ -86,14 +86,14 @@ public WebTaskPlanResourceImpl( TaskTemplateService templateService, @Qualifier("TaskPlanFavoriteServiceImpl") TaskFavoriteService taskFavoriteService, CronJobService cronJobService, - WebAuthService authService, + WebAuthService webAuthService, MessageI18nService i18nService ) { this.planService = planService; this.templateService = templateService; this.taskFavoriteService = taskFavoriteService; this.cronJobService = cronJobService; - this.authService = authService; + this.authService = webAuthService; this.i18nService = i18nService; } @@ -205,11 +205,18 @@ public ServiceResponse> listPlans(String username, Long appId, if (!authResultVO.isPass()) { return ServiceResponse.buildAuthFailResp(authResultVO); } + + List taskPlanList = listPlansByTemplateId(username, appId, templateId); + return ServiceResponse.buildSuccessResp(taskPlanList); + } + + private List listPlansByTemplateId(String username, Long appId, Long templateId) { TaskTemplateInfoDTO taskTemplateBasicInfo = templateService.getTaskTemplateBasicInfoById(appId, templateId); if (taskTemplateBasicInfo == null) { - return ServiceResponse.buildCommonFailResp(ErrorCode.TASK_PLAN_NOT_EXIST, i18nService); + throw new ServiceException(ErrorCode.TEMPLATE_NOT_EXIST); } - List taskPlanInfoList = planService.listPageTaskPlansBasicInfo(appId, templateId); + + List taskPlanInfoList = planService.listTaskPlansBasicInfo(appId, templateId); fillCronInfo(appId, taskPlanInfoList); final String templateVersion = taskTemplateBasicInfo.getVersion(); List taskPlanList = taskPlanInfoList.stream().map(taskPlanInfo -> { @@ -218,7 +225,7 @@ public ServiceResponse> listPlans(String username, Long appId, return TaskPlanInfoDTO.toVO(taskPlanInfo); }).collect(Collectors.toList()); processPlanPermission(username, appId, taskPlanList); - return ServiceResponse.buildSuccessResp(taskPlanList); + return taskPlanList; } private void processPlanPermission(String username, Long appId, List taskPlanList) { @@ -257,6 +264,41 @@ private void processPlanPermission(String username, Long appId, List }); } + @Override + public ServiceResponse> batchGetPlans(String username, Long appId, + String templateIds) { + if (StringUtils.isEmpty(templateIds)) { + log.warn("TemplateIds is empty!"); + return ServiceResponse.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM); + } + + String[] templateIdArray = templateIds.split(","); + List templateIdList = new ArrayList<>(); + for (String templateIdStr : templateIdArray) { + templateIdList.add(Long.parseLong(templateIdStr)); + } + if (CollectionUtils.isEmpty(templateIdList)) { + log.warn("TemplateIdList is empty!"); + return ServiceResponse.buildCommonFailResp(ErrorCode.ILLEGAL_PARAM); + } + + AuthResultVO authResultVO = authService.auth(true, username, ActionId.LIST_BUSINESS, + ResourceTypeEnum.BUSINESS, appId.toString(), null); + if (!authResultVO.isPass()) { + return ServiceResponse.buildAuthFailResp(authResultVO); + } + + List planList = new ArrayList<>(); + for (Long templateId : templateIdList) { + List templatePlanList = listPlansByTemplateId(username, appId, templateId); + if (CollectionUtils.isNotEmpty(templatePlanList)) { + planList.addAll(templatePlanList); + } + } + + return ServiceResponse.buildSuccessResp(planList); + } + @Override public ServiceResponse getPlanById(String username, Long appId, Long templateId, Long planId) { AuthResultVO authResultVO = authService.auth(true, username, ActionId.VIEW_JOB_PLAN, diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskTemplateResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskTemplateResourceImpl.java index a9f7322d18..47f8b4c8b9 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskTemplateResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebTaskTemplateResourceImpl.java @@ -35,7 +35,6 @@ import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.common.web.controller.AbstractJobController; import com.tencent.bk.job.manage.api.web.WebTaskTemplateResource; import com.tencent.bk.job.manage.common.consts.TemplateTypeEnum; import com.tencent.bk.job.manage.common.consts.task.TaskTemplateStatusEnum; @@ -57,7 +56,11 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -65,7 +68,7 @@ */ @Slf4j @RestController -public class WebTaskTemplateResourceImpl extends AbstractJobController implements WebTaskTemplateResource { +public class WebTaskTemplateResourceImpl implements WebTaskTemplateResource { private final TaskTemplateService templateService; private final TaskFavoriteService taskFavoriteService; @@ -76,12 +79,12 @@ public class WebTaskTemplateResourceImpl extends AbstractJobController implement public WebTaskTemplateResourceImpl( TaskTemplateService templateService, @Qualifier("TaskTemplateFavoriteServiceImpl") TaskFavoriteService taskFavoriteService, - WebAuthService authService, + WebAuthService webAuthService, TaskTemplateAuthService taskTemplateAuthService ) { this.templateService = templateService; this.taskFavoriteService = taskFavoriteService; - this.authService = authService; + this.authService = webAuthService; this.taskTemplateAuthService = taskTemplateAuthService; } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebWhiteIPResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebWhiteIPResourceImpl.java index aa627a0325..2226429d8e 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebWhiteIPResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebWhiteIPResourceImpl.java @@ -56,17 +56,19 @@ public WebWhiteIPResourceImpl(WhiteIPService whiteIPService, WebAuthService auth } @Override - public ServiceResponse> listWhiteIP(String username, - String ipStr, - String appIdStr, - String appNameStr, - String actionScopeStr, - String creator, - String lastModifier, - Integer start, - Integer pageSize, - String orderField, - Integer order) { + public ServiceResponse> listWhiteIP( + String username, + String ipStr, + String appIdStr, + String appNameStr, + String actionScopeStr, + String creator, + String lastModifier, + Integer start, + Integer pageSize, + String orderField, + Integer order + ) { AuthResultVO authResultVO = authService.auth(true, username, ActionId.MANAGE_WHITELIST); if (!authResultVO.isPass()) { return ServiceResponse.buildAuthFailResp(authResultVO); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/client/ServiceCredentialResourceClient.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/client/ServiceCredentialResourceClient.java new file mode 100644 index 0000000000..a877e724ba --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/client/ServiceCredentialResourceClient.java @@ -0,0 +1,35 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.client; + +import com.tencent.bk.job.ticket.api.inner.ServiceCredentialResource; +import org.springframework.cloud.openfeign.FeignClient; + +/** + * 凭据服务内部接口远程调用客户端 + */ +@FeignClient(value = "job-ticket", contextId = "credential") +public interface ServiceCredentialResourceClient extends ServiceCredentialResource { +} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/EsbExceptionControllerAdvice.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/EsbExceptionControllerAdvice.java deleted file mode 100644 index 7e5e8bb558..0000000000 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/EsbExceptionControllerAdvice.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.manage.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.esb.model.EsbResp; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.ConversionNotSupportedException; -import org.springframework.beans.TypeMismatchException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.validation.BindException; -import org.springframework.web.HttpMediaTypeNotAcceptableException; -import org.springframework.web.HttpMediaTypeNotSupportedException; -import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.MissingPathVariableException; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.ServletRequestBindingException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.context.request.WebRequest; -import org.springframework.web.context.request.async.AsyncRequestTimeoutException; -import org.springframework.web.multipart.support.MissingServletRequestPartException; -import org.springframework.web.servlet.NoHandlerFoundException; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; - -/** - * 处理ESB异常 - */ -@ControllerAdvice({"com.tencent.bk.job.manage.api.esb"}) -@Slf4j -public class EsbExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - - @Autowired - public EsbExceptionControllerAdvice(MessageI18nService i18nService) { - this.i18nService = i18nService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.warn("Handle service exception", ex); - // esb请求错误统一返回200,具体的错误信息放在返回数据里边 - return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex.getErrorCode(), i18nService), HttpStatus.OK); - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - log.warn("Handle exception", ex); - // esb请求错误统一返回200,具体的错误信息放在返回数据里边 - return new ResponseEntity<>(EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService), - HttpStatus.OK); - } - - - @Override - protected ResponseEntity handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch HttpRequestMethodNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch HttpMediaTypeNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch HttpMediaTypeNotAcceptableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleMissingPathVariable(MissingPathVariableException ex, HttpHeaders headers, - HttpStatus status, WebRequest request) { - log.warn("Catch MissingPathVariableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleMissingServletRequestParameter(MissingServletRequestParameterException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch MissingServletRequestParameterException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleServletRequestBindingException(ServletRequestBindingException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch ServletRequestBindingException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleConversionNotSupported(ConversionNotSupportedException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch ConversionNotSupportedException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, - HttpStatus status, WebRequest request) { - log.warn("Catch TypeMismatchException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch HttpMessageNotReadableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWritableException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch HttpMessageNotWritableException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch MethodArgumentNotValidException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleMissingServletRequestPart(MissingServletRequestPartException ex, - HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch MissingServletRequestPartException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, - WebRequest request) { - log.warn("Catch BindException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, - HttpStatus status, WebRequest request) { - log.warn("Catch NoHandlerFoundException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.BAD_REQUEST, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } - - @Override - protected ResponseEntity handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, - HttpHeaders headers, HttpStatus status, - WebRequest webRequest) { - log.warn("Catch AsyncRequestTimeoutException, cause:{}", ex.getMessage()); - EsbResp resp = EsbResp.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, i18nService); - return new ResponseEntity<>(resp, HttpStatus.OK); - } -} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/ExceptionControllerAdvice.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/ExceptionControllerAdvice.java deleted file mode 100644 index 2e374f9185..0000000000 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/ExceptionControllerAdvice.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.manage.common; - -import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; -import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; -import com.tencent.bk.job.common.iam.model.AuthResult; -import com.tencent.bk.job.common.iam.service.WebAuthService; -import com.tencent.bk.job.common.model.ServiceResponse; -import com.tencent.bk.job.common.model.permission.AuthResultVO; -import com.tencent.bk.job.common.web.exception.HttpStatusServiceException; -import feign.FeignException; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MaxUploadSizeExceededException; -import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - -import javax.servlet.http.HttpServletRequest; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; - -@ControllerAdvice({"com.tencent.bk.job.manage.api.web", "com.tencent.bk.job.manage.api.inner"}) -@Slf4j -public class ExceptionControllerAdvice extends ResponseEntityExceptionHandler { - private final MessageI18nService i18nService; - private final WebAuthService webAuthService; - - @Autowired - public ExceptionControllerAdvice(MessageI18nService i18nService, WebAuthService webAuthService) { - this.i18nService = i18nService; - this.webAuthService = webAuthService; - } - - @ExceptionHandler(ServiceException.class) - @ResponseBody - ResponseEntity handleControllerServiceException(HttpServletRequest request, ServiceException ex) { - log.error("Handle service exception", ex); - if (ex instanceof HttpStatusServiceException) { - HttpStatusServiceException httpStatusServiceException = (HttpStatusServiceException) ex; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(httpStatusServiceException.getErrorCode() - , i18nService), httpStatusServiceException.getHttpStatus()); - } else if (ex instanceof InSufficientPermissionException) { - InSufficientPermissionException inSufficientPermissionException = (InSufficientPermissionException) ex; - AuthResultVO authResultVO = null; - if (inSufficientPermissionException.getAuthResult() != null) { - AuthResult authResult = inSufficientPermissionException.getAuthResult(); - log.debug("Insufficient permission, authResult: {}", authResult); - if (StringUtils.isEmpty(authResult.getApplyUrl())) { - authResult.setApplyUrl(webAuthService.getApplyUrl(authResult.getRequiredActionResources())); - } - authResultVO = webAuthService.toAuthResultVO(authResult); - } else if (ex.getErrorParams()[0] != null && ex.getErrorParams()[0] instanceof AuthResultVO) { - authResultVO = (AuthResultVO) ex.getErrorParams()[0]; - } - return new ResponseEntity<>(ServiceResponse.buildAuthFailResp(authResultVO), HttpStatus.OK); - } else { - if (ex.getErrorCode() > 0) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorCode(), - ex.getErrorParams(), i18nService), HttpStatus.OK); - } else { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ex.getErrorMsg()), HttpStatus.OK); - } - } - } - - @ExceptionHandler(Throwable.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, Throwable ex) { - logRequest(request); - log.error("Handle exception", ex); - // 默认处理 - HttpStatus status = getStatus(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), status); - } - - @ExceptionHandler(FeignException.class) - @ResponseBody - ResponseEntity handleFeignException(HttpServletRequest request, FeignException ex) { - log.warn("Handle feign exception", ex); - if (ex.status() == HttpStatus.UNAUTHORIZED.value()) { - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_AUTH_FAIL, i18nService) - , HttpStatus.UNAUTHORIZED); - } else { - logRequest(request); - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.SERVICE_INTERNAL_ERROR, - i18nService), HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @ExceptionHandler(MaxUploadSizeExceededException.class) - @ResponseBody - ResponseEntity handleControllerException(HttpServletRequest request, MaxUploadSizeExceededException ex) { - logRequest(request); - log.error("Handle MaxUploadSizeExceededException, maxFileSize:{}", ex.getMaxUploadSize()); - long maxFileSize = ex.getMaxUploadSize(); - String fileSizeDesc = (maxFileSize << 20) + "G"; - return new ResponseEntity<>(ServiceResponse.buildCommonFailResp(ErrorCode.UPLOAD_FILE_MAX_SIZE_EXCEEDED, - new String[]{fileSizeDesc}, i18nService), - HttpStatus.OK); - } - - private HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode == null) { - return HttpStatus.INTERNAL_SERVER_ERROR; - } - return HttpStatus.valueOf(statusCode); - } - - private void logRequest(HttpServletRequest request) { - try { - if (log.isDebugEnabled()) { - Map headerMap = new HashMap<>(); - Enumeration headerNames = request.getHeaderNames(); - while (headerNames.hasMoreElements()) { - String headName = headerNames.nextElement(); - headerMap.put(headName, request.getHeader(headName)); - } - log.debug("request=({},{},{},{},{},{})", request.getRemoteHost(), request.getMethod(), - request.getRequestURL().append(request.getQueryString()).toString(), request.getParameterMap(), - headerMap, request.getContentLength()); - } else { - log.info("request=({},{},{},{})", request.getRemoteHost(), request.getMethod(), - request.getRequestURL().append(request.getQueryString()).toString(), request.getContentLength()); - } - } catch (Throwable t) { - log.warn("Fail to log", t); - } - } -} diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/interceptor/UriPermissionInterceptor.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/interceptor/UriPermissionInterceptor.java index a24e8098c2..e404140dd3 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/interceptor/UriPermissionInterceptor.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/common/interceptor/UriPermissionInterceptor.java @@ -27,8 +27,8 @@ import com.tencent.bk.job.common.RequestIdLogger; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; -import com.tencent.bk.job.common.iam.service.WebAuthService; -import com.tencent.bk.job.common.model.permission.AuthResultVO; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.SimpleRequestIdLogger; import lombok.extern.slf4j.Slf4j; @@ -58,10 +58,12 @@ public class UriPermissionInterceptor extends HandlerInterceptorAdapter { private final String URI_PATTERN_PUBLIC_SCRIPT = "/web/public_script/**"; private final String URI_PATTERN_PUBLIC_TAG = "/web/public_tag/**"; private final String URI_PATTERN_SERVICE_INFO = "/web/serviceInfo/**"; - private WebAuthService authService; + private final String URI_PATTERN_DANGEROUS_RULE = "/web/dangerousRule/**"; + private AuthService authService; private PathMatcher pathMatcher; + @Autowired - public UriPermissionInterceptor(WebAuthService authService) { + public UriPermissionInterceptor(AuthService authService) { this.authService = authService; this.pathMatcher = new AntPathMatcher(); } @@ -88,7 +90,9 @@ private List getControlUriPatternsList() { // 公共标签 URI_PATTERN_PUBLIC_TAG, // 服务状态 - URI_PATTERN_SERVICE_INFO + URI_PATTERN_SERVICE_INFO, + // 高危语句规则 + URI_PATTERN_DANGEROUS_RULE ); } @@ -101,19 +105,24 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons "controlUriPatterns=" + getControlUriPatternsList()); //仅超级管理员可使用管理相关接口 if (pathMatcher.match(URI_PATTERN_NOTIFY_BLACKLIST, uri)) { - AuthResultVO authResult = authService.auth(true, username, ActionId.GLOBAL_SETTINGS); + AuthResult authResult = authService.auth(true, username, ActionId.GLOBAL_SETTINGS); if (!authResult.isPass()) { - throw new InSufficientPermissionException(new Object[]{authResult}); + throw new InSufficientPermissionException(authResult); } } else if (pathMatcher.match(URI_PATTERN_GLOBAL_SETTINGS, uri)) { - AuthResultVO authResult = authService.auth(true, username, ActionId.GLOBAL_SETTINGS); + AuthResult authResult = authService.auth(true, username, ActionId.GLOBAL_SETTINGS); if (!authResult.isPass()) { - throw new InSufficientPermissionException(new Object[]{authResult}); + throw new InSufficientPermissionException(authResult); } } else if (pathMatcher.match(URI_PATTERN_SERVICE_INFO, uri)) { - AuthResultVO authResult = authService.auth(true, username, ActionId.SERVICE_STATE_ACCESS); + AuthResult authResult = authService.auth(true, username, ActionId.SERVICE_STATE_ACCESS); + if (!authResult.isPass()) { + throw new InSufficientPermissionException(authResult); + } + } else if (pathMatcher.match(URI_PATTERN_DANGEROUS_RULE, uri)) { + AuthResult authResult = authService.auth(true, username, ActionId.HIGH_RISK_DETECT_RULE); if (!authResult.isPass()) { - throw new InSufficientPermissionException(new Object[]{authResult}); + throw new InSufficientPermissionException(authResult); } } return true; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/TagDAO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/TagDAO.java index 325e2cbbc6..bf8256a388 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/TagDAO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/TagDAO.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.manage.dao; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.model.dto.TagDTO; import java.util.List; @@ -100,4 +102,13 @@ public interface TagDAO { * @return */ List listTags(TagDTO searchCondition); + + /** + * 标签通用查询 + * + * @param tagCondition + * @param baseSearchCondition + * @return + */ + PageData listTags(TagDTO tagCondition, BaseSearchCondition baseSearchCondition); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/AccountDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/AccountDAOImpl.java index a9ef8f6f35..61ee240d0d 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/AccountDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/AccountDAOImpl.java @@ -33,7 +33,7 @@ import com.tencent.bk.job.manage.dao.AccountDAO; import com.tencent.bk.job.manage.model.dto.AccountDTO; import lombok.val; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.Account; import org.jooq.generated.tables.TaskTemplateStepFile; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationHostDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationHostDAOImpl.java index a25b1c248d..98a1165f0b 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationHostDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationHostDAOImpl.java @@ -40,7 +40,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.conf.ParamType; import org.jooq.generated.tables.Host; @@ -183,7 +183,7 @@ private List listHostInfoByConditions(Collection> records; if (start == null || start < 0) { start = 0L; @@ -293,7 +293,7 @@ public List getHostIdListBySearchContents(Collection appIds, Collect .join(tHostTopo) .on(tHost.HOST_ID.eq(tHostTopo.HOST_ID)) .where(conditions) - .orderBy(TABLE.IS_AGENT_ALIVE.desc()); + .orderBy(TABLE.IS_AGENT_ALIVE.desc(), TABLE.HOST_ID.asc()); log.debug("SQL={}", query.getSQL(ParamType.INLINED)); Result records; if (start == null || start < 0) { @@ -308,8 +308,15 @@ public List getHostIdListBySearchContents(Collection appIds, Collect if (records != null && records.size() >= 1) { hostIdList = records.parallelStream().map(record -> record.get(0, Long.class)).collect(Collectors.toList()); } - hostIdList = new ArrayList<>(new HashSet<>(hostIdList)); - return hostIdList; + Set hostIdSet = new HashSet<>(); + List uniqueHostIdList = new ArrayList<>(); + hostIdList.forEach(hostId -> { + if (!hostIdSet.contains(hostId)) { + uniqueHostIdList.add(hostId); + hostIdSet.add(hostId); + } + }); + return uniqueHostIdList; } @Override @@ -322,7 +329,7 @@ public List listHostInfoByDisplayIp(long appId, String i .select(TABLE.HOST_ID, TABLE.APP_ID, TABLE.IP, TABLE.IP_DESC, TABLE.SET_IDS, TABLE.MODULE_IDS, TABLE.CLOUD_AREA_ID, TABLE.DISPLAY_IP, TABLE.OS, TABLE.OS_TYPE, TABLE.MODULE_TYPE, TABLE.IS_AGENT_ALIVE) - .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc()).fetch(); + .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc(), TABLE.HOST_ID.asc()).fetch(); List hostInfoList = new ArrayList<>(); @@ -343,7 +350,7 @@ public List listHostInfoBySourceAndIps(long cloudAreaId, .select(TABLE.HOST_ID, TABLE.APP_ID, TABLE.IP, TABLE.IP_DESC, TABLE.SET_IDS, TABLE.MODULE_IDS, TABLE.CLOUD_AREA_ID, TABLE.DISPLAY_IP, TABLE.OS, TABLE.OS_TYPE, TABLE.MODULE_TYPE, TABLE.IS_AGENT_ALIVE) - .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc()).fetch(); + .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc(), TABLE.HOST_ID.asc()).fetch(); List hostInfoList = new ArrayList<>(); @@ -365,7 +372,7 @@ public List listHostInfoByAppIdsAndSourceAndIps(long app .select(TABLE.HOST_ID, TABLE.APP_ID, TABLE.IP, TABLE.IP_DESC, TABLE.SET_IDS, TABLE.MODULE_IDS, TABLE.CLOUD_AREA_ID, TABLE.DISPLAY_IP, TABLE.OS, TABLE.OS_TYPE, TABLE.MODULE_TYPE, TABLE.IS_AGENT_ALIVE) - .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc()).fetch(); + .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc(), TABLE.HOST_ID.asc()).fetch(); List hostInfoList = new ArrayList<>(); @@ -391,7 +398,8 @@ public PageData listHostInfoByPage(ApplicationHostInfoDT .select(TABLE.HOST_ID, TABLE.APP_ID, TABLE.IP, TABLE.IP_DESC, TABLE.SET_IDS, TABLE.MODULE_IDS, TABLE.CLOUD_AREA_ID, TABLE.DISPLAY_IP, TABLE.OS, TABLE.OS_TYPE, TABLE.MODULE_TYPE, TABLE.IS_AGENT_ALIVE) - .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc()).limit(start, length).fetch(); + .from(TABLE).where(conditions).orderBy(TABLE.IS_AGENT_ALIVE.desc(), TABLE.HOST_ID.asc()) + .limit(start, length).fetch(); List hostInfoList = new ArrayList<>(); @@ -898,7 +906,7 @@ public ApplicationHostInfoDTO getLatestHost(DSLContext dslContext, long appId, l .select(TABLE.HOST_ID, TABLE.APP_ID, TABLE.IP, TABLE.IP_DESC, TABLE.SET_IDS, TABLE.MODULE_IDS, TABLE.CLOUD_AREA_ID, TABLE.DISPLAY_IP, TABLE.OS, TABLE.OS_TYPE, TABLE.MODULE_TYPE, TABLE.IS_AGENT_ALIVE) - .from(TABLE).where(conditions).orderBy(TABLE.ROW_UPDATE_TIME.desc()).fetch(); + .from(TABLE).where(conditions).orderBy(TABLE.ROW_UPDATE_TIME.desc(), TABLE.HOST_ID.asc()).fetch(); if (records != null && records.size() >= 1) { return DbRecordMapper.convertRecordToApplicationHostInfo(records.get(0)); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationInfoDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationInfoDAOImpl.java index 56459cb36c..73bb15f302 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationInfoDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ApplicationInfoDAOImpl.java @@ -32,7 +32,7 @@ import com.tencent.bk.job.manage.dao.ApplicationInfoDAO; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.conf.ParamType; import org.jooq.generated.tables.Application; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ScriptDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ScriptDAOImpl.java index 0e9e72e26e..9d79cd8263 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ScriptDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/ScriptDAOImpl.java @@ -36,7 +36,7 @@ import com.tencent.bk.job.manage.model.dto.ScriptDTO; import com.tencent.bk.job.manage.model.dto.ScriptQueryDTO; import com.tencent.bk.job.manage.model.dto.TagDTO; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.Script; import org.jooq.generated.tables.ScriptVersion; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/TagDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/TagDAOImpl.java index 31919954dd..21e1b68169 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/TagDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/TagDAOImpl.java @@ -26,11 +26,15 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.DuplicateEntryException; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; +import com.tencent.bk.job.common.util.PageUtil; import com.tencent.bk.job.manage.dao.TagDAO; import com.tencent.bk.job.manage.model.dto.TagDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jooq.*; +import org.jooq.conf.ParamType; import org.jooq.exception.DataAccessException; import org.jooq.generated.tables.Tag; import org.jooq.types.UByte; @@ -159,7 +163,7 @@ private List listTagsByConditions(List conditions) { context.select(TABLE.ID, TABLE.APP_ID, TABLE.NAME, TABLE.CREATOR, TABLE.LAST_MODIFY_USER) .from(Tag.TAG).where(conditions).fetch(); List result = new ArrayList<>(); - if (records != null && records.size() > 0) { + if (records.size() > 0) { records.forEach(record -> result.add(record.into(TagDTO.class))); } return result; @@ -167,26 +171,114 @@ private List listTagsByConditions(List conditions) { @Override public List listTags(TagDTO searchCondition) { - List conditions = buildSearchCondition(searchCondition); + List conditions = buildTagCondition(searchCondition); Result> records = context.select(TABLE.ID, TABLE.APP_ID, TABLE.NAME, TABLE.CREATOR, TABLE.LAST_MODIFY_USER).from(Tag.TAG) .where(conditions).orderBy(TABLE.ROW_UPDATE_TIME.desc()).fetch(); List tags = new ArrayList<>(); - if (records != null && records.size() > 0) { + if (records.size() > 0) { records.forEach(record -> tags.add(record.into(TagDTO.class))); } return tags; } - private List buildSearchCondition(TagDTO searchCondition) { + private List buildTagCondition( + TagDTO tagCondition, + BaseSearchCondition baseSearchCondition + ) { + List conditions = buildTagCondition(tagCondition); + conditions.addAll(buildBaseSearchCondition(baseSearchCondition)); + return conditions; + } + + private long getTagCount( + TagDTO tagCondition, + BaseSearchCondition baseSearchCondition + ) { + List conditions = buildTagCondition(tagCondition, baseSearchCondition); + Long count = context.selectCount().from(TABLE).where(conditions).fetchOne(0, Long.class); + if (count == null) { + throw new RuntimeException("Get null query count result"); + } + return count; + } + + @Override + public PageData listTags( + TagDTO tagCondition, + BaseSearchCondition baseSearchCondition + ) { + long count = getTagCount(tagCondition, baseSearchCondition); + + Collection> orderFields = new ArrayList<>(); + if (org.apache.commons.lang3.StringUtils.isBlank(baseSearchCondition.getOrderField())) { + orderFields.add(TABLE.ID.desc()); + } else { + String orderField = baseSearchCondition.getOrderField(); + if ("name".equals(orderField)) { + //正序 + if (baseSearchCondition.getOrder() == 1) { + orderFields.add(TABLE.NAME.asc()); + } else { + orderFields.add(TABLE.NAME.desc()); + } + } else { + String msg = String.format("orderField %s not supported", orderField); + throw new RuntimeException(msg); + } + } + int start = baseSearchCondition.getStartOrDefault(PageUtil.DEFAULT_START); + int length = baseSearchCondition.getLengthOrDefault(PageUtil.DEFAULT_POSITIVE_LENGTH); + List conditions = buildTagCondition(tagCondition); + + SelectSeekStepN> selectSeekStep = context.select(TABLE.ID, TABLE.APP_ID, TABLE.NAME, TABLE.CREATOR, TABLE.LAST_MODIFY_USER).from(Tag.TAG) + .where(conditions).orderBy(orderFields); + if (log.isDebugEnabled()) { + log.debug("SQL=" + selectSeekStep.getSQL(ParamType.INLINED)); + } + Result> records; + if (length > 0) { + records = selectSeekStep.limit(start, length).fetch(); + } else { + records = selectSeekStep.offset(start).fetch(); + } + List tags = new ArrayList<>(); + if (records.size() > 0) { + records.forEach(record -> tags.add(record.into(TagDTO.class))); + } + return new PageData<>(start, length, count, tags); + } + + private List buildTagCondition(TagDTO searchCondition) { List conditions = new ArrayList<>(); - conditions.add(TABLE.APP_ID.eq(ULong.valueOf(searchCondition.getAppId()))); + if (searchCondition.getId() != null) { + conditions.add(TABLE.ID.eq(ULong.valueOf(searchCondition.getId()))); + } + if (searchCondition.getAppId() != null) { + conditions.add(TABLE.APP_ID.eq(ULong.valueOf(searchCondition.getAppId()))); + } if (StringUtils.isNotBlank(searchCondition.getName())) { String likePattern = "%" + searchCondition.getName() + "%"; conditions.add(TABLE.NAME.like(likePattern)); } + if (StringUtils.isNotBlank(searchCondition.getCreator())) { + conditions.add(TABLE.CREATOR.eq(searchCondition.getCreator())); + } conditions.add(TABLE.IS_DELETED.eq(UByte.valueOf(0))); return conditions; } + private List buildBaseSearchCondition( + BaseSearchCondition baseSearchCondition + ) { + List conditions = new ArrayList<>(); + if (StringUtils.isNotBlank(baseSearchCondition.getCreator())) { + conditions.add(TABLE.CREATOR.eq(baseSearchCondition.getCreator())); + } + if (StringUtils.isNotBlank(baseSearchCondition.getLastModifyUser())) { + conditions.add(TABLE.LAST_MODIFY_USER.eq(baseSearchCondition.getLastModifyUser())); + } + return conditions; + } + } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/plan/impl/TaskPlanDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/plan/impl/TaskPlanDAOImpl.java index e4bfbcf06e..bf0cc0c379 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/plan/impl/TaskPlanDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/plan/impl/TaskPlanDAOImpl.java @@ -34,7 +34,7 @@ import com.tencent.bk.job.manage.model.dto.task.TaskPlanInfoDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.TaskPlan; import org.jooq.generated.tables.records.TaskPlanRecord; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/template/impl/TaskTemplateDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/template/impl/TaskTemplateDAOImpl.java index d0b31c7abf..852f5ee4d4 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/template/impl/TaskTemplateDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/template/impl/TaskTemplateDAOImpl.java @@ -34,7 +34,7 @@ import com.tencent.bk.job.manage.service.TagService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.TaskTemplate; import org.jooq.generated.tables.records.TaskTemplateRecord; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/ActionScopeDAO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/ActionScopeDAO.java index c0d02f4887..9ddf3d415c 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/ActionScopeDAO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/ActionScopeDAO.java @@ -35,11 +35,13 @@ public interface ActionScopeDAO { int deleteActionScopeById(DSLContext dslContext, Long id); - ActionScopeDTO getActionScopeById(DSLContext dslContext, Long id); + ActionScopeDTO getActionScopeById(Long id); - ActionScopeVO getActionScopeVOById(DSLContext dslContext, Long id); + ActionScopeDTO getActionScopeByCode(String code); - List listActionScopeDTO(DSLContext dslContext); + ActionScopeVO getActionScopeVOById(Long id); + + List listActionScopeDTO(); int updateActionScopeById(DSLContext dslContext, ActionScopeDTO actionScopeDTO); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/WhiteIPRecordDAO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/WhiteIPRecordDAO.java index a9b40dfced..113ebb1c68 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/WhiteIPRecordDAO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/WhiteIPRecordDAO.java @@ -64,5 +64,5 @@ Long countWhiteIPRecord(DSLContext dslContext, String partIP, List appIdLi List getWhiteIPActionScopes(DSLContext dslContext, Collection appIds, String ip, Long cloudAreaId); - List listWhiteIPByAppIds(DSLContext dslContext, Collection appIds); + List listWhiteIPByAppIds(DSLContext dslContext, Collection appIds, Long actionScopeId); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/ActionScopeDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/ActionScopeDAOImpl.java index 9dc27e1479..5505844da8 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/ActionScopeDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/ActionScopeDAOImpl.java @@ -24,7 +24,7 @@ package com.tencent.bk.job.manage.dao.whiteip.impl; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; import com.tencent.bk.job.manage.dao.whiteip.ActionScopeDAO; import com.tencent.bk.job.manage.model.dto.whiteip.ActionScopeDTO; @@ -33,6 +33,7 @@ import org.jooq.DSLContext; import org.jooq.Record; import org.jooq.generated.tables.ActionScope; +import org.jooq.generated.tables.records.ActionScopeRecord; import org.jooq.types.ULong; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -43,11 +44,13 @@ @Repository public class ActionScopeDAOImpl implements ActionScopeDAO { + private DSLContext defaultDslContext; private static final ActionScope T_ACTION_SCOPE = ActionScope.ACTION_SCOPE; private final MessageI18nService i18nService; @Autowired - public ActionScopeDAOImpl(MessageI18nService i18nService) { + public ActionScopeDAOImpl(DSLContext dslContext, MessageI18nService i18nService) { + this.defaultDslContext = dslContext; this.i18nService = i18nService; } @@ -80,29 +83,24 @@ public int deleteActionScopeById(DSLContext dslContext, Long id) { } @Override - public ActionScopeDTO getActionScopeById(DSLContext dslContext, Long id) { - val record = dslContext.selectFrom(T_ACTION_SCOPE).where( + public ActionScopeDTO getActionScopeById(Long id) { + ActionScopeRecord record = defaultDslContext.selectFrom(T_ACTION_SCOPE).where( T_ACTION_SCOPE.ID.eq(id) ).fetchOne(); - if (record == null) { - return null; - } else { - return new ActionScopeDTO( - record.getId(), - record.getCode(), - record.getName(), - record.getDescription(), - record.getCreator(), - record.getCreateTime().longValue(), - record.getLastModifyUser(), - record.getLastModifyTime().longValue() - ); - } + return convert(record); } @Override - public ActionScopeVO getActionScopeVOById(DSLContext dslContext, Long id) { - val record = dslContext.selectFrom(T_ACTION_SCOPE).where( + public ActionScopeDTO getActionScopeByCode(String code) { + ActionScopeRecord record = defaultDslContext.selectFrom(T_ACTION_SCOPE).where( + T_ACTION_SCOPE.CODE.eq(code) + ).fetchOne(); + return convert(record); + } + + @Override + public ActionScopeVO getActionScopeVOById(Long id) { + val record = defaultDslContext.selectFrom(T_ACTION_SCOPE).where( T_ACTION_SCOPE.ID.eq(id) ).fetchOne(); if (record == null) { @@ -120,8 +118,8 @@ val record = dslContext.selectFrom(T_ACTION_SCOPE).where( } @Override - public List listActionScopeDTO(DSLContext dslContext) { - val records = dslContext.selectFrom(T_ACTION_SCOPE).fetch(); + public List listActionScopeDTO() { + val records = defaultDslContext.selectFrom(T_ACTION_SCOPE).fetch(); if (records == null) { return new ArrayList<>(); } @@ -152,4 +150,17 @@ public int updateActionScopeById(DSLContext dslContext, ActionScopeDTO actionSco .execute(); } + private ActionScopeDTO convert(ActionScopeRecord record) { + if (record == null) return null; + return new ActionScopeDTO( + record.getId(), + record.getCode(), + record.getName(), + record.getDescription(), + record.getCreator(), + record.getCreateTime().longValue(), + record.getLastModifyUser(), + record.getLastModifyTime().longValue() + ); + } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/WhiteIPRecordDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/WhiteIPRecordDAOImpl.java index 0bbe4dc6f9..478a0e4857 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/WhiteIPRecordDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/WhiteIPRecordDAOImpl.java @@ -38,7 +38,7 @@ import com.tencent.bk.job.manage.model.web.vo.whiteip.WhiteIPRecordVO; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.conf.ParamType; import org.jooq.generated.tables.*; @@ -333,7 +333,7 @@ private List listWhiteIPRecordByConditions(DSLContext dslContex val actionScopeIdListStr = (String) record.get(KEY_ACTION_SCOPE_ID_LIST); List actionScopeIdList = CustomCollectionUtils.getNoDuplicateList(actionScopeIdListStr, ","); List actionScopeVOList = actionScopeIdList.stream().map(actionScopeId -> - actionScopeDAO.getActionScopeVOById(dslContext, Long.parseLong(actionScopeId)) + actionScopeDAO.getActionScopeVOById(Long.parseLong(actionScopeId)) ).collect(Collectors.toList()); val appIdListStr = (String) record.get(KEY_APP_ID_LIST); List appIdList = CustomCollectionUtils.getNoDuplicateList(appIdListStr, ","); @@ -488,18 +488,27 @@ private List getWhiteIPActionScopesByConditions(DSLContext dslContext, L } @Override - public List listWhiteIPByAppIds(DSLContext dslContext, Collection appIds) { + public List listWhiteIPByAppIds(DSLContext dslContext, Collection appIds, Long actionScopeId) { val tWhiteIPIP = WhiteIpIp.WHITE_IP_IP.as("tWhiteIPIP"); val tWhiteIPAppRel = WhiteIpAppRel.WHITE_IP_APP_REL.as("tWhiteIPAppRel"); + val tWhiteIPActionScope = WhiteIpActionScope.WHITE_IP_ACTION_SCOPE.as("tWhiteIPActionScope"); + Collection conditions = new ArrayList<>(); + if (appIds != null) { + conditions.add(tWhiteIPAppRel.APP_ID.in(appIds)); + } + if (actionScopeId != null) { + conditions.add(tWhiteIPActionScope.ACTION_SCOPE_ID.eq(actionScopeId)); + } val query = dslContext.select( tWhiteIPIP.CLOUD_AREA_ID.as(KEY_CLOUD_AREA_ID), tWhiteIPIP.IP.as(KEY_IP) ).from(tWhiteIPAppRel) .join(tWhiteIPIP).on(tWhiteIPAppRel.RECORD_ID.eq(tWhiteIPIP.RECORD_ID)) - .where(tWhiteIPAppRel.APP_ID.in(appIds)); + .join(tWhiteIPActionScope).on(tWhiteIPAppRel.RECORD_ID.eq(tWhiteIPActionScope.RECORD_ID)) + .where(conditions); try { val records = query.fetch(); - if (records != null && records.size() > 0) { + if (records.size() > 0) { return records.map(record -> { val cloudId = (Long) record.get(KEY_CLOUD_AREA_ID); val ip = (String) record.get(KEY_IP); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/MigrationServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/migration/EncryptDbAccountPasswordMigrationTask.java similarity index 56% rename from src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/MigrationServiceImpl.java rename to src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/migration/EncryptDbAccountPasswordMigrationTask.java index 66e50fe31f..137cadd026 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/MigrationServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/migration/EncryptDbAccountPasswordMigrationTask.java @@ -22,49 +22,89 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.manage.service.impl; +package com.tencent.bk.job.manage.migration; +import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.crypto.AESUtils; import com.tencent.bk.job.manage.common.consts.account.AccountCategoryEnum; +import com.tencent.bk.job.manage.config.JobManageConfig; import com.tencent.bk.job.manage.dao.AccountDAO; import com.tencent.bk.job.manage.model.dto.AccountDTO; -import com.tencent.bk.job.manage.service.MigrationService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; @Service @Slf4j -public class MigrationServiceImpl implements MigrationService { +public class EncryptDbAccountPasswordMigrationTask { private final AccountDAO accountDAO; + private final JobManageConfig jobManageConfig; + @Autowired - public MigrationServiceImpl(AccountDAO accountDAO) { + public EncryptDbAccountPasswordMigrationTask(AccountDAO accountDAO, + JobManageConfig jobManageConfig) { this.accountDAO = accountDAO; + this.jobManageConfig = jobManageConfig; } - @Override - public boolean encryptDbAccountPassword(String key) { + /** + * 加密DB账号的密码 + * + * @return 结果 + */ + public ServiceResponse> encryptDbAccountPassword() { + log.info("Encrypt db account password start..."); + if (StringUtils.isBlank(jobManageConfig.getEncryptPassword())) { + log.error("Encrypt password is blank"); + return ServiceResponse.buildCommonFailResp("Encrypt password is blank"); + } + List dbAccounts = accountDAO.listAccountByAccountCategory(AccountCategoryEnum.DB); if (CollectionUtils.isEmpty(dbAccounts)) { log.info("Db account is empty, skip"); - return true; + return ServiceResponse.buildSuccessResp(Collections.emptyList()); } + try { + List updateAccountIdList = new ArrayList<>(); for (AccountDTO dbAccount : dbAccounts) { if (StringUtils.isNotEmpty(dbAccount.getDbPassword())) { - dbAccount.setDbPassword(AESUtils.encryptToBase64EncodedCipherText(dbAccount.getDbPassword(), key)); + if (isEncrypted(dbAccount.getDbPassword(), jobManageConfig.getEncryptPassword())) { + log.info("Account[id={}] is encrypted", dbAccount.getId()); + continue; + } + dbAccount.setDbPassword(AESUtils.encryptToBase64EncodedCipherText(dbAccount.getDbPassword(), + jobManageConfig.getEncryptPassword())); + updateAccountIdList.add(dbAccount.getId()); } } accountDAO.batchUpdateDbAccountPassword(dbAccounts); + log.info("Encrypt db account password successfully!"); + return ServiceResponse.buildSuccessResp(updateAccountIdList); } catch (Throwable e) { log.error("Encrypt db account password error", e); + return ServiceResponse.buildCommonFailResp("Encrypt db account password error"); + } + } + + private boolean isEncrypted(String base64EncodedCipherText, String key) { + return tryDecrypt(base64EncodedCipherText, key); + } + + private boolean tryDecrypt(String base64EncodedCipherText, String key) { + try { + AESUtils.decryptBase64EncodedDataToPlainText(base64EncodedCipherText, key); + return true; + } catch (Throwable e) { + log.warn("Decrypt fail", e); return false; } - return true; } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/converter/NotifyTemplateConverter.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/converter/NotifyTemplateConverter.java index afb6575f30..cb76b955ae 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/converter/NotifyTemplateConverter.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/converter/NotifyTemplateConverter.java @@ -24,8 +24,8 @@ package com.tencent.bk.job.manage.model.dto.converter; -import com.tencent.bk.job.common.i18n.MessageI18nService; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.manage.common.consts.notify.NotifyConsts; import com.tencent.bk.job.manage.dao.notify.NotifyEsbChannelDAO; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java index ed006ccb8c..8f4c4c0b69 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/ApplicationService.java @@ -31,6 +31,7 @@ import com.tencent.bk.job.common.model.dto.ApplicationInfoDTO; import com.tencent.bk.job.common.model.dto.DynamicGroupInfoDTO; import com.tencent.bk.job.common.model.vo.HostInfoVO; +import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; import com.tencent.bk.job.manage.model.web.request.AgentStatisticsReq; import com.tencent.bk.job.manage.model.web.request.ipchooser.AppTopologyTreeNode; import com.tencent.bk.job.manage.model.web.request.ipchooser.ListHostByBizTopologyNodesReq; @@ -130,7 +131,7 @@ List getAppTopologyTreeNodeDetail(String username, Long app * @param checkIpList 待查询的 IP 列表 * @return 主机信息列表 */ - List getHostsByIp(String username, Long appId, List checkIpList); + List getHostsByIp(String username, Long appId, ActionScopeEnum actionScope, List checkIpList); List listAllAppsFromLocalDB(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/TagService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/TagService.java index 510b46f942..50a5a7a6a9 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/TagService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/TagService.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.manage.service; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.manage.model.dto.TagDTO; import java.util.List; @@ -126,4 +128,13 @@ public interface TagService { * @return */ List listTags(Long appId, String tagNameKeyword); + + /** + * 标签通用分页查询 + * + * @param tagCondition + * @param baseSearchCondition + * @return + */ + PageData listTags(TagDTO tagCondition, BaseSearchCondition baseSearchCondition); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/WhiteIPService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/WhiteIPService.java index 2acf50d821..13714564c6 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/WhiteIPService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/WhiteIPService.java @@ -26,6 +26,7 @@ import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.vo.CloudAreaInfoVO; +import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; import com.tencent.bk.job.manage.model.dto.whiteip.CloudIPDTO; import com.tencent.bk.job.manage.model.inner.ServiceWhiteIPInfo; import com.tencent.bk.job.manage.model.web.request.whiteip.WhiteIPRecordCreateUpdateReq; @@ -49,7 +50,7 @@ PageData listWhiteIPRecord(String username, String ipStr, Strin * @param appId 业务Id * @return */ - List listWhiteIPByAppId(Long appId); + List listWhiteIP(Long appId, ActionScopeEnum actionScope); Long saveWhiteIP(String username, WhiteIPRecordCreateUpdateReq createUpdateReq); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java index 6bfe48b032..55eb4d1067 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java @@ -24,7 +24,11 @@ package com.tencent.bk.job.manage.service.impl; -import com.tencent.bk.job.common.cc.model.*; +import com.tencent.bk.job.common.cc.model.CcCloudAreaInfoDTO; +import com.tencent.bk.job.common.cc.model.CcGroupDTO; +import com.tencent.bk.job.common.cc.model.CcGroupHostPropDTO; +import com.tencent.bk.job.common.cc.model.CcInstanceDTO; +import com.tencent.bk.job.common.cc.model.InstanceTopologyDTO; import com.tencent.bk.job.common.cc.sdk.CcClient; import com.tencent.bk.job.common.cc.sdk.CcClientFactory; import com.tencent.bk.job.common.cc.service.CloudAreaService; @@ -47,6 +51,7 @@ import com.tencent.bk.job.common.util.PageUtil; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.manage.common.TopologyHelper; +import com.tencent.bk.job.manage.common.consts.whiteip.ActionScopeEnum; import com.tencent.bk.job.manage.dao.ApplicationHostDAO; import com.tencent.bk.job.manage.dao.ApplicationInfoDAO; import com.tencent.bk.job.manage.dao.HostTopoDAO; @@ -70,7 +75,14 @@ import org.springframework.stereotype.Service; import org.springframework.util.StopWatch; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -777,14 +789,9 @@ public List getHostInfoById(String username, Long appId, return hostInfoList; } - @Override - public List getHostsByIp(String username, Long appId, List checkIpList) { - log.info("Input=({},{},{})", username, appId, checkIpList); - if (checkIpList == null || checkIpList.isEmpty()) { - return Collections.emptyList(); - } - checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); + private List parseInputCloudIPList(List checkIpList) { List inputCloudIPList = new ArrayList<>(); + checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); for (int i = 0; i < checkIpList.size(); i++) { String ip = checkIpList.get(i); if (!StringUtils.isBlank(ip)) { @@ -804,26 +811,16 @@ public List getHostsByIp(String username, Long appId, List c } } } - //1.先查IP白名单中是否存在该IP - List appWhiteIPList = whiteIPService.listWhiteIPByAppId(appId); - //生成IP为索引的Map - Map> whiteIPMap = new HashMap<>(); - appWhiteIPList.forEach(cloudIPDTO -> { - String ip = cloudIPDTO.getIp(); - if (whiteIPMap.containsKey(ip)) { - List list = whiteIPMap.get(ip); - list.add(cloudIPDTO); - whiteIPMap.put(ip, list); - } else { - List list = new ArrayList<>(); - list.add(cloudIPDTO); - whiteIPMap.put(ip, list); - } - }); + return inputCloudIPList; + } + + private void separateWhiteIP( + List inputCloudIPList, + List inputWhiteIPList, + List inputNotWhiteIPList, + Map> whiteIPMap + ) { Set whiteIPSet = whiteIPMap.keySet(); - //找出输入IP中的白名单IP - List inputWhiteIPList = new ArrayList<>(); - List inputNotWhiteIPList = new ArrayList<>(); inputCloudIPList.forEach(cloudIPDTO -> { String ip = cloudIPDTO.getIp(); Long cloudId = cloudIPDTO.getCloudAreaId(); @@ -847,6 +844,41 @@ public List getHostsByIp(String username, Long appId, List c inputNotWhiteIPList.add(cloudIPDTO); } }); + } + + @Override + public List getHostsByIp( + String username, + Long appId, + ActionScopeEnum actionScope, + List checkIpList + ) { + log.info("Input=({},{},{})", username, appId, checkIpList); + if (checkIpList == null || checkIpList.isEmpty()) { + return Collections.emptyList(); + } + List inputCloudIPList = parseInputCloudIPList(checkIpList); + //1.先查IP白名单中是否存在该IP + List appWhiteIPList = whiteIPService.listWhiteIP(appId, actionScope); + //生成IP为索引的Map + Map> whiteIPMap = new HashMap<>(); + appWhiteIPList.forEach(cloudIPDTO -> { + String ip = cloudIPDTO.getIp(); + if (whiteIPMap.containsKey(ip)) { + List list = whiteIPMap.get(ip); + list.add(cloudIPDTO); + whiteIPMap.put(ip, list); + } else { + List list = new ArrayList<>(); + list.add(cloudIPDTO); + whiteIPMap.put(ip, list); + } + }); + + //找出输入IP中的白名单IP + List inputWhiteIPList = new ArrayList<>(); + List inputNotWhiteIPList = new ArrayList<>(); + separateWhiteIP(inputCloudIPList,inputWhiteIPList,inputNotWhiteIPList,whiteIPMap); //使用不带业务信息接口查询白名单IP对应的主机详情 //仅根据IP查询,查出后再根据指定云区域过滤 //根据IP查主机(缺少业务信息)本地 @@ -1099,7 +1131,7 @@ private List listHostByBizTopologyNodes(String username, Long appId, public AgentStatistics getAgentStatistics(String username, Long appId, AgentStatisticsReq agentStatisticsReq) { log.info("Input=({},{},{})", username, appId, JsonUtils.toJson(agentStatisticsReq)); ApplicationInfoDTO applicationInfoDTO = getAppInfoById(appId); - List hostsByIp = getHostsByIp(username, appId, agentStatisticsReq.getIpList()); + List hostsByIp = getHostsByIp(username, appId, null, agentStatisticsReq.getIpList()); log.debug("hostsByIp={}", hostsByIp); Set allHostsSet = new HashSet<>(); allHostsSet.addAll(hostsByIp); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/GlobalSettingsServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/GlobalSettingsServiceImpl.java index ff40dff2b5..9dce029fdb 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/GlobalSettingsServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/GlobalSettingsServiceImpl.java @@ -26,8 +26,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.exception.InvalidParamException; -import com.tencent.bk.job.common.i18n.MessageI18nService; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.util.JobContextUtil; import com.tencent.bk.job.common.util.StringUtil; import com.tencent.bk.job.common.util.TimeUtil; @@ -653,7 +653,7 @@ public List listChannelTemplateStatus(String username) @Override public String getDocCenterBaseUrl() { String url = ""; - if (org.apache.commons.lang.StringUtils.isNotBlank(jobManageConfig.getBkDocRoot())) { + if (org.apache.commons.lang3.StringUtils.isNotBlank(jobManageConfig.getBkDocRoot())) { url = removeSuffixBackSlash(jobManageConfig.getBkDocRoot()); } else { String jobEdition = jobManageConfig.getJobEdition(); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/IndexServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/IndexServiceImpl.java index e7cb7a8a91..4ee3ce92cd 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/IndexServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/IndexServiceImpl.java @@ -26,8 +26,8 @@ import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.gse.service.QueryAgentStatusClient; -import com.tencent.bk.job.common.i18n.MessageI18nService; import com.tencent.bk.job.common.i18n.locale.LocaleUtils; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.dto.ApplicationHostInfoDTO; import com.tencent.bk.job.common.model.dto.ApplicationInfoDTO; @@ -51,7 +51,7 @@ import com.tencent.bk.job.manage.service.template.TaskTemplateService; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImpl.java index 4c368d75d7..f1f59f1581 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImpl.java @@ -25,8 +25,9 @@ package com.tencent.bk.job.manage.service.impl; import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.constant.JobConstants; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.exception.InSufficientPermissionException; @@ -38,7 +39,6 @@ import com.tencent.bk.job.common.util.JobUUID; import com.tencent.bk.job.common.util.date.DateUtils; import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.manage.common.constants.JobManageConstants; import com.tencent.bk.job.manage.common.consts.JobResourceStatusEnum; import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum; import com.tencent.bk.job.manage.dao.*; @@ -56,7 +56,7 @@ import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.jooq.DSLContext; import org.jooq.impl.DSL; @@ -244,7 +244,7 @@ public ScriptDTO saveScript(String operator, Long appId, ScriptDTO script) throw long targetAppId = appId; if (script.isPublicScript()) { // 公共脚本业务ID为0 - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; script.setAppId(targetAppId); } @@ -315,7 +315,7 @@ public Pair createScriptWithVersionId( long targetAppId = appId; if (script.isPublicScript()) { // 公共脚本业务ID为0 - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; script.setAppId(targetAppId); } @@ -466,7 +466,7 @@ private void checkDeleteScriptPermission( } long targetAppId = appId; if (existScript.isPublicScript()) { - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; } if (!existScript.getAppId().equals(targetAppId)) { throw new ServiceException(ErrorCode.SCRIPT_NOT_IN_APP); @@ -491,7 +491,7 @@ public void publishScript( boolean isPublicScript = scriptVersions.get(0).isPublicScript(); long targetAppId = appId; if (isPublicScript) { - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; } boolean isScriptVersionInCurrentScript = false; @@ -554,7 +554,7 @@ public void disableScript( boolean isPublicScript = scriptVersions.get(0).isPublicScript(); long targetAppId = appId; if (isPublicScript) { - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; } boolean isScriptVersionInCurrentScript = false; @@ -629,7 +629,7 @@ public void updateScriptName( } long targetAppId = appId; if (script.isPublicScript()) { - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; } boolean isNameExist = scriptDAO.isExistDuplicateName(targetAppId, newName); if (isNameExist) { @@ -648,7 +648,7 @@ public void updateScriptTags(Long appId, String operator, String scriptId, List< checkUpdateScriptPermission(operator, appId, script); long targetAppId = appId; if (script.isPublicScript()) { - targetAppId = JobManageConstants.PUBLIC_APP_ID; + targetAppId = JobConstants.PUBLIC_APP_ID; } tagService.createNewTagIfNotExist(tags, targetAppId, operator); scriptDAO.updateScriptTags(operator, scriptId, tags); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/TagServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/TagServiceImpl.java index 7572500db6..221bd53fed 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/TagServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/TagServiceImpl.java @@ -26,6 +26,8 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ParamErrorException; +import com.tencent.bk.job.common.model.BaseSearchCondition; +import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.util.TagUtils; import com.tencent.bk.job.common.util.check.*; import com.tencent.bk.job.common.util.check.exception.StringCheckException; @@ -205,4 +207,8 @@ public List listTags(Long appId, String tagNameKeyword) { return tagDAO.listTags(searchCondition); } + @Override + public PageData listTags(TagDTO tagCondition, BaseSearchCondition baseSearchCondition){ + return tagDAO.listTags(tagCondition,baseSearchCondition); + } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/WhiteIPServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/WhiteIPServiceImpl.java index 4363dd76a7..d3d028f5f1 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/WhiteIPServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/WhiteIPServiceImpl.java @@ -29,7 +29,7 @@ import com.tencent.bk.job.common.cc.sdk.CcClientFactory; import com.tencent.bk.job.common.constant.AppTypeEnum; import com.tencent.bk.job.common.exception.InvalidParamException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.dto.ApplicationInfoDTO; @@ -43,7 +43,11 @@ import com.tencent.bk.job.manage.dao.ApplicationInfoDAO; import com.tencent.bk.job.manage.dao.whiteip.ActionScopeDAO; import com.tencent.bk.job.manage.dao.whiteip.WhiteIPRecordDAO; -import com.tencent.bk.job.manage.model.dto.whiteip.*; +import com.tencent.bk.job.manage.model.dto.whiteip.ActionScopeDTO; +import com.tencent.bk.job.manage.model.dto.whiteip.CloudIPDTO; +import com.tencent.bk.job.manage.model.dto.whiteip.WhiteIPActionScopeDTO; +import com.tencent.bk.job.manage.model.dto.whiteip.WhiteIPIPDTO; +import com.tencent.bk.job.manage.model.dto.whiteip.WhiteIPRecordDTO; import com.tencent.bk.job.manage.model.inner.ServiceWhiteIPInfo; import com.tencent.bk.job.manage.model.web.request.whiteip.WhiteIPRecordCreateUpdateReq; import com.tencent.bk.job.manage.model.web.vo.AppVO; @@ -60,7 +64,12 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Slf4j @@ -175,16 +184,21 @@ public PageData listWhiteIPRecord( } @Override - public List listWhiteIPByAppId(Long appId) { + public List listWhiteIP(Long appId, ActionScopeEnum actionScope) { List fullAppIds = applicationService.getFullAppIds(appId); log.info("appId={}, contains by fullAppIds={}", appId, fullAppIds); - return whiteIPRecordDAO.listWhiteIPByAppIds(dslContext, fullAppIds); + ActionScopeDTO actionScopeDTO = null; + if (actionScope != null) { + actionScopeDTO = actionScopeDAO.getActionScopeByCode(actionScope.name()); + } + return whiteIPRecordDAO.listWhiteIPByAppIds( + dslContext, + fullAppIds, + actionScopeDTO == null ? null : actionScopeDTO.getId() + ); } - @Override - public Long saveWhiteIP(String username, WhiteIPRecordCreateUpdateReq createUpdateReq) { - LOG.infoWithRequestId("Input(" + username + "," + createUpdateReq.toString() + ")"); - //1.参数校验、预处理 + private List checkReqAndGetIpList(WhiteIPRecordCreateUpdateReq createUpdateReq) { String appIdStr = createUpdateReq.getAppIdStr(); if (null == appIdStr || appIdStr.isEmpty()) { throw new InvalidParamException("appIdStr", "appIdStr cannot be null or empty"); @@ -218,6 +232,16 @@ public Long saveWhiteIP(String username, WhiteIPRecordCreateUpdateReq createUpda throw new InvalidParamException("ipStr", "not a valid ip format"); }); } + return ipList; + } + + @Override + public Long saveWhiteIP(String username, WhiteIPRecordCreateUpdateReq createUpdateReq) { + LOG.infoWithRequestId("Input(" + username + "," + createUpdateReq.toString() + ")"); + //1.参数校验、预处理 + List ipList = checkReqAndGetIpList(createUpdateReq); + List appIdList = Arrays.stream(createUpdateReq.getAppIdStr().split(",")) + .map(Long::parseLong).collect(Collectors.toList()); List actionScopeIdList = createUpdateReq.getActionScopeIdList(); val ipDtoList = ipList.stream().map(ip -> new WhiteIPIPDTO( null, @@ -299,7 +323,7 @@ val record = whiteIPRecordDAO.getWhiteIPRecordById(dslContext, id); record.getIpList().stream().map(WhiteIPIPDTO::getIp).collect(Collectors.toList()), record.getActionScopeList().stream().map(actionScopeDTO -> { val actionScopeId = actionScopeDTO.getActionScopeId(); - return actionScopeDAO.getActionScopeVOById(dslContext, actionScopeId); + return actionScopeDAO.getActionScopeVOById(actionScopeId); }).collect(Collectors.toList()), appVOList, record.getRemark(), @@ -321,7 +345,7 @@ public List listCloudAreas(String username) { @Override public List listActionScope(String username) { - return actionScopeDAO.listActionScopeDTO(dslContext).stream().map(it -> + return actionScopeDAO.listActionScopeDTO().stream().map(it -> new ActionScopeVO( it.getId(), i18nService.getI18n(ActionScopeEnum.getI18nCodeByName(it.getCode())), @@ -367,7 +391,7 @@ public List listWhiteIPInfos() { serviceWhiteIPInfo.setForAllApp(true); List allAppActionScopeList = new ArrayList<>(); for (WhiteIPActionScopeDTO actionScope : whiteIPRecordDTO.getActionScopeList()) { - ActionScopeDTO actionScopeDTO = actionScopeDAO.getActionScopeById(dslContext, + ActionScopeDTO actionScopeDTO = actionScopeDAO.getActionScopeById( actionScope.getActionScopeId()); if (actionScopeDTO == null) { log.error("Cannot find actionScopeDTO by id {}", actionScope.getActionScopeId()); @@ -492,7 +516,7 @@ private void genNormalAppWhiteIPInfo(WhiteIPRecordDTO whiteIPRecordDTO, List> map = new HashMap<>(); List actionScopeList = new ArrayList<>(); whiteIPRecordDTO.getActionScopeList().forEach(actionScope -> { - ActionScopeDTO actionScopeDTO = actionScopeDAO.getActionScopeById(dslContext, + ActionScopeDTO actionScopeDTO = actionScopeDAO.getActionScopeById( actionScope.getActionScopeId()); if (actionScopeDTO == null) { log.warn("Cannot find actionScope by id {}", actionScope.getActionScopeId()); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppHostsUpdateHelper.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppHostsUpdateHelper.java index e371d9c065..76f8d26d23 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppHostsUpdateHelper.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppHostsUpdateHelper.java @@ -86,7 +86,6 @@ public void waitForAppHostsUpdatingLock(Long appId, int intervalMills, int print public boolean isAppHostsUpdating(Long appId) { String updatingMachine = getAppHostsUpdatingMachine(appId); -// log.debug("{} is updating app {}", updatingMachine, appId); return StringUtils.isNotBlank(updatingMachine); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppWatchThread.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppWatchThread.java index 48c83c7f97..34f675c973 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppWatchThread.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/AppWatchThread.java @@ -39,7 +39,7 @@ import com.tencent.bk.job.manage.dao.ApplicationInfoDAO; import com.tencent.bk.job.manage.service.ApplicationService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.jooq.exception.DataAccessException; import org.springframework.data.redis.core.RedisTemplate; @@ -103,7 +103,7 @@ private void handleOneEvent(ResourceEvent event) { if (errorMessage.contains("Duplicate entry") && errorMessage.contains("PRIMARY")) { // 若已存在则忽略 } else { - log.error("insertApp fail:appInfo={}", appInfoDTO, e); + log.error("insertApp fail:appInfo=" + appInfoDTO, e); } } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/EventsHandler.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/EventsHandler.java index b263867ca6..3331184121 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/EventsHandler.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/EventsHandler.java @@ -58,7 +58,7 @@ public void commitEvent(Long appId, ResourceEvent event) { this.appId = appId; } } catch (Exception e) { - log.warn("Fail to commitEvent:{}", event, e); + log.warn("Fail to commitEvent:" + event, e); } } @@ -74,7 +74,7 @@ public void run() { } catch (InterruptedException e) { log.warn("queue.take interrupted", e); } catch (Throwable t) { - log.warn("Fail to handleOneEvent:{}", event, t); + log.warn("Fail to handleOneEvent:" + event, t); } finally { if (queue.size() == 0) { this.idle = true; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostRelationWatchThread.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostRelationWatchThread.java index 1bec10ba42..b417f59e71 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostRelationWatchThread.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostRelationWatchThread.java @@ -40,7 +40,7 @@ import com.tencent.bk.job.manage.model.dto.HostTopoDTO; import com.tencent.bk.job.manage.service.SyncService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.jooq.exception.DataAccessException; import org.springframework.data.redis.core.RedisTemplate; @@ -157,7 +157,7 @@ private void handleOneEvent(ResourceEvent event) { log.debug("handle hostRelationEvent:" + watch.prettyPrint()); } } catch (Throwable t) { - log.error("Fail to handle hostRelationEvent of appId {}, event:{}", appId, event, t); + log.error(String.format("Fail to handle hostRelationEvent of appId %d, event:%s", appId, event), t); } finally { appHostsUpdateHelper.endToUpdateAppHosts(appId); } @@ -176,7 +176,7 @@ private void handleOneEventIndeed(ResourceEvent event) if (errorMessage.contains("Duplicate entry") && errorMessage.contains("PRIMARY")) { // 若已存在则忽略 } else { - log.error("insertHostTopo fail:hostTopoInfo={}", hostTopoDTO, e); + log.error("insertHostTopo fail:hostTopoInfo=" + hostTopoDTO, e); } } // 若主机存在需将拓扑信息同步至主机信息冗余字段 diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostWatchThread.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostWatchThread.java index 62f1df13fa..fe873de9ec 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostWatchThread.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/HostWatchThread.java @@ -39,7 +39,7 @@ import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.manage.dao.ApplicationHostDAO; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.jooq.exception.DataAccessException; import org.springframework.data.redis.core.RedisTemplate; @@ -145,7 +145,7 @@ private void handleOneEventRelatedToApp(ResourceEvent event) { appHostsUpdateHelper.waitAndStartAppHostsUpdating(appId); handleOneEventIndeed(event); } catch (Throwable t) { - log.error("Fail to handle hostEvent of appId {}, event:{}", appId, event, t); + log.error(String.format("Fail to handle hostEvent of appId %d, event:%s", appId, event), t); } finally { appHostsUpdateHelper.endToUpdateAppHosts(appId); } @@ -205,7 +205,7 @@ private void handleOneEventIndeed(ResourceEvent event) { if (errorMessage.contains("Duplicate entry") && errorMessage.contains("PRIMARY")) { // 若已存在则忽略 } else { - log.error("insertHost fail:hostInfo={}", hostInfoDTO, e); + log.error("insertHost fail:hostInfo=" + hostInfoDTO, e); } } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/SyncServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/SyncServiceImpl.java index 5d90b9db66..83d523549f 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/SyncServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/sync/SyncServiceImpl.java @@ -44,7 +44,7 @@ import com.tencent.bk.job.manage.service.ApplicationService; import com.tencent.bk.job.manage.service.SyncService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.jooq.exception.DataAccessException; import org.springframework.beans.factory.annotation.Autowired; @@ -55,8 +55,19 @@ import org.springframework.stereotype.Service; import org.springframework.util.StopWatch; -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -317,21 +328,21 @@ public Long syncApp() { try { addAppToDb(applicationInfoDTO, Collections.emptyList()); } catch (Throwable t) { - log.error("FATAL: insertApp fail:appId={}", applicationInfoDTO.getId(), t); + log.error("FATAL: insertApp fail:appId=" + applicationInfoDTO.getId(), t); } }); updateList.forEach(applicationInfoDTO -> { try { applicationInfoDAO.updateAppInfo(dslContext, applicationInfoDTO); } catch (Throwable t) { - log.error("FATAL: updateApp fail:appId={}", applicationInfoDTO.getId(), t); + log.error("FATAL: updateApp fail:appId=" + applicationInfoDTO.getId(), t); } }); deleteList.forEach(applicationInfoDTO -> { try { deleteAppFromDb(applicationInfoDTO); } catch (Throwable t) { - log.error("FATAL: deleteApp fail:appId={}", applicationInfoDTO.getId(), t); + log.error("FATAL: deleteApp fail:appId=" + applicationInfoDTO.getId(), t); } }); log.info(Thread.currentThread().getName() + ":Finished:sync app from cc"); @@ -345,7 +356,7 @@ public Long syncApp() { handleFailedSyncAppHosts(); appSyncRedisKeyHeartBeatThread.setRunFlag(false); watch.stop(); - log.info("syncApp time consuming:" + watch.toString()); + log.info("syncApp time consuming:" + watch.prettyPrint()); } }); } finally { @@ -416,7 +427,7 @@ private Pair syncAppHostsAtOnce(ApplicationInfoDTO applicationInfoDT appHostsUpdateHelper.waitAndStartAppHostsUpdating(appId); return syncAppHostsIndeed(applicationInfoDTO); } catch (Throwable t) { - log.error("Fail to syncAppHosts of appId {}", appId, t); + log.error("Fail to syncAppHosts of appId " + appId, t); return null; } finally { appHostsUpdateHelper.endToUpdateAppHosts(appId); @@ -424,31 +435,32 @@ private Pair syncAppHostsAtOnce(ApplicationInfoDTO applicationInfoDT } private Pair syncAppHostsIndeed(ApplicationInfoDTO applicationInfoDTO) { + Long appId = applicationInfoDTO.getId(); Long cmdbInterfaceTimeConsuming = 0L; Long writeToDBTimeConsuming = 0L; CcClient ccClient = CcClientFactory.getCcClient(); StopWatch appHostsWatch = new StopWatch(); appHostsWatch.start("getHostsByAppInfo from CMDB"); Long startTime = System.currentTimeMillis(); - log.info("begin to syncAppHosts:appId={}", applicationInfoDTO.getId()); + log.info("begin to syncAppHosts:appId={}", appId); List hosts = getHostsByAppInfo(ccClient, applicationInfoDTO); cmdbInterfaceTimeConsuming += (System.currentTimeMillis() - startTime); appHostsWatch.stop(); appHostsWatch.start("updateHosts to local DB"); startTime = System.currentTimeMillis(); - updateHosts(applicationInfoDTO, hosts); + refreshAppHosts(appId, hosts); writeToDBTimeConsuming += (System.currentTimeMillis() - startTime); appHostsWatch.stop(); - log.info("Performance:syncAppHosts:appId={},{}", applicationInfoDTO.getId(), appHostsWatch.toString()); + log.info("Performance:syncAppHosts:appId={},{}", appId, appHostsWatch.toString()); return Pair.of(cmdbInterfaceTimeConsuming, writeToDBTimeConsuming); } - private Pair syncAppHostAgentStatus(ApplicationInfoDTO applicationInfoDTO) { + private Pair syncAppHostAgentStatus(Long appId) { Long gseInterfaceTimeConsuming = 0L; Long writeToDBTimeConsuming = 0L; StopWatch appHostAgentStatusWatch = new StopWatch(); appHostAgentStatusWatch.start("listHostInfoByAppId"); - List localAppHosts = applicationHostDAO.listHostInfoByAppId(applicationInfoDTO.getId()); + List localAppHosts = applicationHostDAO.listHostInfoByAppId(appId); appHostAgentStatusWatch.stop(); appHostAgentStatusWatch.start("getAgentStatusByAppInfo from GSE"); Long startTime = System.currentTimeMillis(); @@ -457,10 +469,10 @@ private Pair syncAppHostAgentStatus(ApplicationInfoDTO applicationIn appHostAgentStatusWatch.stop(); appHostAgentStatusWatch.start("updateHosts to local DB"); startTime = System.currentTimeMillis(); - updateHostsToDB(applicationInfoDTO, localAppHosts); + updateHostsInApp(appId, localAppHosts); writeToDBTimeConsuming += (System.currentTimeMillis() - startTime); appHostAgentStatusWatch.stop(); - log.debug("Performance:syncAppHostAgentStatus:appId={},{}", applicationInfoDTO.getId(), + log.debug("Performance:syncAppHostAgentStatus:appId={},{}", appId, appHostAgentStatusWatch.toString()); return Pair.of(gseInterfaceTimeConsuming, writeToDBTimeConsuming); } @@ -537,7 +549,7 @@ public Long syncHost() { writeToDBTimeConsuming += timeConsumingPair.getSecond(); } catch (Throwable t) { appHostFailQueue.add(Pair.of(applicationInfoDTO, MAX_RETRY_COUNT)); - log.error("syncHost of app fail:appId={}", applicationInfoDTO.getId(), t); + log.error("syncHost of app fail:appId=" + applicationInfoDTO.getId(), t); } } log.info(Thread.currentThread().getName() + ":Finished:sync host from cc," + @@ -560,7 +572,7 @@ public Long syncHost() { handleFailedSyncAppHosts(); hostSyncRedisKeyHeartBeatThread.setRunFlag(false); watch.stop(); - log.info("syncHost time consuming:" + watch.toString()); + log.info("syncHost time consuming:" + watch.prettyPrint()); } }); } finally { @@ -723,11 +735,11 @@ public Long syncAgentStatus() { Long writeToDBTimeConsuming = 0L; for (ApplicationInfoDTO applicationInfoDTO : localNormalApps) { try { - Pair timeConsumingPair = syncAppHostAgentStatus(applicationInfoDTO); + Pair timeConsumingPair = syncAppHostAgentStatus(applicationInfoDTO.getId()); gseInterfaceTimeConsuming += timeConsumingPair.getFirst(); writeToDBTimeConsuming += timeConsumingPair.getSecond(); } catch (Throwable t) { - log.error("syncAgentStatus of app fail:appId={}", applicationInfoDTO.getId(), t); + log.error("syncAgentStatus of app fail:appId=" + applicationInfoDTO.getId(), t); } } log.info(Thread.currentThread().getName() + ":Finished:sync agentStatus from GSE," + @@ -742,7 +754,7 @@ public Long syncAgentStatus() { } finally { agentStatusSyncRedisKeyHeartBeatThread.setRunFlag(false); watch.stop(); - log.info("syncAgentStatus time consuming:" + watch.toString()); + log.info("syncAgentStatus time consuming:" + watch.prettyPrint()); } }); } finally { @@ -785,7 +797,9 @@ private int addAppToDb(ApplicationInfoDTO applicationInfoDTO, return 1; } - private void updateHostsToDB(ApplicationInfoDTO applicationInfoDTO, List updateList) { + private void updateHostsInApp(Long appId, List updateList) { + StopWatch watch = new StopWatch(); + watch.start("updateAppHostInfo"); // 更新主机 long updateCount = 0L; List updateHostIds = new ArrayList<>(); @@ -821,82 +835,96 @@ private void updateHostsToDB(ApplicationInfoDTO applicationInfoDTO, List applicationHostInfoDTOList) { - Long appId = applicationInfoDTO.getId(); + private void deleteHostsFromApp(Long appId, List deleteList) { StopWatch watch = new StopWatch(); - //找出要删除的/更新的/新增的分别处理 - List insertList; - List updateList; - List deleteList; - //对比库中数据与接口数据 - watch.start("listHostInfoByAppId"); - List localAppHosts = applicationHostDAO.listHostInfoByAppId(applicationInfoDTO.getId()); - watch.stop(); - watch.start("mapTo ccAppHostIds"); - Set ccAppHostIds = - applicationHostInfoDTOList.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toSet()); - watch.stop(); - watch.start("mapTo localAppHostIds"); - Set localAppHostIds = - localAppHosts.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toSet()); - watch.stop(); - watch.start("log ccAppHostIds"); - log.info(String.format("appId=%s,ccAppHostIds=%s", applicationInfoDTO.getId(), String.join(",", - ccAppHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); - watch.stop(); - watch.start("log localAppHostIds"); - log.info(String.format("appId=%s,localAppHostIds=%s", applicationInfoDTO.getId(), String.join(",", - localAppHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); - watch.stop(); - watch.start("compute insertList"); - insertList = - applicationHostInfoDTOList.stream().filter(applicationHostInfoDTO -> - !localAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); - watch.stop(); - watch.start("log insertList"); - log.info(String.format("appId=%s,insertHostIds=%s", applicationInfoDTO.getId(), String.join(",", - insertList.stream().map(ApplicationHostInfoDTO::getHostId).map(Object::toString) - .collect(Collectors.toSet())))); - watch.stop(); - watch.start("compute updateList"); - updateList = - applicationHostInfoDTOList.stream().filter(applicationHostInfoDTO -> - localAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); - watch.stop(); - watch.start("log updateList"); - log.info(String.format("appId=%s,updateHostIds=%s", applicationInfoDTO.getId(), String.join(",", - updateList.stream().map(ApplicationHostInfoDTO::getHostId) - .map(Object::toString).collect(Collectors.toSet())))); - watch.stop(); - watch.start("compute deleteList"); - deleteList = - localAppHosts.stream().filter(applicationHostInfoDTO -> - !ccAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); - watch.stop(); - watch.start("log deleteList"); - log.info(String.format("appId=%s,deleteHostIds=%s", applicationInfoDTO.getId(), String.join(",", - deleteList.stream().map(ApplicationHostInfoDTO::getHostId).map(Object::toString) - .collect(Collectors.toSet())))); + // 删除主机 + watch.start("deleteAppHostInfo"); + List deleteFailHostIds = new ArrayList<>(); + boolean batchDeleted = false; + try { + // 尝试批量删除 + if (!deleteList.isEmpty()) { + applicationHostDAO.batchDeleteAppHostInfoById(dslContext, appId, + deleteList.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toList())); + } + batchDeleted = true; + } catch (Throwable throwable) { + log.warn("Fail to batchDeleteAppHostInfoById, try to delete one by one", throwable); + // 批量删除失败,尝试逐条删除 + for (ApplicationHostInfoDTO applicationHostInfoDTO : deleteList) { + try { + applicationHostDAO.deleteAppHostInfoById(dslContext, appId, applicationHostInfoDTO.getHostId()); + } catch (Throwable t) { + log.error("deleteHost fail:appId={},hostInfo={}", appId, + applicationHostInfoDTO, t); + deleteFailHostIds.add(applicationHostInfoDTO.getHostId()); + } + } + } watch.stop(); + if (!batchDeleted) { + watch.start("log deleteAppHostInfo"); + if (!deleteFailHostIds.isEmpty()) { + allAppDeleteFailHostIds.addAll(deleteFailHostIds); + log.warn(String.format("appId=%s,deleteFailHostIds.size=%d,deleteFailHostIds=%s", + appId, deleteFailHostIds.size(), String.join(",", + deleteFailHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); + } + watch.stop(); + } + log.debug("Performance:deleteHostsFromApp:appId={},{}", appId, watch.prettyPrint()); + } + + private boolean insertOrUpdateOneAppHost(Long appId, ApplicationHostInfoDTO infoDTO) { + try { + applicationHostDAO.insertAppHostInfo(dslContext, infoDTO); + } catch (DataAccessException e) { + String errorMessage = e.getMessage(); + if (errorMessage.contains("Duplicate entry") && errorMessage.contains("PRIMARY")) { + log.warn(String.format( + "insertHost fail, try to update:Duplicate entry:appId=%d," + + "insert hostInfo=%s, old " + + "hostInfo=%s", appId, infoDTO, + applicationHostDAO.getHostById(infoDTO.getHostId())), e); + try { + // 插入失败了就应当更新,以后来的数据为准 + applicationHostDAO.updateAppHostInfoByHostId(dslContext, appId, infoDTO); + } catch (Throwable t) { + log.error(String.format("update after insert fail:appId=%d,hostInfo=%s", appId, infoDTO), t); + return false; + } + } else { + log.error(String.format("insertHost fail:appId=%d,hostInfo=%s", appId, infoDTO), e); + return false; + } + } catch (Throwable t) { + log.error(String.format("insertHost fail:appId=%d,hostInfo=%s", appId, infoDTO), t); + return false; + } + return true; + } + + private void insertHostsToApp(Long appId, List insertList) { + StopWatch watch = new StopWatch(); // 插入主机 watch.start("insertAppHostInfo"); List insertFailHostIds = new ArrayList<>(); @@ -920,22 +948,7 @@ private int updateHosts(ApplicationInfoDTO applicationInfoDTO, } //批量插入失败,尝试逐条插入 for (ApplicationHostInfoDTO infoDTO : insertList) { - try { - applicationHostDAO.insertAppHostInfo(dslContext, infoDTO); - } catch (DataAccessException e) { - String errorMessage = e.getMessage(); - if (errorMessage.contains("Duplicate entry") && errorMessage.contains("PRIMARY")) { - log.warn("insertHost fail, try to update:Duplicate entry:appId={},insert hostInfo={}, old " + - "hostInfo={}", applicationInfoDTO.getId(), infoDTO, - applicationHostDAO.getHostById(infoDTO.getHostId()), e); - // 插入失败了就应当更新,以后来的数据为准 - applicationHostDAO.updateAppHostInfoByHostId(dslContext, appId, infoDTO); - } else { - log.error("insertHost fail:appId={},hostInfo={}", applicationInfoDTO.getId(), infoDTO, e); - insertFailHostIds.add(infoDTO.getHostId()); - } - } catch (Throwable t) { - log.error("insertHost fail:appId={},hostInfo={}", applicationInfoDTO.getId(), infoDTO, t); + if (!insertOrUpdateOneAppHost(appId, infoDTO)) { insertFailHostIds.add(infoDTO.getHostId()); } } @@ -946,51 +959,124 @@ private int updateHosts(ApplicationInfoDTO applicationInfoDTO, if (!insertFailHostIds.isEmpty()) { allAppInsertFailHostIds.addAll(insertFailHostIds); log.warn(String.format("appId=%s,insertFailHostIds.size=%d,insertFailHostIds=%s", - applicationInfoDTO.getId(), insertFailHostIds.size(), String.join(",", + appId, insertFailHostIds.size(), String.join(",", insertFailHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); } watch.stop(); } - watch.start("updateAppHostInfo"); - // 更新主机 - updateHostsToDB(applicationInfoDTO, updateList); + log.debug("Performance:insertHostsToApp:appId={},{}", appId, watch.prettyPrint()); + } + + private List computeInsertList( + Long appId, + Set localAppHostIds, + List applicationHostInfoDTOList + ) { + StopWatch watch = new StopWatch(); + List insertList = + applicationHostInfoDTOList.stream().filter(applicationHostInfoDTO -> + !localAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); + watch.start("log insertList"); + log.info(String.format("appId=%s,insertHostIds=%s", appId, String.join(",", + insertList.stream().map(ApplicationHostInfoDTO::getHostId).map(Object::toString) + .collect(Collectors.toSet())))); watch.stop(); - // 删除主机 - watch.start("deleteAppHostInfo"); - List deleteFailHostIds = new ArrayList<>(); - boolean batchDeleted = false; - try { - // 尝试批量删除 - if (!deleteList.isEmpty()) { - applicationHostDAO.batchDeleteAppHostInfoById(dslContext, appId, - deleteList.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toList())); - } - batchDeleted = true; - } catch (Throwable throwable) { - log.warn("Fail to batchDeleteAppHostInfoById, try to delete one by one", throwable); - // 批量删除失败,尝试逐条删除 - for (ApplicationHostInfoDTO applicationHostInfoDTO : deleteList) { - try { - applicationHostDAO.deleteAppHostInfoById(dslContext, appId, applicationHostInfoDTO.getHostId()); - } catch (Throwable t) { - log.error("deleteHost fail:appId={},hostInfo={}", applicationInfoDTO.getId(), - applicationHostInfoDTO, t); - deleteFailHostIds.add(applicationHostInfoDTO.getHostId()); - } - } + if (watch.getTotalTimeMillis() > 1000) { + log.warn("Write log too slow, {}", watch.prettyPrint()); } + return insertList; + } + + private List computeUpdateList( + Long appId, + Set localAppHostIds, + List applicationHostInfoDTOList + ) { + StopWatch watch = new StopWatch(); + List updateList = + applicationHostInfoDTOList.stream().filter(applicationHostInfoDTO -> + localAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); + watch.start("log updateList"); + log.info(String.format("appId=%s,updateHostIds=%s", appId, String.join(",", + updateList.stream().map(ApplicationHostInfoDTO::getHostId) + .map(Object::toString).collect(Collectors.toSet())))); watch.stop(); - if (!batchDeleted) { - watch.start("log deleteAppHostInfo"); - if (!deleteFailHostIds.isEmpty()) { - allAppDeleteFailHostIds.addAll(deleteFailHostIds); - log.warn(String.format("appId=%s,deleteFailHostIds.size=%d,deleteFailHostIds=%s", - applicationInfoDTO.getId(), deleteFailHostIds.size(), String.join(",", - deleteFailHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); - } - watch.stop(); + if (watch.getTotalTimeMillis() > 1000) { + log.warn("Write log too slow, {}", watch.prettyPrint()); + } + return updateList; + } + + private List computeDeleteList( + Long appId, + Set ccAppHostIds, + List localAppHosts + ) { + StopWatch watch = new StopWatch(); + List deleteList = + localAppHosts.stream().filter(applicationHostInfoDTO -> + !ccAppHostIds.contains(applicationHostInfoDTO.getHostId())).collect(Collectors.toList()); + watch.start("log deleteList"); + log.info(String.format("appId=%s,deleteHostIds=%s", appId, String.join(",", + deleteList.stream().map(ApplicationHostInfoDTO::getHostId).map(Object::toString) + .collect(Collectors.toSet())))); + watch.stop(); + if (watch.getTotalTimeMillis() > 1000) { + log.warn("Write log too slow, {}", watch.prettyPrint()); + } + return deleteList; + } + + private int refreshAppHosts(Long appId, + List applicationHostInfoDTOList) { + StopWatch watch = new StopWatch(); + //找出要删除的/更新的/新增的分别处理 + //对比库中数据与接口数据 + watch.start("listHostInfoByAppId"); + List localAppHosts = applicationHostDAO.listHostInfoByAppId(appId); + watch.stop(); + watch.start("mapTo ccAppHostIds"); + Set ccAppHostIds = + applicationHostInfoDTOList.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toSet()); + watch.stop(); + watch.start("mapTo localAppHostIds"); + Set localAppHostIds = + localAppHosts.stream().map(ApplicationHostInfoDTO::getHostId).collect(Collectors.toSet()); + watch.stop(); + watch.start("log ccAppHostIds"); + log.info(String.format("appId=%s,ccAppHostIds=%s", appId, String.join(",", + ccAppHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); + watch.stop(); + watch.start("log localAppHostIds"); + log.info(String.format("appId=%s,localAppHostIds=%s", appId, String.join(",", + localAppHostIds.stream().map(Object::toString).collect(Collectors.toSet())))); + watch.stop(); + watch.start("compute insertList"); + List insertList = computeInsertList(appId, localAppHostIds, applicationHostInfoDTOList); + watch.stop(); + watch.start("compute updateList"); + List updateList = computeUpdateList(appId, localAppHostIds, applicationHostInfoDTOList); + watch.stop(); + watch.start("compute deleteList"); + List deleteList = computeDeleteList(appId, ccAppHostIds, localAppHosts); + watch.stop(); + watch.start("deleteHostsFromApp"); + // 需要删除的主机 + deleteHostsFromApp(appId, deleteList); + watch.stop(); + watch.start("insertHostsToApp"); + // 需要新增的主机 + insertHostsToApp(appId, insertList); + watch.stop(); + watch.start("updateHostsInApp"); + // 需要更新的主机 + updateHostsInApp(appId, updateList); + watch.stop(); + if (watch.getTotalTimeMillis() > 10000) { + log.info("Performance:refreshAppHosts:appId={},{}", appId, watch.prettyPrint()); + } else { + log.debug("Performance:refreshAppHosts:appId={},{}", appId, watch.prettyPrint()); } - log.debug("Performance:UpdateHosts:appId={},{}", applicationInfoDTO.getId(), watch.toString()); return 1; } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/TaskPlanService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/TaskPlanService.java index 8dbc263b0a..472400fdea 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/TaskPlanService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/TaskPlanService.java @@ -50,7 +50,7 @@ public interface TaskPlanService { * @param templateId 模版 ID * @return 执行方案列表 */ - List listPageTaskPlansBasicInfo(Long appId, Long templateId); + List listTaskPlansBasicInfo(Long appId, Long templateId); /** * 查询执行方案基础信息列表,支持分页 diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/impl/TaskPlanServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/impl/TaskPlanServiceImpl.java index da8a258c22..3ecdb4f976 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/impl/TaskPlanServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/plan/impl/TaskPlanServiceImpl.java @@ -27,7 +27,7 @@ import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ParamErrorException; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.util.JobContextUtil; @@ -54,7 +54,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -115,7 +121,7 @@ public List listTaskPlanIds(Long templateId) { } @Override - public List listPageTaskPlansBasicInfo(Long appId, Long templateId) { + public List listTaskPlansBasicInfo(Long appId, Long templateId) { checkTemplateExist(appId, templateId); return taskPlanDAO.listTaskPlans(appId, templateId); } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TaskTemplateServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TaskTemplateServiceImpl.java index 258f86683c..392dd62282 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TaskTemplateServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TaskTemplateServiceImpl.java @@ -41,9 +41,18 @@ import com.tencent.bk.job.manage.dao.template.TaskTemplateDAO; import com.tencent.bk.job.manage.model.dto.ScriptDTO; import com.tencent.bk.job.manage.model.dto.TagDTO; -import com.tencent.bk.job.manage.model.dto.task.*; +import com.tencent.bk.job.manage.model.dto.task.TaskPlanInfoDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskScriptStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskStepDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskTemplateInfoDTO; +import com.tencent.bk.job.manage.model.dto.task.TaskVariableDTO; import com.tencent.bk.job.manage.model.web.vo.TagCountVO; -import com.tencent.bk.job.manage.service.*; +import com.tencent.bk.job.manage.service.AbstractTaskStepService; +import com.tencent.bk.job.manage.service.AbstractTaskVariableService; +import com.tencent.bk.job.manage.service.CronJobService; +import com.tencent.bk.job.manage.service.ScriptService; +import com.tencent.bk.job.manage.service.TagService; +import com.tencent.bk.job.manage.service.TaskFavoriteService; import com.tencent.bk.job.manage.service.plan.TaskPlanService; import com.tencent.bk.job.manage.service.template.TaskTemplateService; import lombok.extern.slf4j.Slf4j; @@ -55,7 +64,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -387,7 +403,7 @@ public void processTemplateTag(TaskTemplateInfoDTO taskTemplateInfo) { @Override @Transactional public Boolean deleteTaskTemplate(Long appId, Long templateId) { - List taskPlanInfoList = taskPlanService.listPageTaskPlansBasicInfo(appId, templateId); + List taskPlanInfoList = taskPlanService.listTaskPlansBasicInfo(appId, templateId); if (CollectionUtils.isNotEmpty(taskPlanInfoList)) { List taskPlanIdList = taskPlanInfoList.parallelStream().map(TaskPlanInfoDTO::getId).collect(Collectors.toList()); diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TemplateStatusUpdateService.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TemplateStatusUpdateService.java index e2db601345..fe5c3547ec 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TemplateStatusUpdateService.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/template/impl/TemplateStatusUpdateService.java @@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.*; import org.jooq.generated.tables.ScriptVersion; import org.jooq.generated.tables.TaskTemplateStepScript; diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/task/EsbUserInfoUpdateTask.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/task/EsbUserInfoUpdateTask.java index 1e7e9cce21..5caf17b2c1 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/task/EsbUserInfoUpdateTask.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/task/EsbUserInfoUpdateTask.java @@ -34,7 +34,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import lombok.var; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jooq.DSLContext; import org.jooq.impl.DSL; import org.slf4j.Logger; diff --git a/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/common/util/PathMatchTest.java b/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/common/util/PathMatchTest.java new file mode 100644 index 0000000000..c30b254216 --- /dev/null +++ b/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/common/util/PathMatchTest.java @@ -0,0 +1,26 @@ +package com.tencent.bk.job.manage.common.util; + +import org.junit.jupiter.api.Test; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PathMatchTest { + + @Test + public void testPathMatch() { + PathMatcher pathMatcher = new AntPathMatcher(); + // 正例 + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule/info/aa//")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule/info/aa/")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule/info/aa")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule//info")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule/info")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule/")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web//dangerousRule/")); + assertThat(pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRule")); + // 负例 + assertThat(!pathMatcher.match("/web/dangerousRule/**", "/web/dangerousRulf")); + } +} diff --git a/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImplTest.java b/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImplTest.java index 317976583f..c58d87cb24 100644 --- a/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImplTest.java +++ b/src/backend/job-manage/service-job-manage/src/test/java/com/tencent/bk/job/manage/service/impl/ScriptServiceImplTest.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.manage.service.impl; import com.tencent.bk.job.common.exception.ServiceException; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.BaseSearchCondition; import com.tencent.bk.job.common.model.PageData; diff --git a/src/backend/job-ticket/api-job-ticket-pojo/build.gradle b/src/backend/job-ticket/api-job-ticket-pojo/build.gradle index 6ac18def6f..35cf2dacdc 100644 --- a/src/backend/job-ticket/api-job-ticket-pojo/build.gradle +++ b/src/backend/job-ticket/api-job-ticket-pojo/build.gradle @@ -23,7 +23,7 @@ */ dependencies { - compile project(':commons:common') + api project(':commons:common') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation 'com.fasterxml.jackson.core:jackson-core' diff --git a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/consts/CredentialTypeEnum.java b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/consts/CredentialTypeEnum.java index d0caf0cad3..1d37b6b9ba 100644 --- a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/consts/CredentialTypeEnum.java +++ b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/consts/CredentialTypeEnum.java @@ -31,10 +31,22 @@ public enum CredentialTypeEnum { SECRET_KEY(4, "单一SecretKey"); private final Integer value; - private final String name; + private final String description; - CredentialTypeEnum(Integer type, String name) { + public static String getAllNameStr() { + StringBuilder sb = new StringBuilder(); + CredentialTypeEnum[] values = CredentialTypeEnum.values(); + for (int i = 0; i < values.length; i++) { + sb.append(values[i].name()); + if (i < values.length - 1) { + sb.append(","); + } + } + return sb.toString(); + } + + CredentialTypeEnum(Integer type, String description) { this.value = type; - this.name = name; + this.description = description; } } diff --git a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredentialDTO.java b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredential.java similarity index 98% rename from src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredentialDTO.java rename to src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredential.java index 875c725fe7..8e3c71a321 100644 --- a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredentialDTO.java +++ b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/credential/CommonCredential.java @@ -33,7 +33,7 @@ @AllArgsConstructor @Data @EqualsAndHashCode -public class CommonCredentialDTO { +public class CommonCredential { String accessKey; String secretKey; String username; diff --git a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceBasicCredentialDTO.java b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceBasicCredentialDTO.java new file mode 100644 index 0000000000..cd21b182cb --- /dev/null +++ b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceBasicCredentialDTO.java @@ -0,0 +1,43 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.ticket.model.inner.resp; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@ApiModel("凭据基本信息") +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ServiceBasicCredentialDTO { + /** + * 主键Id + */ + @ApiModelProperty("主键Id") + private String id; +} diff --git a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceCredentialDTO.java b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceCredentialDTO.java index 081a6f877f..1fa62554f3 100644 --- a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceCredentialDTO.java +++ b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/inner/resp/ServiceCredentialDTO.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.ticket.model.inner.resp; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -52,8 +53,8 @@ public class ServiceCredentialDTO { @ApiModelProperty("类型") private String type; /** - * 值 + * 凭据 */ - @ApiModelProperty("值") - private String value; + @ApiModelProperty("凭据") + private CommonCredential credential; } diff --git a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/web/req/CredentialCreateUpdateReq.java b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/web/req/CredentialCreateUpdateReq.java index e116e22d86..b5f0dcffa3 100644 --- a/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/web/req/CredentialCreateUpdateReq.java +++ b/src/backend/job-ticket/api-job-ticket-pojo/src/main/java/com/tencent/bk/job/ticket/model/web/req/CredentialCreateUpdateReq.java @@ -24,20 +24,19 @@ package com.tencent.bk.job.ticket.model.web.req; -import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.ticket.consts.CredentialTypeEnum; -import com.tencent.bk.job.ticket.model.credential.AccessKeySecretKey; -import com.tencent.bk.job.ticket.model.credential.Password; -import com.tencent.bk.job.ticket.model.credential.SecretKey; -import com.tencent.bk.job.ticket.model.credential.UsernamePassword; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.*; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.APP_ID_SECRET_KEY; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.PASSWORD; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.SECRET_KEY; +import static com.tencent.bk.job.ticket.consts.CredentialTypeEnum.USERNAME_PASSWORD; @Data -@ApiModel("凭据创建请求") +@ApiModel("凭据创建/更新请求") public class CredentialCreateUpdateReq { @ApiModelProperty(value = "ID,更新凭据的时候需要传入,新建时不需要", required = false) @@ -73,21 +72,22 @@ public class CredentialCreateUpdateReq { @ApiModelProperty("值3") private String value3; - public String getSerializedValue() { + public CommonCredential toCommonCredential() { + CommonCredential credential = new CommonCredential(); + credential.setType(type.name()); if (type == SECRET_KEY) { - SecretKey secretKey = new SecretKey(value1); - return JsonUtils.toJson(secretKey); + credential.setSecretKey(value1); } else if (type == PASSWORD) { - Password password = new Password(value1); - return JsonUtils.toJson(password); + credential.setPassword(value1); } else if (type == APP_ID_SECRET_KEY) { - AccessKeySecretKey accessKeySecretKey = new AccessKeySecretKey(value1, value2); - return JsonUtils.toJson(accessKeySecretKey); + credential.setAccessKey(value1); + credential.setSecretKey(value2); } else if (type == USERNAME_PASSWORD) { - UsernamePassword usernamePassword = new UsernamePassword(value1, value2); - return JsonUtils.toJson(usernamePassword); + credential.setUsername(value1); + credential.setPassword(value2); } else { return null; } + return credential; } } diff --git a/src/backend/job-ticket/api-job-ticket/build.gradle b/src/backend/job-ticket/api-job-ticket/build.gradle index d656e92f79..c28f57beeb 100644 --- a/src/backend/job-ticket/api-job-ticket/build.gradle +++ b/src/backend/job-ticket/api-job-ticket/build.gradle @@ -23,9 +23,10 @@ */ dependencies { - compile project(':commons:common') - compile project(':commons:common-iam') - compile project(':job-ticket:api-job-ticket-pojo') + api project(':commons:common') + api project(':commons:common-iam') + api project(':commons:common-web') + api project(':job-ticket:api-job-ticket-pojo') implementation "org.springframework:spring-web" implementation "javax.ws.rs:javax.ws.rs-api" implementation 'com.fasterxml.jackson.core:jackson-core' diff --git a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResource.java b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResource.java index adf6c9b3ef..a5b0c6fb21 100644 --- a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResource.java +++ b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResource.java @@ -24,19 +24,28 @@ package com.tencent.bk.job.ticket.api.inner; +import com.tencent.bk.job.common.annotation.InternalAPI; import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.common.web.model.InnerServiceResponse; +import com.tencent.bk.job.ticket.model.inner.resp.ServiceBasicCredentialDTO; import com.tencent.bk.job.ticket.model.inner.resp.ServiceCredentialDTO; +import com.tencent.bk.job.ticket.model.web.req.CredentialCreateUpdateReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-ticket:service:Credential"}) @RequestMapping("/service/credentials/app/{appId}") @RestController +@InternalAPI public interface ServiceCredentialResource { @ApiOperation(value = "获取凭据详情", produces = "application/json") @@ -48,4 +57,30 @@ ServiceResponse getCredentialById( @PathVariable("id") String id ); + + @ApiOperation(value = "新建凭据", produces = "application/json") + @PostMapping("/create") + InnerServiceResponse createCredential( + @ApiParam(value = "用户名,网关自动传入", required = true) + @RequestHeader("username") + String username, + @ApiParam(value = "业务ID", required = true) + @PathVariable("appId") Long appId, + @ApiParam(value = "创建或更新请求体", required = true) + @RequestBody + CredentialCreateUpdateReq createUpdateReq + ); + + @ApiOperation(value = "更新凭据", produces = "application/json") + @PutMapping("/update") + InnerServiceResponse updateCredential( + @ApiParam(value = "用户名,网关自动传入", required = true) + @RequestHeader("username") + String username, + @ApiParam(value = "业务ID", required = true) + @PathVariable("appId") Long appId, + @ApiParam(value = "创建或更新请求体", required = true) + @RequestBody + CredentialCreateUpdateReq createUpdateReq + ); } diff --git a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebCredentialResource.java b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebCredentialResource.java index 60157e3333..de4c044582 100644 --- a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebCredentialResource.java +++ b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebCredentialResource.java @@ -24,6 +24,7 @@ package com.tencent.bk.job.ticket.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.PageData; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.ticket.model.web.req.CredentialCreateUpdateReq; @@ -31,11 +32,20 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-ticket:web:Credential"}) @RequestMapping("/web/credentials/app/{appId}") @RestController +@WebAPI public interface WebCredentialResource { @ApiOperation(value = "获取凭据列表", produces = "application/json") diff --git a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResource.java b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResource.java index d541fc0d52..87c4f46bce 100644 --- a/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResource.java +++ b/src/backend/job-ticket/api-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResource.java @@ -24,17 +24,25 @@ package com.tencent.bk.job.ticket.api.web; +import com.tencent.bk.job.common.annotation.WebAPI; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.model.permission.AuthResultVO; import com.tencent.bk.job.ticket.model.web.req.OperationPermissionReq; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Api(tags = {"job-ticket:web:Permission"}) @RequestMapping("/web/permission/") @RestController +@WebAPI public interface WebPermissionResource { /** * 获取权限申请URL diff --git a/src/backend/job-ticket/boot-job-ticket/build.gradle b/src/backend/job-ticket/boot-job-ticket/build.gradle index 400d4d2330..ee0ebe5651 100644 --- a/src/backend/job-ticket/boot-job-ticket/build.gradle +++ b/src/backend/job-ticket/boot-job-ticket/build.gradle @@ -25,17 +25,18 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' dependencies { - compile project(":job-ticket:service-job-ticket") + api project(":job-ticket:service-job-ticket") implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' implementation 'org.springframework.cloud:spring-cloud-starter-config' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' runtimeOnly('mysql:mysql-connector-java') } springBoot { - mainClassName = "com.tencent.bk.job.ticket.JobTicketBootApplication" + mainClass = "com.tencent.bk.job.ticket.JobTicketBootApplication" buildInfo() } task renameArtifacts(type: Copy) { diff --git a/src/backend/job-ticket/boot-job-ticket/src/main/java/com/tencent/bk/job/ticket/config/I18nConfig.java b/src/backend/job-ticket/boot-job-ticket/src/main/java/com/tencent/bk/job/ticket/config/I18nConfig.java deleted file mode 100644 index 18d16e2eb7..0000000000 --- a/src/backend/job-ticket/boot-job-ticket/src/main/java/com/tencent/bk/job/ticket/config/I18nConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. - * - * License for BK-JOB蓝鲸智云作业平台: - * -------------------------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -package com.tencent.bk.job.ticket.config; - -import com.tencent.bk.job.common.i18n.config.MultiReloadableResourceBundleMessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; - -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -@Configuration -public class I18nConfig { - - @Bean("localeResolver") - public LocaleResolver localeResolver() { - CookieLocaleResolver resolver = new CookieLocaleResolver(); - resolver.setCookieName("blueking_language"); - resolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); - return resolver; - } - - @Bean("messageSource") - public ReloadableResourceBundleMessageSource messageSource() { - MultiReloadableResourceBundleMessageSource messageSource = new MultiReloadableResourceBundleMessageSource(); - messageSource.addBasenames("classpath:i18n/message", "classpath*:i18n/exception/message", "classpath*:i18n" + - "/common/message"); - messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); - messageSource.setUseCodeAsDefaultMessage(true); - return messageSource; - } - - @Bean("localeChangeInterceptor") - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor(); - interceptor.setParamName("blueking_language"); - return interceptor; - } - -} diff --git a/src/backend/job-ticket/build.gradle b/src/backend/job-ticket/build.gradle index 44130e7cc8..d3d31cb523 100644 --- a/src/backend/job-ticket/build.gradle +++ b/src/backend/job-ticket/build.gradle @@ -25,6 +25,8 @@ ext { if (System.getProperty("jobTicketVersion")) { set("jobTicketVersion", System.getProperty("jobTicketVersion")) + } else if (System.getProperty("version")) { + set("jobTicketVersion", System.getProperty("version")) } else { set("jobTicketVersion", "1.0.0") } @@ -33,7 +35,7 @@ version "${jobTicketVersion}" subprojects { version "${jobTicketVersion}" dependencies { - compile("org.springframework.boot:spring-boot-autoconfigure") + api("org.springframework.boot:spring-boot-autoconfigure") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -42,7 +44,7 @@ subprojects { implementation 'io.springfox:springfox-swagger2' implementation 'io.springfox:springfox-swagger-ui' implementation "org.hibernate.validator:hibernate-validator" - testCompile("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation "org.junit.jupiter:junit-jupiter" } } diff --git a/src/backend/job-ticket/service-job-ticket/build.gradle b/src/backend/job-ticket/service-job-ticket/build.gradle index 0673355116..2b243ffaa5 100644 --- a/src/backend/job-ticket/service-job-ticket/build.gradle +++ b/src/backend/job-ticket/service-job-ticket/build.gradle @@ -23,10 +23,10 @@ */ dependencies { - compile project(":commons:common-web") - compile project(":job-manage:api-job-manage") - compile project(":job-ticket:api-job-ticket") - compile project(":job-ticket:model-job-ticket") + api project(":commons:common-web") + api project(":job-manage:api-job-manage") + api project(":job-ticket:api-job-ticket") + api project(":job-ticket:model-job-ticket") implementation group: 'org.apache.httpcomponents', name: 'httpclient' implementation "org.springframework.boot:spring-boot-starter-web" implementation('org.springframework.cloud:spring-cloud-starter-openfeign') diff --git a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResourceImpl.java b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResourceImpl.java index 5163856bc6..903622bb9f 100644 --- a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResourceImpl.java +++ b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/inner/ServiceCredentialResourceImpl.java @@ -24,10 +24,19 @@ package com.tencent.bk.job.ticket.api.inner; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AuthService; import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.common.web.model.InnerServiceResponse; +import com.tencent.bk.job.ticket.model.inner.resp.ServiceBasicCredentialDTO; import com.tencent.bk.job.ticket.model.inner.resp.ServiceCredentialDTO; +import com.tencent.bk.job.ticket.model.web.req.CredentialCreateUpdateReq; import com.tencent.bk.job.ticket.service.CredentialService; +import com.tencent.bk.sdk.iam.util.PathBuilder; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -36,10 +45,12 @@ @Slf4j public class ServiceCredentialResourceImpl implements ServiceCredentialResource { + private final AuthService authService; private final CredentialService credentialService; @Autowired - public ServiceCredentialResourceImpl(CredentialService credentialService) { + public ServiceCredentialResourceImpl(AuthService authService, CredentialService credentialService) { + this.authService = authService; this.credentialService = credentialService; } @@ -48,4 +59,52 @@ public ServiceResponse getCredentialById(Long appId, Strin ServiceCredentialDTO serviceCredentialDTO = credentialService.getServiceCredentialById(appId, id); return ServiceResponse.buildSuccessResp(serviceCredentialDTO); } + + @Override + public InnerServiceResponse createCredential( + String username, + Long appId, + CredentialCreateUpdateReq createUpdateReq + ) { + return saveCredential(username, appId, createUpdateReq); + } + + @Override + public InnerServiceResponse updateCredential( + String username, + Long appId, + CredentialCreateUpdateReq createUpdateReq + ) { + return saveCredential(username, appId, createUpdateReq); + } + + private InnerServiceResponse saveCredential( + String username, + Long appId, + CredentialCreateUpdateReq createUpdateReq + ) { + AuthResult authResult = null; + if (StringUtils.isBlank(createUpdateReq.getId())) { + authResult = checkCreateTicketPermission(username, appId); + } else { + authResult = checkManageTicketPermission(username, appId, createUpdateReq.getId()); + } + if (!authResult.isPass()) { + return InnerServiceResponse.buildAuthFailResp(authResult); + } + String credentialId = credentialService.saveCredential(username, appId, createUpdateReq); + return InnerServiceResponse.buildSuccessResp(new ServiceBasicCredentialDTO(credentialId)); + } + + public AuthResult checkCreateTicketPermission(String username, Long appId) { + // 需要拥有在业务下创建凭证的权限 + return authService.auth(true, username, ActionId.CREATE_TICKET, ResourceTypeEnum.BUSINESS, + appId.toString(), null); + } + + public AuthResult checkManageTicketPermission(String username, Long appId, String credentialId) { + // 需要拥有在业务下管理某个具体凭证的权限 + return authService.auth(true, username, ActionId.MANAGE_TICKET, ResourceTypeEnum.TICKET, + credentialId, PathBuilder.newBuilder(ResourceTypeEnum.BUSINESS.getId(), appId.toString()).build()); + } } diff --git a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResourceImpl.java b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResourceImpl.java index ed28bf5120..961739983e 100644 --- a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResourceImpl.java +++ b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/api/web/WebPermissionResourceImpl.java @@ -25,7 +25,7 @@ package com.tencent.bk.job.ticket.api.web; import com.tencent.bk.job.common.constant.ErrorCode; -import com.tencent.bk.job.common.i18n.MessageI18nService; +import com.tencent.bk.job.common.i18n.service.MessageI18nService; import com.tencent.bk.job.common.iam.constant.ActionId; import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; import com.tencent.bk.job.common.iam.service.WebAuthService; diff --git a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/dao/impl/CredentialDAOImpl.java b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/dao/impl/CredentialDAOImpl.java index 5ab117b90d..cef7723fbc 100644 --- a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/dao/impl/CredentialDAOImpl.java +++ b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/dao/impl/CredentialDAOImpl.java @@ -24,16 +24,23 @@ package com.tencent.bk.job.ticket.dao.impl; +import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.util.Base64Util; import com.tencent.bk.job.common.util.JobUUID; import com.tencent.bk.job.common.util.crypto.AESUtils; +import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.ticket.config.JobTicketConfig; import com.tencent.bk.job.ticket.dao.CredentialDAO; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import com.tencent.bk.job.ticket.model.dto.CredentialDTO; import io.micrometer.core.instrument.util.StringUtils; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.jooq.*; +import org.jooq.Condition; +import org.jooq.DSLContext; +import org.jooq.Record10; +import org.jooq.Result; +import org.jooq.UpdateConditionStep; import org.jooq.conf.ParamType; import org.jooq.generated.tables.Credential; import org.jooq.generated.tables.records.CredentialRecord; @@ -80,8 +87,10 @@ public String insertCredential(DSLContext dslContext, CredentialDTO credentialDT credentialDTO.getName(), credentialDTO.getType(), credentialDTO.getDescription(), - AESUtils.encryptToBase64EncodedCipherText(credentialDTO.getValue(), - jobTicketConfig.getEncryptPassword()), + AESUtils.encryptToBase64EncodedCipherText( + JsonUtils.toJson(credentialDTO.getCredential()), + jobTicketConfig.getEncryptPassword() + ), credentialDTO.getCreator(), credentialDTO.getCreateTime(), credentialDTO.getLastModifyUser(), @@ -107,7 +116,8 @@ public String updateCredentialById(DSLContext dslContext, CredentialDTO credenti .set(defaultTable.NAME, credentialDTO.getName()) .set(defaultTable.TYPE, credentialDTO.getType()) .set(defaultTable.DESCRIPTION, credentialDTO.getDescription()) - .set(defaultTable.VALUE, AESUtils.encryptToBase64EncodedCipherText(credentialDTO.getValue(), + .set(defaultTable.VALUE, AESUtils.encryptToBase64EncodedCipherText( + JsonUtils.toJson(credentialDTO.getCredential()), jobTicketConfig.getEncryptPassword())) .set(defaultTable.LAST_MODIFY_USER, credentialDTO.getLastModifyUser()) .set(defaultTable.LAST_MODIFY_TIME, System.currentTimeMillis()) @@ -267,8 +277,8 @@ private Integer countCredentialByConditions(DSLContext dslContext, List record) { + private CredentialDTO convertRecordToDto( + Record10 record) { try { return new CredentialDTO( record.get(defaultTable.ID), @@ -276,8 +286,12 @@ private CredentialDTO convertRecordToDto(Record10() { + }), record.get(defaultTable.CREATOR), record.get(defaultTable.CREATE_TIME), record.get(defaultTable.LAST_MODIFY_USER), diff --git a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/model/dto/CredentialDTO.java b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/model/dto/CredentialDTO.java index b496cbcb5e..cc9a623c0b 100644 --- a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/model/dto/CredentialDTO.java +++ b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/model/dto/CredentialDTO.java @@ -24,12 +24,8 @@ package com.tencent.bk.job.ticket.model.dto; -import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.ticket.consts.CredentialTypeEnum; -import com.tencent.bk.job.ticket.model.credential.AccessKeySecretKey; -import com.tencent.bk.job.ticket.model.credential.Password; -import com.tencent.bk.job.ticket.model.credential.SecretKey; -import com.tencent.bk.job.ticket.model.credential.UsernamePassword; +import com.tencent.bk.job.ticket.model.credential.CommonCredential; import com.tencent.bk.job.ticket.model.inner.resp.ServiceCredentialDTO; import com.tencent.bk.job.ticket.model.web.resp.CredentialVO; import lombok.AllArgsConstructor; @@ -63,7 +59,7 @@ public class CredentialDTO { /** * 值JSON串 */ - private String value; + private CommonCredential credential; /** * 创建人 */ @@ -91,11 +87,9 @@ public CredentialVO toVO() { credentialVO.setValue2("******"); credentialVO.setValue3("******"); if (type.equals(CredentialTypeEnum.USERNAME_PASSWORD.name())) { - UsernamePassword usernamePassword = JsonUtils.fromJson(value, UsernamePassword.class); - credentialVO.setValue1(usernamePassword.getUsername()); + credentialVO.setValue1(credential.getUsername()); } else if (type.equals(CredentialTypeEnum.APP_ID_SECRET_KEY.name())) { - AccessKeySecretKey accessKeySecretKey = JsonUtils.fromJson(value, AccessKeySecretKey.class); - credentialVO.setValue1(accessKeySecretKey.getAccessKey()); + credentialVO.setValue1(credential.getAccessKey()); } credentialVO.setCreator(creator); credentialVO.setCreateTime(createTime); @@ -110,23 +104,19 @@ public ServiceCredentialDTO toServiceCredentialDTO() { serviceCredentialDTO.setAppId(appId); serviceCredentialDTO.setName(name); serviceCredentialDTO.setType(type); - serviceCredentialDTO.setValue(value); + serviceCredentialDTO.setCredential(credential); return serviceCredentialDTO; } public String getFirstValue() { if (type.equals(CredentialTypeEnum.USERNAME_PASSWORD.name())) { - UsernamePassword usernamePassword = JsonUtils.fromJson(this.value, UsernamePassword.class); - return usernamePassword.getUsername(); + return credential.getUsername(); } else if (type.equals(CredentialTypeEnum.PASSWORD.name())) { - Password password = JsonUtils.fromJson(this.value, Password.class); - return password.getPassword(); + return credential.getPassword(); } else if (type.equals(CredentialTypeEnum.SECRET_KEY.name())) { - SecretKey secretKey = JsonUtils.fromJson(this.value, SecretKey.class); - return secretKey.getSecretKey(); + return credential.getSecretKey(); } else if (type.equals(CredentialTypeEnum.APP_ID_SECRET_KEY.name())) { - AccessKeySecretKey accessKeySecretKey = JsonUtils.fromJson(this.value, AccessKeySecretKey.class); - return accessKeySecretKey.getAccessKey(); + return credential.getAccessKey(); } else { throw new RuntimeException("Not support type:" + type); } @@ -134,21 +124,13 @@ public String getFirstValue() { public void setFirstValue(String val) { if (type.equals(CredentialTypeEnum.USERNAME_PASSWORD.name())) { - UsernamePassword usernamePassword = JsonUtils.fromJson(this.value, UsernamePassword.class); - usernamePassword.setUsername(val); - this.value = JsonUtils.toJson(usernamePassword); + this.credential.setUsername(val); } else if (type.equals(CredentialTypeEnum.PASSWORD.name())) { - Password password = JsonUtils.fromJson(this.value, Password.class); - password.setPassword(val); - this.value = JsonUtils.toJson(password); + this.credential.setPassword(val); } else if (type.equals(CredentialTypeEnum.SECRET_KEY.name())) { - SecretKey secretKey = JsonUtils.fromJson(this.value, SecretKey.class); - secretKey.setSecretKey(val); - this.value = JsonUtils.toJson(secretKey); + this.credential.setSecretKey(val); } else if (type.equals(CredentialTypeEnum.APP_ID_SECRET_KEY.name())) { - AccessKeySecretKey accessKeySecretKey = JsonUtils.fromJson(this.value, AccessKeySecretKey.class); - accessKeySecretKey.setAccessKey(val); - this.value = JsonUtils.toJson(accessKeySecretKey); + this.credential.setAccessKey(val); } else { throw new RuntimeException("Not support type:" + type); } @@ -156,15 +138,13 @@ public void setFirstValue(String val) { public String getSecondValue() { if (type.equals(CredentialTypeEnum.USERNAME_PASSWORD.name())) { - UsernamePassword usernamePassword = JsonUtils.fromJson(this.value, UsernamePassword.class); - return usernamePassword.getPassword(); + return credential.getPassword(); } else if (type.equals(CredentialTypeEnum.PASSWORD.name())) { return null; } else if (type.equals(CredentialTypeEnum.SECRET_KEY.name())) { return null; } else if (type.equals(CredentialTypeEnum.APP_ID_SECRET_KEY.name())) { - AccessKeySecretKey accessKeySecretKey = JsonUtils.fromJson(this.value, AccessKeySecretKey.class); - return accessKeySecretKey.getSecretKey(); + return credential.getSecretKey(); } else { throw new RuntimeException("Not support type:" + type); } @@ -172,13 +152,9 @@ public String getSecondValue() { public void setSecondValue(String val) { if (type.equals(CredentialTypeEnum.USERNAME_PASSWORD.name())) { - UsernamePassword usernamePassword = JsonUtils.fromJson(this.value, UsernamePassword.class); - usernamePassword.setPassword(val); - this.value = JsonUtils.toJson(usernamePassword); + this.credential.setPassword(val); } else if (type.equals(CredentialTypeEnum.APP_ID_SECRET_KEY.name())) { - AccessKeySecretKey accessKeySecretKey = JsonUtils.fromJson(this.value, AccessKeySecretKey.class); - accessKeySecretKey.setSecretKey(val); - this.value = JsonUtils.toJson(accessKeySecretKey); + this.credential.setSecretKey(val); } else if (type.equals(CredentialTypeEnum.PASSWORD.name())) { } else if (type.equals(CredentialTypeEnum.SECRET_KEY.name())) { } else { diff --git a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/service/impl/CredentialServiceImpl.java b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/service/impl/CredentialServiceImpl.java index 097890cdb3..4e7747926b 100644 --- a/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/service/impl/CredentialServiceImpl.java +++ b/src/backend/job-ticket/service-job-ticket/src/main/java/com/tencent/bk/job/ticket/service/impl/CredentialServiceImpl.java @@ -153,7 +153,7 @@ private CredentialDTO buildCredentialDTO(String username, Long appId, Credential credentialDTO.setName(createUpdateReq.getName()); credentialDTO.setType(createUpdateReq.getType().name()); credentialDTO.setDescription(createUpdateReq.getDescription()); - credentialDTO.setValue(createUpdateReq.getSerializedValue()); + credentialDTO.setCredential(createUpdateReq.toCommonCredential()); credentialDTO.setLastModifyUser(username); credentialDTO.setLastModifyTime(System.currentTimeMillis()); return credentialDTO; diff --git a/src/backend/task_gen_jooq.gradle b/src/backend/task_gen_jooq.gradle index ea981b9527..1313d7aaa2 100644 --- a/src/backend/task_gen_jooq.gradle +++ b/src/backend/task_gen_jooq.gradle @@ -24,7 +24,7 @@ apply plugin: 'nu.studer.jooq' dependencies { - compile "org.jooq:jooq" + api "org.jooq:jooq" jooqRuntime "mysql:mysql-connector-java" } diff --git a/src/backend/task_job_package.gradle b/src/backend/task_job_package.gradle index 0b06c6769e..9c28cad2fb 100644 --- a/src/backend/task_job_package.gradle +++ b/src/backend/task_job_package.gradle @@ -23,7 +23,7 @@ */ import com.tencent.bk.gradle.tasks.GenCompleteDependJarListAndRemoveInfectedJarsTask -import com.tencent.bk.gradle.tasks.ReplaceCETextTask +import com.tencent.bk.gradle.tasks.ReplaceEditionTextTask task copyToRelease(type: Copy) { from("build/libs") { include("**/job-*.jar") @@ -36,16 +36,16 @@ task copyToRelease(type: Copy) { copyToRelease.dependsOn assemble build.dependsOn copyToRelease -task replaceCEConfig(type: ReplaceCETextTask) { +task replaceEEConfig(type: ReplaceEditionTextTask) { group = "build" - description = "社区版打包时替换classpath下的ee配置为ce" + description = "企业版打包时替换classpath下的ce配置为ee" processResourcesOutputFiles = fileTree(processResources.destinationDir) - srcStr = "edition:\\s*ee" - targetStr = "edition: ce" + srcStr = "edition:\\s*ce" + targetStr = "edition: ee" process ".*.yml" } -replaceCEConfig.dependsOn processResources -classes.dependsOn replaceCEConfig +replaceEEConfig.dependsOn processResources +classes.dependsOn replaceEEConfig task postProcessRelease(type: GenCompleteDependJarListAndRemoveInfectedJarsTask) { group = "build" diff --git a/src/backend/upgrader/build.gradle b/src/backend/upgrader/build.gradle index 45cd21d468..06c209f377 100644 --- a/src/backend/upgrader/build.gradle +++ b/src/backend/upgrader/build.gradle @@ -22,20 +22,23 @@ * IN THE SOFTWARE. */ plugins { - id "com.github.johnrengelman.shadow" version "5.1.0" + id "com.github.johnrengelman.shadow" version "7.1.1" } ext { if (System.getProperty("jobVersion")) { set("jobVersion", System.getProperty("jobVersion")) + } else if (System.getProperty("version")) { + set("jobVersion", System.getProperty("version")) } else { set("jobVersion", "1.0.0") } } version "${jobVersion}" dependencies { - compile project(":commons:common") - compile project(":commons:common-iam") - compile project(":commons:esb-sdk") + api project(":commons:common") + api project(":commons:common-iam") + api project(":commons:common-utils") + api project(":commons:esb-sdk") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'ch.qos.logback:logback-core' @@ -45,7 +48,9 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-annotations' implementation group: 'org.apache.httpcomponents', name: 'httpclient' implementation 'org.reflections:reflections' + implementation("org.apache.logging.log4j:log4j-core:2.17.0") } + apply plugin: "com.github.johnrengelman.shadow" apply plugin: "application" diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/Upgrader.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/Upgrader.java index 84905af27d..d352fb259f 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/Upgrader.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/Upgrader.java @@ -25,9 +25,14 @@ package com.tencent.bk.job.upgrader; import com.tencent.bk.job.common.util.CompareUtil; +import com.tencent.bk.job.common.util.StringUtil; import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; +import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; import com.tencent.bk.job.upgrader.anotation.UpgradeTask; +import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; import com.tencent.bk.job.upgrader.task.IUpgradeTask; +import com.tencent.bk.job.upgrader.task.param.AbstractTaskParam; +import com.tencent.bk.job.upgrader.utils.MessageBeatTask; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Triple; @@ -36,13 +41,20 @@ import org.reflections.scanners.TypeAnnotationsScanner; import java.io.BufferedReader; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.Constructor; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; +import java.util.Scanner; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; @Slf4j public class Upgrader { @@ -52,22 +64,40 @@ public Upgrader() { public static void usage() { log.info("===========================================Usage=============================================="); - log.info("Usage: java -Dconfig.file=/path/to/config/file -jar upgrader-[x.x.x.x].jar [fromVersion] " + - "[toVersion] [executeTime] "); - log.info("fromVersion is the current version of Job, example:3.1.4.3"); - log.info("toVersion is the target version of Job to upgrade, example:3.2.7.3"); - log.info("executeTime is the time point to execute upgrade tasks, which value can be:BEFORE_UPDATE_JOB/AFTER_UPDATE_JOB, " + - "BEFORE_UPDATE_JOB means executing upgrade tasks before upgrading job service jar, while AFTER_UPDATE_JOB means executing upgrade tasks after upgrading job service jar"); - log.info("Example: java -Dconfig.file=/data/bkee/job/upgrader.properties -jar upgrader-1.0.0.0.jar 3.1.4.3 3.2.7.3 " + + log.info("Usage: use command `java -Dfile.encoding=utf8 -Djob.log.dir=path/to/log/dir " + + "-Dconfig.file=/path/to/config/file " + + "-jar upgrader-[x.x.x.x].jar [fromVersion] " + + "[toVersion] [executeTime]` to start the upgrader, " + + "then enter the specific parameters related to the " + + "specific upgrade tasks according to the command line prompt"); + log.info("/path/to/log/dir is the path to log dir, usually set to ${BK_HOME}/logs/job"); + log.info("/path/to/config/file is the path to config file, which is generated by upgrade script, " + + "usually can be ${BK_HOME}/etc/job/upgrader/upgrader.properties"); + log.info("fromVersion is the current version of Job, example:3.2.7.3"); + log.info("toVersion is the target version of Job to upgrade, example:3.3.4.0"); + log.info("executeTime is the time point to execute upgrade tasks, " + + "which value can be:BEFORE_UPDATE_JOB/AFTER_UPDATE_JOB, " + + "BEFORE_UPDATE_JOB means executing upgrade tasks before upgrading job service jar, " + + "while AFTER_UPDATE_JOB means executing upgrade tasks after upgrading job service jar"); + log.info("Example: java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job" + + " -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties " + + "-jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 " + "BEFORE_UPDATE_JOB"); log.info("==========================================用法说明============================================="); - log.info("工具用法: java -Dconfig.file=/path/to/config/file -jar upgrader-[x.x.x.x].jar [fromVersion] " + - "[toVersion] [executeTime] "); - log.info("fromVersion为当前作业平台版本,如3.1.4.3"); - log.info("toVersion为目标作业平台版本,如3.2.7.3"); + log.info("工具用法: 使用命令`java -Dfile.encoding=utf8 -Djob.log.dir=path/to/log/dir" + + " -Dconfig.file=/path/to/config/file" + + " -jar upgrader-[x.x.x.x].jar [fromVersion] " + + "[toVersion] [executeTime]` 启动工具,再根据命令行提示输入与具体版本升级任务相关的特定参数"); + log.info("/path/to/log/dir用于指定工具日志保存路径,通常为${BK_HOME}/logs/job"); + log.info("/path/to/config/file用于指定工具读取的配置文件,该配置文件由部署脚本自动渲染生成," + + "路径为${BK_HOME}/etc/job/upgrader/upgrader.properties"); + log.info("fromVersion为当前作业平台版本,如3.2.7.3"); + log.info("toVersion为目标作业平台版本,如3.3.4.0"); log.info("executeTime为升级任务执行的时间点,取值为BEFORE_UPDATE_JOB、AFTER_UPDATE_JOB," + "在更新作业平台进程前执行本工具填写BEFORE_UPDATE_JOB,更新进程后执行则填写AFTER_UPDATE_JOB"); - log.info("示例:java -Dconfig.file=/data/bkee/job/upgrader.properties -jar upgrader-1.0.0.0.jar 3.1.4.3 3.2.7.3 " + + log.info("示例:java -Dfile.encoding=utf8 -Djob.log.dir=/data/bkee/logs/job" + + " -Dconfig.file=/data/bkee/etc/job/upgrader/upgrader.properties" + + " -jar upgrader-3.3.4.0.jar 3.2.7.3 3.3.4.0 " + "BEFORE_UPDATE_JOB"); } @@ -85,7 +115,125 @@ public static boolean isTaskNeedToExecute( && CompareUtil.compareVersion(taskTargetVersion, toVersion) <= 0; } + private static List, String, Integer>> findAndFilterUpgradeTasks( + String fromVersion, + String toVersion, + String executeTime + ) { + List, String, Integer>> upgradeTaskList = new ArrayList<>(); + // 找出所有UpgradeTask + Reflections reflections = new Reflections( + "com.tencent.bk.job.upgrader.task", + new SubTypesScanner(false), + new TypeAnnotationsScanner() + ); + Set> upgradeTaskSet = reflections.getTypesAnnotatedWith(UpgradeTask.class); + + // 明确指定运行的任务 + List targetTaskList = null; + String targetTasksStr = System.getProperty("target.tasks"); + if (StringUtils.isNotBlank(targetTasksStr)) { + targetTasksStr = targetTasksStr.trim(); + targetTaskList = StringUtil.strToList(targetTasksStr, String.class, ","); + log.info("targetTaskList={}", targetTaskList); + } + + // 筛选 + for (Class clazz : upgradeTaskSet) { + if (targetTaskList != null && !targetTaskList.isEmpty()) { + // 只运行指定的任务 + if (!targetTaskList.contains(clazz.getSimpleName())) { + continue; + } + } + UpgradeTask anotation = clazz.getAnnotation(UpgradeTask.class); + String dataStartVersion = anotation.dataStartVersion(); + String targetVersion = anotation.targetVersion(); + ExecuteTimeEnum targetExecuteTime = anotation.targetExecuteTime(); + int priority = anotation.priority(); + log.info("Found upgradeTask:[{}] for version {}, dataStartVersion={}, priority={}", clazz.getName(), + targetVersion, dataStartVersion, priority); + if (targetExecuteTime.name().equalsIgnoreCase(executeTime) + && isTaskNeedToExecute(fromVersion, toVersion, dataStartVersion, targetVersion) + ) { + log.info("{}-->{},{},Add task {}({},{})", fromVersion, toVersion, executeTime, + clazz.getSimpleName(), targetVersion, targetExecuteTime); + upgradeTaskList.add(Triple.of(clazz, targetVersion, priority)); + } else { + log.info("{}-->{},{},Ignore task {}({},{})", fromVersion, toVersion, executeTime, + clazz.getSimpleName(), targetVersion, targetExecuteTime); + } + } + return upgradeTaskList; + } + + private static void checkAndInputTaskParams( + List, String, Integer>> upgradeTaskList, + Properties properties + ) { + Map paramMap = new HashMap<>(); + Scanner scanner = new Scanner(System.in); + for (Triple, String, Integer> entry : upgradeTaskList) { + Class clazz = entry.getLeft(); + IUpgradeTask upgradeTask = getUpgradeTaskByClass(clazz, properties); + RequireTaskParam requireTaskParamAnotation = clazz.getAnnotation(RequireTaskParam.class); + if (requireTaskParamAnotation != null) { + UpgradeTaskInputParam[] params = requireTaskParamAnotation.value(); + if (params.length > 0) { + log.info("upgradeTask [{}] requires {} param:", upgradeTask.getName(), params.length); + } + for (int i = 0; i < params.length; i++) { + Class paramClass = params[i].value(); + try { + AbstractTaskParam paramInstance = (AbstractTaskParam) paramClass.newInstance(); + log.info("Param {}", i + 1); + log.info("Name: " + paramInstance.getKey()); + log.info("Description: " + paramInstance.getDescriptionEn()); + log.info("描述:" + paramInstance.getDescription()); + // 从JVM参数中取值 + String valueBySystemProperty = System.getProperty(paramInstance.getKey()); + if (!StringUtils.isBlank(valueBySystemProperty)) { + log.info("Param {} already set by VM options, skip", paramInstance.getKey()); + properties.setProperty(paramInstance.getKey(), valueBySystemProperty); + continue; + } + // 从配置文件中取值 + if (properties.containsKey(paramInstance.getKey())) { + log.info("Param {} already set in config file, skip", paramInstance.getKey()); + continue; + } + // 从已指定参数中取值 + if (paramMap.containsKey(paramInstance.getKey())) { + log.info("Param {} already set by another previous task, skip", paramInstance.getKey()); + continue; + } + // 都没有再要求输入 + log.info("Please input param value and click enter to continue:"); + log.info("请输入上述提示所描述的参数,按回车键确认输入:"); + AbstractTaskParam.ParamCheckResult paramCheckResult; + String paramValue; + do { + paramValue = scanner.nextLine(); + paramCheckResult = paramInstance.checkParam(paramValue); + if (!paramCheckResult.isPass()) { + log.warn("Error messages:{}", paramCheckResult.getMessageEn()); + log.warn("错误信息:{}", paramCheckResult.getMessage()); + log.warn("Param value [{}] is invalid, please input again:", paramValue); + } + } while (!paramCheckResult.isPass()); + paramMap.put(paramInstance.getKey(), paramValue.trim()); + } catch (InstantiationException | IllegalAccessException e) { + log.error("Fail to set params for {}", clazz.getSimpleName(), e); + break; + } + } + } + } + paramMap.forEach(properties::setProperty); + } + public static void main(String[] args) { + log.info("Upgrader begin to run"); if (args.length < 3) { usage(); return; @@ -100,40 +248,32 @@ public static void main(String[] args) { Properties properties = new Properties(); String configFilePath = System.getProperty("config.file"); if (StringUtils.isNotBlank(configFilePath)) { + BufferedReader br = null; try { - properties.load(new BufferedReader(new FileReader(configFilePath))); + br = new BufferedReader( + new InputStreamReader(new FileInputStream(configFilePath), StandardCharsets.UTF_8) + ); + properties.load(br); } catch (IOException e) { - log.warn("Cannot read configFile from path:{}", configFilePath, e); + log.warn("Cannot read configFile from path:{}, exit", configFilePath, e); + return; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + log.warn("Fail to close br", e); + } + } } } else { log.warn("Config file is empty"); return; } - log.info("Upgrader begin to run"); - // 找出所有UpgradeTask - Reflections reflections = new Reflections("com.tencent.bk.job.upgrader.task", new SubTypesScanner(false), - new TypeAnnotationsScanner()); - List, String, Integer>> upgradeTaskList = new ArrayList<>(); - Set> upgradeTaskSet = reflections.getTypesAnnotatedWith(UpgradeTask.class); - // 筛选 - upgradeTaskSet.forEach(clazz -> { - UpgradeTask anotation = clazz.getAnnotation(UpgradeTask.class); - String dataStartVersion = anotation.dataStartVersion(); - String targetVersion = anotation.targetVersion(); - ExecuteTimeEnum targetExecuteTime = anotation.targetExecuteTime(); - int priority = anotation.priority(); - log.info("Found upgradeTask:[{}] for version {}, dataStartVersion={}, priority={}", clazz.getName(), - targetVersion, dataStartVersion, priority); - if (targetExecuteTime.name().equalsIgnoreCase(executeTime) - && isTaskNeedToExecute(fromVersion, toVersion, dataStartVersion, targetVersion)) { - log.info("{}-->{},{},Add task {}({},{})", fromVersion, toVersion, executeTime, - clazz.getSimpleName(), targetVersion, targetExecuteTime); - upgradeTaskList.add(Triple.of(clazz, targetVersion, priority)); - } else { - log.info("{}-->{},{},Ignore task {}({},{})", fromVersion, toVersion, executeTime, - clazz.getSimpleName(), targetVersion, targetExecuteTime); - } - }); + + List, String, Integer>> upgradeTaskList = + findAndFilterUpgradeTasks(fromVersion, toVersion, executeTime); + // 排序 upgradeTaskList.sort((o1, o2) -> { int result = CompareUtil.compareVersion(o1.getMiddle(), o2.getMiddle()); @@ -144,53 +284,115 @@ && isTaskNeedToExecute(fromVersion, toVersion, dataStartVersion, targetVersion)) upgradeTaskList.forEach(entry -> { log.info("[{}] for version {}, priority={}", entry.getLeft(), entry.getMiddle(), entry.getRight()); }); - int taskSize = upgradeTaskList.size(); - int successfulTaskCount = 0; + // 参数输入 + checkAndInputTaskParams(upgradeTaskList, properties); // 运行 + runTasks(upgradeTaskList, args, properties); + } + + private static int runTasks( + List, String, Integer>> upgradeTaskList, + String[] args, + Properties properties + ) { + int taskSize = upgradeTaskList.size(); + AtomicInteger successfulTaskNum = new AtomicInteger(0); + int taskNum = upgradeTaskList.size(); + final AtomicInteger currentTaskNum = new AtomicInteger(0); for (Triple, String, Integer> entry : upgradeTaskList) { + currentTaskNum.incrementAndGet(); Class clazz = entry.getLeft(); - try { - IUpgradeTask upgradeTask = null; - try { - Constructor constructor = clazz.getDeclaredConstructor(Properties.class); - upgradeTask = (IUpgradeTask) constructor.newInstance(properties); - } catch (NoSuchMethodException ignore) { - log.info("cannot find constructor with properties, ignore properties"); - } catch (Exception e) { - log.warn("Fail to find constructor with properties", e); - } - if (upgradeTask == null) { - upgradeTask = (IUpgradeTask) clazz.newInstance(); + IUpgradeTask upgradeTask = getUpgradeTaskByClass(clazz, properties); + upgradeTask.init(); + AtomicBoolean taskSuccess = new AtomicBoolean(false); + Thread taskThread = new Thread() { + @Override + public void run() { + try { + log.info("UpgradeTask {}/{} [{}][priority={}] for version {} begin to run", + currentTaskNum.get(), + taskNum, + upgradeTask.getName(), + upgradeTask.getPriority(), + upgradeTask.getTargetVersion()); + int resultCode = upgradeTask.execute(args); + if (resultCode == 0) { + successfulTaskNum.incrementAndGet(); + taskSuccess.set(true); + log.info("UpgradeTask [{}][priority={}] for version {} successfully end", + upgradeTask.getName(), + upgradeTask.getPriority(), + upgradeTask.getTargetVersion()); + } else { + log.warn("UpgradeTask [{}][priority={}] for version {} failed", + upgradeTask.getName(), + upgradeTask.getPriority(), + upgradeTask.getTargetVersion()); + } + } catch (Exception e) { + log.error("Fail to run {}", clazz.getSimpleName(), e); + } } - log.info("UpgradeTask [{}][priority={}] for version {} begin to run", upgradeTask.getName(), - upgradeTask.getPriority(), - upgradeTask.getTargetVersion()); - upgradeTask.execute(args); - successfulTaskCount++; - log.info("UpgradeTask [{}][priority={}] for version {} successfully end", upgradeTask.getName(), + }; + taskThread.start(); + MessageBeatTask beatTask = new MessageBeatTask( + String.format( + "UpgradeTask %d/%d [%s][priority=%d] for version %s is running", + currentTaskNum.get(), + taskNum, + upgradeTask.getName(), upgradeTask.getPriority(), - upgradeTask.getTargetVersion()); - } catch (InstantiationException e) { - log.error("Fail to Instantiate {}", clazz.getSimpleName(), e); - break; - } catch (IllegalAccessException e) { - log.error("Fail to Instantiate {} because of illegalAccess", clazz.getSimpleName(), e); - break; - } catch (Exception e) { - log.error("Fail to run {}", clazz.getSimpleName(), e); + upgradeTask.getTargetVersion() + ) + ); + beatTask.start(); + try { + taskThread.join(); + } catch (InterruptedException e) { + log.error("taskThread interrupted", e); + } + beatTask.interrupt(); + if (currentTaskNum.get() != successfulTaskNum.get()) { break; } } if (taskSize > 0) { - if (successfulTaskCount == taskSize) { + if (successfulTaskNum.get() == taskSize) { log.info("All {} upgradeTasks finished successfully", taskSize); + return 0; } else { - log.warn("{} of {} upgradeTasks finished successfully, others failed, please check", - successfulTaskCount, + log.warn("{} of {} upgradeTasks finished successfully, others not run yet, please check", + successfulTaskNum, taskSize); + return 1; } } else { log.info("No matched upgradeTasks need to run"); } + return 0; + } + + private static IUpgradeTask getUpgradeTaskByClass(Class clazz, Properties properties) { + try { + IUpgradeTask upgradeTask = null; + try { + Constructor constructor = clazz.getDeclaredConstructor(Properties.class); + upgradeTask = (IUpgradeTask) constructor.newInstance(properties); + } catch (NoSuchMethodException ignore) { + log.info("cannot find constructor with properties, ignore properties"); + } catch (Exception e) { + log.warn("Fail to find constructor with properties", e); + } + if (upgradeTask == null) { + upgradeTask = (IUpgradeTask) clazz.newInstance(); + } + return upgradeTask; + } catch (InstantiationException e) { + log.error("Fail to Instantiate {}", clazz.getSimpleName(), e); + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + log.error("Fail to Instantiate {} because of illegalAccess", clazz.getSimpleName(), e); + throw new RuntimeException(e); + } } } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/ExecuteTimeEnum.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/ExecuteTimeEnum.java index a2a6e7b9ae..ac30219da9 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/ExecuteTimeEnum.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/ExecuteTimeEnum.java @@ -28,5 +28,7 @@ public enum ExecuteTimeEnum { // 更新Job进程前 BEFORE_UPDATE_JOB, // 更新Job进程后 - AFTER_UPDATE_JOB + AFTER_UPDATE_JOB, + // 补偿执行的任务,仅用于某些特定环境 + MAKE_UP } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/RequireTaskParam.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/RequireTaskParam.java new file mode 100644 index 0000000000..fc2ed1276c --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/RequireTaskParam.java @@ -0,0 +1,42 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.anotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 升级任务参数注解 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RequireTaskParam { + + UpgradeTaskInputParam[] value() default {}; +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/UpgradeTaskInputParam.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/UpgradeTaskInputParam.java new file mode 100644 index 0000000000..59b4154404 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/anotation/UpgradeTaskInputParam.java @@ -0,0 +1,41 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.anotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 升级任务输入参数注解 + */ +@Target({}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface UpgradeTaskInputParam { + + Class value(); +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractHttpClient.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractHttpClient.java new file mode 100644 index 0000000000..bf17e1f71c --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractHttpClient.java @@ -0,0 +1,126 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.client; + +import com.tencent.bk.job.common.util.http.AbstractHttpHelper; +import com.tencent.bk.job.common.util.http.BasicHttpReq; +import com.tencent.bk.job.common.util.http.DefaultHttpHelper; +import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.job.upgrader.model.IamReq; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; + +import java.util.List; + +import static com.tencent.bk.job.common.constant.HttpHeader.HDR_CONTENT_TYPE; + +@Slf4j +public abstract class AbstractHttpClient { + private String hostUrl; + private AbstractHttpHelper defaultHttpHelper = new DefaultHttpHelper(); + + public AbstractHttpClient(String hostUrl) { + this.hostUrl = hostUrl; + } + + public String doHttpGet(String uri, IamReq params) throws Exception { + return doHttpGet(uri, params, defaultHttpHelper); + } + + abstract List
getBasicHeaders(); + + public String doHttpGet(String uri, BasicHttpReq params, AbstractHttpHelper httpHelper) throws Exception { + if (params == null) { + params = new BasicHttpReq(); + } + if (httpHelper == null) { + httpHelper = defaultHttpHelper; + } + boolean error = false; + long start = System.currentTimeMillis(); + String responseBody = null; + String url = hostUrl; + try { + if (!hostUrl.endsWith("/") && !uri.startsWith("/")) { + url = hostUrl + "/" + uri + params.toUrlParams(); + } else { + url = hostUrl + uri + params.toUrlParams(); + } + responseBody = httpHelper.get(url, getBasicHeaders()); + return responseBody; + } catch (Exception e) { + log.warn("Get url {}| params={}| exception={}", hostUrl + uri, + JsonUtils.toJsonWithoutSkippedFields(params), + e.getMessage()); + error = true; + throw e; + } finally { + log.info("Get url {}| error={}| params={}| time={}| resp={}", hostUrl + uri, error, + JsonUtils.toJsonWithoutSkippedFields(params), (System.currentTimeMillis() - start), responseBody); + } + } + + protected String doHttpPost(String uri, T params) throws Exception { + return doHttpPost(uri, params, defaultHttpHelper); + } + + protected String doHttpPost( + String uri, T params, + AbstractHttpHelper httpHelper + ) throws Exception { + if (httpHelper == null) { + httpHelper = defaultHttpHelper; + } + boolean error = false; + long start = System.currentTimeMillis(); + String responseBody = null; + try { + String url; + if (!hostUrl.endsWith("/") && !uri.startsWith("/")) { + url = hostUrl + "/" + uri; + } else { + url = hostUrl + uri; + } + List
headerList = getBasicHeaders(); + headerList.add(new BasicHeader(HDR_CONTENT_TYPE, "application/json")); + responseBody = httpHelper.post(url, "UTF-8", buildPostBody(params), headerList); + return responseBody; + } catch (Exception e) { + log.warn("Post url {}| params={}| exception={}", uri, JsonUtils.toJsonWithoutSkippedFields(params), + e.getMessage()); + error = true; + throw e; + } finally { + log.info("Post url {}| error={}| params={}| time={}| resp={}", uri, error, + JsonUtils.toJsonWithoutSkippedFields(params), (System.currentTimeMillis() - start), responseBody); + } + } + + protected String buildPostBody(T params) { + return JsonUtils.toJson(params); + } + +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractIamClient.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractIamClient.java index f2d150f505..68d9abdd2a 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractIamClient.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractIamClient.java @@ -24,10 +24,6 @@ package com.tencent.bk.job.upgrader.client; -import com.tencent.bk.job.common.util.http.AbstractHttpHelper; -import com.tencent.bk.job.common.util.http.DefaultHttpHelper; -import com.tencent.bk.job.common.util.json.JsonUtils; -import com.tencent.bk.job.upgrader.model.IamReq; import lombok.extern.slf4j.Slf4j; import org.apache.http.Header; import org.apache.http.message.BasicHeader; @@ -35,26 +31,19 @@ import java.util.ArrayList; import java.util.List; -import static com.tencent.bk.job.common.constant.HttpHeader.HDR_CONTENT_TYPE; - @Slf4j -public abstract class AbstractIamClient { - private String iamHostUrl; +public abstract class AbstractIamClient extends AbstractHttpClient { private String appSecret; private String appCode; - private AbstractHttpHelper defaultHttpHelper = new DefaultHttpHelper(); public AbstractIamClient(String iamHostUrl, String appCode, String appSecret) { - this.iamHostUrl = iamHostUrl; + super(iamHostUrl); this.appCode = appCode; this.appSecret = appSecret; } - public String doHttpGet(String uri, IamReq params) throws Exception { - return doHttpGet(uri, params, defaultHttpHelper); - } - - private List
getBasicHeaders() { + @Override + protected List
getBasicHeaders() { List
headerList = new ArrayList<>(); headerList.add(new BasicHeader("X-Bk-App-Code", appCode)); headerList.add(new BasicHeader("X-Bk-App-Secret", appSecret)); @@ -62,72 +51,4 @@ private List
getBasicHeaders() { return headerList; } - public String doHttpGet(String uri, IamReq params, AbstractHttpHelper httpHelper) throws Exception { - if (httpHelper == null) { - httpHelper = defaultHttpHelper; - } - boolean error = false; - long start = System.currentTimeMillis(); - String responseBody = null; - String url = iamHostUrl; - try { - if (!iamHostUrl.endsWith("/") && !uri.startsWith("/")) { - url = iamHostUrl + "/" + uri + params.toUrlParams(); - } else { - url = iamHostUrl + uri + params.toUrlParams(); - } - responseBody = httpHelper.get(url, getBasicHeaders()); - return responseBody; - } catch (Exception e) { - log.warn("Get url {}| params={}| exception={}", iamHostUrl + uri, - JsonUtils.toJsonWithoutSkippedFields(params), - e.getMessage()); - error = true; - throw e; - } finally { - log.info("Get url {}| error={}| params={}| time={}| resp={}", iamHostUrl + uri, error, - JsonUtils.toJsonWithoutSkippedFields(params), (System.currentTimeMillis() - start), responseBody); - } - } - - protected String doHttpPost(String uri, T params) throws Exception { - return doHttpPost(uri, params, defaultHttpHelper); - } - - protected String doHttpPost( - String uri, T params, - AbstractHttpHelper httpHelper - ) throws Exception { - if (httpHelper == null) { - httpHelper = defaultHttpHelper; - } - boolean error = false; - long start = System.currentTimeMillis(); - String responseBody = null; - try { - String url; - if (!iamHostUrl.endsWith("/") && !uri.startsWith("/")) { - url = iamHostUrl + "/" + uri; - } else { - url = iamHostUrl + uri; - } - List
headerList = getBasicHeaders(); - headerList.add(new BasicHeader(HDR_CONTENT_TYPE, "application/json")); - responseBody = httpHelper.post(url, "UTF-8", buildPostBody(params), headerList); - return responseBody; - } catch (Exception e) { - log.warn("Post url {}| params={}| exception={}", uri, JsonUtils.toJsonWithoutSkippedFields(params), - e.getMessage()); - error = true; - throw e; - } finally { - log.info("Post url {}| error={}| params={}| time={}| resp={}", uri, error, - JsonUtils.toJsonWithoutSkippedFields(params), (System.currentTimeMillis() - start), responseBody); - } - } - - protected String buildPostBody(T params) { - return JsonUtils.toJson(params); - } - } diff --git a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/controller/AbstractIamController.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractJobClient.java similarity index 68% rename from src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/controller/AbstractIamController.java rename to src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractJobClient.java index 9e882f8489..b7ea9a001b 100644 --- a/src/backend/commons/common-iam/src/main/java/com/tencent/bk/job/common/iam/controller/AbstractIamController.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/AbstractJobClient.java @@ -22,30 +22,30 @@ * IN THE SOFTWARE. */ -package com.tencent.bk.job.common.iam.controller; +package com.tencent.bk.job.upgrader.client; -import com.tencent.bk.job.common.web.controller.AbstractJobController; -import com.tencent.bk.sdk.iam.helper.AuthHelper; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.method.HandlerMethod; +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; -/** - * @since 29/5/2020 15:46 - */ @Slf4j -public class AbstractIamController extends AbstractJobController { - - private final AuthHelper authHelper; +public abstract class AbstractJobClient extends AbstractHttpClient { + private String jobAuthToken; - protected AbstractIamController(AuthHelper authHelper) { - this.authHelper = authHelper; + public AbstractJobClient(String jobHostUrl, String jobAuthToken) { + super(jobHostUrl); + this.jobAuthToken = jobAuthToken; } @Override - public boolean preService(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - return authHelper.validRequest(request); + protected List
getBasicHeaders() { + List
headerList = new ArrayList<>(); + headerList.add(new BasicHeader("x-job-auth-token", jobAuthToken)); + headerList.add(new BasicHeader("Content-Type", "application/json")); + return headerList; } + } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/JobClient.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/JobClient.java new file mode 100644 index 0000000000..ef20fdc4fc --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/client/JobClient.java @@ -0,0 +1,141 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.client; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.exception.ServiceException; +import com.tencent.bk.job.common.model.ServiceResponse; +import com.tencent.bk.job.common.util.StringUtil; +import com.tencent.bk.job.common.util.http.AbstractHttpHelper; +import com.tencent.bk.job.common.util.http.BasicHttpReq; +import com.tencent.bk.job.common.util.json.JsonMapper; +import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.job.upgrader.model.AppInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; + +import java.util.List; + +/** + * Job接口调用客户端 + */ +@Slf4j +public class JobClient extends AbstractJobClient { + + /** + * Job API 处理请求成功 + */ + private static final int RESULT_OK = 0; + + private static final String URL_LIST_NORMAL_APPS = "/service/app/list/normal"; + + private static final JsonMapper JSON_MAPPER = JsonMapper.nonDefaultMapper(); + + public JobClient(String jobHostUrl, String jobAuthToken) { + super(jobHostUrl, jobAuthToken); + } + + private R getJobRespByReq(String method, String uri, BasicHttpReq reqBody, + TypeReference typeReference) { + return getJobRespByReq(method, uri, reqBody, typeReference, null); + } + + @SuppressWarnings("all") + private R getJobRespByReq( + String method, + String uri, + BasicHttpReq reqBody, + TypeReference typeReference, + AbstractHttpHelper httpHelper + ) { + // URL模板变量替换 + uri = StringUtil.replacePathVariables(uri, reqBody); + String reqStr = JsonUtils.toJsonWithoutSkippedFields(reqBody); + String respStr = null; + try { + if (method.equals(HttpGet.METHOD_NAME)) { + respStr = doHttpGet(uri, reqBody, httpHelper); + } else if (method.equals(HttpPost.METHOD_NAME)) { + respStr = doHttpPost(uri, reqBody, httpHelper); + } + if (StringUtils.isBlank(respStr)) { + log.error("fail:response is blank|method={}|uri={}|reqStr={}", method, uri, reqStr); + throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "response is blank"); + } else { + log.debug("success|method={}|uri={}|reqStr={}|respStr={}", method, uri, reqStr, respStr); + } + R result = + JSON_MAPPER.fromJson(respStr, typeReference); + ServiceResponse jobResp = (ServiceResponse) result; + if (jobResp == null) { + log.error("fail:jobResp is null after parse|method={}|uri={}|reqStr={}|respStr={}", method, uri, + reqStr, respStr); + throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "jobResp is null after parse"); + } else if (jobResp.getCode() != RESULT_OK) { + log.error( + "fail:jobResp code!=0|jobResp.code={}|jobResp" + + ".errorMessage={}|method={}|uri={}|reqStr={}|respStr={}", + jobResp.getCode(), + jobResp.getErrorMsg(), + method, + uri, + reqStr, + respStr + ); + throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "jobResp code!=0"); + } + if (jobResp.getData() == null) { + log.warn( + "warn:jobResp.getData() == null|jobResp.code={}|jobResp" + + ".errorMessage={}|method={}|uri={}|reqStr={}|respStr={}", + jobResp.getCode(), + jobResp.getErrorMsg(), + method, + uri, + reqStr, + respStr + ); + } + return result; + } catch (Exception e) { + String errorMsg = "Fail to request JOB data|method=" + method + "|uri=" + uri + "|reqStr=" + reqStr; + log.error(errorMsg, e); + throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "Fail to request JOB data"); + } + } + + public List listNormalApps() { + ServiceResponse> resp = getJobRespByReq( + HttpGet.METHOD_NAME, + URL_LIST_NORMAL_APPS, + new BasicHttpReq(), + new TypeReference>>() { + }); + return resp.getData(); + } +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/iam/JobIamHelper.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/iam/JobIamHelper.java new file mode 100644 index 0000000000..220810ec82 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/iam/JobIamHelper.java @@ -0,0 +1,95 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.iam; + +import com.tencent.bk.job.common.iam.config.EsbConfiguration; +import com.tencent.bk.job.common.iam.util.BusinessAuthHelper; +import com.tencent.bk.sdk.iam.config.IamConfiguration; +import com.tencent.bk.sdk.iam.constants.SystemId; +import com.tencent.bk.sdk.iam.helper.AuthHelper; +import com.tencent.bk.sdk.iam.service.HttpClientService; +import com.tencent.bk.sdk.iam.service.PolicyService; +import com.tencent.bk.sdk.iam.service.TokenService; +import com.tencent.bk.sdk.iam.service.impl.DefaultHttpClientServiceImpl; +import com.tencent.bk.sdk.iam.service.impl.PolicyServiceImpl; +import com.tencent.bk.sdk.iam.service.impl.TokenServiceImpl; + +public class JobIamHelper { + + /** + * ESB 分配的系统 App Code + */ + private String appCode; + + /** + * ESB 分配的系统 App Secret + */ + private String appSecret; + + /** + * 权限中心的访问地址 + */ + private String iamBaseUrl; + + /** + * ESB API 的访问地址 + */ + private String esbUrl; + + public JobIamHelper(String appCode, String appSecret, String iamBaseUrl, String esbUrl) { + this.appCode = appCode; + this.appSecret = appSecret; + this.iamBaseUrl = iamBaseUrl; + this.esbUrl = esbUrl; + } + + public IamConfiguration iamConfiguration() { + return new IamConfiguration(SystemId.JOB, appCode, appSecret, iamBaseUrl); + } + + public EsbConfiguration esbConfiguration() { + return new EsbConfiguration(esbUrl, false); + } + + public HttpClientService httpClientService() { + return new DefaultHttpClientServiceImpl(iamConfiguration()); + } + + public PolicyService policyService() { + return new PolicyServiceImpl(iamConfiguration(), httpClientService()); + } + + public TokenService tokenService() { + return new TokenServiceImpl(iamConfiguration(), httpClientService()); + } + + public AuthHelper authHelper() { + return new AuthHelper(tokenService(), policyService(), iamConfiguration()); + } + + public BusinessAuthHelper businessAuthHelper() { + return new BusinessAuthHelper(tokenService(), policyService(), iamConfiguration()); + } +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Expression.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java similarity index 94% rename from src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Expression.java rename to src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java index bbdb59e72a..389c440ddb 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Expression.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/AppInfo.java @@ -28,11 +28,11 @@ import lombok.Data; import lombok.NoArgsConstructor; +@Data @NoArgsConstructor @AllArgsConstructor -@Data -public class Expression { - private String field; - private String op; - private String value; +public class AppInfo { + private Long id; + + private String name; } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Policy.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Policy.java index 33225ca323..8a14d3ea14 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Policy.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/model/Policy.java @@ -25,6 +25,7 @@ package com.tencent.bk.job.upgrader.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.sdk.iam.dto.expression.ExpressionDTO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -36,7 +37,7 @@ public class Policy { private String version; private Long id; private Subject subject; - private CompositeExpression expression; + private ExpressionDTO expression; @JsonProperty("expired_at") private Long expiredAt; } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BaseUpgradeTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BaseUpgradeTask.java index b9a31a29e9..bc6203e605 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BaseUpgradeTask.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/BaseUpgradeTask.java @@ -39,10 +39,14 @@ public abstract class BaseUpgradeTask implements IUpgradeTask { this.properties = properties; } - public Properties getProperties(){ + public Properties getProperties() { return properties; } + @Override + public void init() { + } + @Override public String getName() { return this.getClass().getSimpleName(); diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/IUpgradeTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/IUpgradeTask.java index 23cd3dab12..fef6fd92a8 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/IUpgradeTask.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/IUpgradeTask.java @@ -32,6 +32,8 @@ public interface IUpgradeTask { String getTargetVersion(); + void init(); + int getPriority(); int execute(String[] args); diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManageEncryptDbAccountPasswordMigrationTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManageEncryptDbAccountPasswordMigrationTask.java index c972432b6a..7d79ae92e0 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManageEncryptDbAccountPasswordMigrationTask.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManageEncryptDbAccountPasswordMigrationTask.java @@ -24,19 +24,25 @@ package com.tencent.bk.job.upgrader.task; +import com.fasterxml.jackson.core.type.TypeReference; import com.tencent.bk.job.common.constant.ErrorCode; import com.tencent.bk.job.common.exception.ServiceException; import com.tencent.bk.job.common.model.ServiceResponse; import com.tencent.bk.job.common.util.Base64Util; import com.tencent.bk.job.common.util.json.JsonUtils; import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; +import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; import com.tencent.bk.job.upgrader.anotation.UpgradeTask; +import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; +import com.tencent.bk.job.upgrader.task.param.JobManageServerAddress; +import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; import com.tencent.bk.job.upgrader.utils.HttpHelperFactory; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.http.Header; import org.apache.http.message.BasicHeader; +import java.util.List; import java.util.Properties; import static com.tencent.bk.job.common.constant.ErrorCode.RESULT_OK; @@ -45,6 +51,9 @@ * DB账号密码加密 */ @Slf4j +@RequireTaskParam(value = { + @UpgradeTaskInputParam(value = JobManageServerAddress.class) +}) @UpgradeTask( dataStartVersion = "3.0.0.0", targetVersion = "3.3.4.0", @@ -58,10 +67,12 @@ public ManageEncryptDbAccountPasswordMigrationTask(Properties properties) { @Override public int execute(String[] args) { log.info(getName() + " for version " + getTargetVersion() + " begin to run..."); - String jobManageHost = getProperties().getProperty("job-manage.host"); - if (StringUtils.isBlank(jobManageHost)) { - log.error("job-manage.host is not configured"); - return 1; + String jobManageServerAddress = getProperties().getProperty( + ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS + ); + String jobManageHost = ""; + if (!jobManageServerAddress.startsWith("http://") && !jobManageServerAddress.startsWith("https://")) { + jobManageHost = "http://" + jobManageServerAddress; } String uri = "/migration/action/encryptDbAccountPassword"; String url; @@ -71,9 +82,11 @@ public int execute(String[] args) { url = jobManageHost.substring(0, jobManageHost.length() - 1) + uri; } - String jobAuthToken = getProperties().getProperty("job.security.public-key-base64"); + String jobAuthToken = getProperties().getProperty( + ParamNameConsts.CONFIG_PROPERTY_JOB_SECURITY_PUBLIC_KEY_BASE64 + ); if (StringUtils.isBlank(jobAuthToken)) { - log.error("job.security.public-key-base64 is not configured"); + log.error("{} is not configured", ParamNameConsts.CONFIG_PROPERTY_JOB_SECURITY_PUBLIC_KEY_BASE64); return 1; } jobAuthToken = Base64Util.decodeContentToStr(jobAuthToken); @@ -83,20 +96,21 @@ public int execute(String[] args) { headers[1] = new BasicHeader("Content-Type", "application/json"); - String key = getProperties().getProperty("job.encrypt.password"); + String key = getProperties().getProperty(ParamNameConsts.CONFIG_PROPERTY_JOB_ENCRYPT_PASSWORD); if (StringUtils.isBlank(key)) { - log.error("job.encrypt.password is not configured"); + log.error("{} is not configured", ParamNameConsts.CONFIG_PROPERTY_JOB_ENCRYPT_PASSWORD); return 1; } try { - String respStr = HttpHelperFactory.getDefaultHttpHelper().post(url, "{\"key\":\"" + key + "\"}", - headers); + String respStr = HttpHelperFactory.getDefaultHttpHelper().post(url, "", headers); if (StringUtils.isBlank(respStr)) { log.error("Fail:response is blank|uri={}", url); throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "Encrypt db account password fail"); } - ServiceResponse resp = JsonUtils.fromJson(respStr, ServiceResponse.class); + ServiceResponse> resp = JsonUtils.fromJson(respStr, + new TypeReference>>() { + }); if (resp == null) { log.error("Fail:parse respStr fail|uri={}", url); throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "Encrypt db account password fail"); @@ -104,7 +118,9 @@ public int execute(String[] args) { log.error("Fail: code!=0"); throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "Encrypt db account password fail"); } + log.info("Encrypt db account password successfully!accountIds: {}", resp.getData()); } catch (Exception e) { + log.error("Fail: caught exception", e); throw new ServiceException(ErrorCode.SERVICE_INTERNAL_ERROR, "Encrypt db account password fail"); } return 0; diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManagePublicScriptPermissionMigrationTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManagePublicScriptPermissionMigrationTask.java index f88ec04907..1a58304537 100644 --- a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManagePublicScriptPermissionMigrationTask.java +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/ManagePublicScriptPermissionMigrationTask.java @@ -37,6 +37,7 @@ import com.tencent.bk.job.upgrader.client.IamClient; import com.tencent.bk.job.upgrader.model.ActionPolicies; import com.tencent.bk.job.upgrader.model.Policy; +import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; import com.tencent.bk.sdk.iam.constants.SystemId; import lombok.extern.slf4j.Slf4j; @@ -65,9 +66,9 @@ private IamClient getIamClient() { Properties properties = getProperties(); if (iamClient == null) { iamClient = new IamClient( - (String) properties.get("iam.base-url"), - (String) properties.get("app.code"), - (String) properties.get("app.secret") + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_IAM_BASE_URL), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET) ); } return iamClient; @@ -77,9 +78,9 @@ private EsbIamClient getEsbIamClient() { Properties properties = getProperties(); if (esbIamClient == null) { esbIamClient = new EsbIamClient( - (String) properties.get("esb.service.url"), - (String) properties.get("app.code"), - (String) properties.get("app.secret"), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_ESB_SERVICE_URL), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET), false ); } diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/UseAccountPermissionMigrationTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/UseAccountPermissionMigrationTask.java new file mode 100644 index 0000000000..4cced80785 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/UseAccountPermissionMigrationTask.java @@ -0,0 +1,329 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.task; + +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.exception.ServiceException; +import com.tencent.bk.job.common.iam.client.EsbIamClient; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.constant.ResourceTypeEnum; +import com.tencent.bk.job.common.iam.dto.EsbIamAction; +import com.tencent.bk.job.common.iam.dto.EsbIamBatchAuthedPolicy; +import com.tencent.bk.job.common.iam.dto.EsbIamBatchPathResource; +import com.tencent.bk.job.common.iam.dto.EsbIamPathItem; +import com.tencent.bk.job.common.iam.dto.EsbIamSubject; +import com.tencent.bk.job.common.iam.util.BusinessAuthHelper; +import com.tencent.bk.job.common.util.json.JsonUtils; +import com.tencent.bk.job.common.util.jwt.BasicJwtManager; +import com.tencent.bk.job.common.util.jwt.JwtManager; +import com.tencent.bk.job.upgrader.anotation.ExecuteTimeEnum; +import com.tencent.bk.job.upgrader.anotation.RequireTaskParam; +import com.tencent.bk.job.upgrader.anotation.UpgradeTask; +import com.tencent.bk.job.upgrader.anotation.UpgradeTaskInputParam; +import com.tencent.bk.job.upgrader.client.IamClient; +import com.tencent.bk.job.upgrader.client.JobClient; +import com.tencent.bk.job.upgrader.iam.JobIamHelper; +import com.tencent.bk.job.upgrader.model.ActionPolicies; +import com.tencent.bk.job.upgrader.model.AppInfo; +import com.tencent.bk.job.upgrader.model.Policy; +import com.tencent.bk.job.upgrader.task.param.JobManageServerAddress; +import com.tencent.bk.job.upgrader.task.param.ParamNameConsts; +import com.tencent.bk.sdk.iam.constants.SystemId; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; + +/** + * 账号使用权限迁移任务 + */ +@Slf4j +@RequireTaskParam(value = { + @UpgradeTaskInputParam(value = JobManageServerAddress.class) +}) +@UpgradeTask( + dataStartVersion = "3.0.0.0", + targetVersion = "3.3.5.0", + targetExecuteTime = ExecuteTimeEnum.MAKE_UP) +public class UseAccountPermissionMigrationTask extends BaseUpgradeTask { + + private JobIamHelper jobIamHelper; + private JobClient jobManageClient; + + private IamClient iamClient; + private EsbIamClient esbIamClient; + private List appInfoList; + private Map appInfoMap; + + private String getJobHostUrlByAddress(String address) { + if (!address.startsWith("http://") && !address.startsWith("https://")) { + address = "http://" + address; + } + return address; + } + + public UseAccountPermissionMigrationTask(Properties properties) { + super(properties); + } + + @Override + public void init() { + jobIamHelper = new JobIamHelper( + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET), + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_IAM_BASE_URL), + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_ESB_SERVICE_URL) + ); + String securityPublicKeyBase64 = + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_JOB_SECURITY_PUBLIC_KEY_BASE64); + String securityPrivateKeyBase64 = + (String) getProperties().get(ParamNameConsts.CONFIG_PROPERTY_JOB_SECURITY_PRIVATE_KEY_BASE64); + JwtManager jwtManager = null; + try { + jwtManager = new BasicJwtManager(securityPrivateKeyBase64, securityPublicKeyBase64); + } catch (IOException | GeneralSecurityException e) { + String msg = "Fail to generate jwt auth token"; + log.error(msg, e); + throw new ServiceException(e, ErrorCode.SERVICE_INTERNAL_ERROR, msg); + } + String jobAuthToken = jwtManager.generateToken(60 * 60 * 1000); + jobManageClient = new JobClient( + getJobHostUrlByAddress((String) getProperties().get(ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS)), + jobAuthToken + ); + this.appInfoList = getAllNormalAppInfoFromManage(); + appInfoMap = new HashMap<>(); + appInfoList.forEach(appInfo -> { + appInfoMap.put(appInfo.getId(), appInfo.getName()); + }); + } + + private IamClient getIamClient() { + Properties properties = getProperties(); + if (iamClient == null) { + iamClient = new IamClient( + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_IAM_BASE_URL), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET) + ); + } + return iamClient; + } + + private EsbIamClient getEsbIamClient() { + Properties properties = getProperties(); + if (esbIamClient == null) { + esbIamClient = new EsbIamClient( + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_ESB_SERVICE_URL), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_CODE), + (String) properties.get(ParamNameConsts.CONFIG_PROPERTY_APP_SECRET), + false + ); + } + return esbIamClient; + } + + private List queryAuthorizedPolicies(String actionId) { + ActionPolicies actionPolicies = getIamClient().getActionPolicies(actionId); + return actionPolicies.getResults(); + } + + private List getAllNormalAppInfoFromManage() { + try { + return jobManageClient.listNormalApps(); + } catch (Exception e) { + log.error("Fail to get normal apps from job-manage, please confirm job-manage version>=3.3.5.0"); + throw e; + } + } + + /** + * 根据策略计算出有权限的业务Id列表 + * + * @param policy + * @return + */ + private List getAuthorizedAppIdList(Policy policy) { + BusinessAuthHelper businessAuthHelper = jobIamHelper.businessAuthHelper(); + return businessAuthHelper.getAuthedAppIdList( + null, + policy.getExpression(), + appInfoList.parallelStream().map(AppInfo::getId).collect(Collectors.toList()) + ); + } + + /** + * 根据业务ID获取业务名称 + * + * @param appId + * @return + */ + private String getAppNameById(Long appId) { + if (appInfoMap.containsKey(appId)) return appInfoMap.get(appId); + return null; + } + + private boolean authByPolicy(Policy policy) { + if ("any".equals(policy.getExpression().getOperator().getOperator())) { + // 授予任意业务任意账号权限 + log.info("auth any biz permission to {}", policy.getSubject()); + return authAnyBizUseAccountByPolicy(policy); + } else { + List appIdList = getAuthorizedAppIdList(policy); + log.info("auth {} permission to {}", appIdList, policy.getSubject()); + // 授予业务下任意账号权限 + return authBizUseAccountByPolicy(policy, appIdList); + } + } + + private List getUseAccountActions() { + EsbIamAction esbIamAction = new EsbIamAction(); + esbIamAction.setId(ActionId.USE_ACCOUNT); + List actions = new ArrayList<>(); + actions.add(esbIamAction); + return actions; + } + + private EsbIamSubject getSubjectByPolicy(Policy policy) { + EsbIamSubject esbIamSubject = new EsbIamSubject(); + esbIamSubject.setId(policy.getSubject().getId()); + esbIamSubject.setType(policy.getSubject().getType()); + return esbIamSubject; + } + + /** + * 授予任意业务下任意执行账号使用的权限 + * + * @param policy 权限策略 + * @return 是否授权成功 + */ + private boolean authAnyBizUseAccountByPolicy(Policy policy) { + EsbIamBatchPathResource esbIamBatchPathResource = new EsbIamBatchPathResource(); + esbIamBatchPathResource.setSystem(SystemId.JOB); + esbIamBatchPathResource.setType(ResourceTypeEnum.ACCOUNT.getId()); + esbIamBatchPathResource.setPaths(new ArrayList<>()); + return batchAuth(policy, getUseAccountActions(), getSubjectByPolicy(policy), esbIamBatchPathResource); + } + + /** + * 授予某些业务下任意执行账号使用的权限 + * + * @param policy 权限策略 + * @return 是否授权成功 + */ + private boolean authBizUseAccountByPolicy(Policy policy, List appIdList) { + EsbIamBatchPathResource esbIamBatchPathResource = new EsbIamBatchPathResource(); + esbIamBatchPathResource.setSystem(SystemId.JOB); + esbIamBatchPathResource.setType(ResourceTypeEnum.ACCOUNT.getId()); + List> pathList = new ArrayList<>(); + for (Long appId : appIdList) { + List esbIamPathItemList = new ArrayList<>(); + EsbIamPathItem pathItem = new EsbIamPathItem(); + pathItem.setType(ResourceTypeEnum.BUSINESS.getId()); + pathItem.setId(appId.toString()); + pathItem.setName(getAppNameById(appId)); + esbIamPathItemList.add(pathItem); + pathList.add(esbIamPathItemList); + } + esbIamBatchPathResource.setPaths(pathList); + return batchAuth(policy, getUseAccountActions(), getSubjectByPolicy(policy), esbIamBatchPathResource); + } + + /** + * 调用权限中心接口进行批量授权 + * + * @param policy 权限策略 + * @param actions 授权操作列表 + * @param esbIamSubject 授权对象 + * @param esbIamBatchPathResource 批量资源路径 + * @return 是否授权成功 + */ + private boolean batchAuth( + Policy policy, + List actions, + EsbIamSubject esbIamSubject, + EsbIamBatchPathResource esbIamBatchPathResource + ) { + List resourceList = new ArrayList<>(); + resourceList.add(esbIamBatchPathResource); + try { + List batchAuthedPolicy = getEsbIamClient().batchAuthByPath(actions, + esbIamSubject, resourceList, policy.getExpiredAt()); + log.info("batchAuthedPolicy={}", JsonUtils.toJson(batchAuthedPolicy)); + return true; + } catch (Exception e) { + log.error("Fail to auth subject {} to {}", JsonUtils.toJson(policy.getSubject()), policy.getExpiredAt(), e); + return false; + } + } + + public void printSeparateLine() { + log.info("=================================================="); + } + + public void showPolicies(List policies) { + policies.forEach(policy -> { + log.info("{}: {} expiredAt {}, expression:{}", policy.getId(), + policy.getSubject().getType() + ":" + policy.getSubject().getName(), + policy.getExpiredAt(), JsonUtils.toJson(policy.getExpression())); + }); + } + + @Override + public int execute(String[] args) { + log.info(getName() + " for version " + getTargetVersion() + " begin to run..."); + String oldActionId = ActionId.LIST_BUSINESS; + // 1.旧权限数据读取 + List oldAuthorizedPolicies = queryAuthorizedPolicies(oldActionId); + printSeparateLine(); + log.info("oldAuthorizedPolicies of {}:", oldActionId); + showPolicies(oldAuthorizedPolicies); + printSeparateLine(); + log.info("Begin to auth according to oldPolicies:"); + // 2.新权限数据授权 + oldAuthorizedPolicies.forEach(policy -> { + log.info( + "auth {}:{}:{}:{}", + policy.getSubject().getType(), + policy.getSubject().getName(), + policy.getExpiredAt(), + authByPolicy(policy)); + }); + // 3.新权限策略查询 + String newActionId = ActionId.USE_ACCOUNT; + List newAuthorizedPolicies = queryAuthorizedPolicies(newActionId); + printSeparateLine(); + log.info("newAuthorizedPolicies:"); + showPolicies(newAuthorizedPolicies); + printSeparateLine(); + return 0; + } +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/AbstractTaskParam.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/AbstractTaskParam.java new file mode 100644 index 0000000000..79aa917354 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/AbstractTaskParam.java @@ -0,0 +1,28 @@ +package com.tencent.bk.job.upgrader.task.param; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public abstract class AbstractTaskParam { + private String key; + private String description; + private String descriptionEn; + + @Data + @AllArgsConstructor + public static class ParamCheckResult { + private boolean pass; + private String message; + private String messageEn; + + public static ParamCheckResult ok() { + return new ParamCheckResult(true, "成功", "ok"); + } + } + + public abstract ParamCheckResult checkParam(String value); +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/JobManageServerAddress.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/JobManageServerAddress.java new file mode 100644 index 0000000000..f26297eaae --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/JobManageServerAddress.java @@ -0,0 +1,24 @@ +package com.tencent.bk.job.upgrader.task.param; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public class JobManageServerAddress extends AbstractTaskParam { + + public JobManageServerAddress() { + super( + ParamNameConsts.INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS, + "集群中任意一个job-manage实例对应的IP加端口地址,格式:ip:port,例如:127.0.0.1:10505", + "IP and port of any one of job-manage service instances, format: ip:port,example: 127.0.0.1:10505" + ); + } + + @Override + public ParamCheckResult checkParam(String value) { + if (StringUtils.isBlank(value)) { + return new ParamCheckResult(false, "取值不可为空", "value cannot be empty"); + } + return ParamCheckResult.ok(); + } +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/ParamNameConsts.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/ParamNameConsts.java new file mode 100644 index 0000000000..dac5fc9c29 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/task/param/ParamNameConsts.java @@ -0,0 +1,16 @@ +package com.tencent.bk.job.upgrader.task.param; + +public class ParamNameConsts { + // 需要用户手动输入的参数 + // 集群中任意一个job-manage实例对应的IP加端口地址,格式:ip:port,例如:127.0.0.1:10505 + public static final String INPUT_PARAM_JOB_MANAGE_SERVER_ADDRESS = "job.manage.server.address"; + + // 自动从配置文件读取的参数 + public static final String CONFIG_PROPERTY_APP_CODE = "app.code"; + public static final String CONFIG_PROPERTY_APP_SECRET = "app.secret"; + public static final String CONFIG_PROPERTY_IAM_BASE_URL = "iam.base-url"; + public static final String CONFIG_PROPERTY_ESB_SERVICE_URL = "esb.service.url"; + public static final String CONFIG_PROPERTY_JOB_SECURITY_PUBLIC_KEY_BASE64 = "job.security.public-key-base64"; + public static final String CONFIG_PROPERTY_JOB_SECURITY_PRIVATE_KEY_BASE64 = "job.security.private-key-base64"; + public static final String CONFIG_PROPERTY_JOB_ENCRYPT_PASSWORD = "job.encrypt.password"; +} diff --git a/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/utils/MessageBeatTask.java b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/utils/MessageBeatTask.java new file mode 100644 index 0000000000..6aab8c6cc8 --- /dev/null +++ b/src/backend/upgrader/src/main/java/com/tencent/bk/job/upgrader/utils/MessageBeatTask.java @@ -0,0 +1,56 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.upgrader.utils; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class MessageBeatTask extends Thread { + + private String message; + private long intervalMills; + volatile boolean runFlag = true; + + public MessageBeatTask(String message, long intervalMills) { + this.message = message; + this.intervalMills = intervalMills; + } + + public MessageBeatTask(String message) { + this(message, 5000L); + } + + @Override + public void run() { + try { + while (runFlag) { + log.info(message); + sleep(intervalMills); + } + } catch (InterruptedException e) { + log.info("Stop beat"); + } + } +} diff --git a/src/backend/upgrader/src/main/resources/logback.xml b/src/backend/upgrader/src/main/resources/logback.xml new file mode 100644 index 0000000000..77d29792e8 --- /dev/null +++ b/src/backend/upgrader/src/main/resources/logback.xml @@ -0,0 +1,32 @@ + + + + + + + logback + + + ${UPGRADER_LOG_FILE} + + ${UPGRADER_LOG_FILE}-%d{yyyyMMdd_HH}.log.%i + 1GB + 30 + 10GB + + + ${LOG_PATTERN} + UTF-8 + + + + + ${LOG_PATTERN} + + + + + + + diff --git a/src/frontend/.gitignore b/src/frontend/.gitignore index 4d9d957b9e..c212004129 100644 --- a/src/frontend/.gitignore +++ b/src/frontend/.gitignore @@ -76,5 +76,7 @@ test/unit/coverage *.njsproj *.sln dist +*.local +.history !build diff --git a/src/frontend/index-dev.html b/src/frontend/index-dev.html index 01baaad458..211dc695d7 100644 --- a/src/frontend/index-dev.html +++ b/src/frontend/index-dev.html @@ -44,7 +44,7 @@ const SITE_URL = "/"; const BK_STATIC_URL = "/"; const REMOTE_STATIC_URL = ""; - const AJAX_URL_PREFIX = ""; + const AJAX_URL_PREFIX = "<%= AJAX_URL_PREFIX %>"; const EXTERNAL_THEME = ""; return { diff --git a/src/frontend/index.html b/src/frontend/index.html index 716b2f10ba..09231c8820 100644 --- a/src/frontend/index.html +++ b/src/frontend/index.html @@ -57,6 +57,15 @@ }; })(); + diff --git a/src/frontend/src/components/global-variable/edit/index.vue b/src/frontend/src/components/global-variable/edit/index.vue index 1e77cfbc60..e9944687a9 100644 --- a/src/frontend/src/components/global-variable/edit/index.vue +++ b/src/frontend/src/components/global-variable/edit/index.vue @@ -30,7 +30,7 @@
{{ data.name }}
-
+
containerWidth ? 'top' : 'right'; }, methods: { + /** + * @desc 外部调用——移除主机变量中的无效主机 + */ + removeAllInvalidHost () { + this.$refs.target.removeAllInvalidHost && this.$refs.target.removeAllInvalidHost(); + }, + /** + * @desc 外部调用——移除主机变量中的无效主机 + */ reset () { this.$refs.target.reset(); }, @@ -177,6 +172,7 @@ .variable-value { flex: 1; + max-width: 960px; } .variable-value-error { diff --git a/src/frontend/src/components/jb-account-select/index.vue b/src/frontend/src/components/jb-account-select/index.vue deleted file mode 100644 index bc1286ad84..0000000000 --- a/src/frontend/src/components/jb-account-select/index.vue +++ /dev/null @@ -1,136 +0,0 @@ - - - - diff --git a/src/frontend/src/components/jb-dialog/index.vue b/src/frontend/src/components/jb-dialog/index.vue index ea994b919f..303db10337 100644 --- a/src/frontend/src/components/jb-dialog/index.vue +++ b/src/frontend/src/components/jb-dialog/index.vue @@ -57,9 +57,7 @@ + diff --git a/src/frontend/src/components/jb-edit/input.vue b/src/frontend/src/components/jb-edit/input.vue index 45d5bc6c75..d74f7f2b05 100644 --- a/src/frontend/src/components/jb-edit/input.vue +++ b/src/frontend/src/components/jb-edit/input.vue @@ -28,20 +28,27 @@