All Products
Search
Document Center

Optimization Solver:Optimization Solver console SDKs

Last Updated:Aug 17, 2023

You can use Optimization Solver console SDKs to implement some features of the Optimization Solver console. Only APIs for querying license-related information are provided and used in specific scenarios.

Note

You can use Optimization Solver console SDKs to query the information about purchased licenses and license usage. If the features are not required, you do not need to download the Optimization Solver console SDKs.

SDKs

Optimization Solver console SDKs for a variety of programming languages such as Java, Python3, Go, and C++ are available. You can select an Optimization Solver console SDK based on your business requirements.

Programming language

GitHub URL

GitHub document

Java

alibabacloud-java-sdk

README.md

Go

alibabacloud-go-sdk

README.md

Python3

alibabacloud-python-sdk

README.md

C++

alibabacloud-cpp-sdk

README.md

Optimization Solver console SDK for Java

Features provided by query APIs are simple. The following section describes Optimization Solver console SDK for Java. In the following example, the SDK depends on the fastjson package. We recommend that you use fastjson package V1.2.83.

<dependency>
     <groupId>com.alibaba</groupId>
     <artifactId>fastjson</artifactId>
     <version>1.2.83</version>
</dependency>

1. Check whether services in Optimization Solver are activated

package com.alibaba.mind.opt.sdk;

import com.alibaba.fastjson.JSON;

import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOpenStatusResponse;
import com.aliyun.teaopenapi.models.Config;

public class GetOpenStatusExample {

    public static void main(String[] args) {
        try {
            Config authConfig = new Config();
            /**
             * The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Object Storage Service (OSS) is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
             * In this example, the AccessKey ID and the AccessKey secret are set to environment variables. You can save the AccessKey ID and the AccessKey secret in the configuration file based on your business requirements. 
             * We recommend that you do not save the AccessKey ID and the AccessKey secret in code. Saving the AccessKey ID and the AccessKey secret in code may lead to the leakage of the AccessKey pair.
             */
            authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
            authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
            /**
             * Replace the sample endpoint with the actual endpoint of Optimization Solver.
             */
            authConfig.endpoint = "opt.cn-beijing.aliyuncs.com";
            Client client = new Client(authConfig);
            GetOpenStatusResponse getOpenStatusResponse = client.getOpenStatus();
            System.out.println(JSON.toJSONString(getOpenStatusResponse.getHeaders()));
            System.out.println(JSON.toJSONString(getOpenStatusResponse.getBody()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2. Query the information about purchased licenses

package com.alibaba.mind.opt.sdk;

import com.alibaba.fastjson.JSON;

import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOrderInfoRequest;
import com.aliyun.opt20210730.models.GetOrderInfoResponse;
import com.aliyun.opt20210730.models.GetOrderUsageRequest;
import com.aliyun.opt20210730.models.GetOrderUsageResponse;
import com.aliyun.teaopenapi.models.Config;

public class GetOrderInfoExample {

    public static void main(String[] args) {
        try {
            Config authConfig = new Config();
            /**
             * The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
             * In this example, the AccessKey ID and the AccessKey secret are set to environment variables. You can save the AccessKey ID and the AccessKey secret in the configuration file based on your business requirements. 
             * We recommend that you do not save the AccessKey ID and the AccessKey secret in code. Saving the AccessKey ID and the AccessKey secret in code may lead to the leakage of the AccessKey pair.
             */
            authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
            authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
            /**
             * Replace the sample endpoint with the actual endpoint of Optimization Solver.
             */
            authConfig.endpoint = "opt.cn-hangzhou.aliyuncs.com";
            Client client = new Client(authConfig);
            GetOrderInfoRequest request = new GetOrderInfoRequest();

            /**
             * MP - mathematical programming service
             */
            request.setRelService("MP");
            /**
             * 1 - Local Edition
             */
            request.setResourceType(1);
            GetOrderInfoResponse getOrderInfoResponse = client.getOrderInfo(request);
            System.out.println(JSON.toJSONString(getOrderInfoResponse.getHeaders()));
            System.out.println(JSON.toJSONString(getOrderInfoResponse.getBody()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

3. Query the information about license usage

package com.alibaba.mind.opt.sdk;

import com.alibaba.fastjson.JSON;

import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOrderUsageRequest;
import com.aliyun.opt20210730.models.GetOrderUsageResponse;
import com.aliyun.teaopenapi.models.Config;

public class GetOrderUsageExample {

    public static void main(String[] args) {
        try {
            Config authConfig = new Config();
            /**
             * The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
             * In this example, the AccessKey ID and the AccessKey secret are set to environment variables. You can save the AccessKey ID and the AccessKey secret in the configuration file based on your business requirements. 
             * We recommend that you do not save the AccessKey ID and the AccessKey secret in code. Saving the AccessKey ID and the AccessKey secret in code may lead to the leakage of the AccessKey pair.
             */
            authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
            authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
            /**
             * Replace the sample endpoint with the actual endpoint of Optimization Solver.
             */
            authConfig.endpoint = "opt.cn-hangzhou.aliyuncs.com";
            Client client = new Client(authConfig);
            GetOrderUsageRequest request = new GetOrderUsageRequest();
            /**
             * MP - mathematical programming service
             */
            request.setRelService("MP");
            /**
             * 1 - Local Edition
             */
            request.setResourceType(1);
            /**
             * 1 - one day before and after the day when the request is initiated
             * 2 - one week before and after the day when the request is initiated
             * 3 - one month before and after the day when the request is initiated
             */
            request.setTimeRange(1);
            GetOrderUsageResponse listOrderUsage = client.getOrderUsage(request);
            System.out.println(JSON.toJSONString(listOrderUsage.getHeaders()));
            System.out.println(JSON.toJSONString(listOrderUsage.getBody()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

References

  • The Alibaba Cloud Developer Center brings together popular SDKs for a variety of programming languages and provides information such as Maven project URLs, pip commands, and version descriptions. For more information, visit Developer Center.

  • For more information about SDKs for other programming languages, see Third-Party SDKs.

  • For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.