mirror of https://github.com/apache/jclouds.git
Issue 112: progress on internetservice
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2401 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
16940530f8
commit
f7a814bc04
1
pom.xml
1
pom.xml
|
@ -43,7 +43,6 @@
|
|||
<module>core</module>
|
||||
<module>extensions</module>
|
||||
<module>scriptbuilder</module>
|
||||
<module>atmos</module>
|
||||
<module>aws</module>
|
||||
<module>azure</module>
|
||||
<module>mezeo</module>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -37,10 +38,12 @@ import javax.inject.Inject;
|
|||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
|
||||
|
@ -111,18 +114,51 @@ public class TerremarkVCloudComputeClient {
|
|||
logger.debug("<< on vApp(%s)", vApp.getId());
|
||||
}
|
||||
|
||||
public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) {
|
||||
PublicIpAddress sshIp = null;
|
||||
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
|
||||
for (int port : ports) {
|
||||
InternetService is = null;
|
||||
if (sshIp == null) {
|
||||
logger.debug(">> creating InternetService %d", port);
|
||||
is = tmClient.addInternetService(vApp.getName() + "-" + port, "TCP", port,
|
||||
withDescription(String.format("port %d access to serverId: %s name: %s", port,
|
||||
vApp.getId(), vApp.getName())));
|
||||
sshIp = is.getPublicIpAddress();
|
||||
} else {
|
||||
logger.debug(">> adding InternetService %s:%d", sshIp.getAddress().getHostAddress(),
|
||||
port);
|
||||
is = tmClient.addInternetServiceToExistingIp(sshIp.getId() + "", vApp.getName() + "-"
|
||||
+ port, "TCP", port,
|
||||
withDescription(String.format("port %d access to serverId: %s name: %s", port,
|
||||
vApp.getId(), vApp.getName())));
|
||||
}
|
||||
logger.debug("<< created InternetService(%s) %s:%d", is.getId(), is.getPublicIpAddress()
|
||||
.getAddress().getHostAddress(), is.getPort());
|
||||
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress()
|
||||
.getHostAddress(), is.getPort(), privateAddress.getHostAddress(), port);
|
||||
Node node = tmClient
|
||||
.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
|
||||
logger.debug("<< added Node(%s)", node.getId());
|
||||
}
|
||||
return sshIp.getAddress();
|
||||
}
|
||||
|
||||
public void stop(String id) {
|
||||
TerremarkVApp vApp = tmClient.getVApp(id);
|
||||
|
||||
SERVICE: for (InternetService service : tmClient.getAllInternetServices()) {
|
||||
for (Node node : tmClient.getNodes(service.getId())) {
|
||||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
logger.debug(">> deleting Node(%s)", node.getId());
|
||||
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getId(), service
|
||||
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort(),
|
||||
node.getIpAddress().getHostAddress(), node.getPort());
|
||||
tmClient.deleteNode(node.getId());
|
||||
logger.debug("<< deleted Node(%s)", node.getId());
|
||||
SortedSet<Node> nodes = tmClient.getNodes(service.getId());
|
||||
if (nodes.size() == 0) {
|
||||
logger.debug(">> deleting InternetService(%s)", service.getId());
|
||||
logger.debug(">> deleting InternetService(%s) %s:%d", service.getId(), service
|
||||
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort());
|
||||
tmClient.deleteInternetService(service.getId());
|
||||
logger.debug("<< deleted InternetService(%s)", service.getId());
|
||||
continue SERVICE;
|
||||
|
|
|
@ -72,19 +72,10 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
String id = computeClient.start(name, 1, 512, image);
|
||||
VApp vApp = tmClient.getVApp(id);
|
||||
Iterable<InetAddress> privateAddresses = vApp.getNetworkToAddresses().values();
|
||||
|
||||
InetAddress sshIp = null;
|
||||
InternetService is;
|
||||
for (int port : new int[] { 22, 80, 8080 }) {
|
||||
is = tmClient.addInternetService(id + "-" + port, "TCP", port);
|
||||
tmClient.addNode(is.getId(), Iterables.getLast(privateAddresses), id + "-" + port, port);
|
||||
if (port == 22) {
|
||||
is.getPublicIpAddress().getAddress();
|
||||
}
|
||||
}
|
||||
return new CreateServerResponseImpl(id, vApp.getName(), ImmutableSet.<InetAddress> of(sshIp),
|
||||
privateAddresses, 22, LoginType.SSH, new Credentials("vcloud", "p4ssw0rd"));
|
||||
InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22, 80, 8080);
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), ImmutableSet
|
||||
.<InetAddress> of(publicIp), vApp.getNetworkToAddresses().values(), 22, LoginType.SSH,
|
||||
new Credentials("vcloud", "p4ssw0rd"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package org.jclouds.vcloud.terremark.compute;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "compute.PropertiesTest")
|
||||
public class PropertiesTest {
|
||||
private Properties properties;
|
||||
|
||||
@BeforeTest
|
||||
public void setUp() throws IOException {
|
||||
properties = new Properties();
|
||||
properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties"))
|
||||
.getInput());
|
||||
}
|
||||
|
||||
public void testRimu() {
|
||||
assertEquals(properties.getProperty("terremark.contextbuilder"),
|
||||
TerremarkVCloudContextBuilder.class.getName());
|
||||
assertEquals(properties.getProperty("terremark.propertiesbuilder"),
|
||||
TerremarkVCloudPropertiesBuilder.class.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.vcloud.terremark.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.internal.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkVCloudClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest")
|
||||
public class TerremarkVCloudComputeClientLiveTest {
|
||||
TerremarkVCloudComputeClient client;
|
||||
TerremarkVCloudClient tmClient;
|
||||
|
||||
private String id;
|
||||
private InetAddress privateAddress;
|
||||
|
||||
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
|
||||
|
||||
private static class Expectation {
|
||||
final long hardDisk;
|
||||
final String os;
|
||||
|
||||
public Expectation(long hardDisk, String os) {
|
||||
this.hardDisk = hardDisk;
|
||||
this.os = os;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
|
||||
.put(Image.CENTOS_53,
|
||||
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
|
||||
Image.RHEL_53,
|
||||
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
|
||||
Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
|
||||
Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
|
||||
|
||||
private Predicate<InetAddress> addressTester;
|
||||
|
||||
@Test
|
||||
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
IOException {
|
||||
Image toTest = Image.CENTOS_53;
|
||||
|
||||
String serverName = getCompatibleServerName(toTest);
|
||||
int processorCount = 1;
|
||||
int memory = 512;
|
||||
|
||||
id = client.start(serverName, processorCount, memory, toTest);
|
||||
Expectation expectation = expectationMap.get(toTest);
|
||||
|
||||
TerremarkVApp vApp = tmClient.getVApp(id);
|
||||
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
|
||||
expectation.hardDisk);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
}
|
||||
|
||||
private String getCompatibleServerName(Image toTest) {
|
||||
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
|
||||
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
|
||||
return serverName;
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testPowerOn")
|
||||
public void testGetAnyPrivateAddress() {
|
||||
privateAddress = client.getAnyPrivateAddress(id);
|
||||
assert !addressTester.apply(privateAddress);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetAnyPrivateAddress")
|
||||
public void testSshLoadBalanceIp() {
|
||||
|
||||
InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22, 80);
|
||||
assert addressTester.apply(publicIp);
|
||||
// client.exec(publicIp, "uname -a");
|
||||
}
|
||||
|
||||
private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
|
||||
int processorCount, int memory, long hardDisk) {
|
||||
assertEquals(vApp.getName(), serverName);
|
||||
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
|
||||
.getVirtualQuantity(), processorCount);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
|
||||
.getVirtualQuantity(), 1);
|
||||
assertEquals(
|
||||
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
|
||||
memory);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
|
||||
.getVirtualQuantity(), hardDisk);
|
||||
assertEquals(vApp.getSize().longValue(), vApp.getResourceAllocationByType().get(
|
||||
ResourceType.DISK_DRIVE).getVirtualQuantity());
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (id != null)
|
||||
client.stop(id);
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||
Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(
|
||||
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
|
||||
new JschSshClientModule()).buildInjector();
|
||||
client = injector.getInstance(TerremarkVCloudComputeClient.class);
|
||||
tmClient = injector.getInstance(TerremarkVCloudClient.class);
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue