Search in sources :

Example 1 with Version

use of org.mskcc.oncotree.model.Version in project oncotree by cBioPortal.

the class CacheUtil method resetCache.

public void resetCache() throws FailedCacheRefreshException {
    logger.info("resetCache() -- refilling tumor types cache");
    Map<Version, Map<String, TumorType>> latestTumorTypesCache = new HashMap<>();
    ArrayList<Version> oncoTreeVersions = new ArrayList<Version>();
    ArrayList<String> failedVersions = new ArrayList<String>();
    // use this to store and look up previous oncoTree codes
    HashMap<String, ArrayList<String>> topBraidURIsToOncotreeCodes = new HashMap<String, ArrayList<String>>();
    boolean failedOncoTreeVersionsCacheRefresh = false;
    boolean failedVersionedOncoTreeNodesCacheRefresh = false;
    // update EHCache with newest versions available
    try {
        oncoTreePersistentCache.updateOncoTreeVersionsInPersistentCache();
    } catch (TopBraidException exception) {
        logger.error("resetCache() -- failed to pull versions from repository");
        failedOncoTreeVersionsCacheRefresh = true;
    }
    // attmpt to get versions from EHCache -- RuntimeException thrown when ALL options are exhausted (ehcache, topbraid, backup)
    try {
        oncoTreeVersions = oncoTreePersistentCache.getOncoTreeVersionsFromPersistentCache();
    } catch (RuntimeException e) {
        throw new FailedCacheRefreshException("No data found in specified backup cache location...");
    }
    if (!failedOncoTreeVersionsCacheRefresh) {
        try {
            oncoTreePersistentCache.backupOncoTreeVersionsPersistentCache(oncoTreeVersions);
        } catch (Exception e) {
            logger.error("Unable to backup versions EHCache");
            slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeVersionsCache backup failed." + e.getMessage());
        }
    }
    // versions are ascending by release date
    for (Version version : oncoTreeVersions) {
        Map<String, TumorType> latestTumorTypes = new HashMap<String, TumorType>();
        ArrayList<OncoTreeNode> oncoTreeNodes = new ArrayList<OncoTreeNode>();
        failedVersionedOncoTreeNodesCacheRefresh = false;
        if (version != null) {
            try {
                oncoTreePersistentCache.updateOncoTreeNodesInPersistentCache(version);
            } catch (TopBraidException e) {
                logger.error("resetCache() -- failed to pull tumor types for version '" + version.getVersion() + "' from repository : " + e.toString());
                failedVersionedOncoTreeNodesCacheRefresh = true;
            }
            // store versions for which nodes cannot be successfully loaded (either due to inaccessible data or invalid data)
            try {
                oncoTreeNodes = oncoTreePersistentCache.getOncoTreeNodesFromPersistentCache(version);
            } catch (RuntimeException e) {
                failedVersions.add(version.getVersion());
                logger.warn("resetCache() -- failed to retrieve version '" + version.getVersion() + "'");
                continue;
            }
            if (!failedVersionedOncoTreeNodesCacheRefresh) {
                try {
                    oncoTreePersistentCache.backupOncoTreeNodesPersistentCache(oncoTreeNodes, version);
                } catch (Exception e) {
                    logger.error("Unable to backup oncotree nodes EHCache");
                    slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeNodesCache backup failed." + e.getMessage());
                }
            }
            try {
                latestTumorTypes = tumorTypesUtil.getAllTumorTypesFromOncoTreeNodes(oncoTreeNodes, version, topBraidURIsToOncotreeCodes);
            } catch (InvalidOncoTreeDataException exception) {
                logger.error("Unable to get tumor types from oncotree nodes");
                failedVersions.add(version.getVersion());
                logger.warn("resetCache() -- failed to retrieve version : " + version.getVersion() + " : " + exception.toString());
                continue;
            }
        }
        latestTumorTypesCache.put(version, latestTumorTypes);
    }
    // Fail the cache refresh if required oncotree version cannot be constructed or if no versions can be constructed
    if (latestTumorTypesCache.keySet().size() == 0) {
        logger.error("resetCache() -- failed to pull a single valid OncoTree version");
        throw new FailedCacheRefreshException("Failed to refresh cache - no versions constructed");
    }
    if (failedVersions.contains(requiredOncotreeVersion)) {
        logger.error("resetCache() -- failed to pull required oncotree version: " + requiredOncotreeVersion);
        throw new FailedCacheRefreshException("Failed to refresh cache - required version not constructed");
    }
    if (failedVersions.size() > 0) {
        slackUtil.sendSlackNotification("OncoTree successfully recached `" + requiredOncotreeVersion + "`, but ran into issues with the following versions: " + String.join(", ", failedVersions));
    }
    tumorTypesCache = latestTumorTypesCache;
    // cache is filled, but indicate to endpoint that we did not successfully pull updated data from TopBraid
    if (failedOncoTreeVersionsCacheRefresh || failedVersionedOncoTreeNodesCacheRefresh) {
        throw new FailedCacheRefreshException("Failed to refresh cache - composite error");
    } else {
        dateOfLastCacheRefresh = new Date();
        logger.info("resetCache() -- successfully reset cache from repository");
    }
}
Also used : InvalidOncoTreeDataException(org.mskcc.oncotree.error.InvalidOncoTreeDataException) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException) OncoTreeNode(org.mskcc.oncotree.topbraid.OncoTreeNode) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException) InvalidVersionException(org.mskcc.oncotree.error.InvalidVersionException) InvalidOncoTreeDataException(org.mskcc.oncotree.error.InvalidOncoTreeDataException) TumorType(org.mskcc.oncotree.model.TumorType) Version(org.mskcc.oncotree.model.Version)

