mirror of https://github.com/apache/jclouds.git
fix issue #1264 parse smartos in joyent
This commit is contained in:
parent
e5336187da
commit
d9f11821b2
|
@ -20,7 +20,7 @@ package org.jclouds.compute.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import static com.google.common.base.CaseFormat.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Running Operating system
|
* Running Operating system
|
||||||
|
@ -30,6 +30,10 @@ import com.google.common.base.CaseFormat;
|
||||||
*/
|
*/
|
||||||
public enum OsFamily {
|
public enum OsFamily {
|
||||||
UNRECOGNIZED, AIX, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX,
|
UNRECOGNIZED, AIX, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX,
|
||||||
|
/**
|
||||||
|
* @see <a href="http://smartos.org">SmartOS</a>
|
||||||
|
*/
|
||||||
|
SMARTOS,
|
||||||
/**
|
/**
|
||||||
* @see <a href="http://aws.amazon.com/amazon-linux-ami/">amazon linux ami</a>
|
* @see <a href="http://aws.amazon.com/amazon-linux-ami/">amazon linux ami</a>
|
||||||
*/
|
*/
|
||||||
|
@ -46,12 +50,10 @@ public enum OsFamily {
|
||||||
/**
|
/**
|
||||||
* Google Compute Engine Linux
|
* Google Compute Engine Linux
|
||||||
*/
|
*/
|
||||||
GCEL,
|
GCEL, SIGAR, SLACKWARE, SOLARIS, SUSE, TURBOLINUX, CLOUD_LINUX, UBUNTU, WINDOWS;
|
||||||
SIGAR,
|
|
||||||
SLACKWARE,
|
|
||||||
SOLARIS, SUSE, TURBOLINUX, CLOUD_LINUX, UBUNTU, WINDOWS;
|
|
||||||
public String value() {
|
public String value() {
|
||||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
return UPPER_UNDERSCORE.to(LOWER_HYPHEN, name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,7 +63,7 @@ public enum OsFamily {
|
||||||
|
|
||||||
public static OsFamily fromValue(String osFamily) {
|
public static OsFamily fromValue(String osFamily) {
|
||||||
try {
|
try {
|
||||||
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(osFamily, "osFamily")));
|
return valueOf(LOWER_HYPHEN.to(UPPER_UNDERSCORE, checkNotNull(osFamily, "osFamily")));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return UNRECOGNIZED;
|
return UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,39 +18,30 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.joyent.cloudapi.v6_5.compute.functions;
|
package org.jclouds.joyent.cloudapi.v6_5.compute.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.compute.domain.OsFamily.UNRECOGNIZED;
|
||||||
|
import static org.jclouds.compute.domain.OsFamily.fromValue;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.domain.OperatingSystem.Builder;
|
import org.jclouds.compute.domain.OperatingSystem.Builder;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
|
||||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
|
||||||
import org.jclouds.joyent.cloudapi.v6_5.domain.Dataset;
|
import org.jclouds.joyent.cloudapi.v6_5.domain.Dataset;
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function for transforming a cloudApi specific Dataset into a generic
|
* A function for transforming a cloudApi specific Dataset into a generic OperatingSystem object.
|
||||||
* OperatingSystem object.
|
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class DatasetToOperatingSystem implements Function<Dataset, OperatingSystem> {
|
public class DatasetToOperatingSystem implements Function<Dataset, OperatingSystem> {
|
||||||
public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
|
|
||||||
// Windows Machine 2008 R2 x64
|
|
||||||
public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
|
|
||||||
|
|
||||||
@javax.annotation.Resource
|
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
private final Map<OsFamily, Map<String, String>> osVersionMap;
|
private final Map<OsFamily, Map<String, String>> osVersionMap;
|
||||||
|
|
||||||
|
@ -63,20 +54,24 @@ public class DatasetToOperatingSystem implements Function<Dataset, OperatingSyst
|
||||||
Builder builder = OperatingSystem.builder();
|
Builder builder = OperatingSystem.builder();
|
||||||
builder.name(from.getName());
|
builder.name(from.getName());
|
||||||
builder.description(from.getUrn());
|
builder.description(from.getUrn());
|
||||||
builder.is64Bit(true);//TODO: verify
|
builder.is64Bit(true);// TODO: verify
|
||||||
|
OsFamily family = UNRECOGNIZED;
|
||||||
|
String version = "";
|
||||||
List<String> pieces = ImmutableList.copyOf(Splitter.on(':').split(from.getUrn()));
|
List<String> pieces = ImmutableList.copyOf(Splitter.on(':').split(from.getUrn()));
|
||||||
if (pieces.get(2).indexOf('-') != -1) {
|
if (pieces.get(2).indexOf('-') != -1) {
|
||||||
List<String> osFamVersion = ImmutableList.copyOf(Splitter.on('-').split(pieces.get(2)));
|
List<String> osFamVersion = ImmutableList.copyOf(Splitter.on('-').split(pieces.get(2)));
|
||||||
OsFamily family = OsFamily.fromValue(osFamVersion.get(0));
|
family = fromValue(osFamVersion.get(0));
|
||||||
builder.family(family);
|
if (family != UNRECOGNIZED)
|
||||||
if (family != OsFamily.UNRECOGNIZED)
|
version = osFamVersion.get(1);
|
||||||
builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, osFamVersion.get(1),
|
|
||||||
osVersionMap));
|
|
||||||
} else {
|
} else {
|
||||||
builder.family(OsFamily.fromValue(pieces.get(2)));
|
family = fromValue(pieces.get(2));
|
||||||
}
|
}
|
||||||
|
builder.family(family);
|
||||||
|
if (family != UNRECOGNIZED)
|
||||||
|
version = parseVersionOrReturnEmptyString(family, version, osVersionMap);
|
||||||
|
if ("".equals(version))
|
||||||
|
version = from.getVersion();
|
||||||
|
builder.version(version);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.joyent.joyentcloud;
|
package org.jclouds.joyent.joyentcloud;
|
||||||
|
|
||||||
|
import static com.google.common.base.Predicates.not;
|
||||||
|
import static org.jclouds.compute.domain.OsFamily.SMARTOS;
|
||||||
|
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
|
||||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
|
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,13 +47,14 @@ public class JoyentCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveT
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
|
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
|
||||||
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
|
return not(new Predicate<OsFamilyVersion64Bit>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(OsFamilyVersion64Bit input) {
|
public boolean apply(OsFamilyVersion64Bit input) {
|
||||||
switch (input.family) {
|
switch (input.family) {
|
||||||
case UBUNTU:
|
case UBUNTU:
|
||||||
return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit;
|
return (input.version.equals("") || input.version.equals("10.04") || input.version.equals("12.04"))
|
||||||
|
&& input.is64Bit;
|
||||||
case DEBIAN:
|
case DEBIAN:
|
||||||
return input.is64Bit && !input.version.equals("5.0");
|
return input.is64Bit && !input.version.equals("5.0");
|
||||||
case CENTOS:
|
case CENTOS:
|
||||||
|
@ -66,12 +69,26 @@ public class JoyentCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateBuilder() {
|
public void testTemplateBuilderSmartOS() throws IOException {
|
||||||
|
Template smartTemplate = view.getComputeService().templateBuilder().osFamily(SMARTOS).build();
|
||||||
|
assertEquals(smartTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||||
|
assertEquals(smartTemplate.getImage().getOperatingSystem().getVersion(), "1.6.3");
|
||||||
|
assertEquals(smartTemplate.getImage().getOperatingSystem().getFamily(), SMARTOS);
|
||||||
|
assertEquals(smartTemplate.getImage().getName(), "smartos");
|
||||||
|
assertEquals(smartTemplate.getImage().getDefaultCredentials().getUser(), "root");
|
||||||
|
assertEquals(smartTemplate.getLocation().getId(), "us-east-1");
|
||||||
|
assertEquals(smartTemplate.getImage().getLocation().getId(), "us-east-1");
|
||||||
|
assertEquals(smartTemplate.getHardware().getLocation().getId(), "us-east-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testDefaultTemplateBuilder() {
|
||||||
Template defaultTemplate = this.view.getComputeService().templateBuilder().build();
|
Template defaultTemplate = this.view.getComputeService().templateBuilder().build();
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "12.04");
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), UBUNTU);
|
||||||
assertEquals(defaultTemplate.getImage().getName(), "ubuntu-10.04");
|
assertEquals(defaultTemplate.getImage().getName(), "ubuntu-12.04");
|
||||||
assertEquals(defaultTemplate.getImage().getDefaultCredentials().getUser(), "root");
|
assertEquals(defaultTemplate.getImage().getDefaultCredentials().getUser(), "root");
|
||||||
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
|
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
|
||||||
assertEquals(defaultTemplate.getImage().getLocation().getId(), "us-east-1");
|
assertEquals(defaultTemplate.getImage().getLocation().getId(), "us-east-1");
|
||||||
|
|
Loading…
Reference in New Issue