Search in sources :

Example 1 with UpgradeVersionState

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);
}
Also used : SystemSettingsDao(com.serotonin.m2m2.db.dao.SystemSettingsDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with 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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonString(com.serotonin.json.type.JsonString) IOException(java.io.IOException) Properties(java.util.Properties) ICoreLicense(com.serotonin.m2m2.ICoreLicense) FileInputStream(java.io.FileInputStream) ResponseEntity(org.springframework.http.ResponseEntity) UpdateLicensePayloadModel(com.infiniteautomation.mango.rest.latest.model.modules.UpdateLicensePayloadModel) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with UpgradeVersionState

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();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonString(com.serotonin.json.type.JsonString) Properties(java.util.Properties) JsonWriter(com.serotonin.json.JsonWriter) FileInputStream(java.io.FileInputStream) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) Version(com.github.zafarkhaja.semver.Version) JsonObject(com.serotonin.json.type.JsonObject) Module(com.serotonin.m2m2.module.Module) File(java.io.File) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 4 with 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);
    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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonString(com.serotonin.json.type.JsonString) IOException(java.io.IOException) Properties(java.util.Properties) ICoreLicense(com.serotonin.m2m2.ICoreLicense) FileInputStream(java.io.FileInputStream) ResponseEntity(org.springframework.http.ResponseEntity) UpdateLicensePayloadModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpdateLicensePayloadModel) Module(com.serotonin.m2m2.module.Module) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with UpgradeVersionState

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();
}
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

JsonString (com.serotonin.json.type.JsonString)4 Module (com.serotonin.m2m2.module.Module)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Version (com.github.zafarkhaja.semver.Version)2 JsonWriter (com.serotonin.json.JsonWriter)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)2 ICoreLicense (com.serotonin.m2m2.ICoreLicense)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 ZipInputStream (java.util.zip.ZipInputStream)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2