Issue 210: updated aws demo with timeouts

This commit is contained in:
Adrian Cole 2010-06-15 00:26:59 -04:00
parent aabaae2a51
commit 117bd1ba6b
2 changed files with 25 additions and 8 deletions

View File

@ -18,6 +18,11 @@
*/ */
package org.jclouds.samples.googleappengine.config; package org.jclouds.samples.googleappengine.config;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_RUNNING;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_TERMINATED;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_PORT_OPEN;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_SCRIPT_COMPLETE;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map; import java.util.Map;
@ -56,6 +61,11 @@ public class GuiceServletConfig extends GuiceServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent servletContextEvent) { public void contextInitialized(ServletContextEvent servletContextEvent) {
Properties props = loadJCloudsProperties(servletContextEvent); Properties props = loadJCloudsProperties(servletContextEvent);
props.setProperty(PROPERTY_TIMEOUT_NODE_TERMINATED, "25000");
props.setProperty(PROPERTY_TIMEOUT_NODE_RUNNING, "25000");
props.setProperty(PROPERTY_TIMEOUT_SCRIPT_COMPLETE, "25000");
props.setProperty(PROPERTY_TIMEOUT_PORT_OPEN, "25000");
ImmutableSet<Module> modules = ImmutableSet ImmutableSet<Module> modules = ImmutableSet
.<Module> of(new GoogleAppEngineConfigurationModule()); .<Module> of(new GoogleAppEngineConfigurationModule());
try { try {

View File

@ -19,22 +19,21 @@
package org.jclouds.samples.googleappengine.functions; package org.jclouds.samples.googleappengine.functions;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.samples.googleappengine.domain.StatusResult; import org.jclouds.samples.googleappengine.domain.StatusResult;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@Singleton @Singleton
public class ComputeServiceContextToStatusResult implements Function<String, StatusResult> { public class ComputeServiceContextToStatusResult implements
Function<String, StatusResult> {
@Inject @Inject
private Map<String, ComputeServiceContext> contexts; private Map<String, ComputeServiceContext> contexts;
@ -44,14 +43,22 @@ public class ComputeServiceContextToStatusResult implements Function<String, Sta
public StatusResult apply(final String contextName) { public StatusResult apply(final String contextName) {
final ComputeServiceContext context = contexts.get(contextName); final ComputeServiceContext context = contexts.get(contextName);
final String host = context.getProviderSpecificContext().getEndPoint().getHost(); final String host = context.getProviderSpecificContext().getEndPoint()
.getHost();
String status; String status;
String name = "not found"; String name = "not found";
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Set<? extends ComputeMetadata> nodes = context.getComputeService().listNodes(); // set options that don't block so that we can avoid
if (nodes.size() > 0) // DeadLineExceededExceptions
name = Iterables.get(nodes, 0).getProviderId(); TemplateOptions options = context.getComputeService()
.templateOptions().blockUntilRunning(false);
// set the name to the default template to show that
// it works
name = context.getComputeService().templateBuilder().options(options)
.build().toString();
status = ((System.currentTimeMillis() - start) + "ms"); status = ((System.currentTimeMillis() - start) + "ms");
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Error listing service %s", contextName); logger.error(e, "Error listing service %s", contextName);