use of com.aliyun.oss.ClientConfiguration in project hadoop by apache.
the class AliyunOSSFileSystemStore method initialize.
public void initialize(URI uri, Configuration conf, FileSystem.Statistics stat) throws IOException {
statistics = stat;
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setMaxConnections(conf.getInt(MAXIMUM_CONNECTIONS_KEY, MAXIMUM_CONNECTIONS_DEFAULT));
boolean secureConnections = conf.getBoolean(SECURE_CONNECTIONS_KEY, SECURE_CONNECTIONS_DEFAULT);
clientConf.setProtocol(secureConnections ? Protocol.HTTPS : Protocol.HTTP);
clientConf.setMaxErrorRetry(conf.getInt(MAX_ERROR_RETRIES_KEY, MAX_ERROR_RETRIES_DEFAULT));
clientConf.setConnectionTimeout(conf.getInt(ESTABLISH_TIMEOUT_KEY, ESTABLISH_TIMEOUT_DEFAULT));
clientConf.setSocketTimeout(conf.getInt(SOCKET_TIMEOUT_KEY, SOCKET_TIMEOUT_DEFAULT));
String proxyHost = conf.getTrimmed(PROXY_HOST_KEY, "");
int proxyPort = conf.getInt(PROXY_PORT_KEY, -1);
if (StringUtils.isNotEmpty(proxyHost)) {
clientConf.setProxyHost(proxyHost);
if (proxyPort >= 0) {
clientConf.setProxyPort(proxyPort);
} else {
if (secureConnections) {
LOG.warn("Proxy host set without port. Using HTTPS default 443");
clientConf.setProxyPort(443);
} else {
LOG.warn("Proxy host set without port. Using HTTP default 80");
clientConf.setProxyPort(80);
}
}
String proxyUsername = conf.getTrimmed(PROXY_USERNAME_KEY);
String proxyPassword = conf.getTrimmed(PROXY_PASSWORD_KEY);
if ((proxyUsername == null) != (proxyPassword == null)) {
String msg = "Proxy error: " + PROXY_USERNAME_KEY + " or " + PROXY_PASSWORD_KEY + " set without the other.";
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
clientConf.setProxyUsername(proxyUsername);
clientConf.setProxyPassword(proxyPassword);
clientConf.setProxyDomain(conf.getTrimmed(PROXY_DOMAIN_KEY));
clientConf.setProxyWorkstation(conf.getTrimmed(PROXY_WORKSTATION_KEY));
} else if (proxyPort >= 0) {
String msg = "Proxy error: " + PROXY_PORT_KEY + " set without " + PROXY_HOST_KEY;
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
String endPoint = conf.getTrimmed(ENDPOINT_KEY, "");
CredentialsProvider provider = AliyunOSSUtils.getCredentialsProvider(conf);
ossClient = new OSSClient(endPoint, provider, clientConf);
uploadPartSize = conf.getLong(MULTIPART_UPLOAD_SIZE_KEY, MULTIPART_UPLOAD_SIZE_DEFAULT);
multipartThreshold = conf.getLong(MIN_MULTIPART_UPLOAD_THRESHOLD_KEY, MIN_MULTIPART_UPLOAD_THRESHOLD_DEFAULT);
partSize = conf.getLong(MULTIPART_UPLOAD_SIZE_KEY, MULTIPART_UPLOAD_SIZE_DEFAULT);
if (partSize < MIN_MULTIPART_UPLOAD_PART_SIZE) {
partSize = MIN_MULTIPART_UPLOAD_PART_SIZE;
}
serverSideEncryptionAlgorithm = conf.get(SERVER_SIDE_ENCRYPTION_ALGORITHM_KEY, "");
if (uploadPartSize < 5 * 1024 * 1024) {
LOG.warn(MULTIPART_UPLOAD_SIZE_KEY + " must be at least 5 MB");
uploadPartSize = 5 * 1024 * 1024;
}
if (multipartThreshold < 5 * 1024 * 1024) {
LOG.warn(MIN_MULTIPART_UPLOAD_THRESHOLD_KEY + " must be at least 5 MB");
multipartThreshold = 5 * 1024 * 1024;
}
if (multipartThreshold > 1024 * 1024 * 1024) {
LOG.warn(MIN_MULTIPART_UPLOAD_THRESHOLD_KEY + " must be less than 1 GB");
multipartThreshold = 1024 * 1024 * 1024;
}
String cannedACLName = conf.get(CANNED_ACL_KEY, CANNED_ACL_DEFAULT);
if (StringUtils.isNotEmpty(cannedACLName)) {
CannedAccessControlList cannedACL = CannedAccessControlList.valueOf(cannedACLName);
ossClient.setBucketAcl(bucketName, cannedACL);
}
maxKeys = conf.getInt(MAX_PAGING_KEYS_KEY, MAX_PAGING_KEYS_DEFAULT);
bucketName = uri.getHost();
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class OSSRequestMessageBuilder method build.
public RequestMessage build() {
Map<String, String> sentHeaders = new HashMap<String, String>(this.headers);
sentHeaders.put(OSSHeaders.DATE, DateUtil.formatRfc822Date(new Date()));
Map<String, String> sentParameters = new LinkedHashMap<String, String>(this.parameters);
RequestMessage request = new RequestMessage(this.originalRequest, this.bucket, this.key);
ClientConfiguration clientCofig = this.innerClient.getClientConfiguration();
request.setBucket(bucket);
request.setKey(key);
request.setEndpoint(determineFinalEndpoint(this.endpoint, this.bucket, clientCofig));
request.setResourcePath(determineResourcePath(this.bucket, this.key, clientCofig.isSLDEnabled()));
request.setHeaders(sentHeaders);
request.setParameters(sentParameters);
request.setMethod(this.method);
request.setContent(this.inputStream);
request.setContentLength(this.inputSize);
request.setUseChunkEncoding(this.inputSize == -1 ? true : this.useChunkEncoding);
return request;
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class LiveChannelOperation method generateRtmpUri.
public String generateRtmpUri(GenerateRtmpUriRequest request) throws OSSException, ClientException {
assertParameterNotNull(request, "request");
String bucketName = request.getBucketName();
String liveChannelName = request.getLiveChannelName();
String playlistName = request.getPlaylistName();
Long expires = request.getExpires();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(liveChannelName, "liveChannelName");
ensureLiveChannelNameValid(liveChannelName);
assertParameterNotNull(playlistName, "playlistName");
assertParameterNotNull(expires, "expires");
Credentials currentCreds = this.credsProvider.getCredentials();
String accessId = currentCreds.getAccessKeyId();
String accessKey = currentCreds.getSecretAccessKey();
boolean useSecurityToken = currentCreds.useSecurityToken();
// Endpoint
RequestMessage requestMessage = new RequestMessage(bucketName, liveChannelName);
ClientConfiguration config = this.client.getClientConfiguration();
requestMessage.setEndpoint(OSSUtils.determineFinalEndpoint(this.endpoint, bucketName, config));
// Headers
requestMessage.addHeader(HttpHeaders.DATE, expires.toString());
// Parameters
requestMessage.addParameter(RequestParameters.PLAYLIST_NAME, playlistName);
if (useSecurityToken) {
requestMessage.addParameter(SECURITY_TOKEN, currentCreds.getSecurityToken());
}
// Signature
String canonicalResource = "/" + bucketName + "/" + liveChannelName;
String canonicalString = SignUtils.buildRtmpCanonicalString(canonicalResource, requestMessage, expires.toString());
String signature = ServiceSignature.create().computeSignature(accessKey, canonicalString);
// Build query string
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(HttpHeaders.EXPIRES, expires.toString());
params.put(OSS_ACCESS_KEY_ID, accessId);
params.put(SIGNATURE, signature);
params.putAll(requestMessage.getParameters());
String queryString = HttpUtil.paramToQueryString(params, DEFAULT_CHARSET_NAME);
// Compose rtmp request uri
String uri = requestMessage.getEndpoint().toString();
String livChan = RequestParameters.SUBRESOURCE_LIVE + "/" + liveChannelName;
if (uri.startsWith(OSSConstants.PROTOCOL_HTTP)) {
uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTP, OSSConstants.PROTOCOL_RTMP);
} else if (uri.startsWith(OSSConstants.PROTOCOL_HTTPS)) {
uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTPS, OSSConstants.PROTOCOL_RTMP);
} else if (!uri.startsWith(OSSConstants.PROTOCOL_RTMP)) {
uri = OSSConstants.PROTOCOL_RTMP + uri;
}
if (!uri.endsWith("/")) {
uri += "/";
}
uri += livChan + "?" + queryString;
return uri;
}
use of com.aliyun.oss.ClientConfiguration in project aliyun-oss-java-sdk by aliyun.
the class TestBase method getOSSClient.
public static OSSClient getOSSClient() {
if (ossClient == null) {
resetTestConfig();
ClientConfiguration conf = new ClientConfiguration().setSupportCname(false);
Credentials credentials = new DefaultCredentials(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
ossClient = new OSSClient(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(credentials), conf);
}
return ossClient;
}
use of com.aliyun.oss.ClientConfiguration in project alluxio by Alluxio.
the class OSSUnderFileSystem method createInstance.
/**
* Constructs a new instance of {@link OSSUnderFileSystem}.
*
* @param uri the {@link AlluxioURI} for this UFS
* @return the created {@link OSSUnderFileSystem} instance
* @throws Exception when a connection to GCS could not be created
*/
public static OSSUnderFileSystem createInstance(AlluxioURI uri) throws Exception {
String bucketName = uri.getHost();
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_ACCESS_KEY), "Property " + PropertyKey.OSS_ACCESS_KEY + " is required to connect to OSS");
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_SECRET_KEY), "Property " + PropertyKey.OSS_SECRET_KEY + " is required to connect to OSS");
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_ENDPOINT_KEY), "Property " + PropertyKey.OSS_ENDPOINT_KEY + " is required to connect to OSS");
String accessId = Configuration.get(PropertyKey.OSS_ACCESS_KEY);
String accessKey = Configuration.get(PropertyKey.OSS_SECRET_KEY);
String endPoint = Configuration.get(PropertyKey.OSS_ENDPOINT_KEY);
ClientConfiguration ossClientConf = initializeOSSClientConfig();
OSSClient ossClient = new OSSClient(endPoint, accessId, accessKey, ossClientConf);
return new OSSUnderFileSystem(uri, ossClient, bucketName);
}
Aggregations