Exemplo n.º 1
0
  public String getNextServiceFromEureka(String serviceName) throws ServiceNotFoundException {

    // vipAddress of the Webapp service - Check  acmeair-webapp.properties file
    String vipAddress = serviceName;

    InstanceInfo nextServerInfo = null;
    try {
      nextServerInfo =
          DiscoveryManager.getInstance()
              .getDiscoveryClient()
              .getNextServerFromEureka(vipAddress, false);
    } catch (Exception e) {
      System.out.println("Cannot get an instance of " + vipAddress + "to talk to from eureka : ");
      e.printStackTrace();
      throw new ServiceNotFoundException();
    }

    // return	nextServerInfo.getIPAddr() + ":" + nextServerInfo.getPort();
    // Assume default port
    return nextServerInfo.getIPAddr();
  }
Exemplo n.º 2
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
     * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
     * com.thoughtworks.xstream.converters.MarshallingContext)
     */
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      InstanceInfo info = (InstanceInfo) source;

      if (info.getInstanceId() != null) {
        writer.startNode(ELEM_INSTANCE_ID);
        writer.setValue(info.getInstanceId());
        writer.endNode();
      }

      writer.startNode(ELEM_HOST);
      writer.setValue(info.getHostName());
      writer.endNode();

      writer.startNode(ELEM_APP);
      writer.setValue(info.getAppName());
      writer.endNode();

      writer.startNode(ELEM_IP);
      writer.setValue(info.getIPAddr());
      writer.endNode();

      if (!("unknown".equals(info.getSID()) || "na".equals(info.getSID()))) {
        writer.startNode(ELEM_SID);
        writer.setValue(info.getSID());
        writer.endNode();
      }

      writer.startNode(ELEM_STATUS);
      writer.setValue(getStatus(info));
      writer.endNode();

      writer.startNode(ELEM_OVERRIDDEN_STATUS);
      writer.setValue(info.getOverriddenStatus().name());
      writer.endNode();

      writer.startNode(ELEM_PORT);
      writer.addAttribute(ATTR_ENABLED, String.valueOf(info.isPortEnabled(PortType.UNSECURE)));
      writer.setValue(String.valueOf(info.getPort()));
      writer.endNode();

      writer.startNode(ELEM_SECURE_PORT);
      writer.addAttribute(ATTR_ENABLED, String.valueOf(info.isPortEnabled(PortType.SECURE)));
      writer.setValue(String.valueOf(info.getSecurePort()));
      writer.endNode();

      writer.startNode(ELEM_COUNTRY_ID);
      writer.setValue(String.valueOf(info.getCountryId()));
      writer.endNode();

      if (info.getDataCenterInfo() != null) {
        writer.startNode(NODE_DATACENTER);
        // This is needed for backward compat. for now.
        if (info.getDataCenterInfo().getName() == Name.Amazon) {
          writer.addAttribute("class", "com.netflix.appinfo.AmazonInfo");
        } else {
          writer.addAttribute("class", "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo");
        }
        context.convertAnother(info.getDataCenterInfo());
        writer.endNode();
      }

      if (info.getLeaseInfo() != null) {
        writer.startNode(NODE_LEASE);
        context.convertAnother(info.getLeaseInfo());
        writer.endNode();
      }

      if (info.getMetadata() != null) {
        writer.startNode(NODE_METADATA);
        // for backward compat. for now
        if (info.getMetadata().size() == 0) {
          writer.addAttribute("class", "java.util.Collections$EmptyMap");
        }
        context.convertAnother(info.getMetadata());
        writer.endNode();
      }
      autoMarshalEligible(source, writer);
    }