if (archiveName == null || archiveName.isEmpty()) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, ARCHIVE_NAME_HEADER + " header not present");
}
final SessionInfo sessionInfo = new SessionInfo(accountId, appId, archiveName, archive, DeployStatus.UPLOADING);
sessions.put(accountId, sessionInfo);
return new BodyConsumer() {
@Override
public void chunk(ChannelBuffer request, HttpResponder responder) {
try {
request.readBytes(os, request.readableBytes());
} catch (IOException e) {
sessionInfo.setStatus(DeployStatus.FAILED);
LOG.error("Failed to write deploy jar", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
@Override
public void finished(HttpResponder responder) {
try {
os.close();
sessionInfo.setStatus(DeployStatus.VERIFYING);
deploy(accountId, appId, archive);
sessionInfo.setStatus(DeployStatus.DEPLOYED);
responder.sendString(HttpResponseStatus.OK, "Deploy Complete");
} catch (Exception e) {
sessionInfo.setStatus(DeployStatus.FAILED);
LOG.error("Deploy failure", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} finally {
save(sessionInfo.setStatus(sessionInfo.getStatus()), accountId);
sessions.remove(accountId);
}
}
@Override
public void handleError(Throwable t) {
try {
os.close();
sessionInfo.setStatus(DeployStatus.FAILED);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getCause().getMessage());
} catch (IOException e) {
LOG.error("Error while saving deploy jar.", e);
} finally {
save(sessionInfo.setStatus(sessionInfo.getStatus()), accountId);
sessions.remove(accountId);
}
}
};