Skip to content

Commit b8e4dda

Browse files
author
codezhang
committed
完成CreateVServer
1 parent ae1b5ab commit b8e4dda

5 files changed

Lines changed: 293 additions & 6 deletions

File tree

ucloud-sdk-java-ulb/src/main/java/cn/ucloud/client/DefaultULBClient.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,18 @@ public void updateULBAttribute(UpdateULBAttributeParam param, UcloudHandler hand
8787
}
8888

8989
@Override
90-
public BaseResponseResult createVServer(BaseRequestParam param) throws Exception {
91-
return null;
90+
public CreateVServerResult createVServer(CreateVServerParam param) throws Exception {
91+
UcloudHttp http = new UcloudHttpImpl(CreateVServerResult.class);
92+
CreateVServerResult result = (CreateVServerResult) http.doGet(param, config, null);
93+
return result;
9294
}
9395

9496
@Override
95-
public void createVServer(BaseRequestParam param, UcloudHandler handler, Boolean... asyncFlag) {
96-
97+
public void createVServer(CreateVServerParam param, UcloudHandler handler, Boolean... asyncFlag) {
98+
UcloudHttp http = new UcloudHttpImpl(CreateVServerResult.class);
99+
try {
100+
http.doGet(param, config, handler,asyncFlag);
101+
} catch (Exception e) { }
97102
}
98103

99104
@Override

ucloud-sdk-java-ulb/src/main/java/cn/ucloud/client/ULBClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public interface ULBClient {
3636
void updateULBAttribute(UpdateULBAttributeParam param,UcloudHandler handler,Boolean... asyncFlag);
3737

3838

39-
BaseResponseResult createVServer(BaseRequestParam param) throws Exception;
39+
CreateVServerResult createVServer(CreateVServerParam param) throws Exception;
4040

41-
void createVServer(BaseRequestParam param,UcloudHandler handler,Boolean... asyncFlag);
41+
void createVServer(CreateVServerParam param,UcloudHandler handler,Boolean... asyncFlag);
4242

4343

4444
BaseResponseResult describeVServer(BaseRequestParam param) throws Exception;
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package cn.ucloud.model;
2+
3+
import cn.ucloud.annotation.UcloudParam;
4+
import cn.ucloud.pojo.BaseRequestParam;
5+
6+
import javax.validation.constraints.NotEmpty;
7+
8+
/**
9+
* @description: 创建VServer
10+
* 创建VServer实例,定义监听的协议和端口以及负载均衡算法
11+
* @author: codezhang
12+
* @date: 2018-09-19 11:48
13+
**/
14+
15+
public class CreateVServerParam extends BaseRequestParam {
16+
17+
/**
18+
* require
19+
* 地域。 参见 [地域和可用区列表](../summary/regionlist.html)
20+
*/
21+
@NotEmpty(message = "region can not be empty")
22+
@UcloudParam("Region")
23+
private String region;
24+
25+
/**
26+
* require 负载均衡实例ID
27+
*/
28+
@UcloudParam("ULBId")
29+
@NotEmpty(message = "ulbId can not be empty")
30+
private String ulbId;
31+
32+
/**
33+
* optional
34+
* VServer实例名称,默认为"VServer"
35+
*/
36+
@UcloudParam("VServerName")
37+
private String vserverName;
38+
39+
/**
40+
* optional 监听器类型,枚举值为:
41+
* RequestProxy -> 请求代理;
42+
* PacketsTransmit -> 报文转发;
43+
* 默认为"RequestProxy"
44+
*/
45+
@UcloudParam("ListenType")
46+
private String listenType;
47+
48+
/**
49+
* optional VServer实例的协议,
50+
* 请求代理模式下有 HTTP、HTTPS、TCP,报文转发下有 TCP,UDP。
51+
* 默认为“HTTP"
52+
*/
53+
@UcloudParam("Protocol")
54+
private String protocol;
55+
56+
/**
57+
* optional VServer后端端口,取值范围[1-65535];默认值为80
58+
*/
59+
@UcloudParam("FrontendPort")
60+
private Integer frontendPort;
61+
62+
/**
63+
* optional
64+
* VServer负载均衡模式,枚举值:
65+
* Roundrobin -> 轮询;
66+
* Source -> 源地址;
67+
* ConsistentHash -> 一致性哈希;
68+
* SourcePort -> 源地址(计算端口);
69+
* ConsistentHashPort -> 一致性哈希(计算端口)。
70+
* ConsistentHash,SourcePort,ConsistentHashPort 只在报文转发中使用;
71+
* Roundrobin和Source在请求代理和报文转发中使用。
72+
* 默认为:"Roundrobin"
73+
*/
74+
@UcloudParam("Method")
75+
private String method;
76+
77+
/**
78+
* optional VServer会话保持方式,默认关闭会话保持。
79+
* 枚举值:
80+
* None -> 关闭;
81+
* ServerInsert -> 自动生成KEY;
82+
* UserDefined -> 用户自定义KEY。
83+
*/
84+
@UcloudParam("PersistenceType")
85+
private String persistenceType;
86+
87+
/**
88+
* optional 根据PersistenceType确认;
89+
* None和ServerInsert: 此字段无意义;
90+
* UserDefined:此字段传入自定义会话保持String
91+
*/
92+
@UcloudParam("PersistenceInfo")
93+
private String persistenceInfo;
94+
95+
/**
96+
* optional
97+
* ListenType为RequestProxy时表示空闲连接的回收时间,单位:秒,取值范围:时(0,86400],默认值为60;
98+
* ListenType为PacketsTransmit时表示连接保持的时间,单位:秒,取值范围:[60,900],0 表示禁用连接保持
99+
*/
100+
@UcloudParam("ClientTimeout")
101+
private Integer clientTimeout;
102+
103+
/**
104+
* optional
105+
* 健康检查类型,枚举值:Port -> 端口检查;Path -> 路径检查;
106+
*/
107+
@UcloudParam("MonitorType")
108+
private String monitorType;
109+
110+
public CreateVServerParam(@NotEmpty(message = "region can not be empty") String region,
111+
@NotEmpty(message = "ulbId can not be empty") String ulbId) {
112+
super("CreateVServer");
113+
this.region = region;
114+
this.ulbId = ulbId;
115+
}
116+
117+
public String getRegion() {
118+
return region;
119+
}
120+
121+
public void setRegion(String region) {
122+
this.region = region;
123+
}
124+
125+
public String getUlbId() {
126+
return ulbId;
127+
}
128+
129+
public void setUlbId(String ulbId) {
130+
this.ulbId = ulbId;
131+
}
132+
133+
public String getVserverName() {
134+
return vserverName;
135+
}
136+
137+
public void setVserverName(String vserverName) {
138+
this.vserverName = vserverName;
139+
}
140+
141+
public String getListenType() {
142+
return listenType;
143+
}
144+
145+
public void setListenType(String listenType) {
146+
this.listenType = listenType;
147+
}
148+
149+
public String getProtocol() {
150+
return protocol;
151+
}
152+
153+
public void setProtocol(String protocol) {
154+
this.protocol = protocol;
155+
}
156+
157+
public Integer getFrontendPort() {
158+
return frontendPort;
159+
}
160+
161+
public void setFrontendPort(Integer frontendPort) {
162+
this.frontendPort = frontendPort;
163+
}
164+
165+
public String getMethod() {
166+
return method;
167+
}
168+
169+
public void setMethod(String method) {
170+
this.method = method;
171+
}
172+
173+
public String getPersistenceType() {
174+
return persistenceType;
175+
}
176+
177+
public void setPersistenceType(String persistenceType) {
178+
this.persistenceType = persistenceType;
179+
}
180+
181+
public String getPersistenceInfo() {
182+
return persistenceInfo;
183+
}
184+
185+
public void setPersistenceInfo(String persistenceInfo) {
186+
this.persistenceInfo = persistenceInfo;
187+
}
188+
189+
public Integer getClientTimeout() {
190+
return clientTimeout;
191+
}
192+
193+
public void setClientTimeout(Integer clientTimeout) {
194+
this.clientTimeout = clientTimeout;
195+
}
196+
197+
public String getMonitorType() {
198+
return monitorType;
199+
}
200+
201+
public void setMonitorType(String monitorType) {
202+
this.monitorType = monitorType;
203+
}
204+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cn.ucloud.model;
2+
3+
import cn.ucloud.pojo.BaseResponseResult;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
/**
7+
* @description:
8+
* @author: codezhang
9+
* @date: 2018-09-19 11:58
10+
**/
11+
12+
public class CreateVServerResult extends BaseResponseResult {
13+
14+
/**
15+
* VServer实例的Id
16+
*/
17+
@SerializedName("VServerId")
18+
private String vserverId;
19+
20+
public String getVserverId() {
21+
return vserverId;
22+
}
23+
24+
public void setVserverId(String vserverId) {
25+
this.vserverId = vserverId;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "CreateVServerResult{" +
31+
"vserverId='" + vserverId + '\'' +
32+
", retCode=" + retCode +
33+
", action='" + action + '\'' +
34+
", message='" + message + '\'' +
35+
'}';
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.ucloud.client;
2+
3+
import cn.ucloud.model.CreateVServerParam;
4+
import cn.ucloud.model.CreateVServerResult;
5+
import cn.ucloud.pojo.Account;
6+
import cn.ucloud.pojo.ULBConfig;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
/**
11+
* @description:
12+
* @author: codezhang
13+
* @date: 2018-09-19 12:00
14+
**/
15+
public class CreateVServerTest {
16+
17+
private ULBClient client;
18+
19+
private CreateVServerParam param;
20+
21+
@Before
22+
public void initData() {
23+
client = new DefaultULBClient(new ULBConfig(
24+
new Account(System.getenv("UcloudPrivateKey"),
25+
System.getenv("UcloudPublicKey"),
26+
System.getenv("UcloudPassword"))));
27+
param = new CreateVServerParam("cn-bj2","ulb-0kawkr");
28+
param.setVserverName("sdk-java-vserver");
29+
param.setProjectId("org-4nfe1i");
30+
}
31+
32+
@Test
33+
public void createVServer() {
34+
try {
35+
CreateVServerResult vServer = client.createVServer(param);
36+
System.out.println(vServer);
37+
} catch (Exception e) {
38+
e.printStackTrace();
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)