Search in sources :

Example 1 with IAcsClient

use of com.aliyuncs.IAcsClient in project jointware by isdream.

the class AliyunECSAPIExample method main.

/**
 * @param args
 * @throws ClientException
 * @throws ServerException
 */
public static void main(String[] args) throws ServerException, ClientException {
    IClientProfile profile = DefaultProfile.getProfile(REGINE_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    IAcsClient client = new DefaultAcsClient(profile);
    DescribeZonesRequest request = new DescribeZonesRequest();
    DescribeZonesResponse response = client.getAcsResponse(request);
    System.out.println(response.getZones().get(0).getZoneId());
    DescribeInstancesRequest dur = new DescribeInstancesRequest();
    for (Instance ins : client.getAcsResponse(dur).getInstances()) {
        System.out.println(ins.getInstanceName() + "\t:" + ins.getRegionId());
    }
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) Instance(com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse.Instance) DescribeZonesRequest(com.aliyuncs.ecs.model.v20140526.DescribeZonesRequest) DescribeZonesResponse(com.aliyuncs.ecs.model.v20140526.DescribeZonesResponse) IAcsClient(com.aliyuncs.IAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) DescribeInstancesRequest(com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest)

Example 2 with IAcsClient

use of com.aliyuncs.IAcsClient 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)

Example 3 with IAcsClient

use of com.aliyuncs.IAcsClient in project ranch by heisedebaise.

the class AliyunServiceImpl method getIAcsClient.

@Override
public IAcsClient getIAcsClient(String appCode) {
    if (map.containsKey(appCode))
        return map.get(appCode);
    AliyunModel aliyun = aliyunDao.find(appCode);
    if (aliyun == null)
        return null;
    IAcsClient acsClient = new DefaultAcsClient(DefaultProfile.getProfile("cn-hangzhou", aliyun.getKeyId(), aliyun.getKeySecret()));
    map.put(appCode, acsClient);
    return acsClient;
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IAcsClient(com.aliyuncs.IAcsClient)

Example 4 with IAcsClient

use of com.aliyuncs.IAcsClient in project jointware by isdream.

the class ECSMain method main.

/**
 * @param args
 * @throws ClientException
 * @throws ServerException
 */
public static void main(String[] args) throws ServerException, ClientException {
    IClientProfile profile = DefaultProfile.getProfile(REGINE_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    IAcsClient client = new DefaultAcsClient(profile);
    DescribeZonesRequest request = new DescribeZonesRequest();
    DescribeZonesResponse response = client.getAcsResponse(request);
    System.out.println(response.getZones().get(0).getZoneId());
    DescribeInstancesRequest dur = new DescribeInstancesRequest();
    for (Instance ins : client.getAcsResponse(dur).getInstances()) {
        System.out.println(ins.getInstanceName() + "\t:" + ins.getRegionId());
    }
// dur.setZoneId(zoneId);;
}
Also used : DefaultAcsClient(com.github.isdream.chameleon.vm.aliyun.adapters.DefaultAcsClient) Instance(com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse.Instance) DescribeZonesRequest(com.aliyuncs.ecs.model.v20140526.DescribeZonesRequest) DescribeZonesResponse(com.aliyuncs.ecs.model.v20140526.DescribeZonesResponse) IAcsClient(com.aliyuncs.IAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) DescribeInstancesRequest(com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest)

Aggregations

IAcsClient (com.aliyuncs.IAcsClient)4 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)3 DescribeInstancesRequest (com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest)2 Instance (com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse.Instance)2 DescribeZonesRequest (com.aliyuncs.ecs.model.v20140526.DescribeZonesRequest)2 DescribeZonesResponse (com.aliyuncs.ecs.model.v20140526.DescribeZonesResponse)2 IClientProfile (com.aliyuncs.profile.IClientProfile)2 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 DefaultAcsClient (com.github.isdream.chameleon.vm.aliyun.adapters.DefaultAcsClient)1