Example 2 with Version

use of org.mskcc.oncotree.model.Version in project oncotree by cBioPortal.

the class MSKConceptCache method resetCache.

@EventListener(ApplicationReadyEvent.class)
// call every Sunday at 3am
@Scheduled(cron = "0 0 3 * * SUN")
private // the actual returned MSKConcept is not necessary for webapp deployment
void resetCache() throws Exception {
    logger.info("resetCache() -- attempting to refresh Crosswalk MSKConcept cache");
    HashMap<String, MSKConcept> latestOncoTreeCodesToMSKConcepts = new HashMap<String, MSKConcept>();
    ArrayList<Version> oncoTreeVersions = new ArrayList<Version>();
    try {
        oncoTreeVersions = oncoTreePersistentCache.getOncoTreeVersionsFromPersistentCache();
    } catch (RuntimeException e) {
        throw new FailedCacheRefreshException("Failed to refresh MSKConceptCache, unable to load verisons...");
    }
    for (Version version : oncoTreeVersions) {
        ArrayList<OncoTreeNode> oncoTreeNodes = new ArrayList<OncoTreeNode>();
        try {
            oncoTreeNodes = oncoTreePersistentCache.getOncoTreeNodesFromPersistentCache(version);
        } catch (RuntimeException e) {
            throw new FailedCacheRefreshException("Failed to refresh MSKConceptCache : " + e.toString());
        }
        for (OncoTreeNode node : oncoTreeNodes) {
            // skip querying repeated nodes/MSKConcepts
            if (!latestOncoTreeCodesToMSKConcepts.containsKey(node.getCode())) {
                // pull from crosswalk first
                oncoTreePersistentCache.updateMSKConceptInPersistentCache(node.getCode());
                MSKConcept concept = oncoTreePersistentCache.getMSKConceptFromPersistentCache(node.getCode());
                latestOncoTreeCodesToMSKConcepts.put(node.getCode(), concept);
            }
        }
    }
    // save all MSKConcepts at once
    try {
        oncoTreePersistentCache.backupMSKConceptPersistentCache(latestOncoTreeCodesToMSKConcepts);
    } catch (Exception e) {
        logger.error("Unable to backup MSKConcepts in EHCache");
        slackUtil.sendSlackNotification("*OncoTree Error* - MSKConceptCache backup failed." + e.getMessage());
    }
}
Also used : FailedCacheRefreshException(org.mskcc.oncotree.utils.FailedCacheRefreshException) Version(org.mskcc.oncotree.model.Version) OncoTreeNode(org.mskcc.oncotree.topbraid.OncoTreeNode) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException) FailedCacheRefreshException(org.mskcc.oncotree.utils.FailedCacheRefreshException) Scheduled(org.springframework.scheduling.annotation.Scheduled) EventListener(org.springframework.context.event.EventListener)

