Skip to content

Commit

Permalink
IJMP-1668- Fix connection logs (#78)
Browse files Browse the repository at this point in the history
* handle connection logs

Signed-off-by: Anatoli Kalbasin <qwnize@outlook.com>
  • Loading branch information
callbacksin authored Sep 18, 2024
1 parent db232f4 commit 880cf4b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zowe zDevOps Jenkins plugin

## About the plugin
## About the plugin
The Zowe zDevOps Jenkins Plugin by [IBA Group](https://ibagroupit.com/?utm_campaign=IBA_W-Mainframe&utm_source=jenkins&utm_medium=referral&utm_content=description_zdevops) is an open-source, secure , and reliable agent-less Jenkins plugin that makes it possible to perform most of the actual tasks on the mainframe, managing it with a modern native mainframe zOSMF REST API and the capabilities of available zOSMF SDKs.

## Advantages
Expand Down
36 changes: 24 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.78</version>
<version>4.78</version> <!-- See https://github.com/jenkinsci/plugin-pom/releases for available versions-->
<relativePath />
</parent>

Expand All @@ -19,7 +19,7 @@


<properties>
<revision>0.2.0-</revision>
<revision>0.2.0</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.414.3</jenkins.version>
<java.version>17</java.version>
Expand Down Expand Up @@ -375,22 +375,12 @@
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down Expand Up @@ -439,6 +429,28 @@
<scope>test</scope>
</dependency>

<!-- Jenkins plug-ins -->

<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
</dependency>

</dependencies>

<repositories>
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/zowe/zdevops/classic/AbstractBuildStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.kohsuke.stapler.QueryParameter
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.config.ZOSConnectionList
import org.zowe.zdevops.utils.validateConnection
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
Expand Down Expand Up @@ -71,6 +72,8 @@ abstract class AbstractBuildStep(val connectionName: String) : Builder(), Simple
connURL.host, connURL.port.toString(), connection.username, connection.password, connURL.protocol
)

validateConnection(zosConnection)

perform(build, launcher, listener, zosConnection)
return true
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/org/zowe/zdevops/config/ZOSConnection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import com.cloudbees.plugins.credentials.common.StandardCredentials
import com.cloudbees.plugins.credentials.common.StandardListBoxModel
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.ZosDsnList
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.input.ListParams
import org.zowe.zdevops.Messages
import org.zowe.zdevops.declarative.jobs.zMessages
import hudson.Extension
import hudson.model.AbstractDescribableImpl
import hudson.model.Descriptor
Expand All @@ -32,6 +28,9 @@ import net.sf.json.JSONObject
import org.kohsuke.stapler.DataBoundConstructor
import org.kohsuke.stapler.QueryParameter
import org.kohsuke.stapler.StaplerRequest
import org.zowe.zdevops.Messages
import org.zowe.zdevops.declarative.jobs.zMessages
import org.zowe.zdevops.utils.getTestDatasetList
import java.io.IOException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
Expand Down Expand Up @@ -119,9 +118,9 @@ constructor(
val testConnection = org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection(
connURL.host, connURL.port.toString(), credentials.username, credentials.password.plainText, connURL.protocol
)
ZosDsnList(testConnection).listDsn(zMessages.zdevops_config_ZOSConnection_validation_testDS(), ListParams())
getTestDatasetList(testConnection)
}.onFailure {
return FormValidation.error(zMessages.zdevops_config_ZOSConnection_validation_error());
return FormValidation.error("${zMessages.zdevops_config_ZOSConnection_validation_error()}\n(${it.message})");
}
return FormValidation.ok(zMessages.zdevops_config_ZOSConnection_validation_success())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import jenkins.tasks.SimpleBuildStep
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.zdevops.Messages
import org.zowe.zdevops.config.ZOSConnectionList
import org.zowe.zdevops.utils.validateConnection
import java.io.PrintWriter
import java.io.StringWriter
import java.net.URL
Expand Down Expand Up @@ -50,6 +51,9 @@ abstract class AbstractZosmfAction : Builder(), SimpleBuildStep {
val zoweConnection = ZOSConnection(
connURL.host, connURL.port.toString(), connection.username, connection.password, connURL.protocol
)

validateConnection(zoweConnection)

runCatching {
perform(run, workspace, env, launcher, listener, zoweConnection)
}.onFailure {
Expand Down
42 changes: 42 additions & 0 deletions src/main/kotlin/org/zowe/zdevops/utils/ConnectionValidation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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
*
* Copyright IBA Group 2024
*/

package org.zowe.zdevops.utils

import hudson.AbortException
import org.zowe.kotlinsdk.zowe.client.sdk.core.ZOSConnection
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.ZosDsnList
import org.zowe.kotlinsdk.zowe.client.sdk.zosfiles.input.ListParams
import org.zowe.zdevops.Messages

/**
* Gets a list of datasets
* Calls the listDsn function of ZosDsnList to list data set names.
* Passes a test data set name ('HELLO.THERE').
*
* @param zosConnection The ZOSConnection object representing the connection to the z/OS system.
*/
fun getTestDatasetList(zosConnection: ZOSConnection) {
ZosDsnList(zosConnection).listDsn(Messages.zdevops_config_ZOSConnection_validation_testDS(), ListParams())
}

/**
* Validates a z/OS connection.
*
* @param zosConnection The ZOSConnection object representing the connection to the z/OS system.
*/
fun validateConnection(zosConnection: ZOSConnection) {
try {
getTestDatasetList(zosConnection)
} catch (connectException: Exception) {
val connExMessage = "Failed to connect to z/OS (${zosConnection.user}@${zosConnection.host}:${zosConnection.zosmfPort}): ${connectException.message}"
throw AbortException(connExMessage)
}
}

0 comments on commit 880cf4b

Please sign in to comment.