use of com.thoughtworks.go.addon.businesscontinuity.ConfigFileType in project gocd by gocd.
the class GoFilesStatusProvider method updateStatus.
private void updateStatus() throws IOException {
if (addOnConfiguration.isServerInStandby())
return;
for (ConfigFileType configFileType : fileStatus.keySet()) {
File file = configFileType.load(systemEnvironment);
if (!file.exists())
continue;
if (configFileType.equals(ConfigFileType.CRUISE_CONFIG_XML) && goConfigService.getCurrentConfig().getMd5() != null) {
setFileStatus(ConfigFileType.CRUISE_CONFIG_XML, goConfigService.getCurrentConfig().getMd5());
} else {
try (FileInputStream fileInputStream = new FileInputStream(file)) {
String md5 = CachedDigestUtils.md5Hex(fileInputStream);
setFileStatus(configFileType, md5);
}
}
}
lastUpdateTime = System.currentTimeMillis();
}
use of com.thoughtworks.go.addon.businesscontinuity.ConfigFileType 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.ConfigFileType 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.ConfigFileType 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");
}
use of com.thoughtworks.go.addon.businesscontinuity.ConfigFileType in project gocd by gocd.
the class PrimaryStatusProviderControllerTest method shouldRespondWithLatestStatus.
@Test
void shouldRespondWithLatestStatus() throws IOException {
Map<ConfigFileType, String> latestStatus = new HashMap<>();
latestStatus.put(ConfigFileType.CRUISE_CONFIG_XML, "a");
latestStatus.put(ConfigFileType.AES_CIPHER, "AES-CIPHER");
latestStatus.put(ConfigFileType.JETTY_XML, "c");
when(goFilesStatusProvider.getLatestStatusMap()).thenReturn(latestStatus);
primaryStatusProviderController.latestStatus(httpServletResponse);
ServerStatusResponse serverStatusResponse = new Gson().fromJson(httpServletResponse.getContentAsString(), ServerStatusResponse.class);
assertThat(serverStatusResponse.getFileDetailsMap().size(), is(3));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.CRUISE_CONFIG_XML).getMd5(), is("a"));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.AES_CIPHER).getMd5(), is("AES-CIPHER"));
assertThat(serverStatusResponse.getFileDetailsMap().get(ConfigFileType.JETTY_XML).getMd5(), is("c"));
}
Aggregations