Search in sources :

Example 1 with FileDetails

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);
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) HashMap(java.util.HashMap) FileDetails(com.thoughtworks.go.addon.businesscontinuity.FileDetails) Gson(com.google.gson.Gson) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with FileDetails

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);
        }
    }
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) FileDetails(com.thoughtworks.go.addon.businesscontinuity.FileDetails) File(java.io.File)

Example 3 with FileDetails

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");
}
Also used : ConfigFileType(com.thoughtworks.go.addon.businesscontinuity.ConfigFileType) FileDetails(com.thoughtworks.go.addon.businesscontinuity.FileDetails) ServerStatusResponse(com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigFileType (com.thoughtworks.go.addon.businesscontinuity.ConfigFileType)3 FileDetails (com.thoughtworks.go.addon.businesscontinuity.FileDetails)3 ServerStatusResponse (com.thoughtworks.go.addon.businesscontinuity.primary.ServerStatusResponse)2 Gson (com.google.gson.Gson)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1