diff --git a/labs/joyent-sdc/pom.xml b/labs/joyent-sdc/pom.xml index b7a0a548b3..8c5bd62009 100644 --- a/labs/joyent-sdc/pom.xml +++ b/labs/joyent-sdc/pom.xml @@ -50,9 +50,16 @@ org.jclouds - jclouds-core + jclouds-compute ${project.version} + + org.jclouds + jclouds-compute + ${project.version} + test-jar + test + org.jclouds jclouds-core @@ -66,6 +73,12 @@ ${project.version} test + + org.jclouds.driver + jclouds-sshj + ${project.version} + test + ch.qos.logback logback-classic diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java index c615b9fe40..7bf3be99f5 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java @@ -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.> of(DatacentersAreZonesModule.class, SDCRestClientModule.class)); + .view(TypeToken.of(ComputeServiceContext.class)) + .defaultModules(ImmutableSet.> of(DatacentersAreZonesModule.class, SDCRestClientModule.class, SDCComputeServiceContextModule.class)); } @Override diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceAdapter.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceAdapter.java new file mode 100644 index 0000000000..8635583104 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceAdapter.java @@ -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 { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + protected final SDCClient sdcClient; + protected final Supplier> datacenterIds; + + @Inject + public SDCComputeServiceAdapter(SDCClient sdcClient, @Zone Supplier> datacenterIds) { + this.sdcClient = checkNotNull(sdcClient, "sdcClient"); + this.datacenterIds = checkNotNull(datacenterIds, "datacenterIds"); + } + + @Override + public NodeAndInitialCredentials 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.slashEncode(), + credentialsBuilder.build()); + } + + @Override + public Iterable listHardwareProfiles() { + Builder builder = ImmutableSet.builder(); + for (final String datacenterId : datacenterIds.get()) { + builder.addAll(transform(sdcClient.getPackageClientForDatacenter(datacenterId).listPackages(), + new Function() { + + @Override + public PackageInDatacenter apply(org.jclouds.joyent.sdc.v6_5.domain.Package arg0) { + return new PackageInDatacenter(arg0, datacenterId); + } + + })); + } + return builder.build(); + } + + @Override + public Iterable listImages() { + Builder builder = ImmutableSet.builder(); + for (final String datacenterId : datacenterIds.get()) { + builder.addAll(transform(sdcClient.getDatasetClientForDatacenter(datacenterId).listDatasets(), + new Function() { + + @Override + public DatasetInDatacenter apply(Dataset arg0) { + return new DatasetInDatacenter(arg0, datacenterId); + } + + })); + } + return builder.build(); + } + + @Override + public Iterable listNodes() { + Builder builder = ImmutableSet.builder(); + for (final String datacenterId : datacenterIds.get()) { + builder.addAll(transform(sdcClient.getMachineClientForDatacenter(datacenterId).listMachines(), + new Function() { + + @Override + public MachineInDatacenter apply(Machine arg0) { + return new MachineInDatacenter(arg0, datacenterId); + } + + })); + } + return builder.build(); + } + + @Override + public Iterable 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()); + + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/config/SDCComputeServiceContextModule.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/config/SDCComputeServiceContextModule.java new file mode 100644 index 0000000000..7ed4762d14 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/config/SDCComputeServiceContextModule.java @@ -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 { + + @SuppressWarnings("unchecked") + @Override + protected void configure() { + super.configure(); + bind( + new TypeLiteral>() { + }).to(SDCComputeServiceAdapter.class); + + bind(new TypeLiteral>() { + }).to(MachineInDatacenterToNodeMetadata.class); + + bind(new TypeLiteral>() { + }).to(DatasetInDatacenterToImage.class); + bind(new TypeLiteral>() { + }).to(DatasetToOperatingSystem.class); + + bind(new TypeLiteral>() { + }).to(PackageInDatacenterToHardware.class); + + // we aren't converting location from a provider-specific type + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); + } + + @Provides + @Singleton + protected Supplier> createLocationIndexedById( + @Memoized Supplier> locations) { + return Suppliers.compose(new Function, Map>() { + + @Override + public Map apply(Set arg0) { + return Maps.uniqueIndex(Iterables2.concreteCopy(arg0), new Function() { + + @Override + public String apply(Location arg0) { + return arg0.getId(); + } + + }); + } + }, locations); + + } + + @VisibleForTesting + public static final Map toPortableNodeStatus = ImmutableMap + . 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 toPortableNodeStatus() { + return toPortableNodeStatus; + } + +} \ No newline at end of file diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImage.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImage.java new file mode 100644 index 0000000000..8567e353ca --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImage.java @@ -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 { + private final Function imageToOs; + private final Supplier> locationIndex; + + @Inject + public DatasetInDatacenterToImage(Function imageToOs, + Supplier> 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(); + } +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystem.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystem.java new file mode 100644 index 0000000000..e195f7c609 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystem.java @@ -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 { + 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> osVersionMap; + + @Inject + public DatasetToOperatingSystem(Map> 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 pieces = ImmutableList.copyOf(Splitter.on(':').split(from.getUrn())); + if (pieces.get(2).indexOf('-') != -1) { + List 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(); + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadata.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadata.java new file mode 100644 index 0000000000..7f5855925e --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadata.java @@ -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 { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + protected Map toPortableNodeStatus; + protected final Supplier> locationIndex; + protected final Supplier> images; + protected final Supplier> hardwares; + protected final GroupNamingConvention nodeNamingConvention; + + @Inject + public MachineInDatacenterToNodeMetadata(Map toPortableNodeStatus, + Supplier> locationIndex, @Memoized Supplier> images, + @Memoized Supplier> 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() { + @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 findObjectOfTypeForMachineOrNull(Set supply, String type, + final String objectId, final DatacenterAndId machineInDatacenter) { + return tryFind(supply, new Predicate() { + @Override + public boolean apply(T input) { + return input.getId().equals( + DatacenterAndId.fromDatacenterAndId(machineInDatacenter.getDatacenter(), objectId).slashEncode()); + } + }).orNull(); + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardware.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardware.java new file mode 100644 index 0000000000..3d4e67da08 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardware.java @@ -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 { + + private final Supplier> locationIndex; + + @Inject + public PackageInDatacenterToHardware(Supplier> 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(); + } +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCParserModule.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCParserModule.java index cc2e3f180c..ae0974e79d 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCParserModule.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCParserModule.java @@ -38,7 +38,7 @@ public class SDCParserModule extends AbstractModule { @Provides @Singleton public Map provideCustomAdapterBindings() { - return ImmutableMap. of(Machine.State.class, new SDCTypeAdapters.ServerStateAdapter(), Type.class, + return ImmutableMap. of(Machine.State.class, new SDCTypeAdapters.MachineStateAdapter(), Type.class, new SDCTypeAdapters.SDCTypeAdapter()); } diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndId.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndId.java new file mode 100644 index 0000000000..df04e1da7e --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndId.java @@ -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 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 + "]"; + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndName.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndName.java new file mode 100644 index 0000000000..e6eba70278 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatacenterAndName.java @@ -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 NAME_FUNCTION = new Function(){ + + @Override + public String apply(DatacenterAndName input) { + return input.getName(); + } + + }; + + public final static Function ZONE_FUNCTION = new Function(){ + + @Override + public String apply(DatacenterAndName input) { + return input.getDatacenter(); + } + + }; + + public static DatacenterAndName fromSlashEncoded(String name) { + Iterable 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); + } +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatasetInDatacenter.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatasetInDatacenter.java new file mode 100644 index 0000000000..02c5e945eb --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/DatasetInDatacenter.java @@ -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 + "]"; + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/MachineInDatacenter.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/MachineInDatacenter.java new file mode 100644 index 0000000000..de4fc0becb --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/MachineInDatacenter.java @@ -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 + "]"; + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/PackageInDatacenter.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/PackageInDatacenter.java new file mode 100644 index 0000000000..26acf6ed9c --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/domain/datacenterscoped/PackageInDatacenter.java @@ -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 + "]"; + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineAsyncClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineAsyncClient.java index b32ab43dc9..f4294a9f6f 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineAsyncClient.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineAsyncClient.java @@ -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 createMachine(@PayloadParam("name") String name, @PayloadParam("package") String packageSDC, - @PayloadParam("dataset") String dataset,CreateServerOptions... options); + @PayloadParam("dataset") String dataset,CreateMachineOptions... options); /** * @see MachineClient#stopMachine diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineClient.java index 5cec1ed38c..1f9db184b5 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineClient.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/MachineClient.java @@ -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 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. diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/functions/internal/SDCTypeAdapters.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/functions/internal/SDCTypeAdapters.java index ecfe62e8f9..03a2424cdd 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/functions/internal/SDCTypeAdapters.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/functions/internal/SDCTypeAdapters.java @@ -32,7 +32,7 @@ import com.google.gson.stream.JsonWriter; */ public class SDCTypeAdapters { - public static class ServerStateAdapter extends TypeAdapter { + public static class MachineStateAdapter extends TypeAdapter { @Override public void write(JsonWriter writer, Machine.State value) throws IOException { writer.value(value.value()); diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateServerOptions.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java similarity index 84% rename from labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateServerOptions.java rename to labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java index 631b69fdbc..d009c5c3af 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateServerOptions.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java @@ -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 metadata) { + public CreateMachineOptions metadata(Map 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 tag) { + public CreateMachineOptions tag(Map 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) + * @see CreateMachineOptions#metadata(Map) */ - public static CreateServerOptions metadata(Map metadata) { - CreateServerOptions options = new CreateServerOptions(); + public static CreateMachineOptions metadata(Map metadata) { + CreateMachineOptions options = new CreateMachineOptions(); return options.metadata(metadata); } /** - * @see CreateServerOptions#tag(Map) + * @see CreateMachineOptions#tag(Map) */ - public static CreateServerOptions tag(Map tag) { - CreateServerOptions options = new CreateServerOptions(); + public static CreateMachineOptions tag(Map tag) { + CreateMachineOptions options = new CreateMachineOptions(); return options.tag(tag); } } diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceLiveTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceLiveTest.java new file mode 100644 index 0000000000..dac1eefc25 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/SDCComputeServiceLiveTest.java @@ -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(); + } + + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImageTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImageTest.java new file mode 100644 index 0000000000..a1354b7269 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetInDatacenterToImageTest.java @@ -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> locationIndex = Suppliers.> ofInstance(ImmutableMap + . 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 constant(OperatingSystem operatingSystem) { + return Function.class.cast(Functions.constant(operatingSystem)); + } +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystemTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystemTest.java new file mode 100644 index 0000000000..8c014a385a --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/DatasetToOperatingSystemTest.java @@ -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.> 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()); + } + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadataTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadataTest.java new file mode 100644 index 0000000000..6398fa20b0 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/MachineInDatacenterToNodeMetadataTest.java @@ -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> locationIndex = Suppliers.> ofInstance(ImmutableMap + . 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 images = existingImage == null ? ImmutableSet. of() : ImmutableSet.of(existingImage); + Set hardwares = existingHardware == null ? ImmutableSet. 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.> ofInstance(images), + Suppliers.> 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. of("root_authorized_keys", "ssh-rsa XXXXXX== test@xxxx.ovh.net\n")); + } + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardwareTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardwareTest.java new file mode 100644 index 0000000000..1390929caf --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/compute/functions/PackageInDatacenterToHardwareTest.java @@ -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> locationIndex = Suppliers.> ofInstance(ImmutableMap + . 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); + } + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/MachineClientExpectTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/MachineClientExpectTest.java index 29f9fd861c..5502005ba9 100644 --- a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/MachineClientExpectTest.java +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/MachineClientExpectTest.java @@ -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()); } } diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseCreatedMachineTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseCreatedMachineTest.java index 8920680586..65c61c827c 100644 --- a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseCreatedMachineTest.java +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseCreatedMachineTest.java @@ -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 { @Override @@ -51,7 +51,7 @@ public class ParseCreatedMachineTest extends BaseItemParserTest { 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") diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineListTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineListTest.java index 60d70bfe73..af8af2369c 100644 --- a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineListTest.java +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineListTest.java @@ -54,7 +54,7 @@ public class ParseMachineListTest extends BaseSetParserTest { 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 { .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. builder().add("37.153.96.56").add("10.224.0.57").build()) .memorySizeMb(1024).diskSizeGb(61440).metadata(ImmutableMap. of()) diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineTest.java index 02829a41b5..ca692440f4 100644 --- a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineTest.java +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/parse/ParseMachineTest.java @@ -51,7 +51,7 @@ public class ParseMachineTest extends BaseItemParserTest { 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") diff --git a/labs/joyent-sdc/src/test/resources/logback.xml b/labs/joyent-sdc/src/test/resources/logback.xml deleted file mode 100644 index b77c1b041f..0000000000 --- a/labs/joyent-sdc/src/test/resources/logback.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - target/test-data/jclouds.log - - - %d %-5p [%c] [%thread] %m%n - - - - - target/test-data/jclouds-wire.log - - - %d %-5p [%c] [%thread] %m%n - - - - - target/test-data/jclouds-compute.log - - - %d %-5p [%c] [%thread] %m%n - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/labs/joyent-sdc/src/test/resources/machine.json b/labs/joyent-sdc/src/test/resources/machine.json index fd56f2f794..48151249bb 100644 --- a/labs/joyent-sdc/src/test/resources/machine.json +++ b/labs/joyent-sdc/src/test/resources/machine.json @@ -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"} diff --git a/labs/joyent-sdc/src/test/resources/machine_list.json b/labs/joyent-sdc/src/test/resources/machine_list.json index 29ca4ca7a9..51b82b7923 100644 --- a/labs/joyent-sdc/src/test/resources/machine_list.json +++ b/labs/joyent-sdc/src/test/resources/machine_list.json @@ -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"}] \ No newline at end of file +[{"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"}] \ No newline at end of file diff --git a/labs/joyent-sdc/src/test/resources/new_machine.json b/labs/joyent-sdc/src/test/resources/new_machine.json index fd56f2f794..48151249bb 100644 --- a/labs/joyent-sdc/src/test/resources/new_machine.json +++ b/labs/joyent-sdc/src/test/resources/new_machine.json @@ -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"} diff --git a/labs/joyentcloud/pom.xml b/labs/joyentcloud/pom.xml index 4814a5e67b..a0bdbab1c7 100644 --- a/labs/joyentcloud/pom.xml +++ b/labs/joyentcloud/pom.xml @@ -80,6 +80,12 @@ ${project.version} test + + org.jclouds.driver + jclouds-sshj + ${project.version} + test + ch.qos.logback logback-classic diff --git a/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudComputeServiceLiveTest.java b/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudComputeServiceLiveTest.java new file mode 100644 index 0000000000..9522c5da84 --- /dev/null +++ b/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudComputeServiceLiveTest.java @@ -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"; + } +} diff --git a/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudTemplateBuilderLiveTest.java b/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..289d7ec3ae --- /dev/null +++ b/labs/joyentcloud/src/test/java/org/jclouds/joyent/joyentcloud/JoyentCloudTemplateBuilderLiveTest.java @@ -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 defineUnsupportedOperatingSystems() { + return Predicates.not(new Predicate() { + + @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 getIso3166Codes() { + return ImmutableSet. of("TODO"); + } +}