Issue 981:Quiet down jclouds.compute logger

This commit is contained in:
Adrian Cole 2012-06-16 16:33:32 -04:00
parent c9424692ab
commit 3afdcb66b3
17 changed files with 140 additions and 72 deletions

View File

@ -165,7 +165,7 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
}
});
} catch (NoSuchElementException e) {
logger.debug("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
logger.trace("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
}
return null;
}

View File

@ -103,9 +103,16 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
@Override
public ToStringHelper string() {
return super.string().add("autoAssignFloatingIp", autoAssignFloatingIp)
.add("securityGroupNames", securityGroupNames).add("generateKeyPair", generateKeyPair)
.add("keyPairName", keyPairName).add("userData", userData);
ToStringHelper toString = super.string();
if (!autoAssignFloatingIp)
toString.add("autoAssignFloatingIp", autoAssignFloatingIp);
if (securityGroupNames.size() != 0)
toString.add("securityGroupNames", securityGroupNames);
if (generateKeyPair)
toString.add("generateKeyPair", generateKeyPair);
toString.add("keyPairName", keyPairName);
toString.add("userData", userData);
return toString;
}
public static final NovaTemplateOptions NONE = new NovaTemplateOptions();

View File

@ -32,14 +32,12 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
@ -71,7 +69,6 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
private final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache;
private final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
private final NovaClient novaClient;
private final Provider<TemplateBuilder> templateBuilderProvider;
@Inject
protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(
@ -80,13 +77,11 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
Provider<TemplateBuilder> templateBuilderProvider,
AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode,
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaClient novaClient) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider");
this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode,
@ -98,16 +93,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate;
// ensure we don't mutate the input template, fromTemplate ignores imageId so
// build directly from imageId if we have it
if (template.getImage() != null && template.getImage().getId() != null) {
mutableTemplate = templateBuilderProvider.get().imageId(template.getImage().getId()).fromTemplate(template)
.build();
// otherwise build from generic parameters
} else {
mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build();
}
Template mutableTemplate = template.clone();
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions());

View File

@ -26,8 +26,8 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject;
@ -40,8 +40,8 @@ import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.util.Preconditions2;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
@ -133,10 +133,18 @@ public class CreateServerOptions implements MapBinder {
}
protected ToStringHelper string() {
return toStringHelper("").add("keyName", keyName).add("securityGroupNames", securityGroupNames)
.add("metadata", metadata).add("personality", personality)
.add("adminPassPresent", adminPass != null)
.add("userData", userData == null ? null : new String(userData));
ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
toString.add("keyName", keyName);
if (securityGroupNames.size() > 0)
toString.add("securityGroupNames", securityGroupNames);
if (metadata.size() > 0)
toString.add("metadata", metadata);
if (personality.size() > 0)
toString.add("personality", personality);
if (adminPass != null)
toString.add("adminPassPresent", true);
toString.add("userData", userData == null ? null : new String(userData));
return toString;
}
@Override

View File

@ -90,7 +90,7 @@ public class SudoAwareInitManager {
String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action)
: execScriptAsDefaultUser(action);
returnVal = runCommand(command);
if ("status".equals(action))
if (ImmutableSet.of("status", "stdout", "stderr").contains(action))
logger.trace("<< %s(%d)", action, returnVal.getExitStatus());
else if (computeLogger.isTraceEnabled())
computeLogger.trace("<< %s[%s]", action, returnVal);
@ -103,8 +103,8 @@ public class SudoAwareInitManager {
String statement = String.format("[%s] as %s@%s", command.replace(
node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh
.getUsername(), ssh.getHostAddress());
if (command.endsWith("status"))
logger.trace(">> running " + statement);
if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr"))
logger.trace(">> running %s", statement);
else
computeLogger.debug(">> running " + statement);
ExecResponse returnVal = ssh.exec(command);

View File

@ -47,4 +47,11 @@ public interface Template extends Cloneable {
* options for launching this template, like run scripts or inbound ports
*/
TemplateOptions getOptions();
/**
* clone this template
*
* @see Object#clone
*/
Template clone();
}

View File

@ -58,6 +58,8 @@ import org.jclouds.util.Lists2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
@ -726,7 +728,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
String message = format("no hardware profiles match params: %s", hardwarePredicate);
throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwaresThatAreCompatibleWithOurImages);
}
logger.debug("<< matched hardware(%s)", hardware.getId());
logger.trace("<< matched hardware(%s)", hardware.getId());
return hardware;
}
@ -995,11 +997,40 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override
public String toString() {
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription="
+ imageDescription + ", imageId=" + imageId + ", imagePredicate=" + imagePredicate + ", imageVersion=" + imageVersion + ", location=" + location
+ ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName
+ ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit="
+ os64Bit + ", hardwareId=" + hardwareId + ", hypervisor=" + hypervisor + "]";
return string().toString();
}
/**
* @since 1.5
*/
protected ToStringHelper string() {
ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
if (biggest)
toString.add("biggest", biggest);
if (fastest)
toString.add("fastest", fastest);
toString.add("imageName", imageName);
toString.add("imageDescription", imageDescription);
toString.add("imageId", imageId);
toString.add("imagePredicate", imagePredicate);
toString.add("imageVersion", imageVersion);
if (location != null)
toString.add("locationId", location.getId());
if (minCores >0) //TODO: make non-primitive
toString.add("minCores", minCores);
if (minRam >0) //TODO: make non-primitive
toString.add("minRam", minRam);
if (minRam >0) //TODO: make non-primitive
toString.add("minRam", minRam);
toString.add("osFamily", osFamily);
toString.add("osName", osName);
toString.add("osDescription", osDescription);
toString.add("osVersion", osVersion);
toString.add("osArch", osArch);
toString.add("os64Bit", os64Bit);
toString.add("hardwareId", hardwareId);
toString.add("hypervisor", hypervisor);
return toString;
}
@Override

