mirror of https://github.com/apache/jclouds.git
Issue 130, 129, 112: added ability for terremark to remove its dependencies. added profile and image objects. refactored ant to include logger
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2396 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
0f835d1fdb
commit
2fddd3223e
|
@ -35,7 +35,11 @@ import org.jclouds.compute.domain.CreateServerResponse;
|
|||
public interface ComputeService {
|
||||
SortedSet<Server> listServers();
|
||||
|
||||
CreateServerResponse createServer(String name, String profile, String image);
|
||||
/**
|
||||
*
|
||||
* @see Image
|
||||
*/
|
||||
CreateServerResponse createServer(String name, Profile profile, Image image);
|
||||
|
||||
Server getServerById(String id);
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* 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.compute;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum Image {
|
||||
CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* 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.compute;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum Profile {
|
||||
SMALLEST
|
||||
}
|
|
@ -165,6 +165,9 @@ public class HttpUtils {
|
|||
if (uriPath.indexOf('@') != 1) {
|
||||
List<String> parts = Lists.newArrayList(Splitter.on('@').split(uriPath));
|
||||
String path = parts.remove(parts.size() - 1);
|
||||
if (parts.size() == 2) {
|
||||
parts = Lists.newArrayList(urlEncode(parts.get(0) + "@" + parts.get(1), '/', ':'));
|
||||
}
|
||||
parts.add(urlEncode(path, '/', ':'));
|
||||
uriPath = Joiner.on('@').join(parts);
|
||||
} else {
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder
|
||||
rimuhosting.propertiesbuilder=org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder
|
||||
terremark.contextbuilder=org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder
|
||||
terremark.propertiesbuilder=org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder
|
|
@ -67,6 +67,12 @@ public class HttpUtilsTest extends PerformanceTest {
|
|||
.create("blobstore://account:Base64==@azureblob/container-hyphen/prefix"));
|
||||
}
|
||||
|
||||
public void testTerremark() {
|
||||
URI creds = HttpUtils.createUri("compute://user@domain:password@terremark");
|
||||
assertEquals(creds.getUserInfo(), "user@domain:password");
|
||||
assertEquals(creds, URI.create("compute://user%40domain:password@terremark"));
|
||||
}
|
||||
|
||||
public void testCloudFiles() {
|
||||
URI creds = HttpUtils.createUri("blobstore://account:h3c@cloudfiles/container-hyphen/prefix");
|
||||
assertEquals(creds, URI.create("blobstore://account:h3c@cloudfiles/container-hyphen/prefix"));
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*/
|
||||
package org.jclouds.rimuhosting.miro.servers;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
@ -30,11 +33,15 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.compute.Profile;
|
||||
import org.jclouds.compute.domain.CreateServerResponse;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
|
||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author Ivan Meredith
|
||||
*/
|
||||
|
@ -47,9 +54,16 @@ public class RimuHostingComputeService implements ComputeService {
|
|||
this.rhClient = rhClient;
|
||||
}
|
||||
|
||||
private Map<Image, String> imageNameMap = ImmutableMap.<Image, String> builder().put(
|
||||
Image.CENTOS_53, "centos53").put(Image.UMBUNTU_90, "ubuntu904").build();
|
||||
private Map<Profile, String> profileNameMap = ImmutableMap.<Profile, String> builder().put(
|
||||
Profile.SMALLEST, "MIRO1B").build();
|
||||
|
||||
@Override
|
||||
public CreateServerResponse createServer(String name, String profile, String image) {
|
||||
NewServerResponse serverResponse = rhClient.createInstance(name, image, profile);
|
||||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
NewServerResponse serverResponse = rhClient.createInstance(name, checkNotNull(imageNameMap
|
||||
.get(image), "image not supported: " + image), checkNotNull(profileNameMap
|
||||
.get(profile), "profile not supported: " + profile));
|
||||
return new RimuHostingCreateServerResponse(serverResponse);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ package org.jclouds.rimuhosting.miro.servers;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.compute.Profile;
|
||||
import org.jclouds.compute.domain.CreateServerResponse;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||
|
@ -58,7 +60,8 @@ public class RimuHostingComputeServiceLiveTest {
|
|||
|
||||
@Test
|
||||
public void testServerCreate() {
|
||||
CreateServerResponse server = rhServerService.createServer("test.com", "MIRO1B", "lenny");
|
||||
CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST,
|
||||
Image.CENTOS_53);
|
||||
assertNotNull(rhClient.getInstance(Long.valueOf(server.getId())));
|
||||
rhServerService.getServerById(server.getId()).destroy();
|
||||
}
|
||||
|
|
|
@ -23,17 +23,37 @@
|
|||
====================================================================
|
||||
|
||||
-->
|
||||
<project name="ex6" default="demo" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
|
||||
<artifact:localRepository id="jclouds.repository" path="${user.home}/.m2/repository" />
|
||||
<project name="ex6" default="list" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
|
||||
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository" />
|
||||
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots" />
|
||||
|
||||
<artifact:dependencies pathId="jclouds.classpath">
|
||||
<dependency groupId="org.jclouds" artifactId="jclouds-ant-plugin" version="1.0-SNAPSHOT" />
|
||||
<localRepository refid="jclouds.repository" />
|
||||
<dependency groupId="org.jclouds" artifactId="jclouds-terremark" version="1.0-SNAPSHOT" />
|
||||
<dependency groupId="org.jclouds" artifactId="jclouds-rimuhosting" version="1.0-SNAPSHOT" />
|
||||
<localRepository refid="local.repository" />
|
||||
<remoteRepository refid="jclouds-snapshot.repository" />
|
||||
</artifact:dependencies>
|
||||
|
||||
|
||||
<typedef name="compute" classname="org.jclouds.tools.ant.ComputeTask" classpathref="jclouds.classpath" />
|
||||
|
||||
<target name="demo">
|
||||
<compute action="create" provider="compute://accountkey:accountkey@rimuhosting" />
|
||||
<property name="jclouds.compute.provider" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
|
||||
<property name="jclouds.compute.servername" value="testforjcloud2" />
|
||||
|
||||
<target name="list">
|
||||
<compute action="list" provider="${jclouds.compute.provider}" />
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<compute action="destroy" provider="${jclouds.compute.provider}" >
|
||||
<server name="${jclouds.compute.servername}"/>
|
||||
</compute>
|
||||
</target>
|
||||
|
||||
<target name="create">
|
||||
<compute action="create" provider="${jclouds.compute.provider}" >
|
||||
<server name="${jclouds.compute.servername}" image="CENTOS_53" profile="SMALLEST" />
|
||||
</compute>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,28 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
$HeadURL$
|
||||
$Revision$
|
||||
$Date$
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
$HeadURL$ $Revision$ $Date$ Copyright (C) 2009 Adrian Cole
|
||||
<adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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
|
||||
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.html
|
||||
|
||||
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.
|
||||
http://www.apache.org/licenses/LICENSE-2.0.html 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.
|
||||
====================================================================
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
|
@ -45,7 +40,12 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-rimuhosting</artifactId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-jsch</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -27,22 +27,44 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceFactory;
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.compute.Profile;
|
||||
import org.jclouds.compute.Server;
|
||||
import org.jclouds.compute.domain.CreateServerResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Ivan Meredith
|
||||
*/
|
||||
public class ComputeTask extends Task {
|
||||
private final Map<URI, ComputeService> computeMap;
|
||||
private static Project project;
|
||||
/**
|
||||
* we don't have a reference to the project during the constructor, so we need to defer expansion
|
||||
* with a Provider.
|
||||
*/
|
||||
private static Provider<Module[]> defaultModulesProvider = new Provider<Module[]>() {
|
||||
|
||||
@Override
|
||||
public Module[] get() {
|
||||
return new Module[] { new AntLoggingModule(project) };
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public ComputeTask() throws IOException {
|
||||
this(buildComputeMap(loadDefaultProperties()));
|
||||
|
@ -60,7 +82,7 @@ public class ComputeTask extends Task {
|
|||
|
||||
@Override
|
||||
public ComputeService apply(URI from) {
|
||||
return new ComputeServiceFactory(props).create(from);
|
||||
return new ComputeServiceFactory(props).create(from, defaultModulesProvider.get());
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -71,17 +93,84 @@ public class ComputeTask extends Task {
|
|||
this.computeMap = computeMap;
|
||||
}
|
||||
|
||||
private final String ACTION_CREATE = "create";
|
||||
public static enum Action {
|
||||
CREATE, LIST, DESTROY
|
||||
}
|
||||
|
||||
private String provider;
|
||||
private String action;
|
||||
private ServerElement serverElement;
|
||||
|
||||
/**
|
||||
* @return the configured {@link ServerElement} element
|
||||
*/
|
||||
public final ServerElement createServer() {
|
||||
if (getServer() == null) {
|
||||
this.serverElement = new ServerElement();
|
||||
}
|
||||
|
||||
return this.serverElement;
|
||||
}
|
||||
|
||||
public ServerElement getServer() {
|
||||
return this.serverElement;
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
if (ACTION_CREATE.equalsIgnoreCase(action)) {
|
||||
ComputeTask.project = getProject();
|
||||
Action action = Action.valueOf(this.action.toUpperCase());
|
||||
ComputeService computeService = computeMap.get(HttpUtils.createUri(provider));
|
||||
log("hello");
|
||||
computeService.createServer("test.com", "MIRO1B", "lenny");
|
||||
switch (action) {
|
||||
case CREATE:
|
||||
case DESTROY:
|
||||
if (serverElement != null) {
|
||||
switch (action) {
|
||||
case CREATE:
|
||||
create(computeService);
|
||||
break;
|
||||
case DESTROY:
|
||||
destroy(computeService);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this.log("missing server element for action: " + action, Project.MSG_ERR);
|
||||
}
|
||||
break;
|
||||
case LIST:
|
||||
log("list");
|
||||
for (Server server : computeService.listServers()) {
|
||||
log(String.format(" id=%s, name=%s", server.getId(), server.getName()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.log("bad action: " + action, Project.MSG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
private void create(ComputeService computeService) {
|
||||
log(String.format("create name: %s, profile: %s, image: %s", serverElement.getName(),
|
||||
serverElement.getProfile(), serverElement.getImage()));
|
||||
CreateServerResponse createdServer = computeService.createServer(serverElement.getName(),
|
||||
Profile.valueOf(serverElement.getProfile().toUpperCase()), Image
|
||||
.valueOf(serverElement.getImage().toUpperCase()));
|
||||
log(String.format(" id=%s, name=%s, connection=%s://%s:%s@%s:%d", createdServer.getId(),
|
||||
createdServer.getName(), createdServer.getLoginType().toString().toLowerCase(),
|
||||
createdServer.getCredentials().account, createdServer.getCredentials().key,
|
||||
createdServer.getPublicAddresses().first().getHostAddress(), createdServer
|
||||
.getLoginPort()));
|
||||
}
|
||||
|
||||
private void destroy(ComputeService computeService) {
|
||||
log(String.format("destroy name: %s", serverElement.getName()));
|
||||
SortedSet<Server> serversThatMatch = computeService.getServerByName(serverElement.getName());
|
||||
if (serversThatMatch.size() > 0) {
|
||||
for (Server server : serversThatMatch) {
|
||||
log(String.format(" destroying id=%s, name=%s", server.getId(), server.getName()));
|
||||
if (!server.destroy()) {
|
||||
log(String.format(" could not destroy id=%s, name=%s", server.getId(), server
|
||||
.getName()), Project.MSG_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package org.jclouds.tools.ant.logging;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.jclouds.logging.BaseLogger;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
* {@link org.apache.tools.ant.Project} implementation of {@link Logger}.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class AntLogger extends BaseLogger {
|
||||
private final Project project;
|
||||
private final String category;
|
||||
|
||||
public static class AntLoggerFactory implements LoggerFactory {
|
||||
private final Project project;
|
||||
|
||||
public AntLoggerFactory(Project project) {
|
||||
this.project = checkNotNull(project, "project");
|
||||
}
|
||||
|
||||
public Logger getLogger(String category) {
|
||||
return new AntLogger(project, category);
|
||||
}
|
||||
}
|
||||
|
||||
public AntLogger(Project project, String category) {
|
||||
this.project = checkNotNull(project, "project");
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logTrace(String message) {
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logDebug(String message) {
|
||||
project.log(message, Project.MSG_DEBUG);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logInfo(String message) {
|
||||
project.log(message);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logWarn(String message) {
|
||||
project.log(message, Project.MSG_WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logWarn(String message, Throwable e) {
|
||||
project.log(message, e, Project.MSG_WARN);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logError(String message) {
|
||||
project.log(message, Project.MSG_ERR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logError(String message, Throwable e) {
|
||||
project.log(message, e, Project.MSG_ERR);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.jclouds.tools.ant.logging.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.logging.config.LoggingModule;
|
||||
import org.jclouds.tools.ant.logging.AntLogger;
|
||||
|
||||
/**
|
||||
* Configures logging of type {@link AntLogger}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class AntLoggingModule extends LoggingModule {
|
||||
|
||||
private final Project project;
|
||||
|
||||
public AntLoggingModule(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerFactory createLoggerFactory() {
|
||||
return new AntLogger.AntLoggerFactory(checkNotNull(project, "project"));
|
||||
}
|
||||
}
|
|
@ -2,33 +2,31 @@
|
|||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
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
|
||||
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.
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!--
|
||||
For more configuration infromation and examples see the Apache Log4j
|
||||
website: http://logging.apache.org/log4j/
|
||||
For more configuration infromation and examples see the Apache
|
||||
Log4j website: http://logging.apache.org/log4j/
|
||||
-->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="false">
|
||||
|
@ -48,9 +46,9 @@
|
|||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
@ -70,9 +68,9 @@
|
|||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
@ -94,9 +92,9 @@
|
|||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
@ -130,7 +128,7 @@
|
|||
|
||||
|
||||
|
||||
<category name="org.jclouds.vcloud.terremark.VCloudComputeClient">
|
||||
<category name="org.jclouds.vcloud.VCloudComputeClient">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCVCLOUD" />
|
||||
</category>
|
||||
|
|
|
@ -27,6 +27,7 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
|
|||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
|
@ -57,7 +58,9 @@ import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
|||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||
|
||||
|
@ -98,6 +101,12 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port,
|
||||
AddInternetServiceOptions... options);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/internetServices")
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getAllInternetServices();
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/publicIps/{ipId}/InternetServices")
|
||||
|
@ -133,6 +142,13 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@MapEntityParam("name") String name, @MapEntityParam("port") int port,
|
||||
AddNodeOptions... options);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/internetServices/{internetServiceId}/nodes")
|
||||
@XMLResponseParser(NodesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getNodes(
|
||||
@PathParam("internetServiceId") String internetServiceId);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/nodeServices/{nodeId}")
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
@ -69,4 +70,8 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
@Override
|
||||
TerremarkVApp getVApp(String vAppId);
|
||||
|
||||
SortedSet<InternetService> getAllInternetServices();
|
||||
|
||||
SortedSet<Node> getNodes(String internetServiceId);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
package org.jclouds.vcloud.terremark.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
|
@ -29,16 +29,18 @@ import java.net.InetAddress;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.SshClient.Factory;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.TerremarkVApp;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
|
||||
|
@ -50,31 +52,22 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class VCloudComputeClient {
|
||||
public class TerremarkVCloudComputeClient {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Predicate<InetSocketAddress> socketTester;
|
||||
private final Predicate<URI> taskTester;
|
||||
private final TerremarkVCloudClient tmClient;
|
||||
|
||||
@Inject
|
||||
public VCloudComputeClient(TerremarkVCloudClient tmClient, Factory sshFactory,
|
||||
Predicate<InetSocketAddress> socketTester, Predicate<URI> successTester) {
|
||||
public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate<URI> successTester) {
|
||||
this.tmClient = tmClient;
|
||||
this.sshFactory = sshFactory;
|
||||
this.socketTester = socketTester;
|
||||
this.taskTester = successTester;
|
||||
}
|
||||
|
||||
private final Factory sshFactory;
|
||||
|
||||
public enum Image {
|
||||
CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS
|
||||
}
|
||||
|
||||
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
|
||||
Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(Image.UMBUNTU_JEOS, "11").build();
|
||||
Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(
|
||||
Image.UMBUNTU_JEOS, "11").build();
|
||||
|
||||
public String start(String name, int minCores, int minMegs, Image image) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
|
@ -83,7 +76,8 @@ public class VCloudComputeClient {
|
|||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
|
||||
minCores, minMegs, templateId);
|
||||
TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId,
|
||||
TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
|
||||
TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores)
|
||||
.megabytes(minMegs));
|
||||
logger.debug("<< instantiated VApp(%s)", vApp.getId());
|
||||
|
||||
logger.debug(">> deploying vApp(%s)", vApp.getId());
|
||||
|
@ -109,16 +103,6 @@ public class VCloudComputeClient {
|
|||
return Iterables.getLast(vApp.getNetworkToAddresses().values());
|
||||
}
|
||||
|
||||
public ExecResponse exec(InetAddress address, String command) {
|
||||
InetSocketAddress sshSocket = new InetSocketAddress(address, 22);
|
||||
String username = "vcloud";
|
||||
String password = "p4ssw0rd";
|
||||
logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command);
|
||||
ExecResponse exec = exec(sshSocket, username, password, command);
|
||||
logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError());
|
||||
return exec;
|
||||
}
|
||||
|
||||
public void reboot(String id) {
|
||||
TerremarkVApp vApp = tmClient.getVApp(id);
|
||||
logger.debug(">> rebooting vApp(%s)", vApp.getId());
|
||||
|
@ -129,6 +113,24 @@ public class VCloudComputeClient {
|
|||
|
||||
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());
|
||||
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());
|
||||
tmClient.deleteInternetService(service.getId());
|
||||
logger.debug("<< deleted InternetService(%s)", service.getId());
|
||||
continue SERVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vApp.getStatus() != VAppStatus.OFF) {
|
||||
logger.debug(">> powering off vApp(%s)", vApp.getId());
|
||||
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
|
||||
|
@ -140,23 +142,8 @@ public class VCloudComputeClient {
|
|||
logger.debug("<< deleted vApp(%s)", vApp.getId());
|
||||
}
|
||||
|
||||
private ExecResponse exec(InetSocketAddress socket, String username, String password,
|
||||
String command) {
|
||||
if (!socketTester.apply(socket)) {
|
||||
throw new SocketNotOpenException(socket);
|
||||
}
|
||||
SshClient connection = sshFactory.create(socket, username, password);
|
||||
try {
|
||||
connection.connect();
|
||||
return connection.exec(command);
|
||||
} finally {
|
||||
if (connection != null)
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, String taskType,
|
||||
VAppStatus expectedStatus) {
|
||||
private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask,
|
||||
String taskType, VAppStatus expectedStatus) {
|
||||
if (!taskTester.apply(deployTask.getLocation())) {
|
||||
throw new TaskException(taskType, vApp, deployTask);
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
*
|
||||
* 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 java.net.InetAddress;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.Image;
|
||||
import org.jclouds.compute.Profile;
|
||||
import org.jclouds.compute.Server;
|
||||
import org.jclouds.compute.domain.CreateServerResponse;
|
||||
import org.jclouds.compute.domain.LoginType;
|
||||
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.domain.NamedResource;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.internal.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class TerremarkVCloudComputeService implements ComputeService {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final TerremarkVCloudComputeClient computeClient;
|
||||
private final TerremarkVCloudClient tmClient;
|
||||
|
||||
@Inject
|
||||
public TerremarkVCloudComputeService(TerremarkVCloudClient tmClient,
|
||||
TerremarkVCloudComputeClient computeClient) {
|
||||
this.tmClient = tmClient;
|
||||
this.computeClient = computeClient;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServerById(String id) {
|
||||
return new TerremarkVCloudServer(computeClient, tmClient.getVApp(id));
|
||||
}
|
||||
|
||||
public SortedSet<InternetService> getInternetServicesByName(final String name) {
|
||||
return Sets.newTreeSet(Iterables.filter(tmClient.getAllInternetServices(),
|
||||
new Predicate<InternetService>() {
|
||||
@Override
|
||||
public boolean apply(InternetService input) {
|
||||
return input.getName().equalsIgnoreCase(name);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Server> getServerByName(final String name) {
|
||||
return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate<Server>() {
|
||||
@Override
|
||||
public boolean apply(Server input) {
|
||||
return input.getName().equalsIgnoreCase(name);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Server> listServers() {
|
||||
SortedSet<Server> servers = Sets.newTreeSet();
|
||||
for (NamedResource resource : tmClient.getDefaultVDC().getResourceEntities().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
servers.add(getServerById(resource.getId()));
|
||||
}
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
*
|
||||
* 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 org.jclouds.compute.Server;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkVCloudServer implements Server {
|
||||
|
||||
private final TerremarkVCloudComputeClient computeClient;
|
||||
|
||||
private final TerremarkVApp vApp;
|
||||
|
||||
public TerremarkVCloudServer(TerremarkVCloudComputeClient computeClient, TerremarkVApp vApp) {
|
||||
this.vApp = vApp;
|
||||
this.computeClient = computeClient;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return vApp.getId();
|
||||
}
|
||||
|
||||
public Boolean destroy() {
|
||||
computeClient.stop(getId());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return vApp.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Server o) {
|
||||
return (this == o) ? 0 : getId().compareTo(o.getId());
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import java.net.URI;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
@ -35,6 +36,7 @@ import org.jclouds.vcloud.endpoints.Org;
|
|||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -45,6 +47,7 @@ import com.google.inject.Provides;
|
|||
public class TerremarkVCloudContextModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ComputeService.class).to(TerremarkVCloudComputeService.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -25,21 +25,30 @@ package org.jclouds.vcloud.terremark.config;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.concurrent.internal.SyncProxy;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.predicates.AddressReachable;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientFactory;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
||||
import org.jclouds.vcloud.predicates.TaskSuccess;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
|
@ -50,6 +59,26 @@ import com.google.inject.Provides;
|
|||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 10, TimeUnit.SECONDS);// make it
|
||||
// longer
|
||||
// then
|
||||
// default internet
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetAddress> addressTester(AddressReachable reachable) {
|
||||
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(TaskSuccess success) {
|
||||
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InternetServicesHandler extends HandlerWithResult<SortedSet<InternetService>> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final InternetServiceHandler handler;
|
||||
SortedSet<InternetService> result = Sets.newTreeSet();
|
||||
|
||||
@Inject
|
||||
public InternetServicesHandler(InternetServiceHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<InternetService> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
handler.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
handler.endElement(uri, name, qName);
|
||||
if (qName.equals("InternetService")) {
|
||||
result.add(handler.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
handler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NodesHandler extends HandlerWithResult<SortedSet<Node>> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final NodeHandler handler;
|
||||
SortedSet<Node> result = Sets.newTreeSet();
|
||||
|
||||
@Inject
|
||||
public NodesHandler(NodeHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Node> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
handler.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
handler.endElement(uri, name, qName);
|
||||
if (qName.equals("NodeService")) {
|
||||
result.add(handler.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
handler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -64,7 +64,9 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodesHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -81,19 +83,14 @@ import com.google.inject.util.Providers;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest")
|
||||
public class TerremarkVCloudAsyncClientTest extends
|
||||
RestClientTest<TerremarkVCloudAsyncClient> {
|
||||
public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVCloudAsyncClient> {
|
||||
|
||||
public void testGetDefaultVDC() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class
|
||||
.getMethod("getDefaultVDC");
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method);
|
||||
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC");
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -103,22 +100,19 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testInstantiateVAppTemplate() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"instantiateVAppTemplate", String.class, String.class, Array
|
||||
.newInstance(InstantiateVAppTemplateOptions.class, 0)
|
||||
.getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, "name", 3 + "");
|
||||
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", 3 + "");
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -130,25 +124,17 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
|
||||
public void testInstantiateVAppTemplateOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"instantiateVAppTemplate", String.class, String.class, Array
|
||||
.newInstance(
|
||||
InstantiateVAppTemplateOptions.class,
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, "name", 3 + "", cpuCount(4).megabytes(
|
||||
1024).inNetwork(URI.create("http://newnet")));
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet")));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertEntityEquals(
|
||||
httpMethod,
|
||||
IOUtils
|
||||
.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -158,21 +144,17 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetService() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"addInternetService", String.class, String.class, int.class,
|
||||
Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||
.getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, "name", "tcp", 22);
|
||||
public void testAddInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
||||
String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", "tcp", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -182,22 +164,17 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetServiceOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"addInternetService", String.class, String.class, int.class,
|
||||
Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||
.getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, "name", "tcp", 22, disabled()
|
||||
.withDescription("yahoo"));
|
||||
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
||||
String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", "tcp", 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
|
@ -206,15 +183,30 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetInternetService() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"getInternetService", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12);
|
||||
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServices");
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "GET http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServicesHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class
|
||||
.getMethod("getInternetService", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -225,20 +217,18 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDeleteInternetService() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"deleteInternetService", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12);
|
||||
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"DELETE http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod,
|
||||
ReturnVoidIf2xx.class);
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -247,19 +237,16 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
|
||||
public void testAddInternetServiceToExistingIp() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"addInternetServiceToExistingIp", String.class, String.class,
|
||||
String.class, int.class, Array.newInstance(
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
|
||||
String.class, String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12, "name", "tcp", 22);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, "name", "tcp", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -269,22 +256,18 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetServiceToExistingIpOptions()
|
||||
throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"addInternetServiceToExistingIp", String.class, String.class,
|
||||
String.class, int.class, Array.newInstance(
|
||||
public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
|
||||
String.class, String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12, "name", "tcp", 22, disabled()
|
||||
.withDescription("yahoo"));
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, "name", "tcp", 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
|
@ -293,21 +276,17 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddNode() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode",
|
||||
String.class, InetAddress.class, String.class, int.class, Array
|
||||
.newInstance(AddNodeOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12, InetAddress.getByName("10.2.2.2"),
|
||||
"name", 22);
|
||||
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
|
||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, InetAddress.getByName("10.2.2.2"), "name", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 298\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream("/terremark/CreateNodeService-test2.xml")));
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
|
@ -316,22 +295,17 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddNodeOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode",
|
||||
String.class, InetAddress.class, String.class, int.class, Array
|
||||
.newInstance(AddNodeOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12, InetAddress.getByName("10.2.2.2"),
|
||||
"name", 22, AddNodeOptions.Builder.disabled()
|
||||
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
|
||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled()
|
||||
.withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 336\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass()
|
||||
.getResourceAsStream(
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
|
@ -340,15 +314,12 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetNode() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12);
|
||||
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -359,20 +330,32 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"deleteNode", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor
|
||||
.createRequest(method, 12);
|
||||
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"DELETE http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod,
|
||||
ReturnVoidIf2xx.class);
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodesHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -380,11 +363,9 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) {
|
||||
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(),
|
||||
SetVCloudTokenCookie.class);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -398,39 +379,28 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP))
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP))
|
||||
.toProvider(Providers.<String> of("group"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW))
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW))
|
||||
.toProvider(Providers.<String> of("row"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||
.toProvider(Providers.<String> of("password"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
|
||||
.toProvider(Providers.<String> of("1"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY))
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY))
|
||||
.toProvider(Providers.<String> of("512"));
|
||||
bind(String.class)
|
||||
.annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||
.toProvider(
|
||||
Providers
|
||||
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(
|
||||
URI.create("http://catalog"));
|
||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.toInstance("http://catalogItem");
|
||||
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(
|
||||
URI.create("http://vcloud"));
|
||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance(
|
||||
"http://vapp");
|
||||
bind(URI.class).annotatedWith(VDC.class).toInstance(
|
||||
URI.create("http://vdc"));
|
||||
bind(URI.class).annotatedWith(Network.class).toInstance(
|
||||
URI.create("http://network"));
|
||||
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
|
||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp");
|
||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
||||
bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network"));
|
||||
bind(SetVCloudTokenCookie.class).toInstance(
|
||||
new SetVCloudTokenCookie(new Provider<String>() {
|
||||
|
||||
|
@ -440,8 +410,7 @@ public class TerremarkVCloudAsyncClientTest extends
|
|||
|
||||
}));
|
||||
|
||||
bind(Logger.LoggerFactory.class).toInstance(
|
||||
new LoggerFactory() {
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,13 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
|
||||
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
|
||||
|
||||
@Test
|
||||
public void testGetAllInternetServices() throws Exception {
|
||||
for (InternetService service : tmClient.getAllInternetServices()) {
|
||||
System.out.println(tmClient.getNodes(service.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultVDC() throws Exception {
|
||||
super.testDefaultVDC();
|
||||
|
|
|
@ -1,205 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.predicates.AddressReachable;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.predicates.TaskSuccess;
|
||||
import org.jclouds.vcloud.terremark.VCloudComputeClient.Image;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
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.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
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 {
|
||||
VCloudComputeClient 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 InternetService is;
|
||||
private Node node;
|
||||
private InetAddress publicIp;
|
||||
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() {
|
||||
is = tmClient.addInternetService("SSH", "TCP", 22);
|
||||
node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22);
|
||||
publicIp = is.getPublicIpAddress().getAddress();
|
||||
// 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 (node != null)
|
||||
tmClient.deleteNode(node.getId());
|
||||
if (is != null)
|
||||
tmClient.deleteInternetService(is.getId());
|
||||
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(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
private Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 10,
|
||||
TimeUnit.SECONDS);// make it longer then
|
||||
// default internet
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
private Predicate<InetAddress> addressTester(AddressReachable reachable) {
|
||||
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
private Predicate<URI> successTester(TaskSuccess success) {
|
||||
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}).buildInjector();
|
||||
client = injector.getInstance(VCloudComputeClient.class);
|
||||
tmClient = injector.getInstance(TerremarkVCloudClient.class);
|
||||
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* 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.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code InternetServicesHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.InternetServicesHandlerTest")
|
||||
public class InternetServicesHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test2() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/InternetServices.xml");
|
||||
|
||||
SortedSet<InternetService> result = factory.create(
|
||||
injector.getInstance(InternetServicesHandler.class)).parse(is);
|
||||
assertEquals(
|
||||
result,
|
||||
ImmutableSortedSet
|
||||
.of(new InternetService(
|
||||
524 + "",
|
||||
"IS_for_Jim2",
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"),
|
||||
new PublicIpAddress(
|
||||
4208,
|
||||
InetAddress.getByName("10.1.22.159"),
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208")),
|
||||
45, "HTTP", false, 1, "Some test service")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
*
|
||||
* 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.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NodesHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.NodesHandlerTest")
|
||||
public class NodesHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test1() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/NodeServices.xml");
|
||||
|
||||
SortedSet<Node> result = factory.create(injector.getInstance(NodesHandler.class)).parse(is);
|
||||
assertEquals(result, ImmutableSortedSet.of(new Node(242 + "", "Node for Jim", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"),
|
||||
InetAddress.getByName("172.16.20.3"), 80, false, "Some test node")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!--
|
||||
For more configuration infromation and examples see the Apache Log4j
|
||||
website: http://logging.apache.org/log4j/
|
||||
-->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="false">
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-wire.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="VCLOUDFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-vcloud.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||
%m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="FILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCVCLOUD" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="VCLOUDFILE" />
|
||||
</appender>
|
||||
|
||||
<!-- ================ -->
|
||||
<!-- Limit categories -->
|
||||
<!-- ================ -->
|
||||
|
||||
<category name="org.jclouds">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNC" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.http.headers">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
|
||||
|
||||
<category name="org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCVCLOUD" />
|
||||
</category>
|
||||
|
||||
|
||||
<category name="org.jclouds.predicates.SocketOpen">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="org.jclouds.vcloud.predicates.TaskSuccess">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
|
||||
<category name="jclouds.http.wire">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
<root>
|
||||
<priority value="WARN" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,20 @@
|
|||
<InternetServices xmlns="urn:tmrk:vCloudExpress-1.0"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<InternetService>
|
||||
<Id>524</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524
|
||||
</Href>
|
||||
<Name>IS_for_Jim2</Name>
|
||||
<PublicIpAddress>
|
||||
<Id>4208</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208
|
||||
</Href>
|
||||
<Name>10.1.22.159</Name>
|
||||
</PublicIpAddress>
|
||||
<Port>45</Port>
|
||||
<Protocol>HTTP</Protocol>
|
||||
<Enabled>false</Enabled>
|
||||
<Timeout>1</Timeout>
|
||||
<Description>Some test service</Description>
|
||||
</InternetService>
|
||||
</InternetServices>
|
|
@ -0,0 +1,13 @@
|
|||
<NodeServices xmlns="urn:tmrk:vCloudExpress-1.0"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<NodeService>
|
||||
<Id>242</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242
|
||||
</Href>
|
||||
<Name>Node for Jim</Name>
|
||||
<IpAddress>172.16.20.3</IpAddress>
|
||||
<Port>80</Port>
|
||||
<Enabled>false</Enabled>
|
||||
<Description>Some test node</Description>
|
||||
</NodeService>
|
||||
</NodeServices>
|
Loading…
Reference in New Issue