use of com.thoughtworks.go.addon.businesscontinuity.FileDetails in project gocd by gocd.
the class PrimaryStatusProviderController method latestStatus.
@RequestMapping(value = "/config_files_status", method = RequestMethod.GET)
public void latestStatus(HttpServletResponse response) throws IOException {
Map<ConfigFileType, String> latestFileStatusMap = goFilesStatusProvider.getLatestStatusMap();
Map<ConfigFileType, FileDetails> fileDetailsMap = new HashMap<>();
for (ConfigFileType configFileType : latestFileStatusMap.keySet()) {
if (!isEmpty(latestFileStatusMap.get(configFileType))) {
fileDetailsMap.put(configFileType, new FileDetails(latestFileStatusMap.get(configFileType)));
}
}
ServerStatusResponse serverStatusResponse = new ServerStatusResponse(goFilesStatusProvider.updateInterval(), goFilesStatusProvider.getLastUpdateTime(), fileDetailsMap);
String responseBody = new Gson().toJson(serverStatusResponse);
response.setContentType("application/json");
response.getOutputStream().print(responseBody);
}
use of com.thoughtworks.go.addon.businesscontinuity.FileDetails in project gocd by gocd.
the class StandbyFileSyncService method syncConfigFiles.
private void syncConfigFiles() throws IOException {
Map<ConfigFileType, FileDetails> primaryConfigFileDetails = StandbyFileSyncService.this.primaryServerCommunicationService.getLatestFileStatus().getFileDetailsMap();
for (ConfigFileType fileType : primaryConfigFileDetails.keySet()) {
File fileOnStandby = fileType.load(systemEnvironment);
if (!fileOnStandby.exists()) {
fileOnStandby.createNewFile();
currentFileStatus.put(fileType, "");
}
String md5AtStandby = currentMd5(fileType);
String md5AtPrimary = primaryConfigFileDetails.get(fileType).getMd5();
if (!md5AtStandby.equals(md5AtPrimary)) {
primaryServerCommunicationService.downloadConfigFile(fileType, fileOnStandby);
currentFileStatus.put(fileType, md5AtPrimary);
}
}
}
use of com.thoughtworks.go.addon.businesscontinuity.FileDetails in project gocd by gocd.
the class PrimaryServerCommunicationServiceTest method shouldRespondWithLatestStatus.
@Test
void shouldRespondWithLatestStatus() {
String responseBody = "{\"configFilesUpdateInterval\":10,\"fileDetailsMap\":{\"CRUISE_CONFIG_XML\":{\"md5\":\"a\"}}}";
httpClientMock.onGet("https://localhost:1234/go/add-on/business-continuity/api/config_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, responseBody);
ServerStatusResponse serverStatusResponse = primaryServerCommunicationService.getLatestFileStatus();
assertThat(serverStatusResponse.getConfigFilesUpdateInterval()).isEqualTo(10L);
Map<ConfigFileType, FileDetails> fileDetailsMap = serverStatusResponse.getFileDetailsMap();
assertThat(fileDetailsMap.size()).isEqualTo(1);
assertThat(fileDetailsMap.get(ConfigFileType.CRUISE_CONFIG_XML).getMd5()).isEqualTo("a");
}
Aggregations