From 86b07ed76802f272bffe367e5fbff659f5bd5d42 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 23 Jul 2012 11:43:37 -0700 Subject: [PATCH] format and imports --- .../jclouds/smartos/SmartOSApiMetadata.java | 20 +- .../SmartOSComputeServiceContextModule.java | 17 +- .../smartos/compute/domain/DataSet.java | 208 ++++----- .../smartos/compute/domain/SmartOSHost.java | 436 +++++++++--------- .../jclouds/smartos/compute/domain/VM.java | 329 +++++++------ .../jclouds/smartos/compute/domain/VmNIC.java | 152 +++--- .../compute/domain/VmSpecification.java | 208 ++++----- .../compute/functions/DataSetToImage.java | 5 +- .../functions/DatacenterToLocation.java | 19 +- .../compute/functions/VMToNodeMetadata.java | 75 ++- .../functions/VmSpecificationToHardware.java | 4 +- .../SmartOSComputeServiceAdapter.java | 70 +-- ...nagerComputeServiceContextBuilderTest.java | 29 +- .../SmartOSManagerComputeServiceLiveTest.java | 5 +- .../smartos/compute/domain/DataSetTest.java | 45 +- .../smartos/compute/domain/VMTest.java | 41 +- 16 files changed, 805 insertions(+), 858 deletions(-) diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/SmartOSApiMetadata.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/SmartOSApiMetadata.java index af47bb55b8..8e29b1e0e9 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/SmartOSApiMetadata.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/SmartOSApiMetadata.java @@ -13,7 +13,7 @@ import org.jclouds.smartos.compute.config.SmartOSComputeServiceContextModule; * @author Nigel Magnay */ public class SmartOSApiMetadata extends BaseApiMetadata { - + /** The serialVersionUID */ private static final long serialVersionUID = 3606170564482119304L; @@ -36,16 +36,16 @@ public class SmartOSApiMetadata extends BaseApiMetadata { public static class Builder extends BaseApiMetadata.Builder { - protected Builder(){ + protected Builder() { id("smartos-ssh") - .name("SmartOS SSH API") - .identityName("Username") - .defaultIdentity("root") - .defaultCredential("smartos") - .defaultEndpoint("http://localhost") - .documentation(URI.create("http://http://wiki.smartos.org/display/DOC/How+to+create+a+Virtual+Machine+in+SmartOS")) - .view(ComputeServiceContext.class) - .defaultModule(SmartOSComputeServiceContextModule.class); + .name("SmartOS SSH API") + .identityName("Username") + .defaultIdentity("root") + .defaultCredential("smartos") + .defaultEndpoint("http://localhost") + .documentation( + URI.create("http://http://wiki.smartos.org/display/DOC/How+to+create+a+Virtual+Machine+in+SmartOS")) + .view(ComputeServiceContext.class).defaultModule(SmartOSComputeServiceContextModule.class); } @Override diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/config/SmartOSComputeServiceContextModule.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/config/SmartOSComputeServiceContextModule.java index a5fe6c6805..124bfc9ad3 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/config/SmartOSComputeServiceContextModule.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/config/SmartOSComputeServiceContextModule.java @@ -18,23 +18,23 @@ */ package org.jclouds.smartos.compute.config; -import com.google.common.base.Function; -import com.google.inject.TypeLiteral; -import org.jclouds.smartos.compute.domain.DataSet; -import org.jclouds.smartos.compute.domain.SmartOSHost; -import org.jclouds.smartos.compute.domain.VM; -import org.jclouds.smartos.compute.domain.VmSpecification; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.domain.Location; - +import org.jclouds.smartos.compute.domain.DataSet; +import org.jclouds.smartos.compute.domain.SmartOSHost; +import org.jclouds.smartos.compute.domain.VM; +import org.jclouds.smartos.compute.domain.VmSpecification; import org.jclouds.smartos.compute.functions.DataSetToImage; import org.jclouds.smartos.compute.functions.DatacenterToLocation; import org.jclouds.smartos.compute.functions.VMToNodeMetadata; import org.jclouds.smartos.compute.functions.VmSpecificationToHardware; import org.jclouds.smartos.compute.strategy.SmartOSComputeServiceAdapter; +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + /** * * @author Nigel Magnay @@ -56,7 +56,8 @@ public class SmartOSComputeServiceContextModule extends bind(new TypeLiteral>() { }).to(DatacenterToLocation.class); // to have the compute service adapter override default locations - //install(new LocationsFromComputeServiceAdapterModule(){}); + // install(new LocationsFromComputeServiceAdapterModule(){}); } } \ No newline at end of file diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/DataSet.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/DataSet.java index 0b766af966..be0576672a 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/DataSet.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/DataSet.java @@ -1,141 +1,131 @@ package org.jclouds.smartos.compute.domain; -import com.google.common.base.Objects; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import java.util.UUID; +import com.google.common.base.Objects; + /** * Dataset is a pre-built image ready to be cloned. */ public class DataSet { - private final UUID uuid; - private final String os; - private final String published; - private final String urn; + private final UUID uuid; + private final String os; + private final String published; + private final String urn; - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public Builder toBuilder() { - return builder().fromDataSet(this); - } + public Builder toBuilder() { + return builder().fromDataSet(this); + } - public static class Builder { + public static class Builder { - public UUID uuid; - public String os; - public String published; - public String urn; + public UUID uuid; + public String os; + public String published; + public String urn; - public Builder uuid(UUID uuid) { - this.uuid = uuid; - return this; - } + public Builder uuid(UUID uuid) { + this.uuid = uuid; + return this; + } - public Builder uuid(String uuid) { - this.uuid = UUID.fromString(uuid); - return this; - } + public Builder uuid(String uuid) { + this.uuid = UUID.fromString(uuid); + return this; + } - public Builder os(String os) { - this.os = os; - return this; - } + public Builder os(String os) { + this.os = os; + return this; + } - public Builder published(String published) { - this.published = published; - return this; - } + public Builder published(String published) { + this.published = published; + return this; + } - public Builder urn(String urn) { - this.urn = urn; - return this; - } + public Builder urn(String urn) { + this.urn = urn; + return this; + } - public Builder fromDsadmString(String string) { - String [] sections = string.split(" "); + public Builder fromDsadmString(String string) { + String[] sections = string.split(" "); - uuid ( sections[0] ); - os ( sections[1] ); - published ( sections[2] ); - urn ( sections[3] ); + uuid(sections[0]); + os(sections[1]); + published(sections[2]); + urn(sections[3]); - return this; - } + return this; + } + public DataSet build() { + return new DataSet(uuid, os, published, urn); + } - public DataSet build() { - return new DataSet(uuid, os, published, urn); - } + public Builder fromDataSet(DataSet in) { + return uuid(in.getUuid()).os(in.getOs()).published(in.getPublished()).urn(in.getUrn()); + } + } - public Builder fromDataSet(DataSet in) { - return uuid(in.getUuid()) - .os(in.getOs()) - .published(in.getPublished()) - .urn(in.getUrn()); - } - } + protected DataSet(UUID uuid, String os, String published, String urn) { + this.uuid = uuid; + this.os = os; + this.published = published; + this.urn = urn; + } - protected DataSet(UUID uuid, String os, String published, String urn) { - this.uuid = uuid; - this.os = os; - this.published = published; - this.urn = urn; - } + public UUID getUuid() { + return uuid; + } - public UUID getUuid() { - return uuid; - } + public String getOs() { + return os; + } - public String getOs() { - return os; - } + public String getPublished() { + return published; + } - public String getPublished() { - return published; - } + public String getUrn() { + return urn; + } - public String getUrn() { - return urn; - } + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + // UUID is primary key + return uuid.hashCode(); + } - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - // UUID is primary key - return uuid.hashCode(); - } + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return uuid.equals(((DataSet) obj).uuid); + } - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - return uuid.equals(((DataSet)obj).uuid); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("uuid", uuid) - .add("os", os) - .add("published", published) - .add("urn", urn).toString(); - } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("uuid", uuid).add("os", os).add("published", published) + .add("urn", urn).toString(); + } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/SmartOSHost.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/SmartOSHost.java index 7feb88a9ea..248f42fe0d 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/SmartOSHost.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/SmartOSHost.java @@ -1,19 +1,5 @@ package org.jclouds.smartos.compute.domain; -import com.google.common.base.Splitter; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.net.HostAndPort; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.location.Provider; -import org.jclouds.rest.annotations.Credential; -import org.jclouds.rest.annotations.Identity; -import org.jclouds.ssh.SshClient; - -import javax.annotation.Nullable; -import javax.inject.Inject; -import javax.inject.Singleton; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -23,274 +9,276 @@ import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import org.jclouds.domain.LoginCredentials; +import org.jclouds.location.Provider; +import org.jclouds.rest.annotations.Credential; +import org.jclouds.rest.annotations.Identity; +import org.jclouds.ssh.SshClient; + +import com.google.common.base.Splitter; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.net.HostAndPort; + /** * A host machine that runs smartOS */ -@Singleton public class SmartOSHost { - protected final String hostname; - protected final String username; - protected final String password; + protected final String hostname; + protected final String username; + protected final String password; - protected SshClient.Factory sshClientFactory; + protected SshClient.Factory sshClientFactory; - private SshClient _connection; + private SshClient _connection; - public static class HostException extends RuntimeException { - public HostException(String s, Throwable throwable) { - super(s, throwable); - } + public static class HostException extends RuntimeException { + private static final long serialVersionUID = -2247796213703641847L; - public HostException(String s) { - super(s); - } - } + public HostException(String s, Throwable throwable) { + super(s, throwable); + } - public static class NoResponseException extends Exception { - public NoResponseException() { - } - } + public HostException(String s) { + super(s); + } + } - public static Builder builder() { - return new Builder(); - } + public static class NoResponseException extends Exception { + private static final long serialVersionUID = -2247796213703641847L; - public Builder toBuilder() { - return builder().fromSmartOSHost(this); - } + public NoResponseException() { + } + } - public static class Builder { - protected String hostname; - protected String username; - protected String password; - protected SshClient.Factory sshFactory; + public static Builder builder() { + return new Builder(); + } - public Builder hostname(String hostname) { - this.hostname = hostname; - return this; - } + public Builder toBuilder() { + return builder().fromSmartOSHost(this); + } - public Builder username(String username) { - this.username = username; - return this; - } + public static class Builder { + protected String hostname; + protected String username; + protected String password; + protected SshClient.Factory sshFactory; - public Builder password(String password) { - this.password = password; - return this; - } + public Builder hostname(String hostname) { + this.hostname = hostname; + return this; + } - public Builder sshFactory(SshClient.Factory sshFactory) { - this.sshFactory = sshFactory; - return this; - } + public Builder username(String username) { + this.username = username; + return this; + } - public SmartOSHost build() { - return new SmartOSHost(hostname, username, password, sshFactory); - } + public Builder password(String password) { + this.password = password; + return this; + } - public Builder fromSmartOSHost(SmartOSHost in) { - return this.hostname ( in.getHostname() ) - .username ( in.getHostname() ) - .password ( in.getPassword() ) - .sshFactory( in.getSshClientFactory() ); - } - } + public Builder sshFactory(SshClient.Factory sshFactory) { + this.sshFactory = sshFactory; + return this; + } - @Inject - protected SmartOSHost(@Provider Supplier provider, - @Nullable @Identity String identity, - @Nullable @Credential String credential, - SshClient.Factory sshFactory) { + public SmartOSHost build() { + return new SmartOSHost(hostname, username, password, sshFactory); + } - this.hostname = provider.get().getHost(); - this.username = identity; - this.password = credential; - this.sshClientFactory = sshFactory; - } + public Builder fromSmartOSHost(SmartOSHost in) { + return this.hostname(in.getHostname()).username(in.getHostname()).password(in.getPassword()) + .sshFactory(in.getSshClientFactory()); + } + } - protected SmartOSHost(String hostname, String username, String password, SshClient.Factory sshClientFactory) { - this.hostname = hostname; - this.username = username; - this.password = password; - this.sshClientFactory = sshClientFactory; - } + @Inject + protected SmartOSHost(@Provider Supplier provider, @Nullable @Identity String identity, + @Nullable @Credential String credential, SshClient.Factory sshFactory) { - public String getDescription() { - return "SmartOS@" + hostname; - } + this.hostname = provider.get().getHost(); + this.username = identity; + this.password = credential; + this.sshClientFactory = sshFactory; + } - public String getHostname() { - return hostname; - } + protected SmartOSHost(String hostname, String username, String password, SshClient.Factory sshClientFactory) { + this.hostname = hostname; + this.username = username; + this.password = password; + this.sshClientFactory = sshClientFactory; + } - public String getUsername() { - return username; - } + public String getDescription() { + return "SmartOS@" + hostname; + } - public String getPassword() { - return password; - } + public String getHostname() { + return hostname; + } - public SshClient.Factory getSshClientFactory() { - return sshClientFactory; - } + public String getUsername() { + return username; + } - protected SshClient getConnection() { - if (_connection == null) { + public String getPassword() { + return password; + } - LoginCredentials credentials = new LoginCredentials.Builder() - .user(username) - .password(password) - .build(); + public SshClient.Factory getSshClientFactory() { + return sshClientFactory; + } - _connection = getSshClientFactory().create( - HostAndPort.fromParts(hostname, 22), - credentials - ); + protected SshClient getConnection() { + if (_connection == null) { - _connection.connect(); + LoginCredentials credentials = new LoginCredentials.Builder().user(username).password(password).build(); - } - return _connection; - } + _connection = getSshClientFactory().create(HostAndPort.fromParts(hostname, 22), credentials); + _connection.connect(); - public String exec(String cmd) { - return getConnection().exec(cmd).getOutput(); - } + } + return _connection; + } - public String vmList() { - return exec("vmadm list -p"); - } + public String exec(String cmd) { + return getConnection().exec(cmd).getOutput(); + } + public String vmList() { + return exec("vmadm list -p"); + } - public Map getVMIpAddresses(UUID vmId) - { - ImmutableMap.Builder netMapBuilder = ImmutableMap.builder(); + public Map getVMIpAddresses(UUID vmId) { + ImmutableMap.Builder netMapBuilder = ImmutableMap.builder(); - String response = getConnection().exec("zlogin " + vmId.toString() + " ifconfig -a4").getOutput(); + String response = getConnection().exec("zlogin " + vmId.toString() + " ifconfig -a4").getOutput(); - if( response.length() == 0) - return ImmutableMap.of(); + if (response.length() == 0) + return ImmutableMap.of(); - Iterable strings = Splitter.on("\n").split(response); - Pattern inetMatcher = Pattern.compile("inet [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"); + Iterable strings = Splitter.on("\n").split(response); + Pattern inetMatcher = Pattern.compile("inet [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"); - String iface = ""; - for(String line : strings ) - { - if( line.length() > 0 && Character.isLetterOrDigit(line.charAt(0)) ) - { - iface = line.substring(0, line.indexOf(":") ); - } - else - { - Matcher matcher = inetMatcher.matcher(line); - if( matcher.find() ) - netMapBuilder.put(iface, matcher.group().substring(5)); - } - } + String iface = ""; + for (String line : strings) { + if (line.length() > 0 && Character.isLetterOrDigit(line.charAt(0))) { + iface = line.substring(0, line.indexOf(":")); + } else { + Matcher matcher = inetMatcher.matcher(line); + if (matcher.find()) + netMapBuilder.put(iface, matcher.group().substring(5)); + } + } - return netMapBuilder.build(); + return netMapBuilder.build(); - } + } - /** - * What remotely available images are there in the cloud? - * - * @return Collection of datasets - */ - public Iterable getAvailableImages() { - return toSpecList(exec("dsadm avail")); - } + /** + * What remotely available images are there in the cloud? + * + * @return Collection of datasets + */ + public Iterable getAvailableImages() { + return toSpecList(exec("dsadm avail")); + } - public Iterable getLocalDatasets() { - return toSpecList(exec("dsadm list")); - } + public Iterable getLocalDatasets() { + return toSpecList(exec("dsadm list")); + } - public Iterable getVMs() { - return toVMList(exec("vmadm list -p")); - } + public Iterable getVMs() { + return toVMList(exec("vmadm list -p")); + } - public VM createVM(VmSpecification specification) { + public VM createVM(VmSpecification specification) { - String response = getConnection().exec("(cat < toVMList(String string) { - try { - BufferedReader r = new BufferedReader(new StringReader(string)); - String line; - ImmutableList.Builder resultBuilder = ImmutableList.builder(); - while ((line = r.readLine()) != null) { - VM vm = VM.builder().host(this).fromVmadmString(line).build(); + private Iterable toVMList(String string) { + try { + BufferedReader r = new BufferedReader(new StringReader(string)); + String line; + ImmutableList.Builder resultBuilder = ImmutableList.builder(); + while ((line = r.readLine()) != null) { + VM vm = VM.builder().host(this).fromVmadmString(line).build(); - resultBuilder.add(vm); - } - return resultBuilder.build(); - } catch (IOException e) { - throw new HostException("Error parsing response when building VM list", e); - } - } + resultBuilder.add(vm); + } + return resultBuilder.build(); + } catch (IOException e) { + throw new HostException("Error parsing response when building VM list", e); + } + } - public VM getVM(UUID serverId) { - for (VM vm : getVMs()) - if (vm.uuid.equals(serverId)) - return vm; - return null; - } + public VM getVM(UUID serverId) { + for (VM vm : getVMs()) + if (vm.uuid.equals(serverId)) + return vm; + return null; + } - public DataSet getDataSet(UUID imageId) { - for (DataSet ds : getLocalDatasets()) { - if (ds.getUuid().equals(imageId)) - return ds; - } - return null; - } + public DataSet getDataSet(UUID imageId) { + for (DataSet ds : getLocalDatasets()) { + if (ds.getUuid().equals(imageId)) + return ds; + } + return null; + } - public void destroyHost(UUID uuid) { - exec("vmadm delete " + uuid.toString()); - } + public void destroyHost(UUID uuid) { + exec("vmadm delete " + uuid.toString()); + } - public void rebootHost(UUID uuid) { - exec("vmadm reboot " + uuid.toString()); - } + public void rebootHost(UUID uuid) { + exec("vmadm reboot " + uuid.toString()); + } - public void stopHost(UUID uuid) { - exec("vmadm stop -p"); - } + public void stopHost(UUID uuid) { + exec("vmadm stop -p"); + } - public void startHost(UUID uuid) { - exec("vmadm start " + uuid.toString()); - } + public void startHost(UUID uuid) { + exec("vmadm start " + uuid.toString()); + } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VM.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VM.java index ec9e6e9007..988fd230dd 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VM.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VM.java @@ -1,222 +1,205 @@ package org.jclouds.smartos.compute.domain; +import java.util.Map; +import java.util.UUID; + import com.google.common.base.Objects; import com.google.common.base.Optional; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; -import java.util.UUID; - /** * Representing a Virtual Machine (Zone / KVM ) **/ public class VM { - public enum State - { - RUNNING, - STOPPED, - INCOMPLETE - } + public enum State { + RUNNING, STOPPED, INCOMPLETE + } - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public Builder toBuilder() { - return builder().fromVM(this); - } + public Builder toBuilder() { + return builder().fromVM(this); + } - public static class Builder { + public static class Builder { - protected SmartOSHost host; - protected UUID uuid; - protected String type; - protected String ram; - protected State state = State.STOPPED; - protected String alias; + protected SmartOSHost host; + protected UUID uuid; + protected String type; + protected String ram; + protected State state = State.STOPPED; + protected String alias; - public Builder uuid(UUID uuid) { - this.uuid = uuid; - return this; - } + public Builder uuid(UUID uuid) { + this.uuid = uuid; + return this; + } - public Builder uuid(String uuid) { - this.uuid = UUID.fromString(uuid); - return this; - } + public Builder uuid(String uuid) { + this.uuid = UUID.fromString(uuid); + return this; + } - public Builder host(SmartOSHost host) { - this.host = host; - return this; - } + public Builder host(SmartOSHost host) { + this.host = host; + return this; + } - public Builder type(String type) { - this.type = type; - return this; - } + public Builder type(String type) { + this.type = type; + return this; + } - public Builder ram(String ram) { - this.ram = ram; - return this; - } + public Builder ram(String ram) { + this.ram = ram; + return this; + } - public Builder state(String state) { - this.state = State.valueOf(state.toUpperCase()); - return this; - } + public Builder state(String state) { + this.state = State.valueOf(state.toUpperCase()); + return this; + } - public Builder state(State state) { - this.state = state; - return this; - } + public Builder state(State state) { + this.state = state; + return this; + } - public Builder alias(String alias) { - this.alias = alias; - return this; - } + public Builder alias(String alias) { + this.alias = alias; + return this; + } - public Builder fromVmadmString(String string) { - String[] sections = string.split(":"); + public Builder fromVmadmString(String string) { + String[] sections = string.split(":"); - uuid(sections[0]); + uuid(sections[0]); - type(sections[1]); - ram(sections[2]); - state(sections[3]); + type(sections[1]); + ram(sections[2]); + state(sections[3]); - if (sections.length > 4) - alias(sections[4]); + if (sections.length > 4) + alias(sections[4]); - return this; - } + return this; + } + public VM build() { + return new VM(host, uuid, type, ram, state, alias); + } - public VM build() { - return new VM(host,uuid,type,ram,state,alias); - } + public Builder fromVM(VM in) { + return host(in.getHost()).uuid(in.getUuid()).type(in.getType()).ram(in.getRam()).state(in.getState()) + .alias(in.getAlias()); + } + } - public Builder fromVM(VM in) { - return host(in.getHost()) - .uuid(in.getUuid()) - .type(in.getType()) - .ram(in.getRam()) - .state(in.getState()) - .alias(in.getAlias()); - } - } + protected SmartOSHost host; + protected final UUID uuid; + protected String type; + protected String ram; + protected State state; + protected String alias; + public VM(SmartOSHost host, UUID uuid, String type, String ram, State state, String alias) { + this.host = host; + this.uuid = uuid; + this.type = type; + this.ram = ram; + this.state = state; + this.alias = alias; + } - protected SmartOSHost host; - protected final UUID uuid; - protected String type; - protected String ram; - protected State state; - protected String alias; + public State getState() { + return state; + } + public void destroy() { + host.destroyHost(uuid); + } - public VM(SmartOSHost host, UUID uuid, String type, String ram, State state, String alias) { - this.host = host; - this.uuid = uuid; - this.type = type; - this.ram = ram; - this.state = state; - this.alias = alias; - } + public void reboot() { + host.rebootHost(uuid); + } - public State getState() { - return state; - } + public void stop() { + host.stopHost(uuid); + } - public void destroy() { - host.destroyHost(uuid); - } + public void start() { + host.startHost(uuid); + } - public void reboot() { - host.rebootHost(uuid); - } + public Optional getPublicAddress() throws InterruptedException { + Map ipAddresses; - public void stop() { - host.stopHost(uuid); - } + for (int i = 0; i < 30; i++) { + ipAddresses = host.getVMIpAddresses(uuid); + if (ipAddresses.isEmpty()) { + // Got some + String ip = ipAddresses.get("net0"); + if (ip != null && !ip.equals("0.0.0.0")) + return Optional.of(ip); + } - public void start() { - host.startHost(uuid); - } + Thread.sleep(1000); + } - public Optional getPublicAddress() throws InterruptedException { - Map ipAddresses; + return Optional.absent(); + } - for( int i=0; i<30; i++ ) - { - ipAddresses = host.getVMIpAddresses(uuid); - if( ipAddresses.isEmpty() ) - { - // Got some - String ip = ipAddresses.get("net0"); - if( ip != null && !ip.equals("0.0.0.0")) - return Optional.of(ip); - } + public SmartOSHost getHost() { + return host; + } - Thread.sleep(1000); - } + public UUID getUuid() { + return uuid; + } - return Optional.absent(); - } + public String getType() { + return type; + } - public SmartOSHost getHost() { - return host; - } + public String getRam() { + return ram; + } - public UUID getUuid() { - return uuid; - } + public String getAlias() { + return alias; + } - public String getType() { - return type; - } + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + // UUID is primary key + return uuid.hashCode(); + } - public String getRam() { - return ram; - } + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return uuid.equals(((DataSet) obj).getUuid()); + } - public String getAlias() { - return alias; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - // UUID is primary key - return uuid.hashCode(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - return uuid.equals(((DataSet)obj).getUuid()); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("uuid", uuid) - .add("type", type) - .add("ram", ram) - .add("alias", alias).toString(); - } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("uuid", uuid).add("type", type).add("ram", ram) + .add("alias", alias).toString(); + } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmNIC.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmNIC.java index e8caa3a9bf..3a92064da6 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmNIC.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmNIC.java @@ -2,109 +2,97 @@ package org.jclouds.smartos.compute.domain; import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; -import com.google.inject.name.Named; - -import java.util.UUID; - /** * Specification of a network card. */ public class VmNIC { - @SerializedName("nic_tag") - protected final String tag; - protected final String ip; - protected final String netmask; - protected final String gateway; + @SerializedName("nic_tag") + protected final String tag; + protected final String ip; + protected final String netmask; + protected final String gateway; - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public Builder toBuilder() { - return builder().fromVmNIC(this); - } + public Builder toBuilder() { + return builder().fromVmNIC(this); + } - public static class Builder { + public static class Builder { - public String tag = "admin"; - public String ip; - public String netmask; - public String gateway; + public String tag = "admin"; + public String ip; + public String netmask; + public String gateway; + public Builder simpleDCHPNic() { + tag = "admin"; + ip = "dhcp"; + return this; + } - public Builder simpleDCHPNic() { - tag = "admin"; - ip = "dhcp"; - return this; - } + public Builder tag(String tag) { + this.tag = tag; + return this; + } - public Builder tag(String tag) { - this.tag = tag; - return this; - } + public Builder ip(String ip) { + this.ip = ip; + return this; + } - public Builder ip(String ip) { - this.ip = ip; - return this; - } + public Builder netmask(String netmask) { + this.netmask = netmask; + return this; + } - public Builder netmask(String netmask) { - this.netmask = netmask; - return this; - } + public Builder gateway(String gateway) { + this.gateway = gateway; + return this; + } - public Builder gateway(String gateway) { - this.gateway = gateway; - return this; - } + public VmNIC build() { + return new VmNIC(tag, ip, netmask, gateway); + } - public VmNIC build() { - return new VmNIC(tag,ip,netmask,gateway); - } + public Builder fromVmNIC(VmNIC in) { + return tag(in.getTag()).ip(in.getIp()).netmask(in.getNetmask()).gateway(in.getGateway()); + } + } - public Builder fromVmNIC(VmNIC in) { - return tag ( in.getTag()) - .ip ( in.getIp() ) - .netmask( in.getNetmask() ) - .gateway( in.getGateway() ); - } - } + public VmNIC(String tag, String ip, String netmask, String gateway) { + this.tag = tag; + this.ip = ip; + this.netmask = netmask; + this.gateway = gateway; + } + public String getTag() { + return tag; + } - public VmNIC(String tag, String ip, String netmask, String gateway) { - this.tag = tag; - this.ip = ip; - this.netmask = netmask; - this.gateway = gateway; - } + public String getIp() { + return ip; + } - public String getTag() { - return tag; - } + public String getNetmask() { + return netmask; + } - public String getIp() { - return ip; - } + public String getGateway() { + return gateway; + } - public String getNetmask() { - return netmask; - } - - public String getGateway() { - return gateway; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues() - .add("tag", tag) - .add("ip", ip) - .add("netmask", netmask) - .add("gateway", gateway).toString(); - } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("tag", tag).add("ip", ip).add("netmask", netmask) + .add("gateway", gateway).toString(); + } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmSpecification.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmSpecification.java index e793816fc7..977171408f 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmSpecification.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/domain/VmSpecification.java @@ -1,142 +1,142 @@ package org.jclouds.smartos.compute.domain; - -import com.google.common.collect.ImmutableList; -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; - import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import com.google.common.collect.ImmutableList; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.annotations.SerializedName; + /** * Specification of a VM to build, based on a dataset. */ public class VmSpecification { - protected final String alias; - protected final String brand; + protected final String alias; + protected final String brand; - @SerializedName("dataset_uuid") - protected final DataSet dataset; - protected final String dnsDomain; - protected final String quota; + @SerializedName("dataset_uuid") + protected final DataSet dataset; + protected final String dnsDomain; + protected final String quota; - protected final List nics; + protected final List nics; - public static Builder builder() { - return new Builder(); - } + public static Builder builder() { + return new Builder(); + } - public Builder toBuilder() { - return builder().fromVmSpecification(this); - } + public Builder toBuilder() { + return builder().fromVmSpecification(this); + } - public static class Builder { + public static class Builder { - protected String alias; - protected String brand = "joyent"; - protected DataSet dataset; - protected String dnsDomain = "local"; - protected String quota = "10"; + protected String alias; + protected String brand = "joyent"; + protected DataSet dataset; + protected String dnsDomain = "local"; + protected String quota = "10"; - protected List nics = new ArrayList(); + protected List nics = new ArrayList(); - public Builder alias(String alias) { - this.alias = alias; - return this; - } + public Builder alias(String alias) { + this.alias = alias; + return this; + } - public Builder brand(String brand) { - this.brand = brand; - return this; - } + public Builder brand(String brand) { + this.brand = brand; + return this; + } - public Builder dataset(DataSet dataset) { - this.dataset = dataset; - return this; - } + public Builder dataset(DataSet dataset) { + this.dataset = dataset; + return this; + } - public Builder dnsDomain(String dnsDomain) { - this.dnsDomain = dnsDomain; - return this; - } + public Builder dnsDomain(String dnsDomain) { + this.dnsDomain = dnsDomain; + return this; + } - public Builder quota(String quota) { - this.quota = quota; - return this; - } + public Builder quota(String quota) { + this.quota = quota; + return this; + } - public Builder nics(Collection nic) { - this.nics.addAll(nics); - return this; - } + public Builder nics(Collection nic) { + this.nics.addAll(nics); + return this; + } - public Builder nic(VmNIC nic) { - this.nics.add(nic); - return this; - } + public Builder nic(VmNIC nic) { + this.nics.add(nic); + return this; + } - public VmSpecification build() { - return new VmSpecification(alias, brand, dataset, dnsDomain, quota, nics); - } + public VmSpecification build() { + return new VmSpecification(alias, brand, dataset, dnsDomain, quota, nics); + } - public Builder fromVmSpecification(VmSpecification in) { - return alias (in.getAlias()) - .brand (in.getBrand()) - .dataset (in.getDataset()) - .dnsDomain(in.getDnsDomain()) - .quota (in.getQuota()) - .nics(in.getNics()); - } - } + public Builder fromVmSpecification(VmSpecification in) { + return alias(in.getAlias()).brand(in.getBrand()).dataset(in.getDataset()).dnsDomain(in.getDnsDomain()) + .quota(in.getQuota()).nics(in.getNics()); + } + } - protected VmSpecification(String alias, String brand, DataSet dataset, String dnsDomain, String quota, List nics) { - this.alias = alias; - this.brand = brand; - this.dataset = dataset; - this.dnsDomain = dnsDomain; - this.quota = quota; - this.nics = nics; - } + protected VmSpecification(String alias, String brand, DataSet dataset, String dnsDomain, String quota, + List nics) { + this.alias = alias; + this.brand = brand; + this.dataset = dataset; + this.dnsDomain = dnsDomain; + this.quota = quota; + this.nics = nics; + } - public String getAlias() { - return alias; - } + public String getAlias() { + return alias; + } - public String getBrand() { - return brand; - } + public String getBrand() { + return brand; + } - public DataSet getDataset() { - return dataset; - } + public DataSet getDataset() { + return dataset; + } - public String getDnsDomain() { - return dnsDomain; - } + public String getDnsDomain() { + return dnsDomain; + } - public String getQuota() { - return quota; - } + public String getQuota() { + return quota; + } - public List getNics() { - return ImmutableList.copyOf(nics); - } + public List getNics() { + return ImmutableList.copyOf(nics); + } - public String toJSONSpecification() { - GsonBuilder gson = new GsonBuilder(); - gson.registerTypeAdapter(DataSet.class, new FlattenDataset() ); - Gson g = gson.create(); + public String toJSONSpecification() { + GsonBuilder gson = new GsonBuilder(); + gson.registerTypeAdapter(DataSet.class, new FlattenDataset()); + Gson g = gson.create(); - return g.toJson(this); - } + return g.toJson(this); + } - public class FlattenDataset implements JsonSerializer - { - @Override - public JsonElement serialize(DataSet vmSpecification, Type type, JsonSerializationContext jsonSerializationContext) { - return new JsonPrimitive(dataset.getUuid().toString()); - } - } + public class FlattenDataset implements JsonSerializer { + @Override + public JsonElement serialize(DataSet vmSpecification, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(dataset.getUuid().toString()); + } + } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DataSetToImage.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DataSetToImage.java index ee90c86d89..df4b866382 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DataSetToImage.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DataSetToImage.java @@ -22,13 +22,13 @@ import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.smartos.compute.domain.DataSet; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.smartos.compute.domain.DataSet; import com.google.common.base.Function; @@ -53,7 +53,8 @@ public class DataSetToImage implements Function { OsFamily family; try { family = OsFamily.SOLARIS; - builder.operatingSystem(new OperatingSystem.Builder().name(from.getUrn()).description(from.getUrn()).family(family).build()); + builder.operatingSystem(new OperatingSystem.Builder().name(from.getUrn()).description(from.getUrn()) + .family(family).build()); } catch (IllegalArgumentException e) { logger.debug("<< didn't match os(%s)", from); } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DatacenterToLocation.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DatacenterToLocation.java index ea0984c7f8..b03709d90d 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DatacenterToLocation.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/DatacenterToLocation.java @@ -18,18 +18,19 @@ */ package org.jclouds.smartos.compute.functions; -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import org.jclouds.smartos.compute.domain.SmartOSHost; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; +import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; -import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.smartos.compute.domain.SmartOSHost; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; /** * @author Nigel Magnay @@ -46,8 +47,8 @@ public class DatacenterToLocation implements Function { @Override public Location apply(SmartOSHost from) { - return new LocationBuilder().scope(LocationScope.ZONE).id(from.getHostname() + "").description(from.getDescription()).parent( - provider.get().get()).build(); + return new LocationBuilder().scope(LocationScope.ZONE).id(from.getHostname() + "") + .description(from.getDescription()).parent(provider.get().get()).build(); } } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VMToNodeMetadata.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VMToNodeMetadata.java index 2780c2df1f..b32c32e783 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VMToNodeMetadata.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VMToNodeMetadata.java @@ -18,30 +18,31 @@ */ package org.jclouds.smartos.compute.functions; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.functions.GroupNamingConvention; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.smartos.compute.domain.VM; + import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.sun.corba.se.spi.activation.Server; -import org.jclouds.smartos.compute.domain.VM; -import org.jclouds.collect.FindResourceInSet; -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.*; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.Location; -import org.jclouds.domain.LoginCredentials; -import org.omg.PortableInterceptor.ACTIVE; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; /** * @author Nigel Magnay @@ -49,9 +50,8 @@ import static com.google.common.base.Preconditions.checkNotNull; @Singleton public class VMToNodeMetadata implements Function { - public static final Map serverStatusToNodeStatus = ImmutableMap - . builder() - .put(VM.State.RUNNING, NodeMetadata.Status.RUNNING)// + public static final Map serverStatusToNodeStatus = ImmutableMap + . builder().put(VM.State.RUNNING, NodeMetadata.Status.RUNNING)// .put(VM.State.STOPPED, NodeMetadata.Status.SUSPENDED)// .put(VM.State.INCOMPLETE, NodeMetadata.Status.PENDING)// .build(); @@ -64,8 +64,8 @@ public class VMToNodeMetadata implements Function { @Inject VMToNodeMetadata(Map credentialStore, FindHardwareForServer findHardwareForServer, - FindLocationForServer findLocationForServer, FindImageForServer findImageForServer, - GroupNamingConvention.Factory namingConvention) { + FindLocationForServer findLocationForServer, FindImageForServer findImageForServer, + GroupNamingConvention.Factory namingConvention) { this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix(); this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.findHardwareForServer = checkNotNull(findHardwareForServer, "findHardwareForServer"); @@ -87,21 +87,18 @@ public class VMToNodeMetadata implements Function { builder.operatingSystem(image.getOperatingSystem()); builder.hardware(findHardwareForServer.apply(from)); builder.status(serverStatusToNodeStatus.get(from.getState())); - try { - if( from.getState() == VM.State.RUNNING ) - { - Optional ip = from.getPublicAddress(); - if( ip.isPresent() ) { - builder.publicAddresses(ImmutableSet. of(ip.get())); - builder.privateAddresses(ImmutableSet. of(ip.get())); - } - } - } - catch(Exception ex) - { - // None? - } - //builder.privateAddresses(ImmutableSet. of(from.privateAddress)); + try { + if (from.getState() == VM.State.RUNNING) { + Optional ip = from.getPublicAddress(); + if (ip.isPresent()) { + builder.publicAddresses(ImmutableSet. of(ip.get())); + builder.privateAddresses(ImmutableSet. of(ip.get())); + } + } + } catch (Exception ex) { + // None? + } + // builder.privateAddresses(ImmutableSet. of(from.privateAddress)); builder.credentials(LoginCredentials.fromCredentials(credentialStore.get(from.getUuid() + ""))); return builder.build(); } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VmSpecificationToHardware.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VmSpecificationToHardware.java index e789367af1..d8121c0d1f 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VmSpecificationToHardware.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/functions/VmSpecificationToHardware.java @@ -20,10 +20,10 @@ package org.jclouds.smartos.compute.functions; import javax.inject.Singleton; -import org.jclouds.smartos.compute.domain.VmSpecification; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.Processor; +import org.jclouds.smartos.compute.domain.VmSpecification; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; @@ -41,7 +41,7 @@ public class VmSpecificationToHardware implements Function of(new VolumeImpl(from.disk, true, false))); + // builder.volumes(ImmutableList. of(new VolumeImpl(from.disk, true, false))); return builder.build(); } diff --git a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/strategy/SmartOSComputeServiceAdapter.java b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/strategy/SmartOSComputeServiceAdapter.java index 094ad8cffe..541620c627 100644 --- a/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/strategy/SmartOSComputeServiceAdapter.java +++ b/labs/smartos-ssh/src/main/java/org/jclouds/smartos/compute/strategy/SmartOSComputeServiceAdapter.java @@ -20,24 +20,28 @@ package org.jclouds.smartos.compute.strategy; import static com.google.common.base.Preconditions.checkNotNull; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.smartos.compute.domain.*; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.domain.Template; -import org.jclouds.domain.LoginCredentials; - -import com.google.common.collect.ImmutableSet; - import java.util.ArrayList; import java.util.List; import java.util.UUID; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.smartos.compute.domain.DataSet; +import org.jclouds.smartos.compute.domain.SmartOSHost; +import org.jclouds.smartos.compute.domain.VM; +import org.jclouds.smartos.compute.domain.VmNIC; +import org.jclouds.smartos.compute.domain.VmSpecification; + +import com.google.common.collect.ImmutableSet; + /** - * defines the connection between the {@link org.jclouds.smartos.compute.domain.SmartOSHost} implementation and the jclouds - * {@link ComputeService} + * defines the connection between the {@link org.jclouds.smartos.compute.domain.SmartOSHost} + * implementation and the jclouds {@link ComputeService} * */ @Singleton @@ -50,35 +54,31 @@ public class SmartOSComputeServiceAdapter implements ComputeServiceAdapter createNodeWithGroupEncodedIntoName(String tag, String name, Template template) { - VmSpecification specification = VmSpecification.builder() - .alias(name) + VmSpecification specification = VmSpecification.builder().alias(name) .dataset(getHost().getDataSet(UUID.fromString(template.getImage().getProviderId()))) - .nic(VmNIC.builder().simpleDCHPNic().build()) - .build(); + .nic(VmNIC.builder().simpleDCHPNic().build()).build(); - VM from = getHost().createVM(specification); + VM from = getHost().createVM(specification); - return new NodeAndInitialCredentials(from, from.getUuid() + "", LoginCredentials.builder().user("smartos") + return new NodeAndInitialCredentials(from, from.getUuid() + "", LoginCredentials.builder().user("smartos") .password("smartos").build()); } @Override public Iterable listHardwareProfiles() { - List specificationList = new ArrayList(); + List specificationList = new ArrayList(); - VmSpecification vs = VmSpecification.builder() - .alias("Standard Joyent VM") - .nic(VmNIC.builder().simpleDCHPNic().build()) - .build(); + VmSpecification vs = VmSpecification.builder().alias("Standard Joyent VM") + .nic(VmNIC.builder().simpleDCHPNic().build()).build(); - specificationList.add(vs); + specificationList.add(vs); - return specificationList; + return specificationList; } @Override @@ -88,17 +88,17 @@ public class SmartOSComputeServiceAdapter implements ComputeServiceAdapter listNodes() { return getHost().getVMs(); } - + @Override public Iterable listLocations() { - return ImmutableSet.of(); + return ImmutableSet.of(); } @Override @@ -108,21 +108,21 @@ public class SmartOSComputeServiceAdapter implements ComputeServiceAdapterof(getSshModule())) - .build(ComputeServiceContext.class); + ComputeServiceContext context = ContextBuilder.newBuilder(new SmartOSApiMetadata()) + .modules(ImmutableSet. of(getSshModule())).build(ComputeServiceContext.class); context.close(); } @Test public void testCanBuildById() { ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh") - .modules(ImmutableSet.of(getSshModule())) - .build(ComputeServiceContext.class); + .modules(ImmutableSet. of(getSshModule())).build(ComputeServiceContext.class); context.close(); } @@ -65,8 +61,8 @@ public class SmartOSManagerComputeServiceContextBuilderTest { overrides.setProperty("smartos-ssh.api-version", "1"); ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh") - .modules(ImmutableSet.of(getSshModule())) - .overrides(overrides).build(ComputeServiceContext.class); + .modules(ImmutableSet. of(getSshModule())).overrides(overrides) + .build(ComputeServiceContext.class); context.close(); } @@ -74,15 +70,14 @@ public class SmartOSManagerComputeServiceContextBuilderTest { @Test public void testUnwrapIsCorrectType() { ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh") - .modules(ImmutableSet.of(getSshModule())) - .build(ComputeServiceContext.class); + .modules(ImmutableSet. of(getSshModule())).build(ComputeServiceContext.class); assertEquals(context.unwrap().getClass(), ContextImpl.class); context.close(); } - protected Module getSshModule() { - return new SshjSshClientModule(); - } + protected Module getSshModule() { + return new SshjSshClientModule(); + } } diff --git a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java index df29de6968..8cbc3377e0 100644 --- a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java +++ b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java @@ -49,12 +49,11 @@ public class SmartOSManagerComputeServiceLiveTest extends BaseComputeServiceLive assertEquals(getCores(defaultTemplate.getHardware()), 0.5d); } - // smartos-ssh does not support metadata @Override protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); + "node userMetadata did not match %s %s", userMetadata, node); } - + } diff --git a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/DataSetTest.java b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/DataSetTest.java index a64e92ca5a..6699c6bf9c 100644 --- a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/DataSetTest.java +++ b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/DataSetTest.java @@ -1,36 +1,39 @@ package org.jclouds.smartos.compute.domain; -import com.google.common.collect.ImmutableList; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; +import java.util.UUID; + import org.testng.Assert; import org.testng.annotations.Test; -import java.io.*; -import java.util.List; -import java.util.UUID; +import com.google.common.collect.ImmutableList; @Test(groups = "unit", testName = "DataSetTest") public class DataSetTest { - @Test - public void testParse() throws IOException { - // Response from console from a 'dsadm list' - InputStream is = getClass().getResourceAsStream("dsadm-list-response.txt"); + @Test + public void testParse() throws IOException { + // Response from console from a 'dsadm list' + InputStream is = getClass().getResourceAsStream("dsadm-list-response.txt"); - BufferedReader r = new BufferedReader(new InputStreamReader(is)); - String line = r.readLine(); // skip line - ImmutableList.Builder resultBuilder = ImmutableList.builder(); - while ((line = r.readLine()) != null) { - DataSet ds = DataSet.builder().fromDsadmString(line).build(); + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + String line = r.readLine(); // skip line + ImmutableList.Builder resultBuilder = ImmutableList.builder(); + while ((line = r.readLine()) != null) { + DataSet ds = DataSet.builder().fromDsadmString(line).build(); - resultBuilder.add(ds); - } - List dataSetList = resultBuilder.build(); + resultBuilder.add(ds); + } + List dataSetList = resultBuilder.build(); - Assert.assertEquals(10, dataSetList.size()); + Assert.assertEquals(10, dataSetList.size()); - Assert.assertEquals(UUID.fromString("c0ffee88-883e-47cf-80d1-ad71cc872180"), dataSetList.get(0).getUuid()); - Assert.assertEquals("nrm:nrm:realtime-jenkins:1.7", dataSetList.get(0).getUrn()); + Assert.assertEquals(UUID.fromString("c0ffee88-883e-47cf-80d1-ad71cc872180"), dataSetList.get(0).getUuid()); + Assert.assertEquals("nrm:nrm:realtime-jenkins:1.7", dataSetList.get(0).getUrn()); - - } + } } diff --git a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/VMTest.java b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/VMTest.java index 3397c48b39..5cfa06a5da 100644 --- a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/VMTest.java +++ b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/domain/VMTest.java @@ -1,9 +1,5 @@ package org.jclouds.smartos.compute.domain; -import com.google.common.collect.ImmutableList; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -11,28 +7,33 @@ import java.io.InputStreamReader; import java.util.List; import java.util.UUID; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + @Test(groups = "unit", testName = "VMTest") public class VMTest { - @Test - public void testParse() throws IOException { - // Response from console from a 'vmadm list -p' - InputStream is = getClass().getResourceAsStream("vmadm-list-response.txt"); + @Test + public void testParse() throws IOException { + // Response from console from a 'vmadm list -p' + InputStream is = getClass().getResourceAsStream("vmadm-list-response.txt"); - BufferedReader r = new BufferedReader(new InputStreamReader(is)); - String line = null; - ImmutableList.Builder resultBuilder = ImmutableList.builder(); - while ((line = r.readLine()) != null) { - VM vm = VM.builder().fromVmadmString(line).build(); + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + String line = null; + ImmutableList.Builder resultBuilder = ImmutableList.builder(); + while ((line = r.readLine()) != null) { + VM vm = VM.builder().fromVmadmString(line).build(); - resultBuilder.add(vm); - } - List vmList = resultBuilder.build(); + resultBuilder.add(vm); + } + List vmList = resultBuilder.build(); - Assert.assertEquals(2, vmList.size()); + Assert.assertEquals(2, vmList.size()); - Assert.assertEquals(UUID.fromString("60bd2ae5-4e4d-4952-88f9-1b850259d914"), vmList.get(0).getUuid()); - Assert.assertEquals(VM.State.STOPPED, vmList.get(0).getState()); + Assert.assertEquals(UUID.fromString("60bd2ae5-4e4d-4952-88f9-1b850259d914"), vmList.get(0).getUuid()); + Assert.assertEquals(VM.State.STOPPED, vmList.get(0).getState()); - } + } } \ No newline at end of file