Skip to content

Commit

Permalink
Merge pull request #8604 from royalhuang/issue_7983_history_page_pref
Browse files Browse the repository at this point in the history
feat:流水线构建详情页重构需求 issue #7983 优化websocket和触发类型
  • Loading branch information
bkci-bot authored May 10, 2023
2 parents 1079e9e + ed1c94d commit 1a1c8b0
Show file tree
Hide file tree
Showing 50 changed files with 476 additions and 359 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
package com.example.bkci_app
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import io.flutter.plugin.common.MethodChannel


class AppInstallReceiver(val methodChannel: MethodChannel) : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
val action: String? = intent.action;
var method: String = "";
val packageName: String? = intent.data?.encodedSchemeSpecificPart;
val action: String? = intent.action
var method: String = ""
val packageName: String? = intent.data?.encodedSchemeSpecificPart

if(action.equals(Intent.ACTION_PACKAGE_ADDED)){
println(packageName + "app installed");
method = "bkPackageInstalled";
} else if(action.equals(Intent.ACTION_PACKAGE_REPLACED)){
println(packageName + "app UPDATED");
method = "bkPackageUpdated";
}else if(action.equals(Intent.ACTION_PACKAGE_REMOVED)){
println(packageName + "app uninstalled");
method = "bkPackageRemove";
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
println(packageName + "app installed")
method = "bkPackageInstalled"
} else if (action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
println(packageName + "app UPDATED")
method = "bkPackageUpdated"
} else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
println(packageName + "app uninstalled")
method = "bkPackageRemove"
}
println(method + ":" + packageName);
println(method + ":" + packageName)
if (methodChannel != null) {
methodChannel.invokeMethod(method, packageName, null);
methodChannel.invokeMethod(method, packageName, null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,94 +20,90 @@ import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.File

class MainActivity : FlutterActivity(), ITLoginAuthListener, ITLoginListener {

class MainActivity: FlutterActivity(), ITLoginAuthListener, ITLoginListener {

private val CHANNEL = "flutter.itlogin";
private var initUniLink: String? = null;
lateinit var methodChannel: MethodChannel;
lateinit var channelResult: MethodChannel.Result;
lateinit var appInstallReceiver: AppInstallReceiver;
lateinit var itloginInstance: ITLoginBaseActivityManager;
private var itloginInited: Boolean = false;

private val channel = "flutter.itlogin"
private var initUniLink: String? = null
lateinit var methodChannel: MethodChannel
lateinit var channelResult: MethodChannel.Result
lateinit var appInstallReceiver: AppInstallReceiver
lateinit var itloginInstance: ITLoginBaseActivityManager
private var itloginInited: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState);
appInstallReceiver = AppInstallReceiver(methodChannel);
val filter = IntentFilter();
filter.addDataScheme("package");
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
super.onCreate(savedInstanceState)

appInstallReceiver = AppInstallReceiver(methodChannel)
val filter = IntentFilter()
filter.addDataScheme("package")
filter.addAction(Intent.ACTION_PACKAGE_ADDED)
filter.addAction(Intent.ACTION_PACKAGE_REMOVED)
filter.addAction(Intent.ACTION_PACKAGE_REPLACED)

this.registerReceiver(appInstallReceiver, filter);
initUniLink = intent?.data?.path;
this.registerReceiver(appInstallReceiver, filter)
initUniLink = intent?.data?.path
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.action === Intent.ACTION_VIEW && methodChannel != null) {
val action: String? = intent?.action
val data: String? = intent?.data?.path;
methodChannel.invokeMethod("uni_link", data, null);
val data: String? = intent?.data?.path
methodChannel.invokeMethod("uni_link", data, null)
}
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {

super.configureFlutterEngine(flutterEngine)
println("configureFlutterEngine main flutter")
methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel)
methodChannel.setMethodCallHandler {
// Note: this method is invoked on the main thread.
call, result ->
channelResult = result;
channelResult = result
if (call.method == "checkITLogin") {
checkITLogin();
result.success("success");
checkITLogin()
result.success("success")
} else if (call.method == "logout") {
ITLoginBaseActivityManager.getInstance().logout(this);
ITLoginBaseActivityManager.getInstance().logout(this)
} else if (call.method == "getCkey") {
val credential: Credential = ITLoginSDK.getLoginInfo(this.applicationContext)
println("println(credential.key);")
println(credential.key);
result.success(credential.key);
println(credential.key)
result.success(credential.key)
} else if (call.method == "installApk") {
installApk(call.arguments());
result.success("success");
installApk(call.arguments())
result.success("success")
} else if (call.method == "initITLogin") {
initITLoginSDK();
initITLoginSDK()
// result.success("success");
} else if (call.method == "getInitUniLink") {
if (initUniLink != null) {
result.success(initUniLink);
initUniLink = null;
result.success(initUniLink)
initUniLink = null
}
} else {
result.notImplemented();
result.notImplemented()
}
}
println("intent?.data?.path");
println(initUniLink);

println("intent?.data?.path")
println(initUniLink)
}

fun initITLoginSDK() {
// println("itlogin on init");
if (!itloginInited) {
// println("itlogin on inited");
itloginInstance.onActivityResume(this);
itloginInited = true;
itloginInstance.onActivityResume(this)
itloginInited = true
}
itloginInstance.logout(this);

itloginInstance.logout(this)
}

fun checkITLogin() {
if (this::itloginInstance.isInitialized) {
itloginInstance.onActivityResume(this);
itloginInstance.validateLogin(this);
itloginInstance.onActivityResume(this)
itloginInstance.validateLogin(this)
}
}

Expand All @@ -123,7 +119,7 @@ class MainActivity: FlutterActivity(), ITLoginAuthListener, ITLoginListener {
this.applicationContext,
this.packageName + ".fileprovider",
apkfile
);
)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -142,13 +138,13 @@ class MainActivity: FlutterActivity(), ITLoginAuthListener, ITLoginListener {
// println("itlogin on resume");
if (!this::itloginInstance.isInitialized) {
// println("itlogin on resumeed");
ITLoginBaseActivityManager.getInstance().init(this);
ITLoginSDK.configITLogin(R.style.itloginpushstyle, "蓝盾登录", R.drawable.ic_itlogin_logo, 100);
itloginInstance = ITLoginBaseActivityManager.getInstance();
itloginInstance.itLoginAuthListener = this;
itloginInstance.itLoginListener = this;
itloginInstance.onActivityCreate(this);
itloginInstance.setLogLevel(3.toByte());
ITLoginBaseActivityManager.getInstance().init(this)
ITLoginSDK.configITLogin(R.style.itloginpushstyle, "蓝盾登录", R.drawable.ic_itlogin_logo, 100)
itloginInstance = ITLoginBaseActivityManager.getInstance()
itloginInstance.itLoginAuthListener = this
itloginInstance.itLoginListener = this
itloginInstance.onActivityCreate(this)
itloginInstance.setLogLevel(3.toByte())
}
}

