use of org.talend.dataprep.api.service.upgrade.UpgradeServerVersion in project data-prep by Talend.
the class UpgradeAPI method fetchServerUpgradeVersions.
private List<UpgradeServerVersion> fetchServerUpgradeVersions(org.talend.dataprep.info.Version version) throws IOException {
final HttpPost post = new HttpPost(upgradeVersionLocation);
final String response;
final StringWriter content = new StringWriter();
try (final JsonGenerator generator = mapper.getFactory().createGenerator(content)) {
generator.writeStartObject();
generator.writeStringField("version", version.getVersionId());
generator.writeStringField("id", token);
generator.writeEndObject();
generator.flush();
post.setEntity(new StringEntity(content.toString(), ContentType.APPLICATION_JSON.withCharset(UTF_8)));
response = IOUtils.toString(httpClient.execute(post).getEntity().getContent(), UTF_8);
} finally {
post.releaseConnection();
}
// Read upgrade server response
return mapper.readerFor(new TypeReference<List<UpgradeServerVersion>>() {
}).readValue(response);
}
use of org.talend.dataprep.api.service.upgrade.UpgradeServerVersion in project data-prep by Talend.
the class UpgradeAPI method check.
@RequestMapping(value = "/api/upgrade/check", method = GET)
@ApiOperation(value = "Checks if a newer versions are available and returns them as JSON.", produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@PublicAPI
public Stream<UpgradeServerVersion> check() {
// defensive programming
if (StringUtils.isBlank(upgradeVersionLocation)) {
return Stream.empty();
}
try {
// Get current version
final Version parsedCurrentVersion = fromInternal(service.version());
// POST to URL that serves a JSON Version object
LOGGER.debug("Contacting upgrade server @ '{}'", upgradeVersionLocation);
List<UpgradeServerVersion> versions = fetchServerUpgradeVersions(service.version());
LOGGER.debug("{} available version(s) returned by update server: {}", versions.size(), toString(versions));
// Compare current version with available and filter new versions
return versions.stream().filter(v -> Version.valueOf(v.getVersion()).greaterThan(parsedCurrentVersion));
} catch (Exception e) {
LOGGER.error("Unable to check for new version (message: {}).", e.getMessage());
LOGGER.debug("Exception occurred during new version check. ", e);
return Stream.empty();
}
}
use of org.talend.dataprep.api.service.upgrade.UpgradeServerVersion in project data-prep by Talend.
the class UpgradeAPITest method checkStaticUpgradeServer.
@Test
public void checkStaticUpgradeServer() throws Exception {
// Given
// Server deliver always same response based (does *not* depend on sent content)
upgradeAPI.setUpgradeVersionLocation("http://localhost:" + port + "/upgrade/server/static");
final Version nextVersion = computeNextVersion(versionService);
UpgradeServerVersion expected = new UpgradeServerVersion();
expected.setVersion(nextVersion.toString());
expected.setTitle("My Title 2");
expected.setDownloadUrl("http://www.amazingdownload.com/2");
expected.setReleaseNoteUrl("http://www.amazingrelease.com/2");
// When
String actual = RestAssured.when().get("/api/upgrade/check").asString();
List<UpgradeServerVersion> actualParsed = mapper.readerFor(UpgradeServerVersion.class).<UpgradeServerVersion>readValues(actual).readAll();
// Then
Assert.assertEquals(1, actualParsed.size());
Assert.assertEquals(expected, actualParsed.get(0));
}
use of org.talend.dataprep.api.service.upgrade.UpgradeServerVersion in project data-prep by Talend.
the class UpgradeAPITest method checkDynamicUpgradeServer.
@Test
public void checkDynamicUpgradeServer() throws Exception {
// When
// Server deliver response based on sent content
upgradeAPI.setUpgradeVersionLocation("http://localhost:" + port + "/upgrade/server/dynamic");
// Then
String response = RestAssured.when().get("/api/upgrade/check").asString();
final List<UpgradeServerVersion> versions = mapper.readerFor(new TypeReference<List<UpgradeServerVersion>>() {
}).readValue(response);
assertEquals(1, versions.size());
final UpgradeServerVersion actual = versions.get(0);
final String expectedVersion = versionService.version().getVersionId();
final String expectedToken = TokenGenerator.generateMachineToken(new CryptoHelper("DataPrepIsSoCool"));
assertEquals(expectedToken, actual.getTitle());
assertEquals(expectedVersion, actual.getDownloadUrl());
}
use of org.talend.dataprep.api.service.upgrade.UpgradeServerVersion in project data-prep by Talend.
the class UpgradeAPI method toString.
private static String toString(List<UpgradeServerVersion> versions) {
final StringBuilder builder = new StringBuilder();
builder.append("[ ");
for (UpgradeServerVersion version : versions) {
builder.append(version.getVersion()).append(' ');
}
builder.append(']');
return builder.toString();
}
Aggregations