mirror of https://github.com/apache/jclouds.git
made jetty serve preseed.cfg from inside the jar (was serving from src/test/resources)
This commit is contained in:
parent
04f72a67d7
commit
c9c4a1aef0
|
@ -78,7 +78,7 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
||||||
|
|
||||||
properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor);
|
properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor);
|
||||||
|
|
||||||
properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/src/test/resources/preseed.cfg");
|
properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg");
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
NodeSpec nodeSpec = NodeSpec.builder().master(master).name(name).tag(tag).template(template).build();
|
NodeSpec nodeSpec = NodeSpec.builder().master(master).name(name).tag(tag).template(template).build();
|
||||||
return cloneCreator.apply(nodeSpec);
|
return cloneCreator.apply(nodeSpec);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,35 +19,42 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import static com.google.common.base.Throwables.propagate;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerList;
|
import org.eclipse.jetty.server.handler.HandlerList;
|
||||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||||
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli
|
* Sets up jetty so that it can serve the preseed.cfg file to automate master creation.
|
||||||
|
*
|
||||||
|
* TODO - Probably we can make this only start jetty. This has not been used to serve isos.
|
||||||
|
*
|
||||||
|
* @author Andrea Turli, David Alves
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StartJettyIfNotAlreadyRunning extends CacheLoader<IsoSpec, URI> {
|
public class StartJettyIfNotAlreadyRunning extends CacheLoader<IsoSpec, URI> {
|
||||||
|
|
||||||
@Resource
|
@javax.annotation.Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private Server jetty;
|
private Server jetty;
|
||||||
|
@ -74,24 +81,31 @@ public class StartJettyIfNotAlreadyRunning extends CacheLoader<IsoSpec, URI> {
|
||||||
if (jetty.getState().equals(Server.STARTED)) {
|
if (jetty.getState().equals(Server.STARTED)) {
|
||||||
logger.debug("not starting jetty, as existing host is serving %s", preconfigurationUrl);
|
logger.debug("not starting jetty, as existing host is serving %s", preconfigurationUrl);
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
logger.debug(">> starting jetty to serve %s", preconfigurationUrl);
|
logger.debug(">> starting jetty to serve %s", preconfigurationUrl);
|
||||||
ResourceHandler resourceHandler = new ResourceHandler();
|
|
||||||
resourceHandler.setDirectoriesListed(true);
|
|
||||||
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
|
|
||||||
|
|
||||||
resourceHandler.setResourceBase("");
|
Resource resource = Resource.newClassPathResource("preseed.cfg");
|
||||||
|
checkState(resource.getInputStream() != null, "cannot find preseed.cfg");
|
||||||
|
|
||||||
|
ContextHandler capHandler = new ContextHandler();
|
||||||
|
capHandler.setContextPath("/preseed.cfg");
|
||||||
|
|
||||||
|
ResourceHandler resourceHandler = new ResourceHandler();
|
||||||
|
resourceHandler.setBaseResource(resource);
|
||||||
|
capHandler.setHandler(resourceHandler);
|
||||||
|
|
||||||
HandlerList handlers = new HandlerList();
|
HandlerList handlers = new HandlerList();
|
||||||
handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
|
handlers.setHandlers(new Handler[] { capHandler, new DefaultHandler() });
|
||||||
jetty.setHandler(handlers);
|
jetty.setHandler(handlers);
|
||||||
|
|
||||||
try {
|
|
||||||
jetty.start();
|
jetty.start();
|
||||||
|
|
||||||
|
logger.debug("<< serving %s", resourceHandler.getBaseResource());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "Server jetty could not be started for %s", preconfigurationUrl);
|
logger.error(e, "Server jetty could not be started for %s", preconfigurationUrl);
|
||||||
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
logger.debug("<< serving %s", resourceHandler.getBaseResource());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy()
|
@PreDestroy()
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes /etc/gshadow.lock https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/732864.
|
* Deletes /etc/gshadow.lock. see https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/732864.
|
||||||
*
|
*
|
||||||
* @author dralves
|
* @author dralves
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* 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.virtualbox;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
|
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that jetty is able to serve the preseed.cfg file. This test is here to have access to the
|
||||||
|
* defaultProperties() method in {@link VirtualBoxPropertiesBuilder}.
|
||||||
|
*
|
||||||
|
* @author dralves
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
|
||||||
|
public class StartJettyIfNotAlreadyRunningLiveTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJettyServerServesPreseedFile() throws Exception {
|
||||||
|
Properties props = new VirtualBoxPropertiesBuilder().defaultProperties();
|
||||||
|
|
||||||
|
String preconfigurationUrl = props.getProperty(VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL);
|
||||||
|
|
||||||
|
int port = URI.create(preconfigurationUrl).getPort();
|
||||||
|
|
||||||
|
Server server = new Server(port);
|
||||||
|
|
||||||
|
StartJettyIfNotAlreadyRunning starter = new StartJettyIfNotAlreadyRunning(preconfigurationUrl, server);
|
||||||
|
|
||||||
|
starter.load(null);
|
||||||
|
|
||||||
|
// if this opens up a file we're golden
|
||||||
|
IOUtils.toString(new URL("http://127.0.0.1:" + port + "/preseed.cfg").openStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue