aboutsummaryrefslogtreecommitdiff
path: root/agent/src/main/java/moe/yuuta/dn42peering/agent/grpc/AgentServiceImpl.java
blob: 3ceb9fb0f651e0d618ae321ce9a6d0f0bf4eb451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package moe.yuuta.dn42peering.agent.grpc;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
import moe.yuuta.dn42peering.agent.Deploy;
import moe.yuuta.dn42peering.agent.Persistent;
import moe.yuuta.dn42peering.agent.proto.DeployResult;
import moe.yuuta.dn42peering.agent.proto.NodeConfig;
import moe.yuuta.dn42peering.agent.proto.VertxAgentGrpc;

import javax.annotation.Nonnull;

class AgentServiceImpl extends VertxAgentGrpc.AgentVertxImplBase {
    private final Logger logger = LoggerFactory.getLogger(getClass().getSimpleName());

    private final Vertx vertx;

    AgentServiceImpl(@Nonnull Vertx vertx) {
        this.vertx = vertx;
    }

    @Override
    public Future<DeployResult> deploy(NodeConfig config) {
        return Deploy.deploy(vertx, config)
                .compose(_v -> Future.future(f -> {
                    Persistent.persistent(vertx, config)
                            .onComplete(res -> f.complete(_v)); // Ignore errors
                }));
    }
}