-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
903 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED " AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
dependencies { | ||
api(project(":common:common-stream")) | ||
api(project(":common:common-service")) | ||
api(project(":common:common-artifact:artifact-service")) | ||
implementation("org.springframework.boot:spring-boot-starter-websocket") | ||
implementation("javax.websocket:javax.websocket-api") | ||
implementation("io.undertow:undertow-servlet") | ||
implementation("io.undertow:undertow-websockets-jsr") | ||
} |
21 changes: 21 additions & 0 deletions
21
.../biz-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/config/WebSocketConfigurer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.tencent.bkrepo.websocket.config | ||
|
||
import com.tencent.bkrepo.common.artifact.config.ArtifactConfigurerSupport | ||
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType | ||
import com.tencent.bkrepo.common.artifact.repository.local.LocalRepository | ||
import com.tencent.bkrepo.common.artifact.repository.remote.RemoteRepository | ||
import com.tencent.bkrepo.common.artifact.repository.virtual.VirtualRepository | ||
import com.tencent.bkrepo.common.security.http.core.HttpAuthSecurityCustomizer | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class WebSocketConfigurer : ArtifactConfigurerSupport() { | ||
|
||
override fun getRepositoryType() = RepositoryType.NONE | ||
override fun getLocalRepository(): LocalRepository = object : LocalRepository() {} | ||
override fun getRemoteRepository(): RemoteRepository = object : RemoteRepository() {} | ||
override fun getVirtualRepository(): VirtualRepository = object : VirtualRepository() {} | ||
|
||
override fun getAuthSecurityCustomizer() = | ||
HttpAuthSecurityCustomizer { httpAuthSecurity -> httpAuthSecurity.withPrefix("/websocket") } | ||
} |
10 changes: 10 additions & 0 deletions
10
.../biz-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/config/WebSocketProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tencent.bkrepo.websocket.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties("websocket") | ||
data class WebSocketProperties( | ||
var cacheLimit: Int = 3600, | ||
var minThread: Int = 8, | ||
var transfer: Boolean = false | ||
) |
88 changes: 88 additions & 0 deletions
88
...z-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/config/WebsocketConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.tencent.bkrepo.websocket.config | ||
|
||
import com.tencent.bkrepo.common.redis.RedisOperation | ||
import com.tencent.bkrepo.common.security.http.jwt.JwtAuthProperties | ||
import com.tencent.bkrepo.common.security.manager.AuthenticationManager | ||
import com.tencent.bkrepo.websocket.constant.APP_ENDPOINT | ||
import com.tencent.bkrepo.websocket.constant.USER_ENDPOINT | ||
import com.tencent.bkrepo.websocket.dispatch.push.TransferPush | ||
import com.tencent.bkrepo.websocket.handler.SessionWebSocketHandlerDecoratorFactory | ||
import com.tencent.bkrepo.websocket.listener.TransferPushListener | ||
import com.tencent.bkrepo.websocket.service.WebsocketService | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.messaging.Message | ||
import org.springframework.messaging.simp.config.ChannelRegistration | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer | ||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration | ||
import java.util.function.Consumer | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
@EnableConfigurationProperties(WebSocketProperties::class) | ||
class WebsocketConfiguration( | ||
private val webSocketProperties: WebSocketProperties, | ||
private val websocketService: WebsocketService, | ||
private val redisOperation: RedisOperation, | ||
private val jwtAuthProperties: JwtAuthProperties, | ||
private val authenticationManager: AuthenticationManager, | ||
) : WebSocketMessageBrokerConfigurer { | ||
|
||
override fun configureMessageBroker(config: MessageBrokerRegistry) { | ||
config.setCacheLimit(webSocketProperties.cacheLimit) | ||
config.enableSimpleBroker("/topic") | ||
config.setApplicationDestinationPrefixes("/app") | ||
} | ||
|
||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { | ||
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT) | ||
.setAllowedOriginPatterns("*") | ||
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT) | ||
.setAllowedOriginPatterns("*") | ||
.withSockJS() | ||
} | ||
|
||
@Override | ||
override fun configureClientInboundChannel(registration: ChannelRegistration) { | ||
var defaultCorePoolSize = webSocketProperties.minThread | ||
if (defaultCorePoolSize < Runtime.getRuntime().availableProcessors() * 2) { | ||
defaultCorePoolSize = Runtime.getRuntime().availableProcessors() * 2 | ||
} | ||
registration.taskExecutor().corePoolSize(defaultCorePoolSize) | ||
.maxPoolSize(defaultCorePoolSize * 2) | ||
.keepAliveSeconds(60) | ||
} | ||
|
||
@Override | ||
override fun configureClientOutboundChannel(registration: ChannelRegistration) { | ||
var defaultCorePoolSize = webSocketProperties.minThread | ||
if (defaultCorePoolSize < Runtime.getRuntime().availableProcessors() * 2) { | ||
defaultCorePoolSize = Runtime.getRuntime().availableProcessors() * 2 | ||
} | ||
registration.taskExecutor().corePoolSize(defaultCorePoolSize).maxPoolSize(defaultCorePoolSize * 2) | ||
} | ||
|
||
override fun configureWebSocketTransport(registration: WebSocketTransportRegistration) { | ||
registration.addDecoratorFactory(wsHandlerDecoratorFactory()) | ||
super.configureWebSocketTransport(registration) | ||
} | ||
|
||
@Bean | ||
fun wsHandlerDecoratorFactory(): SessionWebSocketHandlerDecoratorFactory { | ||
return SessionWebSocketHandlerDecoratorFactory( | ||
websocketService = websocketService, | ||
redisOperation = redisOperation, | ||
authenticationManager = authenticationManager, | ||
jwtAuthProperties = jwtAuthProperties | ||
) | ||
} | ||
|
||
@Bean | ||
fun websocketTransferConsumer(transferPushListener: TransferPushListener): Consumer<Message<TransferPush>> { | ||
return Consumer { transferPushListener.accept(it) } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...main/kotlin/com/tencent/bkrepo/websocket/config/WsThreadPoolTaskExeccutorConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.tencent.bkrepo.websocket.config | ||
|
||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration | ||
import org.springframework.boot.task.TaskExecutorBuilder | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Lazy | ||
import org.springframework.context.annotation.Primary | ||
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor | ||
|
||
/** | ||
* Websocket会注册自定义的ThreadPoolTaskExecutor | ||
* | ||
* [org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration.clientInboundChannelExecutor] | ||
* | ||
* [org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration.clientOutboundChannelExecutor] | ||
* | ||
* [org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration.brokerChannelExecutor] | ||
* | ||
* 导致默认的ThreadPoolTaskExecutor不会实例化 | ||
* | ||
* [org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.applicationTaskExecutor] | ||
* | ||
*/ | ||
@Configuration | ||
class WsThreadPoolTaskExeccutorConfiguration { | ||
|
||
@Lazy | ||
@Bean(name = [ | ||
TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, | ||
AsyncAnnotationBeanPostProcessor.DEFAULT_TASK_EXECUTOR_BEAN_NAME | ||
]) | ||
@Primary | ||
fun applicationTaskExecutor(builder: TaskExecutorBuilder): ThreadPoolTaskExecutor { | ||
return builder.build() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...cket/biz-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/constant/WebsocketKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bkrepo.websocket.constant | ||
|
||
const val USER_ENDPOINT = "/ws/user" | ||
const val APP_ENDPOINT = "/ws/app" | ||
|
||
const val SESSION_ID = "sessionId" |
25 changes: 25 additions & 0 deletions
25
...-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/controller/ClipboardController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.tencent.bkrepo.websocket.controller | ||
|
||
import com.tencent.bkrepo.websocket.pojo.fs.CopyPDU | ||
import com.tencent.bkrepo.websocket.pojo.fs.PastePDU | ||
import com.tencent.bkrepo.websocket.service.ClipboardService | ||
import org.springframework.messaging.handler.annotation.MessageMapping | ||
import org.springframework.stereotype.Controller | ||
|
||
@Controller | ||
@MessageMapping("/clipboard") | ||
class ClipboardController( | ||
private val clipboardService: ClipboardService | ||
) { | ||
|
||
@MessageMapping("/copy") | ||
fun copy(copyPDU: CopyPDU) { | ||
clipboardService.copy(copyPDU) | ||
} | ||
|
||
@MessageMapping("/paste") | ||
fun paste(pastePDU: PastePDU) { | ||
clipboardService.paste(pastePDU) | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
...bsocket/biz-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/dispatch/Dispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bkrepo.websocket.dispatch | ||
|
||
/** | ||
* 下发接口 | ||
*/ | ||
interface Dispatcher<T> { | ||
|
||
fun dispatch(data: T) | ||
} |
27 changes: 27 additions & 0 deletions
27
...t/biz-websocket/src/main/kotlin/com/tencent/bkrepo/websocket/dispatch/TransferDispatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.tencent.bkrepo.websocket.dispatch | ||
|
||
import com.tencent.bkrepo.common.api.util.toJsonString | ||
import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier | ||
import com.tencent.bkrepo.websocket.config.WebSocketProperties | ||
import com.tencent.bkrepo.websocket.dispatch.push.TransferPush | ||
import org.springframework.messaging.simp.SimpMessagingTemplate | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TransferDispatch( | ||
private val messageSupplier: MessageSupplier, | ||
private val simpMessagingTemplate: SimpMessagingTemplate, | ||
private val webSocketProperties: WebSocketProperties | ||
) : Dispatcher<TransferPush> { | ||
override fun dispatch(data: TransferPush) { | ||
if (webSocketProperties.transfer) { | ||
messageSupplier.delegateToSupplier(data, topic = TOPIC) | ||
} else { | ||
simpMessagingTemplate.convertAndSend(data.topic, data.data.toJsonString()) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TOPIC = "websocket-transfer-out-0" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...bsocket/src/main/kotlin/com/tencent/bkrepo/websocket/dispatch/push/CopyPDUTransferPush.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tencent.bkrepo.websocket.dispatch.push | ||
|
||
import com.tencent.bkrepo.websocket.pojo.fs.CopyPDU | ||
|
||
class CopyPDUTransferPush( | ||
copyPDU: CopyPDU, | ||
) : TransferPush( | ||
topic = "/topic/clipboard/copy/${copyPDU.workspaceName}", | ||
data = copyPDU | ||
) |
10 changes: 10 additions & 0 deletions
10
...socket/src/main/kotlin/com/tencent/bkrepo/websocket/dispatch/push/PastePDUTransferPush.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tencent.bkrepo.websocket.dispatch.push | ||
|
||
import com.tencent.bkrepo.websocket.pojo.fs.PastePDU | ||
|
||
class PastePDUTransferPush( | ||
pastePDU: PastePDU, | ||
) : TransferPush( | ||
topic = "/topic/clipboard/paste/${pastePDU.workspaceName}", | ||
data = pastePDU | ||
) |
Oops, something went wrong.