瀏覽代碼

refactor(plugin): move all image functions to one plugin

ngjaying 4 年之前
父節點
當前提交
302bb29f83

+ 1 - 1
.ci/Dockerfile-plugins

@@ -31,7 +31,7 @@ RUN set -e -u -x \
            && go build --buildmode=plugin -tags plugins -o plugins/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so plugins/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go \
            ;; \
          * ) \
-           go build --buildmode=plugin -o plugins/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so plugins/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME.go \
+           go build --buildmode=plugin -o plugins/$PLUGIN_TYPE/$PLUGIN_NAME/$PLUGIN_NAME@$VERSION.so plugins/$PLUGIN_TYPE/$PLUGIN_NAME/*.go \
            ;; \
        esac \
     && if [ -f "etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml" ]; then cp etc/$PLUGIN_TYPE/$PLUGIN_NAME.yaml plugins/$PLUGIN_TYPE/$PLUGIN_NAME; fi \

+ 7 - 3
.github/workflows/build_packages.yaml

@@ -68,8 +68,7 @@ jobs:
                 - functions/accumulateWordCount
                 - functions/countPlusOne
                 - functions/echo
-                - functions/thumbnail
-                - functions/resize
+                - functions/image
 
         steps:
         - uses: actions/checkout@v1
@@ -93,7 +92,7 @@ jobs:
             docker run --rm --privileged tonistiigi/binfmt --install all
         - name: build docker image
           run: make docker -j4
-        - name: buiild debian plugins
+        - name: build debian plugins
           env:
             PLUGIN: ${{ matrix.plugin }}
           run: make ${PLUGIN}
@@ -117,6 +116,11 @@ jobs:
                     ${ip_address}:9081/plugins/${plugin_type} \
                     -X POST \
                     -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\", \"shellParas\": [\"2.0.3.1\"]}"
+                elif [ "${plugin_name}" = "image" ]; then
+                     curl \
+                     ${ip_address}:9081/plugins/${plugin_type} \
+                     -X POST \
+                     -d "{\"name\":\"${plugin_name}\", \"file\":\"file:///var/plugins/${os}/${plugin_type}/${plugin_name}_amd64.zip\", \"functions\": [\"resize\",\"thumbnail\"]}"
                 else
                     curl \
                     ${ip_address}:9081/plugins/${plugin_type} \

+ 1 - 0
.github/workflows/run_fvt_tests.yaml

@@ -43,6 +43,7 @@ jobs:
             sudo apt update && sudo apt install pkg-config libczmq-dev -y
             make build_with_edgex
             go build --buildmode=plugin -o plugins/sources/Zmq.so plugins/sources/zmq/zmq.go
+            go build --buildmode=plugin -o plugins/functions/Image.so plugins/functions/image/*.go
         - name: run edgex && emqx && kuiper
           run: |
             sudo ./fvt_scripts/setup_env.sh

+ 1 - 2
Makefile

@@ -177,8 +177,7 @@ PLUGINS := sinks/file \
 	sources/zmq \
 	functions/accumulateWordCount \
 	functions/countPlusOne \
-	functions/thumbnail\
-	functions/resize\
+	functions/image\
 	functions/echo
 
 .PHONY: plugins sinks/tdengine $(PLUGINS)

+ 7 - 0
etc/functions/resize.json

@@ -26,6 +26,13 @@
 			"en_US": "Creates a scaled image with new dimensions (width, height) .If either width or height is set to 0, it will be set to an aspect ratio preserving value.",
 			"zh_CN": "创建具有新尺寸(宽度,高度)的缩放图像。如果width或height设置为0,则将其设置为长宽比保留值。"
 		}
+	},{
+		"name": "thumbnail",
+		"example": "thumbnail(image,maxWidth, maxHeight)",
+		"hint": {
+			"en_US": "Downscales an image preserving its aspect ratio to the maximum dimensions (maxWidth, maxHeight).",
+			"zh_CN": "将保留宽高比的图像缩小到最大尺寸(maxWidth,maxHeight)。"
+		}
 	}]
 }
 

+ 0 - 31
etc/functions/thumbnail.json

@@ -1,31 +0,0 @@
-{
-	"about": {
-		"trial": false,
-		"author": {
-			"name": "EMQ",
-			"email": "contact@emqx.io",
-			"company": "EMQ Technologies Co., Ltd",
-			"website": "https://www.emqx.io"
-		},
-		"helpUrl": {
-      "en_US": "https://github.com/emqx/kuiper/blob/master/docs/en_US/plugins/functions/functions.md",
-      "zh_CN": "https://github.com/emqx/kuiper/blob/master/docs/zh_CN/plugins/functions/functions.md"
-		},
-		"description": {
-			"en_US": "",
-			"zh_CN": ""
-		}
-	},
-	"libs": [
-	  "github.com/nfnt/resize@master"
-	],
-	"functions": [{
-		"name": "thumbnail",
-		"example": "thumbnail(image,maxWidth, maxHeight)",
-		"hint": {
-			"en_US": "Downscales an image preserving its aspect ratio to the maximum dimensions (maxWidth, maxHeight).",
-			"zh_CN": "将保留宽高比的图像缩小到最大尺寸(maxWidth,maxHeight)。"
-		}
-	}]
-}
-

+ 74 - 0
fvt_scripts/binary_image_process.jmx

@@ -108,6 +108,80 @@
             <stringProp name="mqtt.reconn_attampt_max">0</stringProp>
           </net.xmeter.samplers.ConnectSampler>
           <hashTree/>
+          <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="API_AddPlugin" enabled="true">
+            <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
+            <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
+              <collectionProp name="Arguments.arguments">
+                <elementProp name="" elementType="HTTPArgument">
+                  <boolProp name="HTTPArgument.always_encode">false</boolProp>
+                  <stringProp name="Argument.value">{&#xd;
+                    &quot;name&quot;:&quot;image&quot;,&#xd;
+                    &quot;file&quot;:&quot;http://127.0.0.1:9090/plugins/image.zip&quot;,&#xd;
+                    &quot;functions&quot;:[&quot;resize&quot;,&quot;thumbnail&quot;]&#xd;
+                    }</stringProp>
+                  <stringProp name="Argument.metadata">=</stringProp>
+                </elementProp>
+              </collectionProp>
+            </elementProp>
+            <stringProp name="HTTPSampler.domain">${srv}</stringProp>
+            <stringProp name="HTTPSampler.port">${rest_port}</stringProp>
+            <stringProp name="HTTPSampler.protocol"></stringProp>
+            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
+            <stringProp name="HTTPSampler.path">/plugins/functions</stringProp>
+            <stringProp name="HTTPSampler.method">POST</stringProp>
+            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
+            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
+            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
+            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
+            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
+            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
+            <stringProp name="HTTPSampler.response_timeout"></stringProp>
+          </HTTPSamplerProxy>
+          <hashTree>
+            <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion" enabled="true">
+              <collectionProp name="Asserion.test_strings">
+                <stringProp name="49587">201</stringProp>
+              </collectionProp>
+              <stringProp name="Assertion.custom_message"></stringProp>
+              <stringProp name="Assertion.test_field">Assertion.response_code</stringProp>
+              <boolProp name="Assertion.assume_success">true</boolProp>
+              <intProp name="Assertion.test_type">16</intProp>
+            </ResponseAssertion>
+            <hashTree/>
+            <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true">
+              <stringProp name="ConstantTimer.delay">500</stringProp>
+            </ConstantTimer>
+            <hashTree/>
+          </hashTree>
+          <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="API_GetFunc" enabled="true">
+            <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
+              <collectionProp name="Arguments.arguments"/>
+            </elementProp>
+            <stringProp name="HTTPSampler.domain">${srv}</stringProp>
+            <stringProp name="HTTPSampler.port">${rest_port}</stringProp>
+            <stringProp name="HTTPSampler.protocol"></stringProp>
+            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
+            <stringProp name="HTTPSampler.path">/plugins/udfs/resize</stringProp>
+            <stringProp name="HTTPSampler.method">GET</stringProp>
+            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
+            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
+            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
+            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
+            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
+            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
+            <stringProp name="HTTPSampler.response_timeout"></stringProp>
+          </HTTPSamplerProxy>
+          <hashTree>
+            <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">
+              <stringProp name="JSON_PATH">$.plugin</stringProp>
+              <stringProp name="EXPECTED_VALUE">image</stringProp>
+              <boolProp name="JSONVALIDATION">true</boolProp>
+              <boolProp name="EXPECT_NULL">false</boolProp>
+              <boolProp name="INVERT">false</boolProp>
+              <boolProp name="ISREGEX">false</boolProp>
+            </JSONPathAssertion>
+            <hashTree/>
+          </hashTree>
           <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="API_CreateStream" enabled="true">
             <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
             <elementProp name="HTTPsampler.Arguments" elementType="Arguments">

+ 15 - 0
fvt_scripts/prepare_plugins.sh

@@ -24,9 +24,24 @@ cp plugins/zmq.yaml .
 zip zmq.zip Zmq.so zmq.yaml
 rm -rf zmq.yaml Zmq.so
 
+rm -rf image.* Image.so
+
+FILE=../plugins/functions/Image.so
+if [ -f "$FILE" ]; then
+    echo "$FILE exists, not requried to build plugin."
+else
+    echo "$FILE does not exist, will build the plugin."
+    go build --buildmode=plugin -o ../plugins/functions/Image.so ../plugins/functions/image/*.go
+fi
+
+mv ../plugins/functions/Image.so .
+zip image.zip Image.so
+rm -rf Image.so
+
 rm -rf plugins/service/web/plugins/
 mkdir -p plugins/service/web/plugins/
 mv zmq.zip plugins/service/web/plugins/
+mv image.zip plugins/service/web/plugins/
 
 cd plugins/service/
 export BUILD_ID=dontKillMe

+ 1 - 1
plugins/funcMeta.go

@@ -30,7 +30,7 @@ type (
 )
 
 func isInternalFunc(fiName string) bool {
-	internal := []string{`accumulateWordCount.json`, `countPlusOne.json`, `echo.json`, `internal.json`, "windows.json", "thumbnail.json", "resize.json"}
+	internal := []string{`accumulateWordCount.json`, `countPlusOne.json`, `echo.json`, `internal.json`, "windows.json", "image.json"}
 	for _, v := range internal {
 		if v == fiName {
 			return true

+ 6 - 0
plugins/functions/image/exports.go

@@ -0,0 +1,6 @@
+package main
+
+var (
+	Thumbnail thumbnail
+	Resize    imageResize
+)

+ 0 - 2
plugins/functions/resize/resize.go

@@ -58,5 +58,3 @@ func (f *imageResize) Exec(args []interface{}, _ api.FunctionContext) (interface
 func (f *imageResize) IsAggregate() bool {
 	return false
 }
-
-var Resize imageResize

+ 0 - 2
plugins/functions/thumbnail/thumbnail.go

@@ -58,5 +58,3 @@ func (f *thumbnail) Exec(args []interface{}, _ api.FunctionContext) (interface{}
 func (f *thumbnail) IsAggregate() bool {
 	return false
 }
-
-var Thumbnail thumbnail