From ac4c0399c168c265fae68eeefd7294ff2e042f35 Mon Sep 17 00:00:00 2001 From: IceDerce Date: Sat, 11 Feb 2023 19:15:38 +0800 Subject: [PATCH] =?UTF-8?q?[=20server=20]=20[=20oss=20]-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AF=B9=E8=B1=A1=E5=AD=98=E5=82=A8=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E4=BD=BF=E7=94=A8AWS=20S3=20JavaSDK=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/pom.xml | 8 +- server/pom.xml | 19 +- .../io/wdd/func/controller/OSSController.java | 28 ++ .../wdd/func/controller/XrayController.java | 27 + .../oracle/config/OracleOSSConfiguration.java | 79 +++ .../oracle/service/OracleOSSCoreService.java | 6 + .../service/OracleOSSCoreServiceImpl.java | 35 ++ .../java/io/wdd/func/xray/result/test.json | 465 ++++++++++++++++++ 8 files changed, 654 insertions(+), 13 deletions(-) create mode 100644 server/src/main/java/io/wdd/func/controller/OSSController.java create mode 100644 server/src/main/java/io/wdd/func/controller/XrayController.java create mode 100644 server/src/main/java/io/wdd/func/oss/oracle/config/OracleOSSConfiguration.java create mode 100644 server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreService.java create mode 100644 server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreServiceImpl.java create mode 100644 server/src/main/java/io/wdd/func/xray/result/test.json diff --git a/agent/pom.xml b/agent/pom.xml index 93bc353..d35face 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -33,15 +33,15 @@ spring-boot-starter-amqp - + - + diff --git a/server/pom.xml b/server/pom.xml index b745c47..76a7426 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -26,11 +26,6 @@ ${project.parent.version} - - org.springframework.cloud @@ -57,6 +52,13 @@ runtime --> + + + + com.amazonaws + aws-java-sdk-s3 + 1.12.405 + @@ -79,25 +81,24 @@ 8.0.30 - - - + + diff --git a/server/src/main/java/io/wdd/func/controller/OSSController.java b/server/src/main/java/io/wdd/func/controller/OSSController.java new file mode 100644 index 0000000..6d61666 --- /dev/null +++ b/server/src/main/java/io/wdd/func/controller/OSSController.java @@ -0,0 +1,28 @@ +package io.wdd.func.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.wdd.func.oss.oracle.service.OracleOSSCoreService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping("/server/func/oss/") +@Api("Server对象存储的Controller") +public class OSSController { + + @Resource + OracleOSSCoreService oracleOSSCoreService; + + @GetMapping("/bucket/list/all") + @ApiOperation("列出所有的桶") + public void bucketListAll() { + + oracleOSSCoreService.listBucketList(); + System.out.println(" = "); + } + +} diff --git a/server/src/main/java/io/wdd/func/controller/XrayController.java b/server/src/main/java/io/wdd/func/controller/XrayController.java new file mode 100644 index 0000000..ae6275f --- /dev/null +++ b/server/src/main/java/io/wdd/func/controller/XrayController.java @@ -0,0 +1,27 @@ +package io.wdd.func.controller; + + +import io.wdd.func.xray.service.XrayCoreService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping("/server/func/xray/") +public class XrayController { + + + @Resource + XrayCoreService xrayCoreService; + + @GetMapping("/test") + public void test(){ + + xrayCoreService.generateXrayJsonFromNodeList(null); + + System.out.println("结束!"); + + } +} diff --git a/server/src/main/java/io/wdd/func/oss/oracle/config/OracleOSSConfiguration.java b/server/src/main/java/io/wdd/func/oss/oracle/config/OracleOSSConfiguration.java new file mode 100644 index 0000000..d061d72 --- /dev/null +++ b/server/src/main/java/io/wdd/func/oss/oracle/config/OracleOSSConfiguration.java @@ -0,0 +1,79 @@ +package io.wdd.func.oss.oracle.config; + +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3Client; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; + +@Configuration +public class OracleOSSConfiguration { + + /** + * 缓存所有的S3客户端 + */ + public List ALL_S3_CLIENT = new ArrayList<>(); + + + /** + * 从Nacos中获取到所有的对象存储对象 + */ + @Value("${oss.oracle.seoul2.region}") + String SeoulRegion; + @Value("${oss.oracle.seoul2.namespace}") + String Seoul2Namespace; + @Value("${oss.oracle.seoul2.key}") + String Seoul2Key; + @Value("${oss.oracle.seoul2.secret}") + String Seoul2Secret; + + @PostConstruct + public void buildAllS3Client() { + + AWSCredentialsProvider credentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials( + Seoul2Key, + Seoul2Secret + )); + + String oracleOSSEndpoint = buildOracleOSSEndpoint( + Seoul2Namespace, + SeoulRegion + ); + // Create an S3 client pointing at the region + AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder + .EndpointConfiguration( + oracleOSSEndpoint, + SeoulRegion + ); + + AmazonS3 seoul2OSSClient = AmazonS3Client + .builder() + .standard() + .withCredentials(credentials) + .withEndpointConfiguration(endpointConfiguration) + .disableChunkedEncoding() + .enablePathStyleAccess() + .build(); + + + // add cache + ALL_S3_CLIENT.add(seoul2OSSClient); + + } + + private String buildOracleOSSEndpoint(String namespace, String region) { + + return String.format( + "%s.compat.objectstorage.%s.oraclecloud.com", + namespace, + region + ); + } +} diff --git a/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreService.java b/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreService.java new file mode 100644 index 0000000..b6cf3c8 --- /dev/null +++ b/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreService.java @@ -0,0 +1,6 @@ +package io.wdd.func.oss.oracle.service; + +public interface OracleOSSCoreService { + + void listBucketList(); +} diff --git a/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreServiceImpl.java b/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreServiceImpl.java new file mode 100644 index 0000000..f9c38e4 --- /dev/null +++ b/server/src/main/java/io/wdd/func/oss/oracle/service/OracleOSSCoreServiceImpl.java @@ -0,0 +1,35 @@ +package io.wdd.func.oss.oracle.service; + + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.Bucket; +import io.wdd.func.oss.oracle.config.OracleOSSConfiguration; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * https://docs.oracle.com/en-us/iaas/Content/Object/Tasks/s3compatibleapi.htm#usingAPI + */ +@Service +@Slf4j +public class OracleOSSCoreServiceImpl implements OracleOSSCoreService { + + + @Resource + OracleOSSConfiguration ossConfiguration; + + + @Override + public void listBucketList() { + + AmazonS3 amazonS3 = ossConfiguration.ALL_S3_CLIENT.get(0); + + List buckets = amazonS3.listBuckets(); + + + System.out.println("buckets = " + buckets); + } +} diff --git a/server/src/main/java/io/wdd/func/xray/result/test.json b/server/src/main/java/io/wdd/func/xray/result/test.json new file mode 100644 index 0000000..39a3747 --- /dev/null +++ b/server/src/main/java/io/wdd/func/xray/result/test.json @@ -0,0 +1,465 @@ +{ + "log": { + "access": "/var/log/xray/access.log", + "error": "/var/log/xray/error.log", + "loglevel": "warning" + }, + "inbounds": [ + { + "protocol": "vmess", + "listen": "0.0.0.0", + "port": 19999, + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "response": { + "version": "1.1", + "status": "200", + "reason": "Accept", + "headers": { + "Content-Type": [ + "application/octet-stream", + "video/mpeg" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "settings": { + "clients": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ], + "disableInsecureEncryption": false + } + } + ], + "outbounds": [ + { + "protocol": "vmess", + "settings": { + "vnext": [ + { + "address": "140.238.30.110", + "port": 19999, + "users": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ] + } + ] + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "request": { + "version": "1.1", + "method": "GET", + "path": [ + "/news/", + "/finance/", + "/sports/", + "weathers" + ], + "headers": { + "Host": [ + "www.baidu.com", + "www.google.com", + "www.bing.com", + "www.github.com" + ], + "User-Agent": [ + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", + "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46" + ], + "Accept-Encoding": [ + "gzip", + "deflate" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "mux": { + "enabled": false, + "concurrency": -1 + } + }, + { + "protocol": "freedom" + }, + { + "protocol": "blackhole", + "tag": "block" + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "inboundTag": [ + "tc-sh->seoul-2->tokyo-2->phoenix-2" + ], + "outboundTag": "tc-sh->seoul-2->tokyo-2->phoenix-2" + } + ] + } +}, +{ + "log": { + "access": "/var/log/xray/access.log", + "error": "/var/log/xray/error.log", + "loglevel": "warning" + }, + "inbounds": [ + { + "protocol": "vmess", + "listen": "0.0.0.0", + "port": 19999, + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "response": { + "version": "1.1", + "status": "200", + "reason": "Accept", + "headers": { + "Content-Type": [ + "application/octet-stream", + "video/mpeg" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "settings": { + "clients": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ], + "disableInsecureEncryption": false + } + } + ], + "outbounds": [ + { + "protocol": "vmess", + "settings": { + "vnext": [ + { + "address": "140.238.52.228", + "port": 19999, + "users": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ] + } + ] + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "request": { + "version": "1.1", + "method": "GET", + "path": [ + "/news/", + "/finance/", + "/sports/", + "weathers" + ], + "headers": { + "Host": [ + "www.baidu.com", + "www.google.com", + "www.bing.com", + "www.github.com" + ], + "User-Agent": [ + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", + "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46" + ], + "Accept-Encoding": [ + "gzip", + "deflate" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "mux": { + "enabled": false, + "concurrency": -1 + } + }, + { + "protocol": "freedom" + }, + { + "protocol": "blackhole", + "tag": "block" + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "inboundTag": [ + "tc-sh->seoul-2->tokyo-2->phoenix-2" + ], + "outboundTag": "tc-sh->seoul-2->tokyo-2->phoenix-2" + } + ] + } +} +----------------------------------- +{ + "log": { + "access": "/var/log/xray/access.log", + "error": "/var/log/xray/error.log", + "loglevel": "warning" + }, + "inbounds": [ + { + "protocol": "vmess", + "listen": "0.0.0.0", + "port": 19999, + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "response": { + "version": "1.1", + "status": "200", + "reason": "Accept", + "headers": { + "Content-Type": [ + "application/octet-stream", + "video/mpeg" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "settings": { + "clients": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ], + "disableInsecureEncryption": false + } + } + ], + "outbounds": [ + { + "protocol": "vmess", + "settings": { + "vnext": [ + { + "address": "129.146.171.163", + "port": 19999, + "users": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ] + } + ] + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "request": { + "version": "1.1", + "method": "GET", + "path": [ + "/news/", + "/finance/", + "/sports/", + "weathers" + ], + "headers": { + "Host": [ + "www.baidu.com", + "www.google.com", + "www.bing.com", + "www.github.com" + ], + "User-Agent": [ + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", + "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46" + ], + "Accept-Encoding": [ + "gzip", + "deflate" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "mux": { + "enabled": false, + "concurrency": -1 + } + }, + { + "protocol": "freedom" + }, + { + "protocol": "blackhole", + "tag": "block" + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "inboundTag": [ + "tc-sh->seoul-2->tokyo-2->phoenix-2" + ], + "outboundTag": "tc-sh->seoul-2->tokyo-2->phoenix-2" + } + ] + } +} +----------------------------------- +{ + "inbounds": [ + { + "protocol": "vmess", + "listen": "0.0.0.0", + "port": 19999, + "streamSettings": { + "tcpSettings": { + "header": { + "type": "http", + "response": { + "version": "1.1", + "status": "200", + "reason": "Accept", + "headers": { + "Content-Type": [ + "application/octet-stream", + "video/mpeg" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Connection": [ + "keep-alive" + ], + "Pragma": "no-cache" + } + } + } + } + }, + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2", + "settings": { + "clients": [ + { + "id": "402df401-6a63-444b-9386-f3b6d8e1b769", + "email": "tc-sh->seoul-2->tokyo-2->phoenix-2@octopus.io", + "level": 0, + "alterId": 23 + } + ], + "disableInsecureEncryption": false + } + } + ], + "outbounds": [ + { + "protocol": "freedom", + "tag": "tc-sh->seoul-2->tokyo-2->phoenix-2" + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "inboundTag": [ + "tc-sh->seoul-2->tokyo-2->phoenix-2" + ], + "outboundTag": "tc-sh->seoul-2->tokyo-2->phoenix-2" + } + ] + } +}