public String getPropAsString(String propName) { Object value = getProperty(propName); return value == null ? null : value.toString(); }
@SuppressWarnings("unchecked") public T withChunkedEncodingSize(int chunkedEncodingSize) { setChunkedEncodingSize(chunkedEncodingSize); return (T) this; }
if (!smartClient || Boolean.parseBoolean(propAsString(properties, PROPERTY_DISABLE_HEALTH_CHECK))) smartConfig.setHealthCheckEnabled(false); if (!smartClient || Boolean.parseBoolean(propAsString(properties, PROPERTY_DISABLE_HOST_UPDATE))) smartConfig.setHostUpdateEnabled(false); smartConfig.setPollInterval(Integer.parseInt(propAsString(properties, PROPERTY_POLL_INTERVAL))); } catch (NumberFormatException e) { throw new RuntimeException(String.format("invalid poll interval (%s=%s)", smartConfig.setProxyUri(new URI(getPropAsString(PROPERTY_PROXY_URI))); } catch (URISyntaxException e) { throw new IllegalArgumentException("invalid proxy URI", e); smartConfig.setProxyUser(getPropAsString(PROPERTY_PROXY_USER)); smartConfig.setProxyPass(getPropAsString(PROPERTY_PROXY_PASS));
@Override public ClientResponse handle(ClientRequest request) throws ClientHandlerException { // if there's no bucket, we don't need to pin the request (there's no write or read) String bucketName = (String) request.getProperties().get(S3Constants.PROPERTY_BUCKET_NAME); String objectKey = (String) request.getProperties().get(S3Constants.PROPERTY_OBJECT_KEY); if (bucketName != null) { List<Vdc> healthyVdcs = new ArrayList<Vdc>(); for (Vdc vdc : objectConfig.getVdcs()) { if (vdc.isHealthy()) healthyVdcs.add(vdc); } if (healthyVdcs.isEmpty()) { log.debug("there are no healthy VDCs; geo-pinning will include all VDCs"); healthyVdcs.addAll(objectConfig.getVdcs()); } int geoPinIndex = getGeoPinIndex(getGeoId(bucketName, objectKey), healthyVdcs.size()); // if this is a read and failover for retries is requested, round-robin the VDCs for each retry if (objectConfig.isGeoReadRetryFailover() && Method.GET.name().equalsIgnoreCase(request.getMethod())) { Integer retries = (Integer) request.getProperties().get(RetryFilter.PROP_RETRY_COUNT); if (retries != null) { int newIndex = (geoPinIndex + retries) % healthyVdcs.size(); log.info("geo-pin read retry #{}: failing over from primary VDC {} to VDC {}", retries, geoPinIndex, newIndex); geoPinIndex = newIndex; } } request.getProperties().put(GeoPinningRule.PROP_GEO_PINNED_VDC, healthyVdcs.get(geoPinIndex)); } return getNext().handle(request); }
protected WebResource.Builder buildRequest(Client client, ObjectRequest request) { URI uri = objectConfig.resolvePath(request.getPath(), request.getRawQueryString()); WebResource resource = client.resource(uri); // set properties for (Map.Entry<String, Object> entry : request.getProperties().entrySet()) { resource.setProperty(entry.getKey(), entry.getValue()); } // set namespace String namespace = request.getNamespace() != null ? request.getNamespace() : objectConfig.getNamespace(); if (namespace != null) resource.setProperty(RestUtil.PROPERTY_NAMESPACE, namespace); WebResource.Builder builder = resource.getRequestBuilder(); // set headers for (String name : request.getHeaders().keySet()) { for (Object value : request.getHeaders().get(name)) { builder = builder.header(name, value); } } return builder; }
/** * @deprecated (2.0.3) this method does nothing. EncryptionConfig instance should be passed to the constructor of * an encryption client */ @SuppressWarnings("unchecked") public T withEncryptionConfig(EncryptionConfig encryptionConfig) { setEncryptionConfig(encryptionConfig); return (T) this; }
/** * Resolves a path relative to the API context. The returned URI will be of the format * scheme://host[:port][/rootContext]/subPath?query. The scheme and port are pulled from the first endpoint in * the endpoints list. The host to use may be virtual (to be resolved by a load balancer) or calculated in * implementations as round-robin or single-host. Note this is not to be confused with the client-side load * balancing provided by the smart client, which overrides any host set here. * * Note that the query string must already be encoded. This is the only way too allow ampersands (&) as part * of a paremeter value */ public URI resolvePath(String subPath, String rawQuery) { String path = ""; // rootContext should be cleaned by setter if (rootContext != null && rootContext.length() > 0) path += rootContext; // add relative path to context path += subPath; if (path.isEmpty()) path = "/"; try { URI uri = RestUtil.buildUri(protocol.toString().toLowerCase(), resolveHost().getName(), port, path, rawQuery, null); log.debug("raw path & query: " + path + "?" + rawQuery); log.debug("resolved URI: " + uri); return uri; } catch (URISyntaxException e) { throw new RuntimeException("Invalid URI syntax", e); } }
/** * Cloning constructor. */ public ObjectConfig(ObjectConfig<T> other) { this.protocol = other.protocol; // deep copy the VDCs to avoid two clients referencing the same host lists (SDK-122) this.vdcs = new ArrayList<Vdc>(); for (Vdc vdc : other.getVdcs()) { this.vdcs.add(new Vdc(vdc.getName(), vdc.getHosts())); } this.port = other.port; this.smartClient = other.smartClient; this.rootContext = other.rootContext; this.namespace = other.namespace; this.identity = other.identity; this.secretKey = other.secretKey; this.serverClockSkew = other.serverClockSkew; this.userAgent = other.userAgent; this.geoPinningEnabled = other.geoPinningEnabled; this.geoReadRetryFailover = other.geoReadRetryFailover; this.chunkedEncodingSize = other.chunkedEncodingSize; this.properties = new HashMap<String, Object>(other.properties); }