Esempio n. 1
0
public class UniqueIscsiTargetBuilder implements Builder<UniqueIscsiTarget> {
  private static final Random random = new Random();

  private String uuid = UUID.randomUUID().toString();
  private String storageIpAddress = InetAddresses.fromInteger(random.nextInt()).getHostAddress();
  private String storageAgentUrl = "http://" + randomAlphabetic(4) + ".example.com";
  private IscsiTarget iscsiTarget = IscsiTargetBuilder.anIscsiTarget().build();

  public static UniqueIscsiTargetBuilder aUniqueIscsiTarget() {
    return new UniqueIscsiTargetBuilder();
  }

  @Override
  public UniqueIscsiTarget build() {
    return new UniqueIscsiTarget(uuid, storageIpAddress, storageAgentUrl, iscsiTarget);
  }
}
Esempio n. 2
0
  public NodeInfo(
      String environment,
      String pool,
      String nodeId,
      InetAddress nodeIp,
      String location,
      String binarySpec,
      String configSpec) {
    Preconditions.checkNotNull(environment, "environment is null");
    Preconditions.checkNotNull(pool, "pool is null");
    Preconditions.checkArgument(
        environment.matches(NodeConfig.ENV_REGEXP),
        String.format("environment '%s' is invalid", environment));
    Preconditions.checkArgument(
        pool.matches(NodeConfig.POOL_REGEXP), String.format("pool '%s' is invalid", pool));

    this.environment = environment;
    this.pool = pool;

    if (nodeId != null) {
      this.nodeId = nodeId;
    } else {
      this.nodeId = UUID.randomUUID().toString();
    }

    if (location != null) {
      this.location = location;
    } else {
      this.location = "/" + this.nodeId;
    }

    this.binarySpec = binarySpec;
    this.configSpec = configSpec;

    if (nodeIp != null) {
      this.publicIp = nodeIp;
      this.bindIp = nodeIp;
    } else {
      this.publicIp = findPublicIp();
      this.bindIp = InetAddresses.fromInteger(0);
    }
  }
Esempio n. 3
0
 public static String getRandomIpAddress() {
   return InetAddresses.fromInteger(RAND.nextInt()).getHostAddress();
 }
Esempio n. 4
0
  public NodeInfo(
      String environment,
      String pool,
      String nodeId,
      InetAddress internalIp,
      String internalHostname,
      InetAddress bindIp,
      String externalAddress,
      String location,
      String binarySpec,
      String configSpec) {
    Preconditions.checkNotNull(environment, "environment is null");
    Preconditions.checkNotNull(pool, "pool is null");
    Preconditions.checkArgument(
        environment.matches(NodeConfig.ENV_REGEXP),
        String.format("environment '%s' is invalid", environment));
    Preconditions.checkArgument(
        pool.matches(NodeConfig.POOL_REGEXP), String.format("pool '%s' is invalid", pool));

    this.environment = environment;
    this.pool = pool;

    if (nodeId != null) {
      this.nodeId = nodeId;
    } else {
      this.nodeId = UUID.randomUUID().toString();
    }

    if (location != null) {
      this.location = location;
    } else {
      this.location = "/" + this.nodeId;
    }

    this.binarySpec = binarySpec;
    this.configSpec = configSpec;

    if (internalIp != null) {
      this.internalIp = internalIp;
    } else {
      this.internalIp = findPublicIp();
    }

    if (internalHostname != null) {
      Preconditions.checkArgument(
          internalHostname.matches(NodeConfig.HOSTNAME_REGEXP),
          String.format("hostname '%s' is invalid", environment));
      this.internalHostname = internalHostname;
    } else {
      this.internalHostname = findPublicHostname();
    }

    if (bindIp != null) {
      this.bindIp = bindIp;
    } else {
      this.bindIp = InetAddresses.fromInteger(0);
    }

    if (externalAddress != null) {
      this.externalAddress = externalAddress;
    } else {
      this.externalAddress = InetAddresses.toAddrString(this.internalIp);
    }
  }
Esempio n. 5
0
 public void testFromInteger() {
   assertEquals(InetAddresses.fromInteger(0x7f000001), InetAddresses.forString("127.0.0.1"));
 }