예제 #1
0
 public static ReplicationInstance newReplicationInstanceOf(Action action, InstanceInfo instance) {
   switch (action) {
     case Register:
       return new ReplicationInstance(
           instance.getAppName(),
           instance.getId(),
           System.currentTimeMillis(),
           null,
           instance.getStatus().name(),
           instance,
           action);
     case Cancel:
       return new ReplicationInstance(
           instance.getAppName(),
           instance.getId(),
           System.currentTimeMillis(),
           null,
           null,
           null,
           action);
     case Heartbeat:
       return new ReplicationInstance(
           instance.getAppName(),
           instance.getId(),
           System.currentTimeMillis(),
           InstanceStatus.OUT_OF_SERVICE.name(),
           instance.getStatus().name(),
           instance,
           action);
     case StatusUpdate:
       return new ReplicationInstance(
           instance.getAppName(),
           instance.getId(),
           System.currentTimeMillis(),
           InstanceStatus.OUT_OF_SERVICE.name(),
           null,
           null,
           action);
     case DeleteStatusOverride:
       return new ReplicationInstance(
           instance.getAppName(),
           instance.getId(),
           System.currentTimeMillis(),
           InstanceStatus.OUT_OF_SERVICE.name(),
           null,
           null,
           action);
   }
   throw new IllegalStateException("Unexpected action " + action);
 }
  private List<DiscoveryEnabledServer> obtainServersViaDiscovery() {
    List<DiscoveryEnabledServer> serverList = new ArrayList<DiscoveryEnabledServer>();

    DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
    if (discoveryClient == null) {
      return new ArrayList<DiscoveryEnabledServer>();
    }
    if (vipAddresses != null) {
      for (String vipAddress : vipAddresses.split(",")) {
        // if targetRegion is null, it will be interpreted as the same region of client
        List<InstanceInfo> listOfinstanceInfo =
            discoveryClient.getInstancesByVipAddress(vipAddress, isSecure, targetRegion);
        for (InstanceInfo ii : listOfinstanceInfo) {
          if (ii.getStatus().equals(InstanceStatus.UP)) {

            if (shouldUseOverridePort) {
              if (logger.isDebugEnabled()) {
                logger.debug(
                    "Overriding port on client name: " + clientName + " to " + overridePort);
              }

              // copy is necessary since the InstanceInfo builder just uses the original reference,
              // and we don't want to corrupt the global eureka copy of the object which may be
              // used by other clients in our system
              InstanceInfo copy = new InstanceInfo(ii);

              if (isSecure) {
                ii = new InstanceInfo.Builder(copy).setSecurePort(overridePort).build();
              } else {
                ii = new InstanceInfo.Builder(copy).setPort(overridePort).build();
              }
            }

            DiscoveryEnabledServer des = new DiscoveryEnabledServer(ii, isSecure);
            des.setZone(DiscoveryClient.getZone(ii));
            serverList.add(des);
          }
        }
        if (serverList.size() > 0 && prioritizeVipAddressBasedServers) {
          break; // if the current vipAddress has servers, we dont use subsequent vipAddress based
                 // servers
        }
      }
    }
    return serverList;
  }
예제 #3
0
 public String getStatus(InstanceInfo info) {
   return info.getStatus().name();
 }