mirror of https://github.com/apache/jclouds.git
Merge pull request #1131 from jclouds/cleanup
cleaning unused or only used once code
This commit is contained in:
commit
4f5c93c988
|
@ -23,10 +23,10 @@ import static com.google.common.io.ByteStreams.readBytes;
|
|||
import static org.jclouds.Constants.LOGGER_SIGNATURE;
|
||||
import static org.jclouds.crypto.Macs.asByteProcessor;
|
||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
|
||||
import static org.jclouds.util.Strings2.toInputStream;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -141,6 +141,8 @@ public class SignRequest implements HttpRequestFilter {
|
|||
toSign.append(request.getMethod()).append("\n");
|
||||
}
|
||||
|
||||
private static final Pattern TWO_SPACE_PATTERN = Pattern.compile(" ");
|
||||
|
||||
private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) {
|
||||
// TreeSet == Sort the headers alphabetically.
|
||||
Set<String> headers = Sets.newTreeSet(request.getHeaders().keySet());
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.cloudfiles.config;
|
||||
|
||||
import static org.jclouds.util.Suppliers2.valueForKey;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -36,6 +35,7 @@ import org.jclouds.openstack.swift.Storage;
|
|||
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
@ -77,6 +77,28 @@ public class CloudFilesRestClientModule extends SwiftRestClientModule<CloudFiles
|
|||
return valueForKey(factory.createForApiTypeAndVersion("cloudFiles", null),
|
||||
defaultRegion.createForApiType("cloudFiles"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplies a value that corresponds to a particular key in a map, or null, if not found
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static <K, V> Supplier<V> valueForKey(final Supplier<Map<K, Supplier<V>>> input, final Supplier<K> key) {
|
||||
return new Supplier<V>() {
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
K keyToFind = key.get();
|
||||
Supplier<V> value = input.get().get(keyToFind);
|
||||
return value != null ? value.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "withKey()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,29 +16,33 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
package org.jclouds.cloudfiles.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class Lists2Test {
|
||||
public class CloudFilesRestClientModuleTest {
|
||||
|
||||
public void testMultiMax() {
|
||||
Iterable<String> values = ImmutableList.of("1", "2", "2", "3", "3");
|
||||
assertEquals(Lists2.multiMax(Ordering.natural(), values), ImmutableList.of("3", "3"));
|
||||
@Test
|
||||
public void testWithKey() {
|
||||
assertEquals(
|
||||
CloudFilesRestClientModule.<String, String> valueForKey(
|
||||
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("foo",
|
||||
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), "bar");
|
||||
}
|
||||
|
||||
public void testMultiMax1() {
|
||||
Iterable<String> values = ImmutableList.of("1", "2", "2", "3");
|
||||
assertEquals(Lists2.multiMax(Ordering.natural(), values), ImmutableList.of("3"));
|
||||
@Test
|
||||
public void testWithKeyUnmatchedIsNull() {
|
||||
assertEquals(
|
||||
CloudFilesRestClientModule.<String, String> valueForKey(
|
||||
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("boo",
|
||||
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), null);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,6 @@ package org.jclouds.cloudsigma.compute;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static org.jclouds.concurrent.FutureIterables.transformParallel;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -43,6 +42,7 @@ import org.jclouds.cloudsigma.domain.ServerInfo;
|
|||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.cloudsigma.reference.CloudSigmaConstants;
|
||||
import org.jclouds.cloudsigma.util.Servers;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
|
@ -55,13 +55,13 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
@ -170,7 +170,7 @@ public class CloudSigmaComputeServiceAdapter implements
|
|||
*/
|
||||
@Override
|
||||
public Iterable<DriveInfo> listImages() {
|
||||
Iterable<? extends DriveInfo> drives = transformParallel(client.listStandardDrives(),
|
||||
return FluentIterable.from(transformParallel(client.listStandardDrives(),
|
||||
new Function<String, Future<? extends DriveInfo>>() {
|
||||
|
||||
@Override
|
||||
|
@ -189,8 +189,7 @@ public class CloudSigmaComputeServiceAdapter implements
|
|||
public String toString() {
|
||||
return "seedDriveCache()";
|
||||
}
|
||||
}, executor, null, logger, "drives");
|
||||
return Iterables2.concreteCopy(filter(drives, PREINSTALLED_DISK));
|
||||
}, executor, null, logger, "drives")).filter(PREINSTALLED_DISK);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import static org.jclouds.util.Maps2.renameKey;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Maps.filterKeys;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -27,7 +30,10 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,4 +52,32 @@ public class DriveDataToMap implements Function<DriveData, Map<String, String>>
|
|||
public Map<String, String> apply(DriveData from) {
|
||||
return renameKey(baseDriveToMap.apply(from), "use", "use");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the supplied map contains the key {@code k1}, its value will be assigned to the key {@code
|
||||
* k2}. Note that this doesn't modify the input map.
|
||||
*
|
||||
* @param <V>
|
||||
* type of value the map holds
|
||||
* @param in
|
||||
* the map you wish to make a copy of
|
||||
* @param k1
|
||||
* old key
|
||||
* @param k2
|
||||
* new key
|
||||
* @return copy of the map with the value of the key re-routed, or the original, if it {@code k1}
|
||||
* wasn't present.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static <V> Map<String, V> renameKey(Map<String, V> in, String k1, String k2) {
|
||||
if (checkNotNull(in, "input map").containsKey(checkNotNull(k1, "old key"))) {
|
||||
Builder<String, V> builder = ImmutableMap.builder();
|
||||
builder.putAll(filterKeys(in, not(equalTo(k1))));
|
||||
V tags = in.get(k1);
|
||||
builder.put(checkNotNull(k2, "new key"), tags);
|
||||
in = builder.build();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudsigma.functions;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
|
@ -37,6 +38,16 @@ import com.google.inject.Guice;
|
|||
@Test(groups = { "unit" })
|
||||
public class DriveDataToMapTest {
|
||||
|
||||
public void testRenameKeyWhenNotFound() {
|
||||
Map<String, String> nothing = ImmutableMap.of();
|
||||
assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), nothing);
|
||||
}
|
||||
|
||||
public void testRenameKeyWhenFound() {
|
||||
Map<String, String> nothing = ImmutableMap.of("foo", "bar");
|
||||
assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar"));
|
||||
}
|
||||
|
||||
private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class);
|
||||
|
||||
public void testBasics() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.jclouds.ec2.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.currentOrNegative;
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
|
@ -64,6 +63,10 @@ public class IpPermissionHandler extends ParseSax.HandlerForGeneratedRequestWith
|
|||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
private static String currentOrNegative(StringBuilder currentText) {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? "-1" : returnVal;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.elasticstack.compute;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static org.jclouds.concurrent.FutureIterables.transformParallel;
|
||||
import static org.jclouds.elasticstack.util.Servers.small;
|
||||
|
||||
|
@ -35,6 +34,7 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
|
@ -57,12 +57,12 @@ import org.jclouds.elasticstack.domain.ServerStatus;
|
|||
import org.jclouds.elasticstack.domain.WellKnownImage;
|
||||
import org.jclouds.elasticstack.reference.ElasticStackConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
@ -163,7 +163,7 @@ public class ElasticStackComputeServiceAdapter implements
|
|||
*/
|
||||
@Override
|
||||
public Iterable<DriveInfo> listImages() {
|
||||
Iterable<? extends DriveInfo> drives = transformParallel(preinstalledImages.keySet(),
|
||||
return FluentIterable.from(transformParallel(preinstalledImages.keySet(),
|
||||
new Function<String, Future<? extends DriveInfo>>() {
|
||||
|
||||
@Override
|
||||
|
@ -183,8 +183,7 @@ public class ElasticStackComputeServiceAdapter implements
|
|||
return "seedDriveCache()";
|
||||
}
|
||||
|
||||
}, executor, null, logger, "drives");
|
||||
return Iterables2.concreteCopy(filter(drives, notNull()));
|
||||
}, executor, null, logger, "drives")).filter(notNull());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -73,13 +73,13 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAn
|
|||
import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue;
|
||||
import org.jclouds.predicates.PredicateWithResult;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -201,7 +201,7 @@ public class NovaComputeServiceContextModule extends
|
|||
@Singleton
|
||||
protected Supplier<Map<String, Location>> createLocationIndexedById(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.s3.Bucket;
|
||||
import org.jclouds.s3.S3Client;
|
||||
import org.jclouds.util.Patterns;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
|
@ -41,7 +40,9 @@ import com.google.common.base.Predicate;
|
|||
*/
|
||||
public class S3Utils {
|
||||
|
||||
public static final Pattern BUCKET_NAME_PATTERN = Pattern.compile("^[a-z0-9][-_.a-z0-9]+");
|
||||
private static final Pattern BUCKET_NAME_PATTERN = Pattern.compile("^[a-z0-9][-_.a-z0-9]+");
|
||||
private static final Pattern IP_PATTERN = Pattern.compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)"
|
||||
+ "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b");
|
||||
|
||||
// TODO add validatorparam so that this is actually used
|
||||
public static String validateBucketName(String bucketName) {
|
||||
|
@ -51,7 +52,7 @@ public class S3Utils {
|
|||
"bucketName name must start with a number or letter and can only contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)");
|
||||
checkArgument(bucketName.length() > 2 && bucketName.length() < 256,
|
||||
"bucketName name must be between 3 and 255 characters long");
|
||||
checkArgument(!Patterns.IP_PATTERN.matcher(bucketName).matches(),
|
||||
checkArgument(!IP_PATTERN.matcher(bucketName).matches(),
|
||||
"bucketName name cannot be ip address style");
|
||||
return bucketName;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
|||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.compute.functions.HardwareForVApp;
|
||||
import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate;
|
||||
import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
|
||||
|
@ -52,6 +51,7 @@ import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -143,7 +143,7 @@ public class VCloudComputeServiceDependenciesModule extends AbstractModule {
|
|||
@Singleton
|
||||
public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
|
||||
final FenceMode defaultFenceMode) {
|
||||
return Suppliers2.compose(new Function<ReferenceType, NetworkConfig>() {
|
||||
return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() {
|
||||
|
||||
@Override
|
||||
public NetworkConfig apply(ReferenceType input) {
|
||||
|
|
|
@ -26,7 +26,6 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.VCloudSession;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
|
@ -35,6 +34,7 @@ import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfig
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
|
|||
|
||||
@Override
|
||||
public Supplier<ReferenceType> apply(final String user) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(VCloudSession session) {
|
||||
|
|
|
@ -73,7 +73,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -81,7 +81,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -147,7 +147,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -162,7 +162,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -26,9 +26,9 @@ import static com.google.common.collect.Iterables.filter;
|
|||
import static com.google.common.collect.Iterables.getLast;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.util.Maps2.uniqueIndex;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
|
||||
|
@ -58,7 +58,6 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.VCloudToken;
|
||||
|
@ -95,11 +94,11 @@ import org.jclouds.vcloud.features.VmClient;
|
|||
import org.jclouds.vcloud.functions.CatalogItemsInCatalog;
|
||||
import org.jclouds.vcloud.functions.CatalogItemsInOrg;
|
||||
import org.jclouds.vcloud.functions.CatalogsInOrg;
|
||||
import org.jclouds.vcloud.functions.VDCsInOrg;
|
||||
import org.jclouds.vcloud.functions.DefaultNetworkNameInTemplate;
|
||||
import org.jclouds.vcloud.functions.OrgsForLocations;
|
||||
import org.jclouds.vcloud.functions.OrgsForNames;
|
||||
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
|
||||
import org.jclouds.vcloud.functions.VDCsInOrg;
|
||||
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginClient;
|
||||
|
@ -114,6 +113,7 @@ import com.google.common.base.Function;
|
|||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -224,7 +224,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, Org>> orgNameToOrgSupplier) {
|
||||
return Suppliers2.compose(new Function<Map<String, Org>, Map<String, String>>() {
|
||||
return Suppliers.compose(new Function<Map<String, Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, Org> arg0) {
|
||||
|
@ -252,7 +252,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
@OrgList
|
||||
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, URI>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(VCloudSession arg0) {
|
||||
|
@ -304,15 +304,12 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
|
||||
@Override
|
||||
public Map<String, Map<String, Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends Catalog>,
|
||||
Map<String, Catalog>>() {
|
||||
return transformValues(transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends Catalog>, Map<String, Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Catalog> apply(
|
||||
Iterable<? extends Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
public Map<String, Catalog> apply(Iterable<? extends Catalog> from) {
|
||||
return ImmutableMap.copyOf(uniqueIndex(from, name));
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -323,7 +320,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, String>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(VCloudSession input) {
|
||||
|
@ -432,7 +429,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(new Function<ReferenceType, Org>() {
|
||||
return Suppliers.compose(new Function<ReferenceType, Org>() {
|
||||
|
||||
@Override
|
||||
public Org apply(ReferenceType input) {
|
||||
|
|
|
@ -31,7 +31,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
|
@ -60,23 +59,17 @@ public class CatalogItemsInCatalog implements Function<Catalog, Iterable<Catalog
|
|||
|
||||
@Override
|
||||
public Iterable<CatalogItem> apply(Catalog from) {
|
||||
|
||||
Iterable<? extends CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
|
||||
|
||||
return transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
|
||||
@Override
|
||||
public boolean apply(ReferenceType input) {
|
||||
return input.getType().equals(VCloudMediaType.CATALOGITEM_XML);
|
||||
}
|
||||
|
||||
}), new Function<ReferenceType, Future<? extends CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Future<CatalogItem> apply(ReferenceType from) {
|
||||
return aclient.getCatalogClient().getCatalogItem(from.getHref());
|
||||
}
|
||||
|
||||
}, executor, null, logger, "catalogItems in " + from.getHref());
|
||||
return Iterables2.concreteCopy(catalogItems);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
|
@ -57,14 +56,11 @@ public class CatalogsInOrg implements Function<Org, Iterable<Catalog>> {
|
|||
|
||||
@Override
|
||||
public Iterable<Catalog> apply(final Org org) {
|
||||
Iterable<? extends Catalog> catalogs = transformParallel(org.getCatalogs().values(),
|
||||
new Function<ReferenceType, Future<? extends Catalog>>() {
|
||||
return transformParallel(org.getCatalogs().values(), new Function<ReferenceType, Future<? extends Catalog>>() {
|
||||
@Override
|
||||
public Future<Catalog> apply(ReferenceType from) {
|
||||
return aclient.getCatalogClient().getCatalog(from.getHref());
|
||||
}
|
||||
|
||||
}, executor, null, logger, "catalogs in " + org.getName());
|
||||
return Iterables2.concreteCopy(catalogs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
@ -57,16 +56,12 @@ public class NetworksInOrg implements Function<Org, Iterable<OrgNetwork>> {
|
|||
|
||||
@Override
|
||||
public Iterable<OrgNetwork> apply(final Org org) {
|
||||
|
||||
Iterable<OrgNetwork> networkItems = transformParallel(org.getNetworks().values(),
|
||||
new Function<ReferenceType, Future<? extends OrgNetwork>>() {
|
||||
return transformParallel(org.getNetworks().values(), new Function<ReferenceType, Future<? extends OrgNetwork>>() {
|
||||
@Override
|
||||
public Future<? extends OrgNetwork> apply(ReferenceType from) {
|
||||
return aclient.getNetworkClient().getNetwork(from.getHref());
|
||||
}
|
||||
|
||||
}, executor, null, logger, "OrgNetworks in org " + org.getName());
|
||||
return Iterables2.concreteCopy(networkItems);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.functions;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.concurrent.FutureIterables.transformParallel;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -35,13 +33,12 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -65,29 +62,23 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<O
|
|||
*/
|
||||
@Override
|
||||
public Iterable<Org> apply(Iterable<Location> from) {
|
||||
|
||||
return Iterables2.concreteCopy(transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
|
||||
|
||||
FluentIterable<URI> uris = FluentIterable.from(from).filter(new Predicate<Location>() {
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getScope() == LocationScope.ZONE;
|
||||
}
|
||||
|
||||
}), new Function<Location, URI>() {
|
||||
|
||||
}).transform(new Function<Location, URI>() {
|
||||
@Override
|
||||
public URI apply(Location from) {
|
||||
return URI.create(from.getParent().getId());
|
||||
}
|
||||
|
||||
})), new Function<URI, Future<? extends Org>>() {
|
||||
|
||||
});
|
||||
return transformParallel(uris, new Function<URI, Future<? extends Org>>() {
|
||||
@Override
|
||||
public Future<Org> apply(URI from) {
|
||||
return aclient.getOrgClient().getOrg(from);
|
||||
}
|
||||
|
||||
}, executor, null, logger, "organizations for uris"));
|
||||
}, executor, null, logger, "organizations for uris");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import static com.google.common.collect.Iterables.filter;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.Status;
|
||||
|
@ -54,17 +53,14 @@ public class VAppTemplatesInOrg implements Function<Org, Iterable<VAppTemplate>>
|
|||
@Override
|
||||
public Iterable<VAppTemplate> apply(Org from) {
|
||||
Iterable<CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
|
||||
Iterable<VAppTemplate> vAppTemplates = Iterables2.concreteCopy(vAppTemplatesForCatalogItems.apply(catalogs));
|
||||
Iterable<VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
|
||||
return filter(vAppTemplates, and(notNull(), new Predicate<VAppTemplate>(){
|
||||
|
||||
//TODO: test this
|
||||
@Override
|
||||
public boolean apply(VAppTemplate input) {
|
||||
if (input == null)
|
||||
return false;
|
||||
return ImmutableSet.of(Status.RESOLVED, Status.OFF).contains(input.getStatus());
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
@ -57,16 +56,13 @@ public class VDCsInOrg implements Function<Org, Iterable<VDC>> {
|
|||
|
||||
@Override
|
||||
public Iterable<VDC> apply(final Org org) {
|
||||
|
||||
Iterable<VDC> catalogItems = transformParallel(org.getVDCs().values(),
|
||||
new Function<ReferenceType, Future<? extends VDC>>() {
|
||||
return transformParallel(org.getVDCs().values(), new Function<ReferenceType, Future<? extends VDC>>() {
|
||||
@Override
|
||||
public Future<? extends VDC> apply(ReferenceType from) {
|
||||
return aclient.getVDCClient().getVDC(from.getHref());
|
||||
}
|
||||
|
||||
}, executor, null, logger, "vdcs in org " + org.getName());
|
||||
return Iterables2.concreteCopy(catalogItems);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,29 +20,19 @@ package org.jclouds.blobstore.util;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||
import org.jclouds.blobstore.KeyNotFoundException;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||
import org.jclouds.blobstore.functions.BlobName;
|
||||
import org.jclouds.functions.ExceptionToValueOrPropagate;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
@ -62,50 +52,6 @@ public class BlobStoreUtils {
|
|||
.headers(returnVal.getHeaders()).payload(returnVal.getPayload()).build();
|
||||
}
|
||||
|
||||
public static final ExceptionToValueOrPropagate<KeyNotFoundException, ?> keyNotFoundToNullOrPropagate = new ExceptionToValueOrPropagate<KeyNotFoundException, Object>(
|
||||
KeyNotFoundException.class, null);
|
||||
|
||||
public static final ExceptionToValueOrPropagate<ContainerNotFoundException, ?> containerNotFoundToNullOrPropagate = new ExceptionToValueOrPropagate<ContainerNotFoundException, Object>(
|
||||
ContainerNotFoundException.class, null);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T keyNotFoundToNullOrPropagate(Exception e) {
|
||||
return (T) keyNotFoundToNullOrPropagate.apply(e);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T containerNotFoundToNullOrPropagate(Exception e) {
|
||||
return (T) containerNotFoundToNullOrPropagate.apply(e);
|
||||
}
|
||||
|
||||
public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) {
|
||||
Blob blob = checkNotNull(blobStore, "blobStore").blobBuilder(checkNotNull(blobMeta, "blobMeta").getName())
|
||||
.userMetadata(blobMeta.getUserMetadata()).build();
|
||||
if (blobMeta instanceof BlobMetadata) {
|
||||
HttpUtils.copy(((BlobMetadata) blobMeta).getContentMetadata(), blob.getMetadata().getContentMetadata());
|
||||
}
|
||||
blob.getMetadata().setETag(blobMeta.getETag());
|
||||
blob.getMetadata().setId(blobMeta.getProviderId());
|
||||
blob.getMetadata().setLastModified(blobMeta.getLastModified());
|
||||
blob.getMetadata().setLocation(blobMeta.getLocation());
|
||||
blob.getMetadata().setUri(blobMeta.getUri());
|
||||
return blob;
|
||||
}
|
||||
|
||||
public static String parseContainerFromPath(String path) {
|
||||
String container = checkNotNull(path, "path");
|
||||
if (path.indexOf('/') != -1)
|
||||
container = path.substring(0, path.indexOf('/'));
|
||||
return container;
|
||||
}
|
||||
|
||||
public static String parsePrefixFromPath(String path) {
|
||||
String prefix = null;
|
||||
if (checkNotNull(path, "path").indexOf('/') != -1)
|
||||
prefix = path.substring(path.indexOf('/') + 1);
|
||||
return "".equals(prefix) ? null : prefix;
|
||||
}
|
||||
|
||||
public static String parseDirectoryFromPath(String path) {
|
||||
return checkNotNull(path, "path").substring(0, path.lastIndexOf('/'));
|
||||
}
|
||||
|
@ -131,19 +77,6 @@ public class BlobStoreUtils {
|
|||
return objectKey;
|
||||
}
|
||||
|
||||
public static String getContentAsStringOrNullAndClose(Blob blob) throws IOException {
|
||||
checkNotNull(blob, "blob");
|
||||
checkNotNull(blob.getPayload(), "blob.payload");
|
||||
if (blob.getPayload().getInput() == null)
|
||||
return null;
|
||||
Object o = blob.getPayload().getInput();
|
||||
if (o instanceof InputStream) {
|
||||
return Strings2.toStringAndClose((InputStream) o);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Object type not supported: " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static final BlobName blobName = new BlobName();
|
||||
|
||||
public static ListenableFuture<Void> createParentIfNeededAsync(AsyncBlobStore asyncBlobStore, String container,
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.jclouds.blobstore.options.GetOptions.Builder.ifETagMatches;
|
|||
import static org.jclouds.blobstore.options.GetOptions.Builder.ifModifiedSince;
|
||||
import static org.jclouds.blobstore.options.GetOptions.Builder.ifUnmodifiedSince;
|
||||
import static org.jclouds.blobstore.options.GetOptions.Builder.range;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose;
|
||||
import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
|
||||
import static org.jclouds.io.ByteSources.asByteSource;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.blobstore.integration.internal;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.inDirectory;
|
||||
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.blobstore.integration.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagateIfPossible;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
@ -48,6 +49,7 @@ import org.jclouds.blobstore.domain.StorageType;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
@ -64,6 +66,7 @@ import com.google.common.reflect.TypeToken;
|
|||
import com.google.inject.Module;
|
||||
|
||||
public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreContext> {
|
||||
|
||||
protected static final String LOCAL_ENCODING = System.getProperty("file.encoding");
|
||||
protected static final String XML_STRING_FORMAT = "<apples><apple name=\"%s\"></apple> </apples>";
|
||||
protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple");
|
||||
|
@ -501,6 +504,18 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
|
|||
return newScratchContainer;
|
||||
}
|
||||
|
||||
public static String getContentAsStringOrNullAndClose(Blob blob) throws IOException {
|
||||
checkNotNull(blob, "blob");
|
||||
checkNotNull(blob.getPayload(), "blob.payload");
|
||||
if (blob.getPayload().getInput() == null)
|
||||
return null;
|
||||
Object o = blob.getPayload().getInput();
|
||||
if (o instanceof InputStream) {
|
||||
return Strings2.toStringAndClose((InputStream) o);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Object type not supported: " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
protected Module createHttpModule() {
|
||||
return new JavaUrlHttpCommandExecutorServiceModule();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ import static org.easymock.EasyMock.replay;
|
|||
import static org.easymock.EasyMock.verify;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.createParentIfNeededAsync;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getNameFor;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.parseContainerFromPath;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.parsePrefixFromPath;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -149,22 +147,4 @@ public class BlobStoreUtilsTest {
|
|||
assertEquals(getNameFor(request), "four");
|
||||
}
|
||||
|
||||
public void testGetContainer() {
|
||||
String container = parseContainerFromPath("foo");
|
||||
assertEquals(container, "foo");
|
||||
container = parseContainerFromPath("foo/");
|
||||
assertEquals(container, "foo");
|
||||
container = parseContainerFromPath("foo/bar");
|
||||
assertEquals(container, "foo");
|
||||
}
|
||||
|
||||
public void testGetPrefix() {
|
||||
String prefix = parsePrefixFromPath("foo");
|
||||
assertEquals(prefix, null);
|
||||
prefix = parsePrefixFromPath("foo/");
|
||||
assertEquals(prefix, null);
|
||||
prefix = parsePrefixFromPath("foo/bar");
|
||||
assertEquals(prefix, "bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,11 +25,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.util.Multimaps2;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
|
@ -91,8 +90,34 @@ public class Auth implements Comparable<Auth> {
|
|||
|
||||
public Auth(Token token, Multimap<String, Endpoint> serviceCatalog) {
|
||||
this.token = checkNotNull(token, "token");
|
||||
this.serviceCatalog = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(serviceCatalog,
|
||||
"serviceCatalog")));
|
||||
this.serviceCatalog = toOldSchool(ImmutableMultimap.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")));
|
||||
}
|
||||
|
||||
/**
|
||||
* The traditional way to represent a graph in Java is Map<V, Set<V>>, which is awkward in a number of ways. Guava's
|
||||
* Multimap framework makes it easy to handle a mapping from keys to multiple values.
|
||||
* <p/>
|
||||
* Until we write or discover a gson Multimap deserializer, we may be stuck with this.
|
||||
*
|
||||
* TODO: ask on stackoverflow and/or jesse wilson
|
||||
*/
|
||||
@Deprecated
|
||||
private static <K, V> Map<K, Set<V>> toOldSchool(Multimap<K, V> in) {
|
||||
ImmutableMap.Builder<K, Set<V>> out = ImmutableMap.builder();
|
||||
for (K type : in.keySet())
|
||||
out.put(type, ImmutableSet.copyOf(in.get(type)));
|
||||
return out.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #toOldSchool
|
||||
*/
|
||||
@Deprecated
|
||||
private static <K, V> ImmutableMultimap<K, V> fromOldSchool(Map<K, Set<V>> in) {
|
||||
ImmutableMultimap.Builder<K, V> out = ImmutableMultimap.builder();
|
||||
for (K type : in.keySet())
|
||||
out.putAll(type, ImmutableSet.copyOf(in.get(type)));
|
||||
return out.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +131,7 @@ public class Auth implements Comparable<Auth> {
|
|||
* TODO
|
||||
*/
|
||||
public Multimap<String, Endpoint> getServiceCatalog() {
|
||||
return Multimaps2.fromOldSchool(serviceCatalog);
|
||||
return fromOldSchool(serviceCatalog);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,11 +30,11 @@ import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
|||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
|
|||
|
||||
@Override
|
||||
public Supplier<ReferenceType> apply(final String user) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(VCloudSession session) {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -85,7 +85,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -122,7 +122,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -137,7 +137,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -82,12 +82,12 @@ import org.jclouds.trmk.vcloud_0_8.location.DefaultVDC;
|
|||
import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -143,7 +143,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSupplier) {
|
||||
return Suppliers2.compose(
|
||||
return Suppliers.compose(
|
||||
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
|
@ -173,7 +173,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@Singleton
|
||||
@OrgList
|
||||
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, URI>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(VCloudSession arg0) {
|
||||
|
@ -352,7 +352,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg(
|
||||
final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers2.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
|
||||
return Suppliers.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
|
||||
|
||||
@Override
|
||||
public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) {
|
||||
|
|
|
@ -62,11 +62,11 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -213,7 +213,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) {
|
||||
return Suppliers2.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||
return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Image> apply(Set<? extends Image> from) {
|
||||
|
@ -263,7 +263,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {
|
||||
return Suppliers2.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
|
||||
|
|
|
@ -32,6 +32,8 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|||
import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
@ -55,7 +57,6 @@ import org.jclouds.compute.options.TemplateOptions;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Lists2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -800,7 +801,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
Iterable<? extends Image> matchingImages = filter(supportedImages, imagePredicate);
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("<< matched images(%s)", transform(matchingImages, imageToId));
|
||||
List<? extends Image> maxImages = Lists2.multiMax(DEFAULT_IMAGE_ORDERING, matchingImages);
|
||||
List<? extends Image> maxImages = multiMax(DEFAULT_IMAGE_ORDERING, matchingImages);
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("<< best images(%s)", transform(maxImages, imageToId));
|
||||
return maxImages.get(maxImages.size() - 1);
|
||||
|
@ -812,6 +813,27 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like Ordering, but handle the case where there are multiple valid maximums
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@VisibleForTesting
|
||||
static <T, E extends T> List<E> multiMax(Comparator<T> ordering, Iterable<E> iterable) {
|
||||
Iterator<E> iterator = iterable.iterator();
|
||||
List<E> maxes = newArrayList(iterator.next());
|
||||
E maxSoFar = maxes.get(0);
|
||||
while (iterator.hasNext()) {
|
||||
E current = iterator.next();
|
||||
int comparison = ordering.compare(maxSoFar, current);
|
||||
if (comparison == 0) {
|
||||
maxes.add(current);
|
||||
} else if (comparison < 0) {
|
||||
maxes = newArrayList(current);
|
||||
maxSoFar = current;
|
||||
}
|
||||
}
|
||||
return maxes;
|
||||
}
|
||||
protected Set<? extends Image> getImages() {
|
||||
return images.get();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import javax.inject.Provider;
|
|||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Image.Status;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
|
@ -40,7 +41,6 @@ import org.jclouds.compute.domain.Processor;
|
|||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.Image.Status;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -52,6 +52,7 @@ import com.google.common.base.Supplier;
|
|||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -59,6 +60,17 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Test(groups = "unit", singleThreaded = true, testName = "TemplateBuilderImplTest")
|
||||
public class TemplateBuilderImplTest {
|
||||
|
||||
public void testMultiMax() {
|
||||
Iterable<String> values = ImmutableList.of("1", "2", "2", "3", "3");
|
||||
assertEquals(TemplateBuilderImpl.multiMax(Ordering.natural(), values), ImmutableList.of("3", "3"));
|
||||
}
|
||||
|
||||
public void testMultiMax1() {
|
||||
Iterable<String> values = ImmutableList.of("1", "2", "2", "3");
|
||||
assertEquals(TemplateBuilderImpl.multiMax(Ordering.natural(), values), ImmutableList.of("3"));
|
||||
}
|
||||
|
||||
protected Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build();
|
||||
|
||||
protected Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
||||
|
|
|
@ -25,12 +25,13 @@ import static com.google.common.primitives.Ints.asList;
|
|||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||
import static org.jclouds.http.HttpUtils.contains404;
|
||||
import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull;
|
||||
import static org.jclouds.util.Throwables2.containsResourceNotFoundException;
|
||||
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
|
||||
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.collect.IterableWithMarkers;
|
||||
import org.jclouds.collect.PagedIterable;
|
||||
import org.jclouds.collect.PagedIterables;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
@ -157,4 +158,8 @@ public final class Fallbacks {
|
|||
throw propagate(t);
|
||||
}
|
||||
|
||||
private static boolean containsResourceNotFoundException(Throwable from) {
|
||||
return getFirstThrowableOfType(from, ResourceNotFoundException.class) != null;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ package org.jclouds.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.util.Patterns;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -31,6 +31,10 @@ import org.jclouds.util.Patterns;
|
|||
*/
|
||||
public class JsonBall implements Comparable<String>, CharSequence {
|
||||
|
||||
public static final Pattern JSON_STRING_PATTERN = Pattern.compile("^[^\"\\{\\[].*[^\\{\\[\"]$");
|
||||
public static final Pattern JSON_NUMBER_PATTERN = Pattern.compile("^[0-9]*\\.?[0-9]*$");
|
||||
public static final Pattern JSON_BOOLEAN_PATTERN = Pattern.compile("^(true|false)$");
|
||||
|
||||
private final String value;
|
||||
|
||||
@Override
|
||||
|
@ -84,8 +88,8 @@ public class JsonBall implements Comparable<String>, CharSequence {
|
|||
}
|
||||
|
||||
static String quoteStringIfNotNumberOrBoolean(String in) {
|
||||
if (Patterns.JSON_STRING_PATTERN.matcher(in).find() && !Patterns.JSON_NUMBER_PATTERN.matcher(in).find()
|
||||
&& !Patterns.JSON_BOOLEAN_PATTERN.matcher(in).find()) {
|
||||
if (JSON_STRING_PATTERN.matcher(in).find() && !JSON_NUMBER_PATTERN.matcher(in).find()
|
||||
&& !JSON_BOOLEAN_PATTERN.matcher(in).find()) {
|
||||
return "\"" + in + "\"";
|
||||
}
|
||||
return in;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.domain;
|
||||
|
||||
import org.jclouds.crypto.Pems;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.util.CredentialUtils;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
|
@ -28,6 +28,11 @@ import com.google.common.base.Optional;
|
|||
*/
|
||||
public class LoginCredentials extends Credentials {
|
||||
|
||||
public static boolean isPrivateKeyCredential(String credential) {
|
||||
return credential != null
|
||||
&& (credential.startsWith(Pems.PRIVATE_PKCS1_MARKER) || credential.startsWith(Pems.PRIVATE_PKCS8_MARKER));
|
||||
}
|
||||
|
||||
public static LoginCredentials fromCredentials(Credentials creds) {
|
||||
if (creds == null)
|
||||
return null;
|
||||
|
@ -87,7 +92,7 @@ public class LoginCredentials extends Credentials {
|
|||
}
|
||||
|
||||
public Builder credential(String credential) {
|
||||
if (CredentialUtils.isPrivateKeyCredential(credential))
|
||||
if (isPrivateKeyCredential(credential))
|
||||
return noPassword().privateKey(credential);
|
||||
else if (credential != null)
|
||||
return password(credential).noPrivateKey();
|
||||
|
@ -119,7 +124,7 @@ public class LoginCredentials extends Credentials {
|
|||
}
|
||||
|
||||
public LoginCredentials(String username, @Nullable Optional<String> password, @Nullable Optional<String> privateKey, boolean authenticateSudo) {
|
||||
super(username, privateKey != null && privateKey.isPresent() && CredentialUtils.isPrivateKeyCredential(privateKey.get())
|
||||
super(username, privateKey != null && privateKey.isPresent() && isPrivateKeyCredential(privateKey.get())
|
||||
? privateKey.get()
|
||||
: (password != null && password.isPresent() ? password.get() : null));
|
||||
this.authenticateSudo = authenticateSudo;
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ExceptionToValueOrPropagate<E extends Exception, T> implements Function<Exception, T> {
|
||||
|
||||
private final Class<E> matchingClass;
|
||||
private final T value;
|
||||
|
||||
public ExceptionToValueOrPropagate(Class<E> matchingClass, @Nullable T value) {
|
||||
this.matchingClass = checkNotNull(matchingClass, "matchingClass");
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(Exception from) {
|
||||
checkNotNull(from, "exception");
|
||||
List<Throwable> throwables = Throwables.getCausalChain(from);
|
||||
Iterable<E> matchingThrowables = Iterables.filter(throwables, matchingClass);
|
||||
if (Iterables.size(matchingThrowables) >= 1)
|
||||
return value;
|
||||
throw Throwables.propagate(from);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
public class JoinOnK2<K, K2, V> implements Function<Map<K, Supplier<Set<K2>>>, Map<K2, Supplier<V>>> {
|
||||
private final Supplier<Map<K2, Supplier<V>>> regionToEndpointSupplier;
|
||||
|
||||
public JoinOnK2(Supplier<Map<K2, Supplier<V>>> regionToEndpointSupplier) {
|
||||
this.regionToEndpointSupplier = regionToEndpointSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<K2, Supplier<V>> apply(Map<K, Supplier<Set<K2>>> regionToZones) {
|
||||
Map<K2, Supplier<V>> regionToEndpoint = regionToEndpointSupplier.get();
|
||||
Builder<K2, Supplier<V>> builder = ImmutableMap.builder();
|
||||
for (Entry<K, Supplier<Set<K2>>> entry : regionToZones.entrySet()) {
|
||||
for (K2 zone : entry.getValue().get()) {
|
||||
builder.put(zone, regionToEndpoint.get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ParseContentMD5FromHeaders implements Function<HttpResponse, byte[]>,
|
||||
InvocationContext<ParseContentMD5FromHeaders> {
|
||||
|
||||
public static class NoContentMD5Exception extends RuntimeException {
|
||||
|
||||
private final HttpRequest request;
|
||||
private final HttpResponse response;
|
||||
|
||||
public NoContentMD5Exception(HttpRequest request, HttpResponse response) {
|
||||
super(String.format("no MD5 returned from request: %s; response %s", request, response));
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public HttpRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public HttpResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private HttpRequest request;
|
||||
|
||||
public byte[] apply(HttpResponse from) {
|
||||
releasePayload(from);
|
||||
if (from.getPayload() != null) {
|
||||
return from.getPayload().getContentMetadata().getContentMD5();
|
||||
}
|
||||
throw new NoContentMD5Exception(request, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseContentMD5FromHeaders setContext(HttpRequest request) {
|
||||
this.request = request;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.http.pool;
|
||||
|
||||
/**
|
||||
* Properties used in pooling http engines
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface PoolConstants {
|
||||
/**
|
||||
* Integer property. default (12)
|
||||
* <p/>
|
||||
* Limits the amount of connections per host.
|
||||
*/
|
||||
public static final String PROPERTY_POOL_MAX_CONNECTIONS = "jclouds.pool.max_connections";
|
||||
/**
|
||||
* Integer property. default (12)
|
||||
* <p/>
|
||||
* Amount of threads servicing the I/O of http connections
|
||||
*/
|
||||
public static final String PROPERTY_POOL_IO_WORKER_THREADS = "jclouds.http.pool.io_worker_threads";
|
||||
|
||||
/**
|
||||
* Integer property. default (2)
|
||||
* <p/>
|
||||
* Maximum amount of http session failures before a pool is disabled.
|
||||
*/
|
||||
public static final String PROPERTY_POOL_MAX_SESSION_FAILURES = "jclouds.http.pool.max_session_failures";
|
||||
/**
|
||||
* Integer property. default (75)
|
||||
* <p/>
|
||||
* Maximum amount of times to re-use an http connection. Services like Amazon S3 throw errors if
|
||||
* connections are reused too many times.
|
||||
*/
|
||||
public static final String PROPERTY_POOL_MAX_CONNECTION_REUSE = "jclouds.http.pool.max_connection_reuse";
|
||||
}
|
|
@ -52,12 +52,12 @@ import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.functions.ImplicitOptionalConverter;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -120,7 +120,7 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Set<String>> regionIdsSupplier(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, RegionIdFilter filter, RegionIdsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
Suppliers.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -130,7 +130,7 @@ public class LocationModule extends AbstractModule {
|
|||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
ZoneIdFilter filter, ZoneIdsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
Suppliers.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
static class FilterStrings implements Function<Set<String>, Set<String>>{
|
||||
|
|
|
@ -18,10 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.rest.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Map;
|
||||
import static org.jclouds.rest.config.BinderUtils.*;
|
||||
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.util.TypeTokens2;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
@ -41,14 +44,22 @@ public class RestClientModule<S, A> extends RestModule {
|
|||
*/
|
||||
protected RestClientModule(Map<Class<?>, Class<?>> sync2Async) {
|
||||
super(sync2Async);
|
||||
this.syncClientType = TypeTokens2.checkBound(new TypeToken<S>(getClass()) {
|
||||
this.syncClientType = checkBound(new TypeToken<S>(getClass()) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
});
|
||||
this.asyncClientType = TypeTokens2.checkBound(new TypeToken<A>(getClass()) {
|
||||
this.asyncClientType = checkBound(new TypeToken<A>(getClass()) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if the type is an instanceof {@link TypeVariable}
|
||||
*/
|
||||
private static <T> TypeToken<T> checkBound(TypeToken<T> type) throws IllegalStateException {
|
||||
checkState(!(type.getType() instanceof TypeVariable<?>),
|
||||
"unbound type variable: %s, use ctor that explicitly assigns this", type);
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* @see #RestClientModule(Map)
|
||||
*/
|
||||
|
@ -68,8 +79,8 @@ public class RestClientModule<S, A> extends RestModule {
|
|||
*/
|
||||
public RestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType, Map<Class<?>, Class<?>> sync2Async) {
|
||||
super(sync2Async);
|
||||
this.syncClientType = TypeTokens2.checkBound(syncClientType);
|
||||
this.asyncClientType = TypeTokens2.checkBound(asyncClientType);
|
||||
this.syncClientType = checkBound(syncClientType);
|
||||
this.asyncClientType = checkBound(asyncClientType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,6 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
|||
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
|
||||
import static org.jclouds.http.Uris.uriBuilder;
|
||||
import static org.jclouds.io.Payloads.newPayload;
|
||||
import static org.jclouds.util.Maps2.convertUnsafe;
|
||||
import static org.jclouds.util.Strings2.replaceTokens;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -59,6 +58,7 @@ import java.lang.reflect.ParameterizedType;
|
|||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -150,11 +150,13 @@ import com.google.common.cache.CacheBuilder;
|
|||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
@ -528,6 +530,14 @@ public abstract class RestAnnotationProcessor {
|
|||
return request;
|
||||
}
|
||||
|
||||
private static <K, V> Map<K, V> convertUnsafe(Multimap<K, V> in) {
|
||||
LinkedHashMap<K, V> out = Maps.newLinkedHashMap();
|
||||
for (Entry<K, V> entry : in.entries()) {
|
||||
out.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return ImmutableMap.copyOf(out);
|
||||
}
|
||||
|
||||
protected org.jclouds.rest.internal.GeneratedHttpRequest.Builder requestBuilder() {
|
||||
return GeneratedHttpRequest.builder();
|
||||
}
|
||||
|
|
|
@ -28,27 +28,6 @@ public class ClassLoadingUtils {
|
|||
//Utility Class
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a class using the class loader.
|
||||
* 1. The class loader of the context class is being used.
|
||||
* 2. The thread context class loader is being used.
|
||||
* If both approaches fail, returns null.
|
||||
*
|
||||
* @param contextClass The name of a context class to use.
|
||||
* @param className The name of the class to load
|
||||
* @return The class or null if no class loader could load the class.
|
||||
*/
|
||||
public static Class<?> loadClass(Class<?> contextClass, String className) {
|
||||
Class<?> clazz = null;
|
||||
if (contextClass.getClassLoader() != null) {
|
||||
clazz = silentLoadClass(className, contextClass.getClassLoader());
|
||||
}
|
||||
if (clazz == null && Thread.currentThread().getContextClassLoader() != null) {
|
||||
clazz = silentLoadClass(className, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the url of a resource.
|
||||
* 1. The context class is being used.
|
||||
|
@ -69,24 +48,4 @@ public class ClassLoadingUtils {
|
|||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a {@link Class} from the specified {@link ClassLoader} without throwing {@ClassNotFoundException}.
|
||||
*
|
||||
* @param className
|
||||
* @param classLoader
|
||||
* @return
|
||||
*/
|
||||
private static Class<?> silentLoadClass(String className, ClassLoader classLoader) {
|
||||
Class<?> clazz = null;
|
||||
if (classLoader != null && className != null) {
|
||||
try {
|
||||
clazz = classLoader.loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//Ignore and proceed to the next class loader.
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
||||
/**
|
||||
* For wrapping covariant functions for passing to non-covariant methods
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
public class ConcreteFunction<F,T> implements Function<F, T> {
|
||||
private final Function<? super F, ? extends T> delegate;
|
||||
|
||||
public static <F,T> ConcreteFunction<F,T> wrap(Function<? super F, ? extends T> delegate) {
|
||||
return new ConcreteFunction<F, T>(delegate);
|
||||
}
|
||||
|
||||
public ConcreteFunction(Function<? super F, ? extends T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(F input) {
|
||||
return delegate.apply(input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.crypto.Pems;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CredentialUtils {
|
||||
|
||||
public static Credentials overrideCredentialsIfSupplied(Credentials defaultCredentials,
|
||||
@Nullable Credentials overridingCredentials) {
|
||||
if (overridingCredentials == null)
|
||||
return defaultCredentials;
|
||||
String identity = overridingCredentials.identity != null ? overridingCredentials.identity : checkNotNull(
|
||||
defaultCredentials, "defaultCredentials").identity;
|
||||
String credential = overridingCredentials.credential != null ? overridingCredentials.credential : checkNotNull(
|
||||
defaultCredentials, "defaultCredentials").credential;
|
||||
|
||||
return new Credentials(identity, credential);
|
||||
}
|
||||
|
||||
public static boolean isPrivateKeyCredential(Credentials credentials) {
|
||||
return credentials != null && isPrivateKeyCredential(credentials.credential);
|
||||
}
|
||||
|
||||
public static boolean isPrivateKeyCredential(String credential) {
|
||||
return credential != null
|
||||
&& (credential.startsWith(Pems.PRIVATE_PKCS1_MARKER) || credential.startsWith(Pems.PRIVATE_PKCS8_MARKER));
|
||||
}
|
||||
|
||||
public static boolean isPrivateKeyEncrypted(byte[] privateKey) {
|
||||
return new String(privateKey).contains("Proc-Type: 4,ENCRYPTED");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* {@link InputStream} implementation that allows chaining of various streams for seamless
|
||||
* sequential reading
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Tomas Varaneckas <tomas.varaneckas@gmail.com>
|
||||
*/
|
||||
public class InputStreamChain extends InputStream {
|
||||
|
||||
/**
|
||||
* Input stream chain
|
||||
*/
|
||||
private final LinkedList<InputStream> streams = Lists.newLinkedList();
|
||||
|
||||
/**
|
||||
* Currently active stream
|
||||
*/
|
||||
private InputStream current;
|
||||
|
||||
public InputStreamChain(InputStream... inputStreams) {
|
||||
for (InputStream stream : inputStreams) {
|
||||
addInputStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds input stream to the end of chain
|
||||
*
|
||||
* @param stream
|
||||
* InputStream to add to chain
|
||||
* @return instance of self (for fluent calls)
|
||||
*/
|
||||
public InputStreamChain addInputStream(final InputStream stream) {
|
||||
streams.addLast(stream);
|
||||
if (current == null) {
|
||||
current = streams.removeFirst();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a String to the end of chain
|
||||
*
|
||||
* @param value
|
||||
* String to add to the chain
|
||||
* @return instance of self (for fluent calls)
|
||||
*/
|
||||
public InputStreamChain addAsInputStream(final String value) {
|
||||
return addInputStream(Strings2.toInputStream(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int bit = current.read();
|
||||
if (bit == -1 && streams.size() > 0) {
|
||||
try {
|
||||
current.close();
|
||||
} catch (final IOException e) {
|
||||
// replace this with a call to logging facility
|
||||
e.printStackTrace();
|
||||
}
|
||||
current = streams.removeFirst();
|
||||
bit = read();
|
||||
}
|
||||
return bit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
int available = current.available();
|
||||
for (InputStream stream : streams) {
|
||||
available += stream.available();
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
current.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return current.markSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mark(int i) {
|
||||
current.mark(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
current.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long l) throws IOException {
|
||||
return current.skip(l);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* General utilities used in jclouds code for {@link Iterable Iterables}.
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
public class Iterables2 {
|
||||
|
||||
/**
|
||||
* Copies the contents of a wildcarded {@link Iterable} into a concrete {@link Iterable} of the left bound
|
||||
*
|
||||
* @param unboundedValues wildcarded source {@link Iterable}
|
||||
* @return concrete-typed copy of the source
|
||||
*/
|
||||
public static <T> Iterable<T> concreteCopy(Iterable<? extends T> unboundedValues) {
|
||||
// Please do not attempt to sort, as this is wasteful
|
||||
return ImmutableSet.copyOf(unboundedValues);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Lists2 {
|
||||
|
||||
/**
|
||||
* Like Ordering, but handle the case where there are multiple valid maximums
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, E extends T> List<E> multiMax(Comparator<T> ordering, Iterable<E> iterable) {
|
||||
Iterator<E> iterator = iterable.iterator();
|
||||
List<E> maxes = newArrayList(iterator.next());
|
||||
E maxSoFar = maxes.get(0);
|
||||
while (iterator.hasNext()) {
|
||||
E current = iterator.next();
|
||||
int comparison = ordering.compare(maxSoFar, current);
|
||||
if (comparison == 0) {
|
||||
maxes.add(current);
|
||||
} else if (comparison < 0) {
|
||||
maxes = newArrayList(current);
|
||||
maxSoFar = current;
|
||||
}
|
||||
}
|
||||
return maxes;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,21 +19,13 @@
|
|||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Maps.filterKeys;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* General utilities used in jclouds code for {@link Map Maps}.
|
||||
|
@ -41,53 +33,6 @@ import com.google.common.collect.Multimap;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class Maps2 {
|
||||
public static <K> Function<Map<K, ?>, Set<K>> keySetFunction() {
|
||||
return new Function<Map<K, ?>, Set<K>>() {
|
||||
|
||||
@Override
|
||||
public Set<K> apply(Map<K, ?> arg0) {
|
||||
return arg0.keySet();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "keySet()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <K, V> Map<K, V> convertUnsafe(Multimap<K, V> in) {
|
||||
LinkedHashMap<K, V> out = Maps.newLinkedHashMap();
|
||||
for (Entry<K, V> entry : in.entries()) {
|
||||
out.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return ImmutableMap.copyOf(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the supplied map contains the key {@code k1}, its value will be assigned to the key {@code
|
||||
* k2}. Note that this doesn't modify the input map.
|
||||
*
|
||||
* @param <V>
|
||||
* type of value the map holds
|
||||
* @param in
|
||||
* the map you wish to make a copy of
|
||||
* @param k1
|
||||
* old key
|
||||
* @param k2
|
||||
* new key
|
||||
* @return copy of the map with the value of the key re-routed, or the original, if it {@code k1}
|
||||
* wasn't present.
|
||||
*/
|
||||
public static <V> Map<String, V> renameKey(Map<String, V> in, String k1, String k2) {
|
||||
if (checkNotNull(in, "input map").containsKey(checkNotNull(k1, "old key"))) {
|
||||
Builder<String, V> builder = ImmutableMap.builder();
|
||||
builder.putAll(filterKeys(in, not(equalTo(k1))));
|
||||
V tags = in.get(k1);
|
||||
builder.put(checkNotNull(k2, "new key"), tags);
|
||||
in = builder.build();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
* change the keys but keep the values in-tact.
|
||||
|
@ -112,57 +57,4 @@ public class Maps2 {
|
|||
returnVal.put(fn.apply(entry.getKey()), entry.getValue());
|
||||
return returnVal.build();
|
||||
}
|
||||
|
||||
public static <K, V> Supplier<Map<K, V>> composeMapSupplier(Iterable<Supplier<Map<K, V>>> suppliers) {
|
||||
return new ListMapSupplier<K, V>(suppliers);
|
||||
}
|
||||
|
||||
static class ListMapSupplier<K, V> implements Supplier<Map<K, V>> {
|
||||
|
||||
private final Iterable<Supplier<Map<K, V>>> suppliers;
|
||||
|
||||
ListMapSupplier(Iterable<Supplier<Map<K, V>>> suppliers) {
|
||||
this.suppliers = checkNotNull(suppliers, "suppliers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<K, V> get() {
|
||||
Map<K, V> toReturn = Maps.newLinkedHashMap();
|
||||
for (Supplier<Map<K, V>> supplier : suppliers) {
|
||||
toReturn.putAll(supplier.get());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a map with the given keys where values are generated by the given function.
|
||||
* Supports duplicate and {@code null} values, but {@code null} keys are <em>not</em> allowed.
|
||||
*
|
||||
* @param <K> the type of the keys
|
||||
* @param <V> the type of the values
|
||||
* @param keys the keys to be included in the map. Keys must be non-<code>null</code>
|
||||
* @param valueFunction the function that produces values for the keys
|
||||
* @return a map containing the keys from the given set with values which are generated from
|
||||
* the keys
|
||||
* @see Maps#uniqueIndex(Iterable, Function)
|
||||
*/
|
||||
public static <K, V> Map<K, V> fromKeys(Set<K> keys, Function<? super K, V> valueFunction) {
|
||||
Map<K, V> result = Maps.newHashMapWithExpectedSize(keys.size());
|
||||
for (K key : keys) {
|
||||
result.put(checkNotNull(key), valueFunction.apply(key));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Covariant compatible version
|
||||
*
|
||||
* @see {@link Maps#uniqueIndex(Iterable, Function)}
|
||||
*/
|
||||
public static <K, V> ImmutableMap<K, V> uniqueIndex(
|
||||
Iterable<? extends V> values, Function<? super V, ? extends K> keyFunction) {
|
||||
return ImmutableMap.copyOf(Maps.uniqueIndex(values, keyFunction));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Splitter.on;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Modules2 {
|
||||
|
||||
public static Iterable<Module> modulesFromCommaDelimitedString(String moduleClasses) {
|
||||
Iterable<Module> modules = ImmutableSet.of();
|
||||
if (moduleClasses != null) {
|
||||
Iterable<String> transformer = ImmutableList.copyOf(on(',').split(moduleClasses));
|
||||
modules = transform(transformer, new Function<String, Module>() {
|
||||
|
||||
@Override
|
||||
public Module apply(String from) {
|
||||
try {
|
||||
return (Module) ClassLoadingUtils.loadClass(Modules2.class, from).newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException("error instantiating " + from, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("error instantiating " + from, e);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
public static Iterable<Module> modulesForProviderInProperties(String providerName, Properties props) {
|
||||
return concat(modulesFromProperty(props, "jclouds.modules"),
|
||||
modulesFromProperty(props, providerName + ".modules"));
|
||||
}
|
||||
|
||||
public static Iterable<Module> modulesFromProperty(Properties props, String property) {
|
||||
return modulesFromCommaDelimitedString(props.getProperty(property, null));
|
||||
}
|
||||
|
||||
}
|
|
@ -20,16 +20,13 @@ package org.jclouds.util;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
|
||||
|
@ -39,34 +36,6 @@ import com.google.common.collect.Multimaps;
|
|||
*/
|
||||
public class Multimaps2 {
|
||||
|
||||
/**
|
||||
* The traditional way to represent a graph in Java is Map<V, Set<V>>, which is awkward in a
|
||||
* number of ways. Guava's Multimap framework makes it easy to handle a mapping from keys to
|
||||
* multiple values.
|
||||
* <p/>
|
||||
* Until we write or discover a gson Multimap deserializer, we may be stuck with this.
|
||||
*
|
||||
* TODO: ask on stackoverflow and/or jesse wilson
|
||||
*/
|
||||
@Deprecated
|
||||
public static <K, V> Map<K, Set<V>> toOldSchool(Multimap<K, V> in) {
|
||||
ImmutableMap.Builder<K, Set<V>> out = ImmutableMap.builder();
|
||||
for (K type : in.keySet())
|
||||
out.put(type, ImmutableSet.copyOf(in.get(type)));
|
||||
return out.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #toOldSchool
|
||||
*/
|
||||
@Deprecated
|
||||
public static <K, V> ImmutableMultimap<K, V> fromOldSchool(Map<K, Set<V>> in) {
|
||||
Builder<K, V> out = ImmutableMultimap.builder();
|
||||
for (K type : in.keySet())
|
||||
out.putAll(type, ImmutableSet.copyOf(in.get(type)));
|
||||
return out.build();
|
||||
}
|
||||
|
||||
public static <K, V> Multimap<K, V> replaceValue(Multimap<K, V> fromMultimap, final K key, final V value) {
|
||||
checkNotNull(fromMultimap, "input multimap");
|
||||
checkNotNull(key, "key");
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NullSafeCollections {
|
||||
|
||||
public static <T> Set<T> nullSafeSet(T in) {
|
||||
if (in == null) {
|
||||
return ImmutableSet.<T> of();
|
||||
}
|
||||
return ImmutableSet.<T> of(in);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
@ -32,52 +29,8 @@ import com.google.common.cache.LoadingCache;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class Patterns {
|
||||
public static final Pattern TOKEN_PATTERN = Pattern.compile("\\{(.+?)\\}");
|
||||
public static final Pattern TWO_SPACE_PATTERN = Pattern.compile(" ");
|
||||
public static final Pattern URL_ENCODED_PATTERN = Pattern.compile(".*%[a-fA-F0-9][a-fA-F0-9].*");
|
||||
public static final Pattern URI_PATTERN = Pattern.compile("([a-z0-9]+)://([^:]*):(.*)@(.*)");
|
||||
public static final Pattern PATTERN_THAT_BREAKS_URI = Pattern.compile("[a-z0-9]+://.*/.*@.*");
|
||||
public static final Pattern JSON_STRING_PATTERN = Pattern.compile("^[^\"\\{\\[].*[^\\{\\[\"]$");
|
||||
public static final Pattern JSON_NUMBER_PATTERN = Pattern.compile("^[0-9]*\\.?[0-9]*$");
|
||||
public static final Pattern JSON_BOOLEAN_PATTERN = Pattern.compile("^(true|false)$");
|
||||
public static final Pattern PLUS_PATTERN = Pattern.compile("\\+");
|
||||
public static final Pattern STAR_PATTERN = Pattern.compile("\\*");
|
||||
public static final Pattern _7E_PATTERN = Pattern.compile("%7E");
|
||||
|
||||
public static final Pattern NEWLINE_PATTERN = Pattern.compile("\r?\n");
|
||||
public static final Pattern SLASH_PATTERN = Pattern.compile("[/]");
|
||||
public static final Pattern IP_PATTERN = Pattern.compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)"
|
||||
+ "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b");
|
||||
public static final Pattern LEADING_SLASHES = Pattern.compile("^[/]+");
|
||||
public static final Pattern TRAILING_SLASHES = Pattern.compile("[/]*$");
|
||||
public static final Pattern REST_CONTEXT_BUILDER = Pattern.compile("(.*ContextBuilder)<([^,]+), ?([^>]+)>");
|
||||
|
||||
public static final LoadingCache<Character, String> CHAR_TO_ENCODED = CacheBuilder.newBuilder()
|
||||
.<Character, String> build(new CacheLoader<Character, String>() {
|
||||
@Override
|
||||
public String load(Character plain) throws ExecutionException {
|
||||
try {
|
||||
return URLEncoder.encode(plain + "", "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new ExecutionException("Bad encoding on input: " + plain, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static final LoadingCache<Character, Pattern> CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder()
|
||||
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
|
||||
@Override
|
||||
public Pattern load(Character plain) throws ExecutionException {
|
||||
return Pattern.compile(CHAR_TO_ENCODED.get(plain));
|
||||
}
|
||||
});
|
||||
|
||||
public static final LoadingCache<Character, Pattern> CHAR_TO_PATTERN = CacheBuilder.newBuilder()
|
||||
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
|
||||
@Override
|
||||
public Pattern load(Character plain) {
|
||||
return Pattern.compile(plain + "");
|
||||
}
|
||||
});
|
||||
|
||||
public static final LoadingCache<String, Pattern> TOKEN_TO_PATTERN = CacheBuilder.newBuilder()
|
||||
.<String, Pattern> build(new CacheLoader<String, Pattern>() {
|
||||
|
|
|
@ -28,15 +28,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
*/
|
||||
public class Preconditions2 {
|
||||
|
||||
/**
|
||||
* Will throw an exception if the argument is null or empty.
|
||||
*
|
||||
* @param nullableString
|
||||
* string to verify. Can be null or empty.
|
||||
*/
|
||||
public static void checkNotEmpty(String nullableString) {
|
||||
Preconditions2.checkNotEmpty(nullableString, "Argument can't be null or empty");
|
||||
}
|
||||
|
||||
/**
|
||||
* Will throw an exception if the argument is null or empty. Accepts a custom error message.
|
||||
|
@ -50,5 +41,4 @@ public class Preconditions2 {
|
|||
checkArgument(nullableString != null && nullableString.length() > 0, message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,19 +35,4 @@ public class Predicates2 {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns a predicate that evaluates to true if the String being tested ends with a prefix. */
|
||||
public static Predicate<String> endsWith(final String suffix) {
|
||||
return new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(final String input) {
|
||||
return input.endsWith(suffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "endsWith(" + suffix + ")";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,4 @@ public class SaxUtils {
|
|||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
public static String currentOrNegative(StringBuilder currentText) {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? "-1" : returnVal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,7 @@ package org.jclouds.util;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.io.ByteStreams.toByteArray;
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
import static org.jclouds.util.Patterns.CHAR_TO_ENCODED;
|
||||
import static org.jclouds.util.Patterns.CHAR_TO_PATTERN;
|
||||
import static org.jclouds.util.Patterns.TOKEN_TO_PATTERN;
|
||||
import static org.jclouds.util.Patterns.URL_ENCODED_PATTERN;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -41,6 +38,9 @@ import java.util.regex.Pattern;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.InputSupplier;
|
||||
|
@ -77,6 +77,21 @@ public class Strings2 {
|
|||
throw new IllegalStateException("error creating pattern: " + in, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final LoadingCache<Character, String> CHAR_TO_ENCODED = CacheBuilder.newBuilder()
|
||||
.<Character, String> build(new CacheLoader<Character, String>() {
|
||||
@Override
|
||||
public String load(Character plain) throws ExecutionException {
|
||||
try {
|
||||
return URLEncoder.encode(plain + "", "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new ExecutionException("Bad encoding on input: " + plain, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
private static final Pattern URL_ENCODED_PATTERN = Pattern.compile(".*%[a-fA-F0-9][a-fA-F0-9].*");
|
||||
|
||||
public static boolean isUrlEncoded(String in) {
|
||||
return URL_ENCODED_PATTERN.matcher(in).matches();
|
||||
}
|
||||
|
@ -106,13 +121,6 @@ public class Strings2 {
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
public static String replaceAll(String input, char ifMatch, Pattern pattern, String replacement) {
|
||||
if (input.indexOf(ifMatch) != -1) {
|
||||
input = pattern.matcher(input).replaceAll(replacement);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String replaceAll(String input, char match, String replacement) {
|
||||
if (input.indexOf(match) != -1) {
|
||||
try {
|
||||
|
@ -124,6 +132,14 @@ public class Strings2 {
|
|||
return input;
|
||||
}
|
||||
|
||||
private static final LoadingCache<Character, Pattern> CHAR_TO_PATTERN = CacheBuilder.newBuilder()
|
||||
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
|
||||
@Override
|
||||
public Pattern load(Character plain) {
|
||||
return Pattern.compile(plain + "");
|
||||
}
|
||||
});
|
||||
|
||||
public static String toString(InputSupplier<? extends InputStream> supplier)
|
||||
throws IOException {
|
||||
return CharStreams.toString(CharStreams.newReaderSupplier(supplier,
|
||||
|
@ -157,7 +173,7 @@ public class Strings2 {
|
|||
* token/value pairs
|
||||
*/
|
||||
public static String replaceTokens(String input, Map<String, String> replacements) {
|
||||
Matcher matcher = Patterns.TOKEN_PATTERN.matcher(input);
|
||||
Matcher matcher = TOKEN_PATTERN.matcher(input);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
while (matcher.find()) {
|
||||
|
@ -173,6 +189,8 @@ public class Strings2 {
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
private static final Pattern TOKEN_PATTERN = Pattern.compile("\\{(.+?)\\}");
|
||||
|
||||
public static String replaceTokens(String input, Multimap<String, ?> tokenValues) {
|
||||
for (Entry<String, ?> tokenValue : tokenValues.entries()) {
|
||||
Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey());
|
||||
|
|
|
@ -18,21 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.OutputSupplier;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,26 +34,6 @@ import com.google.common.io.OutputSupplier;
|
|||
*/
|
||||
public class Suppliers2 {
|
||||
|
||||
/**
|
||||
* Supplies a value that corresponds to a particular key in a map, or null, if not found
|
||||
*/
|
||||
public static <K, V> Supplier<V> valueForKey(final Supplier<Map<K, Supplier<V>>> input, final Supplier<K> key) {
|
||||
return new Supplier<V>() {
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
K keyToFind = key.get();
|
||||
Supplier<V> value = input.get().get(keyToFind);
|
||||
return value != null ? value.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "withKey()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <K, V> Supplier<V> getLastValueInMap(final Supplier<Map<K, Supplier<V>>> input) {
|
||||
return new Supplier<V>() {
|
||||
@Override
|
||||
|
@ -90,19 +64,6 @@ public class Suppliers2 {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* converts an {@link OutputStream} to an {@link OutputSupplier}
|
||||
*
|
||||
*/
|
||||
public static OutputSupplier<OutputStream> newOutputStreamSupplier(final OutputStream output) {
|
||||
checkNotNull(output, "output");
|
||||
return new OutputSupplier<OutputStream>() {
|
||||
public OutputStream getOutput() throws IOException {
|
||||
return output;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the value of the first supplier, or the value of the fallback, if the unlessNull is
|
||||
* null.
|
||||
|
@ -153,33 +114,4 @@ public class Suppliers2 {
|
|||
};
|
||||
}
|
||||
|
||||
// only here until guava compose gives a toString!
|
||||
// http://code.google.com/p/guava-libraries/issues/detail?id=1052
|
||||
public static <F, T> Supplier<T> compose(Function<? super F, T> function, Supplier<F> supplier) {
|
||||
Preconditions.checkNotNull(function);
|
||||
Preconditions.checkNotNull(supplier);
|
||||
return new SupplierComposition<F, T>(function, supplier);
|
||||
}
|
||||
|
||||
private static class SupplierComposition<F, T> implements Supplier<T> {
|
||||
|
||||
final Function<? super F, T> function;
|
||||
final Supplier<F> supplier;
|
||||
|
||||
SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
|
||||
this.function = function;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return function.apply(supplier.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("function", function).add("supplier", supplier).toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.CreationException;
|
||||
|
@ -58,10 +59,6 @@ public class Throwables2 {
|
|||
};
|
||||
}
|
||||
|
||||
public static boolean containsResourceNotFoundException(Throwable from) {
|
||||
return getFirstThrowableOfType(from, ResourceNotFoundException.class) != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Throwable> T getFirstThrowableOfType(Throwable from, Class<T> clazz) {
|
||||
if (from instanceof ProvisionException)
|
||||
|
@ -77,7 +74,8 @@ public class Throwables2 {
|
|||
}
|
||||
}
|
||||
|
||||
public static <T extends Throwable> T getFirstThrowableOfType(TransformParallelException e, Class<T> clazz) {
|
||||
@VisibleForTesting
|
||||
static <T extends Throwable> T getFirstThrowableOfType(TransformParallelException e, Class<T> clazz) {
|
||||
for (Exception exception : e.getFromToException().values()) {
|
||||
T cause = getFirstThrowableOfType(exception, clazz);
|
||||
if (cause != null)
|
||||
|
@ -86,7 +84,8 @@ public class Throwables2 {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e, Class<T> clazz) {
|
||||
@VisibleForTesting
|
||||
static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e, Class<T> clazz) {
|
||||
for (Message message : e.getErrorMessages()) {
|
||||
if (message.getCause() != null) {
|
||||
T cause = getFirstThrowableOfType(message.getCause(), clazz);
|
||||
|
@ -102,7 +101,8 @@ public class Throwables2 {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static <T extends Throwable> T getFirstThrowableOfType(CreationException e, Class<T> clazz) {
|
||||
@VisibleForTesting
|
||||
static <T extends Throwable> T getFirstThrowableOfType(CreationException e, Class<T> clazz) {
|
||||
for (Message message : e.getErrorMessages()) {
|
||||
if (message.getCause() != null) {
|
||||
T cause = getFirstThrowableOfType(message.getCause(), clazz);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TypeTokens2 {
|
||||
/**
|
||||
* @throws IllegalStateException if the type is an instanceof {@link TypeVariable}
|
||||
*/
|
||||
public static <T> TypeToken<T> checkBound(TypeToken<T> type) throws IllegalStateException {
|
||||
checkState(!(type.getType() instanceof TypeVariable<?>),
|
||||
"unbound type variable: %s, use ctor that explicitly assigns this", type);
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
@ -41,6 +42,52 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit")
|
||||
public class JsonBallTest {
|
||||
|
||||
public void testJSON_STRING_PATTERN1() {
|
||||
Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("hello");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN2() {
|
||||
Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("hello world!");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN3() {
|
||||
Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("\"hello world!\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN4() {
|
||||
Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("[hello world!]");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN5() {
|
||||
Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("{hello world!}");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN1() {
|
||||
Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("1");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN2() {
|
||||
Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("1.1");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN3() {
|
||||
Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("\"1.1\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN4() {
|
||||
Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("\"1\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
private ParseJson<Map<String, JsonBall>> handler;
|
||||
private Json mapper;
|
||||
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
* under the License.
|
||||
*/
|
||||
package org.jclouds.json.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.domain.JsonBall.JSON_BOOLEAN_PATTERN;
|
||||
import static org.jclouds.domain.JsonBall.JSON_NUMBER_PATTERN;
|
||||
import static org.jclouds.domain.JsonBall.JSON_STRING_PATTERN;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.util.Patterns;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
@ -80,8 +81,8 @@ public class NullHackJsonLiteralAdapterTest {
|
|||
}
|
||||
|
||||
static String quoteStringIfNotNumberOrBoolean(String in) {
|
||||
if (Patterns.JSON_STRING_PATTERN.matcher(in).find() && !Patterns.JSON_NUMBER_PATTERN.matcher(in).find()
|
||||
&& !Patterns.JSON_BOOLEAN_PATTERN.matcher(in).find()) {
|
||||
if (JSON_STRING_PATTERN.matcher(in).find() && !JSON_NUMBER_PATTERN.matcher(in).find()
|
||||
&& !JSON_BOOLEAN_PATTERN.matcher(in).find()) {
|
||||
return "\"" + in + "\"";
|
||||
}
|
||||
return in;
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class CredentialUtilsTest {
|
||||
|
||||
public void testOverridingCredentialsWhenOverridingIsNull() {
|
||||
Credentials defaultCredentials = new Credentials("foo", "bar");
|
||||
Credentials overridingCredentials = null;
|
||||
assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials),
|
||||
defaultCredentials);
|
||||
}
|
||||
|
||||
public void testOverridingCredentialsWhenOverridingLoginIsNull() {
|
||||
Credentials defaultCredentials = new Credentials("foo", "bar");
|
||||
Credentials overridingCredentials = new Credentials(null, "baz");
|
||||
assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials),
|
||||
new Credentials("foo", "baz"));
|
||||
}
|
||||
|
||||
public void testOverridingCredentialsWhenOverridingCredentialIsNull() {
|
||||
Credentials defaultCredentials = new Credentials("foo", "bar");
|
||||
Credentials overridingCredentials = new Credentials("fooble", null);
|
||||
assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials),
|
||||
new Credentials("fooble", "bar"));
|
||||
}
|
||||
|
||||
public void testOverridingCredentialsWhenOverridingCredentialsAreNull() {
|
||||
Credentials defaultCredentials = new Credentials("foo", "bar");
|
||||
Credentials overridingCredentials = new Credentials(null, null);
|
||||
assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials),
|
||||
new Credentials("foo", "bar"));
|
||||
}
|
||||
|
||||
}
|
|
@ -18,11 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static com.google.common.base.Functions.constant;
|
||||
import static com.google.common.base.Functions.identity;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -30,24 +26,12 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class Maps2Test {
|
||||
public void testRenameKeyWhenNotFound() {
|
||||
Map<String, String> nothing = ImmutableMap.of();
|
||||
assertEquals(Maps2.renameKey(nothing, "foo", "bar"), nothing);
|
||||
}
|
||||
|
||||
public void testRenameKeyWhenFound() {
|
||||
Map<String, String> nothing = ImmutableMap.of("foo", "bar");
|
||||
assertEquals(Maps2.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar"));
|
||||
}
|
||||
|
||||
public void testTransformKeys() {
|
||||
Map<String, String> map = ImmutableMap.of("prefix:foo", "bar");
|
||||
|
@ -60,45 +44,4 @@ public class Maps2Test {
|
|||
|
||||
}), ImmutableMap.of("foo", "bar"));
|
||||
}
|
||||
|
||||
public void testFromKeysEmptyKeys() {
|
||||
assertTrue(Maps2.fromKeys(ImmutableSet.of(), identity()).isEmpty(),
|
||||
"Expected returned map to be empty");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = { NullPointerException.class })
|
||||
public void testFromKeysNullKey() {
|
||||
Maps2.fromKeys(newHashSet((Object) null), constant("const"));
|
||||
}
|
||||
|
||||
public void testFromKeys() {
|
||||
// ImmutableMap doesn't support null values
|
||||
Map<String, String> expected = Maps.newHashMap();
|
||||
expected.put("foo", "foo");
|
||||
expected.put("bar", "foo");
|
||||
expected.put("baz", null);
|
||||
|
||||
assertEquals(Maps2.fromKeys(ImmutableSet.of("foo", "bar", "baz"),
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
return (input.equals("baz") ? null : "foo");
|
||||
}
|
||||
}), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCovariantUniqueIndex() {
|
||||
Iterable<Integer> values = Lists.newArrayList(1, 2, 3, 4, 5);
|
||||
Map<Number, Number> map = Maps2.<Number, Number>uniqueIndex(values, new Function<Object, Double>() {
|
||||
|
||||
@Override
|
||||
public Double apply(Object input) {
|
||||
return (Integer)input + 0.1;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(map.get(1.1), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.util;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class PatternsTest {
|
||||
|
||||
public void testJSON_STRING_PATTERN1() {
|
||||
Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("hello");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN2() {
|
||||
Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("hello world!");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN3() {
|
||||
Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("\"hello world!\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN4() {
|
||||
Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("[hello world!]");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_STRING_PATTERN5() {
|
||||
Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("{hello world!}");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN1() {
|
||||
Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("1");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN2() {
|
||||
Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("1.1");
|
||||
assert (matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN3() {
|
||||
Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("\"1.1\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testJSON_NUMBER_PATTERN4() {
|
||||
Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("\"1\"");
|
||||
assert (!matcher.find());
|
||||
}
|
||||
|
||||
public void testREST_CONTEXT_BUILDER() {
|
||||
Matcher matcher = Patterns.REST_CONTEXT_BUILDER
|
||||
.matcher("org.jclouds.rest.ContextBuilder<java.lang.String,java.lang.Integer>");
|
||||
assert (matcher.find());
|
||||
assertEquals(matcher.group(1), "org.jclouds.rest.ContextBuilder");
|
||||
assertEquals(matcher.group(2), "java.lang.String");
|
||||
assertEquals(matcher.group(3), "java.lang.Integer");
|
||||
|
||||
}
|
||||
|
||||
public void testREST_CONTEXT_BUILDERwithSpace() {
|
||||
Matcher matcher = Patterns.REST_CONTEXT_BUILDER
|
||||
.matcher("org.jclouds.rest.ContextBuilder<java.lang.String, java.lang.Integer>");
|
||||
assert (matcher.find());
|
||||
assertEquals(matcher.group(1), "org.jclouds.rest.ContextBuilder");
|
||||
assertEquals(matcher.group(2), "java.lang.String");
|
||||
assertEquals(matcher.group(3), "java.lang.Integer");
|
||||
}
|
||||
}
|
|
@ -31,22 +31,6 @@ import com.google.common.collect.ImmutableMap;
|
|||
|
||||
public class Suppliers2Test {
|
||||
|
||||
@Test
|
||||
public void testWithKey() {
|
||||
assertEquals(
|
||||
Suppliers2.<String, String> valueForKey(
|
||||
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("foo",
|
||||
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithKeyUnmatchedIsNull() {
|
||||
assertEquals(
|
||||
Suppliers2.<String, String> valueForKey(
|
||||
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("boo",
|
||||
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLastValueInMap() {
|
||||
assertEquals(
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
package org.jclouds.ssh.jsch;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ssh.jsch.JschSshClient.Connection;
|
||||
import org.jclouds.util.CredentialUtils;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.net.HostAndPort;
|
||||
|
@ -120,13 +118,10 @@ public class SessionConnection implements Connection<Session> {
|
|||
if (loginCredentials.getPrivateKey() == null) {
|
||||
session.setPassword(loginCredentials.getPassword());
|
||||
} else {
|
||||
byte[] privateKey = loginCredentials.getPrivateKey().getBytes();
|
||||
if (CredentialUtils.isPrivateKeyEncrypted(privateKey)) {
|
||||
throw new IllegalArgumentException(
|
||||
checkArgument(!loginCredentials.getPrivateKey().contains("Proc-Type: 4,ENCRYPTED"),
|
||||
"JschSshClientModule does not support private keys that require a passphrase");
|
||||
}
|
||||
jsch.addIdentity(loginCredentials.getUser(), Arrays.copyOf(privateKey, privateKey.length), null,
|
||||
emptyPassPhrase);
|
||||
byte[] privateKey = loginCredentials.getPrivateKey().getBytes();
|
||||
jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
|
||||
}
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
|
|
|
@ -68,10 +68,10 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.Utils;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -147,7 +147,7 @@ public class AbiquoRestClientModule extends RestClientModule<AbiquoApi, AbiquoAs
|
|||
public Supplier<Map<Integer, Datacenter>> getAvailableRegionsIndexedById(
|
||||
final AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier<Enterprise> currentEnterprise) {
|
||||
Supplier<Map<Integer, Datacenter>> availableRegionsMapSupplier = Suppliers2.compose(
|
||||
Supplier<Map<Integer, Datacenter>> availableRegionsMapSupplier = Suppliers.compose(
|
||||
new Function<List<Datacenter>, Map<Integer, Datacenter>>() {
|
||||
@Override
|
||||
public Map<Integer, Datacenter> apply(final List<Datacenter> datacenters) {
|
||||
|
|
|
@ -54,16 +54,16 @@ import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatacenterAndNam
|
|||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatasetInDatacenter;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.MachineInDatacenter;
|
||||
import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.PackageInDatacenter;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.inject.Injector;
|
||||
|
@ -134,11 +134,11 @@ public class JoyentCloudComputeServiceContextModule extends
|
|||
@Singleton
|
||||
protected Supplier<Map<String, Location>> createLocationIndexedById(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Location> apply(Set<? extends Location> arg0) {
|
||||
return Maps.uniqueIndex(Iterables2.concreteCopy(arg0), new Function<Location, String>() {
|
||||
return Maps.uniqueIndex(ImmutableSet.<Location> copyOf(arg0), new Function<Location, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Location arg0) {
|
||||
|
|
|
@ -45,30 +45,30 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.savvis.vpdc.VPDCAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.VPDCApi;
|
||||
import org.jclouds.savvis.vpdc.VPDCAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.domain.internal.VCloudSession;
|
||||
import org.jclouds.savvis.vpdc.features.BrowsingAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.BrowsingApi;
|
||||
import org.jclouds.savvis.vpdc.features.FirewallAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.BrowsingAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.FirewallApi;
|
||||
import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.FirewallAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.ServiceManagementApi;
|
||||
import org.jclouds.savvis.vpdc.features.VMAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.features.VMApi;
|
||||
import org.jclouds.savvis.vpdc.features.VMAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler;
|
||||
import org.jclouds.savvis.vpdc.internal.LoginAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.internal.LoginApi;
|
||||
import org.jclouds.savvis.vpdc.internal.LoginAsyncApi;
|
||||
import org.jclouds.savvis.vpdc.internal.VCloudToken;
|
||||
import org.jclouds.savvis.vpdc.location.FirstNetwork;
|
||||
import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
|
@ -93,7 +93,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCApi, VPDCAsyncApi
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, String>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(VCloudSession input) {
|
||||
|
@ -108,7 +108,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCApi, VPDCAsyncApi
|
|||
@Singleton
|
||||
protected Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> provideOrgs(Supplier<VCloudSession> cache,
|
||||
@Identity final String user) {
|
||||
return Suppliers2.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() {
|
||||
return Suppliers.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() {
|
||||
|
||||
@Override
|
||||
public Set<org.jclouds.savvis.vpdc.domain.Resource> apply(VCloudSession input) {
|
||||
|
@ -124,7 +124,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCApi, VPDCAsyncApi
|
|||
@Singleton
|
||||
protected Supplier<String> provideDefaultOrgId(
|
||||
@org.jclouds.savvis.vpdc.internal.Org Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> orgs) {
|
||||
return Suppliers2.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() {
|
||||
return Suppliers.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Set<org.jclouds.savvis.vpdc.domain.Resource> input) {
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi;
|
||||
import org.jclouds.vcloud.director.v1_5.annotations.Login;
|
||||
|
@ -94,6 +93,7 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -172,7 +172,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
@Login
|
||||
protected Supplier<URI> loginUrl(@Provider Supplier<URI> provider) {
|
||||
// TODO: technically, we should implement version api, but this will work
|
||||
return Suppliers2.compose(new Function<URI, URI>() {
|
||||
return Suppliers.compose(new Function<URI, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(URI arg0) {
|
||||
|
@ -184,7 +184,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
|
||||
@Provides
|
||||
protected Supplier<Session> currentSession(Supplier<SessionWithToken> in) {
|
||||
return Suppliers2.compose(new Function<SessionWithToken, Session>() {
|
||||
return Suppliers.compose(new Function<SessionWithToken, Session>() {
|
||||
|
||||
@Override
|
||||
public Session apply(SessionWithToken arg0) {
|
||||
|
@ -199,7 +199,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.director.v1_5.annotations.Session
|
||||
protected Supplier<String> sessionToken(Supplier<SessionWithToken> in) {
|
||||
return Suppliers2.compose(new Function<SessionWithToken, String>() {
|
||||
return Suppliers.compose(new Function<SessionWithToken, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(SessionWithToken arg0) {
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.azureblob;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||
import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404;
|
||||
import org.jclouds.http.functions.ParseContentMD5FromHeaders;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
||||
/**
|
||||
* Helper functions needed to to derive BlobStore values
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd135733.aspx" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
|
||||
public interface AzureBlobUtil {
|
||||
|
||||
@GET
|
||||
@Headers(keys = "Range", values = "bytes=0-0")
|
||||
// should use HEAD, this is a hack per http://code.google.com/p/jclouds/issues/detail?id=92
|
||||
@ResponseParser(ParseContentMD5FromHeaders.class)
|
||||
@Fallback(ThrowKeyNotFoundOn404.class)
|
||||
@Path("{key}")
|
||||
byte[] getMD5(@EndpointParam URI container, @PathParam("key") String key);
|
||||
|
||||
}
|
Loading…
Reference in New Issue