org.jclouds.compute.functions.GroupNamingConvention.uniqueNameForGroup()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(67)

本文整理了Java中org.jclouds.compute.functions.GroupNamingConvention.uniqueNameForGroup()方法的一些代码示例,展示了GroupNamingConvention.uniqueNameForGroup()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroupNamingConvention.uniqueNameForGroup()方法的具体详情如下:
包路径:org.jclouds.compute.functions.GroupNamingConvention
类名称:GroupNamingConvention
方法名:uniqueNameForGroup

GroupNamingConvention.uniqueNameForGroup介绍

[英]encodes the {code group parameter} into a name that exists more than once in the group.

note

Do not expect this name to be guaranteed unique, though a good implementation should guess a unique name in one or two tries.
[中]将{code group parameter}编码为组中多次存在的名称。
####注
不要期望这个名称被保证是唯一的,尽管一个好的实现应该在一两次尝试中猜出一个唯一的名称。

代码示例

代码示例来源:origin: jclouds/legacy-jclouds

/**
* Find the next node names that can be used. These will be derived from the group and the
* template. We will pre-allocate a specified quantity, and attempt to verify that there is no
* name conflict with the current service.
* 
* @param group
* @param count
* @param template
* @return
*/
protected Set<String> getNextNames(final String group, final Template template, int count) {
 Set<String> names = newLinkedHashSet();
 Iterable<? extends ComputeMetadata> currentNodes = listNodesStrategy.listNodes();
 int maxTries = 100;
 int currentTries = 0;
 while (names.size() < count && currentTries++ < maxTries) {
   final String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(group);
   if (!any(currentNodes, new Predicate<ComputeMetadata>() {
    @Override
    public boolean apply(ComputeMetadata input) {
      return name.equals(input.getName());
    }
   })) {
    names.add(name);
   }
 }
 return names;
}

代码示例来源:origin: org.apache.jclouds.api/ec2

@VisibleForTesting
  KeyPair createNewKeyPairInRegion(String region, String group) {
   checkNotNull(region, "region");
   checkNotNull(group, "group");
   logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
   KeyPair keyPair = null;
   String prefix = group;
   
   while (keyPair == null) {
     String keyName = namingConvention.create().uniqueNameForGroup(prefix);
     try {
      keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName);
     } catch (IllegalStateException e) {
      logger.trace("   invalid keyname (%s in %s); retrying", keyName, region);
     }
   }
   
   logger.debug("<< created keyPair(%s)", keyPair);
   return keyPair;
  }
}

代码示例来源:origin: com.amysta.jclouds.api/ec2

@VisibleForTesting
  KeyPair createNewKeyPairInRegion(String region, String group) {
   checkNotNull(region, "region");
   checkNotNull(group, "group");
   logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
   KeyPair keyPair = null;
   String prefix = group;
   
   while (keyPair == null) {
     String keyName = namingConvention.create().uniqueNameForGroup(prefix);
     try {
      keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName);
     } catch (IllegalStateException e) {
      logger.trace("   invalid keyname (%s in %s); retrying", keyName, region);
     }
   }
   
   logger.debug("<< created keyPair(%s)", keyPair);
   return keyPair;
  }
}

代码示例来源:origin: apache/jclouds

@VisibleForTesting
  KeyPair createNewKeyPairInRegion(String region, String group) {
   checkNotNull(region, "region");
   checkNotNull(group, "group");
   logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
   KeyPair keyPair = null;
   String prefix = group;
   
   while (keyPair == null) {
     String keyName = namingConvention.create().uniqueNameForGroup(prefix);
     try {
      keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName);
     } catch (IllegalStateException e) {
      logger.trace("   invalid keyname (%s in %s); retrying", keyName, region);
     }
   }
   
   logger.debug("<< created keyPair(%s)", keyPair);
   return keyPair;
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@VisibleForTesting
  KeyPair createNewKeyPairInRegion(String region, String group) {
   checkNotNull(region, "region");
   checkNotNull(group, "group");
   logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
   KeyPair keyPair = null;
   String prefix = group;
   
   while (keyPair == null) {
     String keyName = namingConvention.create().uniqueNameForGroup(prefix);
     try {
      keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region, keyName);
     } catch (IllegalStateException e) {
      logger.trace("   invalid keyname (%s in %s); retrying", keyName, region);
     }
   }
   
   logger.debug("<< created keyPair(%s)", keyPair);
   return keyPair;
  }
}

代码示例来源:origin: org.jclouds.api/ec2

