Search in sources :

Example 1 with TopBraidException

use of org.mskcc.oncotree.topbraid.TopBraidException 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 TopBraidException

use of org.mskcc.oncotree.topbraid.TopBraidException in project oncotree by cBioPortal.

the class OncotreeTestConfig method resetNotWorkingVersionRepository.

public void resetNotWorkingVersionRepository(OncoTreeVersionRepository mockRepository) {
    Mockito.reset(mockRepository);
    Mockito.when(mockRepository.getOncoTreeVersions()).thenThrow(new TopBraidException("faking a problem getting the topbraid data"));
}
Also used : TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException)

Example 3 with TopBraidException

use of org.mskcc.oncotree.topbraid.TopBraidException in project oncotree by cBioPortal.

the class OncotreeTestConfig method resetNotWorkingRepository.

public void resetNotWorkingRepository(OncoTreeRepository mockRepository) {
    Mockito.reset(mockRepository);
    Mockito.when(mockRepository.getOncoTree(any(Version.class))).thenThrow(new TopBraidException("faking a problem getting the topbraid data"));
}
Also used : Version(org.mskcc.oncotree.model.Version) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException)

Aggregations

TopBraidException (org.mskcc.oncotree.topbraid.TopBraidException)3 Version (org.mskcc.oncotree.model.Version)2 InvalidOncoTreeDataException (org.mskcc.oncotree.error.InvalidOncoTreeDataException)1 InvalidVersionException (org.mskcc.oncotree.error.InvalidVersionException)1 TumorType (org.mskcc.oncotree.model.TumorType)1 OncoTreeNode (org.mskcc.oncotree.topbraid.OncoTreeNode)1