Search in sources :

Example 1 with PublisherUsageStatistics

use of com.infiniteautomation.mango.util.usage.PublisherUsageStatistics in project ma-core-public by infiniteautomation.

the class PublisherDao method getUsage.

/**
 * Get the count of data sources per type
 */
public List<PublisherUsageStatistics> getUsage() {
    Field<Integer> count = DSL.count(table.publisherType);
    List<PublisherUsageStatistics> publisherUsageStatistics = create.select(table.publisherType, count).from(table).groupBy(table.publisherType).fetch().map(record -> {
        PublisherUsageStatistics usage = new PublisherUsageStatistics();
        usage.setPublisherType(record.get(table.publisherType));
        usage.setCount(record.get(count));
        return usage;
    });
    return publisherUsageStatistics;
}
Also used : PublisherUsageStatistics(com.infiniteautomation.mango.util.usage.PublisherUsageStatistics)

Example 2 with PublisherUsageStatistics

use of com.infiniteautomation.mango.util.usage.PublisherUsageStatistics 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();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HashMap(java.util.HashMap) JsonString(com.serotonin.json.type.JsonString) Properties(java.util.Properties) FeatureDisabledException(com.infiniteautomation.mango.util.exception.FeatureDisabledException) PublisherPointsUsageStatistics(com.infiniteautomation.mango.util.usage.PublisherPointsUsageStatistics) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) Version(com.github.zafarkhaja.semver.Version) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Path(java.nio.file.Path) PublisherUsageStatistics(com.infiniteautomation.mango.util.usage.PublisherUsageStatistics) InputStream(java.io.InputStream) JsonWriter(com.serotonin.json.JsonWriter) DataSourceUsageStatistics(com.infiniteautomation.mango.util.usage.DataSourceUsageStatistics) JsonObject(com.serotonin.json.type.JsonObject) DataPointUsageStatistics(com.infiniteautomation.mango.util.usage.DataPointUsageStatistics) Module(com.serotonin.m2m2.module.Module) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Aggregations

PublisherUsageStatistics (com.infiniteautomation.mango.util.usage.PublisherUsageStatistics)2 Version (com.github.zafarkhaja.semver.Version)1 FeatureDisabledException (com.infiniteautomation.mango.util.exception.FeatureDisabledException)1 DataPointUsageStatistics (com.infiniteautomation.mango.util.usage.DataPointUsageStatistics)1 DataSourceUsageStatistics (com.infiniteautomation.mango.util.usage.DataSourceUsageStatistics)1 PublisherPointsUsageStatistics (com.infiniteautomation.mango.util.usage.PublisherPointsUsageStatistics)1 JsonWriter (com.serotonin.json.JsonWriter)1 JsonObject (com.serotonin.json.type.JsonObject)1 JsonString (com.serotonin.json.type.JsonString)1 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 Module (com.serotonin.m2m2.module.Module)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1