@VisibleForTesting
  KeyPair createNewKeyPairInRegion(String region, String group) {
   checkNotNull(region, "region");
   checkNotNull(group, "group");
   logger.debug(">> creating keyPair region(%s) group(%s)", region, group);
   KeyPair keyPair = null;
   String prefix = group;
   
   while (keyPair == null) {
     String keyName = namingConvention.create().uniqueNameForGroup(prefix);
     try {
      keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region, keyName);
     } catch (IllegalStateException e) {
      logger.trace("   invalid keyname (%s in %s); retrying", keyName, region);
     }
   }
   
   logger.debug("<< created keyPair(%s)", keyPair);
   return keyPair;
  }
}

代码示例来源:origin: org.apache.jclouds.labs/azurecompute-arm

private PublicIPAddress createPublicIp(String resourceGroup, String location, String nodeName) {
 String name = namingConvention.uniqueNameForGroup(nodeName);
 
 PublicIPAddressProperties properties = PublicIPAddressProperties.builder()
    .publicIPAllocationMethod("Static")
    .idleTimeoutInMinutes(4)
    .build();
 
 logger.debug(">> allocating new public ip address: %s", name);
 PublicIPAddress ip = api.getPublicIPAddressApi(resourceGroup).createOrUpdate(name, location,
    ImmutableMap.of("jclouds", nodeName, AUTOGENERATED_IP_KEY, "true"), properties);
 checkState(publicIpAvailable.create(resourceGroup).apply(name),
     "Public IP was not provisioned in the configured timeout");
 
 return ip;
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public KeyPair load(ZoneAndName zoneAndName) {
 String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
 String prefix = zoneAndName.getName();
 Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
 checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
    zoneId);
 logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);
 KeyPair keyPair = null;
 while (keyPair == null) {
   try {
    keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
   } catch (IllegalStateException e) {
   }
 }
 logger.debug("<< created keyPair(%s)", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: apache/jclouds

private void generateKeyPairAndAddKeyToSet(PacketTemplateOptions options, Set<String> generatedSshKeyIds,
   String prefix) {
 logger.debug(">> creating default keypair for node...");
 Map<String, String> defaultKeys = keyGenerator.get();
 SshKey sshKey = api.sshKeyApi().create(namingConvention.create().uniqueNameForGroup(prefix),
    defaultKeys.get("public"));
 generatedSshKeyIds.add(sshKey.id());
 logger.debug(">> keypair created! %s", sshKey);
 // If a private key has not been explicitly set, configure the generated
 // one
 if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) {
   options.overrideLoginPrivateKey(defaultKeys.get("private"));
 }
}

代码示例来源:origin: apache/jclouds

private PublicIPAddress createPublicIp(String resourceGroup, String location, String nodeName) {
 String name = namingConvention.uniqueNameForGroup(nodeName);
 
 PublicIPAddressProperties properties = PublicIPAddressProperties.builder()
    .publicIPAllocationMethod("Static")
    .idleTimeoutInMinutes(4)
    .build();
 
 logger.debug(">> allocating new public ip address: %s", name);
 PublicIPAddress ip = api.getPublicIPAddressApi(resourceGroup).createOrUpdate(name, location,
    ImmutableMap.of("jclouds", nodeName, AUTOGENERATED_IP_KEY, "true"), null, properties);
 checkState(publicIpAvailable.create(resourceGroup).apply(name),
     "Public IP was not provisioned in the configured timeout");
 
 return ip;
}

代码示例来源:origin: io.cloudsoft.jclouds.api/openstack-nova

