Issue 130: basic support for compute abstraction

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2391 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-10 06:36:10 +00:00
parent 60312b64f3
commit 3c41116782
10 changed files with 207 additions and 88 deletions

View File

@ -24,7 +24,8 @@
package org.jclouds.compute; package org.jclouds.compute;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.Future;
import org.jclouds.compute.domain.CreateServerResponse;
/** /**
* TODO: better name? * TODO: better name?
@ -32,12 +33,12 @@ import java.util.concurrent.Future;
* @author Ivan Meredith * @author Ivan Meredith
*/ */
public interface ComputeService { public interface ComputeService {
public Server createServerAndWait(String name, String profile, String image); SortedSet<Server> listServers();
public Future<Server> createServer(String name, String profile, String image); CreateServerResponse createServer(String name, String profile, String image);
public SortedSet<Server> listServers(); Server getServerById(String id);
public Server getServer(String id); SortedSet<Server> getServerByName(String id);
} }

View File

@ -23,21 +23,22 @@
*/ */
package org.jclouds.compute; package org.jclouds.compute;
import java.util.SortedSet;
/** /**
* @author Ivan Meredith * @author Ivan Meredith
*/ */
public interface Server { public interface Server extends Comparable<Server> {
/**
* unique id of the server. potentially generated by the service.
*
*/
public String getId(); public String getId();
public Platform createPlatform(String id/*, Archive archive , mount? */); /**
* user defined name of the server.
*
*/
public String getName();
public Platform getPlatform(String id); public Boolean destroy();
public SortedSet<Platform> listPlatforms();
public SortedSet<Instance> listInstances(/* platform("mybilling-1.0.1").tags("production" */);
public Boolean destroyServer();
} }

View File

@ -21,22 +21,39 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.compute; package org.jclouds.compute.domain;
import java.net.InetAddress;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.Future;
import org.jclouds.domain.Credentials;
/** /**
* @author Adrian Cole
* @author Ivan Meredith * @author Ivan Meredith
*/ */
public interface Platform { public interface CreateServerResponse {
public String getId();
public Future<Instance> createInstance(); /**
* unique id of the server. potentially generated by the service.
*
*/
String getId();
public Instance createInstanceAndWait(); /**
* user defined name of the server.
*
*/
String getName();
public Instance getInstance(String id); SortedSet<InetAddress> getPublicAddresses();
SortedSet<InetAddress> getPrivateAddresses();
int getLoginPort();
LoginType getLoginType();
Credentials getCredentials();
public SortedSet<Instance> listInstances();
} }

View File

@ -21,15 +21,17 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.compute; package org.jclouds.compute.domain;
import com.google.common.base.Service;
/** /**
* The login type of the server.
*
* @author Adrian Cole
* @author Ivan Meredith * @author Ivan Meredith
*/ */
public interface Instance extends Service { public enum LoginType {
String getId();
RDP, SSH
String getTag();
} }

View File

@ -0,0 +1,98 @@
/**
*
* 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.domain.internal;
import java.net.InetAddress;
import java.util.Comparator;
import java.util.SortedSet;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.LoginType;
import org.jclouds.domain.Credentials;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public class CreateServerResponseImpl implements CreateServerResponse {
private static final Comparator<InetAddress> ADDRESS_COMPARATOR = new Comparator<InetAddress>() {
@Override
public int compare(InetAddress o1, InetAddress o2) {
return (o1 == o2) ? 0 : o1.getHostAddress().compareTo(o2.getHostAddress());
}
};
private final String id;
private final String name;
private final SortedSet<InetAddress> publicAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR);
private final SortedSet<InetAddress> privateAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR);
private final int loginPort;
private final LoginType loginType;
private final Credentials credentials;
public CreateServerResponseImpl(String id, String name, Iterable<InetAddress> publicAddresses,
Iterable<InetAddress> privateAddresses, int loginPort, LoginType loginType,
Credentials credentials) {
this.id = id;
this.name = name;
Iterables.addAll(this.publicAddresses, publicAddresses);
Iterables.addAll(this.privateAddresses, privateAddresses);
this.loginPort = loginPort;
this.loginType = loginType;
this.credentials = credentials;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public SortedSet<InetAddress> getPublicAddresses() {
return publicAddresses;
}
public SortedSet<InetAddress> getPrivateAddresses() {
return privateAddresses;
}
public int getLoginPort() {
return loginPort;
}
public LoginType getLoginType() {
return loginType;
}
public Credentials getCredentials() {
return credentials;
}
}

View File

@ -23,17 +23,18 @@
*/ */
package org.jclouds.rimuhosting.miro.servers; package org.jclouds.rimuhosting.miro.servers;
import org.jclouds.compute.ComputeService;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.domain.Server;
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
import javax.inject.Singleton;
import javax.inject.Inject;
import java.util.concurrent.Future;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
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;
/** /**
* @author Ivan Meredith * @author Ivan Meredith
*/ */
@ -46,13 +47,11 @@ public class RimuHostingComputeService implements ComputeService {
this.rhClient = rhClient; this.rhClient = rhClient;
} }
public org.jclouds.compute.Server createServerAndWait(String name, String profile, String image) { @Override
public CreateServerResponse createServer(String name, String profile, String image) {
NewServerResponse serverResp = rhClient.createInstance(name, image, profile); NewServerResponse serverResp = rhClient.createInstance(name, image, profile);
return new RimuHostingServer(serverResp.getInstance(), rhClient); // return new RimuHostingServer(serverResp.getInstance(), rhClient);
} throw new UnsupportedOperationException();
public Future<org.jclouds.compute.Server> createServer(String name, String profile, String image) {
return null; //To change body of implemented methods use File | Settings | File Templates.
} }
public SortedSet<org.jclouds.compute.Server> listServers() { public SortedSet<org.jclouds.compute.Server> listServers() {
@ -64,7 +63,12 @@ public class RimuHostingComputeService implements ComputeService {
return servers; return servers;
} }
public org.jclouds.compute.Server getServer(String id) { public org.jclouds.compute.Server getServerById(String id) {
return new RimuHostingServer(rhClient.getInstance(Long.valueOf(id)), rhClient); return new RimuHostingServer(rhClient.getInstance(Long.valueOf(id)), rhClient);
} }
@Override
public SortedSet<org.jclouds.compute.Server> getServerByName(String id) {
throw new UnsupportedOperationException();
}
} }

