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