コード例 #1
0
ファイル: Converters.java プロジェクト: tangjiaxu/eureka
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks
     * .xstream.io.HierarchicalStreamReader,
     * com.thoughtworks.xstream.converters.UnmarshallingContext)
     */
    @Override
    @SuppressWarnings("unchecked")
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
      InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();

      while (reader.hasMoreChildren()) {
        reader.moveDown();

        String nodeName = reader.getNodeName();

        if (ELEM_HOST.equals(nodeName)) {
          builder.setHostName(reader.getValue());
        } else if (ELEM_INSTANCE_ID.equals(nodeName)) {
          builder.setInstanceId(reader.getValue());
        } else if (ELEM_APP.equals(nodeName)) {
          builder.setAppName(reader.getValue());
        } else if (ELEM_IP.equals(nodeName)) {
          builder.setIPAddr(reader.getValue());
        } else if (ELEM_SID.equals(nodeName)) {
          builder.setSID(reader.getValue());
        } else if (ELEM_IDENTIFYING_ATTR.equals(nodeName)) {
          // nothing;
        } else if (ELEM_STATUS.equals(nodeName)) {
          builder.setStatus(InstanceStatus.toEnum(reader.getValue()));
        } else if (ELEM_OVERRIDDEN_STATUS.equals(nodeName)) {
          builder.setOverriddenStatus(InstanceStatus.toEnum(reader.getValue()));
        } else if (ELEM_PORT.equals(nodeName)) {
          builder.setPort(Integer.valueOf(reader.getValue()).intValue());
          // Defaults to true
          builder.enablePort(PortType.UNSECURE, !"false".equals(reader.getAttribute(ATTR_ENABLED)));
        } else if (ELEM_SECURE_PORT.equals(nodeName)) {
          builder.setSecurePort(Integer.valueOf(reader.getValue()).intValue());
          // Defaults to false
          builder.enablePort(PortType.SECURE, "true".equals(reader.getAttribute(ATTR_ENABLED)));
        } else if (ELEM_COUNTRY_ID.equals(nodeName)) {
          builder.setCountryId(Integer.valueOf(reader.getValue()).intValue());
        } else if (NODE_DATACENTER.equals(nodeName)) {
          builder.setDataCenterInfo(
              (DataCenterInfo) context.convertAnother(builder, DataCenterInfo.class));
        } else if (NODE_LEASE.equals(nodeName)) {
          builder.setLeaseInfo((LeaseInfo) context.convertAnother(builder, LeaseInfo.class));
        } else if (NODE_METADATA.equals(nodeName)) {
          builder.setMetadata((Map<String, String>) context.convertAnother(builder, Map.class));
        } else {
          autoUnmarshalEligible(reader, builder.getRawInstance());
        }

        reader.moveUp();
      }

      return builder.build();
    }
コード例 #2
0
 static List<InstanceInfo> getDummyInstanceInfo(String appName, List<Server> serverList) {
   List<InstanceInfo> list = new ArrayList<InstanceInfo>();
   for (Server server : serverList) {
     InstanceInfo info =
         InstanceInfo.Builder.newBuilder()
             .setAppName(appName)
             .setHostName(server.getHost())
             .setPort(server.getPort())
             .build();
     list.add(info);
   }
   return list;
 }
コード例 #3
0
  private DiscoveryEnabledServer createServer(String host, int port, String zone) {
    AmazonInfo amazonInfo =
        AmazonInfo.Builder.newBuilder()
            .addMetadata(AmazonInfo.MetaDataKey.availabilityZone, zone)
            .build();

    Builder builder = InstanceInfo.Builder.newBuilder();
    InstanceInfo info =
        builder
            .setAppName("l10nservicegeneral")
            .setDataCenterInfo(amazonInfo)
            .setHostName(host)
            .setPort(port)
            .build();
    DiscoveryEnabledServer server = new DiscoveryEnabledServer(info, false);
    server.setZone(zone);
    return server;
  }
