Fix su timeout in HttpRestWrapper.
Migliorato caricamento iniziale databases.
This commit is contained in:
@@ -25,6 +25,7 @@ import java.sql.DriverManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.reflections.scanners.Scanners.TypesAnnotated;
|
||||
@@ -51,6 +52,8 @@ public class EmsCoreContext {
|
||||
private boolean contextInitialized = false;
|
||||
|
||||
private boolean firstStart = true;
|
||||
@Autowired
|
||||
private ExecutorService taskExecutor;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
@@ -79,19 +82,7 @@ public class EmsCoreContext {
|
||||
logger.debug("Init");
|
||||
|
||||
try {
|
||||
//new Thread(() -> {
|
||||
try {
|
||||
emsCoreDBLoader.load((multiDBTransactionManager, onDone) -> {
|
||||
try {
|
||||
this.onPostDBLoaded(multiDBTransactionManager, onDone);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//}).start();
|
||||
emsCoreDBLoader.load(this::onPostDBLoaded);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(EmsCoreContext.class.getSimpleName(), e);
|
||||
@@ -100,27 +91,10 @@ public class EmsCoreContext {
|
||||
}
|
||||
|
||||
|
||||
private void onPostDBLoaded(MultiDBTransactionManager multiDBTransactionManager, Runnable onDone) throws InterruptedException {
|
||||
|
||||
// final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
dispatchPostContextConstruct(multiDBTransactionManager);
|
||||
|
||||
contextInitialized = true;
|
||||
|
||||
dispatchPostWebServerConstruct(multiDBTransactionManager);
|
||||
onDone.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("EmsCoreContext.onPostDBLoaded", e);
|
||||
}
|
||||
}).start();
|
||||
|
||||
// executorService.shutdown();
|
||||
// executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
||||
|
||||
private void onPostDBLoaded(MultiDBTransactionManager multiDBTransactionManager) throws InvocationTargetException, IllegalAccessException {
|
||||
dispatchPostContextConstruct(multiDBTransactionManager);
|
||||
contextInitialized = true;
|
||||
dispatchPostWebServerConstruct(multiDBTransactionManager);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package it.integry.ems._context;
|
||||
import it.integry.annotations.PostContextConstruct;
|
||||
import it.integry.common.var.EmsDBConst;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.expansion.RunnableArgss;
|
||||
import it.integry.ems.expansion.RunnableArgsThrowable;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.settings.SettingsController;
|
||||
@@ -65,26 +65,22 @@ public class EmsCoreDBLoader {
|
||||
});
|
||||
}
|
||||
|
||||
public void load(final RunnableArgss<MultiDBTransactionManager, Runnable> onComplete) throws Exception {
|
||||
public void load(final RunnableArgsThrowable<MultiDBTransactionManager> onComplete) throws Exception {
|
||||
connectionPool.init();
|
||||
|
||||
MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionPool);
|
||||
try {
|
||||
discoverAllConnections(multiDBTransactionManager);
|
||||
setupAzienda(multiDBTransactionManager);
|
||||
userCacheService.discoverAllUsers(multiDBTransactionManager);
|
||||
taskExecutorService.executeTask(() -> {
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionPool)){
|
||||
discoverAllConnections(multiDBTransactionManager);
|
||||
setupAzienda(multiDBTransactionManager);
|
||||
userCacheService.discoverAllUsers(multiDBTransactionManager);
|
||||
|
||||
if (onComplete != null) onComplete.run(multiDBTransactionManager);
|
||||
} catch (Exception ex) {
|
||||
logger.error("EmsCoreDBLoader", ex);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}, false);
|
||||
|
||||
if (onComplete != null) onComplete.run(multiDBTransactionManager, () -> {
|
||||
try {
|
||||
multiDBTransactionManager.closeAll();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
logger.error("EmsCoreDBLoader", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void discoverAllConnections(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package it.integry.ems.expansion;
|
||||
|
||||
public interface RunnableArgsReturnThrowable<T> {
|
||||
|
||||
T run() throws Exception;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,6 @@ package it.integry.ems.expansion;
|
||||
|
||||
public interface RunnableArgsThrowable<T> {
|
||||
|
||||
T run() throws Exception;
|
||||
void run(T data) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import it.integry.security.utility.RestUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -113,7 +114,11 @@ public class HttpRestWrapper {
|
||||
}
|
||||
|
||||
public static int callGenericGet(String url, String username, String password, StringBuilder bodyResponse, HashMap<String, String> queryParams) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
final Client client = makeDefaultConfig();
|
||||
return callGenericGet(url, username, password, bodyResponse, queryParams, null);
|
||||
}
|
||||
|
||||
public static int callGenericGet(String url, String username, String password, StringBuilder bodyResponse, HashMap<String, String> queryParams, Integer timeout) throws NoSuchAlgorithmException, KeyManagementException {
|
||||
final Client client = makeDefaultConfig(timeout);
|
||||
WebTarget webTarget = client.target(url);
|
||||
|
||||
if (queryParams != null) {
|
||||
@@ -316,10 +321,11 @@ public class HttpRestWrapper {
|
||||
throw e;
|
||||
}
|
||||
|
||||
final ClientBuilder builder = ClientBuilder.newBuilder().hostnameVerifier((s, session) -> true)
|
||||
final ResteasyClientBuilder builder = new ResteasyClientBuilder()
|
||||
.hostnameVerifier((s, session) -> true)
|
||||
.sslContext(sslContext);
|
||||
|
||||
if (UtilityInteger.isNullOrZero(timeout))
|
||||
if (!UtilityInteger.isNullOrZero(timeout))
|
||||
builder.connectTimeout(timeout, TimeUnit.SECONDS);
|
||||
|
||||
return builder.build();
|
||||
|
||||
@@ -238,6 +238,16 @@ public class DroolsDataCompleting {
|
||||
.anyMatch(y -> y == customerDB))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if(customerDB == null) {
|
||||
logger.warn("Impossibile riconoscere ed iniettare il customer db all'interno delle regole");
|
||||
return;
|
||||
}
|
||||
|
||||
if(customer == null) {
|
||||
logger.warn("Impossibile riconoscere ed iniettare il customer all'interno delle regole");
|
||||
return;
|
||||
}
|
||||
|
||||
ksession.setGlobal("customerDb", customerDB);
|
||||
ksession.setGlobal("customer", customer);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package it.integry.ems_model.utility;
|
||||
|
||||
import it.integry.ems.dto.Result;
|
||||
import it.integry.ems.expansion.RunnableArgsThrowable;
|
||||
import it.integry.ems.expansion.RunnableArgsReturnThrowable;
|
||||
import it.integry.ems.expansion.RunnableThrowable;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -18,14 +18,14 @@ public class UtilityThread {
|
||||
|
||||
@Deprecated()
|
||||
public static ArrayList<Result<Object>> executeParallel(@NotNull List<RunnableThrowable> runnables) throws InterruptedException, ExecutionException {
|
||||
return executeParallel(runnables.stream().map(x -> (RunnableArgsThrowable<Object>) () -> {
|
||||
return executeParallel(runnables.stream().map(x -> (RunnableArgsReturnThrowable<Object>) () -> {
|
||||
x.run();
|
||||
return null;
|
||||
}).collect(Collectors.toList()), Runtime.getRuntime().availableProcessors() * 2);
|
||||
}
|
||||
|
||||
@Deprecated()
|
||||
public static <T> ArrayList<Result<T>> executeParallel(List<RunnableArgsThrowable<T>> runnables, int threadNumber) throws InterruptedException {
|
||||
public static <T> ArrayList<Result<T>> executeParallel(List<RunnableArgsReturnThrowable<T>> runnables, int threadNumber) throws InterruptedException {
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Math.min(Runtime.getRuntime().availableProcessors() * 2, threadNumber));
|
||||
|
||||
List<Callable<T>> calls = new ArrayList<>();
|
||||
|
||||
@@ -7,7 +7,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.document.dto.*;
|
||||
import it.integry.ems.document.dto.CaricoLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.ChiusuraLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.RientroLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.ScaricoLavorazioneDTO;
|
||||
import it.integry.ems.document.service.DocumentProdService;
|
||||
import it.integry.ems.exception.MissingDataException;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
@@ -31,6 +34,7 @@ import it.integry.ems.service.dto.production.OrdineLavorazioneDTO;
|
||||
import it.integry.ems.service.exception.EmptyReportException;
|
||||
import it.integry.ems.service.production.ProductionOrderDataHandlerService;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
@@ -70,6 +74,7 @@ import java.util.*;
|
||||
public class MesProductionServiceV2 {
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
@Autowired
|
||||
public PrinterService printerService;
|
||||
|
||||
@@ -94,9 +99,6 @@ public class MesProductionServiceV2 {
|
||||
@Autowired
|
||||
private ProductionOrderDataHandlerService productionOrderDataHandlerService;
|
||||
|
||||
@Autowired
|
||||
private ProductionWarehouseService productionWarehouseService;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@@ -112,9 +114,11 @@ public class MesProductionServiceV2 {
|
||||
private WMSGenericService wmsGenericService;
|
||||
|
||||
public BasePanelAnswerDTO callSupervisorServiceGET(String serviceIp, int servicePort, String serviceName, HashMap<String, String> queryParams) throws Exception {
|
||||
Integer timeout = setupGest.getSetupInteger(multiDBTransactionManager.getPrimaryConnection(), "MES", "HMI", "TIMEOUT_MACHINE_CONNECTION", 5);
|
||||
|
||||
String url = String.format("http://%s:%d/%s", serviceIp, servicePort, serviceName);
|
||||
StringBuilder srb = new StringBuilder();
|
||||
int requestStatusCode = HttpRestWrapper.callGenericGet(url, null, null, srb, queryParams);
|
||||
int requestStatusCode = HttpRestWrapper.callGenericGet(url, null, null, srb, queryParams, timeout);
|
||||
|
||||
if (requestStatusCode != HttpURLConnection.HTTP_OK)
|
||||
throw new Exception(String.format("Non è stato possibile comunicare con il pannello supervisore (Status: %d)", requestStatusCode));
|
||||
@@ -125,11 +129,11 @@ public class MesProductionServiceV2 {
|
||||
}
|
||||
|
||||
public BasePanelAnswerDTO callSupervisorServicePOST(String serviceIp, int servicePort, String serviceName, String jsonRequest) throws Exception {
|
||||
Integer timeout = setupGest.getSetupInteger(multiDBTransactionManager.getPrimaryConnection(), "MES", "HMI", "TIMEOUT_MACHINE_CONNECTION", 5);
|
||||
|
||||
String url = String.format("http://%s:%d/%s", serviceIp, servicePort, serviceName);
|
||||
StringBuilder srb = new StringBuilder();
|
||||
|
||||
Integer timeout = setupGest.getSetupInteger(multiDBTransactionManager.getPrimaryConnection(), "MES", "HMI", "TIMEOUT_MACHINE_CONNECTION", 0);
|
||||
|
||||
int requestStatusCode = HttpRestWrapper.callGeneric(url, null, null, jsonRequest, ContentType.APPLICATION_JSON, srb, null, timeout);
|
||||
|
||||
if (requestStatusCode != HttpURLConnection.HTTP_OK) {
|
||||
@@ -143,6 +147,10 @@ public class MesProductionServiceV2 {
|
||||
|
||||
|
||||
public Object getCurrentMachinesStatus(String codJfas) throws Exception {
|
||||
if (UtilityDebug.isIntegryServer()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RegisterSupervisorDTO hmiData = getSupervisorPanelData(codJfas);
|
||||
|
||||
if (hmiData != null) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package it.integry.ems.retail.ReportVariazioni.service;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.dto.Result;
|
||||
import it.integry.ems.expansion.RunnableArgsThrowable;
|
||||
import it.integry.ems.expansion.RunnableArgsReturnThrowable;
|
||||
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniDTO;
|
||||
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniDettaglioDTO;
|
||||
import it.integry.ems.retail.ReportVariazioni.dto.VariazioniPvInputDTO;
|
||||
@@ -1133,7 +1133,7 @@ public class VariazioniPvService {
|
||||
|
||||
List<VariazioniDTO> listini = getListini(variazioniPvInputDTO, existVariazioni);
|
||||
|
||||
List<RunnableArgsThrowable<Triple<String, String, List<VariazioniDettaglioDTO>>>> calls = new ArrayList<>();
|
||||
List<RunnableArgsReturnThrowable<Triple<String, String, List<VariazioniDettaglioDTO>>>> calls = new ArrayList<>();
|
||||
|
||||
for (VariazioniDTO pv : listini) {
|
||||
for (String report : tipiReport) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.google.common.base.Joiner;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.dto.ExtendedStbActivity;
|
||||
import it.integry.ems.dto.Result;
|
||||
import it.integry.ems.expansion.RunnableArgsThrowable;
|
||||
import it.integry.ems.expansion.RunnableArgsReturnThrowable;
|
||||
import it.integry.ems.file_sharer.IFileSharerAttachment;
|
||||
import it.integry.ems.file_sharer.sharers.email.EmailFileAttachment;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
@@ -1438,7 +1438,7 @@ public class SystemController {
|
||||
|
||||
String tempDir = Paths.get(UtilityDirs.getTempDirectoryPath(), "vgalimenti-export-" + dateTimeFormatter.format(LocalDateTime.now())).toString();
|
||||
|
||||
List<RunnableArgsThrowable<Triple<String, String, List<VariazioniDettaglioDTO>>>> calls = new ArrayList<>();
|
||||
List<RunnableArgsReturnThrowable<Triple<String, String, List<VariazioniDettaglioDTO>>>> calls = new ArrayList<>();
|
||||
|
||||
|
||||
for (HashMap<String, Object> document : documents) {
|
||||
|
||||
Reference in New Issue
Block a user