[ server ] [ oss ]- 新增对象存储的内容,使用AWS S3 JavaSDK 实现

This commit is contained in:
IceDerce
2023-02-11 19:15:38 +08:00
parent caa13293eb
commit ac4c0399c1
8 changed files with 654 additions and 13 deletions

View File

@@ -26,11 +26,6 @@
<version>${project.parent.version}</version>
</dependency>
<!--<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>-->
<!-- add in 2023-02-08 needed for some operation -->
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -57,6 +52,13 @@
<scope>runtime</scope>
</dependency>-->
<!-- 添加于 2023-02-11 用于Oracle Object Storage-->
<!-- https://docs.oracle.com/en-us/iaas/tools/java/3.3.0/ -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.405</version>
</dependency>
<!--mybatis-plus的依赖-->
<dependency>
@@ -79,25 +81,24 @@
<version>8.0.30</version>
</dependency>
<!--<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<!--<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependency>-->
</dependencies>
</dependencyManagement>

View File

@@ -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(" = ");
}
}

View File

@@ -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("结束!");
}
}

View File

@@ -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<AmazonS3> 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
);
}
}

View File

@@ -0,0 +1,6 @@
package io.wdd.func.oss.oracle.service;
public interface OracleOSSCoreService {
void listBucketList();
}

View File

@@ -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<Bucket> buckets = amazonS3.listBuckets();
System.out.println("buckets = " + buckets);
}
}

View File

@@ -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"
}
]
}
}