ENTAXY-248 release 1.8.1

This commit is contained in:
2022-02-28 15:20:38 +03:00
parent 4d274c4fcc
commit c826adf1db
1958 changed files with 195926 additions and 10280 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
<artifactId>management</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.core.management</groupId>
@ -22,6 +22,9 @@
ru.entaxy.esb.platform.runtime.core.management.connection.api,
ru.entaxy.esb.platform.runtime.core.management.connection.util
</bundle.osgi.export.pkg>
<!-- bundle.osgi.private.pkg>
ru.entaxy.esb.platform.runtime.core.management.connection.impl
</bundle.osgi.private.pkg -->
</properties>
<dependencies>
@ -30,6 +33,23 @@
<artifactId>connection-producer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
<artifactId>artifact-management</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base.connecting
</groupId>
<artifactId>connection</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -24,5 +24,10 @@ import ru.entaxy.esb.platform.runtime.base.connecting.connection.Connection;
import java.util.List;
public interface ConnectionManager {
/*
@Deprecated
public List<Connection> createAndInstallConnections(String json) throws Exception;
*/
public List<Connection> installUpdateConnections(String json, String newTimestamp) throws Exception;
public List<Connection> checkInstallConnections(String json, String timestamp) throws Exception;
}

View File

@ -19,39 +19,157 @@
*/
package ru.entaxy.esb.platform.runtime.core.management.connection.impl;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.runtime.base.connecting.connection.Connection;
import ru.entaxy.esb.platform.runtime.base.connecting.connection.util.ConnectionUtil;
import ru.entaxy.esb.platform.runtime.base.connecting.producer.connection.util.ConnectionProducerUtil;
import ru.entaxy.esb.platform.runtime.core.management.connection.api.ConnectionManager;
import ru.entaxy.esb.system.management.blueprint.generator.Blueprint;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ru.entaxy.esb.platform.runtime.base.connecting.connection.Connection;
import ru.entaxy.esb.platform.runtime.base.connecting.connection.util.ConnectionUtil;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;
import ru.entaxy.esb.platform.runtime.base.connecting.producer.connection.util.ConnectionProducerUtil;
import ru.entaxy.esb.platform.runtime.core.management.connection.api.ConnectionManager;
import ru.entaxy.platform.core.artifact.Artifact;
import ru.entaxy.platform.core.artifact.Artifacts;
import ru.entaxy.platform.core.artifact.DeployedArtifact;
import ru.entaxy.platform.core.artifact.installer.builder.Installer;
import ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller;
import ru.entaxy.platform.core.artifact.service.ArtifactService;
public class ConnectionManagerImpl implements ConnectionManager {
private static final String CONNECTION = "connection";
private static final String GROUP_ID = "ru.entaxy.esb.";
/*
private static final String GROUP_ID = "ru.entaxy.esb.";
private static final String XML_EXTENSION = "xml";
private static final String LOCAL_FILE_REPOSITORY = "data" + File.separator + "local-repository";
*/
protected ArtifactService artifactService;
private static final Logger log = LoggerFactory.getLogger(ConnectionManagerImpl.class);
@Override
public List<Connection> checkInstallConnections(String json, String timestamp) throws Exception {
List<Connection> connections = parseConnections(json);
for (Connection connection: connections) {
Artifact artifact = createArtifactForConnection(connection);
artifact.getCoordinates().timestamped(timestamp);
DeployedArtifact deployed;
if (connection.isPlatform()) {
deployed = artifactService.deployLocal(artifact);
} else {
deployed = artifactService.deployShared(artifact);
}
log.info("Artifact [{}] deployed to location [{}]", artifact.getCoordinates(), deployed.getLocation());
Installer<?> installer = connection.isPlatform()
?artifactService.installers().local()
:artifactService.installers().cluster();
// TODO add support for other types
// assume artifact is blueprint
installer
.artifact(deployed)
.typed(BlueprintInstaller.class)
.installOnlyIfMissing()
.start()
.install();
}
return connections;
}
@Override
public List<Connection> installUpdateConnections(String json, String newTimestamp) throws Exception {
List<Connection> connections = parseConnections(json);
for (Connection connection: connections) {
Artifact artifact = createArtifactForConnection(connection);
artifact.getCoordinates().timestamped(newTimestamp);
DeployedArtifact deployed;
if (connection.isPlatform()) {
deployed = artifactService.deployLocal(artifact);
} else {
deployed = artifactService.deployShared(artifact);
}
log.info("Artifact [{}] deployed to location [{}]", artifact.getCoordinates(), deployed.getLocation());
Installer<?> installer = connection.isPlatform()
?artifactService.installers().local()
:artifactService.installers().cluster();
// TODO add support for other types
// assume artifact is blueprint
installer
.artifact(deployed)
.typed(BlueprintInstaller.class)
.update(deployed
.getArtifact().getProperties()
.getOrDefault(Constants.BUNDLE_SYMBOLICNAME, "")
.toString())
.start()
.install();
}
return connections;
}
protected List<Connection> parseConnections(String json){
List<Connection> connectionList = new ArrayList<>();
JsonElement jsonElement = getJsonElement(json);
List<JsonObject> jsonConnectionList = getJsonConnectionList(jsonElement);
for (JsonObject jsonConnection : jsonConnectionList) {
connectionList.add(ConnectionProducerUtil.createConnection(jsonConnection));
}
return connectionList;
}
protected List<Artifact> createArtifactsForConnections(List<Connection> connections) throws Exception{
List<Artifact> artifacts = new ArrayList<>();
for (Connection connection: connections)
artifacts.add(createArtifactForConnection(connection));
return artifacts;
}
protected Artifact createArtifactForConnection(Connection connection) throws Exception{
Generated result = ConnectionUtil.getInit(connection);
String type = CONNECTION;
String name = connection.getName();
String version = "1.0.0";
// TODO add support for other artifact types
if (Generated.GENERATED_TYPE_BLUEPRINT.equals(result.getType())) {
Artifact artifact = Artifacts.fromGenerated(result);
artifact.getCoordinates()
.timestampedVersion(version)
.groupId(Artifact.DEFAULT_RUNTIME_GROUP_ID + "." + type)
.artifactId(type + "-" + name);
artifact.provideCapability(artifact.getCoordinates().getGroupId())
.attribute("name",connection.getName())
.attribute("platform", connection.isPlatform()?"true":"false");
log.info("Artifact of category [{}] is prepared: [{}]", artifact.getCategory(), artifact.getCoordinates());
return artifact;
} else {
log.error("Generated result for connection [{}] is of type '{}' while expected '{}'"
, connection.getName()
, result.getType()
, Generated.GENERATED_TYPE_BLUEPRINT);
return null;
}
}
/*
public List<Connection> createAndInstallConnections(String json) throws Exception {
return createConnections(json, false, true);
}
@ -69,7 +187,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
}
return connectionList;
}
*/
private JsonElement getJsonElement(String json) {
return new Gson().fromJson(json, JsonElement.class);
}
@ -95,7 +213,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
return jsonConnectionList;
}
/*
private Connection createConnection(JsonObject jsonConnection, boolean register, boolean install) {
Connection connection = ConnectionProducerUtil.createConnection(jsonConnection);
if (register) {
@ -115,20 +233,64 @@ public class ConnectionManagerImpl implements ConnectionManager {
String name = connection.getName();
String type = CONNECTION;
String version = String.valueOf(1.0);
Blueprint blueprint = ConnectionUtil.getInit(connection);
log.debug(new String(blueprint.getBody(), Charset.defaultCharset()));
Generated result = ConnectionUtil.getInit(connection);
// TODO: pass the Generated to artifact management
if (Generated.GENERATED_TYPE_BLUEPRINT.equals(result.getType())) {
Artifact artifact = Artifacts.fromGenerated(result);
artifact.getCoordinates()
.timestampedVersion(version)
.groupId(Artifact.DEFAULT_RUNTIME_GROUP_ID + "." + type)
.artifactId(type + "-" + name);
log.info("Artifact of category [{}] is prepared: [{}]", artifact.getCategory(), artifact.getCoordinates());
// return bundleManager.installAndStartBundle(name, type, version, blueprint);
// Local bundle install needed instead of cellar install to cluster
String bundleUrl = deployBlueprint(GROUP_ID + type, type + "-" + name,
version, XML_EXTENSION, blueprint.getBody());
Bundle bundle = installAndStartBundle(bundleUrl);
return bundle;
// TODO: 09.07.2021 callback for webeditor needed
DeployedArtifact deployedArtifact = artifactService.deployLocal(artifact);
log.info("Artifact [{}] deployed to location [{}]", artifact.getCoordinates(), deployedArtifact.getLocation());
InstallationResult installationResult = this.artifactService
.installers()
.cluster()
.artifact(deployedArtifact)
.typed(BlueprintInstaller.class)
.start()
.update(deployedArtifact.getArtifact().getProperties().getOrDefault(Constants.BUNDLE_SYMBOLICNAME, "").toString())
.install();
*/
/*
log.debug(new String(result.getObject().toString().getBytes(), Charset.defaultCharset()));
log.info("Blueprint is generated for connection [{}]", connection.getName());
// Local bundle install needed instead of cellar install to cluster
String bundleUrl = deployBlueprint(GROUP_ID + type, type + "-" + name,
version, XML_EXTENSION, result.getObject().toString().getBytes());
Bundle bundle = installAndStartBundle(bundleUrl);
*/
/* if (installationResult.isSuccessful()) {
if (installationResult.getObject() != null)
if (installationResult.getObject() instanceof Bundle) {
Bundle bundle = (Bundle)installationResult.getObject();
log.info("Bundle [{}] successfully {}'d from artifact [{}]"
, bundle.getBundleId()
, installationResult.getResult().name()
, deployedArtifact.getArtifact().getCoordinates());
return bundle;
}
}
return null;
// TODO: 09.07.2021 callback for webeditor needed
} else {
log.error("Generated result for connection [{}] is of type '{}' while expected '{}'"
, connection.getName()
, result.getType()
, Generated.GENERATED_TYPE_BLUEPRINT);
return null;
}
}
// ru.entaxy.esb.system.deployer.file.FileSystemRepositoryImpl.deployBlueprint method copy
@Deprecated
public String deployBlueprint(String groupId, String name, String version,
String extension, byte[] data) throws Exception {
Path path = preparePath(groupId, name, version, extension);
@ -139,13 +301,15 @@ public class ConnectionManagerImpl implements ConnectionManager {
return "blueprint:file:" + path.normalize();
}
@Deprecated
private Path preparePath(String groupId, String name, String version, String extension) {
String gpoupIdPath = groupId.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
String fileName = name + "-" + version + "." + extension;
Path path = Paths.get(LOCAL_FILE_REPOSITORY, gpoupIdPath, fileName);
return path;
}
@Deprecated
private Bundle installAndStartBundle(String bundleUrl) {
BundleContext bundleContext = FrameworkUtil.getBundle(ConnectionManagerImpl.class).getBundleContext();
Bundle bundle = null;
@ -161,6 +325,9 @@ public class ConnectionManagerImpl implements ConnectionManager {
}
return bundle;
}
*/
public void setArtifactService(ArtifactService artifactService) {
this.artifactService = artifactService;
}
}

