Search in sources :

Example 1 with ConfigFileType

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

Example 2 with ConfigFileType

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);
}
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 3 with ConfigFileType

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

Example 4 with ConfigFileType

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");
}
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)

Example 5 with ConfigFileType

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

Aggregations

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