From 8fc46ad02dd5ebc2e2bd1c219a7b1cd2dcb42388 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 9 Aug 2022 15:20:52 +0800 Subject: [PATCH 1/3] fix instructions under example --- .../device/helloworld-deployment.yaml | 22 ++++++++++++++++ .../device/helloworld-edgedevice.yaml | 12 +++++++++ .../device/helloworld-service.yaml | 16 ++++++++++++ .../examples/hello-world-device/go.mod | 3 +++ .../http-deviceshifu-configmap.yaml | 5 ++-- .../mqtt_deviceshifu_configmap.yaml | 5 ++-- .../opcua_deviceshifu_configmap.yaml | 19 +++++++------- .../deviceshifu-camera-configmap.yaml | 26 ++++++++++--------- .../plc-deviceshifu-configmap.yaml | 20 +++++++------- 9 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml create mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml create mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml create mode 100644 deviceshifu/examples/hello-world-device/go.mod diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml new file mode 100644 index 000000000..e109ea306 --- /dev/null +++ b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: helloworld + name: helloworld + namespace: devices +spec: + replicas: 1 + selector: + matchLabels: + app: helloworld + template: + metadata: + labels: + app: helloworld + spec: + containers: + - image: helloworld-device:v0.0.1 + name: helloworld + ports: + - containerPort: 11111 diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml new file mode 100644 index 000000000..2645f44c1 --- /dev/null +++ b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml @@ -0,0 +1,12 @@ +apiVersion: shifu.edgenesis.io/v1alpha1 +kind: EdgeDevice +metadata: + name: edgedevice-helloworld + namespace: devices +spec: + sku: "Hello World" + connection: Ethernet + address: helloworld.devices.svc.cluster.local:11111 + protocol: HTTP +status: + edgedevicephase: "Pending" diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml new file mode 100644 index 000000000..0e2c70e5d --- /dev/null +++ b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: helloworld + name: helloworld + namespace: devices +spec: + ports: + - port: 11111 + protocol: TCP + targetPort: 11111 + selector: + app: helloworld + type: LoadBalancer + diff --git a/deviceshifu/examples/hello-world-device/go.mod b/deviceshifu/examples/hello-world-device/go.mod new file mode 100644 index 000000000..69451d9ee --- /dev/null +++ b/deviceshifu/examples/hello-world-device/go.mod @@ -0,0 +1,3 @@ +module helloworld + +go 1.18 diff --git a/examples/httpDeviceShifu/deployment/http-deviceshifu-configmap.yaml b/examples/httpDeviceShifu/deployment/http-deviceshifu-configmap.yaml index 13169aae0..9759c0c15 100644 --- a/examples/httpDeviceShifu/deployment/http-deviceshifu-configmap.yaml +++ b/examples/httpDeviceShifu/deployment/http-deviceshifu-configmap.yaml @@ -10,8 +10,9 @@ data: driverImage: http-device:v0.0.1 # available instructions instructions: | - status: - info: + instructions: + status: + info: # telemetry retrieval methods # in this example, a device_health telemetry is collected by calling hello instruction every 1 second telemetries: | diff --git a/examples/mqttDeviceShifu/mqtt_deploy/mqtt_deviceshifu_configmap.yaml b/examples/mqttDeviceShifu/mqtt_deploy/mqtt_deviceshifu_configmap.yaml index 7a9ebad52..6ebf8d327 100644 --- a/examples/mqttDeviceShifu/mqtt_deploy/mqtt_deviceshifu_configmap.yaml +++ b/examples/mqttDeviceShifu/mqtt_deploy/mqtt_deviceshifu_configmap.yaml @@ -10,6 +10,7 @@ data: instructions: | telemetries: | - device_health: - properties: + telemetries: + device_health: + properties: diff --git a/examples/opcuaDeviceShifu/opcua_deploy/opcua_deviceshifu_configmap.yaml b/examples/opcuaDeviceShifu/opcua_deploy/opcua_deviceshifu_configmap.yaml index 6c9cc924c..0ba5b36b9 100644 --- a/examples/opcuaDeviceShifu/opcua_deploy/opcua_deviceshifu_configmap.yaml +++ b/examples/opcuaDeviceShifu/opcua_deploy/opcua_deviceshifu_configmap.yaml @@ -8,15 +8,16 @@ data: driverSku: Test OPC UA Server driverImage: instructions: | - get_value: - instructionProperties: - OPCUANodeID: "ns=2;i=2" - get_time: - instructionProperties: - OPCUANodeID: "i=2258" - get_server: - instructionProperties: - OPCUANodeID: "i=2261" + instructions: + get_value: + instructionProperties: + OPCUANodeID: "ns=2;i=2" + get_time: + instructionProperties: + OPCUANodeID: "i=2258" + get_server: + instructionProperties: + OPCUANodeID: "i=2261" telemetries: | telemetrySettings: telemetryUpdateIntervalInMiliseconds: 1000 diff --git a/examples/rtspDeviceShifu/camera-deployment/deviceshifu-camera-configmap.yaml b/examples/rtspDeviceShifu/camera-deployment/deviceshifu-camera-configmap.yaml index 1671ea32a..a7bea52ce 100644 --- a/examples/rtspDeviceShifu/camera-deployment/deviceshifu-camera-configmap.yaml +++ b/examples/rtspDeviceShifu/camera-deployment/deviceshifu-camera-configmap.yaml @@ -8,21 +8,23 @@ data: driverSku: HikVision driverImage: edgenesis/camera-python:v0.0.1 instructions: | - capture: - info: - stream: - move/up: - move/down: - move/left: - move/right: + instructions: + capture: + info: + stream: + move/up: + move/down: + move/left: + move/right: # Telemetries are configurable health checks of the EdgeDevice # Developer/user can configure certain instructions to be used as health check # of the device. In this example, the device_health telemetry is mapped to # "get_status" instruction, executed every 1000 ms telemetries: | - device_health: - properties: - instruction: info - initialDelayMs: 1000 - intervalMs: 1000 + telemetries: + device_health: + properties: + instruction: info + initialDelayMs: 1000 + intervalMs: 1000 diff --git a/examples/siemensPLCDeviceShifu/plc-deployment/plc-deviceshifu-configmap.yaml b/examples/siemensPLCDeviceShifu/plc-deployment/plc-deviceshifu-configmap.yaml index f973f9ce6..9e371a1e7 100644 --- a/examples/siemensPLCDeviceShifu/plc-deployment/plc-deviceshifu-configmap.yaml +++ b/examples/siemensPLCDeviceShifu/plc-deployment/plc-deviceshifu-configmap.yaml @@ -11,15 +11,17 @@ data: driverExecution: " " # available instructions instructions: | - sendsinglebit: - sendcontent: - getcontent: - getcpuordercode: + instructions: + sendsinglebit: + sendcontent: + getcontent: + getcpuordercode: # telemetry retrieval methods # in this example, a device_health telemetry is collected by calling hello instruction every 1 second telemetries: | - device_health: - properties: - instruction: getcpuordercode - initialDelayMs: 1000 - intervalMs: 1000 + telemetries: + device_health: + properties: + instruction: getcpuordercode + initialDelayMs: 1000 + intervalMs: 1000 From 1c973db422639bbe9129ce271200cae18da02fe9 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 9 Aug 2022 15:26:17 +0800 Subject: [PATCH 2/3] delete unused file --- .../device/helloworld-deployment.yaml | 22 ------------------- .../device/helloworld-edgedevice.yaml | 12 ---------- .../device/helloworld-service.yaml | 16 -------------- .../examples/hello-world-device/go.mod | 3 --- 4 files changed, 53 deletions(-) delete mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml delete mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml delete mode 100644 deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml delete mode 100644 deviceshifu/examples/hello-world-device/go.mod diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml deleted file mode 100644 index e109ea306..000000000 --- a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-deployment.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app: helloworld - name: helloworld - namespace: devices -spec: - replicas: 1 - selector: - matchLabels: - app: helloworld - template: - metadata: - labels: - app: helloworld - spec: - containers: - - image: helloworld-device:v0.0.1 - name: helloworld - ports: - - containerPort: 11111 diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml deleted file mode 100644 index 2645f44c1..000000000 --- a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-edgedevice.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: shifu.edgenesis.io/v1alpha1 -kind: EdgeDevice -metadata: - name: edgedevice-helloworld - namespace: devices -spec: - sku: "Hello World" - connection: Ethernet - address: helloworld.devices.svc.cluster.local:11111 - protocol: HTTP -status: - edgedevicephase: "Pending" diff --git a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml b/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml deleted file mode 100644 index 0e2c70e5d..000000000 --- a/deviceshifu/examples/hello-world-device/configuration/device/helloworld-service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - app: helloworld - name: helloworld - namespace: devices -spec: - ports: - - port: 11111 - protocol: TCP - targetPort: 11111 - selector: - app: helloworld - type: LoadBalancer - diff --git a/deviceshifu/examples/hello-world-device/go.mod b/deviceshifu/examples/hello-world-device/go.mod deleted file mode 100644 index 69451d9ee..000000000 --- a/deviceshifu/examples/hello-world-device/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module helloworld - -go 1.18 From 0a2d38c8d04dfc75b0711bb78f70d8f03cf83eca Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 9 Aug 2022 18:09:29 +0800 Subject: [PATCH 3/3] fix haikang bug --- deviceshifu/pkg/deviceshifu/deviceshifu.go | 2 -- deviceshifu/pkg/deviceshifubase/deviceshifubase.go | 5 +++-- deviceshifu/pkg/deviceshifubase/deviceshifubase_config.go | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/deviceshifu/pkg/deviceshifu/deviceshifu.go b/deviceshifu/pkg/deviceshifu/deviceshifu.go index 116384cd8..1feed96e1 100644 --- a/deviceshifu/pkg/deviceshifu/deviceshifu.go +++ b/deviceshifu/pkg/deviceshifu/deviceshifu.go @@ -190,8 +190,6 @@ func (handler DeviceCommandHandlerHTTP) commandHandleFunc() http.HandlerFunc { log.Printf("timeout URI parsing error" + parseErr.Error()) return } - - r.URL.Query().Del(deviceshifubase.DEVICE_INSTRUCTION_TIMEOUT_URI_QUERY_STR) } switch reqType { diff --git a/deviceshifu/pkg/deviceshifubase/deviceshifubase.go b/deviceshifu/pkg/deviceshifubase/deviceshifubase.go index bf2292f0c..9e2a897f1 100644 --- a/deviceshifu/pkg/deviceshifubase/deviceshifubase.go +++ b/deviceshifu/pkg/deviceshifubase/deviceshifubase.go @@ -54,6 +54,7 @@ const ( KUBERNETES_CONFIG_DEFAULT string = "" DEVICE_INSTRUCTION_TIMEOUT_URI_QUERY_STR string = "timeout" DEVICE_DEFAULT_GLOBAL_TIMEOUT_SECONDS int = 3 + DEFAULT_HTTP_SERVER_TIMEOUT_SECONDS int = 0 ) var ( @@ -105,8 +106,8 @@ func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifuBase, *http.Serv Server: &http.Server{ Addr: DEVICE_DEFAULT_PORT_STR, Handler: mux, - ReadTimeout: 60 * time.Second, - WriteTimeout: 60 * time.Second, + ReadTimeout: time.Duration(DEFAULT_HTTP_SERVER_TIMEOUT_SECONDS) * time.Second, + WriteTimeout: time.Duration(DEFAULT_HTTP_SERVER_TIMEOUT_SECONDS) * time.Second, }, DeviceShifuConfig: deviceShifuConfig, EdgeDevice: edgeDevice, diff --git a/deviceshifu/pkg/deviceshifubase/deviceshifubase_config.go b/deviceshifu/pkg/deviceshifubase/deviceshifubase_config.go index 5df839d23..967fa46ea 100644 --- a/deviceshifu/pkg/deviceshifubase/deviceshifubase_config.go +++ b/deviceshifu/pkg/deviceshifubase/deviceshifubase_config.go @@ -4,7 +4,6 @@ import ( "context" "errors" "log" - "time" "edgenesis.io/shifu/k8s/crd/api/v1alpha1" "gopkg.in/yaml.v3" @@ -164,7 +163,6 @@ func NewEdgeDeviceRestClient(config *rest.Config) (*rest.RESTClient, error) { crdConfig.APIPath = "/apis" crdConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme) crdConfig.UserAgent = rest.DefaultKubernetesUserAgent() - crdConfig.Timeout = 3 * time.Second exampleRestClient, err := rest.UnversionedRESTClientFor(crdConfig) if err != nil { return nil, err