use of com.serotonin.m2m2.UpgradeVersionState in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method saveInfoSettings.
@DwrPermission(admin = true)
public void saveInfoSettings(String instanceDescription, String upgradeVersionState) {
SystemSettingsDao systemSettingsDao = SystemSettingsDao.instance;
systemSettingsDao.setValue(SystemSettingsDao.INSTANCE_DESCRIPTION, instanceDescription);
systemSettingsDao.setValue(SystemSettingsDao.UPGRADE_VERSION_STATE, upgradeVersionState);
}
use of com.serotonin.m2m2.UpgradeVersionState in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpdateLicensePayload.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Get the update license payload, to make requests to store", notes = "Admin Only")
@RequestMapping(method = RequestMethod.GET, value = "/update-license-payload")
public ResponseEntity<UpdateLicensePayloadModel> getUpdateLicensePayload(@ApiParam(value = "Set content disposition to attachment", required = false, defaultValue = "true", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean download, HttpServletRequest request) {
Map<String, String> jsonModules = new HashMap<>();
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
for (Module module : modules) {
if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
}
// Add in the unloaded modules so we don't re-download them if we don't have to
for (Module module : ModuleRegistry.getUnloadedModules()) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
String storeUrl = Common.envProps.getString("store.url");
int upgradeVersionState = SystemSettingsDao.getInstance().getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE);
int currentVersionState = UpgradeVersionState.DEVELOPMENT;
Properties props = new Properties();
File propFile = Common.MA_HOME_PATH.resolve("release.properties").toFile();
try {
if (propFile.exists()) {
InputStream in;
in = new FileInputStream(propFile);
try {
props.load(in);
} finally {
in.close();
}
String versionState = props.getProperty("versionState");
try {
if (versionState != null)
currentVersionState = Integer.valueOf(versionState);
} catch (NumberFormatException e) {
}
}
} catch (IOException e1) {
// Ignore
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.CONTENT_DISPOSITION, download ? "attachment" : "inline");
return new ResponseEntity<>(new UpdateLicensePayloadModel(Providers.get(ICoreLicense.class).getGuid(), SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION), Common.envProps.getString("distributor"), jsonModules, storeUrl, upgradeVersionState, currentVersionState), responseHeaders, HttpStatus.OK);
}
use of com.serotonin.m2m2.UpgradeVersionState in project ma-core-public by infiniteautomation.
the class ModulesDwr method getAvailableUpgrades.
public static JsonValue getAvailableUpgrades() throws JsonException, IOException, HttpException {
// Create the request
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
Map<String, Object> json = new HashMap<>();
json.put("guid", Providers.get(ICoreLicense.class).getGuid());
json.put("description", SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
json.put("distributor", Common.envProps.getString("distributor"));
json.put("upgradeVersionState", SystemSettingsDao.getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
Properties props = new Properties();
File propFile = new File(Common.MA_HOME + File.separator + "release.properties");
int versionState = UpgradeVersionState.DEVELOPMENT;
if (propFile.exists()) {
InputStream in = new FileInputStream(propFile);
try {
props.load(in);
} finally {
in.close();
}
String currentVersionState = props.getProperty("versionState");
try {
if (currentVersionState != null)
versionState = Integer.valueOf(currentVersionState);
} catch (NumberFormatException e) {
}
}
json.put("currentVersionState", versionState);
Map<String, String> jsonModules = new HashMap<>();
json.put("modules", jsonModules);
Version coreVersion = Common.getVersion();
jsonModules.put("core", coreVersion.toString());
for (Module module : modules) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
// Add in the unloaded modules so we don't re-download them if we don't have to
for (Module module : ModuleRegistry.getUnloadedModules()) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
StringWriter stringWriter = new StringWriter();
new JsonWriter(Common.JSON_CONTEXT, stringWriter).writeObject(json);
String requestData = stringWriter.toString();
// Send the request
String baseUrl = Common.envProps.getString("store.url");
baseUrl += "/servlet/versionCheck";
HttpPost post = new HttpPost(baseUrl);
post.setEntity(new StringEntity(requestData));
String responseData = HttpUtils4.getTextContent(Common.getHttpClient(), post, 1);
// Parse the response
JsonTypeReader jsonReader = new JsonTypeReader(responseData);
return jsonReader.read();
}
use of com.serotonin.m2m2.UpgradeVersionState in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpdateLicensePayload.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Get the update license payload, to make requests to store", notes = "Admin Only")
@RequestMapping(method = RequestMethod.GET, value = "/update-license-payload")
public ResponseEntity<UpdateLicensePayloadModel> getUpdateLicensePayload(@ApiParam(value = "Set content disposition to attachment", required = false, defaultValue = "true", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean download, HttpServletRequest request) {
Map<String, String> jsonModules = new HashMap<>();
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
Module core = ModuleRegistry.getCoreModule();
modules.add(0, core);
for (Module module : modules) {
if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
}
// Add in the unloaded modules so we don't re-download them if we don't have to
for (Module module : ModuleRegistry.getUnloadedModules()) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
String storeUrl = Common.envProps.getString("store.url");
int upgradeVersionState = SystemSettingsDao.getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE);
int currentVersionState = UpgradeVersionState.DEVELOPMENT;
Properties props = new Properties();
File propFile = new File(Common.MA_HOME + File.separator + "release.properties");
try {
if (propFile.exists()) {
InputStream in;
in = new FileInputStream(propFile);
try {
props.load(in);
} finally {
in.close();
}
String versionState = props.getProperty("versionState");
try {
if (versionState != null)
currentVersionState = Integer.valueOf(versionState);
} catch (NumberFormatException e) {
}
}
} catch (IOException e1) {
// Ignore
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.CONTENT_DISPOSITION, download ? "attachment" : "inline");
return new ResponseEntity<>(new UpdateLicensePayloadModel(Providers.get(ICoreLicense.class).getGuid(), SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION), Common.envProps.getString("distributor"), jsonModules, storeUrl, upgradeVersionState, currentVersionState), responseHeaders, HttpStatus.OK);
}
use of com.serotonin.m2m2.UpgradeVersionState in project ma-core-public by infiniteautomation.
the class ModulesService method getAvailableUpgrades.
/**
* Get the information for available upgrades
*/
public JsonValue getAvailableUpgrades() throws JsonException, IOException, HttpException {
permissionService.ensureAdminRole(Common.getUser());
if (env.getProperty("store.disableUpgrades", Boolean.class, false)) {
throw new FeatureDisabledException(new TranslatableMessage("modules.error.upgradesDisabled"));
}
// Create the request
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
Map<String, Object> json = new HashMap<>();
json.put("guid", Providers.get(ICoreLicense.class).getGuid());
json.put("description", SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
json.put("distributor", env.getProperty("distributor"));
json.put("upgradeVersionState", SystemSettingsDao.getInstance().getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
Properties props = new Properties();
Path propFile = Common.MA_HOME_PATH.resolve("release.properties");
int versionState = UpgradeVersionState.DEVELOPMENT;
if (Files.isRegularFile(propFile)) {
try (InputStream in = Files.newInputStream(propFile)) {
props.load(in);
}
String currentVersionState = props.getProperty("versionState");
try {
if (currentVersionState != null)
versionState = Integer.parseInt(currentVersionState);
} catch (NumberFormatException e) {
}
}
json.put("currentVersionState", versionState);
Map<String, String> jsonModules = new HashMap<>();
json.put("modules", jsonModules);
Version coreVersion = Common.getVersion();
jsonModules.put(ModuleRegistry.CORE_MODULE_NAME, coreVersion.toString());
for (Module module : modules) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
// Add in the unloaded modules so we don't re-download them if we don't have to
for (Module module : ModuleRegistry.getUnloadedModules()) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
// Optionally Add Usage Data Check if first login for admin has happened to ensure they have
if (SystemSettingsDao.getInstance().getBooleanValue(SystemSettingsDao.USAGE_TRACKING_ENABLED)) {
// Collect statistics
List<DataSourceUsageStatistics> dataSourceCounts = DataSourceDao.getInstance().getUsage();
json.put("dataSourcesUsage", dataSourceCounts);
List<DataPointUsageStatistics> dataPointCounts = DataPointDao.getInstance().getUsage();
json.put("dataPointsUsage", dataPointCounts);
List<PublisherUsageStatistics> publisherUsage = PublisherDao.getInstance().getUsage();
json.put("publishersUsage", publisherUsage);
List<PublisherPointsUsageStatistics> publisherPointsUsageStatistics = publishedPointDao.getUsage();
json.put("publisherPointsUsage", publisherPointsUsageStatistics);
for (ValueMonitor<?> m : Common.MONITORED_VALUES.getMonitors()) {
if (m.isUploadToStore()) {
if (m.getValue() != null) {
json.put(m.getId(), m.getValue());
}
}
}
}
StringWriter stringWriter = new StringWriter();
new JsonWriter(Common.JSON_CONTEXT, stringWriter).writeObject(json);
String requestData = stringWriter.toString();
// Send the request
String baseUrl = env.getProperty("store.url");
if (StringUtils.isEmpty(baseUrl)) {
log.info("No version check performed as no store.url is defined in configuration file.");
return null;
}
baseUrl += "/servlet/versionCheck";
HttpPost post = new HttpPost(baseUrl);
post.setEntity(new StringEntity(requestData));
String responseData = HttpUtils4.getTextContent(Common.getHttpClient(), post, 1);
// Parse the response
JsonTypeReader jsonReader = new JsonTypeReader(responseData);
return jsonReader.read();
}
Aggregations