ENTAXY-374 release 1.8.2

This commit is contained in:
2022-08-23 13:40:11 +03:00
parent b68642f81c
commit 1061b96c7e
616 changed files with 60896 additions and 3202 deletions

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
<artifactId>initializer</artifactId>
<version>1.8.1</version>
<version>1.8.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -30,7 +30,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Entaxy-Initializer-Class>ru.entaxy.esb.platform.runtime.core.initializer.connection.ConnectionInitializer?id=connections&amp;repeat=true&amp;depends-on=core,datasources</Entaxy-Initializer-Class>
<Entaxy-Initializer-Class>ru.entaxy.esb.platform.runtime.core.initializer.connection.ConnectionInitializer?id=connections&amp;repeat=true&amp;retries=10&amp;interval=2000&amp;depends-on=core,datasources</Entaxy-Initializer-Class>
</instructions>
</configuration>
</plugin>
@ -51,6 +51,11 @@
<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>
</artifacts>
</configuration>
</execution>
@ -84,5 +89,19 @@
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.core.object-producing
</groupId>
<artifactId>object-producer-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.core.object-producing
</groupId>
<artifactId>object-producer-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -23,16 +23,28 @@ import org.osgi.framework.BundleContext;
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.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.artifact.service.ArtifactService;
import ru.entaxy.platform.core.producer.api.EntaxyProducerService;
import ru.entaxy.platform.core.producer.api.EntaxyProducerUtils;
import ru.entaxy.platform.core.producer.executor.objectmodel.ObjectModel;
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.stream.Collectors;
public class ConnectionInitializer extends AbstractInitializer {
@ -41,22 +53,49 @@ public class ConnectionInitializer extends AbstractInitializer {
private static final String JSON_FILE_NAME = "entaxy-platform-connections.json";
private static final String jsonBundlePath = "/connection/" + JSON_FILE_NAME;
private static final String JSON_FILE_PATH = System.getProperty("karaf.etc")
private static final String INIT_FILES_PATH = System.getProperty("karaf.etc")
+ File.separator
+ "init"
+ "init";
private static final String JSON_FILE_PATH = INIT_FILES_PATH
+ File.separator
+ JSON_FILE_NAME;
private EntaxyProducerService entaxyProducerService;
@Override
public void init() throws InitializerException {
log.info("ConnectionInitializer started");
log.info("-->> " + JSON_FILE_PATH);
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) {
e.printStackTrace();
log.error("Error initializing connections from " + JSON_FILE_PATH, e);
throw new InitializerException(this, "Can't create platform connections", "", e);
}
}
@ -64,16 +103,147 @@ public class ConnectionInitializer extends AbstractInitializer {
@Override
public void reinit() throws InitializerException {
// TODO Auto-generated method stub
}
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;
}
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()
.any()
.command("add-config")
.command("pre-generate")
.set(EntaxyProducerService.INSTRUCTIONS.PRINT_OUTPUT, true)
.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", "");
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);
String instructions = builder
.getInstructionsString();
entaxyProducerService.produce(jsonData, instructions);
}
}
}
private void initPlatformConnections(BundleContext bundleContext) throws Exception {
chackAndPrepareFile(bundleContext);
checkAndPrepareFile(bundleContext);
String json = getJsonAsString(bundleContext);
FileUtils.FileHelper helper = new FileUtils.FileHelper(JSON_FILE_PATH);
if (!helper.isReadable()) {
// TODO throw exception
log.error("Platform connectons file {} is not readable", JSON_FILE_PATH);
log.error("Platform connections file {} is not readable", JSON_FILE_PATH);
return;
}
@ -89,7 +259,7 @@ public class ConnectionInitializer extends AbstractInitializer {
helper.updateMd5();
} else {
log.info("File is not changed, install/check connections");
// we need to create if absent connectoins with old timestamp
// we need to create if absent connections with old timestamp
// ConnectionManagerUtil.getService().createAndInstallConnections(json);
ConnectionManagerUtil.getService().checkInstallConnections(json, helper.getTimestamp());
}
@ -97,7 +267,7 @@ public class ConnectionInitializer extends AbstractInitializer {
}
private void chackAndPrepareFile(BundleContext context) throws IOException {
private void checkAndPrepareFile(BundleContext context) throws IOException {
File f = new File(JSON_FILE_PATH);
if (!f.exists()) {
FileUtils.string2file(getJsonAsString(context), JSON_FILE_PATH);

View File

@ -1,19 +1,5 @@
{
"connections": [
{
"nodeType": "connection",
"uuid": "connection-uuid-1",
"name": "entaxy-file",
"adapterName": "fileAdapter",
"platform": true,
"pathParameter": "data/shared",
"properties": {},
"options": {
"noop": true,
"fileName": "default.txt",
"allowNullBody": "true"
}
},
{
"nodeType": "connection",
"uuid": "connection-uuid-2",
@ -34,7 +20,8 @@
"nodeType": "connection",
"uuid": "connection-uuid-3",
"name": "entaxy-db-storage",
"adapterName": "postgresqlAdapter",
"adapterName.pg": "postgresqlAdapter",
"adapterName": "h2Adapter",
"platform": true,
"pathParameter": "entaxy.esb.storage",
"properties": {},
@ -44,7 +31,8 @@
"nodeType": "connection",
"uuid": "connection-uuid-4",
"name": "entaxy-db-cache",
"adapterName": "postgresqlAdapter",
"adapterName.pg": "postgresqlAdapter",
"adapterName": "h2Adapter",
"platform": true,
"pathParameter": "entaxy.esb.cache",
"properties": {},

View File

@ -0,0 +1,29 @@
{
"connections": [
{
"factoryId": "file-adapter",
"objectId": "entaxy-file",
"properties": {
"rootDirectory": "data/shared"
}
},
{
"factoryId": "file-adapter",
"objectId": "entaxy-file-internal",
"properties": {
"__parentConnection": {
"isRef": true,
"type": "entaxy.runtime.connection",
"required": true,
"isRefByValueOnly": true,
"refField": "rootDirectory",
"targetId": "entaxy-file"
},
"rootDirectory": {
"isCalculated": true,
"expression": "${__parentConnection}/.entaxy"
}
}
}
]
}

View File

@ -1,54 +0,0 @@
{
"connections": [
{
"nodeType": "connection",
"uuid": "connection-uuid-1",
"name": "entaxy-file",
"adapterName": "fileAdapter",
"platform": true,
"pathParameter": "data/shared",
"properties": {},
"options": {
"noop": true,
"fileName": "default.txt",
"allowNullBody": "true"
}
},
{
"nodeType": "connection",
"uuid": "connection-uuid-2",
"name": "entaxy-broker",
"adapterName": "artemisAmqpAdapter",
"platform": true,
"pathParameter": "queue:entaxy.default",
"properties": {
"url": "amqp://localhost:5672",
"username": "entaxy",
"password": "entaxy"
},
"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": {}
}
]
}