Search in sources :

Example 1 with ClientConfiguration

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();
}
Also used : OSSClient(com.aliyun.oss.OSSClient) CredentialsProvider(com.aliyun.oss.common.auth.CredentialsProvider) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) ClientConfiguration(com.aliyun.oss.ClientConfiguration)

Example 2 with ClientConfiguration

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage) Date(java.util.Date) ClientConfiguration(com.aliyun.oss.ClientConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ClientConfiguration

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;
}
Also used : RequestMessage(com.aliyun.oss.common.comm.RequestMessage) Credentials(com.aliyun.oss.common.auth.Credentials) ClientConfiguration(com.aliyun.oss.ClientConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ClientConfiguration

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;
}
Also used : DefaultCredentials(com.aliyun.oss.common.auth.DefaultCredentials) OSSClient(com.aliyun.oss.OSSClient) DefaultCredentialProvider(com.aliyun.oss.common.auth.DefaultCredentialProvider) ClientConfiguration(com.aliyun.oss.ClientConfiguration) Credentials(com.aliyun.oss.common.auth.Credentials) DefaultCredentials(com.aliyun.oss.common.auth.DefaultCredentials)

Example 5 with ClientConfiguration

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);
}
Also used : OSSClient(com.aliyun.oss.OSSClient) ClientConfiguration(com.aliyun.oss.ClientConfiguration)

Aggregations

ClientConfiguration (com.aliyun.oss.ClientConfiguration)13 OSSClient (com.aliyun.oss.OSSClient)6 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)6 ClientException (com.aliyun.oss.ClientException)4 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 URI (java.net.URI)4 Test (org.junit.Test)3 Credentials (com.aliyun.oss.common.auth.Credentials)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 ServiceException (com.aliyun.oss.ServiceException)1 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)1 DefaultCredentialProvider (com.aliyun.oss.common.auth.DefaultCredentialProvider)1 DefaultCredentials (com.aliyun.oss.common.auth.DefaultCredentials)1 ResponseHandler (com.aliyun.oss.common.comm.ResponseHandler)1 ResponseMessage (com.aliyun.oss.common.comm.ResponseMessage)1 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)1 File (java.io.File)1