Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 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.cloudsigma.compute;
 import static;
 import static;
 import static org.jclouds.concurrent.FutureIterables.transformParallel;
 import java.util.Map;
defines the connection between the org.jclouds.cloudsigma.CloudSigmaClient implementation and the jclouds org.jclouds.compute.ComputeService
 public class CloudSigmaComputeServiceAdapter implements
    private static final Predicate<DriveInfoPREINSTALLED_DISK = Predicates.and(Predicates.notNull(),
          new Predicate<DriveInfo>() {
             public boolean apply(DriveInfo drive) {
                return drive.getType().equals(.) && drive.getDriveType().contains("preinstalled");
    private final CloudSigmaClient client;
    private final Predicate<DriveInfodriveNotClaimed;
    private final JustProvider locationSupplier;
    private final String defaultVncPassword;
    private final Cache<StringDriveInfocache;
    private final ExecutorService executor;
    protected Logger logger = .;
    public CloudSigmaComputeServiceAdapter(CloudSigmaClient clientPredicate<DriveInfodriveNotClaimed,
          JustProvider locationSupplier, @Named(.String defaultVncPassword,
         Cache<StringDriveInfocache, @Named(.ExecutorService executor) {
      this. = checkNotNull(client"client");
      this. = checkNotNull(driveNotClaimed"driveNotClaimed");
      this. = checkNotNull(locationSupplier"locationSupplier");
      this. = checkNotNull(defaultVncPassword"defaultVncPassword");
      this. = checkNotNull(cache"cache");
      this. = checkNotNull(executor"executor");
         Map<StringCredentialscredentialStore) {
      long bootSize = (long) (template.getHardware().getVolumes().get(0).getSize() * 1024 * 1024 * 1024l);
      .debug(">> imaging boot drive source(%s) bytes(%d)"template.getImage().getId(), bootSize);
      DriveInfo drive = .cloneDrive(template.getImage().getId(), template.getImage().getId(),
            new CloneDriveOptions().size(bootSize));
      boolean success = .apply(drive);
      .debug("<< image(%s) complete(%s)"drive.getUuid(), success);
      if (!success) {
         throw new IllegalStateException("could not image drive in time!");
      Server toCreate = Servers.small(namedrive.getUuid(), ).mem(template.getHardware().getRam())
            .cpu((int) (template.getHardware().getProcessors().get(0).getSpeed())).build();
      .debug(">> creating server");
      ServerInfo from = .createServer(toCreate);
      .debug("<< created server(%s)"from.getUuid());
      .debug(">> starting server(%s)"from.getUuid());
      // store the credentials so that later functions can use them
      credentialStore.put("node#" + from.getUuid(), new Credentials("root"));
      return from;
      Builder<Hardwarehardware = ImmutableSet.<Hardwarebuilder();
      for (double cpu : new double[] { 1000, 5000, 10000, 20000 })
         for (int ram : new int[] { 512, 1024, 4 * 1024, 16 * 1024, 32 * 1024 }) {
            final float size = (floatcpu / 100;
            String id = String.format("cpu=%f,ram=%s,disk=%f"cpuramsize);
            hardware.add(new HardwareBuilder().supportsImage(new Predicate<Image>() {
               public boolean apply(Image input) {
                  String toParse = input.getUserMetadata().get("size");
                  return (toParse != null && new Float(toParse) <= size);
               public String toString() {
                  return "sizeLessThanOrEqual(" + size + ")";
            }).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu)))
                  .volumes(ImmutableList.<Volumeof(new VolumeImpl(sizetruetrue))).build());

look up the current standard images and do not error out, if they are not found.
   public Iterable<DriveInfolistImages() {
            new Function<StringFuture<DriveInfo>>() {
               public Future<DriveInfoapply(String input) {
                  try {
                     return Futures.immediateFuture(.getUnchecked(input));
                  } catch (NullPointerException e) {
                     .debug("drive %s not found"input);
                  } catch (UncheckedExecutionException e) {
                     .warn(e"error finding drive %s: %s"inpute.getMessage());
                  return Futures.immediateFuture(null);
               public String toString() {
                  return "seedDriveCache()";
            }, null"drives");
      return filter(drives);
   public Iterable<ServerInfolistNodes() {
      return (Iterable<ServerInfo>) .listServerInfo();
   public Iterable<LocationlistLocations() {
      return (Iterable<Location>) .get();
   public ServerInfo getNode(String id) {
      return .getServerInfo(id);
   public void destroyNode(String id) {
      ServerInfo server = getNode(id);
      if (server != null) {
         for (Device dev : server.getDevices().values())
   public void rebootNode(String id) {
   public void resumeNode(String id) {
   public void suspendNode(String id) {
New to GrepCode? Check out our FAQ X