initial public commit

This commit is contained in:
2021-09-06 17:46:59 +03:00
commit b744b08829
824 changed files with 91593 additions and 0 deletions

View File

@ -0,0 +1,54 @@
/*-
* ~~~~~~licensing~~~~~~
* blueprint-generator
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.blueprint.generator;
public class Blueprint {
private String name;
private byte[] body;
public Blueprint(String name, byte[] body) {
this.name = name;
this.body = body;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getBody() {
return body;
}
public void setBody(byte[] body) {
this.body = body;
}
@Override
public String toString() {
return "Blueprint{" +
"name='" + name + '\'' +
'}';
}
}

View File

@ -0,0 +1,36 @@
/*-
* ~~~~~~licensing~~~~~~
* blueprint-generator
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.blueprint.generator;
import freemarker.template.TemplateException;
import ru.entaxy.esb.system.common.exception.TemplateNotFound;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
public interface BlueprintGenerator {
Blueprint createBlueprint(URL templateUrl, String templateName, String systemName, Map<String, String> params)
throws TemplateNotFound, TemplateException, IOException;
Blueprint createBlueprint(String templateName, String systemName, Map<String, String> params)
throws TemplateNotFound, TemplateException, IOException;
}

View File

@ -0,0 +1,106 @@
/*-
* ~~~~~~licensing~~~~~~
* blueprint-generator
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.blueprint.generator;
import freemarker.cache.URLTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import ru.entaxy.esb.system.common.exception.TemplateNotFound;
import java.io.IOException;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import static freemarker.template.Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX;
public class BlueprintGeneratorImpl implements BlueprintGenerator {
private static final Log LOG = LogFactory.getLog(BlueprintGeneratorImpl.class.getName());
private static final String SYSTEM_NAME = "systemName";
private static final String FTL_EXTENSION = ".ftl";
private static final String XML_EXTENSION = ".xml";
private BundleContext bundleContext;
@Override
public Blueprint createBlueprint(URL templateUrl, String templateName, String systemName, Map<String, String> params)
throws TemplateNotFound, TemplateException, IOException {
return writeBlueprint(templateUrl, templateName, systemName, params);
}
@Override
public Blueprint createBlueprint(String templateName, String systemName, Map<String, String> params) throws TemplateNotFound,
TemplateException, IOException {
return createBlueprint(bundleContext.getBundle().getEntry("/template/"), templateName, systemName, params);
}
private Blueprint writeBlueprint(URL templateUrl, String templateName, String systemName, Map<String, String> params)
throws IOException, TemplateException, TemplateNotFound {
Template temp = getTemplateByName(templateUrl, templateName);
addSystemParam(params, systemName);
try (StringWriter writer = new StringWriter()) {
temp.process(params, writer);
return new Blueprint(templateName + "-" + systemName + XML_EXTENSION, writer.toString().getBytes());
}
}
private void addSystemParam(Map<String, String> params, String systemName) {
params.put(SYSTEM_NAME, systemName);
}
private Template getTemplateByName(URL templateUrl, String templateName) throws IOException, TemplateNotFound {
Configuration cfg = getConfiguration(templateUrl);
return cfg.getTemplate(templateName + FTL_EXTENSION);
}
private Configuration getConfiguration(URL templateUrl) throws TemplateNotFound {
Configuration freemarkerConfig = new Configuration();
freemarkerConfig.setObjectWrapper(new DefaultObjectWrapper());
freemarkerConfig.setLocalizedLookup(false);
freemarkerConfig.setTemplateLoader(getURLTemplateLoader(templateUrl));
freemarkerConfig.setInterpolationSyntax(SQUARE_BRACKET_INTERPOLATION_SYNTAX);
return freemarkerConfig;
}
private URLTemplateLoader getURLTemplateLoader(URL templateUrl) {
return new URLTemplateLoader() {
@Override
protected URL getURL(String templateName) {
try {
return new URL(templateUrl + templateName);
} catch (MalformedURLException e) {
LOG.error(e);
}
return null;
}
};
}
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
blueprint-generator
==========
Copyright (C) 2020 - 2021 EmDev LLC
==========
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~~~~~~/licensing~~~~~~
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
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="blueprintGenerator" class="ru.entaxy.esb.system.management.blueprint.generator.BlueprintGeneratorImpl"
activation="eager">
<property name="bundleContext" ref="blueprintBundleContext"/>
</bean>
<service ref="blueprintGenerator"
interface="ru.entaxy.esb.system.management.blueprint.generator.BlueprintGenerator"/>
</blueprint>

View File

@ -0,0 +1,57 @@
<#--
~~~~~~licensing~~~~~~
blueprint-generator
==========
Copyright (C) 2020 - 2021 EmDev LLC
==========
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~~~~~~/licensing~~~~~~
-->
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
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="inConnectorCollector" class="ru.entaxy.esb.system.profile.commons.InConnectorCollector"/>
<bean id="system-profile" class="ru.entaxy.esb.system.registry.systems.profile.impl.defaults.DefaultSystemProfile"
activation="eager">
<property name="systemName" value="[=systemName]"/>
<property name="profileOutput" ref="profileOutput"/>
</bean>
<bean id="profileOutput" class="ru.entaxy.esb.system.profile.commons.profile_output.ProfileOutputImpl"
activation="eager">
<property name="systemName" value="[=systemName]"/>
</bean>
<service activation="eager" auto-export="interfaces" ref="system-profile"/>
<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
</bean>
<camelContext id="profile-[=systemName]" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="direct-vm:profile-[=systemName]-enter-point"/>
<log message="Message ${headers} send to bridge" loggingLevel="TRACE"/>
<toD uri="permission:checkSystemAccessException?objectId=${headers.X-SystemId}&amp;subjectId=[=systemName]"/>
<setHeader name="NTX_DestinationPointAfterBridge">
<simple>system:[=systemName]</simple>
</setHeader>
<to uri="jms:queue:entaxy.local.out.[=origin]"/>
</route>
</camelContext>
</blueprint>

View File

@ -0,0 +1,66 @@
<#--
~~~~~~licensing~~~~~~
blueprint-generator
==========
Copyright (C) 2020 - 2021 EmDev LLC
==========
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~~~~~~/licensing~~~~~~
-->
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
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">
<reference id="entaxy-broker" interface="org.apache.camel.Component"
filter="(connection.name=entaxy-broker)"/>
<camelContext id="route-[=systemName]" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="direct-vm:profile-[=systemName]-exit-point"/>
<log message="Message ${headers} send to route" loggingLevel="TRACE"/>
<when>
<simple>${headers.ENTAXY_Destination} == 'nsi'
&amp;&amp; ${headers.ENTAXY_DestinationType} == null
</simple>
<setHeader name="NTX_NSI_Answer">
<simple>true</simple>
</setHeader>
<to uri="entaxy-broker:queue:entaxy.nsi.entry.point?exchangePattern=InOnly"/>
</when>
<choice>
<when>
<simple>${headers.ENTAXY_DestinationType} == 'system.name'</simple>
<toD uri="system:${headers.ENTAXY_Destination}"/>
</when>
<when>
<simple>${headers.ENTAXY_DestinationType} == 'system-group.name'</simple>
<toD uri="system-group:${headers.ENTAXY_Destination}"/>
</when>
<when>
<simple>${headers.ENTAXY_DestinationType} == 'queue.name'</simple>
<toD uri="entaxy-broker:queue:${headers.ENTAXY_Destination}"/>
</when>
<when>
<simple>${headers.ENTAXY_DestinationType} == 'topic.name'</simple>
<toD uri="entaxy-broker:topic:${headers.ENTAXY_Destination}"/>
</when>
<otherwise>
<toD uri="system:${headers.ENTAXY_Destination}"/>
</otherwise>
</choice>
</route>
</camelContext>
</blueprint>

View File

@ -0,0 +1,93 @@
<#--
~~~~~~licensing~~~~~~
blueprint-generator
==========
Copyright (C) 2020 - 2021 EmDev LLC
==========
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
~~~~~~/licensing~~~~~~
-->
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
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">
<reference-list id="outConnector"
interface="ru.entaxy.esb.system.profile.commons.connectors.out.OutConnector"
filter="(systemName=[=systemName])" availability="optional">
<reference-listener ref="profileOutput"
bind-method="register" unbind-method="unregister"/>
</reference-list>
<reference-list id="inConnector"
interface="ru.entaxy.esb.system.profile.commons.connectors.in.InConnector"
filter="(systemName=[=systemName])" availability="optional">
<reference-listener ref="inConnectorCollector"
bind-method="register" unbind-method="unregister"/>
</reference-list>
<bean id="inConnectorCollector" class="ru.entaxy.esb.system.profile.commons.InConnectorCollector"/>
<bean id="system-profile" class="ru.entaxy.esb.system.registry.systems.profile.impl.defaults.DefaultSystemProfile"
activation="eager">
<property name="systemName" value="[=systemName]"/>
<property name="profileOutput" ref="profileOutput"/>
<property name="inConnectorCollector" ref="inConnectorCollector"/>
</bean>
<bean id="profileOutput" class="ru.entaxy.esb.system.profile.commons.profile_output.ProfileOutputImpl"
activation="eager">
<property name="systemName" value="[=systemName]"/>
</bean>
<service activation="eager" auto-export="interfaces" ref="system-profile"/>
<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
</bean>
<camelContext id="profile-[=systemName]" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="direct-vm:profile-[=systemName]-exit-dispatcher"/>
<log message="Message ${headers} send to profile dispatcher" loggingLevel="TRACE"/>
<choice>
<when>
<simple>${headers.NTX_NextPoint} != null</simple>
<setProperty name="NTX_Tmp">
<simple>${headers.NTX_NextPoint}</simple>
</setProperty>
<removeHeader headerName="NTX_NextPoint"/>
<toD uri="${exchangeProperty.NTX_Tmp}"/>
</when>
<otherwise>
<to uri="direct-vm:profile-[=systemName]-exit-point"/>
</otherwise>
</choice>
</route>
<route>
<from uri="direct-vm:profile-[=systemName]-enter-point"/>
<log message="Message ${headers} send to profile output" loggingLevel="TRACE"/>
<choice>
<when>
<simple>${headers.NTX_Origin} == null</simple>
<toD uri="permission:checkSystemAccessException?objectId=${headers.X-SystemId}&amp;subjectId=[=systemName]"/>
</when>
</choice>
<to uri="bean:profileOutput?method=sendTo"/>
</route>
</camelContext>
</blueprint>