POM cleanup and line endings.

This commit is contained in:
Andrew Phillips 2010-03-30 10:19:50 +02:00
parent bb4aa551a7
commit c4bf0f21ad
2 changed files with 214 additions and 214 deletions

View File

@ -28,13 +28,13 @@
==================================================================== ====================================================================
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId> <artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath> <relativePath>../project/pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId> <groupId>${groupId}</groupId>
<artifactId>jclouds-${artifactId}</artifactId> <artifactId>jclouds-${artifactId}</artifactId>
<name>jclouds ${clientName} core</name> <name>jclouds ${clientName} core</name>

View File

@ -1,214 +1,214 @@
/** /**
* *
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com> * Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* *
* ==================================================================== * ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.terremark.compute; package org.jclouds.vcloud.terremark.compute;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient { public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
private final TerremarkVCloudClient client; private final TerremarkVCloudClient client;
@Inject @Inject
protected TerremarkVCloudComputeClient(TerremarkVCloudClient client, protected TerremarkVCloudComputeClient(TerremarkVCloudClient client,
Predicate<String> successTester, @Named("NOT_FOUND") Predicate<VApp> notFoundTester, Predicate<String> successTester, @Named("NOT_FOUND") Predicate<VApp> notFoundTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) { Map<VAppStatus, NodeState> vAppStatusToNodeState) {
super(client, successTester, notFoundTester, vAppStatusToNodeState); super(client, successTester, notFoundTester, vAppStatusToNodeState);
this.client = client; this.client = client;
} }
@Override @Override
protected Map<String, String> parseResponse(VApp vAppResponse) { protected Map<String, String> parseResponse(VApp vAppResponse) {
return ImmutableMap.<String, String> of("id", vAppResponse.getId(), "username", "vcloud", return ImmutableMap.<String, String> of("id", vAppResponse.getId(), "username", "vcloud",
"password", "p4ssw0rd"); "password", "p4ssw0rd");
} }
@Override @Override
public Map<String, String> start(String vDCId, String name, String templateId, int minCores, public Map<String, String> start(String vDCId, String name, String templateId, int minCores,
int minMegs, Long diskSize, Map<String, String> properties, int... portsToOpen) { int minMegs, Long diskSize, Map<String, String> properties, int... portsToOpen) {
Map<String, String> response = super.start(vDCId, name, templateId, minCores, minMegs, null, Map<String, String> response = super.start(vDCId, name, templateId, minCores, minMegs, null,
properties, portsToOpen);// trmk does not support resizing the primary disk properties, portsToOpen);// trmk does not support resizing the primary disk
if (portsToOpen.length > 0) if (portsToOpen.length > 0)
createPublicAddressMappedToPorts(response.get("id"), portsToOpen); createPublicAddressMappedToPorts(response.get("id"), portsToOpen);
return response; return response;
} }
public InetAddress createPublicAddressMappedToPorts(String vAppId, int... ports) { public InetAddress createPublicAddressMappedToPorts(String vAppId, int... ports) {
VApp vApp = client.getVApp(vAppId); VApp vApp = client.getVApp(vAppId);
PublicIpAddress ip = null; PublicIpAddress ip = null;
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values()); InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
for (int port : ports) { for (int port : ports) {
InternetService is = null; InternetService is = null;
Protocol protocol; Protocol protocol;
switch (port) { switch (port) {
case 22: case 22:
protocol = Protocol.TCP; protocol = Protocol.TCP;
break; break;
case 80: case 80:
case 8080: case 8080:
protocol = Protocol.HTTP; protocol = Protocol.HTTP;
break; break;
case 443: case 443:
protocol = Protocol.HTTPS; protocol = Protocol.HTTPS;
break; break;
default: default:
protocol = Protocol.HTTP; protocol = Protocol.HTTP;
break; break;
} }
if (ip == null) { if (ip == null) {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getId(), logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getId(),
protocol, port); protocol, port);
is = client.addInternetServiceToVDC(vApp.getVDC().getId(), vApp.getName() + "-" + port, is = client.addInternetServiceToVDC(vApp.getVDC().getId(), vApp.getName() + "-" + port,
protocol, port, withDescription(String.format( protocol, port, withDescription(String.format(
"port %d access to serverId: %s name: %s", port, vApp.getId(), vApp "port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
.getName()))); .getName())));
ip = is.getPublicIpAddress(); ip = is.getPublicIpAddress();
} else { } else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress().getHostAddress(), logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress().getHostAddress(),
protocol, port); protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port,
protocol, port, withDescription(String.format( protocol, port, withDescription(String.format(
"port %d access to serverId: %s name: %s", port, vApp.getId(), vApp "port %d access to serverId: %s name: %s", port, vApp.getId(), vApp
.getName()))); .getName())));
} }
logger.debug("<< created InternetService(%s) %s:%s:%d", is.getId(), is logger.debug("<< created InternetService(%s) %s:%s:%d", is.getId(), is
.getPublicIpAddress().getAddress().getHostAddress(), is.getProtocol(), is .getPublicIpAddress().getAddress().getHostAddress(), is.getProtocol(), is
.getPort()); .getPort());
logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress() logger.debug(">> adding Node %s:%d -> %s:%d", is.getPublicIpAddress().getAddress()
.getHostAddress(), is.getPort(), privateAddress.getHostAddress(), port); .getHostAddress(), is.getPort(), privateAddress.getHostAddress(), port);
Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port); Node node = client.addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port);
logger.debug("<< added Node(%s)", node.getId()); logger.debug("<< added Node(%s)", node.getId());
} }
return ip != null ? ip.getAddress() : null; return ip != null ? ip.getAddress() : null;
} }
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) { private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
Set<PublicIpAddress> ipAddresses = Sets.newHashSet(); Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC() SERVICE: for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC()
.getId())) { .getId())) {
for (Node node : client.getNodes(service.getId())) { for (Node node : client.getNodes(service.getId())) {
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) { if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
ipAddresses.add(service.getPublicIpAddress()); ipAddresses.add(service.getPublicIpAddress());
logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getId(), service logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getId(), service
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort(), .getPublicIpAddress().getAddress().getHostAddress(), service.getPort(),
node.getIpAddress().getHostAddress(), node.getPort()); node.getIpAddress().getHostAddress(), node.getPort());
client.deleteNode(node.getId()); client.deleteNode(node.getId());
logger.debug("<< deleted Node(%s)", node.getId()); logger.debug("<< deleted Node(%s)", node.getId());
SortedSet<Node> nodes = client.getNodes(service.getId()); SortedSet<Node> nodes = client.getNodes(service.getId());
if (nodes.size() == 0) { if (nodes.size() == 0) {
logger.debug(">> deleting InternetService(%s) %s:%d", service.getId(), service logger.debug(">> deleting InternetService(%s) %s:%d", service.getId(), service
.getPublicIpAddress().getAddress().getHostAddress(), service.getPort()); .getPublicIpAddress().getAddress().getHostAddress(), service.getPort());
client.deleteInternetService(service.getId()); client.deleteInternetService(service.getId());
logger.debug("<< deleted InternetService(%s)", service.getId()); logger.debug("<< deleted InternetService(%s)", service.getId());
continue SERVICE; continue SERVICE;
} }
} }
} }
} }
return ipAddresses; return ipAddresses;
} }
private void deletePublicIpAddressesWithNoServicesAttached(Set<PublicIpAddress> ipAddresses) { private void deletePublicIpAddressesWithNoServicesAttached(Set<PublicIpAddress> ipAddresses) {
IPADDRESS: for (PublicIpAddress address : ipAddresses) { IPADDRESS: for (PublicIpAddress address : ipAddresses) {
SortedSet<InternetService> services = client SortedSet<InternetService> services = client
.getInternetServicesOnPublicIp(address.getId()); .getInternetServicesOnPublicIp(address.getId());
if (services.size() == 0) { if (services.size() == 0) {
logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address
.getAddress().getHostAddress()); .getAddress().getHostAddress());
client.deletePublicIp(address.getId()); client.deletePublicIp(address.getId());
logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); logger.debug("<< deleted PublicIpAddress(%s)", address.getId());
continue IPADDRESS; continue IPADDRESS;
} }
} }
} }
/** /**
* deletes the internet service and nodes associated with the vapp. Deletes the IP address, if * deletes the internet service and nodes associated with the vapp. Deletes the IP address, if
* there are no others using it. Finally, it powers off and deletes the vapp. Note that we do not * there are no others using it. Finally, it powers off and deletes the vapp. Note that we do not
* call undeploy, as terremark does not support the command. * call undeploy, as terremark does not support the command.
*/ */
@Override @Override
public void stop(String id) { public void stop(String id) {
VApp vApp = client.getVApp(id); VApp vApp = client.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp); Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
deletePublicIpAddressesWithNoServicesAttached(ipAddresses); deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
if (vApp.getStatus() != VAppStatus.OFF) { if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp
.getStatus()); .getStatus());
Task task = client.powerOffVApp(vApp.getId()); Task task = client.powerOffVApp(vApp.getId());
if (!taskTester.apply(task.getId())) { if (!taskTester.apply(task.getId())) {
throw new TaskException("powerOff", vApp, task); throw new TaskException("powerOff", vApp, task);
} }
vApp = client.getVApp(id); vApp = client.getVApp(id);
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getId()); logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getId());
} }
logger.debug(">> deleting vApp(%s)", vApp.getId()); logger.debug(">> deleting vApp(%s)", vApp.getId());
client.deleteVApp(id); client.deleteVApp(id);
boolean successful = notFoundTester.apply(vApp); boolean successful = notFoundTester.apply(vApp);
logger.debug("<< deleted vApp(%s) completed(%s)", vApp.getId(), successful); logger.debug("<< deleted vApp(%s) completed(%s)", vApp.getId(), successful);
} }
@Override @Override
public Set<InetAddress> getPrivateAddresses(String id) { public Set<InetAddress> getPrivateAddresses(String id) {
VApp vApp = client.getVApp(id); VApp vApp = client.getVApp(id);
return Sets.newHashSet(vApp.getNetworkToAddresses().values()); return Sets.newHashSet(vApp.getNetworkToAddresses().values());
} }
@Override @Override
public Set<InetAddress> getPublicAddresses(String id) { public Set<InetAddress> getPublicAddresses(String id) {
VApp vApp = client.getVApp(id); VApp vApp = client.getVApp(id);
Set<InetAddress> ipAddresses = Sets.newHashSet(); Set<InetAddress> ipAddresses = Sets.newHashSet();
for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getId())) { for (InternetService service : client.getAllInternetServicesInVDC(vApp.getVDC().getId())) {
for (Node node : client.getNodes(service.getId())) { for (Node node : client.getNodes(service.getId())) {
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) { if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
ipAddresses.add(service.getPublicIpAddress().getAddress()); ipAddresses.add(service.getPublicIpAddress().getAddress());
} }
} }
} }
return ipAddresses; return ipAddresses;
} }
} }