use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryManagerTest method generateToolGroup.
private ToolGroup generateToolGroup(DockerRegistry registry) {
ToolGroup group = new ToolGroup();
group.setName(TEST_GROUP_NAME);
group.setRegistryId(registry.getId());
group.setOwner(TEST_USER);
return group;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryEventServiceTest method shouldAddDockerRegistryEvent.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldAddDockerRegistryEvent() {
doNothing().when(entityManager).setManagers(anyListOf(SecuredEntityManager.class));
ToolGroup toolGroup1 = new ToolGroup();
toolGroup1.setId(1L);
ToolGroup toolGroup2 = new ToolGroup();
toolGroup2.setId(2L);
when(issueManager.loadIssuesForEntity(any())).thenReturn(Arrays.asList(Issue.builder().id(1L).build(), Issue.builder().id(2L).build()));
when(toolGroupManager.loadByRegistryId(anyLong())).thenReturn(Arrays.asList(toolGroup1, toolGroup2));
when(toolManager.loadToolsByGroup(anyLong())).thenReturn(null);
doNothing().when(eventDao).insertUpdateEvent(anyString(), anyLong());
dockerRegistryEventService.updateEventsWithChildrenAndIssues(1L);
verify(eventDao).insertUpdateEvent("docker_registry", 1L);
verify(eventDao).insertUpdateEvent("tool_group", 1L);
verify(eventDao).insertUpdateEvent("tool_group", 2L);
// 1 registry + 2 toolGroup
verify(eventDao, times(3)).insertUpdateEvent("issue", 1L);
verify(eventDao, times(3)).insertUpdateEvent("issue", 2L);
verifyNoMoreInteractions(eventDao);
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerContainerOperationManager method commitContainer.
public PipelineRun commitContainer(PipelineRun run, DockerRegistry registry, String newImageName, boolean clearContainer, boolean stopPipeline) {
final String containerId = kubernetesManager.getContainerIdFromKubernetesPod(run.getPodId(), run.getDockerImage());
final String apiToken = authManager.issueTokenForCurrentUser(null).getToken();
String dockerLogin;
String dockerPassword;
// Let's use pipe auth if it's enabled for registry
if (registry.isPipelineAuth()) {
dockerLogin = authManager.getAuthorizedUser();
dockerPassword = apiToken;
} else {
dockerLogin = registry.getUserName() == null ? EMPTY : registry.getUserName();
dockerPassword = registry.getPassword() == null ? EMPTY : registry.getPassword();
}
if (newImageName.startsWith(registry.getPath())) {
newImageName = newImageName.replace(registry.getPath() + DELIMITER, EMPTY);
}
Matcher matcher = GROUP_AND_IMAGE.matcher(newImageName);
Assert.isTrue(matcher.find(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_IS_NOT_PROVIDED, newImageName));
String toolGroupName = matcher.group(1);
ToolGroup toolGroup = toolGroupManager.loadByNameOrId(registry.getPath() + DELIMITER + toolGroupName);
try {
Assert.notNull(containerId, messageHelper.getMessage(MessageConstants.ERROR_CONTAINER_ID_FOR_RUN_NOT_FOUND, run.getId()));
String commitContainerCommand = String.format(COMMIT_COMMAND_TEMPLATE, commitRunStarterScriptUrl, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST), apiToken, commitScriptsDistributionsUrl, preferenceManager.getPreference(SystemPreferences.BASE_PIPE_DISTR_URL), run.getId(), containerId, clearContainer, stopPipeline, preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), registry.getPath(), registry.getId(), toolGroup.getId(), newImageName, dockerLogin, dockerPassword, registry.isPipelineAuth());
Process sshConnection = submitCommandViaSSH(run.getInstance().getNodeIP(), commitContainerCommand);
boolean isFinished = sshConnection.waitFor(preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), TimeUnit.SECONDS);
Assert.state(isFinished && sshConnection.exitValue() == 0, messageHelper.getMessage(MessageConstants.ERROR_RUN_PIPELINES_COMMIT_FAILED, run.getId()));
} catch (IllegalStateException | IllegalArgumentException | IOException e) {
LOGGER.error(e.getMessage());
updatePipelineRunCommitStatus(run, CommitStatus.FAILURE);
throw new CmdExecutionException(COMMIT_COMMAND_DESCRIPTION, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
updatePipelineRunCommitStatus(run, CommitStatus.FAILURE);
throw new CmdExecutionException(COMMIT_COMMAND_DESCRIPTION, e);
}
updatePipelineRunCommitStatus(run, CommitStatus.COMMITTING);
return run;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryManager method fetchToolGroup.
private ToolGroup fetchToolGroup(DockerRegistryEvent event, DockerRegistry registry, String group) {
ToolGroup toolGroup;
if (!toolGroupManager.doesToolGroupExist(registry.getPath(), group)) {
String actor = event.getActor().getName();
Assert.isTrue(permissionManager.isActionAllowedForUser(registry, actor, AclPermission.WRITE), messageHelper.getMessage(MessageConstants.ERROR_PERMISSION_IS_NOT_GRANTED, registry.getPath(), AclPermission.WRITE_PERMISSION));
toolGroup = new ToolGroup();
toolGroup.setName(group);
toolGroup.setRegistryId(registry.getId());
toolGroup.setOwner(event.getActor().getName());
toolGroupManager.create(toolGroup);
} else {
toolGroup = toolGroupManager.loadByNameOrId(registry.getPath() + Constants.PATH_DELIMITER + group);
}
return toolGroup;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class PipelineConfigurationManagerTest method setUp.
@Before
public void setUp() throws Exception {
registry = new DockerRegistry();
registry.setPath(TEST_REPO);
registry.setOwner(TEST_USER);
dockerRegistryDao.createDockerRegistry(registry);
library = new ToolGroup();
library.setName(TOOL_GROUP_NAME);
library.setRegistryId(registry.getId());
library.setOwner(TEST_USER);
toolGroupDao.createToolGroup(library);
tool = new Tool();
tool.setImage(TEST_IMAGE);
tool.setRam(TEST_RAM);
tool.setCpu(TEST_CPU);
tool.setOwner(TEST_USER);
tool.setRegistryId(registry.getId());
tool.setToolGroupId(library.getId());
toolDao.createTool(tool);
// Data storages of user 1
NFSDataStorage dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS", "test/path1");
dataStorage.setMountOptions("testMountOptions1");
dataStorage.setMountPoint("/some/other/path");
dataStorage.setOwner(TEST_OWNER1);
dataStorageDao.createDataStorage(dataStorage);
dataStorages.add(dataStorage);
S3bucketDataStorage bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket", "test/path2");
bucketDataStorage.setOwner(TEST_OWNER1);
dataStorageDao.createDataStorage(bucketDataStorage);
dataStorages.add(bucketDataStorage);
// Data storages of user 2
dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS2", "test/path3");
dataStorage.setMountOptions("testMountOptions2");
dataStorage.setOwner(TEST_OWNER2);
dataStorageDao.createDataStorage(dataStorage);
dataStorages.add(dataStorage);
bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket2", "test/path4");
bucketDataStorage.setOwner(TEST_OWNER2);
dataStorageDao.createDataStorage(bucketDataStorage);
dataStorages.add(bucketDataStorage);
dataStorages.forEach(ds -> aclTestDao.createAclForObject(ds));
aclTestDao.grantPermissions(dataStorage, TEST_OWNER1, Collections.singletonList((AclPermission) AclPermission.READ));
}
Aggregations