修复镜像相关问题&&代码重构

This commit is contained in:
朱厚九 2024-07-10 14:55:21 +08:00
parent 97396d784b
commit 329c98ebc5
57 changed files with 405 additions and 172 deletions

View File

@ -18,5 +18,5 @@ start:
.PHONY: build .PHONY: build
build: build:
docker buildx build --platform linux/amd64 -t "您的仓库地址" -f cmd/hummingbird/Dockerfile --push . docker buildx build --platform linux/amd64 -t "" -f cmd/hummingbird-core/Dockerfile --push .

View File

@ -30,12 +30,12 @@ Timeout = 120
[Databases.Metadata] [Databases.Metadata]
[Databases.Metadata.Primary] [Databases.Metadata.Primary]
Type = 'sqlite' Type = 'sqlite'
DataSource = 'hummingbird/db-data/core-data/core.db?_timeout=5000' DataSource = 'manifest/docker/db-data/core-data/core.db?_timeout=5000'
[Databases.Data] [Databases.Data]
[Databases.Data.Primary] [Databases.Data.Primary]
Type = 'leveldb' Type = 'leveldb'
DataSource = 'hummingbird/db-data/leveldb-core-data/' DataSource = 'manifest/docker/db-data/leveldb-core-data/'
[MessageQueue] [MessageQueue]
Protocol = 'tcp' Protocol = 'tcp'

View File

