Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
TencentEMapReduce committed Nov 27, 2017
1 parent 3bce193 commit 098e29d
Show file tree
Hide file tree
Showing 44 changed files with 4,963 additions and 0 deletions.
76 changes: 76 additions & 0 deletions emr-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### qcloudapi-sdk-java

qcloudapi-sdk-java是为了让Java开发者能够在自己的代码里更快捷方便的使用腾讯云的API而开发的SDK工具包。

#### 更新

[2017/7/12] 回滚:不默认传Version参数

[2017/6.29] https请求支持SNI特性:访问api的域名放入server_name扩展字段中。

[5/19] 设置接口默认Version:
Cvm模块新版本API已经上线,通过是否传Version区分新旧版本。SDK默认调用新接口,因此需要增加Version的默认设置。
CvmAPI接口介绍见:https://www.qcloud.com/document/api/213/569

[3/10] 增加HmacSHA256签名算法的兼容。

[7/15] 增加Tdsql模块。

#### 资源

* [公共参数](http://wiki.qcloud.com/wiki/%E5%85%AC%E5%85%B1%E5%8F%82%E6%95%B0)
* [API列表](http://wiki.qcloud.com/wiki/API)
* [错误码](http://wiki.qcloud.com/wiki/%E9%94%99%E8%AF%AF%E7%A0%81)

#### 入门

1. 申请安全凭证。
在第一次使用云API之前,用户首先需要在腾讯云网站上申请安全凭证,安全凭证包括 SecretId 和 SecretKey, SecretId 是用于标识 API 调用者的身份,SecretKey是用于加密签名字符串和服务器端验证签名字符串的密钥。SecretKey 必须严格保管,避免泄露。

2. 下载SDK,放入到您的程序目录。
使用方法请参考下面的例子。

#### 例子
#### DescribeInstances 接口
public class Demo {
public static void main(String[] args) {
/* 如果是循环调用下面举例的接口,需要从此处开始你的循环语句。切记! */
TreeMap<String, Object> config = new TreeMap<String, Object>();
config.put("SecretId", "你的secretId");
config.put("SecretKey", "你的secretKey");
/* 请求方法类型 POST、GET */
config.put("RequestMethod", "GET");
/* 区域参数,可选: gz:广州; sh:上海; hk:香港; ca:北美;等。 */
config.put("DefaultRegion", "gz");

/*
* 你将要使用接口所在的模块,可以从 官网->云api文档->XXXX接口->接口描述->域名
* 中获取,比如域名:cvm.api.qcloud.com,module就是new Cvm()。
*/
/*
* DescribeInstances
* 的api文档地址:http://www.qcloud.com/wiki/v2/DescribeInstances
*/
QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Cvm(),config);
TreeMap<String, Object> params = new TreeMap<String, Object>();
/* 将需要输入的参数都放入 params 里面,必选参数是必填的。 */
/* DescribeInstances 接口的部分可选参数如下 */
params.put("offset", 0);
params.put("limit", 3);
/*在这里指定所要用的签名算法,不指定默认为HmacSHA1*/
//params.put("SignatureMethod", "HmacSHA256");
/* generateUrl 方法生成请求串,但不发送请求。在正式请求中,可以删除下面这行代码。 */
// System.out.println(module.generateUrl("DescribeInstances", params));

String result = null;
try {
/* call 方法正式向指定的接口名发送请求,并把请求参数params传入,返回即是接口的请求结果。 */
result = module.call("DescribeInstances", params);
JSONObject json_result = new JSONObject(result);
System.out.println(json_result);
} catch (Exception e) {
System.out.println("error..." + e.getMessage());
}

}
}
7 changes: 7 additions & 0 deletions emr-sdk/git-remote-https.exe.stackdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Exception: STATUS_ACCESS_VIOLATION at eip=6102048B
eax=104200F8 ebx=61246884 ecx=76531ABE edx=005DC1CC esi=00000000 edi=0028F9F4
ebp=61020C00 esp=0028C7C4 program=D:\cygwin\lib\git-core\git-remote-https.exe, pid 16060, thread main
cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B
Stack trace:
Frame Function Args
End of stack trace
48 changes: 48 additions & 0 deletions emr-sdk/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tencent.cloud.emr</groupId>
<artifactId>emr-api</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>emr-example</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<maxmem>1024m</maxmem>
<fork>true</fork>
<compilerArgs>
<arg>-Xlint:all,-serial,-path</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!--repository>
<id>apache release</id>
<url>https://repository.apache.org/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository-->
</repositories>
</project>
50 changes: 50 additions & 0 deletions emr-sdk/src/main/java/Demo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.TreeMap;

import main.java.qcloud.Module.Emr;
import main.java.qcloud.QcloudApiModuleCenter;
import main.java.qcloud.Utilities.Json.JSONObject;

public class Demo {
public static void main(String[] args) {
/* 如果是循环调用下面举例的接口,需要从此处开始你的循环语句。切记! */
TreeMap<String, Object> config = new TreeMap<String, Object>();
config.put("SecretId", "aaa");
config.put("SecretKey", "bbb");
/* 请求方法类型 POST、GET */
config.put("RequestMethod", "GET");
/* 区域参数,可选: gz:广州; sh:上海; hk:香港; ca:北美;等。 */
config.put("DefaultRegion", "ap-beijing");

/*
* 你将要使用接口所在的模块,可以从 官网->云api文档->XXXX接口->接口描述->域名
* 中获取,比如域名:cvm.api.qcloud.com,module就是 new Cvm()。
*/
/*
* 示例:DescribeInstances
* 的api文档地址:http://www.qcloud.com/wiki/v2/DescribeInstances
*/
QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Emr(),
config);

TreeMap<String, Object> params = new TreeMap<String, Object>();
/* 将需要输入的参数都放入 params 里面,必选参数是必填的。 */
/* DescribeInstances 接口的部分可选参数如下 */
params.put("ClusterId", "emr-111");
params.put("NodeFlag", "master");
/*在这里指定所要用的签名算法,不指定默认为HmacSHA1*/
//params.put("SignatureMethod", "HmacSHA256");

/* generateUrl方法生成请求串,可用于调试使用 */
//System.out.println(module.generateUrl("DescribeInstances", params));
String result = null;
try {
/* call 方法正式向指定的接口名发送请求,并把请求参数params传入,返回即是接口的请求结果。 */
result = module.call("EmrDescribeClusterNode", params);
JSONObject json_result = new JSONObject(result);
System.out.println(json_result);
} catch (Exception e) {
System.out.println("error..." + e.getMessage());
}

}
}
85 changes: 85 additions & 0 deletions emr-sdk/src/main/java/VodDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.File;
import java.util.TreeMap;

import main.java.qcloud.QcloudApiModuleCenter;
import main.java.qcloud.Module.Vod;
import main.java.qcloud.Utilities.SHA1;
import main.java.qcloud.Utilities.Json.JSONObject;

public class VodDemo {
public static void main(String[] args) {
TreeMap<String, Object> config = new TreeMap<String, Object>();

config.put("SecretId", "你的secretId");
config.put("SecretKey", "你的secretKey");
config.put("RequestMethod", "POST");
config.put("DefaultRegion", "gz");
QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Vod(), config);
try{
System.out.println("starting...");
String fileName = "d:\\test.rmvb";
long fileSize = new File(fileName).length();
String fileSHA1 = SHA1.fileNameToSHA(fileName);

int fixDataSize = 1024*1024*50; //每次上传字节数,可自定义
int firstDataSize = 1024*10; //切片上传:最小片字节数(默认不变),如果:dataSize + offset > fileSize,把这个值变小即可
int tmpDataSize = firstDataSize;
long remainderSize = fileSize;
int tmpOffset = 0;
int code, flag;
String fileId;
String result = null;

if(remainderSize<=0){
System.out.println("wrong file path...");
}
while (remainderSize>0) {
TreeMap<String, Object> params = new TreeMap<String, Object>();
/*
* 亲,输入参数的类型,记得参考wiki详细说明
*/
params.put("fileSha", fileSHA1);
params.put("fileType", "rmvb");
params.put("fileName", "Test");
params.put("fileSize", fileSize);
params.put("dataSize", tmpDataSize);
params.put("offset", tmpOffset);
params.put("file", fileName);
params.put("isTranscode", 0);
params.put("isScreenshot", 0);
params.put("isWatermark", 0);


result = module.call("MultipartUploadVodFile", params);
System.out.println(result);
JSONObject json_result = new JSONObject(result);
code = json_result.getInt("code");
if (code == -3002) { //服务器异常返回,需要重试上传(offset=0, dataSize=10K,满足大多数视频的上传)
tmpDataSize = firstDataSize;
tmpOffset = 0;
continue;
} else if (code != 0) {
return;
}
flag = json_result.getInt("flag");
if (flag == 1) {
fileId = json_result.getString("fileId");
break;
} else {
tmpOffset = Integer.parseInt(json_result.getString("offset"));
}
remainderSize = fileSize - tmpOffset;
if (fixDataSize < remainderSize) {
tmpDataSize = fixDataSize;
} else {
tmpDataSize = (int) remainderSize;
}
}
System.out.println("end...");
}
catch (Exception e) {
e.printStackTrace();
System.out.println("error..."+e.toString());
}
}
}
Loading

0 comments on commit 098e29d

Please sign in to comment.