diff options
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r-- | sinksh/syntax_modules/sink_info.cpp | 51 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 79 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_show.cpp | 27 |
3 files changed, 136 insertions, 21 deletions
diff --git a/sinksh/syntax_modules/sink_info.cpp b/sinksh/syntax_modules/sink_info.cpp new file mode 100644 index 0000000..aa515e6 --- /dev/null +++ b/sinksh/syntax_modules/sink_info.cpp | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include <QDebug> | ||
21 | #include <QObject> // tr() | ||
22 | |||
23 | #include "common/definitions.h" | ||
24 | |||
25 | #include "sinksh_utils.h" | ||
26 | #include "state.h" | ||
27 | #include "syntaxtree.h" | ||
28 | #include "sink_version.h" | ||
29 | |||
30 | namespace SinkInfo | ||
31 | { | ||
32 | |||
33 | bool info(const QStringList &args, State &state) | ||
34 | { | ||
35 | state.printLine(QString("Sink version: %1").arg(sink_VERSION_STRING)); | ||
36 | state.printLine(QString("Storage location: %1").arg(Sink::storageLocation())); | ||
37 | state.printLine(QString("Data location: %1").arg(Sink::dataLocation())); | ||
38 | state.printLine(QString("Config location: %1").arg(Sink::configLocation())); | ||
39 | state.printLine(QString("Temporary file location: %1").arg(Sink::temporaryFileLocation())); | ||
40 | state.printLine(QString("Resource storage location: %1").arg(Sink::resourceStorageLocation("$RESOURCE"))); | ||
41 | return false; | ||
42 | } | ||
43 | |||
44 | Syntax::List syntax() | ||
45 | { | ||
46 | return Syntax::List() << Syntax{"info", QObject::tr("Shows general system info"), &SinkInfo::info, Syntax::NotInteractive}; | ||
47 | } | ||
48 | |||
49 | REGISTER_SYNTAX(SinkInfo) | ||
50 | |||
51 | } | ||
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index a8a3805..da62250 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -19,8 +19,6 @@ | |||
19 | 19 | ||
20 | #include <QDebug> | 20 | #include <QDebug> |
21 | #include <QObject> // tr() | 21 | #include <QObject> // tr() |
22 | #include <QTimer> | ||
23 | #include <QDir> | ||
24 | 22 | ||
25 | #include "common/resource.h" | 23 | #include "common/resource.h" |
26 | #include "common/storage.h" | 24 | #include "common/storage.h" |
@@ -30,6 +28,7 @@ | |||
30 | #include "common/definitions.h" | 28 | #include "common/definitions.h" |
31 | #include "common/entitybuffer.h" | 29 | #include "common/entitybuffer.h" |
32 | #include "common/metadata_generated.h" | 30 | #include "common/metadata_generated.h" |
31 | #include "common/bufferutils.h" | ||
33 | 32 | ||
34 | #include "sinksh_utils.h" | 33 | #include "sinksh_utils.h" |
35 | #include "state.h" | 34 | #include "state.h" |
@@ -41,7 +40,7 @@ namespace SinkInspect | |||
41 | bool inspect(const QStringList &args, State &state) | 40 | bool inspect(const QStringList &args, State &state) |
42 | { | 41 | { |
43 | if (args.isEmpty()) { | 42 | if (args.isEmpty()) { |
44 | state.printError(QObject::tr("Options: $type [--resource $resource] [--db $db] [--filter $id] [--showinternal]")); | 43 | state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type])")); |
45 | } | 44 | } |
46 | auto options = SyntaxTree::parseOptions(args); | 45 | auto options = SyntaxTree::parseOptions(args); |
47 | auto resource = options.options.value("resource").value(0); | 46 | auto resource = options.options.value("resource").value(0); |
@@ -49,6 +48,75 @@ bool inspect(const QStringList &args, State &state) | |||
49 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); | 48 | Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); |
50 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); | 49 | auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); |
51 | 50 | ||
51 | bool validateRids = options.options.contains("validaterids"); | ||
52 | if (validateRids) { | ||
53 | if (options.options.value("validaterids").isEmpty()) { | ||
54 | state.printError(QObject::tr("Specify a type to validate.")); | ||
55 | return false; | ||
56 | } | ||
57 | auto type = options.options.value("validaterids").first().toUtf8(); | ||
58 | /* | ||
59 | * Try to find all rid's for all uid's. | ||
60 | * If we have entities without rid's that either means we have only created it locally or that we have a problem. | ||
61 | */ | ||
62 | Sink::Storage::DataStore syncStore(Sink::storageLocation(), resource + ".synchronization", Sink::Storage::DataStore::ReadOnly); | ||
63 | auto syncTransaction = syncStore.createTransaction(Sink::Storage::DataStore::ReadOnly); | ||
64 | |||
65 | auto db = transaction.openDatabase(type + ".main", | ||
66 | [&] (const Sink::Storage::DataStore::Error &e) { | ||
67 | Q_ASSERT(false); | ||
68 | state.printError(e.message); | ||
69 | }, false); | ||
70 | |||
71 | auto ridMap = syncTransaction.openDatabase("localid.mapping." + type, | ||
72 | [&] (const Sink::Storage::DataStore::Error &e) { | ||
73 | Q_ASSERT(false); | ||
74 | state.printError(e.message); | ||
75 | }, false); | ||
76 | |||
77 | QHash<QByteArray, QByteArray> hash; | ||
78 | |||
79 | ridMap.scan("", [&] (const QByteArray &key, const QByteArray &data) { | ||
80 | hash.insert(key, data); | ||
81 | return true; | ||
82 | }, | ||
83 | [&](const Sink::Storage::DataStore::Error &e) { | ||
84 | state.printError(e.message); | ||
85 | }, | ||
86 | false); | ||
87 | |||
88 | QSet<QByteArray> uids; | ||
89 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { | ||
90 | uids.insert(Sink::Storage::DataStore::uidFromKey(key)); | ||
91 | return true; | ||
92 | }, | ||
93 | [&](const Sink::Storage::DataStore::Error &e) { | ||
94 | state.printError(e.message); | ||
95 | }, | ||
96 | false); | ||
97 | |||
98 | int missing = 0; | ||
99 | for (const auto &uid : uids) { | ||
100 | if (!hash.remove(uid)) { | ||
101 | missing++; | ||
102 | qWarning() << "Failed to find RID for " << uid; | ||
103 | } | ||
104 | } | ||
105 | if (missing) { | ||
106 | qWarning() << "Found a total of " << missing << " missing rids"; | ||
107 | } | ||
108 | |||
109 | //If we still have items in the hash it means we have rid mappings for entities | ||
110 | //that no longer exist. | ||
111 | if (!hash.isEmpty()) { | ||
112 | qWarning() << "Have rids left: " << hash.size(); | ||
113 | } else if (!missing) { | ||
114 | qWarning() << "Everything is in order."; | ||
115 | } | ||
116 | |||
117 | return false; | ||
118 | } | ||
119 | |||
52 | auto dbs = options.options.value("db"); | 120 | auto dbs = options.options.value("db"); |
53 | auto idFilter = options.options.value("filter"); | 121 | auto idFilter = options.options.value("filter"); |
54 | bool showInternal = options.options.contains("showinternal"); | 122 | bool showInternal = options.options.contains("showinternal"); |
@@ -96,7 +164,10 @@ bool inspect(const QStringList &args, State &state) | |||
96 | state.printError("Read invalid buffer from disk: " + key); | 164 | state.printError("Read invalid buffer from disk: " + key); |
97 | } else { | 165 | } else { |
98 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); | 166 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); |
99 | state.printLine("Key: " + key + " Operation: " + QString::number(metadata->operation())); | 167 | state.printLine("Key: " + key |
168 | + " Operation: " + QString::number(metadata->operation()) | ||
169 | + " Replay: " + (metadata->replayToSource() ? "true" : "false") | ||
170 | + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "")); | ||
100 | } | 171 | } |
101 | } else { | 172 | } else { |
102 | state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); | 173 | state.printLine("Key: " + key + " Value: " + QString::fromUtf8(data)); |
diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp index 391505a..7a4166f 100644 --- a/sinksh/syntax_modules/sink_show.cpp +++ b/sinksh/syntax_modules/sink_show.cpp | |||
@@ -18,18 +18,12 @@ | |||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <QCoreApplication> | ||
22 | #include <QDebug> | 21 | #include <QDebug> |
23 | #include <QObject> // tr() | 22 | #include <QObject> // tr() |
24 | #include <QModelIndex> | 23 | #include <QModelIndex> |
25 | #include <QTime> | 24 | #include <QTime> |
26 | 25 | ||
27 | #include "common/resource.h" | ||
28 | #include "common/storage.h" | 26 | #include "common/storage.h" |
29 | #include "common/resourceconfig.h" | ||
30 | #include "common/log.h" | ||
31 | #include "common/storage.h" | ||
32 | #include "common/definitions.h" | ||
33 | 27 | ||
34 | #include "sinksh_utils.h" | 28 | #include "sinksh_utils.h" |
35 | #include "state.h" | 29 | #include "state.h" |
@@ -41,25 +35,24 @@ namespace SinkShow | |||
41 | bool show(const QStringList &args, State &state) | 35 | bool show(const QStringList &args, State &state) |
42 | { | 36 | { |
43 | if (args.isEmpty()) { | 37 | if (args.isEmpty()) { |
44 | state.printError(QObject::tr("Please provide at least one type to show (e.g. resource, ..")); | 38 | state.printError(QObject::tr("Options: $type --resource $resource --id $id")); |
45 | return false; | 39 | return false; |
46 | } | 40 | } |
47 | 41 | ||
48 | auto argList = args; | 42 | auto options = SyntaxTree::parseOptions(args); |
49 | if (argList.size() < 2 || !SinkshUtils::isValidStoreType(argList.at(0))) { | 43 | |
44 | auto type = options.positionalArguments.isEmpty() ? QString{} : options.positionalArguments.first(); | ||
45 | auto resource = options.options.value("resource"); | ||
46 | auto id = options.options.value("id"); | ||
47 | |||
48 | if (id.isEmpty() || resource.isEmpty() || !SinkshUtils::isValidStoreType(type)) { | ||
50 | state.printError(QObject::tr("Invalid command syntax. Supply type and resource at least.")); | 49 | state.printError(QObject::tr("Invalid command syntax. Supply type and resource at least.")); |
51 | return false; | 50 | return false; |
52 | } | 51 | } |
53 | auto type = argList.takeFirst(); | ||
54 | auto resource = argList.takeFirst(); | ||
55 | bool queryForResourceOrAgent = argList.isEmpty(); | ||
56 | 52 | ||
57 | Sink::Query query; | 53 | Sink::Query query; |
58 | if (queryForResourceOrAgent) { | 54 | query.resourceFilter(resource.first().toLatin1()); |
59 | query.filter(resource.toLatin1()); | 55 | query.filter(id.first().toLatin1()); |
60 | } else { | ||
61 | query.resourceFilter(resource.toLatin1()); | ||
62 | } | ||
63 | 56 | ||
64 | QTime time; | 57 | QTime time; |
65 | time.start(); | 58 | time.start(); |