百度智能云

All Product Document

          Auto Scaling

          AsGroupClient

          AsGroupClient is the client of the Auto Scaling Group service, which provides a series of methods for developers to interact with the AsGroup service.

          Create AsGroupClient

          Access AsGroup through AK/SK

          You can create a AsGroupClient by referring to the following code:

          public class Sample { 
              public static void main(String[] args) { 
                  String ACCESS_KEY_ID = <your-access-key-id>;                    // User's Access Key ID 
                  String SECRET_ACCESS_KEY = <your-secret-access-key>;            // User's Secret Access Key 
          
                  // Initialize an AsGroupClient 
                  AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
                  config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY)); 
                  AsGroupClient client = new AsGroupClient(config); 
              } 
          } 

          In the above codes, the variables ACCESS_KEY_ID and SECRET_ACCESS_KEY are allocated to the user by the system, both of which are strings to identify the user, and are used for signature authentication to access BCC. Among them, ACCESS_KEY_ID corresponds to the "Access Key ID" in the console, and SECRET_ACCESS_KEY corresponds to the "Access Key Secret" in the console. Please refer to the "Operation Guide Get ACCESSKEY".

          The above method uses the default domain name as the service address of the AsGroup. If the user needs to specify the domain name himself, he can specify it by passing in the ENDPOINT parameter.

          String ACCESS_KEY_ID = <your-access-key-id>;                    // User's Access Key ID 
          String SECRET_ACCESS_KEY = <your-secret-access-key>;            // User's Secret Access Key 
          String ENDPOINT = <domain-name>;                                // You specify your own name 
          
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY)); 
          config.setEndpoint(ENDPOINT); 
          AsGroupClient client = new AsGroupClient(config); 

          Note: The ENDPOINT parameter can only be defined with the specified domain name of the areas included. If not specified, it defaults to the Beijing area http://as.bj.baidubce.com. Baidu AI Cloud currently has opened access to multi-region support, please refer to Region Selection Introduction.

          Currently, it supports four regions: "North China-Beijing", "South China-Guangzhou", "East China-Suzhou" and "Central China-Wuhan". Beijing: http://as.bj.baidubce.com, Guangzhou region http://as.gz.baidubce.com, Suzhou region http://as.su.baidubce.com, Wuhan region: http://as.fwh.baidubce.com

          Configure HTTPS Protocol to Access AsGroup

          AsGroup supports HTTPS, and you can access to AsGroup service with HTTP in AsGroup Java SDK with the following 2 methods:

          • Indicate https: in endpoint;
          String endpoint = "http://as.bj.baidubce.com"; 
          String ak = "ak"; 
          String sk = "sk"; 
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          config.setCredentials(new DefaultBceCredentials(ak, sk)); 
          AsGroupClient client = new AsGroupClient(config); 
          • Set the https protocol by calling the setProtocol method:
          String endpoint = "as.bj.baidubce.com"; // endpoint does not contain protocol 
          String ak = "ak"; 
          String sk = "sk"; 
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          config.setCredentials(new DefaultBceCredentials(ak, sk)); 
          config.setEndpoint(ENDPOINT); 
          config.setProtocol(Protocol.HTTPS); // if it is not specified, use http 
          AsGroupClient client = new AsGroupClient(config); 

          Note: If protocol is indicated in endpoint, the entry in endpoint takes effect, and a separate call to setProtocol () does not work.

          String endpoint = "http://as.bj.baidubce.com"; 
          String ak = "ak"; 
          String sk = "sk"; 
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          config.setCredentials(new DefaultBceCredentials(ak, sk)); 
          config.setEndpoint(ENDPOINT);    
          config.setProtocol(Protocol.HTTPS); // it has been indicated in endpoint that this is an invalid operation, which also applies to http. 
          AsGroupClient client = new AsGroupClient(config); 

          Configure AsGroupClient

          If you need to configure some detailed parameters of the AsGroupClient, introduce into the AsGroupClientConfiguration object when the AsGroupClient is constructed. AsGroupClientConfiguration is the configuration class of AsGroup service, and it can configure agent, maximum connection number and other parameters for the client.

          Use Agent

          The following codes enable client to use agent to access AsGroup service:

          String ACCESS_KEY_ID = <your-access-key-id>;                    // User's Access Key ID 
          String SECRET_ACCESS_KEY = <your-secret-access-key>;            // User's Secret Access Key 
          String ENDPOINT = <domain-name>;                                // You specify your own name 
          
          // Create an instance of AsGroupClientConfiguration 
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          
          // Configure the agent as local 8080 port 
          config.setProxyHost("127.0.0.1"); 
          config.setProxyPort(8080); 
          
          // Create AsGroup client 
          config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY)); 
          config.setEndpoint(ENDPOINT); 
          AsGroupClient client = new AsGroupClient(config); 

          Using the code segment above, all operations of client are executed as an agent via the 8080 port of 127.0.0.1 address. For the agent with user authentication, the following code segment can be used to configure username and password:

          // Create an instance of AsGroupClientConfiguration 
          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          
          // Configure the agent as local 8080 port 
          config.setProxyHost("127.0.0.1"); 
          config.setProxyPort(8080); 
          
          // Set username and password 
          config.setProxyUsername(<username>);                              // User name 
          config.setProxyPassword(<password>);                              // Password 

          Set Network Parameters

          Users can set basic network parameters with AsGroupClientConfiguration:

          AsGroupClientConfiguration config = new AsGroupClientConfiguration(); 
          
          // Set the maximum number of HTTP connections to 10. 
          config.setMaxConnections(10); 
          
          // Set TCP connection timeout to 5,000 milliseconds 
          config.setConnectionTimeout(5000); 
          
          // Set the timeout for socket data transmission to 2,000 milliseconds 
          config.setSocketTimeout(2000); 

          Parameter Description

          All parameters that can be specified through AsGroupClientConfiguration are shown in the following table:

          Parameter Description
          User agent (UserAgent), referring to the HTTP User-Agent header
          Protocol Connection protocol type
          ProxyDomain Windows domain name for access to NTLM authenticated proxy server
          ProxyHost Proxy server host address
          ProxyPort Proxy server port
          ProxyUsername User name for proxy server authentication
          ProxyPassword Password for proxy server authentication
          ProxyPreemptiveAuthenticationEnabled Whether to set up user agent authentication
          ProxyWorkstation Windows workstation name of the NTLM proxy server
          LocalAddress Local address
          ConnectionTimeoutInMillis Timeout for establishing a connection (unit: millisecond)
          SocketTimeoutInMillis Timeout for transmitting data over open connections (unit: millisecond)
          MaxConnections Maximum number of HTTP connections allowed to open
          RetryPolicy Connection retry policy
          SocketBufferSizeInBytes Socket buffer size
          StreamBufferSize Stream file buffer size
          Previous
          SDK Installation Toolkit
          Next
          Scaling Group Interface