mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix sonar bugs for DockerHelper class
This commit is contained in:
@@ -39,6 +39,8 @@ import com.github.dockerjava.api.model.Frame;
|
|||||||
import com.github.dockerjava.core.DockerClientBuilder;
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
import com.github.dockerjava.core.command.LogContainerResultCallback;
|
import com.github.dockerjava.core.command.LogContainerResultCallback;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -55,8 +57,10 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class DockerHelper
|
public class DockerHelper
|
||||||
{
|
{
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private static final Logger LOGGER = LoggerFactory.getLogger(DockerHelper.class);
|
||||||
private static final String REPO_IMAGE_NAME = "repository";
|
private static final String REPO_IMAGE_NAME = "repository";
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
private DockerClient dockerClient;
|
private DockerClient dockerClient;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -82,9 +86,9 @@ public class DockerHelper
|
|||||||
{
|
{
|
||||||
final List<String> logs = new ArrayList<>();
|
final List<String> logs = new ArrayList<>();
|
||||||
// get the logs since current time - 10 seconds
|
// get the logs since current time - 10 seconds
|
||||||
int timeStamp = (int) (System.currentTimeMillis() / 1000) - 10;
|
final int timeStamp = (int) (System.currentTimeMillis() / 1000) - 10;
|
||||||
|
|
||||||
LogContainerCmd logContainerCmd = dockerClient.logContainerCmd(containerId);
|
final LogContainerCmd logContainerCmd = getDockerClient().logContainerCmd(containerId);
|
||||||
logContainerCmd.withStdOut(true)
|
logContainerCmd.withStdOut(true)
|
||||||
.withStdErr(true)
|
.withStdErr(true)
|
||||||
.withSince(timeStamp) // UNIX timestamp to filter logs. Output log-entries since that timestamp.
|
.withSince(timeStamp) // UNIX timestamp to filter logs. Output log-entries since that timestamp.
|
||||||
@@ -104,7 +108,7 @@ public class DockerHelper
|
|||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
Thread.currentThread().interrupt(); // set interrupt flag
|
Thread.currentThread().interrupt(); // set interrupt flag
|
||||||
logger.error("Failed to retrieve logs of container " + containerId, e);
|
LOGGER.error("Failed to retrieve logs of container " + containerId, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return logs;
|
return logs;
|
||||||
@@ -117,7 +121,7 @@ public class DockerHelper
|
|||||||
*/
|
*/
|
||||||
public List<String> getAlfrescoLogs()
|
public List<String> getAlfrescoLogs()
|
||||||
{
|
{
|
||||||
Optional<Container> alfrescoContainer = findContainerByImageName(REPO_IMAGE_NAME);
|
final Optional<Container> alfrescoContainer = findContainerByImageName(REPO_IMAGE_NAME);
|
||||||
return (alfrescoContainer.isPresent()) ? getDockerLogs(alfrescoContainer.get().getId()) : Collections.emptyList();
|
return (alfrescoContainer.isPresent()) ? getDockerLogs(alfrescoContainer.get().getId()) : Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +133,7 @@ public class DockerHelper
|
|||||||
*/
|
*/
|
||||||
private Optional<Container> findContainerByImageName(String imageName)
|
private Optional<Container> findContainerByImageName(String imageName)
|
||||||
{
|
{
|
||||||
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
|
final List<Container> containers = getDockerClient().listContainersCmd().withShowAll(true).exec();
|
||||||
|
|
||||||
return containers.stream()
|
return containers.stream()
|
||||||
.filter(container -> container.getImage().contains(imageName))
|
.filter(container -> container.getImage().contains(imageName))
|
||||||
|
@@ -146,7 +146,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest
|
|||||||
STEP("Create test collaboration site to store documents in.");
|
STEP("Create test collaboration site to store documents in.");
|
||||||
publicSite = dataSite.usingAdmin().createPublicRandomSite();
|
publicSite = dataSite.usingAdmin().createPublicRandomSite();
|
||||||
|
|
||||||
STEP("Create a test foloder within the collaboration site");
|
STEP("Create a test folder within the collaboration site");
|
||||||
testFolder = dataContent.usingAdmin().usingSite(publicSite).createFolder();
|
testFolder = dataContent.usingAdmin().usingSite(publicSite).createFolder();
|
||||||
|
|
||||||
STEP("Create record categories and record folders");
|
STEP("Create record categories and record folders");
|
||||||
|
Reference in New Issue
Block a user