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

Fixed the test

parent e6a80f2e
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!161Resolve "Frontend bugs"
...@@ -156,16 +156,12 @@ public class ContainerEndpoint { ...@@ -156,16 +156,12 @@ public class ContainerEndpoint {
public ResponseEntity<ContainerDto> findById(@NotNull @PathVariable("id") Long containerId) public ResponseEntity<ContainerDto> findById(@NotNull @PathVariable("id") Long containerId)
throws DockerClientException, ContainerNotFoundException { throws DockerClientException, ContainerNotFoundException {
log.debug("endpoint find container, id={}", containerId); log.debug("endpoint find container, id={}", containerId);
final Container container = containerService.find(containerId); ContainerDto dto;
final ContainerDto dto = containerMapper.containerToContainerDto(container);
final ContainerDto inspect;
try { try {
inspect = containerService.inspect(containerId); dto = containerService.inspect(containerId);
dto.setIpAddress(inspect.getIpAddress());
dto.setRunning(inspect.getRunning());
dto.setState(inspect.getState());
} catch (ContainerNotRunningException e) { } catch (ContainerNotRunningException e) {
/* ignore */ /* ignore */
dto = containerMapper.containerToContainerDto(containerService.find(containerId));
dto.setRunning(false); dto.setRunning(false);
dto.setState(ContainerStateDto.EXITED); dto.setState(ContainerStateDto.EXITED);
} }
......
...@@ -12,46 +12,56 @@ import java.util.List; ...@@ -12,46 +12,56 @@ import java.util.List;
public interface ContainerService { public interface ContainerService {
/** /**
* @param createDto * Creates a container.
* @param principal *
* @return * @param createDto The container metadata.
* @throws ImageNotFoundException * @param principal The principal of the creating user.
* @throws DockerClientException * @return The container object, if successful.
* @throws ContainerAlreadyExistsException * @throws ImageNotFoundException The image of the container was not found in the metadata database.
* @throws UserNotFoundException * @throws DockerClientException The docker client was unable to perform this action.
* @throws ContainerAlreadyExistsException A container with this name already exists.
* @throws UserNotFoundException The user creating the container was not found in the metadata database.
*/ */
Container create(ContainerCreateRequestDto createDto, Principal principal) throws ImageNotFoundException, Container create(ContainerCreateRequestDto createDto, Principal principal) throws ImageNotFoundException,
DockerClientException, ContainerAlreadyExistsException, UserNotFoundException; DockerClientException, ContainerAlreadyExistsException, UserNotFoundException;
/** /**
* @param containerId * Stops a container by given id from the metadata database.
* @return *
* @throws ContainerNotFoundException * @param containerId The container id.
* @throws DockerClientException * @return The container object, if successful.
* @throws ContainerNotFoundException The container was not found in the metadata database.
* @throws DockerClientException The docker client was unable to perform this action.
*/ */
Container stop(Long containerId) throws ContainerNotFoundException, DockerClientException, ContainerAlreadyStoppedException; Container stop(Long containerId) throws ContainerNotFoundException, DockerClientException, ContainerAlreadyStoppedException;
/** /**
* @param containerId * Removes a stopped container by given id from the metadata database.
* @throws ContainerNotFoundException *
* @throws DockerClientException * @param containerId The container id.
* @throws ContainerStillRunningException * @throws ContainerNotFoundException The container was not found in the metadata database.
* @throws DockerClientException The docker client was unable to perform this action.
* @throws ContainerStillRunningException The container is still running and this action cannot be performed.
*/ */
void remove(Long containerId) throws ContainerNotFoundException, DockerClientException, void remove(Long containerId) throws ContainerNotFoundException, DockerClientException,
ContainerStillRunningException, ContainerAlreadyRemovedException; ContainerStillRunningException, ContainerAlreadyRemovedException;
/** /**
* @param id * Finds a container with a specific id from the metadata database.
* @return *
* @throws ContainerNotFoundException * @param id The container id.
* @return The container object, if successful.
* @throws ContainerNotFoundException The container was not found in the metadata database.
*/ */
Container find(Long id) throws ContainerNotFoundException; Container find(Long id) throws ContainerNotFoundException;
/** /**
* @param id * Inspects a container state and resources by given id.
* @return *
* @throws DockerClientException * @param id The container id.
* @throws ContainerNotRunningException * @return The container object.
* @throws DockerClientException The docker client was unable to perform this action.
* @throws ContainerNotRunningException The docker container is not running.
*/ */
ContainerDto inspect(Long id) throws DockerClientException, ContainerNotRunningException, ContainerNotFoundException; ContainerDto inspect(Long id) throws DockerClientException, ContainerNotRunningException, ContainerNotFoundException;
...@@ -63,13 +73,20 @@ public interface ContainerService { ...@@ -63,13 +73,20 @@ public interface ContainerService {
*/ */
List<Container> getAll(Integer limit); List<Container> getAll(Integer limit);
/**
* Find all containers on the server.
*
* @return List of containers.
*/
List<com.github.dockerjava.api.model.Container> list(); List<com.github.dockerjava.api.model.Container> list();
/** /**
* @param containerId * Starts a container with given id from the metadata database.
* @return *
* @throws ContainerNotFoundException * @param containerId The container id.
* @throws DockerClientException * @return The container object, if successful.
* @throws ContainerNotFoundException The container was not found in the metadata database.
* @throws DockerClientException The docker client was unable to perform this action.
*/ */
Container start(Long containerId) throws ContainerNotFoundException, DockerClientException, ContainerAlreadyRunningException; Container start(Long containerId) throws ContainerNotFoundException, DockerClientException, ContainerAlreadyRunningException;
} }
...@@ -208,20 +208,19 @@ public class ContainerServiceImpl implements ContainerService { ...@@ -208,20 +208,19 @@ public class ContainerServiceImpl implements ContainerService {
log.error("Failed to inspect container state: container is not running"); log.error("Failed to inspect container state: container is not running");
throw new ContainerNotRunningException("Failed to inspect container state"); throw new ContainerNotRunningException("Failed to inspect container state");
} }
final ContainerDto entity = ContainerDto.builder() final ContainerDto dto = containerMapper.containerToContainerDto(container);
.hash(container.getHash()) dto.setHash(container.getHash());
.running(response.getState().getRunning()) dto.setRunning(response.getState().getRunning());
.state(containerMapper.containerStateToContainerStateDto(response.getState())) dto.setState(containerMapper.containerStateToContainerStateDto(response.getState()));
.build();
/* now we only support one network */ /* now we only support one network */
response.getNetworkSettings() response.getNetworkSettings()
.getNetworks() .getNetworks()
.forEach((key, network) -> { .forEach((key, network) -> {
log.trace("key {} network {}", key, network); log.trace("key {} network {}", key, network);
container.setIpAddress(network.getIpAddress()); dto.setIpAddress(network.getIpAddress());
}); });
log.info("Inspected container with hash {}", container.getHash()); log.info("Inspected container with hash {}", container.getHash());
return entity; return dto;
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment