use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.
the class ToolManager method getCurrentImageSize.
public long getCurrentImageSize(final String dockerImage) {
LOGGER.info("Getting size of image {}", dockerImage);
Tool tool = loadByNameOrId(dockerImage);
DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
String imageWithoutTag = getImageWithoutTag(tool.getImage());
String tag = getTagFromImageName(dockerImage);
DockerClient dockerClient = dockerRegistryManager.getDockerClient(dockerRegistry, imageWithoutTag);
try {
ToolVersion toolVersion = dockerClient.getVersionAttributes(dockerRegistry, imageWithoutTag, tag);
if (Objects.isNull(toolVersion) || Objects.isNull(toolVersion.getSize())) {
LOGGER.warn(messageHelper.getMessage(MessageConstants.ERROR_TOOL_VERSION_INVALID_SIZE, dockerImage));
return 0;
}
return toolVersion.getSize();
} catch (IllegalArgumentException e) {
LOGGER.error("An error occurred while getting image size: {} ", e.getMessage());
return 0;
}
}
use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.
the class ToolVersionDaoTest method shouldCRUDForSingleVersion.
@Test
public void shouldCRUDForSingleVersion() {
Long toolId = tool.getId();
toolVersionDao.createToolVersion(toolVersion1);
ToolVersion actual = toolVersionDao.loadToolVersion(toolId, TEST_VERSION).orElse(null);
validateToolVersion(actual, TEST_DIGEST, TEST_SIZE, TEST_VERSION, TEST_LAST_MODIFIED_DATE, toolId);
ToolVersion toolVersionWithSameVersion = ToolVersion.builder().digest(TEST_DIGEST_2).size(TEST_SIZE).version(TEST_VERSION).modificationDate(TEST_LAST_MODIFIED_DATE).toolId(tool.getId()).id(toolVersion1.getId()).build();
toolVersionDao.updateToolVersion(toolVersionWithSameVersion);
actual = toolVersionDao.loadToolVersion(toolId, TEST_VERSION).orElse(null);
validateToolVersion(actual, TEST_DIGEST_2, TEST_SIZE, TEST_VERSION, TEST_LAST_MODIFIED_DATE, toolId);
toolVersionDao.deleteToolVersion(toolId, TEST_VERSION);
actual = toolVersionDao.loadToolVersion(toolId, TEST_VERSION).orElse(null);
assertThat(actual).isNull();
}
use of com.epam.pipeline.entity.docker.ToolVersion in project cloud-pipeline by epam.
the class DockerRegistryNotificationTest method setUp.
@Before
public void setUp() {
AclTestDao.AclSid adminSid = new AclTestDao.AclSid(true, ADMIN);
aclTestDao.createAclSid(adminSid);
userManager.createUser(ADMIN, Collections.singletonList(2L), Collections.emptyList(), null, null);
AclTestDao.AclSid testUserSid = new AclTestDao.AclSid(true, TEST_USER);
aclTestDao.createAclSid(testUserSid);
userManager.createUser(TEST_USER, Collections.singletonList(2L), Collections.emptyList(), null, null);
DockerRegistry registry = new DockerRegistry();
registry.setPath(TEST_REPO);
registry.setOwner(TEST_USER);
registryDao.createDockerRegistry(registry);
DockerRegistry registry2 = new DockerRegistry();
registry2.setPath(TEST_REPO_WITHOUT_WRITE_ACCESS);
registry2.setOwner(ADMIN);
registryDao.createDockerRegistry(registry2);
DockerRegistry registry3 = new DockerRegistry();
registry3.setPath(TEST_REPO_WITH_EXTERNAL_PATH);
registry3.setExternalUrl(EXTERNAL_REPO_PATH);
registry3.setOwner(ADMIN);
registryDao.createDockerRegistry(registry3);
ToolGroup group = new ToolGroup();
group.setName("library");
group.setRegistryId(registry.getId());
group.setOwner(TEST_USER);
toolGroupDao.createToolGroup(group);
// And for USER group, which all users are belong to
AclTestDao.AclSid userGroupSid = new AclTestDao.AclSid(false, "ROLE_USER");
aclTestDao.createAclSid(userGroupSid);
// Mock ACL stuff
AclTestDao.AclClass groupAclClass = new AclTestDao.AclClass(ToolGroup.class.getCanonicalName());
aclTestDao.createAclClassIfNotPresent(groupAclClass);
AclTestDao.AclClass toolAclClass = new AclTestDao.AclClass(Tool.class.getCanonicalName());
aclTestDao.createAclClassIfNotPresent(toolAclClass);
AclTestDao.AclClass registryAclClass = new AclTestDao.AclClass(DockerRegistry.class.getCanonicalName());
aclTestDao.createAclClassIfNotPresent(registryAclClass);
AclTestDao.AclObjectIdentity registryIdentity = new AclTestDao.AclObjectIdentity(testUserSid, registry.getId(), registryAclClass.getId(), null, true);
aclTestDao.createObjectIdentity(registryIdentity);
AclTestDao.AclObjectIdentity registryIdentity2 = new AclTestDao.AclObjectIdentity(adminSid, registry2.getId(), registryAclClass.getId(), null, true);
aclTestDao.createObjectIdentity(registryIdentity2);
AclTestDao.AclObjectIdentity registryIdentity3 = new AclTestDao.AclObjectIdentity(adminSid, registry3.getId(), registryAclClass.getId(), null, true);
aclTestDao.createObjectIdentity(registryIdentity3);
AclTestDao.AclObjectIdentity groupIdentity = new AclTestDao.AclObjectIdentity(testUserSid, group.getId(), groupAclClass.getId(), null, true);
aclTestDao.createObjectIdentity(groupIdentity);
// All Test users can write to registry
AclTestDao.AclEntry registryAclEntry = new AclTestDao.AclEntry(registryIdentity, 1, adminSid, AclPermission.WRITE.getMask(), true);
aclTestDao.createAclEntry(registryAclEntry);
registryAclEntry.setSid(testUserSid);
registryAclEntry.setOrder(2);
aclTestDao.createAclEntry(registryAclEntry);
// All Test users can write to group
AclTestDao.AclEntry groupAclEntry = new AclTestDao.AclEntry(groupIdentity, 1, adminSid, AclPermission.WRITE.getMask(), true);
aclTestDao.createAclEntry(groupAclEntry);
groupAclEntry.setSid(testUserSid);
groupAclEntry.setOrder(2);
aclTestDao.createAclEntry(groupAclEntry);
// Only Admin can write to second registry
AclTestDao.AclEntry registryAclEntry2 = new AclTestDao.AclEntry(registryIdentity2, 1, adminSid, AclPermission.WRITE.getMask(), true);
aclTestDao.createAclEntry(registryAclEntry2);
AclTestDao.AclEntry registryAclEntry3 = new AclTestDao.AclEntry(registryIdentity3, 1, adminSid, AclPermission.WRITE.getMask(), true);
aclTestDao.createAclEntry(registryAclEntry3);
registryAclEntry3.setSid(testUserSid);
registryAclEntry3.setOrder(2);
aclTestDao.createAclEntry(registryAclEntry3);
MockitoAnnotations.initMocks(this);
TestUtils.configureDockerClientMock(dockerClient, dockerClientFactoryMock);
dockerClientFactoryMock.setObjectMapper(new ObjectMapper());
when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class))).thenReturn(dockerClient);
when(dockerClient.getImageTags(any(String.class), any(String.class))).thenReturn(Collections.singletonList("latest"));
ToolVersion toolVersion = new ToolVersion();
toolVersion.setDigest("test_digest");
toolVersion.setSize(DOCKER_SIZE);
toolVersion.setVersion("test_version");
Mockito.doReturn(toolVersion).when(dockerClient).getVersionAttributes(Mockito.any(), Mockito.any(), Mockito.any());
doNothing().when(toolVersionManager).updateOrCreateToolVersion(anyLong(), anyString(), anyString(), any(DockerRegistry.class), any(DockerClient.class));
}
Aggregations