Expand All @@ -163,20 +159,17 @@ class MainActivity: FlutterActivity(), ITLoginAuthListener, ITLoginListener {
super.onPause()
if (this::itloginInstance.isInitialized && itloginInited) {
// println("itlogin on pause");
itloginInstance.onActivityPause();
itloginInited = false;
itloginInstance.onActivityPause()
itloginInited = false
}

}

override fun onDestroy() {
super.onDestroy()
if (this::itloginInstance.isInitialized && itloginInited) {
itloginInstance.onActivityFinish()

}
unregisterReceiver(appInstallReceiver)

}

override fun finish() {
Expand All @@ -189,51 +182,48 @@ class MainActivity: FlutterActivity(), ITLoginAuthListener, ITLoginListener {
override fun onAuthSuccess() {
// TODO("Not yet implemented")
println("auth success")
handleSuccess();
handleSuccess()
}

fun handleSuccess () {
fun handleSuccess() {
val credential: Credential = ITLoginSDK.getLoginInfo(this.applicationContext)
val sharePrefs: SharedPreferences = this.getSharedPreferences("", Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = sharePrefs.edit();
editor.putString("flutter.cKey", credential.key);
editor.commit();
sendMessageToFlutter(credential.key);
val editor: SharedPreferences.Editor = sharePrefs.edit()
editor.putString("flutter.cKey", credential.key)
editor.commit()
sendMessageToFlutter(credential.key)
}

fun sendMessageToFlutter(cKey: String) {
if (methodChannel != null) {
methodChannel.invokeMethod("loginResult", cKey, null);
methodChannel.invokeMethod("loginResult", cKey, null)
}
}

override fun onAuthFailure(p0: ITLoginError?) {
// TODO("Not yet implemented")
println("auth fail");
println("auth fail")
}

override fun onLoginSuccess() {
// TODO("Not yet implemented")
println("login success")
handleSuccess();
handleSuccess()
}

override fun onLoginFailure(p0: ITLoginError?) {
// TODO("Not yet implemented")
println("login failure");

println("login failure")
}

override fun onFinishLogout(p0: Boolean) {
// TODO("Not yet implemented")
println("logout finish")
channelResult.success("logout success");
channelResult.success("logout success")
}

override fun onLoginCancel() {
// TODO("Not yet implemented")
println("login cancel")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ jooq {
}
}
}

}

tasks.getByName<AbstractCompile>("compileKotlin") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tasks {

named<ShadowJar>("shadowJar") {
mergeServiceFiles()
destinationDirectory.set(File("${rootDir}/release"))
destinationDirectory.set(File("$rootDir/release"))
archiveClassifier.set("")
archiveVersion.set("")
isZip64 = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ data class Stage(
fun resetBuildOption(init: Boolean? = false) {
if (init == true) {
status = null
timeCost = null
startEpoch = null
elapsed = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ data class BuildRecordTimeCost(
var systemCost: Long = 0,
@ApiModelProperty("执行耗时", required = true)
var executeCost: Long = 0,
@ApiModelProperty("等待耗时", required = true)
@ApiModelProperty("等待耗时(包括了排队和等待人工审核操作时间)", required = true)
var waitCost: Long = 0,
@ApiModelProperty("排队耗时(流水线并发、Stage下Job并发和Job互斥)", required = true)
@ApiModelProperty("只处于排队的耗时(流水线并发、Stage下Job并发和Job互斥)", required = true)
var queueCost: Long = 0,
@ApiModelProperty("总耗时(结束时间-开始时间)", required = true)
var totalCost: Long = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ data class BuildPageInfo(
val pipelineId: String?,
val projectId: String?,
val atomId: String?,
val executeCount: String?
val executeCount: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ object BuildTimeCostUtils {
record.containerVar[BuildRecordTimeLine::class.java.simpleName] ?: return@forEach,
object : TypeReference<BuildRecordTimeLine>() {}
)
// 计算等到耗时需要将率先执行完毕的container追加无状态区间
record.endTime?.let {
val fixedMoment = BuildRecordTimeLine.Moment(it.timestampmilli(), endTime.timestampmilli())
containerTimeLine.waitCostMoments.add(fixedMoment)
containerTimeLine.queueCostMoments.add(fixedMoment)
}
// 执行时间取并集
containerExecuteCost = mergeTimeLine(containerExecuteCost, containerTimeLine.executeCostMoments)
val mergedWaitCost = mergeTimeLine(containerTimeLine.waitCostMoments, containerTimeLine.queueCostMoments)
// 等待时间取交集
containerWaitCost = intersectionTimeLine(containerWaitCost, containerTimeLine.waitCostMoments)
containerWaitCost = intersectionTimeLine(containerWaitCost, mergedWaitCost)
// 排队时间取交集
containerQueueCost = intersectionTimeLine(containerQueueCost, containerTimeLine.queueCostMoments)
}
Expand All @@ -105,7 +112,7 @@ object BuildTimeCostUtils {
)
return@sumOf time.between()
} + containerWaitCost.sumOf { it.endTime - it.startTime }
val systemCost = totalCost - executeCost - queueCost - waitCost
val systemCost = totalCost - executeCost - waitCost
return BuildRecordTimeCost(
totalCost = totalCost,
executeCost = executeCost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ object VMUtils {

fun getEndLabel() = "end-"

fun isVMTask(taskId: String) = taskId.startsWith(getStartVmLabel()) ||
taskId.startsWith(getStopVmLabel()) ||
taskId.startsWith(getEndLabel())

fun isMatrixContainerId(containerId: String) = try {
containerId.toInt() > 1000
} catch (ignore: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import io.swagger.annotations.ApiModelProperty
data class BuildId(
@ApiModelProperty("构建ID", required = true)
val id: String,
@ApiModelProperty("当前执行次数")
val executeCount: Int = 1,
@ApiModelProperty("项目ID")
val projectId: String? = null,
@ApiModelProperty("流水线ID")
Expand Down
Loading

0 comments on commit 1a1c8b0

Please sign in to comment.