diff --git a/core/src/main/java/org/jclouds/compute/ComputeService.java b/core/src/main/java/org/jclouds/compute/ComputeService.java index 96082aba71..06693c2d09 100644 --- a/core/src/main/java/org/jclouds/compute/ComputeService.java +++ b/core/src/main/java/org/jclouds/compute/ComputeService.java @@ -24,20 +24,21 @@ package org.jclouds.compute; import java.util.SortedSet; -import java.util.concurrent.Future; + +import org.jclouds.compute.domain.CreateServerResponse; /** * TODO: better name? - * + * * @author Ivan Meredith */ public interface ComputeService { - public Server createServerAndWait(String name, String profile, String image); + SortedSet listServers(); - public Future createServer(String name, String profile, String image); + CreateServerResponse createServer(String name, String profile, String image); - public SortedSet listServers(); + Server getServerById(String id); + + SortedSet getServerByName(String id); - public Server getServer(String id); - } diff --git a/core/src/main/java/org/jclouds/compute/Server.java b/core/src/main/java/org/jclouds/compute/Server.java index 9b37d2ceb7..d6987eaa68 100644 --- a/core/src/main/java/org/jclouds/compute/Server.java +++ b/core/src/main/java/org/jclouds/compute/Server.java @@ -23,21 +23,22 @@ */ package org.jclouds.compute; -import java.util.SortedSet; - /** * @author Ivan Meredith */ -public interface Server { +public interface Server extends Comparable { + + /** + * unique id of the server. potentially generated by the service. + * + */ 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 SortedSet listPlatforms(); - - public SortedSet listInstances(/* platform("mybilling-1.0.1").tags("production" */); - - public Boolean destroyServer(); + public Boolean destroy(); } diff --git a/core/src/main/java/org/jclouds/compute/Platform.java b/core/src/main/java/org/jclouds/compute/domain/CreateServerResponse.java similarity index 64% rename from core/src/main/java/org/jclouds/compute/Platform.java rename to core/src/main/java/org/jclouds/compute/domain/CreateServerResponse.java index dd5926b1db..e74f9dd757 100644 --- a/core/src/main/java/org/jclouds/compute/Platform.java +++ b/core/src/main/java/org/jclouds/compute/domain/CreateServerResponse.java @@ -21,22 +21,39 @@ * under the License. * ==================================================================== */ -package org.jclouds.compute; +package org.jclouds.compute.domain; +import java.net.InetAddress; import java.util.SortedSet; -import java.util.concurrent.Future; + +import org.jclouds.domain.Credentials; /** + * @author Adrian Cole * @author Ivan Meredith */ -public interface Platform { - public String getId(); +public interface CreateServerResponse { - public Future 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 getPublicAddresses(); - public SortedSet listInstances(); -} + SortedSet getPrivateAddresses(); + + int getLoginPort(); + + LoginType getLoginType(); + + Credentials getCredentials(); + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/compute/Instance.java b/core/src/main/java/org/jclouds/compute/domain/LoginType.java similarity index 84% rename from core/src/main/java/org/jclouds/compute/Instance.java rename to core/src/main/java/org/jclouds/compute/domain/LoginType.java index 9acbc4a32e..ada439b826 100644 --- a/core/src/main/java/org/jclouds/compute/Instance.java +++ b/core/src/main/java/org/jclouds/compute/domain/LoginType.java @@ -21,15 +21,17 @@ * 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 */ -public interface Instance extends Service { - String getId(); +public enum LoginType { - String getTag(); -} + RDP, SSH + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/compute/domain/internal/CreateServerResponseImpl.java b/core/src/main/java/org/jclouds/compute/domain/internal/CreateServerResponseImpl.java new file mode 100644 index 0000000000..bcee8453f6 --- /dev/null +++ b/core/src/main/java/org/jclouds/compute/domain/internal/CreateServerResponseImpl.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 ADDRESS_COMPARATOR = new Comparator() { + + @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 publicAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); + private final SortedSet privateAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); + private final int loginPort; + private final LoginType loginType; + private final Credentials credentials; + + public CreateServerResponseImpl(String id, String name, Iterable publicAddresses, + Iterable 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 getPublicAddresses() { + return publicAddresses; + } + + public SortedSet getPrivateAddresses() { + return privateAddresses; + } + + public int getLoginPort() { + return loginPort; + } + + public LoginType getLoginType() { + return loginType; + } + + public Credentials getCredentials() { + return credentials; + } + +} diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java index eb6ca95354..3ffb1feecd 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java @@ -23,17 +23,18 @@ */ 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.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 */ @@ -42,29 +43,32 @@ public class RimuHostingComputeService implements ComputeService { RimuHostingClient rhClient; @Inject - public RimuHostingComputeService(RimuHostingClient rhClient){ + public RimuHostingComputeService(RimuHostingClient 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); - return new RimuHostingServer(serverResp.getInstance(), rhClient); - } - - public Future createServer(String name, String profile, String image) { - return null; //To change body of implemented methods use File | Settings | File Templates. + // return new RimuHostingServer(serverResp.getInstance(), rhClient); + throw new UnsupportedOperationException(); } public SortedSet listServers() { SortedSet servers = new TreeSet(); SortedSet rhServers = rhClient.getInstanceList(); - for(Server rhServer : rhServers) { - servers.add(new RimuHostingServer(rhServer,rhClient)); + for (Server rhServer : rhServers) { + servers.add(new RimuHostingServer(rhServer, rhClient)); } 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); } + + @Override + public SortedSet getServerByName(String id) { + throw new UnsupportedOperationException(); + } } \ No newline at end of file diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingServer.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingServer.java index f4994ef53b..8be3ac97bc 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingServer.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingServer.java @@ -24,18 +24,15 @@ package org.jclouds.rimuhosting.miro.servers; import org.jclouds.compute.Server; -import org.jclouds.compute.Platform; -import org.jclouds.compute.Instance; import org.jclouds.rimuhosting.miro.RimuHostingClient; -import java.util.SortedSet; - public class RimuHostingServer implements Server { org.jclouds.rimuhosting.miro.domain.Server rhServer; 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.rhClient = rhClient; } @@ -44,24 +41,18 @@ public class RimuHostingServer implements Server { return rhServer.toString(); } - public Platform createPlatform(String id) { - 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 listPlatforms() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public SortedSet listInstances() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public Boolean destroyServer() { + public Boolean destroy() { rhClient.destroyInstance(rhServer.getId()); return Boolean.TRUE; } + + @Override + public String getName() { + throw new UnsupportedOperationException(); + } + + @Override + public int compareTo(Server o) { + return (this == o) ? 0 : getId().compareTo(o.getId()); + } } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/PropertiesTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/PropertiesTest.java index b58b68e4b7..5562c1e34a 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/PropertiesTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/PropertiesTest.java @@ -50,10 +50,10 @@ public class PropertiesTest { .getInput()); } - public void testAzure() { - assertEquals(properties.getProperty("rimuhosting.contextBuilder"), + public void testRimu() { + assertEquals(properties.getProperty("rimuhosting.contextbuilder"), RimuHostingContextBuilder.class.getName()); - assertEquals(properties.getProperty("rimuhosting.propertiesBuilder"), + assertEquals(properties.getProperty("rimuhosting.propertiesbuilder"), RimuHostingPropertiesBuilder.class.getName()); } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java index f92d36eff5..46d82c7e87 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java @@ -23,15 +23,19 @@ */ 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 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 */ @@ -44,17 +48,18 @@ public class RimuHostingComputeServiceLiveTest { public void setupClient() { String account = "ddd"; String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder( - account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule()).buildInjector(); + Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(account, + key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule()) + .buildInjector(); rhClient = injector.getInstance(RimuHostingClient.class); rhServerService = injector.getInstance(RimuHostingComputeService.class); } @Test - public void testServerCreate(){ - Server server = rhServerService.createServerAndWait("test.com", "MIRO1B", "lenny"); + public void testServerCreate() { + CreateServerResponse server = rhServerService.createServer("test.com", "MIRO1B", "lenny"); assertNotNull(rhClient.getInstance(Long.valueOf(server.getId()))); - server.destroyServer(); + rhServerService.getServerById(server.getId()).destroy(); } } diff --git a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java index 321c1811d5..9f00ba4f8b 100644 --- a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java +++ b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java @@ -81,7 +81,7 @@ public class ComputeTask extends Task { if (ACTION_CREATE.equalsIgnoreCase(action)) { ComputeService computeService = computeMap.get(HttpUtils.createUri(provider)); log("hello"); - computeService.createServerAndWait("test.com", "MIRO1B", "lenny"); + computeService.createServer("test.com", "MIRO1B", "lenny"); } }