@Override
public KeyPair load(ZoneAndName zoneAndName) {
 String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
 String prefix = zoneAndName.getName();
 Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
 checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
    zoneId);
 logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);
 KeyPair keyPair = null;
 while (keyPair == null) {
   try {
    keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
   } catch (IllegalStateException e) {
   }
 }
 logger.debug("<< created keyPair(%s)", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: com.amysta.jclouds.api/openstack-nova

@Override
public KeyPair load(RegionAndName regionAndName) {
 String regionId = checkNotNull(regionAndName, "regionAndName").getRegion();
 String prefix = regionAndName.getName();
 Optional<? extends KeyPairApi> api = novaApi.getKeyPairApi(regionId);
 checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in region %s!",
    regionId);
 logger.debug(">> creating keyPair region(%s) prefix(%s)", regionId, prefix);
 KeyPair keyPair = null;
 while (keyPair == null) {
   try {
    keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
   } catch (IllegalStateException e) {
   }
 }
 logger.debug("<< created keyPair(%s)", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: org.jclouds.api/openstack-nova

@Override
public KeyPair load(ZoneAndName zoneAndName) {
 String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
 String prefix = zoneAndName.getName();
 Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
 checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
    zoneId);
 logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix);
 KeyPair keyPair = null;
 while (keyPair == null) {
   try {
    keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
   } catch (IllegalStateException e) {
   }
 }
 logger.debug("<< created keyPair(%s)", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: org.apache.jclouds.api/openstack-nova

private KeyPair generateKeyPair(String region, String prefix) {
 logger.debug(">> creating default keypair for node...");
 KeyPair keyPair = novaApi.getKeyPairApi(region).get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
 logger.debug(">> keypair created! %s", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: apache/jclouds

private KeyPair generateKeyPair(String region, String prefix) {
 logger.debug(">> creating default keypair for node...");
 KeyPair keyPair = novaApi.getKeyPairApi(region).get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix));
 logger.debug(">> keypair created! %s", keyPair.getName());
 return keyPair;
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testCanChangeSuffixSupplier() {
 GroupNamingConvention fn = Guice.createInjector(new AbstractModule() {
   @Override
   protected void configure() {
    bind(new TypeLiteral<Supplier<String>>() {
    }).toInstance(Suppliers.ofInstance("foo"));
   }
 }).getInstance(GroupNamingConvention.Factory.class).create();
 assertEquals(fn.uniqueNameForGroup("cluster"), "jclouds-cluster-foo");
 // note accidental treatment of a unique node as a shared one can lead to 
 // incorrect group names, as long as we permit delimiter to be in group name
 assertEquals(fn.groupInSharedNameOrNull("jclouds-cluster-foo"), "cluster-foo");
 assertEquals(fn.groupInUniqueNameOrNull("jclouds-cluster-foo"), "cluster");
 assertTrue(fn.containsGroup("cluster").apply("jclouds-cluster-foo"));
}

代码示例来源:origin: apache/jclouds

public void testCanChangeSuffixSupplier() {
 GroupNamingConvention fn = Guice.createInjector(new AbstractModule() {
   @Override
   protected void configure() {
    bind(new TypeLiteral<Supplier<String>>() {
    }).toInstance(Suppliers.ofInstance("foo"));
   }
 }).getInstance(GroupNamingConvention.Factory.class).create();
 assertEquals(fn.uniqueNameForGroup("cluster"), "jclouds-cluster-foo");
 // note accidental treatment of a unique node as a shared one can lead to 
 // incorrect group names, as long as we permit delimiter to be in group name
 assertEquals(fn.groupInSharedNameOrNull("jclouds-cluster-foo"), "cluster-foo");
 assertEquals(fn.groupInUniqueNameOrNull("jclouds-cluster-foo"), "cluster");
 assertTrue(fn.containsGroup("cluster").apply("jclouds-cluster-foo"));
}

代码示例来源:origin: org.jclouds.labs/joyent-sdc

@Override
public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) {
 String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter();
 String prefix = datacenterAndName.getName();
 
 Map<String, String> keyPair = SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom.get());
 String publicKey = keyPair.get("public");
 String privateKey = keyPair.get("private");
 logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix);
 Key key = null;
 while (key == null) {
   String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix);
   try {
    key = sdcClient.getKeyClient().create(Key.builder().name(name).key(publicKey).build());
   } catch (IllegalStateException e) {
    logger.trace("error creating keypair named %s, %s", name, e.getMessage());
   }
 }
 logger.debug("<< created key(%s)", key.getName());
 return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey);
}

代码示例来源:origin: io.cloudsoft.jclouds.labs/joyent-cloudapi

@Override
public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) {
 String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter();
 String prefix = datacenterAndName.getName();
 Map<String, String> keyPair = sshKeyPairGenerator.get();
 String publicKey = keyPair.get("public");
 String privateKey = keyPair.get("private");
 logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix);
 Key key = null;
 while (key == null) {
   String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix);
   try {
    key = cloudApiApi.getKeyApi().create(Key.builder().name(name).key(publicKey).build());
   } catch (IllegalStateException e) {
    logger.trace("error creating keypair named %s, %s", name, e.getMessage());
   }
 }
 logger.debug("<< created key(%s)", key.getName());
 return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey);
}

代码示例来源:origin: org.apache.jclouds.labs/joyent-cloudapi

@Override
public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) {
 String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter();
 String prefix = datacenterAndName.getName();
 Map<String, String> keyPair = sshKeyPairGenerator.get();
 String publicKey = keyPair.get("public");
 String privateKey = keyPair.get("private");
 logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix);
 Key key = null;
 while (key == null) {
   String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix);
   try {
    key = cloudApiApi.getKeyApi().create(Key.builder().name(name).key(publicKey).build());
   } catch (IllegalStateException e) {
    logger.trace("error creating keypair named %s, %s", name, e.getMessage());
   }
 }
 logger.debug("<< created key(%s)", key.getName());
 return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey);
}

相关文章