From 496242aebe8befafb6e3bf8e6cebba91d152603c Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Tue, 19 Sep 2017 22:45:03 -0400 Subject: [PATCH] feat: added graphinfo command for debugging. --- .../commands/admin/GraphStatusCommand.java | 64 +++++++++++++++++++ .../configuration/ConfigureCommands.java | 1 + .../aethermud/storage/AetherMudStorage.java | 3 + .../syncleus/aethermud/storage/GraphInfo.java | 48 ++++++++++++++ .../graphdb/GraphDbAetherMudStorage.java | 17 ++++- 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/syncleus/aethermud/command/commands/admin/GraphStatusCommand.java create mode 100644 src/main/java/com/syncleus/aethermud/storage/GraphInfo.java diff --git a/src/main/java/com/syncleus/aethermud/command/commands/admin/GraphStatusCommand.java b/src/main/java/com/syncleus/aethermud/command/commands/admin/GraphStatusCommand.java new file mode 100644 index 00000000..f6483400 --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/command/commands/admin/GraphStatusCommand.java @@ -0,0 +1,64 @@ +/** + * Copyright 2017 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.command.commands.admin; + +import com.google.common.collect.Sets; +import com.syncleus.aethermud.command.commands.Command; +import com.syncleus.aethermud.core.GameManager; +import com.syncleus.aethermud.player.PlayerRole; +import com.syncleus.aethermud.storage.AetherMudStorage; +import com.syncleus.aethermud.storage.GraphInfo; +import com.syncleus.aethermud.storage.graphdb.GraphStorageFactory; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.MessageEvent; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +public class GraphStatusCommand extends Command { + final static List<String> validTriggers = Arrays.asList("graphstatus"); + final static String description = "Display some statistics on the GraphDB for debugging."; + final static String correctUsage = "graphstatus"; + final static Set<PlayerRole> roles = Sets.newHashSet(PlayerRole.ADMIN); + + public GraphStatusCommand(GameManager gameManager) { + super(gameManager, validTriggers, description, correctUsage, roles); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { + execCommand(ctx, e, () -> { + + try (GraphStorageFactory.AetherMudTx tx = this.gameManager.getGraphStorageFactory().beginTransaction()) { + AetherMudStorage storage = tx.getStorage(); + GraphInfo info = storage.getGraphInfo(); + + write("Number of nodes: " + info.getNumberOfNodes() + "\r\n"); + write("Number of items: " + info.getNumberOfItems() + "\r\n"); + write("Number of item instances: " + info.getNumberOfItemInstances() + "\r\n"); + write("Number of item internal names:\r\n"); + for(String internalName : info.getItemInternalNames()) + write(internalName + "\r\n"); + } + + }); + } + +} + + + diff --git a/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java b/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java index df8139fd..587510ab 100644 --- a/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java +++ b/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java @@ -122,5 +122,6 @@ public class ConfigureCommands { commandRegistry.addCommand(new LoadMerchantCommand(gameManager)); commandRegistry.addCommand(new RestartCommand(gameManager)); commandRegistry.addCommand(new GiveHealthCommand(gameManager)); + commandRegistry.addCommand(new GraphStatusCommand(gameManager)); } } diff --git a/src/main/java/com/syncleus/aethermud/storage/AetherMudStorage.java b/src/main/java/com/syncleus/aethermud/storage/AetherMudStorage.java index ce33fa66..f19d20a0 100644 --- a/src/main/java/com/syncleus/aethermud/storage/AetherMudStorage.java +++ b/src/main/java/com/syncleus/aethermud/storage/AetherMudStorage.java @@ -56,4 +56,7 @@ public interface AetherMudStorage { List<? extends NpcData> getNpcDatas(); NpcData newNpcData(); + + GraphInfo getGraphInfo(); + } diff --git a/src/main/java/com/syncleus/aethermud/storage/GraphInfo.java b/src/main/java/com/syncleus/aethermud/storage/GraphInfo.java new file mode 100644 index 00000000..5d42629c --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/storage/GraphInfo.java @@ -0,0 +1,48 @@ +/** + * Copyright 2017 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.storage; + +import java.util.List; + +public class GraphInfo { + private final int numberOfItems; + private final int numberOfItemInstances; + private final List<String> itemInternalNames; + private final int numberOfNodes; + + public GraphInfo(int numberOfItems, int numberOfItemInstances, List<String> itemInternalNames, int numberOfNodes) { + this.numberOfItems = numberOfItems; + this.numberOfItemInstances = numberOfItemInstances; + this.itemInternalNames = itemInternalNames; + this.numberOfNodes = numberOfNodes; + } + + public int getNumberOfItems() { + return numberOfItems; + } + + public int getNumberOfItemInstances() { + return numberOfItemInstances; + } + + public List<String> getItemInternalNames() { + return itemInternalNames; + } + + public int getNumberOfNodes() { + return numberOfNodes; + } +} diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/GraphDbAetherMudStorage.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/GraphDbAetherMudStorage.java index 1c32b022..2ca865aa 100644 --- a/src/main/java/com/syncleus/aethermud/storage/graphdb/GraphDbAetherMudStorage.java +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/GraphDbAetherMudStorage.java @@ -23,10 +23,12 @@ import com.syncleus.aethermud.items.ItemInstance; import com.syncleus.aethermud.npc.NpcBuilder; import com.syncleus.aethermud.npc.NpcSpawn; import com.syncleus.aethermud.storage.AetherMudStorage; +import com.syncleus.aethermud.storage.GraphInfo; import com.syncleus.aethermud.storage.graphdb.model.ItemData; import com.syncleus.aethermud.storage.graphdb.model.ItemInstanceData; import com.syncleus.aethermud.storage.graphdb.model.NpcData; import com.syncleus.aethermud.storage.graphdb.model.PlayerData; +import com.syncleus.ferma.VertexFrame; import com.syncleus.ferma.WrappedFramedGraph; import org.apache.log4j.Logger; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -88,7 +90,7 @@ public class GraphDbAetherMudStorage implements AetherMudStorage { itemInstanceData = existing.get(); else itemInstanceData = framedGraph.addFramedVertex(ItemInstanceData.class); - ItemInstanceData.copyItem(itemInstanceData, itemInstance, this.getItem(itemInstance.getItem().getInternalItemName()).get()); + ItemInstanceData.copyItem(itemInstanceData, itemInstance, this.saveItem(itemInstance.getItem())); return itemInstanceData; } } @@ -127,6 +129,19 @@ public class GraphDbAetherMudStorage implements AetherMudStorage { } } + @Override + public GraphInfo getGraphInfo() { + final List<? extends ItemData> allItems = this.getAllItems(); + final int numberOfItems = allItems.size(); + final List<String> internalNames = new ArrayList<>(); + for(ItemData itemData : allItems) { + internalNames.add(itemData.getInternalItemName()); + } + final int numberOfItemInstances = framedGraph.traverse((g) -> framedGraph.getTypeResolver().hasType(g.V(), ItemInstanceData.class)).toList(ItemInstanceData.class).size(); + final int numberOfNodes = framedGraph.traverse((g) -> g.V()).toList(VertexFrame.class).size(); + return new GraphInfo(numberOfItems, numberOfItemInstances, internalNames, numberOfNodes); + } + public List<? extends NpcSpawn> getAllNpcs(GameManager gameManager) { List<? extends NpcData> npcDatas = this.getNpcDatas(); return npcDatas.stream() -- GitLab