Add deployment routes for use by Ansible

This commit is contained in:
Colin McDonald 2016-11-27 01:06:01 -05:00
parent 76c0148b89
commit db0adc8b87
4 changed files with 65 additions and 4 deletions

View File

@ -55,6 +55,7 @@ import net.frozenorb.apiv3.route.chatFilter.DELETEChatFilterId;
import net.frozenorb.apiv3.route.chatFilter.GETChatFilter;
import net.frozenorb.apiv3.route.chatFilter.GETChatFilterId;
import net.frozenorb.apiv3.route.chatFilter.POSTChatFilter;
import net.frozenorb.apiv3.route.deployment.POSTDeploymentUpdateServer;
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokens;
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokensIdUse;
import net.frozenorb.apiv3.route.emailTokens.GETEmailTokensIdOwner;
@ -372,6 +373,8 @@ public final class APIv3 extends AbstractVerticle {
//http.put("/chatFilter/:chatFilterEntryId").blockingHandler(new PUTChatFilterId(), false);
http.delete("/chatFilter/:chatFilterEntryId").blockingHandler(new DELETEChatFilterId(), false);
http.post("/deployment/updateServer/:serverId").blockingHandler(new POSTDeploymentUpdateServer(), false);
http.post("/disposableLoginTokens").blockingHandler(new POSTDisposableLoginTokens(), false);
http.post("/disposableLoginTokens/:disposableLoginToken/use").blockingHandler(new POSTDisposableLoginTokensIdUse(), false);

View File

@ -21,6 +21,7 @@ import fr.javatic.mongo.jacksonCodec.Entity;
import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Entity
@AllArgsConstructor
@ -31,9 +32,9 @@ public final class AccessToken {
@Getter @Id private String id;
@Getter private String actorName;
@Getter private ActorType actorType;
@Getter private List<String> lockedIps;
@Getter @Setter private List<String> lockedIps;
@Getter private Instant createdAt;
@Getter private Instant lastUpdatedAt;
@Getter @Setter private Instant lastUpdatedAt;
public static void findAll(SingleResultCallback<List<AccessToken>> callback) {
accessTokensCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));

View File

@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import fr.javatic.mongo.jacksonCodec.Entity;
import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.Getter;
import lombok.Setter;
@Entity
public final class Server {
@ -39,8 +40,8 @@ public final class Server {
@Getter @Id private String id;
@Getter private String displayName;
@Getter private String serverGroup;
@Getter private String serverIp;
@Getter private Instant lastUpdatedAt;
@Getter @Setter private String serverIp;
@Getter @Setter private Instant lastUpdatedAt;
@Getter private double lastTps;
@Getter @ExcludeFromReplies private Set<UUID> players;

View File

@ -0,0 +1,56 @@
package net.frozenorb.apiv3.route.deployment;
import com.google.common.collect.ImmutableList;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.AccessToken;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import java.time.Instant;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
public final class POSTDeploymentUpdateServer implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String serverId = ctx.request().getParam("serverId");
JsonObject requestBody = ctx.getBodyAsJson();
String ip = requestBody.getString("ip");
int port = requestBody.getInteger("port", 0);
if (ip == null || port == 0) {
ErrorUtils.respondInvalidInput(ctx, "'ip' and 'port' are required.");
}
Server server = Server.findById(serverId);
AccessToken accessToken = SyncUtils.runBlocking(v -> AccessToken.findByNameAndType(serverId, ActorType.SERVER, v));
if (server == null) {
ErrorUtils.respondNotFound(ctx, "server", serverId);
return;
}
if (accessToken == null) {
ErrorUtils.respondNotFound(ctx, "access token", serverId);
return;
}
server.setServerIp(ip + ":" + port);
server.setLastUpdatedAt(Instant.now());
accessToken.setLockedIps(ImmutableList.of(ip));
accessToken.setLastUpdatedAt(Instant.now());
SyncUtils.<Void>runBlocking(server::save);
SyncUtils.<Void>runBlocking(accessToken::save);
ctx.response().end(accessToken.getId());
}
}