Skip to content

Commit

Permalink
v0.10.155
Browse files Browse the repository at this point in the history
  • Loading branch information
friendshipbridge committed Mar 24, 2021
1 parent f9ab708 commit 411fc54
Show file tree
Hide file tree
Showing 42 changed files with 2,137 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Release Notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
发行说明:记录每次SDK更新的说明,最新版本的SDK包含以前所有版本的更新内容。
---------------------------------------------------------------------
【版本:v0.10.155】
涉及产品:BES, 支持升配集群配置

【版本:v0.10.154】
涉及产品:VOD, 修复统计接口反序列化赋值异常问题

【版本:v0.10.153】
涉及产品:IOTHUB, 新增IoTCore设备和模版相关接口

【版本:v0.10.152】
涉及产品:MCT, 新增转码输出信息到Job查询接口

【版本:v0.10.151】
涉及产品:SMS, 新增签名、模板列表查询接口

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.baidubce</groupId>
<artifactId>bce-java-sdk</artifactId>
<version>0.10.151</version>
<version>0.10.155</version>
<name>bce-sdk-java</name>
<description>The BCE SDK for Java provides Java APIs for all of BCE services.</description>
<url>http://bce.baidu.com/sdk/index.html</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ public static class ModuleDesc {
@JsonProperty
private int desireInstanceNum;

@JsonProperty
private DiskSlotInfo diskSlotInfo;

public DiskSlotInfo getDiskSlotInfo() {
return diskSlotInfo;
}

public void setDiskSlotInfo(DiskSlotInfo diskSlotInfo) {
this.diskSlotInfo = diskSlotInfo;
}

