Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : thread block on some unix system when creating demo project #615

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,12 @@

package com.decathlon.ara.loader;

import com.decathlon.ara.ci.bean.Build;
import com.decathlon.ara.ci.bean.CycleDef;
import com.decathlon.ara.ci.bean.PlatformRule;
import com.decathlon.ara.ci.bean.QualityThreshold;
import com.decathlon.ara.common.NotGonnaHappenException;
import com.decathlon.ara.domain.CycleDefinition;
import com.decathlon.ara.domain.enumeration.Result;
import com.decathlon.ara.repository.CycleDefinitionRepository;
import com.decathlon.ara.service.ExecutionService;
import com.decathlon.ara.service.SettingService;
import com.decathlon.ara.service.dto.cycledefinition.CycleDefinitionDTO;
import com.decathlon.ara.service.support.Settings;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.decathlon.ara.loader.DemoLoaderConstants.BRANCH_DEVELOP;
import static com.decathlon.ara.loader.DemoLoaderConstants.BRANCH_MASTER;
import static com.decathlon.ara.loader.DemoLoaderConstants.CYCLE_DAY;
import static com.decathlon.ara.loader.DemoLoaderConstants.CYCLE_NIGHT;
import static com.decathlon.ara.loader.DemoLoaderConstants.PROJECT_CODE_DEMO;

import javax.persistence.EntityManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -50,20 +31,48 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.decathlon.ara.loader.DemoLoaderConstants.*;
import javax.persistence.EntityManager;

import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.decathlon.ara.ci.bean.Build;
import com.decathlon.ara.ci.bean.CycleDef;
import com.decathlon.ara.ci.bean.PlatformRule;
import com.decathlon.ara.ci.bean.QualityThreshold;
import com.decathlon.ara.common.NotGonnaHappenException;
import com.decathlon.ara.domain.CycleDefinition;
import com.decathlon.ara.domain.enumeration.Result;
import com.decathlon.ara.repository.CycleDefinitionRepository;
import com.decathlon.ara.service.ExecutionService;
import com.decathlon.ara.service.SettingService;
import com.decathlon.ara.service.dto.cycledefinition.CycleDefinitionDTO;
import com.decathlon.ara.service.support.Settings;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Service for loading executions into the Demo project.
Expand All @@ -82,6 +91,8 @@ public class DemoExecutionLoader {

private static final Pattern POSTMAN_ECHO_HOST_PATTERN = Pattern.compile("postman-echo.com");

private static final Random RANDOM = new Random();

private static final BiPredicate<Path, BasicFileAttributes> JSON_FILE_FILTER = (path, attributes) -> attributes.isRegularFile() && path.getFileName().toString().endsWith(".json");

private final SettingService settingService;
Expand Down Expand Up @@ -306,15 +317,9 @@ private void copyStreamToFile(InputStream stream, File destinationFile) throws I
}

private String randomGitCommitId() {
Random random;
try {
random = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
random = new SecureRandom();
}
char[] id = new char[40];
for (int i = 0; i < id.length; i++) {
id[i] = Integer.toHexString(random.nextInt(16)).charAt(0);
id[i] = Integer.toHexString(RANDOM.nextInt(16)).charAt(0);
}
return new String(id);
}
Expand Down