added toString to common functions so that they are easier to see when debugging

This commit is contained in:
Adrian Cole 2011-03-14 01:39:59 -07:00
parent b0f37625ec
commit f5fa2d983b
9 changed files with 166 additions and 127 deletions

View File

@ -82,9 +82,9 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
@Inject
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AtmosAsyncClient async,
AtmosClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd,
BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions,
@Memoized Supplier<Set<? extends Location>> locations, AtmosAsyncClient async, AtmosClient sync,
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
super(context, blobUtils, service, defaultLocation, locations);
@ -235,9 +235,12 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
@Override
public String call() throws Exception {
return AtmosUtils.putBlob(sync, crypto, blob2Object, container, blob);
}
@Override
public String toString() {
return "putBlob(" + container + "," + blob.getMetadata().getName() + ")";
}
}), service);
}

View File

@ -129,6 +129,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
return blobUtils.countBlobs(containerName, options);
}
@Override
public String toString() {
return "countBlobs(" + containerName + ")";
}
}), service);
}
@ -159,6 +163,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
return null;
}
@Override
public String toString() {
return "clearContainer(" + containerName + ")";
}
}), service);
}
@ -177,6 +185,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
return null;
}
@Override
public String toString() {
return "deleteDirectory(" + containerName + "," + directory + ")";
}
}), service);
}
@ -195,6 +207,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
return blobUtils.directoryExists(containerName, directory);
}
@Override
public String toString() {
return "directoryExists(" + containerName + "," + directory + ")";
}
}), service);
}
@ -215,6 +231,11 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
blobUtils.createDirectory(containerName, directory);
return null;
}
@Override
public String toString() {
return "createDirectory(" + containerName + "," + directory + ")";
}
}), service);
}
@ -247,6 +268,10 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
return null;
}
@Override
public String toString() {
return "deleteContainer(" + container + ")";
}
}), service);
}

View File

@ -155,8 +155,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
public String sign(String stringToSign) {
String signature;
try {
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(stringToSign),
crypto.hmacSHA256(secretKey.getBytes())));
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(stringToSign), crypto
.hmacSHA256(secretKey.getBytes())));
if (signatureWire.enabled())
signatureWire.input(Strings2.toInputStream(signature));
} catch (Exception e) {
@ -184,14 +184,16 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
@VisibleForTesting
String buildCanonicalizedString(Multimap<String, String> decodedParams) {
return ModifyRequest.makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
return ModifyRequest.makeQueryLine(decodedParams, sortAWSFirst);
}
public static final Comparator<Map.Entry<String, String>> sortAWSFirst = new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
if (o1.getKey().startsWith("AWSAccessKeyId"))
return -1;
return o1.getKey().compareTo(o2.getKey());
}
});
}
};
@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {

View File

@ -83,6 +83,10 @@ public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>>
return sizesInOrg.apply(from);
}
@Override
public String toString() {
return "sizesInOrg(" + from.getHref() + ")";
}
});
}

View File

@ -83,6 +83,10 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
return imagesInOrg.apply(from);
}
@Override
public String toString() {
return "imagesInOrg(" + from.getHref() + ")";
}
});
}

View File

@ -133,12 +133,14 @@ public class BaseComputeService implements ComputeService {
@Inject
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
GetNodeMetadataStrategy getNodeMetadataStrategy,
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider,
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
@ -287,6 +289,10 @@ public class BaseComputeService implements ComputeService {
return from;
}
@Override
public String toString() {
return "destroyNode(" + from.getId() + ")";
}
});
}
@ -484,8 +490,8 @@ public class BaseComputeService implements ComputeService {
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter, Payload runScript,
RunScriptOptions options) throws RunScriptOnNodesException {
try {
return runScriptOnNodesMatching(filter,
Statements.exec(Strings2.toStringAndClose(checkNotNull(runScript, "runScript").getInput())), options);
return runScriptOnNodesMatching(filter, Statements.exec(Strings2.toStringAndClose(checkNotNull(runScript,
"runScript").getInput())), options);
} catch (IOException e) {
Throwables.propagate(e);
return null;
@ -552,8 +558,7 @@ public class BaseComputeService implements ComputeService {
private Iterable<? extends RunScriptOnNode> transformNodesIntoInitializedScriptRunners(
Iterable<? extends NodeMetadata> nodes, Statement script, RunScriptOptions options,
Map<NodeMetadata, Exception> badNodes) {
return filter(
transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes),
return filter(transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes),
executor, null, logger, "initialize script runners"), notNull());
}

View File

@ -150,7 +150,7 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
request = filter.filter(request);
}
checkRequestHasContentLengthOrChunkedEncoding(request,
"After filtering, the request has niether chunked encoding nor content length: " + request);
"After filtering, the request has neither chunked encoding nor content length: " + request);
logger.debug("Sending request %s: %s", request.hashCode(), request.getRequestLine());
wirePayloadIfEnabled(wire, request);
utils.logRequest(headerLog, request, ">>");
@ -203,6 +203,11 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
return shouldContinue;
}
@Override
public String toString() {
return "[command=" + command + "]";
}
}
protected abstract Q convert(HttpRequest request) throws IOException, InterruptedException;

View File

@ -20,16 +20,12 @@
package org.jclouds.http.utils;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
import java.net.URI;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import javax.annotation.Nullable;
import javax.ws.rs.core.UriBuilder;
@ -40,6 +36,7 @@ import org.jclouds.util.Strings2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
@ -51,9 +48,7 @@ import com.google.common.collect.Multimap;
public class ModifyRequest {
@SuppressWarnings("unchecked")
public static <R extends HttpRequest> R putHeaders(R request, Multimap<String, String> moreHeaders) {
return (R) request
.toBuilder()
.headers(
return (R) request.toBuilder().headers(
ImmutableMultimap.<String, String> builder().putAll(request.getHeaders()).putAll(moreHeaders).build())
.build();
}
@ -168,8 +163,8 @@ public class ModifyRequest {
public static String makeQueryLine(Multimap<String, String> params,
@Nullable Comparator<Map.Entry<String, String>> sorter, char... skips) {
Iterator<Map.Entry<String, String>> pairs = ((sorter == null) ? params.entries() : sortEntries(params.entries(),
sorter)).iterator();
Iterator<Map.Entry<String, String>> pairs = ((sorter == null) ? params.entries() : ImmutableSortedSet.copyOf(
sorter, params.entries())).iterator();
StringBuilder formBuilder = new StringBuilder();
while (pairs.hasNext()) {
Map.Entry<String, String> pair = pairs.next();
@ -183,12 +178,4 @@ public class ModifyRequest {
}
return formBuilder.toString();
}
public static SortedSet<Entry<String, String>> sortEntries(Collection<Map.Entry<String, String>> in,
Comparator<Map.Entry<String, String>> sorter) {
SortedSet<Entry<String, String>> entries = newTreeSet(sorter);
entries.addAll(in);
return entries;
}
}

View File

@ -77,6 +77,10 @@ public class FutureExceptionParserTest {
throw exception;
}
@Override
public String toString() {
return "throwException(" + exception + ")";
}
}), executorService);
future = new ExceptionParsingListenableFuture(future, new Function<Exception, String>() {