public String getType() {
return type;
}
Expand Down Expand Up @@ -170,6 +181,12 @@ public String toJson(String region) throws IOException {
jsonGenerator.writeNumberField("desireInstanceNum", module.getDesireInstanceNum());
jsonGenerator.writeStringField("version", module.getVersion());
jsonGenerator.writeStringField("type", module.getType());
if (module.getDiskSlotInfo() != null) {
jsonGenerator.writeObjectFieldStart("diskSlotInfo");
jsonGenerator.writeStringField("type", module.getDiskSlotInfo().getType());
jsonGenerator.writeNumberField("size", module.getDiskSlotInfo().getSize());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
Expand Down
276 changes: 276 additions & 0 deletions src/main/java/com/baidubce/services/endpoint/EndpointClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
/*
* Copyright (C) 2021 Baidu, Inc. All Rights Reserved.
*/
package com.baidubce.services.endpoint;

import static com.baidubce.util.Validate.checkStringNotEmpty;
import static com.baidubce.util.Validate.checkMultyParamsNotBothEmpty;
import static com.google.common.base.Preconditions.checkNotNull;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.baidubce.AbstractBceClient;
import com.baidubce.BceClientConfiguration;
import com.baidubce.BceClientException;
import com.baidubce.http.Headers;
import com.baidubce.http.HttpMethodName;
import com.baidubce.http.handler.BceErrorResponseHandler;
import com.baidubce.http.handler.BceJsonResponseHandler;
import com.baidubce.http.handler.BceMetadataResponseHandler;
import com.baidubce.http.handler.HttpResponseHandler;
import com.baidubce.internal.InternalRequest;
import com.baidubce.internal.RestartableInputStream;
import com.baidubce.model.AbstractBceRequest;
import com.baidubce.model.AbstractBceResponse;
import com.baidubce.services.endpoint.model.CreateEndpointRequest;
import com.baidubce.services.endpoint.model.CreateEndpointResponse;
import com.baidubce.services.endpoint.model.Endpoint;
import com.baidubce.services.endpoint.model.GetEndpointRequest;
import com.baidubce.services.endpoint.model.ListEndpointRequest;
import com.baidubce.services.endpoint.model.ListEndpointResponse;
import com.baidubce.services.endpoint.model.ModifyEndpointRequest;
import com.baidubce.services.endpoint.model.ReleaseEndpointRequest;
import com.baidubce.services.endpoint.model.ServiceRequest;
import com.baidubce.services.endpoint.model.ServiceResponse;
import com.baidubce.util.HttpUtils;
import com.baidubce.util.JsonUtils;
import com.google.common.base.Strings;

/**
* Created by XingChunyang
* Date: 2021/01/21.
*/

/**
* Provides the client for accessing the Baidu Cloud network Service ENDPOINT.
*/
public class EndpointClient extends AbstractBceClient {
private static final Logger LOGGER = LoggerFactory.getLogger(EndpointClient.class);

private static final String VERSION = "v1";
private static final String ENDPOINT_PREFIX = "endpoint";

/**
* Responsible for handling httpResponses from all network service calls.
*/
private static final HttpResponseHandler[] endpointHandlers = new HttpResponseHandler[] {
new BceMetadataResponseHandler(),
new BceErrorResponseHandler(),
new BceJsonResponseHandler()
};

public EndpointClient() {
this(new EndpointClientConfiguration());
}

/**
* Constructs a new InstanceClient to invoke service methods on endpoint instance.
*
* @param clientConfiguration The BCE client configuration options.
*/
public EndpointClient(BceClientConfiguration clientConfiguration) {
super(clientConfiguration, endpointHandlers);
}

/**
* Creates and initializes a new request object for the specified network resource. This method is responsible
* for determining the right way to address resources.
*
* @param bceRequest The original request, as created by the user.
* @param httpMethod The HTTP method to use when sending the request.
* @param pathVariables The optional variables used in the URI path.
*
* @return A new request object, populated with endpoint, resource path, ready for callers to populate
* any additional headers or parameters, and execute.
*/
private InternalRequest createRequest(AbstractBceRequest bceRequest, HttpMethodName httpMethod,
String... pathVariables) {
List<String> path = new ArrayList<String>();

path.add(VERSION);

if (pathVariables != null) {
for (String pathVariable : pathVariables) {
path.add(pathVariable);
}
}
URI uri = HttpUtils.appendUri(this.getEndpoint(), path.toArray(new String[path.size()]));
InternalRequest request = new InternalRequest(httpMethod, uri);
request.setCredentials(bceRequest.getRequestCredentials());
return request;
}

/**
* The method to fill the internalRequest's content field with bceRequest.
* Only support HttpMethodName.POST or HttpMethodName.PUT
*
* @param internalRequest A request object, populated with endpoint, resource path, ready for callers to populate
* any additional headers or parameters, and execute.
* @param bceRequest The original request, as created by the user.
*/
private void fillPayload(InternalRequest internalRequest, AbstractBceRequest bceRequest) {
if (internalRequest.getHttpMethod() == HttpMethodName.POST
|| internalRequest.getHttpMethod() == HttpMethodName.PUT) {
String strJson = JsonUtils.toJsonString(bceRequest);
byte[] requestJson = null;
try {
requestJson = strJson.getBytes(DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new BceClientException("Unsupported encode.", e);
}
internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(requestJson.length));
internalRequest.addHeader(Headers.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
internalRequest.setContent(RestartableInputStream.wrap(requestJson));
}
}

/**
* The default method to generate the random String for clientToken if the optional parameter clientToken
* is not specified by the user.
* <p/>
* The default algorithm is using {@link UUID} to generate a random UUID,
*
* @return An random String generated by {@link UUID}.
*/
private String generateClientToken() {
return UUID.randomUUID().toString();
}

/**
* @return Return a list of service owned by the authenticated user.
*/
public ServiceResponse listService() {
InternalRequest internalRequest =
this.createRequest(new ServiceRequest(), HttpMethodName.GET, ENDPOINT_PREFIX, "publicService");
return this.invokeHttpClient(internalRequest, ServiceResponse.class);
}


/**
* Create an endpoint with the specified options.
* You must fill the field of clientToken,which is especially for keeping idempotent.
*
* @param request he request containing all options for creating a endpoint.
*
* @return
*/
public CreateEndpointResponse createEndpoint(CreateEndpointRequest request) {
checkNotNull(request, "request should not be null.");
if (Strings.isNullOrEmpty(request.getClientToken())) {
request.setClientToken(generateClientToken());
}
checkNotNull(request.getBilling(), "billing should not be empty");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.POST, ENDPOINT_PREFIX);
internalRequest.addParameter("clientToken", request.getClientToken());
fillPayload(internalRequest, request);
return invokeHttpClient(internalRequest, CreateEndpointResponse.class);
}

/**
* Return a list of endpoints owned by the authenticated user.
*
* @param request The request containing all options for listing own's endpoint.
*
* @return The response containing a list of endpoints owned by the authenticated user.
*/
public ListEndpointResponse listEndpoint(ListEndpointRequest request) {
checkNotNull(request, "request should not be null.");
checkStringNotEmpty(request.getVpcId(), "vpcId should not be empty");
InternalRequest internalRequest = this.createRequest(request, HttpMethodName.GET, ENDPOINT_PREFIX);
if (StringUtils.isNotBlank(request.getMarker())) {
internalRequest.addParameter("marker", request.getMarker());
}
if (request.getMaxKeys() > 0) {
internalRequest.addParameter("maxKeys", String.valueOf(request.getMaxKeys()));
}
internalRequest.addParameter("vpcId", request.getVpcId());
if (StringUtils.isNotBlank(request.getName())) {
internalRequest.addParameter("name", request.getName());
}
if (StringUtils.isNotBlank(request.getIpAddress())) {
internalRequest.addParameter("ipAddress", request.getIpAddress());
}
if (StringUtils.isNotBlank(request.getStatus())) {
internalRequest.addParameter("status", request.getStatus());
}
if (StringUtils.isNotBlank(request.getSubnetId())) {
internalRequest.addParameter("subnetId", request.getSubnetId());
}
if (StringUtils.isNotBlank(request.getService())) {
internalRequest.addParameter("service", request.getService());
}
return invokeHttpClient(internalRequest, ListEndpointResponse.class);
}

/**
* Get the detail information of specified endpoint.
*
* @param endpointId The id of the endpoint.
*
* @return A Endpoint detail model for the endpointId.
*/
public Endpoint getEndpoint(String endpointId) {
checkStringNotEmpty(endpointId, "endpointId should not be empty.");
GetEndpointRequest request = new GetEndpointRequest().withEndpointId(endpointId);
return getEndpoint(request);
}

/**
* Get the detail information of specified Endpoint.
*
* @param request The request of the network.
*
* @return A Endpoint detail model for the request.
*/
public Endpoint getEndpoint(GetEndpointRequest request) {
checkNotNull(request, "request should not be null.");
checkStringNotEmpty(request.getEndpointId(), "endpointId should not be empty.");
InternalRequest internalRequest = this.createRequest(
request, HttpMethodName.GET, ENDPOINT_PREFIX, request.getEndpointId());
return this.invokeHttpClient(internalRequest, Endpoint.class);
}

/**
* Modifying the name of the specified endpoint.
*
* @param request The request containing all options for modifying the endpoint name/description;
*/
public void modifyEndpoint(ModifyEndpointRequest request) {
checkNotNull(request, "request should not be null.");
checkStringNotEmpty(request.getEndpointId(), "endpointId should not be null.");
checkMultyParamsNotBothEmpty(Arrays.asList(request.getName(), request.getDescription()),
"name and description should not be all null.");
if (Strings.isNullOrEmpty(request.getClientToken())) {
request.setClientToken(this.generateClientToken());
}
InternalRequest internalRequest = this.createRequest(
request, HttpMethodName.PUT, ENDPOINT_PREFIX, request.getEndpointId());
fillPayload(internalRequest, request);
this.invokeHttpClient(internalRequest, AbstractBceResponse.class);
}

/**
* Releasing specified endpoint.
*
* @param request The request containing all options for releasing the specified endpoint.
*/
public void releaseEndpoint(ReleaseEndpointRequest request) {
checkNotNull(request, "request should not be null.");
checkStringNotEmpty(request.getEndpointId(), "endpointId should not be empty.");
if (Strings.isNullOrEmpty(request.getClientToken())) {
request.setClientToken(this.generateClientToken());
}
InternalRequest internalRequest = this.createRequest(
request, HttpMethodName.DELETE, ENDPOINT_PREFIX, request.getEndpointId());
this.invokeHttpClient(internalRequest, AbstractBceResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (C) 2021 Baidu, Inc. All Rights Reserved.
*/
package com.baidubce.services.endpoint;

import com.baidubce.BceClientConfiguration;

/**
* Created by XingChunyang
* Date: 2021/01/21.
*/

public class EndpointClientConfiguration extends BceClientConfiguration {
}
Loading

0 comments on commit 411fc54

Please sign in to comment.