Example 3 with Version

use of org.mskcc.oncotree.model.Version in project oncotree by cBioPortal.

the class OncotreeTestConfig method setupLatestVersion.

private Version setupLatestVersion() {
    Version latestVersion = new Version();
    latestVersion = new Version();
    latestVersion.setVersion("oncotree_latest_stable");
    latestVersion.setGraphURI("urn:x-evn-master:oncotree_2017_06_21");
    latestVersion.setDescription("This is an alias for whatever OncoTree version is the latest stable (timestamped) release.");
    return latestVersion;
}
Also used : Version(org.mskcc.oncotree.model.Version)

Example 4 with Version

use of org.mskcc.oncotree.model.Version in project oncotree by cBioPortal.

the class OncotreeTestConfig method legacyVersion.

@Bean
public Version legacyVersion() {
    Version legacyVersion = new Version();
    legacyVersion.setVersion("oncotree_legacy_1.1");
    legacyVersion.setGraphURI("urn:x-evn-master:oncotree_legacy_1_1");
    legacyVersion.setDescription("This is the closest match in TopBraid for the TumorTypes_txt file associated with release 1.1 of OncoTree (approved by committee)");
    return legacyVersion;
}
Also used : Version(org.mskcc.oncotree.model.Version) Bean(org.springframework.context.annotation.Bean)

Example 5 with Version

use of org.mskcc.oncotree.model.Version in project oncotree by cBioPortal.

the class OncotreeTestConfig method oncoTreeVersionRepositoryMockResponse.

@Bean
public ArrayList<Version> oncoTreeVersionRepositoryMockResponse() {
    ArrayList<Version> oncoTreeVersionRepositoryMockResponse = new ArrayList<Version>();
    // versions are always supposed to be in ascending order
    oncoTreeVersionRepositoryMockResponse.add(legacyVersion());
    Version nextVersion = new Version();
    nextVersion.setVersion("oncotree_2017_06_21");
    nextVersion.setGraphURI("urn:x-evn-master:oncotree_2017_06_21");
    nextVersion.setDescription("Stable OncoTree released on date 2017-06-21");
    oncoTreeVersionRepositoryMockResponse.add(nextVersion);
    oncoTreeVersionRepositoryMockResponse.add(latestVersion());
    nextVersion = new Version();
    nextVersion.setVersion("oncotree_development");
    nextVersion.setGraphURI("urn:x-evn-master:oncotree_current");
    nextVersion.setDescription("Latest OncoTree under development (subject to change without notice)");
    oncoTreeVersionRepositoryMockResponse.add(nextVersion);
    return oncoTreeVersionRepositoryMockResponse;
}
Also used : Version(org.mskcc.oncotree.model.Version) Bean(org.springframework.context.annotation.Bean)

Aggregations

Version (org.mskcc.oncotree.model.Version)15 Test (org.junit.Test)5 TumorType (org.mskcc.oncotree.model.TumorType)3 Bean (org.springframework.context.annotation.Bean)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 OncoTreeNode (org.mskcc.oncotree.topbraid.OncoTreeNode)2 TopBraidException (org.mskcc.oncotree.topbraid.TopBraidException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 InputStream (java.io.InputStream)1 Deprecated (java.lang.Deprecated)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CacheManager (javax.cache.CacheManager)1 InvalidOncoTreeDataException (org.mskcc.oncotree.error.InvalidOncoTreeDataException)1 InvalidVersionException (org.mskcc.oncotree.error.InvalidVersionException)1 FailedCacheRefreshException (org.mskcc.oncotree.utils.FailedCacheRefreshException)1 Cacheable (org.springframework.cache.annotation.Cacheable)1 EventListener (org.springframework.context.event.EventListener)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1