Skip to content
Snippets Groups Projects
Unverified Commit aa052276 authored by Martin Weise's avatar Martin Weise
Browse files

Fixed conflict, closes #137

parent e15de21f
No related branches found
No related tags found
2 merge requests!81New stable release,!43Merge dev to master
#!/bin/bash
docker container stop $(docker container ls -aq) || true
docker container rm $(docker container ls -aq) || true
docker container stop $(docker container ls -aq -f name=^/fda-.*) || true
docker container rm $(docker container ls -aq -f name=^/fda-.*) || true
docker volume rm $(docker volume ls -q) || true
docker network rm fda-userdb || true
docker network rm fda-public || true
\ No newline at end of file
......@@ -64,7 +64,7 @@ public class ContainerEndpoint {
@ApiResponse(code = 404, message = "The container was not found after creation."),
})
public ResponseEntity<ContainerBriefDto> create(@Valid @RequestBody ContainerCreateRequestDto data)
throws ImageNotFoundException, DockerClientException {
throws ImageNotFoundException, DockerClientException, ContainerAlreadyExistsException {
final Container container = containerService.create(data);
final ContainerBriefDto response = containerMapper.containerToDatabaseContainerBriefDto(container);
return ResponseEntity.status(HttpStatus.CREATED)
......
......@@ -54,7 +54,7 @@ public class ContainerEndpointUnitTest extends BaseUnitTest {
}
@Test
public void create_succeeds() throws ImageNotFoundException, DockerClientException {
public void create_succeeds() throws ImageNotFoundException, DockerClientException, ContainerAlreadyExistsException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.name(CONTAINER_1_NAME)
.repository(IMAGE_1.getRepository())
......@@ -72,7 +72,7 @@ public class ContainerEndpointUnitTest extends BaseUnitTest {
@Disabled
@Test
public void create_noImage_fails() throws DockerClientException, ImageNotFoundException {
public void create_noImage_fails() throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.name(CONTAINER_1_NAME)
.repository("image")
......@@ -89,7 +89,7 @@ public class ContainerEndpointUnitTest extends BaseUnitTest {
@Disabled
@Test
public void create_docker_fails() throws DockerClientException, ImageNotFoundException {
public void create_docker_fails() throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.name(CONTAINER_1_NAME)
.repository(IMAGE_1.getRepository())
......
......@@ -146,7 +146,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
}
@Test
public void create_succeeds() throws DockerClientException, ImageNotFoundException {
public void create_succeeds() throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
......@@ -159,7 +159,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
}
@Test
public void create_conflictingNames_fails() throws DockerClientException, ImageNotFoundException {
public void create_conflictingNames_fails() throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
......
package at.tuwien.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.CONFLICT, reason = "Container name exists")
public class ContainerAlreadyExistsException extends Exception {
public ContainerAlreadyExistsException(String message) {
super(message);
}
public ContainerAlreadyExistsException(String message, Throwable thr) {
super(message, thr);
}
public ContainerAlreadyExistsException(Throwable thr) {
super(thr);
}
}
......@@ -9,7 +9,7 @@ import java.util.List;
public interface ContainerService {
@Transactional
Container create(ContainerCreateRequestDto createDto) throws ImageNotFoundException, DockerClientException;
Container create(ContainerCreateRequestDto createDto) throws ImageNotFoundException, DockerClientException, ContainerAlreadyExistsException;
@Transactional
Container stop(Long containerId) throws ContainerNotFoundException, DockerClientException;
......
......@@ -53,7 +53,7 @@ public class ContainerServiceImpl implements ContainerService {
@Override
@Transactional
public Container create(ContainerCreateRequestDto createDto) throws ImageNotFoundException, DockerClientException {
public Container create(ContainerCreateRequestDto createDto) throws ImageNotFoundException, DockerClientException, ContainerAlreadyExistsException {
final Optional<ContainerImage> image = imageRepository.findByRepositoryAndTag(createDto.getRepository(), createDto.getTag());
if (image.isEmpty()) {
log.error("failed to get image with name {}:{}", createDto.getRepository(), createDto.getTag());
......@@ -82,7 +82,7 @@ public class ContainerServiceImpl implements ContainerService {
.exec();
} catch (ConflictException e) {
log.error("Conflicting names {}", createDto.getName());
throw new DockerClientException("Unexpected behavior", e);
throw new ContainerAlreadyExistsException("Unexpected behavior", e);
} catch (NotFoundException e) {
log.error("The image {}:{} not available on the container service", createDto.getRepository(), createDto.getTag());
log.debug("payload was {}", createDto);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment