Search in sources :

Example 1 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionVerifier method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    for (final Map.Entry<String, Version> productVersionEntry : this.requiredProductVersions.entrySet()) {
        final String product = productVersionEntry.getKey();
        final Version dbVersion = this.versionDao.getVersion(product);
        if (dbVersion == null) {
            throw new ApplicationContextException("No Version exists for " + product + " in the database. Please check the upgrade instructions for this release.");
        }
        final Version codeVersion = productVersionEntry.getValue();
        final Field mostSpecificMatchingField = VersionUtils.getMostSpecificMatchingField(dbVersion, codeVersion);
        switch(mostSpecificMatchingField) {
            //Versions completely match
            case LOCAL:
                {
                    logger.info("Software and Database versions are both {} for {}", dbVersion, product);
                    continue;
                }
            //Versions match except for local part
            case PATCH:
            //Versions match except for patch.local part
            case MINOR:
                {
                    //If db is before code and auto-update is enabled run hibernate-update
                    final Field upgradeField = mostSpecificMatchingField.getLessImportant();
                    if (dbVersion.isBefore(codeVersion) && this.updatePolicy != null && (upgradeField.equals(this.updatePolicy) || upgradeField.isLessImportantThan(this.updatePolicy))) {
                        logger.info("Automatically updating database from {} to {} for {}", dbVersion, codeVersion, product);
                        this.portalShellBuildHelper.hibernateUpdate("automated-hibernate-update", product, true, null);
                        continue;
                    } else if (codeVersion.isBefore(dbVersion)) {
                        //It is ok to run older code on a newer DB within the local/patch range
                        continue;
                    }
                }
            //Versions match except for minor.patch.local part
            case MAJOR:
            //Versions do not match at all
            default:
                {
                    if (dbVersion.isBefore(codeVersion)) {
                        throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". Please check the upgrade instructions for this release");
                    } else {
                        throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". It is not possible to run ");
                    }
                }
        }
    }
}
Also used : Field(org.apereo.portal.version.om.Version.Field) Version(org.apereo.portal.version.om.Version) ApplicationContextException(org.springframework.context.ApplicationContextException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionUtilsTest method testGetMostSpecificMatchingField.

@Test
public void testGetMostSpecificMatchingField() {
    Version v1 = VersionUtils.parseVersion("4.0.5");
    Version v2 = VersionUtils.parseVersion("4.0.5");
    assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v2, v1));
    v2 = VersionUtils.parseVersion("4.0.5.1");
    assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v2, v1));
    v1 = VersionUtils.parseVersion("4.0.5.2");
    v2 = VersionUtils.parseVersion("4.0.5.3");
    assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertEquals(Version.Field.PATCH, VersionUtils.getMostSpecificMatchingField(v2, v1));
    v2 = VersionUtils.parseVersion("4.0.6");
    assertEquals(Version.Field.MINOR, VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertEquals(Version.Field.MINOR, VersionUtils.getMostSpecificMatchingField(v2, v1));
    v2 = VersionUtils.parseVersion("4.1.0.0");
    assertEquals(Version.Field.MAJOR, VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertEquals(Version.Field.MAJOR, VersionUtils.getMostSpecificMatchingField(v2, v1));
    v2 = VersionUtils.parseVersion("5.6.7");
    assertNull(VersionUtils.getMostSpecificMatchingField(v1, v2));
    assertNull(VersionUtils.getMostSpecificMatchingField(v2, v1));
}
Also used : Version(org.apereo.portal.version.om.Version) Test(org.junit.Test)

Example 3 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionUtilsTest method testVersionParsing.

@Test
public void testVersionParsing() {
    Version version = VersionUtils.parseVersion("4.0.5");
    assertNotNull(version);
    assertEquals(4, version.getMajor());
    assertEquals(0, version.getMinor());
    assertEquals(5, version.getPatch());
    assertNull(version.getLocal());
    version = VersionUtils.parseVersion("4.0.5.3");
    assertNotNull(version);
    assertEquals(4, version.getMajor());
    assertEquals(0, version.getMinor());
    assertEquals(5, version.getPatch());
    assertEquals(Integer.valueOf(3), version.getLocal());
}
Also used : Version(org.apereo.portal.version.om.Version) Test(org.junit.Test)

Example 4 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionUtilsTest method testVersionUpgrade.

@Test
public void testVersionUpgrade() {
    Version v1 = VersionUtils.parseVersion("4.0.5");
    Version v2 = VersionUtils.parseVersion("4.0.5");
    assertTrue(VersionUtils.canUpdate(v1, v2));
    assertTrue(VersionUtils.canUpdate(v2, v1));
    v2 = VersionUtils.parseVersion("4.0.5.1");
    assertTrue(VersionUtils.canUpdate(v1, v2));
    assertFalse(VersionUtils.canUpdate(v2, v1));
    v1 = VersionUtils.parseVersion("4.0.5.2");
    v2 = VersionUtils.parseVersion("4.0.5.3");
    assertTrue(VersionUtils.canUpdate(v1, v2));
    assertFalse(VersionUtils.canUpdate(v2, v1));
    v2 = VersionUtils.parseVersion("4.0.6");
    assertTrue(VersionUtils.canUpdate(v1, v2));
    assertFalse(VersionUtils.canUpdate(v2, v1));
}
Also used : Version(org.apereo.portal.version.om.Version) Test(org.junit.Test)

Example 5 with Version

use of org.apereo.portal.version.om.Version in project uPortal by Jasig.

the class VersionedDataUpdaterImpl method preUpdateDatabase.

@Override
@OpenEntityManager(unitName = BasePortalJpaDao.PERSISTENCE_UNIT_NAME)
public void preUpdateDatabase(String product) {
    //This happens first because even if there are no updaters we need to make sure the attempted update is valid
    final Version dbVersion = getAndVerifyDatabaseVersionForUpdate(product);
    final SortedSet<IVersionedDatabaseUpdateHelper> updateHelpers = this.databaseUpdateHelpers.get(product);
    if (updateHelpers == null || updateHelpers.isEmpty()) {
        logger.info("No IVersionedDatabaseUpdateHelpers configured for database {}, nothing will be done in preUpdate", product);
    } else {
        //updateHelpers is sorted oldest to newest by version so iterate through and run the updaters that apply
        for (final IVersionedDatabaseUpdateHelper updateHelper : updateHelpers) {
            final Version updateVersion = updateHelper.getVersion();
            if (dbVersion.equals(updateVersion) || dbVersion.isBefore(updateVersion)) {
                logger.info("PreUpdate {} from {} to {}", product, dbVersion, updateVersion);
                updateHelper.preUpdate();
                logger.info("PreUpdate {} from {} to {} complete", product, dbVersion, updateVersion);
            }
        }
    }
}
Also used : Version(org.apereo.portal.version.om.Version)

Aggregations

Version (org.apereo.portal.version.om.Version)12 Test (org.junit.Test)5 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)2 PortalTransactional (org.apereo.portal.jpa.BasePortalJpaDao.PortalTransactional)2 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Field (org.apereo.portal.version.om.Version.Field)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1