release version 1.10.0
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>initializer</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -29,7 +29,7 @@
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Entaxy-Initializer-Class>ru.entaxy.esb.platform.runtime.core.initializer.connection.ConnectionInitializer?id=connections&repeat=true&retries=10&interval=2000&depends-on=core,datasources</Entaxy-Initializer-Class>
|
||||
<Entaxy-Initializer-Class-0>ru.entaxy.esb.platform.runtime.core.initializer.connection.ConnectionInitializer?id=connections&repeat=true&retries=10&interval=2000&depends-on=core,datasources</Entaxy-Initializer-Class-0>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@ -45,16 +45,21 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>src/main/non-packaged-resources/etc/init/entaxy-platform-connections.json</file>
|
||||
<type>json</type>
|
||||
<classifier>init-config</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>src/main/non-packaged-resources/etc/init/file-connections.json</file>
|
||||
<type>json</type>
|
||||
<classifier>init-config-files</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>src/main/non-packaged-resources/etc/init/db-connections.json</file>
|
||||
<type>json</type>
|
||||
<classifier>init-config-databases</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>src/main/non-packaged-resources/etc/init/broker-connections.json</file>
|
||||
<type>json</type>
|
||||
<classifier>init-config-brokers</classifier>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
@ -68,11 +73,6 @@
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>osgi.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core.management</groupId>
|
||||
<artifactId>connection-manager</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* connection-initializer
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,278 +27,319 @@ package ru.entaxy.esb.platform.runtime.core.initializer.connection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.entaxy.esb.platform.runtime.core.initializer.api.AbstractInitializer;
|
||||
import ru.entaxy.esb.platform.runtime.core.initializer.api.InitializerException;
|
||||
import ru.entaxy.esb.platform.runtime.core.management.connection.util.ConnectionManagerUtil;
|
||||
import ru.entaxy.esb.platform.runtime.core.initializer.api.AbstractStandaloneInitializer;
|
||||
import ru.entaxy.esb.platform.runtime.core.initializer.api.Initialized;
|
||||
import ru.entaxy.esb.platform.runtime.core.initializer.api.StandaloneInitializer;
|
||||
import ru.entaxy.platform.base.objects.factory.exceptions.FactoryNotFoundException;
|
||||
import ru.entaxy.platform.base.support.FileUtils;
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
import ru.entaxy.platform.base.support.osgi.OSGIUtils;
|
||||
import ru.entaxy.platform.core.artifact.ArtifactCoordinates;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
|
||||
import ru.entaxy.platform.core.producer.api.EntaxyProducerUtils;
|
||||
import ru.entaxy.platform.core.producer.api.ProducerResult;
|
||||
import ru.entaxy.platform.core.producer.api.ProducerResult.CommandResult;
|
||||
import ru.entaxy.platform.core.producer.executor.generationmodel.GenerateTask;
|
||||
import ru.entaxy.platform.core.producer.executor.generationmodel.GenerationModel;
|
||||
import ru.entaxy.platform.core.producer.executor.installer.InstalledObjectList;
|
||||
import ru.entaxy.platform.core.producer.executor.objectmodel.ObjectModel;
|
||||
|
||||
public class ConnectionInitializer extends AbstractInitializer {
|
||||
@Component(service = ConnectionInitializer.class, immediate = true)
|
||||
@StandaloneInitializer(id = "connections")
|
||||
public class ConnectionInitializer extends AbstractStandaloneInitializer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ConnectionInitializer.class);
|
||||
|
||||
private static final String JSON_FILE_NAME = "entaxy-platform-connections.json";
|
||||
|
||||
private static final String jsonBundlePath = "/connection/" + JSON_FILE_NAME;
|
||||
protected static final Logger log = LoggerFactory.getLogger(ConnectionInitializer.class);
|
||||
|
||||
private static final String INIT_FILES_PATH = System.getProperty("karaf.etc")
|
||||
+ File.separator
|
||||
+ "init";
|
||||
|
||||
private static final String JSON_FILE_PATH = INIT_FILES_PATH
|
||||
+ File.separator
|
||||
+ JSON_FILE_NAME;
|
||||
private static final String INIT_FILES_PATH = System.getProperty("karaf.etc")
|
||||
+ File.separator
|
||||
+ "init";
|
||||
|
||||
private EntaxyProducerService entaxyProducerService;
|
||||
|
||||
@Override
|
||||
public void init() throws InitializerException {
|
||||
log.info("ConnectionInitializer started");
|
||||
log.info("-->> " + JSON_FILE_PATH);
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC,
|
||||
policyOption = ReferencePolicyOption.GREEDY, target = "(id=core)")
|
||||
volatile Initialized coreInitializedMarker;
|
||||
|
||||
|
||||
try {
|
||||
entaxyProducerService = OSGIUtils.services().bundleContext(bundleContext)
|
||||
.ofClass(EntaxyProducerService.class)
|
||||
.waitService(50000)
|
||||
.get();
|
||||
if (entaxyProducerService == null)
|
||||
throw new InitializerException(this, "Service EntaxyProducerService not found", "", null);
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting EntaxyProducerService", e);
|
||||
throw new InitializerException(this, "Error getting EntaxyProducerService", "", e);
|
||||
}
|
||||
|
||||
// first scan factory-base files
|
||||
try {
|
||||
scanAndInitFromFactoryFiles();
|
||||
} catch (Exception e) {
|
||||
log.error("Error initializing connections from factory files", e);
|
||||
throw new InitializerException(this, "Can't create platform connections", "", e);
|
||||
}
|
||||
|
||||
|
||||
// then use the old one
|
||||
try {
|
||||
initPlatformConnections(bundleContext);
|
||||
} catch (Exception e) {
|
||||
log.error("Error initializing connections from " + JSON_FILE_PATH, e);
|
||||
throw new InitializerException(this, "Can't create platform connections", "", e);
|
||||
}
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC,
|
||||
policyOption = ReferencePolicyOption.GREEDY, target = "(id=datasources)")
|
||||
volatile Initialized datasourcesInitializedMarker;
|
||||
|
||||
|
||||
@Reference
|
||||
EntaxyProducerService entaxyProducerService;
|
||||
|
||||
ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||
|
||||
int globalRetriesCount = 10;
|
||||
|
||||
int globalRetryInterval = 2000;
|
||||
|
||||
boolean factoryFilesTaskResult = false;
|
||||
|
||||
public void setFactoryFilesTaskResult(boolean factoryFilesTaskResult) {
|
||||
this.factoryFilesTaskResult = factoryFilesTaskResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reinit() throws InitializerException {
|
||||
// TODO Auto-generated method stub
|
||||
protected void checkAndRegister() {
|
||||
if (factoryFilesTaskResult)
|
||||
register();
|
||||
}
|
||||
|
||||
private void scanAndInitFromFactoryFiles() throws Exception {
|
||||
|
||||
File initDir = new File(INIT_FILES_PATH);
|
||||
if (!initDir.exists() || !initDir.isDirectory())
|
||||
return;
|
||||
|
||||
File[] files = initDir.listFiles(new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".json") && !JSON_FILE_NAME.equals(name);
|
||||
}
|
||||
});
|
||||
|
||||
if ((files == null) || (files.length==0))
|
||||
return;
|
||||
|
||||
for (int i=0; i<files.length; i++) {
|
||||
log.debug("FOUND FILE :: " + files[i].getName());
|
||||
|
||||
//
|
||||
// check if the file contains objects
|
||||
//
|
||||
|
||||
FileUtils.FileHelper helper = new FileUtils.FileHelper(files[i].getAbsolutePath());
|
||||
if (!helper.isReadable()) {
|
||||
// TODO throw exception
|
||||
log.warn("Platform connections file {} is not readable", JSON_FILE_PATH);
|
||||
continue;
|
||||
|
||||
protected class FactoryFilesTask implements Runnable {
|
||||
|
||||
protected CommandResult getCommandResult(final String id, ProducerResult producerResult) {
|
||||
Optional<CommandResult> result =
|
||||
producerResult.getCommandResults().stream().filter(c -> c.commandId.equals(id))
|
||||
.findFirst();
|
||||
if (result.isEmpty())
|
||||
return null;
|
||||
return result.get();
|
||||
}
|
||||
|
||||
protected boolean checkResult(ProducerResult producerResult) {
|
||||
CommandResult cr = getCommandResult("install", producerResult);
|
||||
if (cr == null)
|
||||
return false;
|
||||
if (!cr.result || cr.skipped)
|
||||
return false;
|
||||
|
||||
try {
|
||||
GenerationModel generationModel = producerResult.findResultObject(GenerationModel.class);
|
||||
List<GenerateTask> generateTasks = generationModel.getTasks().stream()
|
||||
.filter(t -> (t instanceof GenerateTask))
|
||||
.filter(t -> !t.isToMerge())
|
||||
.map(t -> (GenerateTask) t)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
InstalledObjectList installedList = producerResult.findResultObject(InstalledObjectList.class);
|
||||
|
||||
log.debug("FactoryFilesTask :: Generated:[{}]; Installed:[{}]", generateTasks.size(),
|
||||
installedList.size());
|
||||
|
||||
return installedList.size() == generateTasks.size();
|
||||
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
JsonObject jsonData;
|
||||
try {
|
||||
URL url = files[i].toURI().toURL();
|
||||
jsonData = JSONUtils.getJsonRootObject(url);
|
||||
} catch (Exception e) {
|
||||
log.warn("Configuration loading failed:" + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectModel objectModel = new ObjectModel();
|
||||
|
||||
try {
|
||||
objectModel.load(jsonData);
|
||||
objectModel.checkRefs();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error loading model from " + files[i].getAbsolutePath(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (objectModel.objects.size() == 0)
|
||||
continue;
|
||||
|
||||
log.debug("CONTAINS OBJECTS :: " + files[i].getName());
|
||||
|
||||
|
||||
//
|
||||
// check availability of factories
|
||||
//
|
||||
List<String> factoryIds = objectModel.objects.stream()
|
||||
.map(obj -> obj.factoryId)
|
||||
.collect(Collectors.toList());
|
||||
for (String factoryId: factoryIds) {
|
||||
String message = "CHECK FACTORY :: " + factoryId + "..";
|
||||
if (entaxyProducerService.findFactoryById(factoryId) == null) {
|
||||
message += " NOT FOUND";
|
||||
log.debug(message);
|
||||
throw new InitializerException(this, "Factory not found: " + factoryId, "", null);
|
||||
}
|
||||
message += " FOUND";
|
||||
log.debug(message);
|
||||
}
|
||||
|
||||
log.debug("FACTORIES AVAILABLE :: " + files[i].getName());
|
||||
|
||||
//
|
||||
// produce objects
|
||||
//
|
||||
|
||||
EntaxyProducerUtils.InstructionsBuilder builder = EntaxyProducerUtils.instructions()
|
||||
.lifecycle("general")
|
||||
.any()
|
||||
.command("add-config")
|
||||
.command("pre-generate")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.PRINT_OUTPUT, false)
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY
|
||||
, ArtifactCoordinates.VERSION_POLICY_DATED_EMBEDDED)
|
||||
.command("deploy")
|
||||
.set("deployLocal", true);
|
||||
|
||||
if (helper.isChanged()) {
|
||||
log.info("File is new or changed, install/update connections: " + files[i].getAbsolutePath());
|
||||
// we need to create/update connections with new timestamp
|
||||
String oldTimestamp = helper.getTimestamp();
|
||||
String newTimestamp = helper.updateTimestamp();
|
||||
|
||||
builder
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP, newTimestamp)
|
||||
.command("install")
|
||||
.set("update", "")
|
||||
.set("installLocal", true)
|
||||
.set("startLevel", 75);
|
||||
|
||||
String instructions = builder
|
||||
.getInstructionsString();
|
||||
|
||||
entaxyProducerService.produce(jsonData, instructions);
|
||||
|
||||
helper.updateMd5();
|
||||
} else {
|
||||
log.info("File is not changed, install/check connection: " + files[i].getAbsolutePath());
|
||||
|
||||
String oldTimestamp = helper.getTimestamp();
|
||||
|
||||
builder
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP, oldTimestamp)
|
||||
.command("install")
|
||||
.set("installOnlyIfMissing", true)
|
||||
.set("installLocal", true)
|
||||
.set("startLevel", 75);
|
||||
|
||||
String instructions = builder
|
||||
.getInstructionsString();
|
||||
|
||||
entaxyProducerService.produce(jsonData, instructions);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initPlatformConnections(BundleContext bundleContext) throws Exception {
|
||||
checkAndPrepareFile(bundleContext);
|
||||
String json = getJsonAsString(bundleContext);
|
||||
|
||||
FileUtils.FileHelper helper = new FileUtils.FileHelper(JSON_FILE_PATH);
|
||||
if (!helper.isReadable()) {
|
||||
// TODO throw exception
|
||||
log.error("Platform connections file {} is not readable", JSON_FILE_PATH);
|
||||
return;
|
||||
// return true;
|
||||
}
|
||||
|
||||
if (helper.isChanged()) {
|
||||
log.info("File is new or changed, install/update connections");
|
||||
// we need to create/update connections with new timestamp
|
||||
String oldTimestamp = helper.getTimestamp();
|
||||
String newTimestamp = helper.updateTimestamp();
|
||||
|
||||
// ConnectionManagerUtil.getService().createAndInstallConnections(json);
|
||||
ConnectionManagerUtil.getService().installUpdateConnections(json, newTimestamp);
|
||||
|
||||
helper.updateMd5();
|
||||
} else {
|
||||
log.info("File is not changed, install/check connections");
|
||||
// we need to create if absent connections with old timestamp
|
||||
// ConnectionManagerUtil.getService().createAndInstallConnections(json);
|
||||
ConnectionManagerUtil.getService().checkInstallConnections(json, helper.getTimestamp());
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
int retriesLeft = globalRetriesCount;
|
||||
|
||||
File initDir = new File(INIT_FILES_PATH);
|
||||
if (!initDir.exists() || !initDir.isDirectory()) {
|
||||
log.info("FactoryFilesTask :: initDir not available");
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = initDir.listFiles(new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".json");
|
||||
}
|
||||
});
|
||||
|
||||
if ((files == null) || (files.length == 0)) {
|
||||
log.info("FactoryFilesTask :: files not found in initDir");
|
||||
return;
|
||||
}
|
||||
while (retriesLeft > 0) {
|
||||
try {
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
log.debug("FactoryFilesTask :: FOUND FILE :: " + files[i].getName());
|
||||
|
||||
//
|
||||
// check if the file contains objects
|
||||
//
|
||||
|
||||
FileUtils.FileHelper helper = new FileUtils.FileHelper(files[i].getAbsolutePath());
|
||||
if (!helper.isReadable()) {
|
||||
// TODO throw exception
|
||||
log.warn("FactoryFilesTask :: file {} is not readable", files[i].getAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
JsonObject jsonData;
|
||||
try {
|
||||
URL url = files[i].toURI().toURL();
|
||||
jsonData = JSONUtils.getJsonRootObject(url);
|
||||
} catch (Exception e) {
|
||||
log.warn("FactoryFilesTask :: Configuration loading failed:" + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectModel objectModel = new ObjectModel();
|
||||
|
||||
try {
|
||||
objectModel.load(jsonData);
|
||||
objectModel.checkRefs();
|
||||
} catch (Exception e) {
|
||||
log.warn("FactoryFilesTask :: Error loading model from " + files[i].getAbsolutePath(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (objectModel.objects.size() == 0)
|
||||
continue;
|
||||
|
||||
log.debug("FactoryFilesTask :: CONTAINS OBJECTS :: " + files[i].getName());
|
||||
|
||||
//
|
||||
// check availability of factories
|
||||
//
|
||||
List<String> factoryIds = objectModel.objects.stream()
|
||||
.map(obj -> obj.factoryId)
|
||||
.collect(Collectors.toList());
|
||||
for (String factoryId : factoryIds) {
|
||||
String message = "CHECK FACTORY :: " + factoryId + "..";
|
||||
if (entaxyProducerService.findFactoryById(factoryId) == null) {
|
||||
message += " NOT FOUND";
|
||||
log.debug(message);
|
||||
throw new FactoryNotFoundException("Factory not found: " + factoryId);// (this,
|
||||
// "Factory
|
||||
// not
|
||||
// found:
|
||||
// "
|
||||
// +
|
||||
// factoryId,
|
||||
// "",
|
||||
// null);
|
||||
}
|
||||
message += " FOUND";
|
||||
log.debug(message);
|
||||
}
|
||||
|
||||
log.debug("FactoryFilesTask :: FACTORIES AVAILABLE :: " + files[i].getName());
|
||||
|
||||
//
|
||||
// produce objects
|
||||
//
|
||||
|
||||
EntaxyProducerUtils.InstructionsBuilder builder = EntaxyProducerUtils.instructions()
|
||||
.lifecycle("general")
|
||||
.any()
|
||||
.command("add-config")
|
||||
.command("pre-generate")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.PRINT_OUTPUT, false)
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.VERSION_POLICY,
|
||||
ArtifactCoordinates.VERSION_POLICY_DATED_EMBEDDED)
|
||||
.command("deploy")
|
||||
.set("deployLocal", true);
|
||||
|
||||
if (helper.isChanged()) {
|
||||
log.info("FactoryFilesTask :: File is new or changed, install/update connections: "
|
||||
+ files[i].getAbsolutePath());
|
||||
// we need to create/update connections with new timestamp
|
||||
String oldTimestamp = helper.getTimestamp();
|
||||
String newTimestamp = helper.updateTimestamp();
|
||||
|
||||
builder
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP, newTimestamp)
|
||||
.command("install")
|
||||
.set("update", "")
|
||||
.set("installLocal", true)
|
||||
.set("startLevel", 75);
|
||||
|
||||
String instructions = builder
|
||||
.getInstructionsString();
|
||||
|
||||
log.info("FactoryFilesTask :: running with instructions [" + instructions + "]");
|
||||
|
||||
ProducerResult result = entaxyProducerService.produce(jsonData, instructions);
|
||||
|
||||
log.debug("FactoryFilesTask :: last result command ["
|
||||
+ result.getLastCommandResult().commandId + "]");
|
||||
|
||||
if (!result.getAllExceptions().isEmpty()) {
|
||||
throw new Exception("ProducerResult contains exceptions");
|
||||
}
|
||||
|
||||
if (!checkResult(result)) {
|
||||
throw new Exception("ProducerResult not valid");
|
||||
}
|
||||
helper.updateMd5();
|
||||
} else {
|
||||
log.info("FactoryFilesTask :: File is not changed, install/check connection: "
|
||||
+ files[i].getAbsolutePath());
|
||||
|
||||
String oldTimestamp = helper.getTimestamp();
|
||||
|
||||
builder
|
||||
.command("build")
|
||||
.set(EntaxyProducerService.INSTRUCTIONS.ARTIFACT.TIMESTAMP, oldTimestamp)
|
||||
.command("install")
|
||||
.set("installOnlyIfMissing", true)
|
||||
.set("installLocal", true)
|
||||
.set("startLevel", 75);
|
||||
|
||||
String instructions = builder
|
||||
.getInstructionsString();
|
||||
|
||||
ProducerResult result = entaxyProducerService.produce(jsonData, instructions);
|
||||
if (!result.getAllExceptions().isEmpty()) {
|
||||
throw new Exception("ProducerResult contains exceptions");
|
||||
}
|
||||
if (!checkResult(result)) {
|
||||
throw new Exception("ProducerResult not valid");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setFactoryFilesTaskResult(true);
|
||||
checkAndRegister();
|
||||
return;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(
|
||||
String.format("Error in FactoryFilesTask; iteration=%d", globalRetriesCount - retriesLeft),
|
||||
e);
|
||||
try {
|
||||
Thread.sleep(globalRetryInterval);
|
||||
} catch (InterruptedException e1) {
|
||||
log.warn("FactoryFilesTask interrupted");
|
||||
checkAndRegister();
|
||||
return;
|
||||
}
|
||||
}
|
||||
retriesLeft--;
|
||||
}
|
||||
|
||||
checkAndRegister();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void checkAndPrepareFile(BundleContext context) throws IOException {
|
||||
File f = new File(JSON_FILE_PATH);
|
||||
if (!f.exists()) {
|
||||
FileUtils.string2file(getJsonAsString(context), JSON_FILE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
private String getJsonAsString(BundleContext context) throws IOException {
|
||||
URL jsonUrl;
|
||||
File f = new File(JSON_FILE_PATH);
|
||||
if (f.exists() && f.canRead()) {
|
||||
jsonUrl = f.toURI().toURL();
|
||||
log.info("Path to json file: " + jsonUrl.toString());
|
||||
} else {
|
||||
jsonUrl = context.getBundle().getEntry(jsonBundlePath);
|
||||
log.debug("Path to json file: " + jsonUrl.toString());
|
||||
}
|
||||
InputStream inputStream = jsonUrl.openStream();
|
||||
byte[] bytes = inputStream.readAllBytes();
|
||||
String result = new String(bytes, Charset.defaultCharset());
|
||||
inputStream.close();
|
||||
return result;
|
||||
}
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
log.info("ConnectionInitializer started");
|
||||
|
||||
setBundleContext(componentContext.getBundleContext());
|
||||
|
||||
threadPool.execute(new FactoryFilesTask());
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
{
|
||||
"connections": [
|
||||
{
|
||||
"nodeType": "connection",
|
||||
"uuid": "connection-uuid-2",
|
||||
"name": "entaxy-broker",
|
||||
"adapterName": "artemisAdapter",
|
||||
"platform": true,
|
||||
"pathParameter": "queue:entaxy.default",
|
||||
"properties": {
|
||||
"url": "(tcp://localhost:61616)",
|
||||
"username": "entaxy",
|
||||
"password": "entaxy",
|
||||
"maxConnections": "20",
|
||||
"maxSessionsPerConnection": "100"
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"nodeType": "connection",
|
||||
"uuid": "connection-uuid-3",
|
||||
"name": "entaxy-db-storage",
|
||||
"adapterName.pg": "postgresqlAdapter",
|
||||
"adapterName": "h2Adapter",
|
||||
"platform": true,
|
||||
"pathParameter": "entaxy.esb.storage",
|
||||
"properties": {},
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"nodeType": "connection",
|
||||
"uuid": "connection-uuid-4",
|
||||
"name": "entaxy-db-cache",
|
||||
"adapterName.pg": "postgresqlAdapter",
|
||||
"adapterName": "h2Adapter",
|
||||
"platform": true,
|
||||
"pathParameter": "entaxy.esb.cache",
|
||||
"properties": {},
|
||||
"options": {}
|
||||
}
|
||||
]
|
||||
}
|
@ -5,7 +5,8 @@
|
||||
"objectId": "entaxy-file",
|
||||
"properties": {
|
||||
"rootDirectory": "data/shared",
|
||||
"createResourceProvider": true
|
||||
"createResourceProvider": true,
|
||||
"isPlatform": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -13,7 +14,8 @@
|
||||
"objectId": "entaxy-file-internal",
|
||||
"properties": {
|
||||
"rootDirectory": "data/shared/.entaxy",
|
||||
"createResourceProvider": true
|
||||
"createResourceProvider": true,
|
||||
"isPlatform": true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user