@ -0,0 +1,33 @@
{
"files": {
"main.css": "/static/css/main.822cee67.css",
"main.js": "/static/js/main.9a4b5878.js",
"static/js/342.e07172ae.chunk.js": "/static/js/342.e07172ae.chunk.js",
"static/js/558.d067177e.chunk.js": "/static/js/558.d067177e.chunk.js",
"static/js/324.bf4cc54f.chunk.js": "/static/js/324.bf4cc54f.chunk.js",
"static/js/258.efff4014.chunk.js": "/static/js/258.efff4014.chunk.js",
"static/js/787.d3befce1.chunk.js": "/static/js/787.d3befce1.chunk.js",
"ts.worker.js": "/ts.worker.js",
"json.worker.js": "/json.worker.js",
"editor.worker.js": "/editor.worker.js",
"static/media/head-bg.8b029587.png": "/static/media/head-bg.8b029587.60f3a93d8a581efd4c49.png",
"static/media/bg.ad187fed.png": "/static/media/bg.ad187fed.a47d112f49f56eb1cfa5.png",
"static/media/codicon.ttf": "/static/media/codicon.b797181c93b3755f4fa1.ttf",
"static/media/bg-1.7f3acdfb.png": "/static/media/bg-1.7f3acdfb.aad6275b1801455a76c0.png",
"static/media/newlogo.png": "/static/media/newlogo.e2ad3c36f34a1c2c10d1.png",
"static/media/default.32752796.png": "/static/media/default.32752796.9e3b4c5313ccb5060485.png",
"static/media/background.png": "/static/media/background.8ed5e5404edf817e15f5.png",
"index.html": "/index.html",
"main.822cee67.css.map": "/static/css/main.822cee67.css.map",
"main.9a4b5878.js.map": "/static/js/main.9a4b5878.js.map",
"342.e07172ae.chunk.js.map": "/static/js/342.e07172ae.chunk.js.map",
"558.d067177e.chunk.js.map": "/static/js/558.d067177e.chunk.js.map",
"324.bf4cc54f.chunk.js.map": "/static/js/324.bf4cc54f.chunk.js.map",
"258.efff4014.chunk.js.map": "/static/js/258.efff4014.chunk.js.map",
"787.d3befce1.chunk.js.map": "/static/js/787.d3befce1.chunk.js.map"
},
"entrypoints": [
"static/css/main.822cee67.css",
"static/js/main.9a4b5878.js"
]
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="apple-touch-icon" href="/favicon.ico"/><link rel="manifest" href="/manifest.json"/><title>登录</title><script defer="defer" src="/static/js/main.9a4b5878.js"></script><link href="/static/css/main.822cee67.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*!-----------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
* Released under the MIT license
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
*-----------------------------------------------------------------------------*/

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "logo.png",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/png"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,6 @@
/*!-----------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
* Released under the MIT license
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
*-----------------------------------------------------------------------------*/

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
"use strict";(self.webpackChunkmyapp=self.webpackChunkmyapp||[]).push([[787],{787:function(e,t,n){n.r(t),n.d(t,{getCLS:function(){return y},getFCP:function(){return g},getFID:function(){return C},getLCP:function(){return P},getTTFB:function(){return D}});var i,r,a,o,u=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},f=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},s=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},m=function(e,t,n){var i;return function(r){t.value>=0&&(r||n)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},v=-1,p=function(){return"hidden"===document.visibilityState?0:1/0},d=function(){f((function(e){var t=e.timeStamp;v=t}),!0)},l=function(){return v<0&&(v=p(),d(),s((function(){setTimeout((function(){v=p(),d()}),0)}))),{get firstHiddenTime(){return v}}},g=function(e,t){var n,i=l(),r=u("FCP"),a=function(e){"first-contentful-paint"===e.name&&(f&&f.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),n(!0)))},o=window.performance&&performance.getEntriesByName&&performance.getEntriesByName("first-contentful-paint")[0],f=o?null:c("paint",a);(o||f)&&(n=m(e,r,t),o&&a(o),s((function(i){r=u("FCP"),n=m(e,r,t),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,n(!0)}))}))})))},h=!1,T=-1,y=function(e,t){h||(g((function(e){T=e.value})),h=!0);var n,i=function(t){T>-1&&e(t)},r=u("CLS",0),a=0,o=[],v=function(e){if(!e.hadRecentInput){var t=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-t.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,n())}},p=c("layout-shift",v);p&&(n=m(i,r,t),f((function(){p.takeRecords().map(v),n(!0)})),s((function(){a=0,T=-1,r=u("CLS",0),n=m(i,r,t)})))},E={passive:!0,capture:!0},w=new Date,L=function(e,t){i||(i=t,r=e,a=new Date,F(removeEventListener),S())},S=function(){if(r>=0&&r<a-w){var e={entryType:"first-input",name:i.type,target:i.target,cancelable:i.cancelable,startTime:i.timeStamp,processingStart:i.timeStamp+r};o.forEach((function(t){t(e)})),o=[]}},b=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){L(e,t),r()},i=function(){r()},r=function(){removeEventListener("pointerup",n,E),removeEventListener("pointercancel",i,E)};addEventListener("pointerup",n,E),addEventListener("pointercancel",i,E)}(t,e):L(t,e)}},F=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,b,E)}))},C=function(e,t){var n,a=l(),v=u("FID"),p=function(e){e.startTime<a.firstHiddenTime&&(v.value=e.processingStart-e.startTime,v.entries.push(e),n(!0))},d=c("first-input",p);n=m(e,v,t),d&&f((function(){d.takeRecords().map(p),d.disconnect()}),!0),d&&s((function(){var a;v=u("FID"),n=m(e,v,t),o=[],r=-1,i=null,F(addEventListener),a=p,o.push(a),S()}))},k={},P=function(e,t){var n,i=l(),r=u("LCP"),a=function(e){var t=e.startTime;t<i.firstHiddenTime&&(r.value=t,r.entries.push(e),n())},o=c("largest-contentful-paint",a);if(o){n=m(e,r,t);var v=function(){k[r.id]||(o.takeRecords().map(a),o.disconnect(),k[r.id]=!0,n(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),f(v,!0),s((function(i){r=u("LCP"),n=m(e,r,t),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,k[r.id]=!0,n(!0)}))}))}))}},D=function(e){var t,n=u("TTFB");t=function(){try{var t=performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,t={entryType:"navigation",startTime:0};for(var n in e)"navigationStart"!==n&&"toJSON"!==n&&(t[n]=Math.max(e[n]-e.navigationStart,0));return t}();if(n.value=n.delta=t.responseStart,n.value<0||n.value>performance.now())return;n.entries=[t],e(n)}catch(e){}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)}))}}}]);
//# sourceMappingURL=787.d3befce1.chunk.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,117 @@
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/*! @license DOMPurify 2.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.1/LICENSE */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*!-----------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
* Released under the MIT license
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
*-----------------------------------------------------------------------------*/
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* use-sync-external-store-shim.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @remix-run/router v1.0.3
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* React Router DOM v6.4.3
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* React Router v6.4.3
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*!-----------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
* Released under the MIT license
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
*-----------------------------------------------------------------------------*/

File diff suppressed because one or more lines are too long

