コード例 #1
0
 public TemplateBuilder createTemplateBuilder() {
   final Supplier<Set<? extends Image>> images =
       Suppliers.<Set<? extends Image>>ofInstance(
           ImmutableSet.of(
               new ImageBuilder()
                   .providerId("ebs-image-provider")
                   .name("image")
                   .id("us-east-1/bogus-image")
                   .location(jcloudsDomainLocation)
                   .userMetadata(ImmutableMap.of("rootDeviceType", RootDeviceType.EBS.value()))
                   .operatingSystem(
                       new OperatingSystem(
                           OsFamily.UBUNTU,
                           null,
                           "1.0",
                           VirtualizationType.PARAVIRTUAL.value(),
                           "ubuntu",
                           true))
                   .description("description")
                   .version("1.0")
                   .defaultCredentials(LoginCredentials.builder().user("root").build())
                   .status(Image.Status.AVAILABLE)
                   .build()));
   ImmutableMap<RegionAndName, Image> imageMap =
       (ImmutableMap<RegionAndName, Image>) ImagesToRegionAndIdMap.imagesToMap(images.get());
   Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache =
       Suppliers.<LoadingCache<RegionAndName, ? extends Image>>ofInstance(
           CacheBuilder.newBuilder()
               .<RegionAndName, Image>build(CacheLoader.from(Functions.forMap(imageMap))));
   JcloudsStubTemplateBuilder jcloudsStubTemplateBuilder = new JcloudsStubTemplateBuilder();
   return jcloudsStubTemplateBuilder.newTemplateBuilder(images, imageCache);
 }
  private PresentWhenExtensionAnnotationMatchesExtensionSet whenExtensionsAndAliasesInRegionInclude(
      String region, final Set<Extension> extensions, final Multimap<URI, URI> aliases) {
    final LoadingCache<String, Set<? extends Extension>> extensionsForRegion =
        CacheBuilder.newBuilder()
            .build(
                CacheLoader.from(
                    Functions.forMap(
                        ImmutableMap.<String, Set<? extends Extension>>of(
                            region, extensions, "differentregion", ImmutableSet.<Extension>of()))));

    PresentWhenExtensionAnnotationMatchesExtensionSet fn =
        Guice.createInjector(
                new AbstractModule() {
                  @Override
                  protected void configure() {
                    MapBinder<URI, URI> aliasBindings =
                        MapBinder.newMapBinder(
                                binder(), URI.class, URI.class, NamespaceAliases.class)
                            .permitDuplicates();
                    for (URI key : aliases.keySet()) {
                      for (URI value : aliases.get(key)) {
                        aliasBindings.addBinding(key).toInstance(value);
                      }
                    }
                  }

                  @Provides
                  LoadingCache<String, Set<? extends Extension>> getExtensions() {
                    return extensionsForRegion;
                  }
                })
            .getInstance(PresentWhenExtensionAnnotationMatchesExtensionSet.class);

    return fn;
  }
コード例 #3
0
  @Override
  public Statement apply(String group) {
    checkNotNull(group, "group");
    String validatorClientName = validatorName.get();
    PrivateKey validatorKey = validatorCredential.get();

    JsonBall bootstrapConfig = null;
    try {
      bootstrapConfig = bootstrapConfigForGroup.load(group);
    } catch (Exception e) {
      throw propagate(e);
    }

    Map<String, JsonBall> config =
        json.fromJson(bootstrapConfig.toString(), BootstrapConfigForGroup.BOOTSTRAP_CONFIG_TYPE);
    Optional<JsonBall> environment = Optional.fromNullable(config.get("environment"));

    String chefConfigDir = "{root}etc{fs}chef";
    Statement createChefConfigDir = exec("{md} " + chefConfigDir);
    Statement createClientRb =
        appendFile(
            chefConfigDir + "{fs}client.rb",
            ImmutableList.of(
                "require 'rubygems'",
                "require 'ohai'",
                "o = Ohai::System.new",
                "o.all_plugins",
                String.format("node_name \"%s-\" + o[:ipaddress]", group),
                "log_level :info",
                "log_location STDOUT",
                String.format("validation_client_name \"%s\"", validatorClientName),
                String.format("chef_server_url \"%s\"", endpoint.get())));

    Statement createValidationPem =
        appendFile(
            chefConfigDir + "{fs}validation.pem",
            Splitter.on(newLinePattern).split(Pems.pem(validatorKey)));

    String chefBootFile = chefConfigDir + "{fs}first-boot.json";
    Statement createFirstBoot =
        appendFile(chefBootFile, Collections.singleton(json.toJson(bootstrapConfig)));

    ImmutableMap.Builder<String, String> options = ImmutableMap.builder();
    options.put("-j", chefBootFile);
    if (environment.isPresent()) {
      options.put("-E", environment.get().toString());
    }
    String strOptions = Joiner.on(' ').withKeyValueSeparator(" ").join(options.build());
    Statement runChef = exec("chef-client " + strOptions);

    return newStatementList(
        new ExitInsteadOfReturn(installChef),
        createChefConfigDir,
        createClientRb,
        createValidationPem,
        createFirstBoot,
        runChef);
  }
コード例 #4
0
ファイル: Ddb.java プロジェクト: saitxuc/hippo-java
 @SuppressWarnings("unchecked")
 @Override
 public synchronized V get(@Nonnull Object key) throws RuntimeException {
   V v = super.get(key);
   if (v == null) {
     try {
       v = loader.load((K) key);
       super.put((K) key, v);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
   return v;
 }
コード例 #5
0
ファイル: CacheContext.java プロジェクト: ramgtv/caffeine
 public <K, V> LoadingCache<K, V> build(CacheLoader<K, V> loader) {
   LoadingCache<K, V> cache = null;
   if (isCaffeine()) {
     cache = isAsync() ? caffeine.buildAsync(loader).synchronous() : caffeine.build(loader);
   } else {
     cache =
         new GuavaLoadingCache<>(
             guava.build(
                 com.google.common.cache.CacheLoader.asyncReloading(
                     new SingleLoader<>(loader), executor.delegate())),
             ticker(),
             isRecordingStats());
   }
   this.cache = cache;
   return cache;
 }
コード例 #6
0
 @Override
 protected CacheLoader<String, Optional<String>> bucketToRegion(
     @Region Supplier<Set<String>> regionSupplier, final S3Client client) {
   return CacheLoader.<String, Optional<String>>from(
       Functions.forMap(
           ImmutableMap.<String, Optional<String>>builder()
               .put("bucket", Optional.<String>absent())
               .put("destinationbucket", Optional.<String>absent())
               .put("bucket-us-standard", Optional.of("us-standard"))
               .put("bucket-us-west-1", Optional.of("us-west-1"))
               .put("bucket-us-west-2", Optional.of("us-west-2"))
               .put("bucket-eu-west-1", Optional.of("eu-west-1"))
               .put("bucket-sa-east-1", Optional.of("sa-east-1"))
               .put("bucket-ap-southeast-1", Optional.of("ap-southeast-1"))
               .put("bucket-ap-northeast-1", Optional.of("ap-northeast-1"))
               .build()));
 }