Search in sources :

Example 21 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class PipelineManager method delete.

@Transactional(propagation = Propagation.REQUIRED)
public Pipeline delete(Long id, boolean keepRepository) {
    Pipeline pipeline = load(id);
    if (!keepRepository) {
        try {
            gitManager.deletePipelineRepository(pipeline);
        } catch (GitClientException | UnsupportedEncodingException | URISyntaxException | HttpClientErrorException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    runLogDao.deleteLogsForPipeline(id);
    restartRunManager.deleteRestartedRunsForPipeline(id);
    runStatusManager.deleteRunStatusForPipeline(id);
    pipelineRunDao.deleteRunsByPipeline(id);
    dataStorageRuleDao.deleteRulesByPipeline(id);
    pipelineDao.deletePipeline(id);
    return pipeline;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) GitClientException(com.epam.pipeline.exception.git.GitClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class SystemPreferences method areGitPreferencesValid.

private boolean areGitPreferencesValid(Map<String, Preference> gitPreferences) {
    long adminId = Long.parseLong(gitPreferences.get(GIT_USER_ID.getKey()).getValue());
    GitlabClient client = gitManager.getGitlabClient(gitPreferences.get(GIT_HOST.getKey()).getValue(), gitPreferences.get(GIT_TOKEN.getKey()).getValue(), adminId, gitPreferences.get(GIT_USER_NAME.getKey()).getValue());
    client.buildCloneCredentials(false, false, 1L);
    try {
        GitlabVersion version = client.getVersion();
        Matcher matcher = GIT_VERSION_PATTERN.matcher(version.getVersion());
        if (matcher.find()) {
            Integer major = Integer.parseInt(matcher.group(1));
            Integer minor = Integer.parseInt(matcher.group(2));
            if ((major == 9 && minor >= 5) || (major == 8 && minor < 3)) {
                throw new IllegalArgumentException("Invalid git version: " + version.getVersion());
            }
        } else {
            throw new IllegalArgumentException("Invalid git version: " + version.getVersion());
        }
    } catch (GitClientException e) {
        throw new IllegalArgumentException("Could not request Gitlab version", e);
    }
    return true;
}
Also used : GitlabClient(com.epam.pipeline.manager.git.GitlabClient) GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) Matcher(java.util.regex.Matcher) GitClientException(com.epam.pipeline.exception.git.GitClientException)

Example 23 with GitClientException

use of com.epam.pipeline.exception.git.GitClientException in project cloud-pipeline by epam.

the class GitManagerTest method shouldFetchPipelineDocs.

@Test
public void shouldFetchPipelineDocs() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final GitRepositoryEntry bla = new GitRepositoryEntry();
    bla.setName(README_FILE);
    bla.setType(BLOB_TYPE);
    final List<GitRepositoryEntry> tree = singletonList(bla);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(TEST_REVISION)).withQueryParam(PATH, equalTo(DOCS + "/")).withQueryParam(RECURSIVE, equalTo(String.valueOf(false))).willReturn(okJson(with(tree))));
    final GitTagEntry tag = new GitTagEntry();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + TEST_REVISION))).willReturn(okJson(with(tag))));
    final List<GitRepositoryEntry> repoEntries = gitManager.getPipelineDocs(pipeline.getId(), TEST_REVISION);
    final boolean noEntries = repoEntries.isEmpty();
    final boolean docsOnly = repoEntries.stream().filter(e -> !e.getName().startsWith(".")).allMatch(e -> e.getName().endsWith(".md"));
    assertFalse(noEntries);
    assertTrue(docsOnly);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PipelineManager(com.epam.pipeline.manager.pipeline.PipelineManager) SneakyThrows(lombok.SneakyThrows) Date(java.util.Date) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) ZonedDateTime(java.time.ZonedDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) WireMock.notFound(com.github.tomakehurst.wiremock.client.WireMock.notFound) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) WireMock.givenThat(com.github.tomakehurst.wiremock.client.WireMock.givenThat) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) Path(java.nio.file.Path) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) GitProject(com.epam.pipeline.entity.git.GitProject) UploadFileMetadata(com.epam.pipeline.controller.vo.UploadFileMetadata) GIT_MASTER_REPOSITORY(com.epam.pipeline.manager.git.GitManager.GIT_MASTER_REPOSITORY) Matchers.any(org.mockito.Matchers.any) Base64(java.util.Base64) List(java.util.List) PipelineSourceItemsVO(com.epam.pipeline.controller.vo.PipelineSourceItemsVO) Whitebox(org.mockito.internal.util.reflection.Whitebox) GitRepositoryUrl(com.epam.pipeline.entity.git.GitRepositoryUrl) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) UTC(java.time.ZoneOffset.UTC) CmdExecutor(com.epam.pipeline.manager.CmdExecutor) Comparator.reverseOrder(java.util.Comparator.reverseOrder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitClientException(com.epam.pipeline.exception.git.GitClientException) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) Matchers.anyString(org.mockito.Matchers.anyString) Value(org.springframework.beans.factory.annotation.Value) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) GitFile(com.epam.pipeline.entity.git.GitFile) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Ignore(org.junit.Ignore) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) Paths(java.nio.file.Paths) Revision(com.epam.pipeline.entity.pipeline.Revision) DRAFT_PREFIX(com.epam.pipeline.manager.git.GitManager.DRAFT_PREFIX) Collections(java.util.Collections) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Aggregations

GitClientException (com.epam.pipeline.exception.git.GitClientException)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 URISyntaxException (java.net.URISyntaxException)11 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)10 URI (java.net.URI)10 RestTemplate (org.springframework.web.client.RestTemplate)10 List (java.util.List)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)7 HashMap (java.util.HashMap)6 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)5 IOException (java.io.IOException)5 Date (java.util.Date)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)3 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)3 GitProject (com.epam.pipeline.entity.git.GitProject)3 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)3 Revision (com.epam.pipeline.entity.pipeline.Revision)3 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)3 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)2