Search in sources :

Example 1 with PomVersion

use of com.spotify.helios.common.PomVersion in project helios by spotify.

the class VersionResponseFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // If ever there was a valid use of goto, this would be it... if Java had it.
    if (!(request instanceof HttpServletRequest)) {
        log.debug("request is not HTTP");
        chain.doFilter(request, response);
        return;
    }
    final HttpServletRequest httpReq = (HttpServletRequest) request;
    final HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.addHeader(HELIOS_SERVER_VERSION_HEADER, SERVER_VERSION.toString());
    final String header = httpReq.getHeader(HELIOS_VERSION_HEADER);
    if (header == null) {
        log.debug("No header " + HELIOS_VERSION_HEADER);
        httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, MISSING.toString());
        chain.doFilter(request, response);
        return;
    }
    final PomVersion clientVersion;
    try {
        clientVersion = PomVersion.parse(header);
    } catch (RuntimeException e) {
        log.debug("failure to parse version header " + header);
        httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, INVALID.toString());
        httpResponse.sendError(400, "Helios client version format is bogus - expect n.n.n");
        return;
    }
    metrics.clientVersion(clientVersion.toString());
    final Status status = getStatus(SERVER_VERSION, clientVersion);
    httpResponse.addHeader(HELIOS_VERSION_STATUS_HEADER, status.toString());
    if (status == Status.INCOMPATIBLE) {
        log.debug("version " + clientVersion + " is incompatible");
        httpResponse.sendError(426, "Your client version is incompatible with the server version " + POM_VERSION);
    } else {
        log.debug("version " + clientVersion + " state " + status);
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VersionCompatibility.getStatus(com.spotify.helios.common.VersionCompatibility.getStatus) Status(com.spotify.helios.common.VersionCompatibility.Status) PomVersion(com.spotify.helios.common.PomVersion) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 2 with PomVersion

use of com.spotify.helios.common.PomVersion in project helios by spotify.

the class VersionResource method versionCheck.

/**
   * Given the client version, returns the version status, i.e. whether or not they should be
   * compatible or not.
   * @param client The client version.
   * @return The VersionCheckResponse object.
   */
@GET
@Path("/check")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public VersionCheckResponse versionCheck(@QueryParam("client") @DefaultValue("") final String client) {
    final PomVersion serverVersion = PomVersion.parse(Version.POM_VERSION);
    final VersionCompatibility.Status status;
    if (isNullOrEmpty(client)) {
        return new VersionCheckResponse(VersionCompatibility.Status.MISSING, serverVersion, Version.RECOMMENDED_VERSION);
    }
    final PomVersion clientVersion = PomVersion.parse(client);
    status = VersionCompatibility.getStatus(serverVersion, clientVersion);
    return new VersionCheckResponse(status, serverVersion, Version.RECOMMENDED_VERSION);
}
Also used : VersionCheckResponse(com.spotify.helios.common.VersionCheckResponse) VersionCompatibility(com.spotify.helios.common.VersionCompatibility) PomVersion(com.spotify.helios.common.PomVersion) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

PomVersion (com.spotify.helios.common.PomVersion)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 VersionCheckResponse (com.spotify.helios.common.VersionCheckResponse)1 VersionCompatibility (com.spotify.helios.common.VersionCompatibility)1 Status (com.spotify.helios.common.VersionCompatibility.Status)1 VersionCompatibility.getStatus (com.spotify.helios.common.VersionCompatibility.getStatus)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1