use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class PluginFiles method download.
private Optional<File> download(InstalledPlugin plugin) {
GetRequest request = new GetRequest("api/plugins/download").setParam("plugin", plugin.key).setTimeOutInMs(5 * 60_000);
try {
Class.forName("java.util.jar.Pack200");
request.setParam("acceptCompressions", PACK200);
} catch (ClassNotFoundException e) {
// ignore and don't use any compression
}
File downloadedFile = newTempFile();
LOGGER.debug("Download plugin '{}' to '{}'", plugin.key, downloadedFile);
try (WsResponse response = wsClient.call(request)) {
Optional<String> expectedMd5 = response.header(MD5_HEADER);
if (!expectedMd5.isPresent()) {
throw new IllegalStateException(format("Fail to download plugin [%s]. Request to %s did not return header %s", plugin.key, response.requestUrl(), MD5_HEADER));
}
downloadBinaryTo(plugin, downloadedFile, response);
// verify integrity
String effectiveTempMd5 = computeMd5(downloadedFile);
if (!expectedMd5.get().equals(effectiveTempMd5)) {
throw new IllegalStateException(format("Fail to download plugin [%s]. File %s was expected to have checksum %s but had %s", plugin.key, downloadedFile, expectedMd5.get(), effectiveTempMd5));
}
// un-compress if needed
String cacheMd5;
File tempJar;
Optional<String> compression = response.header(COMPRESSION_HEADER);
if (compression.isPresent() && PACK200.equals(compression.get())) {
tempJar = unpack200(plugin.key, downloadedFile);
cacheMd5 = response.header(UNCOMPRESSED_MD5_HEADER).orElseThrow(() -> new IllegalStateException(format("Fail to download plugin [%s]. Request to %s did not return header %s.", plugin.key, response.requestUrl(), UNCOMPRESSED_MD5_HEADER)));
} else {
tempJar = downloadedFile;
cacheMd5 = expectedMd5.get();
}
// put in cache
File jarInCache = jarInCache(plugin.key, cacheMd5);
mkdir(jarInCache.getParentFile());
moveFile(tempJar, jarInCache);
return Optional.of(jarInCache);
} catch (HttpException e) {
if (e.code() == HttpURLConnection.HTTP_NOT_FOUND) {
// uninstalled.
return Optional.empty();
}
// not 2xx nor 404
throw new IllegalStateException(format("Fail to download plugin [%s]. Request to %s returned code %d.", plugin.key, e.url(), e.code()));
}
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class RestartTest method restart_in_prod_mode_requires_sysadmin_permission_and_restarts.
@Test
public void restart_in_prod_mode_requires_sysadmin_permission_and_restarts() throws Exception {
// server classloader locks Jar files on Windows
if (!SystemUtils.IS_OS_WINDOWS) {
orchestrator = Orchestrator.builderEnv().setOrchestratorProperty("orchestrator.keepWorkspace", "true").build();
orchestrator.start();
verifyFailWith403(() -> newWsClient(orchestrator).system().restart());
createNonSystemAdministrator("john", "doe");
verifyFailWith403(() -> ItUtils.newUserWsClient(orchestrator, "john", "doe").system().restart());
createSystemAdministrator("big", "boss");
ItUtils.newUserWsClient(orchestrator, "big", "boss").system().restart();
WsResponse wsResponse = newAdminWsClient(orchestrator).wsConnector().call(new GetRequest("/api/system/status")).failIfNotSuccessful();
assertThat(wsResponse.content()).contains("RESTARTING");
// we just wait five seconds, for a lack of a better approach to waiting for the restart process to start in SQ
Thread.sleep(5000);
assertThat(FileUtils.readFileToString(orchestrator.getServer().getWebLogs())).contains("SonarQube restart requested by big");
}
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class ServerSystemTest method download_system_info.
@Test
public void download_system_info() throws Exception {
waitForComputeEngineToBeUp(orchestrator);
WsResponse response = newAdminWsClient(orchestrator).wsConnector().call(new GetRequest("api/system/info"));
assertThat(response.code()).isEqualTo(200);
assertThat(response.content()).contains(// SONAR-7436 monitor ES and CE
"\"Compute Engine Database Connection\":", "\"Compute Engine State\":", "\"Compute Engine Tasks\":", "\"Elasticsearch\":", "\"State\":\"GREEN\"", // SONAR-7271 get settings
"\"Settings\":", "\"sonar.jdbc.url\":", "\"sonar.path.data\":");
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class QualityGateTest method getAnalysisId.
private String getAnalysisId(String taskId) throws IOException {
WsResponse activity = wsClient.wsConnector().call(new GetRequest("api/ce/task").setParam("id", taskId).setMediaType(MediaTypes.PROTOBUF));
WsCe.TaskResponse activityWsResponse = WsCe.TaskResponse.parseFrom(activity.contentStream());
return activityWsResponse.getTask().getAnalysisId();
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class UserRule method getUsers.
public Users getUsers() {
WsResponse response = adminWsClient().wsConnector().call(new GetRequest("api/users/search"));
assertThat(response.code()).isEqualTo(200);
return Users.parse(response.content());
}
Aggregations