View File

@ -25,6 +25,7 @@ import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import ru.entaxy.esb.platform.runtime.core.management.connection.api.ConnectionManager;
import ru.entaxy.platform.base.support.osgi.OSGIUtils;
public class ConnectionManagerUtil {
@ -35,9 +36,21 @@ public class ConnectionManagerUtil {
// get our own bundleContext
BundleContext bundleContext = FrameworkUtil.getBundle(ConnectionManagerUtil.class).getBundleContext();
try {
return OSGIUtils.services().bundleContext(bundleContext)
.waitService(2000)
.ofClass(ConnectionManager.class)
.<ConnectionManager>get();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return null;
}
// found an issue: service is not returned 'cause the initializers start earlier than
// Karaf publishes service
// So we should use tracker here to be sure the service is active
/*
if (tracker == null) {
tracker = new ServiceTracker(bundleContext, ConnectionManager.class, null);
tracker.open();
@ -47,10 +60,12 @@ public class ConnectionManagerUtil {
} catch (Exception e) {
// TODO: handle exception
}
*/
/*
ServiceReference<ConnectionManager> connectionManagerServiceReference =
tracker.getServiceReference();
// bundleContext.getServiceReference(ConnectionManager.class);
return bundleContext.getService(connectionManagerServiceReference);
*/
}
}

View File

@ -23,7 +23,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="connectionManager" class="ru.entaxy.esb.platform.runtime.core.management.connection.impl.ConnectionManagerImpl"/>
<reference id="artifactService" interface="ru.entaxy.platform.core.artifact.service.ArtifactService" availability="mandatory"></reference>
<bean id="connectionManager" class="ru.entaxy.esb.platform.runtime.core.management.connection.impl.ConnectionManagerImpl">
<property name="artifactService" ref="artifactService"></property>
</bean>
<service ref="connectionManager" interface="ru.entaxy.esb.platform.runtime.core.management.connection.api.ConnectionManager"/>