TODO(karya): Show library author info for failed library/module.
| 131 | |
| 132 | // TODO(karya): Show library author info for failed library/module. |
| 133 | Try<Nothing> ModuleManager::verifyModule( |
| 134 | const string& moduleName, |
| 135 | const ModuleBase* moduleBase) |
| 136 | { |
| 137 | CHECK_NOTNULL(moduleBase); |
| 138 | if (moduleBase->mesosVersion == nullptr || |
| 139 | moduleBase->moduleApiVersion == nullptr || |
| 140 | moduleBase->authorName == nullptr || |
| 141 | moduleBase->authorEmail == nullptr || |
| 142 | moduleBase->description == nullptr || |
| 143 | moduleBase->kind == nullptr) { |
| 144 | return Error("Error loading module '" + moduleName + "'; missing fields"); |
| 145 | } |
| 146 | |
| 147 | // Verify module API version. |
| 148 | if (stringify(moduleBase->moduleApiVersion) != MESOS_MODULE_API_VERSION) { |
| 149 | return Error( |
| 150 | "Module API version mismatch. Mesos has: " MESOS_MODULE_API_VERSION ", " |
| 151 | "library requires: " + stringify(moduleBase->moduleApiVersion)); |
| 152 | } |
| 153 | |
| 154 | if (!kindToVersion.contains(moduleBase->kind)) { |
| 155 | return Error("Unknown module kind: " + stringify(moduleBase->kind)); |
| 156 | } |
| 157 | |
| 158 | Try<Version> mesosVersion = Version::parse(MESOS_VERSION); |
| 159 | CHECK_SOME(mesosVersion); |
| 160 | |
| 161 | Try<Version> minimumVersion = Version::parse(kindToVersion[moduleBase->kind]); |
| 162 | CHECK_SOME(minimumVersion); |
| 163 | |
| 164 | Try<Version> moduleMesosVersion = Version::parse(moduleBase->mesosVersion); |
| 165 | if (moduleMesosVersion.isError()) { |
| 166 | return Error(moduleMesosVersion.error()); |
| 167 | } |
| 168 | |
| 169 | if (moduleMesosVersion.get() < minimumVersion.get()) { |
| 170 | return Error( |
| 171 | "Minimum supported mesos version for '" + stringify(moduleBase->kind) + |
| 172 | "' is " + stringify(minimumVersion.get()) + ", but module is compiled " |
| 173 | "with version " + stringify(moduleMesosVersion.get())); |
| 174 | } |
| 175 | |
| 176 | if (moduleBase->compatible == nullptr) { |
| 177 | if (moduleMesosVersion.get() != mesosVersion.get()) { |
| 178 | return Error( |
| 179 | "Mesos has version " + stringify(mesosVersion.get()) + |
| 180 | ", but module is compiled with version " + |
| 181 | stringify(moduleMesosVersion.get())); |
| 182 | } |
| 183 | return Nothing(); |
| 184 | } |
| 185 | |
| 186 | if (moduleMesosVersion.get() > mesosVersion.get()) { |
| 187 | return Error( |
| 188 | "Mesos has version " + stringify(mesosVersion.get()) + |
| 189 | ", but module is compiled with version " + |
| 190 | stringify(moduleMesosVersion.get())); |