Skip to content

Commit

Permalink
GH-292 Configs rework
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Feb 19, 2025
1 parent 3e397bb commit fc53339
Show file tree
Hide file tree
Showing 69 changed files with 4,739 additions and 180 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ tasks {

testLogging {
events("passed", "skipped", "failed")
// showStandardStreams = true
}

// ignoreFailures = true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ junit-platform = "1.11.3"
junit-jupiter = "5.11.3"
remoterobot = "0.11.23"
okhttp3 = "4.12.0"
mockk = "1.13.12"
mockk = "1.13.16"
kotest = "5.9.1"
jgrapht = "1.5.2"
keytar = "1.0.0"
Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/org/zowe/explorer/config/ConfigSandboxImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.zowe.explorer.utils.crudable.EntityWithUuid
import org.zowe.explorer.utils.crudable.ReloadableEventHandler
import org.zowe.explorer.utils.isThe
import org.zowe.explorer.utils.isTheSameAs
import org.zowe.explorer.v3.state.config.migration.performOldConfigStorageMigration

/** Stateful class to represent the plugin configs sandbox */
data class SandboxState(
Expand Down Expand Up @@ -148,6 +149,7 @@ class ConfigSandboxImpl : ConfigSandbox {
}
} else {
ConfigService.getService().crudable.replaceGracefully(clazz, list.stream())
performOldConfigStorageMigration()
}
}
}
Expand All @@ -157,10 +159,6 @@ class ConfigSandboxImpl : ConfigSandbox {
/** Fetch the config service values to the config sandbox for each config class */
override fun fetch() {
synchronized(stateLock) {
// rollbackSandbox<ConnectionConfig>()
// rollbackSandbox<FilesWorkingSetConfig>()
// rollbackSandbox<JesWorkingSetConfig>()
// rollbackSandbox<Credentials>()
ConfigService.getService()
.getRegisteredConfigClasses()
.forEach {
Expand All @@ -176,7 +174,6 @@ class ConfigSandboxImpl : ConfigSandbox {
* Triggers the onReload event when the rollback is finished
* @param clazz the class of configs to rollback in the config sandbox
*/
@Suppress("UNCHECKED_CAST")
override fun <T> rollback(clazz: Class<out T>) {
synchronized(stateLock) {
val current = if (clazz.isThe<Credentials>()) {
Expand All @@ -196,6 +193,7 @@ class ConfigSandboxImpl : ConfigSandbox {
listOfNotNull(classToList(clazz, state), classToList(clazz, initialState))
.forEach { list ->
list.clear()
@Suppress("UNCHECKED_CAST")
list.addAll(
current
.map { it.clone(clazz) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
import com.jetbrains.rd.util.UUID
import org.zowe.explorer.config.connect.Credentials
import org.zowe.explorer.utils.castOrNull
import org.zowe.explorer.utils.crudable.AddFilter
import org.zowe.explorer.utils.crudable.ConcurrentCrudable
import org.zowe.explorer.utils.crudable.Crudable
import org.zowe.explorer.utils.crudable.CrudableLists
import org.zowe.explorer.utils.crudable.SimpleReadWriteAdapter
import org.zowe.explorer.utils.crudable.UpdateFilter
import org.zowe.explorer.utils.crudable.*
import org.zowe.explorer.utils.loadConfigClass
import org.zowe.explorer.utils.runIfTrue
import java.time.Duration
Expand Down
25 changes: 21 additions & 4 deletions src/main/kotlin/org/zowe/explorer/config/ConfigStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,34 @@ package org.zowe.explorer.config

import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import org.zowe.explorer.v3.state.config.cache.ConfigCacheService
import org.zowe.explorer.v3.state.config.migration.performOldConfigStorageMigration
import org.zowe.explorer.v3.state.settings.OtherSettingsService
import org.zowe.explorer.v3.state.storage.StableStorage
import org.zowe.explorer.v3.state.storage.StorageService

/**
* Activity to prepare configs.
* @author Valiantsin Krus.
* Activity to prepare config services before the project startup.
* Will load [StorageService] and [ConfigCacheService],
* together with the previously saved configs from the related XML file.
*
* DEPRECATED: (The next functionality will be deleted in the future)
* Will load [ConfigService] together with the previously saved configs from the related XML file
*/
class ConfigStartupActivity : ProjectActivity {

/** Registers all config classes and migrate configs to state v2. */
@OptIn(StableStorage::class)
override suspend fun execute(project: Project) {
ConfigService.getService().apply {
registerAllConfigClasses()
}
// The next line is needed to initialize subscriptions to storage service events.
// WARNING: it is necessary to initialize the cache service together with the storage service!
ConfigCacheService.getService()
// The next line is needed to initialize subscriptions to storage service events.
// WARNING: it is necessary to initialize the other settings service together with the storage service!
OtherSettingsService.getService()
StorageService.getService().registerConfigTypes()

performOldConfigStorageMigration()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.zowe.explorer.v3.operations.OperationsService
import org.zowe.explorer.v3.operations.RenameOperationData
import org.zowe.explorer.vfs.MFVirtualFile

typealias ConnectionConfigNew = org.zowe.explorer.v3.ConnectionConfig
typealias ConnectionConfigNew = org.zowe.explorer.v3.ConnectionConfigOldStruct
typealias UssRequesterNew = org.zowe.explorer.v3.UssRequester<ConnectionConfigNew>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock

/**
* Class that implements abstract read/write lock adapter class.
* Triggers reentrant read/write lock on read or write lock
* Triggers reentrant read/write lock on read/write lock getter
*/
class SimpleReadWriteAdapter : ReadWriteLocksAdapter() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,26 @@
package org.zowe.explorer.v3

import org.zowe.explorer.utils.crudable.annotations.Column
import org.zowe.explorer.v3.state.config.Config
import org.zowe.explorer.v3.state.config.ConfigType
import org.zowe.kotlinsdk.annotations.ZVersion

// TODO: tags
// TODO: clarify abstraction
/**
* Connection config based class. Could be used as a basic connection config representation or as a base for other
* connection config type
* @param uuid the unique UUID of the entity
* @param name the name of the connection config
* @param url the URL for the connection config
* @param isAllowSelfSigned to indicate whether it is allowed to use self-signed certificates during a connection
* @param zVersion the version of the z/OS being used for the connection
* @param owner the actual USS user related to the USS user provided in the connection to work with in the USS part
*/
open class ConnectionConfig(
open class ConnectionConfigOldStruct(
uuid: String = EMPTY_ID,
@Column var name: String = "",
@Column var url: String = "",
@Column var isAllowSelfSigned: Boolean = true,
@Column var zVersion: ZVersion = ZVersion.ZOS_2_3,
@Column var owner: String = ""
) : EntityWithUuid(uuid) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false

other as ConnectionConfig

if (name != other.name) return false
if (url != other.url) return false
if (isAllowSelfSigned != other.isAllowSelfSigned) return false
if (zVersion != other.zVersion) return false
if (owner != other.owner) return false

return true
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + url.hashCode()
result = 31 * result + isAllowSelfSigned.hashCode()
result = 31 * result + zVersion.hashCode()
result = 31 * result + owner.hashCode()
return result
}

override fun toString(): String {
return "ConnectionConfig(name='$name', url='$url', isAllowSelfSigned=$isAllowSelfSigned, zVersion=$zVersion, owner=$owner)"
}

}
) : Config(uuid, configType = ConfigType.HTTP_CONNECTION_CONFIG_V1)
31 changes: 13 additions & 18 deletions src/main/kotlin/org/zowe/explorer/v3/EntityWithUuid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,26 @@
*/
package org.zowe.explorer.v3

import org.zowe.explorer.utils.crudable.annotations.Column
import com.intellij.util.xmlb.annotations.Attribute
import java.util.*

/**
* Class that represents an entity with UUID
* @param uuid the UUID of the entity
* @property uuid the UUID of the entity
*/
abstract class EntityWithUuid(@Column(unique = true) var uuid: String = EMPTY_ID) {
abstract class EntityWithUuid(
@get:Attribute
var uuid: String = EMPTY_ID
) {

companion object {
const val EMPTY_ID = ""
}

override fun hashCode(): Int {
return uuid.hashCode()
init {
if (uuid == EMPTY_ID) {
uuid = UUID.randomUUID().toString()
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
val that = other as EntityWithUuid
return uuid == that.uuid
}

override fun toString(): String {
return "EntityWithUuid{uuid='$uuid'}"
companion object {
const val EMPTY_ID = ""
}

}
2 changes: 1 addition & 1 deletion src/main/kotlin/org/zowe/explorer/v3/Requester.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package org.zowe.explorer.v3
* Interface to track requests origins. Represents the elements that requested a related data
* @property connectionConfig the related connection config
*/
interface Requester<ConnectionConfigType : ConnectionConfig> {
interface Requester<ConnectionConfigType : ConnectionConfigOldStruct> {
val connectionConfig: ConnectionConfigType
}
35 changes: 35 additions & 0 deletions src/main/kotlin/org/zowe/explorer/v3/SupportedSchemes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.explorer.v3

/**
* Supported schemes for a mainframe connection
* @param scheme a scheme string representation
*/
enum class SupportedSchemes(val scheme: String) {
HTTP("http"),
HTTPS("https"),
UNSUPPORTED("unsupported scheme");

companion object {
operator fun invoke(scheme: String): SupportedSchemes {
return entries.find { it.scheme == scheme } ?: UNSUPPORTED
}
}

override fun toString(): String {
return scheme
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/org/zowe/explorer/v3/UssRequester.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
package org.zowe.explorer.v3

/** Class to track USS requests origins */
class UssRequester<ConnectionConfigType : ConnectionConfig>(
class UssRequester<ConnectionConfigType : ConnectionConfigOldStruct>(
override val connectionConfig: ConnectionConfigType
) : Requester<ConnectionConfigType>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

package org.zowe.explorer.v3.operations

import org.zowe.explorer.v3.ConnectionConfig
import org.zowe.explorer.v3.ConnectionConfigOldStruct
import org.zowe.explorer.v3.Requester

/**
* Interface to describe an operation data
* @property resultClass the result class of the result that should be returned after an operation execution
* @property origin the exact operation requester to distinguish the source of the operation request
*/
interface OperationData<Result, ConnectionConfigType : ConnectionConfig> {
interface OperationData<Result, ConnectionConfigType : ConnectionConfigOldStruct> {
val resultClass: Class<out Result>
val origin: Requester<ConnectionConfigType>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package org.zowe.explorer.v3.operations

import com.intellij.openapi.progress.DumbProgressIndicator
import com.intellij.openapi.progress.ProgressIndicator
import org.zowe.explorer.v3.ConnectionConfig
import org.zowe.explorer.v3.ConnectionConfigOldStruct

/**
* Base abstract class to represent operation runner
* @property operationDataClass the operation class supported by the operation runner
* @property resultClass the result class of the operation
*/
abstract class OperationRunner<R : Any, C : ConnectionConfig, O : OperationData<R, C>> {
abstract class OperationRunner<R : Any, C : ConnectionConfigOldStruct, O : OperationData<R, C>> {

abstract val operationDataClass: Class<out OperationData<*, *>>

Expand Down
Loading

0 comments on commit fc53339

Please sign in to comment.