Search in sources :

Example 1 with OpenFcServiceRequest

use of com.aliyuncs.fc_open.model.v20200310.OpenFcServiceRequest in project fc-java-sdk by aliyun.

the class PopClient method openFCService.

public OpenFunctionComputeResponse openFCService(Config config, OpenFunctionComputeRequest request) throws ClientException, ServerException {
    request.validate();
    try {
        String accessKeyId = config.getAccessKeyID();
        String accessSecret = config.getAccessKeySecret();
        DefaultProfile profile = null;
        if (StringUtils.isBlank(config.getSecurityToken())) {
            profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret);
        } else {
            String sToken = config.getSecurityToken();
            profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret, sToken);
        }
        OpenFcServiceRequest openFCServiceRequest = new OpenFcServiceRequest();
        IAcsClient client = new DefaultAcsClient(profile);
        openFCServiceRequest.setSysEndpoint(OPEN_FC_SERVICE_ENDPOINT);
        OpenFcServiceResponse openFCServiceResponse = client.getAcsResponse(openFCServiceRequest);
        OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
        response.setRequestId(openFCServiceResponse.getRequestId());
        response.setOrderId(openFCServiceResponse.getOrderId());
        return response;
    } catch (com.aliyuncs.exceptions.ClientException e) {
        if (StringUtils.contains(e.getErrMsg(), "已开通")) {
            OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
            response.setRequestId(e.getRequestId());
            response.setCode(ERROR_CODE_ORDER_OPENED);
            response.setMsg("You have subscribed FunctionCompute, please proceed to FC console and start using it.");
            return response;
        }
        throw new ClientException(e.getErrCode(), e.getErrMsg(), e.getRequestId());
    }
}
Also used : OpenFunctionComputeResponse(com.aliyuncs.fc.response.OpenFunctionComputeResponse) DefaultProfile(com.aliyuncs.profile.DefaultProfile) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) OpenFcServiceResponse(com.aliyuncs.fc_open.model.v20200310.OpenFcServiceResponse) OpenFcServiceRequest(com.aliyuncs.fc_open.model.v20200310.OpenFcServiceRequest) IAcsClient(com.aliyuncs.IAcsClient) ClientException(com.aliyuncs.fc.exceptions.ClientException)

Aggregations

DefaultAcsClient (com.aliyuncs.DefaultAcsClient)1 IAcsClient (com.aliyuncs.IAcsClient)1 ClientException (com.aliyuncs.fc.exceptions.ClientException)1 OpenFunctionComputeResponse (com.aliyuncs.fc.response.OpenFunctionComputeResponse)1 OpenFcServiceRequest (com.aliyuncs.fc_open.model.v20200310.OpenFcServiceRequest)1 OpenFcServiceResponse (com.aliyuncs.fc_open.model.v20200310.OpenFcServiceResponse)1 DefaultProfile (com.aliyuncs.profile.DefaultProfile)1