Author: shijh
Date: Wed Oct 11 14:06:31 2017
New Revision: 1811826
URL: http://svn.apache.org/viewvc?rev=1811826&view=rev
Log:
Implemented: Add a new plugin for the redis
(OFBIZ-9829)
Thanks Haipeng for this wonderful contribution.
Added:
ofbiz/ofbiz-plugins/trunk/redis/
ofbiz/ofbiz-plugins/trunk/redis/README.md (with props)
ofbiz/ofbiz-plugins/trunk/redis/build.gradle (with props)
ofbiz/ofbiz-plugins/trunk/redis/config/
ofbiz/ofbiz-plugins/trunk/redis/config/redis.json
ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties (with props)
ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/
ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy (with
props)
ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml (with props)
ofbiz/ofbiz-plugins/trunk/redis/servicedef/
ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml (with props)
ofbiz/ofbiz-plugins/trunk/redis/src/
ofbiz/ofbiz-plugins/trunk/redis/src/main/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
(with props)
Added: ofbiz/ofbiz-plugins/trunk/redis/README.md
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/README.md?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/README.md (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/README.md Wed Oct 11 14:06:31 2017
@@ -0,0 +1,19 @@
+<img src="http://ofbiz.apache.org/images/OFBiz-logoV3-apache.png" alt="Apache
OFBiz" />
+
+<img src="https://redis.io/images/redis.png" width="150px"/>
+
+# Redis component
+This OFBiz component leverages Redis capabilities. This component is developed
on Redis 3.2.x and should be compatible with the latest Redis 4.0.x.
+
+If redis.encrypt.password in redis.properties is set, the values stored in
Redis will be encrypted.
+
+You can get more info on Redis from https://redis.io/.
+
+
+# Codis
+This component is also compatible with Codis, you can get Codis from
https://github.com/CodisLabs/codis.
+To use Codis, simply set "address" to Codis proxy port, i.e. 19000 in
redis.json:
+"address": "redis://127.0.0.1:19000"
+
+# Redisson
+Redisson is a Java client of Redis used by this component. It's Apache License
V2.0. You can get Redisson from https://github.com/redisson/redisson.
Propchange: ofbiz/ofbiz-plugins/trunk/redis/README.md
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/README.md
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/README.md
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/ofbiz-plugins/trunk/redis/build.gradle
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/build.gradle?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/build.gradle (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/build.gradle Wed Oct 11 14:06:31 2017
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+dependencies {
+ pluginLibsCompile 'org.redisson:redisson:3.4.4'
+}
Propchange: ofbiz/ofbiz-plugins/trunk/redis/build.gradle
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/build.gradle
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/build.gradle
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/ofbiz-plugins/trunk/redis/config/redis.json
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/config/redis.json?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/config/redis.json (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/config/redis.json Wed Oct 11 14:06:31 2017
@@ -0,0 +1,27 @@
+{
+ "singleServerConfig":{
+ "idleConnectionTimeout":10000,
+ "pingTimeout":1000,
+ "connectTimeout":10000,
+ "timeout":3000,
+ "retryAttempts":3,
+ "retryInterval":1500,
+ "reconnectionTimeout":3000,
+ "failedAttempts":3,
+ "password": null,
+ "subscriptionsPerConnection":5,
+ "clientName":null,
+ "address": "redis://127.0.0.1:6379",
+ "subscriptionConnectionMinimumIdleSize":1,
+ "subscriptionConnectionPoolSize":50,
+ "connectionMinimumIdleSize":10,
+ "connectionPoolSize":64,
+ "database":0,
+ "dnsMonitoring":false,
+ "dnsMonitoringInterval":5000
+ },
+ "threads":0,
+ "nettyThreads":0,
+ "codec":null,
+ "useLinuxNativeEpoll":false
+}
Added: ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties Wed Oct 11 14:06:31
2017
@@ -0,0 +1,21 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+###############################################################################
+
+redis.encrypt.password=passwordpasswordpasswordpasswordpasswordpasswordpasswordpasswordpassword
+
Propchange: ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/config/redis.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy Wed Oct
11 14:06:31 2017
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.security.Key
+
+import org.apache.ofbiz.base.crypto.DesCrypt
+import org.apache.ofbiz.base.lang.JSON
+import org.apache.ofbiz.base.util.Debug
+import org.apache.ofbiz.base.util.UtilValidate
+import org.apache.ofbiz.entity.util.EntityUtilProperties
+import org.apache.ofbiz.redis.RedisClient
+import org.apache.ofbiz.service.ServiceUtil
+import org.redisson.api.RBinaryStream
+import org.redisson.api.RedissonClient
+
+public Map<String,Object> getRedisInfo(){
+ Map<String, Object> result = ServiceUtil.returnSuccess();
+ def redisKey = (String) context.get("redisKey");
+ def redisValue = [:];
+ RedissonClient syncClient = RedisClient.getSyncInstance();
+ RBinaryStream stream = syncClient.getBinaryStream(redisKey);
+ String password = EntityUtilProperties.getPropertyValue("redis",
"redis.encrypt.password", delegator);
+ try {
+ if(UtilValidate.isNotEmpty(stream)){
+ def bytes = stream.get();
+ if(bytes != null){
+ Key decryptKey = DesCrypt.getDesKey(password.getBytes("UTF-8"));
+ byte[] decrypts = DesCrypt.decrypt(decryptKey, bytes);
+ String content = new String(decrypts, "UTF-8");
+ if(UtilValidate.isNotEmpty(content)){
+ redisValue = JSON.from(content).toObject(Map.class);
+ }
+ }
+ }
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ result.put("redisValue", redisValue);
+ return result;
+}
+
+public Map<String,Object> setRedisInfo(){
+ Map<String, Object> result = ServiceUtil.returnSuccess();
+ def redisKey = (String) context.get("redisKey");
+ def redisValue = (Map) context.get("redisValue");
+ if(UtilValidate.isNotEmpty(redisValue)){
+ Iterator iterator = redisValue.keySet().iterator();
+ while(iterator.hasNext()){
+ String k = iterator.next();
+ if(UtilValidate.isEmpty(redisValue[k])){
+ iterator.remove();
+ }
+ }
+ }
+ RedissonClient syncClient = RedisClient.getSyncInstance();
+ RBinaryStream stream = syncClient.getBinaryStream(redisKey);
+ String password = EntityUtilProperties.getPropertyValue("redis",
"redis.encrypt.password", delegator);
+ try {
+ if(UtilValidate.isNotEmpty(stream)){
+ def content = JSON.from(redisValue ?: "").toString();
+ Key encryptKey = DesCrypt.getDesKey(password.getBytes("UTF-8"));
+ byte[] encryptContent = DesCrypt.encrypt(encryptKey,
content.getBytes("UTF-8"));
+ stream.set(encryptContent);
+ }
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ return result;
+}
+
+public Map<String,Object> deleteRedisInfo(){
+ Map<String, Object> result = ServiceUtil.returnSuccess();
+ def redisKey = (String) context.get("redisKey");
+ RedissonClient syncClient = RedisClient.getSyncInstance();
+ RBinaryStream stream = syncClient.getBinaryStream(redisKey);
+ try {
+ if(UtilValidate.isNotEmpty(stream)){
+ stream.delete();
+ }
+ } catch (Exception e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ return result;
+}
\ No newline at end of file
Propchange: ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/groovyScripts/RedisServices.groovy
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml Wed Oct 11 14:06:31 2017
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<ofbiz-component name="redis"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
+
+ <resource-loader name="main" type="component" />
+
+ <service-resource type="model" loader="main"
location="servicedef/services.xml"/>
+
+</ofbiz-component>
\ No newline at end of file
Propchange: ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/ofbiz-component.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml?rev=1811826&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml (added)
+++ ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml Wed Oct 11 14:06:31
2017
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd">
+ <description>Redis Services</description>
+
+ <service name="getRedisInfo" engine="groovy"
+ location="component://redis/groovyScripts/RedisServices.groovy"
invoke="getRedisInfo"
+ auth="true">
+ <attribute name="redisKey" type="String" mode="IN" optional="false" />
+ <attribute name="redisValue" type="Map" mode="OUT" optional="true" />
+ </service>
+
+ <service name="setRedisInfo" engine="groovy"
+ location="component://redis/groovyScripts/RedisServices.groovy"
invoke="setRedisInfo"
+ auth="true">
+ <attribute name="redisKey" type="String" mode="IN" optional="false" />
+ <attribute name="redisValue" type="Map" mode="IN" optional="true" />
+ </service>
+
+ <service name="deleteRedisInfo" engine="groovy"
+ location="component://redis/groovyScripts/RedisServices.groovy"
invoke="deleteRedisInfo"
+ auth="true">
+ <attribute name="redisKey" type="String" mode="IN" optional="false" />
+ </service>
+
+</services>
\ No newline at end of file
Propchange: ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-plugins/trunk/redis/servicedef/services.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java?rev=1811826&view=auto
==============================================================================
---
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
(added)
+++
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
Wed Oct 11 14:06:31 2017
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+
*******************************************************************************/
+package org.apache.ofbiz.redis;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.ofbiz.base.location.FlexibleLocation;
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilValidate;
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.api.RedissonReactiveClient;
+import org.redisson.config.Config;
+
+public class RedisClient {
+
+ public static final String module = RedisClient.class.getName();
+ protected static final String REDIS_CONFIG_JSON =
"component://redis/config/redis.json";
+ private static RedissonClient redisSyncClient = null;
+ private static RedissonReactiveClient redisASyncClient = null;
+
+ public static RedissonClient getSyncInstance() {
+ if (UtilValidate.isEmpty(redisSyncClient)) {
+ try {
+ URL fileUrl =
FlexibleLocation.resolveLocation(REDIS_CONFIG_JSON);
+ Debug.logInfo("Redis initializing configuration from: " +
fileUrl, module);
+ Config config = Config.fromJSON(fileUrl);
+ redisSyncClient = Redisson.create(config);
+ } catch (IOException e) {
+ Debug.logError("Error while initializing configuration of
Redis from " + REDIS_CONFIG_JSON, module);
+ Debug.logError(e, module);
+ }
+ }
+ return redisSyncClient;
+ }
+
+ public static RedissonReactiveClient getASyncInstance() {
+ if (UtilValidate.isEmpty(redisASyncClient)) {
+ try {
+ URL fileUrl =
FlexibleLocation.resolveLocation(REDIS_CONFIG_JSON);
+ Debug.logInfo("Redis initializing configuration from: " +
fileUrl, module);
+ Config config = Config.fromJSON(fileUrl);
+ redisASyncClient = Redisson.createReactive(config);
+ } catch (IOException e) {
+ Debug.logError("Error while initializing configuration of
Redis from " + REDIS_CONFIG_JSON, module);
+ Debug.logError(e, module);
+ }
+ }
+ return redisASyncClient;
+ }
+}
\ No newline at end of file
Propchange:
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/ofbiz-plugins/trunk/redis/src/main/java/org/apache/ofbiz/redis/RedisClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain