added compute service adapter for joyent

This commit is contained in:
Adrian Cole 2012-06-13 23:52:57 -04:00
parent 4eef8fcfaf
commit db086697aa
34 changed files with 1594 additions and 82 deletions

View File

@ -50,9 +50,16 @@
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
@ -66,6 +73,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>

View File

@ -22,6 +22,8 @@ import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.joyent.sdc.v6_5.compute.config.SDCComputeServiceContextModule;
import org.jclouds.joyent.sdc.v6_5.config.DatacentersAreZonesModule;
import org.jclouds.joyent.sdc.v6_5.config.SDCRestClientModule;
import org.jclouds.rest.RestContext;
@ -75,7 +77,8 @@ public class SDCApiMetadata extends BaseRestApiMetadata {
.version("~6.5")
.defaultEndpoint("https://api.joyentcloud.com")
.defaultProperties(SDCApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>> of(DatacentersAreZonesModule.class, SDCRestClientModule.class));
.view(TypeToken.of(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>> of(DatacentersAreZonesModule.class, SDCRestClientModule.class, SDCComputeServiceContextModule.class));
}
@Override

View File

@ -0,0 +1,200 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.joyent.sdc.v6_5.SDCClient;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatacenterAndId;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
import org.jclouds.joyent.sdc.v6_5.options.CreateMachineOptions;
import org.jclouds.location.Zone;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
* The adapter used by the SDCComputeServiceContextModule to interface the
* SDC-specific domain model to the computeService generic domain model.
*
* @author Adrian Cole
*/
public class SDCComputeServiceAdapter implements
ComputeServiceAdapter<MachineInDatacenter, PackageInDatacenter, DatasetInDatacenter, Location> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final SDCClient sdcClient;
protected final Supplier<Set<String>> datacenterIds;
@Inject
public SDCComputeServiceAdapter(SDCClient sdcClient, @Zone Supplier<Set<String>> datacenterIds) {
this.sdcClient = checkNotNull(sdcClient, "sdcClient");
this.datacenterIds = checkNotNull(datacenterIds, "datacenterIds");
}
@Override
public NodeAndInitialCredentials<MachineInDatacenter> createNodeWithGroupEncodedIntoName(String group, String name,
Template template) {
LoginCredentials.Builder credentialsBuilder = LoginCredentials.builder();
CreateMachineOptions options = new CreateMachineOptions();
// TODO: assign template.getOptions.metadata/tags
String datacenterId = template.getLocation().getId();
String datasetId = template.getImage().getProviderId();
String packageId = template.getHardware().getProviderId();
logger.debug(">> creating new machine datacenter(%s) name(%s) package(%s) dataset(%s) options(%s)", datacenterId,
name, packageId, datasetId, options);
Machine machine = sdcClient.getMachineClientForDatacenter(datacenterId).createMachine(name, packageId, datasetId,
options);
logger.trace("<< machine(%s)", machine.getId());
MachineInDatacenter machineInDatacenter = new MachineInDatacenter(machine, datacenterId);
// TODO: credentials or password
// if (!privateKey.isPresent())
// credentialsBuilder.password(lightweightMachine.getAdminPass());
return new NodeAndInitialCredentials<MachineInDatacenter>(machineInDatacenter, machineInDatacenter.slashEncode(),
credentialsBuilder.build());
}
@Override
public Iterable<PackageInDatacenter> listHardwareProfiles() {
Builder<PackageInDatacenter> builder = ImmutableSet.builder();
for (final String datacenterId : datacenterIds.get()) {
builder.addAll(transform(sdcClient.getPackageClientForDatacenter(datacenterId).listPackages(),
new Function<org.jclouds.joyent.sdc.v6_5.domain.Package, PackageInDatacenter>() {
@Override
public PackageInDatacenter apply(org.jclouds.joyent.sdc.v6_5.domain.Package arg0) {
return new PackageInDatacenter(arg0, datacenterId);
}
}));
}
return builder.build();
}
@Override
public Iterable<DatasetInDatacenter> listImages() {
Builder<DatasetInDatacenter> builder = ImmutableSet.builder();
for (final String datacenterId : datacenterIds.get()) {
builder.addAll(transform(sdcClient.getDatasetClientForDatacenter(datacenterId).listDatasets(),
new Function<Dataset, DatasetInDatacenter>() {
@Override
public DatasetInDatacenter apply(Dataset arg0) {
return new DatasetInDatacenter(arg0, datacenterId);
}
}));
}
return builder.build();
}
@Override
public Iterable<MachineInDatacenter> listNodes() {
Builder<MachineInDatacenter> builder = ImmutableSet.builder();
for (final String datacenterId : datacenterIds.get()) {
builder.addAll(transform(sdcClient.getMachineClientForDatacenter(datacenterId).listMachines(),
new Function<Machine, MachineInDatacenter>() {
@Override
public MachineInDatacenter apply(Machine arg0) {
return new MachineInDatacenter(arg0, datacenterId);
}
}));
}
return builder.build();
}
@Override
public Iterable<Location> listLocations() {
// locations provided by guice
return ImmutableSet.of();
}
@Override
public MachineInDatacenter getNode(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
Machine machine = sdcClient.getMachineClientForDatacenter(datacenterAndId.getDatacenter()).getMachine(
datacenterAndId.getId());
return machine == null ? null : new MachineInDatacenter(machine, datacenterAndId.getDatacenter());
}
@Override
public DatasetInDatacenter getImage(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
Dataset dataset = sdcClient.getDatasetClientForDatacenter(datacenterAndId.getDatacenter()).getDataset(
datacenterAndId.getId());
return dataset == null ? null : new DatasetInDatacenter(dataset, datacenterAndId.getDatacenter());
}
@Override
public void destroyNode(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
sdcClient.getMachineClientForDatacenter(datacenterAndId.getDatacenter()).deleteMachine(datacenterAndId.getId());
}
@Override
public void rebootNode(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
sdcClient.getMachineClientForDatacenter(datacenterAndId.getDatacenter()).rebootMachine(datacenterAndId.getId());
}
@Override
public void resumeNode(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
sdcClient.getMachineClientForDatacenter(datacenterAndId.getDatacenter()).stopMachine(datacenterAndId.getId());
}
@Override
public void suspendNode(String id) {
DatacenterAndId datacenterAndId = DatacenterAndId.fromSlashEncoded(id);
sdcClient.getMachineClientForDatacenter(datacenterAndId.getDatacenter()).startMachine(datacenterAndId.getId());
}
}

