-
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
32 changed files
with
1,309 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
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") | ||
} |
48 changes: 48 additions & 0 deletions
48
.../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,48 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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") } | ||
} |
37 changes: 37 additions & 0 deletions
37
.../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,37 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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 | ||
) |
116 changes: 116 additions & 0 deletions
116
...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,116 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.tencent.bkrepo.websocket.config | ||
|
||
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.scheduling.concurrent.ThreadPoolTaskScheduler | ||
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 jwtAuthProperties: JwtAuthProperties, | ||
private val authenticationManager: AuthenticationManager, | ||
private val taskScheduler: ThreadPoolTaskScheduler | ||
) : WebSocketMessageBrokerConfigurer { | ||
|
||
override fun configureMessageBroker(config: MessageBrokerRegistry) { | ||
config.setCacheLimit(webSocketProperties.cacheLimit) | ||
config.enableSimpleBroker("/topic") | ||
.setHeartbeatValue(longArrayOf(3000,3000)) | ||
.setTaskScheduler(taskScheduler) | ||
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, | ||
authenticationManager = authenticationManager, | ||
jwtAuthProperties = jwtAuthProperties | ||
) | ||
} | ||
|
||
@Bean | ||
fun websocketTransferConsumer(transferPushListener: TransferPushListener): Consumer<Message<TransferPush>> { | ||
return Consumer { transferPushListener.accept(it) } | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...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,65 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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" |
Oops, something went wrong.