[case18] talk about Eureka Server’s REST API

  springcloud

Order

This paper mainly studies the REST API of Eureka Server.

ApplicationsResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/ApplicationsResource.java

@Path("/{version}/apps")
@Produces({"application/xml", "application/json"})
public class ApplicationsResource {
    @Path("{appId}")
    public ApplicationResource getApplicationResource(
            @PathParam("version") String version,
            @PathParam("appId") String appId) {
        CurrentRequestVersion.set(Version.toEnum(version));
        return new ApplicationResource(appId, serverConfig, registry);
    }

    //...
    @GET
    public Response getContainers(@PathParam("version") String version,
                                  @HeaderParam(HEADER_ACCEPT) String acceptHeader,
                                  @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding,
                                  @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept,
                                  @Context UriInfo uriInfo,
                                  @Nullable @QueryParam("regions") String regionsStr) {
                                  //...
    }

    @Path("delta")
    @GET
    public Response getContainerDifferential(
            @PathParam("version") String version,
            @HeaderParam(HEADER_ACCEPT) String acceptHeader,
            @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding,
            @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept,
            @Context UriInfo uriInfo, @Nullable @QueryParam("regions") String regionsStr) { 
            //...
    }                                     

}

Here are three interfaces:

  • /{version}/apps/{appId}
  • /{version}/apps
  • /{version}/apps/delta

For spring cloud eureka, version here is eureka

ApplicationResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/ApplicationResource.java

    @GET
    public Response getApplication(@PathParam("version") String version,
                                   @HeaderParam("Accept") final String acceptHeader,
                                   @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
                                   //...
    } 

    @Path("{id}")
    public InstanceResource getInstanceInfo(@PathParam("id") String id) {
        return new InstanceResource(this, id, serverConfig, registry);
    }        

    @POST
    @Consumes({"application/json", "application/xml"})
    public Response addInstance(InstanceInfo info,
                                @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) {
                                //...
    }                                                  

Three interfaces are provided here

  • /{version}
  • /{id}
  • POST /

InstancesResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/InstancesResource.java

@Produces({"application/xml", "application/json"})
@Path("/{version}/instances")
public class InstancesResource {
    @GET
    @Path("{id}")
    public Response getById(@PathParam("version") String version,
                            @PathParam("id") String id) {
                            //...
    }


}

An interface is provided here.

  • /{version}/instances/{id}

StatusResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/StatusResource.java

@Path("/{version}/status")
@Produces({"application/xml", "application/json"})
public class StatusResource {
    @GET
    public StatusInfo getStatusInfo() {
        return statusUtil.getStatusInfo();
    }
    //...
}

An interface is provided here.

  • /{version}/status

VIPResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/VIPResource.java

@Path("/{version}/vips")
@Produces({"application/xml", "application/json"})
public class VIPResource extends AbstractVIPResource {
    @GET
    @Path("{vipAddress}")
    public Response statusUpdate(@PathParam("version") String version,
                                 @PathParam("vipAddress") String vipAddress,
                                 @HeaderParam("Accept") final String acceptHeader,
                                 @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
        return getVipResponse(version, vipAddress, acceptHeader,
                EurekaAccept.fromString(eurekaAccept), Key.EntityType.VIP);
    }
}

An interface is provided here.

  • /{version}/vips/{vipAddress}

SecureVIPResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/SecureVIPResource.java

@Path("/{version}/svips")
@Produces({"application/xml", "application/json"})
public class SecureVIPResource extends AbstractVIPResource {
    @GET
    @Path("{svipAddress}")
    public Response statusUpdate(@PathParam("version") String version,
                                 @PathParam("svipAddress") String svipAddress,
                                 @HeaderParam("Accept") final String acceptHeader,
                                 @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
        return getVipResponse(version, svipAddress, acceptHeader,
                EurekaAccept.fromString(eurekaAccept), Key.EntityType.SVIP);
    }
}

An interface is provided here.

  • /{version}/svips/{svipAddress}

PeerReplicationResource

eureka-core-1.8.8-sources.jar! /com/netflix/eureka/resources/PeerReplicationResource.java

@Path("/{version}/peerreplication")
@Produces({"application/xml", "application/json"})
public class PeerReplicationResource {
    @Path("batch")
    @POST
    public Response batchReplication(ReplicationList replicationList) {
        //....
    }
}

An interface is provided here.

  • POST /{version}/peerreplication/batch

Summary

Eureka server’s rest api is implemented using javax.ws Then the version of spring cloud, whose version passes the eureka value. The interface implemented with javax.ws feels very difficult to find mapping and a little difficult compared with spring mvc.

doc