Search in sources :

Example 1 with DockerTagsResponseModel

use of com.synopsys.integration.alert.update.model.DockerTagsResponseModel in project hub-alert by blackducksoftware.

the class UpdateChecker method getLatestAvailableTag.

private Optional<VersionDateModel> getLatestAvailableTag(DockerTagRetriever dockerTagRetriever, boolean isProduction) {
    DockerTagsResponseModel tagsResponseModel = dockerTagRetriever.getTagsModel();
    List<DockerTagModel> tags = new LinkedList<>();
    while (!tagsResponseModel.isEmpty()) {
        tags.addAll(tagsResponseModel.getResults());
        tagsResponseModel = dockerTagRetriever.getNextPage(tagsResponseModel);
    }
    return tags.stream().filter(dockerTagModel -> {
        if (isProduction) {
            return isProductionVersion(dockerTagModel.getName());
        }
        return true;
    }).map(dockerTagModel -> new VersionDateModel(dockerTagModel.getName(), dockerTagModel.getLastUpdated())).min(versionDateModelComparator());
}
Also used : DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) DOCKER_DATE_FORMAT(com.synopsys.integration.alert.common.util.DateUtils.DOCKER_DATE_FORMAT) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) UpdateModel(com.synopsys.integration.alert.update.model.UpdateModel) IntLogger(com.synopsys.integration.log.IntLogger) AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) Gson(com.google.gson.Gson) ParseException(java.text.ParseException) LinkedList(java.util.LinkedList) AboutModel(com.synopsys.integration.alert.web.api.about.AboutModel) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) DockerTagModel(com.synopsys.integration.alert.update.model.DockerTagModel) List(java.util.List) Component(org.springframework.stereotype.Component) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) Comparator(java.util.Comparator) DateUtils.parseDate(com.synopsys.integration.alert.common.util.DateUtils.parseDate) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) DockerTagModel(com.synopsys.integration.alert.update.model.DockerTagModel) LinkedList(java.util.LinkedList)

Example 2 with DockerTagsResponseModel

use of com.synopsys.integration.alert.update.model.DockerTagsResponseModel in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTest.

@Test
public void getTagsModelTest() throws IntegrationException {
    IntHttpClient intHttpClient = Mockito.mock(IntHttpClient.class);
    Response mockResponse = createMockResponse();
    Mockito.when(intHttpClient.execute(Mockito.any(Request.class))).thenReturn(mockResponse);
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertEquals(TAGS_COUNT, tagsModel.getCount());
    assertEquals(TAGS_COUNT, tagsModel.getResults().size());
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) Test(org.junit.jupiter.api.Test)

Example 3 with DockerTagsResponseModel

use of com.synopsys.integration.alert.update.model.DockerTagsResponseModel in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method createMockResponse.

private Response createMockResponse() throws IntegrationException {
    Response mockResponse = Mockito.mock(Response.class);
    List<DockerTagModel> tagModels = List.of(createDockerTagModel("1.0.0"), createDockerTagModel("1.0.1"));
    DockerTagsResponseModel mockDockerTagsResponseModel = new DockerTagsResponseModel(TAGS_COUNT, null, null, tagModels);
    String jsonString = gson.toJson(mockDockerTagsResponseModel);
    Mockito.when(mockResponse.getContentString()).thenReturn(jsonString);
    Mockito.doNothing().when(mockResponse).throwExceptionForError();
    return mockResponse;
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) DockerTagModel(com.synopsys.integration.alert.update.model.DockerTagModel)

Example 4 with DockerTagsResponseModel

use of com.synopsys.integration.alert.update.model.DockerTagsResponseModel in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getTagsModelTestIT() throws IntegrationException {
    IntLogger intLogger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
    IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, 10, true, ProxyInfo.NO_PROXY_INFO);
    HttpUrl httpUrl = new HttpUrl("https://google.com");
    Request testRequest = new Request.Builder(httpUrl).build();
    try (Response googleResponse = intHttpClient.execute(testRequest)) {
        googleResponse.throwExceptionForError();
    } catch (IntegrationException | IOException e) {
        assumeTrue(null == e, "Could not connect. Skipping this test...");
    }
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertFalse(tagsModel.isEmpty(), "Expected tags from the docker repo to exist");
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) IntLogger(com.synopsys.integration.log.IntLogger) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Aggregations

DockerTagsResponseModel (com.synopsys.integration.alert.update.model.DockerTagsResponseModel)4 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)3 Response (com.synopsys.integration.rest.response.Response)3 DockerTagModel (com.synopsys.integration.alert.update.model.DockerTagModel)2 IntLogger (com.synopsys.integration.log.IntLogger)2 Request (com.synopsys.integration.rest.request.Request)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 DOCKER_DATE_FORMAT (com.synopsys.integration.alert.common.util.DateUtils.DOCKER_DATE_FORMAT)1 DateUtils.parseDate (com.synopsys.integration.alert.common.util.DateUtils.parseDate)1 TestTags (com.synopsys.integration.alert.test.common.TestTags)1 UpdateModel (com.synopsys.integration.alert.update.model.UpdateModel)1 AboutModel (com.synopsys.integration.alert.web.api.about.AboutModel)1 AboutReader (com.synopsys.integration.alert.web.api.about.AboutReader)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 PrintStreamIntLogger (com.synopsys.integration.log.PrintStreamIntLogger)1 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1