Search in sources :

Example 6 with Command

use of com.eightkdata.mongowp.server.api.Command in project torodb by torodb.

the class ServerStatusImplementation method apply.

@Override
public Status<ServerStatusReply> apply(Request req, Command<? super ServerStatusArgument, ? super ServerStatusReply> command, ServerStatusArgument arg, MongodConnection context) {
    ServerStatusReply.Builder replyBuilder = new ServerStatusReply.Builder();
    //TODO: improve and complete
    if (arg.isHost()) {
        try {
            replyBuilder.setHost(InetAddress.getLocalHost().getHostName() + ":" + selfHostAndPort.getPort());
        } catch (Throwable throwable) {
            replyBuilder.setHost("localhost:" + selfHostAndPort.getPort());
        }
    }
    if (arg.isVersion()) {
        replyBuilder.setVersion(MongoLayerConstants.VERSION_STRING);
    }
    if (arg.isProcess()) {
        replyBuilder.setProcess("mongod");
    }
    if (arg.isPid()) {
        try {
            replyBuilder.setPid(Integer.valueOf(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]));
        } catch (Throwable throwable) {
            LOGGER.warn("Cannot get PID: " + throwable.getMessage());
        }
    }
    if (arg.isUptime()) {
        replyBuilder.setUptime(ManagementFactory.getRuntimeMXBean().getUptime());
    }
    if (arg.isUptimeEstimate()) {
        replyBuilder.setUptimeEstimate(ManagementFactory.getRuntimeMXBean().getUptime());
    }
    if (arg.isLocalTime()) {
        replyBuilder.setLocalTime(Instant.now());
    }
    if (arg.isLocks()) {
        Locks.Count dummyCount = new Locks.Count(0, 0, 0, 0);
        Locks.Lock dummyLock = new Locks.Lock(dummyCount, dummyCount, dummyCount, dummyCount);
        replyBuilder.setLocks(new Locks(dummyLock, dummyLock, dummyLock, dummyLock, dummyLock, dummyLock));
    }
    if (arg.isGlobalLock()) {
        GlobalLock.GlobalLockStats dummyGlobalLockStats = new GlobalLock.GlobalLockStats(0, 0, 0);
        replyBuilder.setGlobalLock(new GlobalLock(0, dummyGlobalLockStats, dummyGlobalLockStats));
    }
    if (arg.isMem()) {
        replyBuilder.setMem(new Mem(0, 0, 0, false, 0, 0, ""));
    }
    if (arg.isConnections()) {
        replyBuilder.setConnections(new Connections(0, 0, 0));
    }
    if (arg.isExtraInfo()) {
        replyBuilder.setExtraInfo(new ExtraInfo("", 0, 0));
    }
    if (arg.isBackgroundFlushing()) {
        replyBuilder.setBackgroundFlushing(new BackgroundFlushing(0, 0, 0, 0, Instant.now()));
    }
    if (arg.isCursors()) {
        replyBuilder.setCursors(new Cursors("", 0, 0, 0, 0, 0));
    }
    if (arg.isNetwork()) {
        replyBuilder.setNetwork(new Network(0, 0, 0));
    }
    //}
    if (arg.isOpcountersRepl()) {
        replyBuilder.setOpcountersRepl(new Opcounters(0, 0, 0, 0, 0, 0));
    }
    if (arg.isOpcounters()) {
        replyBuilder.setOpcounters(new Opcounters(0, 0, 0, 0, 0, 0));
    }
    if (arg.isRangeDeleter()) {
        ImmutableList.Builder<RangeDeleter.LastDeletedStat> builder = ImmutableList.builder();
        replyBuilder.setRangeDeleter(new RangeDeleter(builder.build()));
    }
    if (arg.isSecurity()) {
        replyBuilder.setSecurity(new Security(null, false, null));
    }
    if (arg.isStorageEngine()) {
        replyBuilder.setStorageEngine(new StorageEngine("ToroDB"));
    }
    if (arg.isAsserts()) {
        replyBuilder.setAsserts(new Asserts(0, 0, 0, 0, 0));
    }
    if (arg.isDur()) {
        replyBuilder.setDur(new Dur(0, 0, 0, 0, 0, 0, new Dur.TimeMs(0, 0, 0, 0, 0, 0, 0)));
    }
    if (arg.isWriteBacksQueued()) {
        replyBuilder.setWritebacksQueued(0);
    }
    if (arg.isMetrics()) {
        ImmutableList.Builder<Metrics.Command> builder = ImmutableList.builder();
        Metrics.Stats dummyStats = new Metrics.Stats(0, 0);
        replyBuilder.setMetrics(new Metrics(builder.build(), new Metrics.Document(0, 0, 0, 0), new Metrics.GetLastError(dummyStats, 0), new Metrics.Operation(0, 0, 0), new Metrics.QueryExecutor(0), new Metrics.Record(0), new Metrics.Repl(new Metrics.Repl.Apply(dummyStats, 0), new Metrics.Repl.Buffer(0, 0, 0), new Metrics.Repl.Network(0, dummyStats, 0, 0), new Metrics.Repl.Oplog(dummyStats, 0), new Metrics.Repl.Preload(dummyStats, dummyStats)), new Metrics.Storage(new Metrics.Storage.Freelist(new Metrics.Storage.Freelist.Search(0, 0, 0))), new Metrics.Ttl(0, 0)));
    }
    return Status.ok(replyBuilder.build());
}
Also used : Connections(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Connections) ImmutableList(com.google.common.collect.ImmutableList) Security(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Security) StorageEngine(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.StorageEngine) GlobalLock(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.GlobalLock) Metrics(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Metrics) Opcounters(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Opcounters) RangeDeleter(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.RangeDeleter) Network(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Network) Cursors(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Cursors) ServerStatusReply(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.ServerStatusReply) Dur(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Dur) Locks(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Locks) ExtraInfo(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.ExtraInfo) BackgroundFlushing(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.BackgroundFlushing) GlobalLock(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.GlobalLock) Mem(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Mem) Command(com.eightkdata.mongowp.server.api.Command) Asserts(com.torodb.mongodb.commands.signatures.diagnostic.ServerStatusCommand.Asserts)

Aggregations

Command (com.eightkdata.mongowp.server.api.Command)6 Status (com.eightkdata.mongowp.Status)5 Request (com.eightkdata.mongowp.server.api.Request)4 AttributeReference (com.torodb.core.language.AttributeReference)4 List (java.util.List)4 ErrorCode (com.eightkdata.mongowp.ErrorCode)3 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)3 Constants (com.torodb.mongodb.language.Constants)3 IndexFieldInfo (com.torodb.torod.IndexFieldInfo)3 Arrays (java.util.Arrays)3 CommandFailed (com.eightkdata.mongowp.exceptions.CommandFailed)2 ImmutableList (com.google.common.collect.ImmutableList)2 Cursor (com.torodb.core.cursors.Cursor)2 Builder (com.torodb.core.language.AttributeReference.Builder)2 KvDocument (com.torodb.kvdocument.values.KvDocument)2 KvValue (com.torodb.kvdocument.values.KvValue)2 WriteTorodbCommandImpl (com.torodb.mongodb.commands.impl.WriteTorodbCommandImpl)2 IndexOptions (com.torodb.mongodb.commands.pojos.index.IndexOptions)2 KnownType (com.torodb.mongodb.commands.pojos.index.IndexOptions.KnownType)2 DropIndexesArgument (com.torodb.mongodb.commands.signatures.admin.DropIndexesCommand.DropIndexesArgument)2