Exemplo n.º 1
0
  public Applications toApplications() {
    Map<String, Application> appsByName = new HashMap<>();
    Iterator<InstanceInfo> it = serviceIterator();
    while (it.hasNext()) {
      InstanceInfo instanceInfo = it.next();
      Application instanceApp = appsByName.get(instanceInfo.getAppName());
      if (instanceApp == null) {
        instanceApp = new Application(instanceInfo.getAppName());
        appsByName.put(instanceInfo.getAppName(), instanceApp);
      }
      instanceApp.addInstance(instanceInfo);
    }

    // Do not pass application list to the constructor, as it does not initialize properly
    // Applications
    // data structure.
    Applications applications = new Applications();
    for (Application app : appsByName.values()) {
      applications.addApplication(app);
    }

    applications.setAppsHashCode(applications.getReconcileHashCode());

    return applications;
  }
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) {
      Application app = (Application) source;

      writer.startNode(ELEM_NAME);
      writer.setValue(app.getName());
      writer.endNode();

      for (InstanceInfo instanceInfo : app.getInstances()) {
        writer.startNode(NODE_INSTANCE);
        context.convertAnother(instanceInfo);
        writer.endNode();
      }
    }
Exemplo n.º 3
0
  private boolean isReplicaAvailable(String myAppName, String url) {

    try {
      String givenHostName = new URI(url).getHost();
      Application app = PeerAwareInstanceRegistry.getInstance().getApplication(myAppName, false);
      for (InstanceInfo info : app.getInstances()) {
        if (info.getHostName().equals(givenHostName)) {
          return true;
        }
      }
    } catch (Throwable e) {
      logger.error("Could not determine if the replica is available ", e);
    }
    return false;
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(6, 1).build();
    testApplication = instanceInfos.toApplications().getRegisteredApplications().get(0);

    applicationResource =
        new ApplicationResource(
            testApplication.getName(),
            serverContext.getServerConfig(),
            serverContext.getRegistry());

    for (InstanceInfo instanceInfo : testApplication.getInstances()) {
      registry.register(instanceInfo, false);
    }
  }
  @Test
  public void testMiniAppGet() throws Exception {
    Response response =
        applicationResource.getApplication(
            Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.compact.name());

    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);

    Application decodedApp = decoder.decode(json, Application.class);
    // assert false as one is mini, so should NOT equal
    assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false));

    for (InstanceInfo instanceInfo : testApplication.getInstances()) {
      InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
      assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
    }
  }
Exemplo n.º 6
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks
     * .xstream.io.HierarchicalStreamReader,
     * com.thoughtworks.xstream.converters.UnmarshallingContext)
     */
    @Override
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
      Application app = new Application();

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

        String nodeName = reader.getNodeName();

        if (ELEM_NAME.equals(nodeName)) {
          app.setName(reader.getValue());
        } else if (NODE_INSTANCE.equals(nodeName)) {
          app.addInstance((InstanceInfo) context.convertAnother(app, InstanceInfo.class));
        }
        reader.moveUp();
      }
      return app;
    }