use of com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method listModules.
@ApiOperation(value = "List Current Installed Modules", notes = "List all installed")
@RequestMapping(method = RequestMethod.GET, value = "/list")
public List<ModuleModel> listModules(@AuthenticationPrincipal PermissionHolder user) {
permissionService.ensureAdminRole(user);
List<ModuleModel> models = new ArrayList<ModuleModel>();
List<Module> modules = ModuleRegistry.getModules();
for (Module module : modules) {
if (module instanceof CoreModule) {
CoreModuleModel coreModel = new CoreModuleModel(ModuleRegistry.getModule(ModuleRegistry.CORE_MODULE_NAME));
coreModel.setGuid(Providers.get(ICoreLicense.class).getGuid());
coreModel.setInstanceDescription(SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
coreModel.setDistributor(Common.envProps.getString("distributor"));
coreModel.setUpgradeVersionState(SystemSettingsDao.getInstance().getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
coreModel.setStoreUrl(Common.envProps.getString("store.url"));
models.add(coreModel);
} else {
models.add(new ModuleModel(module));
}
}
// Add the unloaded modules at the end?
List<Module> unloaded = ModuleRegistry.getUnloadedModules();
for (Module module : unloaded) {
ModuleModel model = new ModuleModel(module);
model.setUnloaded(true);
models.add(model);
}
return models;
}
use of com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method markModuleForDeletion.
@ApiOperation(value = "Set Marked For Deletion state of Module", notes = "Marking a module for deletion will un-install it upon restart")
@RequestMapping(method = RequestMethod.PUT, value = "/deletion-state")
public ModuleModel markModuleForDeletion(@ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(name = "delete", required = true) boolean delete, @ApiParam(value = "Module model") @RequestBody() ModuleModel model, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
permissionService.ensureAdminRole(user);
Module module = ModuleRegistry.getModule(model.getName());
if (module == null)
throw new NotFoundException();
module.setMarkedForDeletion(delete);
if (module.isMarkedForDeletion() != delete)
throw new ModuleRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
return new ModuleModel(module);
}
use of com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpgradeStatus.
@ApiOperation(value = "Get Current Upgrade Task Status", notes = "")
@RequestMapping(method = RequestMethod.GET, value = "/upgrade-status")
public UpgradeStatusModel getUpgradeStatus(@AuthenticationPrincipal PermissionHolder user) {
permissionService.ensureAdminRole(user);
UpgradeStatus status = service.monitorDownloads();
UpgradeStatusModel model = new UpgradeStatusModel();
if (status.getStage() == UpgradeState.IDLE) {
// Not running
model.setRunning(false);
} else {
List<ModuleModel> modules = new ArrayList<ModuleModel>();
List<StringStringPair> results = status.getResults();
for (StringStringPair r : results) modules.add(new ModuleModel(r.getKey(), r.getValue()));
model.setResults(modules);
model.setFinished(status.isFinished());
model.setCancelled(status.isCancelled());
model.setWillRestart(status.isRestart());
model.setError(status.getError());
model.setStage(status.getStage().name());
}
return model;
}
use of com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpgrades.
@ApiOperation(value = "Get Available Upgrades", notes = "Check the store for Upgrades")
@RequestMapping(method = RequestMethod.GET, value = "/upgrades-available")
public ModuleUpgradesModel getUpgrades(@AuthenticationPrincipal PermissionHolder user) {
permissionService.ensureAdminRole(user);
// Do the check
try {
JsonValue jsonResponse = null;
// This is handled oddly in the ModulesDwr so check it here for validation
String baseUrl = Common.envProps.getString("store.url");
if (!StringUtils.isEmpty(baseUrl)) {
jsonResponse = service.getAvailableUpgrades();
} else {
ProcessResult result = new ProcessResult();
result.addGenericMessage("modules.versionCheck.storeNotSet");
throw new ValidationFailedRestException(result);
}
if (jsonResponse == null) {
// Indicates that the store url is not set, which we check for above so this really means the response was a null JSON value
throw new BadRequestException(new TranslatableMessage("modules.versionCheck.storeResponseEmpty"));
} else if (jsonResponse instanceof JsonString) {
throw new ServerErrorException(new TranslatableMessage("common.default", jsonResponse.toString()));
} else {
List<ModuleUpgradeModel> upgrades = new ArrayList<>();
List<ModuleUpgradeModel> newInstalls = new ArrayList<>();
List<ModuleModel> unavailableModules = new ArrayList<>();
ModuleUpgradesModel model = new ModuleUpgradesModel(upgrades, newInstalls);
JsonObject root = jsonResponse.toJsonObject();
JsonValue jsonUpgrades = root.get("upgrades");
JsonArray jsonUpgradesArray = jsonUpgrades.toJsonArray();
Iterator<JsonValue> it = jsonUpgradesArray.iterator();
while (it.hasNext()) {
JsonValue v = it.next();
if (v.getJsonValue("name") == null) {
it.remove();
continue;
}
String name = v.getJsonValue("name").toString();
Module module = ModuleRegistry.getModule(name);
if (module == null) {
it.remove();
continue;
}
upgrades.add(new ModuleUpgradeModel(module, v));
}
JsonValue jsonInstalls = root.get("newInstalls");
JsonArray jsonInstallsArray = jsonInstalls.toJsonArray();
for (JsonValue v : jsonInstallsArray) {
newInstalls.add(new ModuleUpgradeModel(v));
}
// Extract any unavailable modules
if (root.containsKey("unavailableModules")) {
JsonValue jsonUnavailableModules = root.get("unavailableModules");
JsonArray jsonUnavailableModulesArray = jsonUnavailableModules.toJsonArray();
List<Module> modules = ModuleRegistry.getModules();
for (JsonValue v : jsonUnavailableModulesArray) {
Module unavailable = null;
String moduleName = v.toString();
for (Module module : modules) {
if (StringUtils.equals(module.getName(), moduleName)) {
unavailable = module;
break;
}
}
if (unavailable == null) {
// Didn't find it? Store must be wrong?
LOG.warn("Store reported unavailable module " + moduleName + " but it isn't installed.");
} else {
unavailableModules.add(new ModuleModel(unavailable));
}
}
}
model.setUnavailableModules(unavailableModules);
return model;
}
} catch (SocketTimeoutException e) {
throw new ServerErrorException(new TranslatableMessage("rest.error.requestTimeout", Common.envProps.getString("store.url")));
} catch (UnknownHostException e) {
throw new ServerErrorException(new TranslatableMessage("rest.error.unknownHost", Common.envProps.getString("store.url")));
} catch (IOException | JsonException | HttpException e) {
throw new ServerErrorException(e);
}
}
use of com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method markForDeletion.
@ApiOperation(value = "Set Marked For Deletion state of Module", notes = "Marking a module for deletion will un-install it upon restart")
@RequestMapping(method = RequestMethod.PUT, value = "/deletion-state/{moduleName}")
public ResponseEntity<ModuleModel> markForDeletion(@PathVariable String moduleName, @ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(name = "delete", required = true) boolean delete, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
Module module = ModuleRegistry.getModule(moduleName);
if (module == null)
throw new NotFoundException();
module.setMarkedForDeletion(delete);
if (module.isMarkedForDeletion() != delete)
throw new ModuleRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
return ResponseEntity.ok(new ModuleModel(module));
}
Aggregations