use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class StandbyFileSyncServiceTest method shouldSyncPlugins.
@Test
void shouldSyncPlugins() throws Exception {
Map<ConfigFileType, FileDetails> latestStatusMap = new HashMap<>();
when(primaryServerCommunicationService.getLatestFileStatus()).thenReturn(new ServerStatusResponse(60, 0L, latestStatusMap));
Map<String, String> pluginMap1 = new HashMap<String, String>() {
{
put("name", "external-1.jar");
put("md5", "md5-1");
}
};
Map<String, String> pluginMap2 = new HashMap<String, String>() {
{
put("name", "external-2.jar");
put("md5", "md5-2");
}
};
Map<String, Object> pluginsList = new HashMap<>();
pluginsList.put("external", Arrays.asList(pluginMap1, pluginMap2));
when(primaryServerCommunicationService.getLatestPluginsStatus()).thenReturn(pluginsList);
StandbyFileSyncService syncService = new StandbyFileSyncService(systemEnvironment, primaryServerCommunicationService, new MockScheduledExecutorService(), addOnConfiguration);
assertThat(FileUtils.readFileToString(new File(systemEnvironment.getExternalPluginAbsolutePath(), "external-1.jar"), UTF_8), is("external-1.jar contents"));
assertThat(FileUtils.readFileToString(new File(systemEnvironment.getExternalPluginAbsolutePath(), "external-2.jar"), UTF_8), is("external-2.jar contents"));
verify(primaryServerCommunicationService).getLatestFileStatus();
File external3 = new File(systemEnvironment.getExternalPluginAbsolutePath(), "external-3.jar");
FileUtils.writeStringToFile(external3, "external-3.jar", UTF_8);
syncService.getCurrentExternalPluginsStatus().put("external-3.jar", "md5-3");
syncService.syncPlugins();
assertThat("external-3.jar should have got deleted.", external3.exists(), is(false));
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class StandbyFileSyncServiceTest method shouldSyncConfigFiles.
@Test
void shouldSyncConfigFiles() throws Exception {
Map<ConfigFileType, FileDetails> latestStatusMap = new HashMap<ConfigFileType, FileDetails>() {
{
put(ConfigFileType.CRUISE_CONFIG_XML, new FileDetails("new-md5"));
put(ConfigFileType.AES_CIPHER, new FileDetails("new-md5"));
put(ConfigFileType.JETTY_XML, new FileDetails("new-md5"));
}
};
when(primaryServerCommunicationService.getLatestFileStatus()).thenReturn(new ServerStatusResponse(60, 0L, latestStatusMap));
Map<String, Object> pluginsList = new HashMap<>();
pluginsList.put("external", new ArrayList<Map>());
when(primaryServerCommunicationService.getLatestPluginsStatus()).thenReturn(pluginsList);
new StandbyFileSyncService(systemEnvironment, primaryServerCommunicationService, new MockScheduledExecutorService(), addOnConfiguration);
assertThat(FileUtils.readFileToString(new File(systemEnvironment.getCruiseConfigFile()), UTF_8), is("CRUISE_CONFIG_XML contents"));
assertThat(FileUtils.readFileToString(systemEnvironment.getAESCipherFile(), UTF_8), is("AES_CIPHER contents"));
assertThat(FileUtils.readFileToString(systemEnvironment.getJettyConfigFile(), UTF_8), is("JETTY_XML contents"));
verify(primaryServerCommunicationService).getLatestFileStatus();
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse in project gocd by gocd.
the class StandbyFileSyncServiceTest method shouldClearErrorsAfterSuccess.
@Test
void shouldClearErrorsAfterSuccess() {
when(primaryServerCommunicationService.getLatestFileStatus()).thenThrow(new RuntimeException("could not connect")).thenReturn(new ServerStatusResponse(0, 0, new HashMap<>()));
Map<String, Object> pluginsList = new HashMap<>();
pluginsList.put("external", new ArrayList<Map>());
when(primaryServerCommunicationService.getLatestPluginsStatus()).thenReturn(pluginsList);
MockScheduledExecutorService executorService = new MockScheduledExecutorService(2);
StandbyFileSyncService standbyFileSyncService = new StandbyFileSyncService(systemEnvironment, primaryServerCommunicationService, executorService, addOnConfiguration);
List<String> errors = standbyFileSyncService.syncErrors();
assertThat(errors.size(), is(0));
}
use of com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse 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.primary.ServerStatusResponse in project gocd by gocd.
the class DashBoardController method primaryServerDetails.
Map<String, Object> primaryServerDetails() {
Map<String, Object> details = new HashMap<>();
String primaryServerUrl = primaryServerCommunicationService.primaryServerUrl();
details.put("url", primaryServerUrl);
try {
details.put("latestDatabaseWalLocation", primaryServerCommunicationService.latestDatabaseWalLocation());
ServerStatusResponse latestFileStatus = primaryServerCommunicationService.getLatestFileStatus();
details.put("configFilesUpdateInterval", latestFileStatus.getConfigFilesUpdateInterval());
details.put("lastConfigUpdateTime", new Date(latestFileStatus.getLastConfigFilesUpdateTime()));
Map<ConfigFileType, FileDetails> fileDetailsMap = latestFileStatus.getFileDetailsMap();
for (ConfigFileType fileType : fileDetailsMap.keySet()) {
details.put(fileType.name(), fileDetailsMap.get(fileType));
}
details.put("pluginStatus", primaryPluginStatus());
} catch (Exception e) {
details.put("error", format("Could not fetch latest file status from master, Reason, %s", e.getMessage()));
}
return details;
}
Aggregations