Search in sources :

Example 1 with Release

use of org.nzbhydra.mapping.github.Release in project nzbhydra2 by theotherp.

the class UpdateManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    testee.currentVersionString = "1.0.0";
    testee.repositoryBaseUrl = "http:/127.0.0.1:7070/repos/theotherp/apitests";
    testee.changelogUrl = "http:/127.0.0.1:7070/changelog";
    testee.blockedVersionsUrl = "http:/127.0.0.1:7070/blockedVersions.json";
    testee.afterPropertiesSet();
    Release latestRelease = new Release();
    latestRelease.setTagName("v2.0.0");
    latestRelease.setBody("Some new stuff");
    Release previousRelease = new Release();
    previousRelease.setTagName("v1.0.0");
    previousRelease.setBody("A list:\n" + "* a\n" + "* b");
    when(webAccessMock.callUrl(startsWith("http:/127.0.0.1:7070/repos/theotherp/apitests/releases/latest"), any(), any())).thenReturn(latestRelease);
    // Return in wrong order to test sorting of releases by version
    when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/repos/theotherp/apitests/releases"), any(), any())).thenReturn(Arrays.asList(previousRelease, latestRelease));
    when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/changelog"), any(TypeReference.class))).thenReturn(Arrays.asList(new ChangelogVersionEntry("3.0.0", Arrays.asList(new ChangelogChangeEntry("note", "a note"))), new ChangelogVersionEntry("2.0.0", Arrays.asList(new ChangelogChangeEntry("fix", "a minor fix"))), new ChangelogVersionEntry("0.0.1", Arrays.asList(new ChangelogChangeEntry("feature", "a new feature")))));
    when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/blockedVersions.json"), any(TypeReference.class))).thenReturn(Arrays.asList(new BlockedVersion("3.0.0", "comment")));
}
Also used : ChangelogChangeEntry(org.nzbhydra.mapping.changelog.ChangelogChangeEntry) ChangelogVersionEntry(org.nzbhydra.mapping.changelog.ChangelogVersionEntry) TypeReference(com.fasterxml.jackson.core.type.TypeReference) BlockedVersion(org.nzbhydra.update.UpdateManager.BlockedVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Release(org.nzbhydra.mapping.github.Release) Before(org.junit.Before)

Example 2 with Release

use of org.nzbhydra.mapping.github.Release in project nzbhydra2 by theotherp.

the class UpdateManager method getLatestVersion.

private SemanticVersion getLatestVersion() throws UpdateException {
    Release latestRelease = latestReleaseCache.get();
    latestVersion = new SemanticVersion(latestRelease.getTagName());
    return latestVersion;
}
Also used : Release(org.nzbhydra.mapping.github.Release) SemanticVersion(org.nzbhydra.mapping.SemanticVersion)

Example 3 with Release

use of org.nzbhydra.mapping.github.Release in project nzbhydra2 by theotherp.

the class UpdateManager method installUpdate.

public void installUpdate() throws UpdateException {
    Release latestRelease = latestReleaseCache.get();
    logger.info("Starting update process to {}", latestRelease.getTagName());
    Asset asset = getAsset(latestRelease);
    String url = asset.getBrowserDownloadUrl();
    logger.debug("Downloading update from URL {}", url);
    File updateZip;
    try {
        File updateFolder = new File(NzbHydra.getDataFolder(), "update");
        if (!updateFolder.exists()) {
            logger.debug("Creating update folder {}", updateFolder);
            Files.createDirectory(updateFolder.toPath());
        } else {
            logger.debug("Cleaning update folder {}", updateFolder.getAbsolutePath());
            FileUtils.cleanDirectory(updateFolder);
        }
        updateZip = new File(updateFolder, asset.getName());
        logger.debug("Saving update file as {}", updateZip.getAbsolutePath());
        applicationEventPublisher.publishEvent(new UpdateEvent("Downloading update file"));
        webAccess.downloadToFile(url, updateZip);
    } catch (RestClientException | IOException e) {
        logger.error("Error while download or saving ZIP", e);
        throw new UpdateException("Error while downloading, saving or extracting update ZIP", e);
    }
    if (configProvider.getBaseConfig().getMain().isBackupBeforeUpdate()) {
        try {
            logger.info("Creating backup before shutting down");
            applicationEventPublisher.publishEvent(new UpdateEvent("Creating backup before update"));
            backupAndRestore.backup();
        } catch (Exception e) {
            throw new UpdateException("Unable to create backup before update", e);
        }
    }
    logger.info("Shutting down to let wrapper execute the update");
    applicationEventPublisher.publishEvent(new UpdateEvent("Shutting down to let wrapper execute update"));
    exitWithReturnCode(UPDATE_RETURN_CODE);
}
Also used : RestClientException(org.springframework.web.client.RestClientException) Asset(org.nzbhydra.mapping.github.Asset) IOException(java.io.IOException) File(java.io.File) Release(org.nzbhydra.mapping.github.Release) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException)

Aggregations

Release (org.nzbhydra.mapping.github.Release)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 SemanticVersion (org.nzbhydra.mapping.SemanticVersion)1 ChangelogChangeEntry (org.nzbhydra.mapping.changelog.ChangelogChangeEntry)1 ChangelogVersionEntry (org.nzbhydra.mapping.changelog.ChangelogVersionEntry)1 Asset (org.nzbhydra.mapping.github.Asset)1 BlockedVersion (org.nzbhydra.update.UpdateManager.BlockedVersion)1 RestClientException (org.springframework.web.client.RestClientException)1