View File

@ -0,0 +1,123 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.config;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.joyent.sdc.v6_5.compute.SDCComputeServiceAdapter;
import org.jclouds.joyent.sdc.v6_5.compute.functions.DatasetInDatacenterToImage;
import org.jclouds.joyent.sdc.v6_5.compute.functions.DatasetToOperatingSystem;
import org.jclouds.joyent.sdc.v6_5.compute.functions.MachineInDatacenterToNodeMetadata;
import org.jclouds.joyent.sdc.v6_5.compute.functions.PackageInDatacenterToHardware;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
import org.jclouds.util.Iterables2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Module for building a compute service context for SDC
*
* @author Adrian Cole
*/
public class SDCComputeServiceContextModule extends
ComputeServiceAdapterContextModule<MachineInDatacenter, PackageInDatacenter, DatasetInDatacenter, Location> {
@SuppressWarnings("unchecked")
@Override
protected void configure() {
super.configure();
bind(
new TypeLiteral<ComputeServiceAdapter<MachineInDatacenter, PackageInDatacenter, DatasetInDatacenter, Location>>() {
}).to(SDCComputeServiceAdapter.class);
bind(new TypeLiteral<Function<MachineInDatacenter, NodeMetadata>>() {
}).to(MachineInDatacenterToNodeMetadata.class);
bind(new TypeLiteral<Function<DatasetInDatacenter, Image>>() {
}).to(DatasetInDatacenterToImage.class);
bind(new TypeLiteral<Function<Dataset, OperatingSystem>>() {
}).to(DatasetToOperatingSystem.class);
bind(new TypeLiteral<Function<PackageInDatacenter, Hardware>>() {
}).to(PackageInDatacenterToHardware.class);
// we aren't converting location from a provider-specific type
bind(new TypeLiteral<Function<Location, Location>>() {
}).to((Class) IdentityFunction.class);
}
@Provides
@Singleton
protected Supplier<Map<String, Location>> createLocationIndexedById(
@Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
@Override
public Map<String, Location> apply(Set<? extends Location> arg0) {
return Maps.uniqueIndex(Iterables2.concreteCopy(arg0), new Function<Location, String>() {
@Override
public String apply(Location arg0) {
return arg0.getId();
}
});
}
}, locations);
}
@VisibleForTesting
public static final Map<Machine.State, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<Machine.State, NodeMetadata.Status> builder()
.put(Machine.State.RUNNING, NodeMetadata.Status.RUNNING)
.put(Machine.State.STOPPED, NodeMetadata.Status.SUSPENDED)
.put(Machine.State.PUBLISHING, NodeMetadata.Status.PENDING)
.put(Machine.State.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build();
@Singleton
@Provides
protected Map<Machine.State, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
}

View File

@ -0,0 +1,64 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.domain.Location;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* A function for transforming a sdc-specific Image into a generic Image object.
*
* @author Adrian Cole
*/
public class DatasetInDatacenterToImage implements Function<DatasetInDatacenter, Image> {
private final Function<Dataset, OperatingSystem> imageToOs;
private final Supplier<Map<String, Location>> locationIndex;
@Inject
public DatasetInDatacenterToImage(Function<Dataset, OperatingSystem> imageToOs,
Supplier<Map<String, Location>> locationIndex) {
this.imageToOs = checkNotNull(imageToOs, "imageToOs");
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
}
@Override
public Image apply(DatasetInDatacenter datasetInDatacenter) {
Location location = locationIndex.get().get(datasetInDatacenter.getDatacenter());
checkState(location != null, "location %s not in locationIndex: %s", datasetInDatacenter.getDatacenter(),
locationIndex.get());
Dataset image = datasetInDatacenter.getDataset();
return new ImageBuilder().id(datasetInDatacenter.slashEncode()).providerId(image.getId()).name(image.getName())
.operatingSystem(imageToOs.apply(image)).description(image.getName()).location(location)
.status(Image.Status.AVAILABLE).build();
}
}

View File