View File

@ -129,8 +129,8 @@ public class TemplateImpl implements Template {
* {@inheritDoc}
*/
@Override
protected Object clone() throws CloneNotSupportedException {
return new TemplateImpl(image, size, location, options);
public Template clone() {
return new TemplateImpl(image, size, location, options.clone());
}
}

View File

@ -338,9 +338,9 @@ public class BaseComputeService implements ComputeService {
*/
@Override
public Set<ComputeMetadata> listNodes() {
logger.debug(">> listing nodes");
logger.trace(">> listing nodes");
Set<ComputeMetadata> set = newLinkedHashSet(listNodesStrategy.listNodes());
logger.debug("<< list(%d)", set.size());
logger.trace("<< list(%d)", set.size());
return set;
}
@ -350,9 +350,9 @@ public class BaseComputeService implements ComputeService {
@Override
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
checkNotNull(filter, "filter");
logger.debug(">> listing node details matching(%s)", filter);
logger.trace(">> listing node details matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
logger.debug("<< list(%d)", set.size());
logger.trace("<< list(%d)", set.size());
return set;
}

View File

@ -455,11 +455,23 @@ public class RunScriptOptions {
}
protected ToStringHelper string() {
return Objects.toStringHelper("").add("loginUser", loginUser)
.add("loginPasswordPresent", (loginPassword != null))
.add("loginPrivateKeyPresent", (loginPrivateKey != null)).add("authenticateSudo", authenticateSudo)
.add("port:seconds", port + ":" + seconds).add("taskName", taskName).add("runAsRoot", runAsRoot)
.add("blockOnComplete", blockOnComplete).add("wrapInInitScript", wrapInInitScript);
ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
toString.add("loginUser", loginUser);
if (loginPassword != null)
toString.add("loginPasswordPresent", true);
if (loginPrivateKey != null)
toString.add("loginPrivateKeyPresent", true);
toString.add("authenticateSudo", authenticateSudo);
if (port != -1 && seconds != -1) // TODO: not primitives
toString.add("blockOnPort:seconds", port + ":" + seconds);
toString.add("taskName", taskName);
if (!runAsRoot)
toString.add("runAsRoot", runAsRoot);
if (!blockOnComplete)
toString.add("blockOnComplete", blockOnComplete);
if (!wrapInInitScript)
toString.add("wrapInInitScript", wrapInInitScript);
return toString;
}
}

View File

@ -317,7 +317,9 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable {
}
protected Set<Integer> inboundPorts = ImmutableSet.of(22);
private final static Set<Integer> DEFAULT_INBOUND_PORTS = ImmutableSet.of(22);
protected Set<Integer> inboundPorts = DEFAULT_INBOUND_PORTS;
protected Statement script;
@ -352,11 +354,24 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable {
@Override
public ToStringHelper string() {
return super.string().add("inboundPorts", inboundPorts).add("scriptPresent", script != null)
.add("publicKeyPresent", publicKey != null).add("privateKeyPresent", privateKey != null).add("tags", tags)
.add("blockUntilRunning", blockUntilRunning).add("tags", tags).add("userMetadata", userMetadata);
ToStringHelper toString = super.string();
if (!DEFAULT_INBOUND_PORTS.equals(inboundPorts))
toString.add("inboundPorts", inboundPorts);
if (script != null)
toString.add("scriptPresent", true);
if (publicKey != null)
toString.add("publicKeyPresent", true);
if (privateKey != null)
toString.add("privateKeyPresent", true);
if (!blockUntilRunning)
toString.add("blockUntilRunning", blockUntilRunning);
if (tags.size() != 0)
toString.add("tags", tags);
if (userMetadata.size() != 0)
toString.add("userMetadata", userMetadata);
return toString;
}
public int[] getInboundPorts() {
return Ints.toArray(inboundPorts);
}

View File

@ -374,7 +374,7 @@ public class TemplateBuilderImplTest {
// make sure big data is not in the exception message
assertEquals(
e.getMessage(),
"no hardware profiles support images matching params: [biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=us-east-1/imageId, imagePredicate=null, imageVersion=null, location=[id=us-east-1, scope=REGION, description=us-east-1, parent=aws-ec2, iso3166Codes=[], metadata={}], minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null, osArch=null, os64Bit=false, hardwareId=null, hypervisor=null]");
"no hardware profiles support images matching params: {imageId=us-east-1/imageId, locationId=us-east-1, os64Bit=false}");
verify(image);
verify(os);
verify(defaultTemplate);
@ -852,6 +852,8 @@ public class TemplateBuilderImplTest {
TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU)
.hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true);
assertEquals(templateBuilder.toString(), "{minRam=512, minRam=512, osFamily=ubuntu, osVersion=1[10].[10][04], os64Bit=true, hypervisor=OpenVZ}");
Template template = templateBuilder.build();
assertEquals(template.getHardware().getHypervisor(), "OpenVZ");
assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit");
@ -902,7 +904,9 @@ public class TemplateBuilderImplTest {
};
TemplateBuilder templateBuilder = templateBuilderProvider.get().hardwareId("m1.small").imageId("us-east-2/ami-ffff");
assertEquals(templateBuilder.toString(), "{imageId=us-east-2/ami-ffff, hardwareId=m1.small}");
Template template = templateBuilder.build();
assertEquals(template.getLocation().getId(), "us-east-2");

View File

@ -45,6 +45,7 @@ public class TemplateOptionsTest {
public void testinstallPrivateKey() throws IOException {
TemplateOptions options = new TemplateOptions();
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
assertEquals(options.toString(), "{privateKeyPresent=true}");
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
}
@ -75,6 +76,7 @@ public class TemplateOptionsTest {
public void testauthorizePublicKey() throws IOException {
TemplateOptions options = new TemplateOptions();
options.authorizePublicKey("ssh-rsa");
assertEquals(options.toString(), "{publicKeyPresent=true}");
assertEquals(options.getPublicKey(), "ssh-rsa");
}
@ -105,6 +107,7 @@ public class TemplateOptionsTest {
public void testblockOnPort() {
TemplateOptions options = new TemplateOptions();
options.blockOnPort(22, 30);
assertEquals(options.toString(), "{blockOnPort:seconds=22:30}");
assertEquals(options.getPort(), 22);
assertEquals(options.getSeconds(), 30);
@ -148,6 +151,7 @@ public class TemplateOptionsTest {
@Test
public void testinboundPortsStatic() {
TemplateOptions options = inboundPorts(22, 30);
assertEquals(options.toString(), "{inboundPorts=[22, 30]}");
assertEquals(options.getInboundPorts()[0], 22);
assertEquals(options.getInboundPorts()[1], 30);
}
@ -155,6 +159,7 @@ public class TemplateOptionsTest {
@Test
public void testblockUntilRunningDefault() {
TemplateOptions options = new TemplateOptions();
assertEquals(options.toString(), "{}");
assertEquals(options.shouldBlockUntilRunning(), true);
}
@ -162,6 +167,7 @@ public class TemplateOptionsTest {
public void testblockUntilRunning() {
TemplateOptions options = new TemplateOptions();
options.blockUntilRunning(false);
assertEquals(options.toString(), "{blockUntilRunning=false}");
assertEquals(options.shouldBlockUntilRunning(), false);
}

View File

@ -47,6 +47,6 @@ public class DeadEventLoggingHandler
*/
@Subscribe
public final void handleDeadEvent(DeadEvent deadEvent) {
logger.warn("detected dead event %s", deadEvent.getEvent());
logger.trace("detected dead event %s", deadEvent.getEvent());
}
}

View File

@ -81,7 +81,10 @@ public class SDCTemplateOptions extends TemplateOptions implements Cloneable {
@Override
public ToStringHelper string() {
return super.string().add("generateKey", generateKey);
ToStringHelper toString = super.string();
if (generateKey)
toString.add("generateKey", generateKey);
return toString;
}
/**

View File

@ -28,14 +28,12 @@ import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
@ -57,7 +55,6 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo
CreateNodesWithGroupEncodedIntoNameThenAddToSet {
private final LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache;
private final Provider<TemplateBuilder> templateBuilderProvider;
@Inject
protected ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(
@ -66,11 +63,9 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo
GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
Provider<TemplateBuilder> templateBuilderProvider,
LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider");
this.keyCache = checkNotNull(keyCache, "keyCache");
}
@ -78,17 +73,7 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate;
// ensure we don't mutate the input template, fromTemplate ignores imageId
// so
// build directly from imageId if we have it
if (template.getImage() != null && template.getImage().getId() != null) {
mutableTemplate = templateBuilderProvider.get().imageId(template.getImage().getId()).fromTemplate(template)
.build();
// otherwise build from generic parameters
} else {
mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build();
}
Template mutableTemplate = template.clone();
SDCTemplateOptions templateOptions = SDCTemplateOptions.class.cast(mutableTemplate.getOptions());

View File

@ -19,7 +19,6 @@
package org.jclouds.joyent.sdc.v6_5.options;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
@ -30,6 +29,7 @@ import org.jclouds.util.Maps2;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
@ -64,7 +64,11 @@ public class CreateMachineOptions extends BaseHttpRequestOptions {
@Override
public String toString() {
return toStringHelper("").add("name", name).add("package", name).add("metadata", metadata).toString();
ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
toString.add("name", name).add("package", name);
if (metadata.size() > 0)
toString.add("metadata", metadata);
return toString.toString();
}
@Override