Skip to content

Commit

Permalink
try to download compressed ubuntu usn database
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Nov 16, 2023
1 parent cf3efeb commit 34a26b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -116,22 +117,40 @@ private static Optional<String> archToPackageArchLabel(String arch) {

private static Map<String, UbuntuErrataInfo> downloadUbuntuErrataInfo(String jsonDBUrl) throws IOException {
HttpClientAdapter httpClient = new HttpClientAdapter();
HttpGet httpGet = new HttpGet(jsonDBUrl);
String bzipJsonDBUrl = jsonDBUrl + ".bz2";
HttpGet httpGet = new HttpGet(bzipJsonDBUrl);
LOG.info("download ubuntu errata start");
HttpResponse httpResponse = httpClient.executeRequest(httpGet);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
try (
InputStream responseStream = httpResponse.getEntity().getContent();
Reader responseReader = new InputStreamReader(responseStream);
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(responseStream);
Reader responseReader = new InputStreamReader(bzIn);
) {
Map<String, UbuntuErrataInfo> errataInfo = GSON.fromJson(responseReader, ERRATA_INFO_TYPE);
LOG.info("download ubuntu errata end");
return errataInfo;
}
}
else {
throw new IOException("error downloading " + jsonDBUrl + " status code " + statusCode);
LOG.info("Failed to get bzip2 DB - try plain DB");
httpGet = new HttpGet(jsonDBUrl);
httpResponse = httpClient.executeRequest(httpGet);
statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
try (
InputStream responseStream = httpResponse.getEntity().getContent();
Reader responseReader = new InputStreamReader(responseStream);
) {
Map<String, UbuntuErrataInfo> errataInfo = GSON.fromJson(responseReader, ERRATA_INFO_TYPE);
LOG.info("download ubuntu errata end");
return errataInfo;
}
}
else {
throw new IOException("error downloading " + jsonDBUrl + " status code " + statusCode);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.mc.ubuntu-errata-compressed-db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- try to download compressed ubuntu usn database

0 comments on commit 34a26b6

Please sign in to comment.