@ -0,0 +1,82 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OperatingSystem.Builder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
/**
* A function for transforming a sdc specific Dataset into a generic
* OperatingSystem object.
*
* @author Adrian Cole
*/
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;
@Inject
public DatasetToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(Dataset from) {
Builder builder = OperatingSystem.builder();
builder.name(from.getName());
builder.description(from.getUrn());
builder.is64Bit(true);//TODO: verify
List<String> pieces = ImmutableList.copyOf(Splitter.on(':').split(from.getUrn()));
if (pieces.get(2).indexOf('-') != -1) {
List<String> osFamVersion = ImmutableList.copyOf(Splitter.on('-').split(pieces.get(2)));
OsFamily family = OsFamily.fromValue(osFamVersion.get(0));
builder.family(family);
if (family != OsFamily.UNRECOGNIZED)
builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, osFamVersion.get(1),
osVersionMap));
} else {
builder.family(OsFamily.fromValue(pieces.get(2)));
}
return builder.build();
}
}

View File

@ -0,0 +1,138 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.tryFind;
import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.ComputeMetadata;
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.domain.OperatingSystem;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatacenterAndId;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatacenterAndName;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
import org.jclouds.logging.Logger;
import org.jclouds.util.InetAddresses2;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
/**
* A function for transforming a sdc-specific Machine into a generic
* NodeMetadata object.
*
* @author Adrian Cole
*/
public class MachineInDatacenterToNodeMetadata implements Function<MachineInDatacenter, NodeMetadata> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected Map<Machine.State, org.jclouds.compute.domain.NodeMetadata.Status> toPortableNodeStatus;
protected final Supplier<Map<String, Location>> locationIndex;
protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Hardware>> hardwares;
protected final GroupNamingConvention nodeNamingConvention;
@Inject
public MachineInDatacenterToNodeMetadata(Map<Machine.State, NodeMetadata.Status> toPortableNodeStatus,
Supplier<Map<String, Location>> locationIndex, @Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwares, GroupNamingConvention.Factory namingConvention) {
this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus");
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
this.images = checkNotNull(images, "images");
this.hardwares = checkNotNull(hardwares, "hardwares");
}
@Override
public NodeMetadata apply(MachineInDatacenter machineInDatacenter) {
Location zone = locationIndex.get().get(machineInDatacenter.getDatacenter());
checkState(zone != null, "location %s not in locationIndex: %s", machineInDatacenter.getDatacenter(),
locationIndex.get());
Machine from = machineInDatacenter.getMachine();
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.id(machineInDatacenter.slashEncode());
builder.providerId(from.getId());
builder.name(from.getName());
builder.hostname(from.getName());
builder.location(zone);
addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
builder.imageId(DatacenterAndName.fromDatacenterAndName(machineInDatacenter.getDatacenter(), from.getDataset())
.slashEncode());
builder.operatingSystem(findOperatingSystemForMachineOrNull(machineInDatacenter));
builder.hardware(findHardwareForMachineOrNull(machineInDatacenter));
builder.status(toPortableNodeStatus.get(from.getState()));
builder.publicAddresses(filter(from.getIps(), Predicates.not(InetAddresses2.IsPrivateIPAddress.INSTANCE)));
builder.privateAddresses(filter(from.getIps(), InetAddresses2.IsPrivateIPAddress.INSTANCE));
return builder.build();
}
protected Hardware findHardwareForMachineOrNull(final MachineInDatacenter machineInDatacenter) {
return tryFind(hardwares.get(), new Predicate<Hardware>() {
@Override
public boolean apply(Hardware input) {
return input.getRam() == machineInDatacenter.getMachine().getMemorySizeMb()
&& getSpace(input) == machineInDatacenter.getMachine().getDiskSizeGb()
&& input.getLocation().getId().equals(machineInDatacenter.getDatacenter());
}
}).orNull();
}
protected OperatingSystem findOperatingSystemForMachineOrNull(MachineInDatacenter machineInDatacenter) {
Image image = findObjectOfTypeForMachineOrNull(images.get(), "image", machineInDatacenter.getMachine()
.getDataset(), machineInDatacenter);
return (image != null) ? image.getOperatingSystem() : null;
}
public <T extends ComputeMetadata> T findObjectOfTypeForMachineOrNull(Set<? extends T> supply, String type,
final String objectId, final DatacenterAndId machineInDatacenter) {
return tryFind(supply, new Predicate<T>() {
@Override
public boolean apply(T input) {
return input.getId().equals(
DatacenterAndId.fromDatacenterAndId(machineInDatacenter.getDatacenter(), objectId).slashEncode());
}
}).orNull();
}
}

View File

@ -0,0 +1,66 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.domain.Location;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* A function for transforming the sdc specific PackageInDatacenter object to
* the generic Hardware object.
*
* @author Adrian Cole
*/
public class PackageInDatacenterToHardware implements Function<PackageInDatacenter, Hardware> {
private final Supplier<Map<String, Location>> locationIndex;
@Inject
public PackageInDatacenterToHardware(Supplier<Map<String, Location>> locationIndex) {
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
}
@Override
public Hardware apply(PackageInDatacenter pkgInDatacenter) {
Location location = locationIndex.get().get(pkgInDatacenter.getDatacenter());
checkState(location != null, "location %s not in locationIndex: %s", pkgInDatacenter.getDatacenter(),
locationIndex.get());
org.jclouds.joyent.sdc.v6_5.domain.Package pkg = pkgInDatacenter.getPackage();
return new HardwareBuilder().id(pkgInDatacenter.slashEncode()).providerId(pkg.getName()).name(pkg.getName())
.ram(pkg.getMemorySizeMb())
// TODO: no api call to get processors.. either hard-code or
// calculate
.processor(new Processor(1, 1.0)).volume(new VolumeImpl(Float.valueOf(pkg.getDiskSizeGb()), true, true))
.location(location).build();
}
}

