Search in sources :

Example 6 with ToolVersion

use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.

the class ToolVersionManager method createToolVersionSettings.

/**
 * Creates settings for specific tool version.
 * @param toolId tool ID
 * @param version tool version (tag)
 * @param settings list of tool version settings
 */
@Transactional(propagation = Propagation.REQUIRED)
public ToolVersion createToolVersionSettings(final Long toolId, final String version, final List<ConfigurationEntry> settings) {
    Tool tool = toolManager.load(toolId);
    Assert.notNull(tool, messageHelper.getMessage(MessageConstants.ERROR_TOOL_NOT_FOUND));
    Optional<ToolVersion> toolVersion = toolVersionDao.loadToolVersion(toolId, version);
    ToolVersion toolVersionWithSettings;
    if (toolVersion.isPresent()) {
        toolVersionWithSettings = toolVersion.get();
        toolVersionWithSettings.setSettings(settings);
        toolVersionDao.updateToolVersionWithSettings(toolVersionWithSettings);
    } else {
        toolVersionWithSettings = ToolVersion.builder().toolId(toolId).version(version).settings(settings).build();
        toolVersionDao.createToolVersionWithSettings(toolVersionWithSettings);
    }
    return toolVersionWithSettings;
}
Also used : ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ToolVersion

use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.

the class ToolVersionManager method updateOrCreateToolVersion.

/**
 * Updates existing tool version according to it's state on docker registry. If required tool version
 * does not exist a new one will be created.
 * @param toolId tool ID
 * @param version tool version (tag)
 * @param imageName the name of the image
 * @param registry docker registry
 * @param dockerClient docker client
 */
@Transactional(propagation = Propagation.REQUIRED)
public void updateOrCreateToolVersion(final Long toolId, final String version, final String imageName, final DockerRegistry registry, final DockerClient dockerClient) {
    Optional<ToolVersion> toolVersion = toolVersionDao.loadToolVersion(toolId, version);
    ToolVersion versionAttributes = dockerClient.getVersionAttributes(registry, imageName, version);
    versionAttributes.setToolId(toolId);
    if (toolVersion.isPresent()) {
        versionAttributes.setId(toolVersion.get().getId());
        toolVersionDao.updateToolVersion(versionAttributes);
    } else {
        toolVersionDao.createToolVersion(versionAttributes);
    }
}
Also used : ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ToolVersion

use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.

the class ToolManagerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    TestUtils.configureDockerClientMock(dockerClient, dockerClientFactory);
    firstRegistry = new DockerRegistry();
    firstRegistry.setPath(TEST_REPO);
    firstRegistry.setOwner(TEST_USER);
    registryDao.createDockerRegistry(firstRegistry);
    secondRegistry = new DockerRegistry();
    secondRegistry.setPath(TEST_REPO_2);
    secondRegistry.setOwner(TEST_USER);
    registryDao.createDockerRegistry(secondRegistry);
    LABELS.add(LABEL_1);
    LABELS.add(LABEL_2);
    ENDPOINTS.add("{\"nginx\" : {\"port\" : 8080}}");
    ENDPOINTS.add("9080");
    firstToolGroup = new ToolGroup();
    firstToolGroup.setName(TEST_GROUP_NAME);
    firstToolGroup.setRegistryId(firstRegistry.getId());
    toolGroupManager.create(firstToolGroup);
    secondToolGroup = new ToolGroup();
    secondToolGroup.setName(TEST_GROUP_NAME);
    secondToolGroup.setRegistryId(secondRegistry.getId());
    toolGroupManager.create(secondToolGroup);
    ToolVersion toolVersion = new ToolVersion();
    toolVersion.setDigest("test_digest");
    toolVersion.setSize(DOCKER_SIZE);
    toolVersion.setVersion("test_version");
    Mockito.when(dockerClient.getVersionAttributes(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(toolVersion);
    final InstanceType instanceType = new InstanceType();
    instanceType.setName(TEST_ALLOWED_INSTANCE_TYPE);
    instanceOfferManager.updateOfferedInstanceTypes(Collections.singletonList(instanceType));
}
Also used : ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Before(org.junit.Before)

Example 9 with ToolVersion

use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.

the class TestUtils method configureDockerClientMock.

/**
 * Helper method for mocking DockerClient functionality
 * @param dockerClientMock a {@link DockerClient} mock object
 * @param dockerClientFactoryMock a {@link DockerClientFactory} mock object
 * @return a mocking ManifestV2
 */
public static ManifestV2 configureDockerClientMock(DockerClient dockerClientMock, DockerClientFactory dockerClientFactoryMock) {
    ManifestV2 mockManifest = new ManifestV2();
    mockManifest.setConfig(new ManifestV2.Config(TEST_DIGEST, null));
    mockManifest.setDigest(TEST_DIGEST);
    mockManifest.setLayers(Collections.singletonList(new ManifestV2.Config(TEST_DIGEST, null)));
    Mockito.doReturn(dockerClientMock).when(dockerClientFactoryMock).getDockerClient(any());
    Mockito.doReturn(dockerClientMock).when(dockerClientFactoryMock).getDockerClient(any(), any());
    Mockito.doReturn(Collections.singletonList(LATEST_TAG)).when(dockerClientMock).getImageTags(any(), anyString());
    Mockito.doReturn(Optional.of(mockManifest)).when(dockerClientMock).deleteImage(any(), any(), any());
    ToolVersion toolVersion = new ToolVersion();
    toolVersion.setDigest("test_digest");
    toolVersion.setSize(DOCKER_SIZE);
    toolVersion.setVersion("test_version");
    Mockito.doReturn(toolVersion).when(dockerClientMock).getVersionAttributes(any(), any(), any());
    return mockManifest;
}
Also used : ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion)

Example 10 with ToolVersion

use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.

the class DockerClient method getVersionAttributes.

public ToolVersion getVersionAttributes(final DockerRegistry registry, final String imageName, final String tag) {
    ToolVersion attributes = new ToolVersion();
    attributes.setVersion(tag);
    ManifestV2 manifestV2 = getManifest(registry, imageName, tag).orElseThrow(() -> new IllegalArgumentException(String.format("Cannot get manifest for image %s/%s", imageName, tag)));
    attributes.setDigest(manifestV2.getDigest());
    attributes.setSize(manifestV2.getLayers().stream().mapToLong(ManifestV2.Config::getSize).sum());
    attributes.setModificationDate(getLatestDate(registry, imageName, tag));
    return attributes;
}
Also used : ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion)

Aggregations

ToolVersion (com.epam.pipeline.entity.docker.ToolVersion)13 Test (org.junit.Test)5 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)4 Tool (com.epam.pipeline.entity.pipeline.Tool)4 Before (org.junit.Before)4 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)3 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)3 DockerClient (com.epam.pipeline.manager.docker.DockerClient)3 Transactional (org.springframework.transaction.annotation.Transactional)2 MessageHelper (com.epam.pipeline.common.MessageHelper)1 PreferenceDao (com.epam.pipeline.dao.preference.PreferenceDao)1 AclTestDao (com.epam.pipeline.dao.util.AclTestDao)1 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)1 ConfigurationEntry (com.epam.pipeline.entity.configuration.ConfigurationEntry)1 PipeConfValueVO (com.epam.pipeline.entity.configuration.PipeConfValueVO)1 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)1 Preference (com.epam.pipeline.entity.preference.Preference)1 com.epam.pipeline.entity.scan (com.epam.pipeline.entity.scan)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1 DateUtils (com.epam.pipeline.entity.utils.DateUtils)1