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);
}
}
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);
}
Aggregations