View File

@ -121,13 +121,9 @@ type DeviceLibraryResponse struct {
func DeviceLibraryResponseFromModel(dl models.DeviceLibrary) DeviceLibraryResponse { func DeviceLibraryResponseFromModel(dl models.DeviceLibrary) DeviceLibraryResponse {
// 如果docker镜像id为空那么返回给前端的版本为 `-` // 如果docker镜像id为空那么返回给前端的版本为 `-`
if dl.DockerImageId == "" { if dl.DockerImageId == "" && !dl.IsInternal {
dl.Version = "-" dl.Version = "-"
} }
//if dl.ConfigFile != "" {
// dl.ConfigFile = path.Base(dl.ConfigFile)
//}
return DeviceLibraryResponse{ return DeviceLibraryResponse{
Id: dl.Id, Id: dl.Id,
Name: dl.Name, Name: dl.Name,

View File

@ -185,7 +185,13 @@ func (m *deviceLibraryManager) updateDLDefaultVersion(dl models.DeviceLibrary, n
func (m *deviceLibraryManager) downloadVersion(dl models.DeviceLibrary, dc models.DockerConfig, version string) (string, error) { func (m *deviceLibraryManager) downloadVersion(dl models.DeviceLibrary, dc models.DockerConfig, version string) (string, error) {
// 3.下载应用 // 3.下载应用
imageId, err := m.appModel.DownApp(dtos.DockerConfigFromModel(dc), dtos.DeviceLibraryFromModel(dl), version) var cfg dtos.DockerConfig
if dl.IsInternal {
cfg = dtos.WincLinkDockerConfig()
} else {
cfg = dtos.DockerConfigFromModel(dc)
}
imageId, err := m.appModel.DownApp(cfg, dtos.DeviceLibraryFromModel(dl), version)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -11,11 +11,12 @@ func (app *driverLibApp) GetDeviceLibraryAndMirrorConfig(dlId string) (dl models
} }
// 2.获取docker仓库配置 // 2.获取docker仓库配置
dc, err = app.dbClient.DockerConfigById(dl.DockerConfigId) if !dl.IsInternal {
if err != nil { dc, err = app.dbClient.DockerConfigById(dl.DockerConfigId)
app.lc.Errorf("2.DeviceLibraryOperate docker hub, id:%s, DockerConfigId:%s, err:%v", dlId, dl.DockerConfigId, err) if err != nil {
return app.lc.Errorf("2.DeviceLibraryOperate docker hub, id:%s, DockerConfigId:%s, err:%v", dlId, dl.DockerConfigId, err)
return
}
} }
return return
} }

View File

@ -43,7 +43,6 @@ func (ctl *controller) DeviceLibrariesSearch(c *gin.Context) {
} }
dtos.CorrectionPageParam(&req.BaseSearchConditionQuery) dtos.CorrectionPageParam(&req.BaseSearchConditionQuery)
//req2 := dtos.FromDeviceLibrarySearchQueryRequestToRpc(req)
list, total, edgeXErr := ctl.getDriverLibApp().DeviceLibrariesSearch(c, req) list, total, edgeXErr := ctl.getDriverLibApp().DeviceLibrariesSearch(c, req)
if edgeXErr != nil { if edgeXErr != nil {
httphelper.RenderFail(c, edgeXErr, c.Writer, lc) httphelper.RenderFail(c, edgeXErr, c.Writer, lc)

View File

@ -78,39 +78,43 @@ func NewBootstrap(router *gin.Engine) *Bootstrap {
} }
func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool { func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool {
configuration := container.ConfigurationFrom(dic.Get) configuration := container.ConfigurationFrom(dic.Get)
lc := pkgContainer.LoggingClientFrom(dic.Get) lc := pkgContainer.LoggingClientFrom(dic.Get)
if !b.initClient(ctx, wg, dic, configuration, lc) { if !b.initClient(ctx, wg, dic, configuration, lc) {
return false return false
} }
if !initApp(ctx, configuration, dic) {
return false
}
// rpc 服务 // rpc 服务
if ok := initRPCServer(ctx, wg, dic); !ok { if ok := initRPCServer(ctx, wg, dic); !ok {
return false return false
} }
lc.Infof("init rpc server") lc.Infof("init rpc server")
// http 路由 // http 路由
route.LoadRestRoutes(b.router, dic) route.LoadRestRoutes(b.router, dic)
// 业务逻辑 // 业务逻辑
application.InitSchedule(dic, lc) application.InitSchedule(dic, lc)
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
<-ctx.Done() <-ctx.Done()
crontab.Stop() crontab.Stop()
}() }()
return true return true
} }
func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.Container, configuration *config.ConfigurationStruct, lc logger.LoggingClient) bool { func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.Container, configuration *config.ConfigurationStruct, lc logger.LoggingClient) bool {
appMode, err := dmi.New(dic, ctx, wg, dtos.DriverConfigManage{ appMode, err := dmi.New(dic, ctx, wg, dtos.DriverConfigManage{
DockerManageConfig: dtos.DockerManageConfig{ DockerManageConfig: dtos.DockerManageConfig{
ContainerConfigPath: configuration.DockerManage.ContainerConfigPath, ContainerConfigPath: configuration.DockerManage.ContainerConfigPath,
@ -124,7 +128,7 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
lc.Error("create driver model interface error %v", err) lc.Error("create driver model interface error %v", err)
return false return false
} }
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
interfaces.DriverModelInterfaceName: func(get di.Get) interface{} { interfaces.DriverModelInterfaceName: func(get di.Get) interface{} {
return appMode return appMode
@ -136,147 +140,147 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
return homePageApp return homePageApp
}, },
}) })
languageApp := languagesdkapp.NewLanguageSDKApp(ctx, dic) languageApp := languagesdkapp.NewLanguageSDKApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.LanguageSDKAppName: func(get di.Get) interface{} { container.LanguageSDKAppName: func(get di.Get) interface{} {
return languageApp return languageApp
}, },
}) })
monitorApp := monitor.NewMonitor(ctx, dic) monitorApp := monitor.NewMonitor(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MonitorAppName: func(get di.Get) interface{} { container.MonitorAppName: func(get di.Get) interface{} {
return monitorApp return monitorApp
}, },
}) })
streamClient := streamclient.NewStreamClient(lc) streamClient := streamclient.NewStreamClient(lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
pkgContainer.StreamClientName: func(get di.Get) interface{} { pkgContainer.StreamClientName: func(get di.Get) interface{} {
return streamClient return streamClient
}, },
}) })
driverApp := driverapp.NewDriverApp(ctx, dic) driverApp := driverapp.NewDriverApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DriverAppName: func(get di.Get) interface{} { container.DriverAppName: func(get di.Get) interface{} {
return driverApp return driverApp
}, },
}) })
driverServiceApp := driverserviceapp.NewDriverServiceApp(ctx, dic) driverServiceApp := driverserviceapp.NewDriverServiceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DriverServiceAppName: func(get di.Get) interface{} { container.DriverServiceAppName: func(get di.Get) interface{} {
return driverServiceApp return driverServiceApp
}, },
}) })
productApp := productapp.NewProductApp(ctx, dic) productApp := productapp.NewProductApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ProductAppName: func(get di.Get) interface{} { container.ProductAppName: func(get di.Get) interface{} {
return productApp return productApp
}, },
}) })
thingModelApp := thingmodelapp.NewThingModelApp(ctx, dic) thingModelApp := thingmodelapp.NewThingModelApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ThingModelAppName: func(get di.Get) interface{} { container.ThingModelAppName: func(get di.Get) interface{} {
return thingModelApp return thingModelApp
}, },
}) })
deviceApp := deviceapp.NewDeviceApp(ctx, dic) deviceApp := deviceapp.NewDeviceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DeviceItfName: func(get di.Get) interface{} { container.DeviceItfName: func(get di.Get) interface{} {
return deviceApp return deviceApp
}, },
}) })
alertCentreApp := alertcentreapp.NewAlertCentreApp(ctx, dic) alertCentreApp := alertcentreapp.NewAlertCentreApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.AlertRuleAppName: func(get di.Get) interface{} { container.AlertRuleAppName: func(get di.Get) interface{} {
return alertCentreApp return alertCentreApp
}, },
}) })
ruleEngineApp := ruleengine.NewRuleEngineApp(ctx, dic) ruleEngineApp := ruleengine.NewRuleEngineApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.RuleEngineAppName: func(get di.Get) interface{} { container.RuleEngineAppName: func(get di.Get) interface{} {
return ruleEngineApp return ruleEngineApp
}, },
}) })
sceneApp := scene.NewSceneApp(ctx, dic) sceneApp := scene.NewSceneApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.SceneAppName: func(get di.Get) interface{} { container.SceneAppName: func(get di.Get) interface{} {
return sceneApp return sceneApp
}, },
}) })
conJobApp := timerapp.NewCronTimer(ctx, jobrunner.NewJobRunFunc(dic), dic) conJobApp := timerapp.NewCronTimer(ctx, jobrunner.NewJobRunFunc(dic), dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ConJobAppName: func(get di.Get) interface{} { container.ConJobAppName: func(get di.Get) interface{} {
return conJobApp return conJobApp
}, },
}) })
dataResourceApp := dataresource.NewDataResourceApp(ctx, dic) dataResourceApp := dataresource.NewDataResourceApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DataResourceName: func(get di.Get) interface{} { container.DataResourceName: func(get di.Get) interface{} {
return dataResourceApp return dataResourceApp
}, },
}) })
cosApp := cos.NewCos("", "", "") cosApp := cos.NewCos("", "", "")
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.CosAppName: func(get di.Get) interface{} { container.CosAppName: func(get di.Get) interface{} {
return cosApp return cosApp
}, },
}) })
categoryTemplateApp := categorytemplate.NewCategoryTemplateApp(ctx, dic) categoryTemplateApp := categorytemplate.NewCategoryTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.CategoryTemplateAppName: func(get di.Get) interface{} { container.CategoryTemplateAppName: func(get di.Get) interface{} {
return categoryTemplateApp return categoryTemplateApp
}, },
}) })
unitTemplateApp := unittemplate.NewUnitTemplateApp(ctx, dic) unitTemplateApp := unittemplate.NewUnitTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.UnitTemplateAppName: func(get di.Get) interface{} { container.UnitTemplateAppName: func(get di.Get) interface{} {
return unitTemplateApp return unitTemplateApp
}, },
}) })
docsApp := docapp.NewDocsApp(ctx, dic) docsApp := docapp.NewDocsApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.DocsAppName: func(get di.Get) interface{} { container.DocsAppName: func(get di.Get) interface{} {
return docsApp return docsApp
}, },
}) })
quickNavigationApp := quicknavigationapp.NewQuickNavigationApp(ctx, dic) quickNavigationApp := quicknavigationapp.NewQuickNavigationApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.QuickNavigationAppName: func(get di.Get) interface{} { container.QuickNavigationAppName: func(get di.Get) interface{} {
return quickNavigationApp return quickNavigationApp
}, },
}) })
thingModelTemplateApp := thingmodeltemplate.NewThingModelTemplateApp(ctx, dic) thingModelTemplateApp := thingmodeltemplate.NewThingModelTemplateApp(ctx, dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.ThingModelTemplateAppName: func(get di.Get) interface{} { container.ThingModelTemplateAppName: func(get di.Get) interface{} {
return thingModelTemplateApp return thingModelTemplateApp
}, },
}) })
hpcloudServiceApp := hpcloudclient.NewHpcloud(lc) hpcloudServiceApp := hpcloudclient.NewHpcloud(lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.HpcServiceAppName: func(get di.Get) interface{} { container.HpcServiceAppName: func(get di.Get) interface{} {
return hpcloudServiceApp return hpcloudServiceApp
}, },
}) })
smsServiceApp := sms.NewSmsClient(lc, "", smsServiceApp := sms.NewSmsClient(lc, "",
"", "") "", "")
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
@ -284,21 +288,21 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
return smsServiceApp return smsServiceApp
}, },
}) })
limitMethodApp := application.NewLimitMethodConf(*configuration) limitMethodApp := application.NewLimitMethodConf(*configuration)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
pkgContainer.LimitMethodConfName: func(get di.Get) interface{} { pkgContainer.LimitMethodConfName: func(get di.Get) interface{} {
return limitMethodApp return limitMethodApp
}, },
}) })
ekuiperApp := ekuiperclient.New(configuration.Clients["Ekuiper"].Address(), lc) ekuiperApp := ekuiperclient.New(configuration.Clients["Ekuiper"].Address(), lc)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.EkuiperAppName: func(get di.Get) interface{} { container.EkuiperAppName: func(get di.Get) interface{} {
return ekuiperApp return ekuiperApp
}, },
}) })
//agentApp := agentclient.New(configuration.Clients["Agent"].Address()) //agentApp := agentclient.New(configuration.Clients["Agent"].Address())
//dic.Update(di.ServiceConstructorMap{ //dic.Update(di.ServiceConstructorMap{
// container.AgentClientName: func(get di.Get) interface{} { // container.AgentClientName: func(get di.Get) interface{} {
@ -312,28 +316,28 @@ func (b *Bootstrap) initClient(ctx context.Context, wg *sync.WaitGroup, dic *di.
// return cacheClient // return cacheClient
// }, // },
//}) //})
persistItf := persistence.NewPersistApp(dic) persistItf := persistence.NewPersistApp(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.PersistItfName: func(get di.Get) interface{} { container.PersistItfName: func(get di.Get) interface{} {
return persistItf return persistItf
}, },
}) })
userItf := userapp.New(dic) userItf := userapp.New(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.UserItfName: func(get di.Get) interface{} { container.UserItfName: func(get di.Get) interface{} {
return userItf return userItf
}, },
}) })
messageItf := messageapp.NewMessageApp(dic, configuration.Clients["Ekuiper"].Address()) messageItf := messageapp.NewMessageApp(dic, configuration.Clients["Ekuiper"].Address())
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MessageItfName: func(get di.Get) interface{} { container.MessageItfName: func(get di.Get) interface{} {
return messageItf return messageItf
}, },
}) })
messageStoreItf := messagestore.NewMessageStore(dic) messageStoreItf := messagestore.NewMessageStore(dic)
dic.Update(di.ServiceConstructorMap{ dic.Update(di.ServiceConstructorMap{
container.MessageStoreItfName: func(get di.Get) interface{} { container.MessageStoreItfName: func(get di.Get) interface{} {

View File

@ -16,107 +16,136 @@ package initialize
import ( import (
"context" "context"
"github.com/winc-link/hummingbird/internal/hummingbird/core/container" "encoding/json"
"github.com/kirinlabs/HttpRequest"
"github.com/winc-link/hummingbird/internal/hummingbird/core/config"
pkgContainer "github.com/winc-link/hummingbird/internal/pkg/container" pkgContainer "github.com/winc-link/hummingbird/internal/pkg/container"
"github.com/winc-link/hummingbird/internal/pkg/di" "github.com/winc-link/hummingbird/internal/pkg/di"
"github.com/winc-link/hummingbird/internal/pkg/errort"
"github.com/winc-link/hummingbird/internal/pkg/logger" "github.com/winc-link/hummingbird/internal/pkg/logger"
"strings"
"sync" "sync"
"time"
) )
func initApp(ctx context.Context, dic *di.Container) bool { func initApp(ctx context.Context, configuration *config.ConfigurationStruct, dic *di.Container) bool {
lc := pkgContainer.LoggingClientFrom(dic.Get) lc := pkgContainer.LoggingClientFrom(dic.Get)
dbClient := container.DBClientFrom(dic.Get) go initEkuiperStreams(dic, lc, configuration)
_, edgeXErr := dbClient.GetUserByUserName("admin")
if edgeXErr != nil {
if errort.Is(errort.AppPasswordError, edgeXErr) {
var wg sync.WaitGroup
wg.Add(6)
go syncQuickNavigation(&wg, dic, lc)
go syncDocTemplate(&wg, dic, lc)
go syncUnitTemplate(&wg, dic, lc)
go syncCategory(&wg, dic, lc)
go syncThingModel(&wg, dic, lc)
go syncDocuments(&wg, dic, lc)
//go initEkuiperStreams(&wg, dic, lc)
wg.Wait()
lc.Infof("initApp end...")
}
}
return true return true
} }
func syncCategory(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) { func initEkuiperStreams(dic *di.Container, lc logger.LoggingClient, configuration *config.ConfigurationStruct) {
defer wg.Done() // time 10s 以保证ekuiper初始化完成
categoryApp := container.CategoryTemplateAppFrom(dic.Get) time.Sleep(10 * time.Second)
req := HttpRequest.NewRequest()
_, err := categoryApp.Sync(context.Background(), "Ireland") r := make(map[string]string)
lc.Infof("sync category start...") r["sql"] = "CREATE STREAM mqtt_stream () WITH (DATASOURCE=\"eventbus/in\", FORMAT=\"JSON\",SHARED = \"true\")"
b, _ := json.Marshal(r)
url := configuration.Clients["Ekuiper"].Address() + "/streams"
resp, err := req.Post(url, b)
if err != nil { if err != nil {
lc.Errorf("sync category fail...") lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
return
} }
lc.Infof("sync category success") lc.Infof("init ekuiper stream start")
lc.Info("ekuiper stream start resp code", resp.StatusCode())
if resp.StatusCode() == 201 {
body, err := resp.Body()
if err != nil {
lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
return
}
if strings.Contains(string(body), "created") {
lc.Infof("init ekuiper stream success")
return
}
} else if resp.StatusCode() == 400 {
body, err := resp.Body()
lc.Infof("init ekuiper stream body", string(body))
if err != nil {
lc.Errorf("init ekuiper stream failed error:%+v", err.Error())
return
}
if strings.Contains(string(body), "already exists") {
lc.Infof("init ekuiper stream plug success")
return
}
} else {
lc.Errorf("init ekuiper stream failed resp code:%+v", resp.StatusCode())
}
} }
func syncUnitTemplate(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) { func DownloadEkuiperKafkaPlug(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) {
defer wg.Done() defer wg.Done()
unitTempApp := container.UnitTemplateAppFrom(dic.Get) req := HttpRequest.NewRequest()
kafkaPlug := make(map[string]string)
_, err := unitTempApp.Sync(context.Background(), "Ireland") kafkaPlug["name"] = "kafka"
lc.Infof("sync unit start") kafkaPlug["file"] = "https://packages.emqx.net/kuiper-plugins/1.10.0/debian/sinks/kafka_amd64.zip"
b, _ := json.Marshal(kafkaPlug)
resp, err := req.Post("http://ekuiper:9081/plugins/sinks", b)
if err != nil { if err != nil {
lc.Errorf("sync unit fail") lc.Errorf("down ekuiper kafka plug failed error:%+v", err.Error())
}
if resp.StatusCode() == 201 {
body, err := resp.Body()
if err != nil {
lc.Errorf("down ekuiper kafka plug failed error:%+v", err.Error())
return
}
if strings.Contains(string(body), "created") {
lc.Infof("down ekuiper kafka plug success")
return
}
} else if resp.StatusCode() == 400 {
body, err := resp.Body()
if err != nil {
lc.Errorf("down ekuiper kafka plug failed error:%+v", err.Error())
return
}
if strings.Contains(string(body), "duplicate") {
lc.Infof("down ekuiper kafka plug success")
return
}
} else {
lc.Errorf("down ekuiper kafka plug failed resp code:%+v", resp.StatusCode())
} }
lc.Infof("sync unit success")
} }
func syncDocTemplate(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) { func DownloadEkuiperTdenginePlug(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) {
defer wg.Done() defer wg.Done()
docApp := container.DocsTemplateAppFrom(dic.Get) req := HttpRequest.NewRequest()
kafkaPlug := make(map[string]interface{})
_, err := docApp.SyncDocs(context.Background(), "Ireland") kafkaPlug["name"] = "tdengine"
lc.Infof("sync doc start") kafkaPlug["file"] = "https://packages.emqx.net/kuiper-plugins/1.10.0/debian/sinks/tdengine_amd64.zip"
kafkaPlug["shellParas"] = []string{"2.4.0.26"}
b, _ := json.Marshal(kafkaPlug)
resp, err := req.Post("http://ekuiper:9081/plugins/sinks", b)
if err != nil { if err != nil {
lc.Errorf("sync doc fail") lc.Errorf("down ekuiper tdengine plug failed error:%+v", err.Error())
} }
lc.Infof("sync doc success") if resp.StatusCode() == 201 {
body, err := resp.Body()
} if err != nil {
lc.Errorf("down ekuiper tdengine plug failed error:%+v", err.Error())
func syncQuickNavigation(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) { return
defer wg.Done() }
quickApp := container.QuickNavigationAppTemplateAppFrom(dic.Get) if strings.Contains(string(body), "created") {
_, err := quickApp.SyncQuickNavigation(context.Background(), "Ireland") lc.Infof("down ekuiper tdengine plug success")
lc.Infof("sync quickNavigation start") return
if err != nil { }
lc.Errorf("sync quickNavigation fail...", err.Error()) } else if resp.StatusCode() == 400 {
body, err := resp.Body()
if err != nil {
lc.Errorf("down ekuiper tdengine plug failed error:%+v", err.Error())
return
}
if strings.Contains(string(body), "duplicate") {
lc.Infof("down ekuiper tdengine plug success")
return
}
} else {
lc.Errorf("down ekuiper tdengine plug failed resp code:%+v", resp.StatusCode())
} }
lc.Infof("sync quickNavigation success")
}
func syncThingModel(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) {
defer wg.Done()
thingModelApp := container.ThingModelTemplateAppFrom(dic.Get)
_, err := thingModelApp.Sync(context.Background(), "Ireland")
lc.Infof("sync thingModel start")
if err != nil {
lc.Errorf("sync thingModel fail...", err.Error())
}
lc.Infof("sync thingModel success")
}
func syncDocuments(wg *sync.WaitGroup, dic *di.Container, lc logger.LoggingClient) {
defer wg.Done()
languageApp := container.LanguageAppNameFrom(dic.Get)
err := languageApp.Sync(context.Background(), "Ireland")
lc.Infof("sync language start")
if err != nil {
lc.Errorf("sync language fail...", err.Error())
}
lc.Infof("sync language success")
} }

View File

@ -76,6 +76,8 @@ func RegisterGateway(engine *gin.Engine, dic *di.Container) {
v1Auth.GET("device-libraries", ctl.DeviceLibrariesSearch) v1Auth.GET("device-libraries", ctl.DeviceLibrariesSearch)
v1Auth.DELETE("device-libraries/:deviceLibraryId", ctl.DeviceLibraryDelete) v1Auth.DELETE("device-libraries/:deviceLibraryId", ctl.DeviceLibraryDelete)
v1Auth.PUT("device-libraries/:deviceLibraryId", ctl.DeviceLibraryUpdate) v1Auth.PUT("device-libraries/:deviceLibraryId", ctl.DeviceLibraryUpdate)
v1Auth.GET("driver-classify", ctl.DeviceClassify)
} }
/*******驱动实例 *******/ /*******驱动实例 *******/
{ {

Binary file not shown.

Binary file not shown.

View File

@ -1 +0,0 @@
MANIFEST-000007

View File

@ -1 +0,0 @@
MANIFEST-000005

View File

@ -1,39 +0,0 @@
=============== Jun 23, 2024 (UTC) ===============
07:28:50.576890 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:28:50.595517 db@open opening
07:28:50.601758 version@stat F·[] S·0B[] Sc·[]
07:28:50.606910 db@janitor F·2 G·0
07:28:50.608077 db@open done T·11.719649ms
07:28:52.124654 db@close closing
07:28:52.125660 db@close done T·1.005394ms
=============== Jun 23, 2024 (UTC) ===============
07:28:58.402544 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:28:58.415412 version@stat F·[] S·0B[] Sc·[]
07:28:58.416824 db@open opening
07:28:58.418046 journal@recovery F·1
07:28:58.419128 journal@recovery recovering @1
07:28:58.430863 version@stat F·[] S·0B[] Sc·[]
07:28:58.545419 db@janitor F·2 G·0
07:28:58.547729 db@open done T·129.962204ms
07:49:44.007188 db@close closing
07:49:44.008431 db@close done T·1.252401ms
=============== Jun 23, 2024 (UTC) ===============
07:52:54.060168 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:52:54.070750 version@stat F·[] S·0B[] Sc·[]
07:52:54.071563 db@open opening
07:52:54.072563 journal@recovery F·1
07:52:54.073517 journal@recovery recovering @2
07:52:54.080468 version@stat F·[] S·0B[] Sc·[]
07:52:54.117002 db@janitor F·2 G·0
07:52:54.117872 db@open done T·45.529864ms
07:52:54.740007 db@close closing
07:52:54.741617 db@close done T·1.607086ms
=============== Jun 23, 2024 (UTC) ===============
07:52:59.485349 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
07:52:59.496162 version@stat F·[] S·0B[] Sc·[]
07:52:59.497367 db@open opening
07:52:59.499105 journal@recovery F·1
07:52:59.500621 journal@recovery recovering @4
07:52:59.511912 version@stat F·[] S·0B[] Sc·[]
07:52:59.534086 db@janitor F·2 G·0
07:52:59.535315 db@open done T·36.592228ms