View File

@ -38,7 +38,7 @@ public class SDCParserModule extends AbstractModule {
@Provides
@Singleton
public Map<Type, Object> provideCustomAdapterBindings() {
return ImmutableMap.<Type, Object> of(Machine.State.class, new SDCTypeAdapters.ServerStateAdapter(), Type.class,
return ImmutableMap.<Type, Object> of(Machine.State.class, new SDCTypeAdapters.MachineStateAdapter(), Type.class,
new SDCTypeAdapters.SDCTypeAdapter());
}

View File

@ -0,0 +1,88 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.domain.datacenterscoped;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
public class DatacenterAndId {
public static DatacenterAndId fromSlashEncoded(String id) {
Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
checkArgument(Iterables.size(parts) == 2, "id must be in format datacenterId/id");
return new DatacenterAndId(Iterables.get(parts, 0), Iterables.get(parts, 1));
}
public static DatacenterAndId fromDatacenterAndId(String datacenterId, String id) {
return new DatacenterAndId(datacenterId, id);
}
private static String slashEncodeDatacenterAndId(String datacenterId, String id) {
return checkNotNull(datacenterId, "datacenterId") + "/" + checkNotNull(id, "id");
}
public String slashEncode() {
return slashEncodeDatacenterAndId(datacenterId, id);
}
protected final String datacenterId;
protected final String id;
protected DatacenterAndId(String datacenterId, String id) {
this.datacenterId = checkNotNull(datacenterId, "datacenterId");
this.id = checkNotNull(id, "id");
}
@Override
public int hashCode() {
return Objects.hashCode(datacenterId, id);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DatacenterAndId other = (DatacenterAndId) obj;
return Objects.equal(datacenterId, other.datacenterId) && Objects.equal(id, other.id);
}
public String getDatacenter() {
return datacenterId;
}
public String getId() {
return id;
}
@Override
public String toString() {
return "[datacenterId=" + datacenterId + ", id=" + id + "]";
}
}

View File

@ -0,0 +1,113 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.domain.datacenterscoped;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
/**
* Helpful when looking for resources by datacenter and name
*
* @author Adrian Cole
*/
public class DatacenterAndName {
public final static Function<DatacenterAndName, String> NAME_FUNCTION = new Function<DatacenterAndName, String>(){
@Override
public String apply(DatacenterAndName input) {
return input.getName();
}
};
public final static Function<DatacenterAndName, String> ZONE_FUNCTION = new Function<DatacenterAndName, String>(){
@Override
public String apply(DatacenterAndName input) {
return input.getDatacenter();
}
};
public static DatacenterAndName fromSlashEncoded(String name) {
Iterable<String> parts = Splitter.on('/').split(checkNotNull(name, "name"));
checkArgument(Iterables.size(parts) == 2, "name must be in format datacenterId/name");
return new DatacenterAndName(Iterables.get(parts, 0), Iterables.get(parts, 1));
}
public static DatacenterAndName fromDatacenterAndName(String datacenterId, String name) {
return new DatacenterAndName(datacenterId, name);
}
private static String slashEncodeDatacenterAndName(String datacenterId, String name) {
return checkNotNull(datacenterId, "datacenterId") + "/" + checkNotNull(name, "name");
}
public String slashEncode() {
return slashEncodeDatacenterAndName(datacenterId, name);
}
protected final String datacenterId;
protected final String name;
protected DatacenterAndName(String datacenterId, String name) {
this.datacenterId = checkNotNull(datacenterId, "datacenterId");
this.name = checkNotNull(name, "name");
}
public String getDatacenter() {
return datacenterId;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DatacenterAndName that = DatacenterAndName.class.cast(o);
return equal(this.datacenterId, that.datacenterId) && equal(this.name, that.name);
}
@Override
public int hashCode() {
return Objects.hashCode(datacenterId, name);
}
@Override
public String toString() {
return string().toString();
}
protected ToStringHelper string() {
return Objects.toStringHelper("").add("datacenterId", datacenterId).add("name", name);
}
}

View File

@ -0,0 +1,48 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.domain.datacenterscoped;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
/**
* @author Adrian Cole
*/
public class DatasetInDatacenter extends DatacenterAndId {
protected final Dataset dataset;
public DatasetInDatacenter(Dataset dataset, String datacenterId) {
super(datacenterId, checkNotNull(dataset, "dataset").getId());
this.dataset = dataset;
}
public Dataset getDataset() {
return dataset;
}
// superclass hashCode/equals are good enough, and help us use DatacenterAndId and DatasetInDatacenter
// interchangeably as Map keys
@Override
public String toString() {
return "[dataset=" + dataset + ", datacenterId=" + datacenterId + "]";
}
}

View File

@ -0,0 +1,48 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.domain.datacenterscoped;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
/**
* @author Adrian Cole
*/
public class MachineInDatacenter extends DatacenterAndId {
protected final Machine machine;
public MachineInDatacenter(Machine machine, String datacenterId) {
super(datacenterId, checkNotNull(machine, "machine").getId());
this.machine = machine;
}
public Machine getMachine() {
return machine;
}
// superclass hashCode/equals are good enough, and help us use DatacenterAndId and MachineInDatacenter
// interchangeably as Map keys
@Override
public String toString() {
return "[machine=" + machine + ", datacenterId=" + datacenterId + "]";
}
}

View File

@ -0,0 +1,46 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.domain.datacenterscoped;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Adrian Cole
*/
public class PackageInDatacenter extends DatacenterAndName {
protected final org.jclouds.joyent.sdc.v6_5.domain.Package pkg;
public PackageInDatacenter(org.jclouds.joyent.sdc.v6_5.domain.Package pkg, String datacenterId) {
super(datacenterId, checkNotNull(pkg, "pkg").getName());
this.pkg = pkg;
}
public org.jclouds.joyent.sdc.v6_5.domain.Package getPackage() {
return pkg;
}
// superclass hashCode/equals are good enough, and help us use DatacenterAndId and PackageInDatacenter
// interchangeably as Map keys
@Override
public String toString() {
return "[pkg=" + pkg + ", datacenterId=" + datacenterId + "]";
}
}

View File

@ -31,7 +31,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.options.CreateServerOptions;
import org.jclouds.joyent.sdc.v6_5.options.CreateMachineOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.MapBinder;
@ -81,10 +81,10 @@ public interface MachineAsyncClient {
@POST
@Path("/my/machines")
@Consumes(MediaType.APPLICATION_JSON)
@MapBinder(CreateServerOptions.class)
@MapBinder(CreateMachineOptions.class)
ListenableFuture<Machine> createMachine(@PayloadParam("name") String name,
@PayloadParam("package") String packageSDC,
@PayloadParam("dataset") String dataset,CreateServerOptions... options);
@PayloadParam("dataset") String dataset,CreateMachineOptions... options);
/**
* @see MachineClient#stopMachine

View File

@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.options.CreateServerOptions;
import org.jclouds.joyent.sdc.v6_5.options.CreateMachineOptions;
/**
* Provides synchronous access to Machine.
@ -39,7 +39,7 @@ public interface MachineClient {
/**
* Lists all machines we have on record for your account.
*
* @return an account's associated server objects.
* @return an account's associated machine objects.
*/
Set<Machine> listMachines();
@ -64,7 +64,7 @@ public interface MachineClient {
* optional parameters to be passed into the machine creation request
* @return the newly created machine
*/
Machine createMachine(String name, String packageSDC, String dataset, CreateServerOptions... options);
Machine createMachine(String name, String packageSDC, String dataset, CreateMachineOptions... options);
/**
* Allows you to shut down a machine.

View File

@ -32,7 +32,7 @@ import com.google.gson.stream.JsonWriter;
*/
public class SDCTypeAdapters {
public static class ServerStateAdapter extends TypeAdapter<Machine.State> {
public static class MachineStateAdapter extends TypeAdapter<Machine.State> {
@Override
public void write(JsonWriter writer, Machine.State value) throws IOException {
writer.value(value.value());

View File

@ -40,7 +40,7 @@ import com.google.gson.annotations.SerializedName;
* @author Gerald Pereira
*
*/
public class CreateServerOptions implements MapBinder {
public class CreateMachineOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
@ -52,8 +52,8 @@ public class CreateServerOptions implements MapBinder {
if (this == object) {
return true;
}
if (object instanceof CreateServerOptions) {
final CreateServerOptions other = CreateServerOptions.class.cast(object);
if (object instanceof CreateMachineOptions) {
final CreateMachineOptions other = CreateMachineOptions.class.cast(object);
return equal(tag, tag) && equal(metadata, other.metadata);
} else {
return false;
@ -97,7 +97,7 @@ public class CreateServerOptions implements MapBinder {
* An arbitrary set of metadata key/value pairs can be set at provision time, but they must be
* prefixed with "metadata."
*/
public CreateServerOptions metadata(Map<String, String> metadata) {
public CreateMachineOptions metadata(Map<String, String> metadata) {
checkNotNull(metadata, "metadata");
this.metadata = ImmutableMap.copyOf(metadata);
return this;
@ -106,7 +106,7 @@ public class CreateServerOptions implements MapBinder {
/**
* An arbitrary set of tags can be set at provision time, but they must be prefixed with "tag."
*/
public CreateServerOptions tag(Map<String, String> tag) {
public CreateMachineOptions tag(Map<String, String> tag) {
checkNotNull(tag, "tag");
this.tag = ImmutableMap.copyOf(tag);
return this;
@ -132,18 +132,18 @@ public class CreateServerOptions implements MapBinder {
public static class Builder {
/**
* @see CreateServerOptions#metadata(Map<String, String>)
* @see CreateMachineOptions#metadata(Map<String, String>)
*/
public static CreateServerOptions metadata(Map<String, String> metadata) {
CreateServerOptions options = new CreateServerOptions();
public static CreateMachineOptions metadata(Map<String, String> metadata) {
CreateMachineOptions options = new CreateMachineOptions();
return options.metadata(metadata);
}
/**
* @see CreateServerOptions#tag(Map<String, String>)
* @see CreateMachineOptions#tag(Map<String, String>)
*/
public static CreateServerOptions tag(Map<String, String> tag) {
CreateServerOptions options = new CreateServerOptions();
public static CreateMachineOptions tag(Map<String, String> tag) {
CreateMachineOptions options = new CreateMachineOptions();
return options.tag(tag);
}
}

View File

@ -0,0 +1,26 @@
package org.jclouds.joyent.sdc.v6_5.compute;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "SDCComputeServiceLiveTest")
public class SDCComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public SDCComputeServiceLiveTest() {
provider = "joyent-sdc";
}
@Override
protected Module getSshModule() {
return new SshjSshClientModule();
}
}

View File

@ -0,0 +1,92 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
import org.jclouds.joyent.sdc.v6_5.parse.ParseDatasetTest;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
/**
* Tests the function that transforms sdc-specific images to generic images.
*
* @author Adrian Cole
*/
@Test(testName = "DatasetInDatacenterToHardwareTest")
public class DatasetInDatacenterToImageTest {
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-sdc")
.description("openstack-sdc").build();
Location zone = new LocationBuilder().id("us-sw-1").description("us-sw-1").scope(LocationScope.ZONE)
.parent(provider).build();
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
.<String, Location> of("us-sw-1", zone));
Dataset datasetToConvert = new ParseDatasetTest().expected();
@Test
public void testConversionWhereLocationFound() {
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
"My Test OS", true);
DatasetInDatacenterToImage converter = new DatasetInDatacenterToImage(constant(operatingSystem), locationIndex);
DatasetInDatacenter datasetInZoneToConvert = new DatasetInDatacenter(datasetToConvert, "us-sw-1");
org.jclouds.compute.domain.Image convertedImage = converter.apply(datasetInZoneToConvert);
assertEquals(convertedImage.getId(), datasetInZoneToConvert.slashEncode());
assertEquals(convertedImage.getProviderId(), datasetToConvert.getId());
assertEquals(convertedImage.getLocation(), locationIndex.get().get("us-sw-1"));
assertEquals(convertedImage.getName(), datasetToConvert.getName());
assertEquals(convertedImage.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
assertEquals(convertedImage.getOperatingSystem(), operatingSystem);
}
@Test(expectedExceptions = IllegalStateException.class)
public void testConversionWhereLocationNotFound() {
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
"My Test OS", true);
DatasetInDatacenterToImage converter = new DatasetInDatacenterToImage(constant(operatingSystem), locationIndex);
DatasetInDatacenter datasetInZoneToConvert = new DatasetInDatacenter(datasetToConvert, "South");
converter.apply(datasetInZoneToConvert);
}
@SuppressWarnings("unchecked")
private static Function<Dataset, OperatingSystem> constant(OperatingSystem operatingSystem) {
return Function.class.cast(Functions.constant(operatingSystem));
}
}

View File

@ -0,0 +1,58 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.Map;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
import org.jclouds.joyent.sdc.v6_5.parse.ParseDatasetTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests for the function for transforming a sdc specific Image into a generic
* OperatingSystem object.
*
* @author Adrian Cole
*/
@Test(testName = "DatasetToOperatingSystemTest")
public class DatasetToOperatingSystemTest {
public void testCentos6() {
Dataset datasetToConvert = new ParseDatasetTest().expected();
OperatingSystem convertedOs = new DatasetToOperatingSystem(ImmutableMap.<OsFamily, Map<String, String>> of(
OsFamily.CENTOS, ImmutableMap.of("6", "6.0"))).apply(datasetToConvert);
assertEquals(convertedOs.getName(), datasetToConvert.getName());
assertEquals(convertedOs.getFamily(), OsFamily.CENTOS);
assertEquals(convertedOs.getDescription(), datasetToConvert.getUrn());
assertEquals(convertedOs.getVersion(), "6.0");
assertEquals(convertedOs.getArch(), null);
assertTrue(convertedOs.is64Bit());
}
}

View File

@ -0,0 +1,142 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.joyent.sdc.v6_5.compute.config.SDCComputeServiceContextModule;
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
import org.jclouds.joyent.sdc.v6_5.parse.ParseCreatedMachineTest;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
/**
* Tests for the function for transforming a sdc specific Machine into a generic
* NodeMetadata object.
*
* @author Adrian Cole
*/
@Test(testName = "MachineInDatacenterToNodeMetadataTest")
public class MachineInDatacenterToNodeMetadataTest {
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-sdc")
.description("openstack-sdc").build();
Location zone = new LocationBuilder().id("us-sw-1").description("us-sw-1").scope(LocationScope.ZONE)
.parent(provider).build();
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
.<String, Location> of("us-sw-1", zone));
GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(
GroupNamingConvention.Factory.class);
@Test
public void testWhenNoHardwareOrImageMatchImageIdIsStillSet() {
Hardware existingHardware = new HardwareBuilder().id("us-sw-1/FOOOOOOOO").providerId("FOOOOOOOO").location(zone)
.build();
Image existingImage = new ImageBuilder().id("us-sw-1/FOOOOOOOO")
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
.providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build();
checkHardwareAndImageStatus(null, existingHardware, "us-sw-1/sdc:sdc:centos-5.7:1.2.1", null, existingImage);
}
@Test
public void testWhenHardwareAndImageMatchHardwareOperatingSystemAndImageIdAreSet() {
Hardware existingHardware = new HardwareBuilder().id("us-sw-1/Small 1GB").providerId("Small 1GB").ram(1024)
.volume(new VolumeImpl(Float.valueOf(61440), true, true)).location(zone).build();
Image existingImage = new ImageBuilder().id("us-sw-1/sdc:sdc:centos-5.7:1.2.1")
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
.providerId("sdc:sdc:centos-5.7:1.2.1").description("foobuntu").status(Image.Status.AVAILABLE)
.location(zone).build();
checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(),
existingImage.getOperatingSystem(), existingImage);
}
// TODO: clean up this syntax
private void checkHardwareAndImageStatus(Hardware expectedHardware, Hardware existingHardware,
String expectedImageId, OperatingSystem expectedOs, Image existingImage) {
Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
.of(existingHardware);
Machine machineToConvert = new ParseCreatedMachineTest().expected();
MachineInDatacenter machineInDatacenterToConvert = new MachineInDatacenter(machineToConvert, "us-sw-1");
MachineInDatacenterToNodeMetadata converter = new MachineInDatacenterToNodeMetadata(
SDCComputeServiceContextModule.toPortableNodeStatus, locationIndex,
Suppliers.<Set<? extends Image>> ofInstance(images),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata convertedNodeMetadata = converter.apply(machineInDatacenterToConvert);
assertEquals(machineInDatacenterToConvert.slashEncode(), convertedNodeMetadata.getId());
assertEquals(machineToConvert.getId(), convertedNodeMetadata.getProviderId());
assertEquals(convertedNodeMetadata.getLocation().getScope(), LocationScope.ZONE);
assertEquals(convertedNodeMetadata.getLocation().getId(), "us-sw-1");
assertEquals(machineToConvert.getName(), convertedNodeMetadata.getName());
assertEquals(convertedNodeMetadata.getGroup(), "sample");
assertEquals(convertedNodeMetadata.getImageId(), expectedImageId);
assertEquals(convertedNodeMetadata.getOperatingSystem(), expectedOs);
assertEquals(convertedNodeMetadata.getHardware(), expectedHardware);
assertEquals(SDCComputeServiceContextModule.toPortableNodeStatus.get(machineToConvert.getState()),
convertedNodeMetadata.getStatus());
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.224.0.63"));
assertNotNull(convertedNodeMetadata.getPublicAddresses());
assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("37.153.96.62"));
assertNotNull(convertedNodeMetadata.getUserMetadata());
assertEquals(convertedNodeMetadata.getUserMetadata(),
ImmutableMap.<String, String> of("root_authorized_keys", "ssh-rsa XXXXXX== test@xxxx.ovh.net\n"));
}
}

View File

@ -0,0 +1,88 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.sdc.v6_5.compute.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import java.util.Map;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.joyent.sdc.v6_5.domain.Package;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
/**
* Tests the function used to transform Package objects into Hardware objects
*
* @author Adrian Cole
*/
@Test(testName = "PackageInDatacenterToHardwareTest")
public class PackageInDatacenterToHardwareTest {
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-sdc").description(
"openstack-sdc").build();
Location zone = new LocationBuilder().id("us-sw-1").description("us-sw-1").scope(
LocationScope.ZONE).parent(provider).build();
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
.<String, Location> of("us-sw-1", zone));
Package packageToConvert = org.jclouds.joyent.sdc.v6_5.domain.Package.builder().name("Small 1GB").memorySizeMb(1024)
.diskSizeGb(30720).swapSizeMb(2048).isDefault(true).build();
@Test
public void testConversionWhereLocationFound() {
PackageInDatacenter packageInZoneToConvert = new PackageInDatacenter(packageToConvert, "us-sw-1");
Hardware converted = new PackageInDatacenterToHardware(locationIndex).apply(packageInZoneToConvert);
assertEquals(converted.getName(), packageToConvert.getName());
assertEquals(converted.getId(), packageInZoneToConvert.slashEncode());
assertEquals(converted.getProviderId(), packageToConvert.getName());
assertEquals(converted.getLocation(), locationIndex.get().get("us-sw-1"));
assertEquals(converted.getRam(), packageToConvert.getMemorySizeMb());
//TODO!
// assertNotNull(converted.getProcessors());
// assertFalse(converted.getProcessors().isEmpty());
// assertEquals(converted.getProcessors().iterator().next().getCores(), (double) packageToConvert.getVcpus());
assertNotNull(converted.getVolumes());
assertFalse(converted.getVolumes().isEmpty());
assertEquals(converted.getVolumes().iterator().next().getSize(), Float.valueOf(packageToConvert.getDiskSizeGb()));
}
@Test(expectedExceptions = IllegalStateException.class)
public void testConversionWhereLocationNotFound() {
PackageInDatacenter packageInZoneToConvert = new PackageInDatacenter(packageToConvert, "South");
new PackageInDatacenterToHardware(locationIndex).apply(packageInZoneToConvert);
}
}

View File

@ -70,7 +70,7 @@ public class MachineClientExpectTest extends BaseSDCClientExpectTest {
"application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
.payload(
payloadFromStringWithContentType(
"{\"name\":\"testJClouds\",\"package\":\"Small 1GB\",\"dataset\":\"sdc:sdc:centos-5.7:1.2.1\"}",
"{\"name\":\"sample-e92\",\"package\":\"Small 1GB\",\"dataset\":\"sdc:sdc:centos-5.7:1.2.1\"}",
"application/json")).build();
HttpResponse createMachineResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")
@ -79,7 +79,7 @@ public class MachineClientExpectTest extends BaseSDCClientExpectTest {
SDCClient clientWithNewMachine = requestsSendResponses(getDatacenters, getDatacentersResponse, createMachine, createMachineResponse);
assertEquals(clientWithNewMachine.getMachineClientForDatacenter("us-sw-1").createMachine("testJClouds", "Small 1GB",
assertEquals(clientWithNewMachine.getMachineClientForDatacenter("us-sw-1").createMachine("sample-e92", "Small 1GB",
"sdc:sdc:centos-5.7:1.2.1").toString(), new ParseCreatedMachineTest().expected().toString());
}
}

View File

@ -37,7 +37,7 @@ import com.google.inject.Injector;
/**
* @author Gerald Pereira
*/
@Test(groups = "unit", testName = "ParseServerTest")
@Test(groups = "unit", testName = "ParseMachineTest")
public class ParseCreatedMachineTest extends BaseItemParserTest<Machine> {
@Override
@ -51,7 +51,7 @@ public class ParseCreatedMachineTest extends BaseItemParserTest<Machine> {
return Machine
.builder()
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
.name("testJClouds")
.name("sample-e92")
.type(Type.VIRTUALMACHINE)
.state(Machine.State.STOPPED)
.dataset("sdc:sdc:centos-5.7:1.2.1")

View File

@ -54,7 +54,7 @@ public class ParseMachineListTest extends BaseSetParserTest<Machine> {
Machine
.builder()
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
.name("testJClouds")
.name("sample-e92")
.type(Type.VIRTUALMACHINE)
.state(Machine.State.RUNNING)
.dataset("sdc:sdc:centos-5.7:1.2.1")
@ -68,7 +68,7 @@ public class ParseMachineListTest extends BaseSetParserTest<Machine> {
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-11T09:00:33+00:00"))
.build(),
Machine.builder().id("d73cb0b0-7d1f-44ef-8c40-e040eef0f726").name("testJClouds2").type(Type.SMARTMACHINE)
Machine.builder().id("d73cb0b0-7d1f-44ef-8c40-e040eef0f726").name("sample-e922").type(Type.SMARTMACHINE)
.state(Machine.State.RUNNING).dataset("sdc:sdc:smartosplus:3.1.0")
.ips(ImmutableSet.<String> builder().add("37.153.96.56").add("10.224.0.57").build())
.memorySizeMb(1024).diskSizeGb(61440).metadata(ImmutableMap.<String, String> of())

View File

@ -51,7 +51,7 @@ public class ParseMachineTest extends BaseItemParserTest<Machine> {
return Machine
.builder()
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
.name("testJClouds")
.name("sample-e92")
.type(Type.VIRTUALMACHINE)
.state(Machine.State.STOPPED)
.dataset("sdc:sdc:centos-5.7:1.2.1")

View File

@ -1,51 +0,0 @@
<?xml version="1.0"?>
<configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="WIREFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-wire.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="COMPUTEFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-compute.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<root>
<level value="warn" />
</root>
<logger name="org.jclouds">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<logger name="jclouds.wire">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.headers">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.compute">
<level value="DEBUG" />
<appender-ref ref="COMPUTEFILE" />
</logger>
</configuration>

View File

@ -1 +1 @@
{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"testJClouds","type":"virtualmachine","state":"stopped","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T08:44:53+00:00"}
{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"sample-e92","type":"virtualmachine","state":"stopped","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T08:44:53+00:00"}

View File

@ -1 +1 @@
[{"id":"d73cb0b0-7d1f-44ef-8c40-e040eef0f726","name":"testJClouds2","type":"smartmachine","state":"running","dataset":"sdc:sdc:smartosplus:3.1.0","ips":["37.153.96.56","10.224.0.57"],"memory":1024,"disk":61440,"metadata":{},"created":"2012-05-09T13:39:43+00:00","updated":"2012-05-09T13:43:45+00:00"},{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"testJClouds","type":"virtualmachine","state":"running","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net\n"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T09:00:33+00:00"}]
[{"id":"d73cb0b0-7d1f-44ef-8c40-e040eef0f726","name":"sample-e922","type":"smartmachine","state":"running","dataset":"sdc:sdc:smartosplus:3.1.0","ips":["37.153.96.56","10.224.0.57"],"memory":1024,"disk":61440,"metadata":{},"created":"2012-05-09T13:39:43+00:00","updated":"2012-05-09T13:43:45+00:00"},{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"sample-e92","type":"virtualmachine","state":"running","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net\n"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T09:00:33+00:00"}]

View File

@ -1 +1 @@
{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"testJClouds","type":"virtualmachine","state":"stopped","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T08:44:53+00:00"}
{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"sample-e92","type":"virtualmachine","state":"stopped","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T08:44:53+00:00"}

View File

@ -80,6 +80,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>

View File

@ -0,0 +1,34 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.joyentcloud;
import org.jclouds.joyent.sdc.v6_5.compute.SDCComputeServiceLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "JoyentCloudComputeServiceLiveTest")
public class JoyentCloudComputeServiceLiveTest extends SDCComputeServiceLiveTest {
public JoyentCloudComputeServiceLiveTest() {
provider = "joyentcloud";
}
}

View File

@ -0,0 +1,85 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.joyent.joyentcloud;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "JoyentCloudTemplateBuilderLiveTest")
public class JoyentCloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public JoyentCloudTemplateBuilderLiveTest() {
provider = "joyentcloud";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return (input.version.equals("") || input.version.equals("10.04")) && input.is64Bit;
case DEBIAN:
return input.is64Bit && !input.version.equals("5.0");
case CENTOS:
return (input.version.equals("") || input.version.equals("5.7") || input.version.equals("6.0"))
&& input.is64Bit;
default:
return false;
}
}
});
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = this.view.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getName(), "ubuntu-10.04");
assertEquals(defaultTemplate.getImage().getDefaultCredentials().getUser(), "root");
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(defaultTemplate.getImage().getLocation().getId(), "us-east-1");
assertEquals(defaultTemplate.getHardware().getLocation().getId(), "us-east-1");
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("TODO");
}
}