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 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.cloudsigma.compute.functions;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 

Author(s):
Adrian Cole
 
 public class ServerInfoToNodeMetadata implements Function<ServerInfoNodeMetadata> {
    public static final Map<ServerStatusNodeStateserverStatusToNodeState = ImmutableMap
          .put(..)//
          .put(..)//
          .put(..)//
          .put(..)//
          .build();
 
    private final Function<ServerStringgetImageIdFromServer;
    private final Function<StringImagefindImageForId;
    private final Map<StringCredentialscredentialStore;
    private final Supplier<LocationlocationSupplier;
    private final Function<DeviceVolumedeviceToVolume;
 
    @Inject
    ServerInfoToNodeMetadata(Map<StringCredentialscredentialStoreFunction<ServerStringgetImageIdFromServer,
          Function<StringImagefindImageForIdFunction<DeviceVolumedeviceToVolume,
          Supplier<LocationlocationSupplier) {
       this. = checkNotNull(credentialStore"credentialStore");
       this. = checkNotNull(locationSupplier"locationSupplier");
       this. = checkNotNull(deviceToVolume"deviceToVolume");
       this. = checkNotNull(findImageForId"findImageForId");
       this. = checkNotNull(getImageIdFromServer"getImageIdFromServer");
    }
 
    @SuppressWarnings({ "unchecked""rawtypes" })
    @Override
    public NodeMetadata apply(ServerInfo from) {
       NodeMetadataBuilder builder = new NodeMetadataBuilder();
       builder.ids(from.getUuid());
       builder.name(from.getName());
       builder.location(.get());
       builder.group(parseGroupFromName(from.getName()));
 
      String imageId = .apply(from);
      if (imageId != null) {
         Image image = .apply(imageId);
         if (image != null) {
            builder.operatingSystem(image.getOperatingSystem());
            builder.adminPassword(image.getAdminPassword());
         }
      }
      builder.hardware(new HardwareBuilder().ids(from.getUuid())
            .processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem())
            .volumes((List) ImmutableList.of(Iterables.transform(from.getDevices().values(), ))).build());
      builder.state(.get(from.getStatus()));
      builder.publicAddresses(ImmutableSet.<Stringof(from.getVnc().getIp()));
      builder.privateAddresses(ImmutableSet.<Stringof());
      builder.credentials(.get("node#"from.getUuid()));
      return builder.build();
   }
   public static final class DeviceToVolume implements Function<DeviceVolume> {
      @Resource
      protected Logger logger = .;
      private final Cache<StringDriveInfocache;
      @Inject
      public DeviceToVolume(Cache<StringDriveInfocache) {
         this. = checkNotNull(cache"cache");
      }
      @Override
      public Volume apply(Device input) {
         VolumeBuilder builder = new VolumeBuilder();
         builder.id(input.getId());
         try {
            DriveInfo drive = .getUnchecked(input.getDriveUuid());
            builder.size(drive.getSize() / 1024 / 1024f);
         } catch (NullPointerException e) {
            .debug("drive %s not found"input.getDriveUuid());
         } catch (UncheckedExecutionException e) {
            .warn(e"error finding drive %s: %s"input.getDriveUuid(), e.getMessage());
         }
         return new VolumeBuilder().durable(true).type(..).build();
      }
   }

   
When we create the boot drive of the server, by convention we set the name to the image it came from.

Author(s):
Adrian Cole
   public static class GetImageIdFromServer implements Function<ServerString> {
      @Resource
      protected Logger logger = .;
      private final Cache<StringDriveInfocache;
      @Inject
      public GetImageIdFromServer(Cache<StringDriveInfocache) {
         this. = cache;
      }
      @Override
      public String apply(Server from) {
         String imageId = null;
         String bootDeviceId = Iterables.get(from.getBootDeviceIds(), 0);
         Device bootDevice = from.getDevices().get(bootDeviceId);
         if (bootDevice != null) {
            try {
               DriveInfo drive = .getUnchecked(bootDevice.getDriveUuid());
               imageId = drive.getName();
            } catch (NullPointerException e) {
               .debug("drive %s not found"bootDevice.getDriveUuid());
            } catch (UncheckedExecutionException e) {
               .warn(e"error finding drive %s: %s"bootDevice.getDriveUuid(), e.getMessage());
            }
         }
         return imageId;
      }
   }
   public static class FindImageForId extends FindResourceInSet<StringImage> {
      @Inject
      public FindImageForId(@Memoized Supplier<Set<? extends Image>> images) {
         super(images);
      }
      @Override
      public boolean matches(String fromImage input) {
         return input.getProviderId().equals(from);
      }
   }
New to GrepCode? Check out our FAQ X