use of com.infiniteautomation.mango.util.usage.PublisherPointsUsageStatistics 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();
}
use of com.infiniteautomation.mango.util.usage.PublisherPointsUsageStatistics in project ma-core-public by infiniteautomation.
the class PublishedPointDao method getUsage.
/**
* Count the points for a type of publisher (used for metrics reporting)
*/
public List<PublisherPointsUsageStatistics> getUsage() {
Field<Integer> count = DSL.count(table.id);
return create.select(publishers.publisherType, count).from(table).join(publishers).on(publishers.id.eq(table.publisherId)).groupBy(publishers.publisherType).fetch().map(record -> {
PublisherPointsUsageStatistics usage = new PublisherPointsUsageStatistics();
usage.setPublisherType(record.get(publishers.publisherType));
usage.setCount(record.get(count));
return usage;
});
}
Aggregations