コード例 #4
0
  public void y() {
    InstanceInfo info =
        InstanceInfo.Builder.newBuilder()
            .setStatus(InstanceStatus.UP)
            .setAppName("testopenam")
            .setHostName("localhost")
            .setPort(8080)
            .setVIPAddress("testopenam")
            //    			.setMetadata(new HashMap() {{put("instanceId", "openam1");}})
            .setDataCenterInfo(new InstanceIdDataCenterInfo("openam1"))
            .setHomePageUrl(
                "/OpenAM-12.0.0/isAlive.jsp", "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp")
            .setStatusPageUrl(
                "/OpenAM-12.0.0/isAlive.jsp", "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp")
            .setHealthCheckUrls(
                "/OpenAM-12.0.0/isAlive.jsp",
                "http://localhost:8080/OpenAM-12.0.0/isAlive.jsp",
                null)
            .build();
    info.getId();

    PeerAwareInstanceRegistry.getInstance().register(info, false);
  }
コード例 #5
0
  // useInstanceId to false to generate older InstanceInfo types that does not use instanceId field
  // for instance id.
  private InstanceInfo generateInstanceInfo(
      int appIndex, int appInstanceId, boolean useInstanceId) {
    String appName = appNames[appIndex];
    String hostName = "instance" + appInstanceId + '.' + appName + ".com";
    String publicIp = "20.0." + appIndex + '.' + appInstanceId;
    String privateIp = "192.168." + appIndex + '.' + appInstanceId;

    String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId);
    if (taggedId) {
      instanceId = instanceId + '_' + appName;
    }

    AmazonInfo dataCenterInfo =
        AmazonInfo.Builder.newBuilder()
            .addMetadata(MetaDataKey.accountId, "testAccountId")
            .addMetadata(MetaDataKey.amiId, String.format("ami-%04d%04d", appIndex, appInstanceId))
            .addMetadata(MetaDataKey.availabilityZone, zone)
            .addMetadata(MetaDataKey.instanceId, instanceId)
            .addMetadata(MetaDataKey.instanceType, "m2.xlarge")
            .addMetadata(MetaDataKey.localIpv4, privateIp)
            .addMetadata(MetaDataKey.publicHostname, hostName)
            .addMetadata(MetaDataKey.publicIpv4, publicIp)
            .build();

    String unsecureURL = "http://" + hostName + ":8080";
    String secureURL = "https://" + hostName + ":8081";

    long now = System.currentTimeMillis();
    LeaseInfo leaseInfo =
        LeaseInfo.Builder.newBuilder()
            .setDurationInSecs(3 * RENEW_INTERVAL)
            .setRenewalIntervalInSecs(RENEW_INTERVAL)
            .setServiceUpTimestamp(now - RENEW_INTERVAL)
            .setRegistrationTimestamp(now)
            .setEvictionTimestamp(now + 3 * RENEW_INTERVAL)
            .setRenewalTimestamp(now + RENEW_INTERVAL)
            .build();

    Builder builder =
        useInstanceId
            ? InstanceInfo.Builder.newBuilder().setInstanceId(instanceId)
            : InstanceInfo.Builder.newBuilder();

    builder
        .setActionType(ActionType.ADDED)
        .setAppGroupName(appName + "Group")
        .setAppName(appName)
        .setHostName(hostName)
        .setIPAddr(publicIp)
        .setPort(8080)
        .setSecurePort(8081)
        .enablePort(PortType.SECURE, true)
        .setHealthCheckUrls(
            "/healthcheck", unsecureURL + "/healthcheck", secureURL + "/healthcheck")
        .setHomePageUrl("/homepage", unsecureURL + "/homepage")
        .setStatusPageUrl("/status", unsecureURL + "/status")
        .setLeaseInfo(leaseInfo)
        .setStatus(InstanceStatus.UP)
        .setVIPAddress(hostName + ":8080")
        .setSecureVIPAddress(hostName + ":8081")
        .setDataCenterInfo(dataCenterInfo)
        .setLastUpdatedTimestamp(System.currentTimeMillis() - 100)
        .setLastDirtyTimestamp(System.currentTimeMillis() - 100)
        .setIsCoordinatingDiscoveryServer(true)
        .enablePort(PortType.UNSECURE, true);
    if (includeAsg) {
      builder.setASGName(appName + "ASG");
    }
    if (withMetaData) {
      builder.add("appKey" + appIndex, Integer.toString(appInstanceId));
    }
    return builder.build();
  }