View File

@ -24,18 +24,15 @@
package org.jclouds.rimuhosting.miro.servers; package org.jclouds.rimuhosting.miro.servers;
import org.jclouds.compute.Server; import org.jclouds.compute.Server;
import org.jclouds.compute.Platform;
import org.jclouds.compute.Instance;
import org.jclouds.rimuhosting.miro.RimuHostingClient; import org.jclouds.rimuhosting.miro.RimuHostingClient;
import java.util.SortedSet;
public class RimuHostingServer implements Server { public class RimuHostingServer implements Server {
org.jclouds.rimuhosting.miro.domain.Server rhServer; org.jclouds.rimuhosting.miro.domain.Server rhServer;
RimuHostingClient rhClient; RimuHostingClient rhClient;
public RimuHostingServer(org.jclouds.rimuhosting.miro.domain.Server rhServer, RimuHostingClient rhClient){ public RimuHostingServer(org.jclouds.rimuhosting.miro.domain.Server rhServer,
RimuHostingClient rhClient) {
this.rhServer = rhServer; this.rhServer = rhServer;
this.rhClient = rhClient; this.rhClient = rhClient;
} }
@ -44,24 +41,18 @@ public class RimuHostingServer implements Server {
return rhServer.toString(); return rhServer.toString();
} }
public Platform createPlatform(String id) { public Boolean destroy() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Platform getPlatform(String id) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public SortedSet<Platform> listPlatforms() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public SortedSet<Instance> listInstances() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Boolean destroyServer() {
rhClient.destroyInstance(rhServer.getId()); rhClient.destroyInstance(rhServer.getId());
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
public String getName() {
throw new UnsupportedOperationException();
}
@Override
public int compareTo(Server o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
} }

View File

@ -50,10 +50,10 @@ public class PropertiesTest {
.getInput()); .getInput());
} }
public void testAzure() { public void testRimu() {
assertEquals(properties.getProperty("rimuhosting.contextBuilder"), assertEquals(properties.getProperty("rimuhosting.contextbuilder"),
RimuHostingContextBuilder.class.getName()); RimuHostingContextBuilder.class.getName());
assertEquals(properties.getProperty("rimuhosting.propertiesBuilder"), assertEquals(properties.getProperty("rimuhosting.propertiesbuilder"),
RimuHostingPropertiesBuilder.class.getName()); RimuHostingPropertiesBuilder.class.getName());
} }

View File

@ -23,15 +23,19 @@
*/ */
package org.jclouds.rimuhosting.miro.servers; package org.jclouds.rimuhosting.miro.servers;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeGroups;
import org.jclouds.rimuhosting.miro.*;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.compute.Server;
import com.google.inject.*;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.RimuHostingContextBuilder;
import org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.inject.Injector;
/** /**
* @author Ivan Meredith * @author Ivan Meredith
*/ */
@ -44,8 +48,9 @@ public class RimuHostingComputeServiceLiveTest {
public void setupClient() { public void setupClient() {
String account = "ddd"; String account = "ddd";
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder( Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(account,
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule()).buildInjector(); key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule())
.buildInjector();
rhClient = injector.getInstance(RimuHostingClient.class); rhClient = injector.getInstance(RimuHostingClient.class);
rhServerService = injector.getInstance(RimuHostingComputeService.class); rhServerService = injector.getInstance(RimuHostingComputeService.class);
@ -53,8 +58,8 @@ public class RimuHostingComputeServiceLiveTest {
@Test @Test
public void testServerCreate() { public void testServerCreate() {
Server server = rhServerService.createServerAndWait("test.com", "MIRO1B", "lenny"); CreateServerResponse server = rhServerService.createServer("test.com", "MIRO1B", "lenny");
assertNotNull(rhClient.getInstance(Long.valueOf(server.getId()))); assertNotNull(rhClient.getInstance(Long.valueOf(server.getId())));
server.destroyServer(); rhServerService.getServerById(server.getId()).destroy();
} }
} }

View File

@ -81,7 +81,7 @@ public class ComputeTask extends Task {
if (ACTION_CREATE.equalsIgnoreCase(action)) { if (ACTION_CREATE.equalsIgnoreCase(action)) {
ComputeService computeService = computeMap.get(HttpUtils.createUri(provider)); ComputeService computeService = computeMap.get(HttpUtils.createUri(provider));
log("hello"); log("hello");
computeService.createServerAndWait("test.com", "MIRO1B", "lenny"); computeService.createServer("test.com", "MIRO1B", "lenny");
} }
} }