Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to downloaded datasets in logs after DownloadOperation execution #89

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* Copyright (c) 2023-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
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.classic.steps
Expand Down Expand Up @@ -70,7 +74,8 @@ constructor(
zosConnection: ZOSConnection
) {
val workspace = build.executor?.currentWorkspace!!
downloadDSOrDSMemberByType(dsn, vol, returnEtag, listener, zosConnection, workspace)
val jenkinsJobUrl = build.getEnvironment(listener)["JOB_URL"]
downloadDSOrDSMemberByType(dsn, vol, returnEtag, listener, zosConnection, workspace, jenkinsJobUrl)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/*
* Copyright (c) 2022-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
*
* Copyright IBA Group 2022
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.declarative.jobs

import hudson.*
import hudson.EnvVars
import hudson.Extension
import hudson.FilePath
import hudson.Launcher
import hudson.model.Run
import hudson.model.TaskListener
import org.jenkinsci.Symbol
Expand Down Expand Up @@ -47,7 +54,8 @@ class DownloadFileDeclarative @DataBoundConstructor constructor(val dsn: String)
zosConnection: ZOSConnection
) {
val workspacePath = FilePath(null, workspace.remote.replace(workspace.name,""))
downloadDSOrDSMemberByType(dsn, vol, returnEtag, listener, zosConnection, workspacePath)
val jenkinsJobUrl = env["BUILD_URL"] + "/execution/node/3/"
downloadDSOrDSMemberByType(dsn, vol, returnEtag, listener, zosConnection, workspacePath, jenkinsJobUrl)
}


Expand Down
24 changes: 17 additions & 7 deletions src/main/kotlin/org/zowe/zdevops/logic/DownloadOperation.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/*
* Copyright (c) 2023-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
*
* Copyright IBA Group 2023
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.zdevops.logic

import hudson.AbortException
import hudson.FilePath
import hudson.console.HyperlinkNote
import hudson.model.TaskListener
import org.apache.commons.io.IOUtils
import org.zowe.kotlinsdk.DatasetOrganization
Expand All @@ -36,14 +41,16 @@ import java.io.StringWriter
* @param zosConnection The connection to the z/OS system.
* @param workspace The workspace where the dataset will be downloaded.
* @param listener The listener for capturing task progress and logs.
* @param jenkinsJobUrl The job/pipeline URL
*/
fun downloadDS(
dsn: String,
vol: String?,
returnEtag: Boolean?,
zosConnection: ZOSConnection,
workspace: FilePath,
listener: TaskListener
listener: TaskListener,
jenkinsJobUrl: String?,
) {
var downloadedDSN: InputStream?
try {
Expand All @@ -55,7 +62,8 @@ fun downloadDS(
IOUtils.copy(downloadedDSN, writer, "UTF-8")
val file = File("$workspace\\$dsn")
file.writeText(writer.toString())
listener.logger.println(Messages.zdevops_declarative_DSN_downloaded_success(dsn))
listener.logger.println(Messages.zdevops_declarative_DSN_downloaded_success(
HyperlinkNote.encodeTo("${jenkinsJobUrl}ws/$dsn/*view*/", dsn)))
}

/**
Expand All @@ -67,30 +75,32 @@ fun downloadDS(
* @param listener The listener for capturing task progress and logs.
* @param zosConnection The connection to the z/OS system.
* @param workspace The workspace where the dataset will be downloaded.
* @param jenkinsJobUrl The job/pipeline URL
*/
fun downloadDSOrDSMemberByType(
dsn: String,
vol: String?,
returnEtag: Boolean?,
listener: TaskListener,
zosConnection: ZOSConnection,
workspace: FilePath
workspace: FilePath,
jenkinsJobUrl: String?
) {
listener.logger.println(Messages.zdevops_declarative_DSN_downloading(dsn, vol, zosConnection.host, zosConnection.zosmfPort))
val dsnMemberPattern = Regex("[\\w#\[email protected]]{1,}\\([\\w#\$@]{1,8}\\)") //means it's a PDS member
if (dsn.contains(dsnMemberPattern)) {
downloadDS(dsn, vol, returnEtag, zosConnection, workspace, listener)
downloadDS(dsn, vol, returnEtag, zosConnection, workspace, listener, jenkinsJobUrl)
} else {
val dsnList = ZosDsnList(zosConnection).listDsn(dsn, ListParams(vol))
if (dsnList.items.isEmpty()) {
throw AbortException("Can't find $dsn ${ if(vol.isNullOrBlank()) "" else "on volume $vol"}")
}
when (dsnList.items.first().datasetOrganization) {
DatasetOrganization.PS -> downloadDS(dsn, vol, returnEtag, zosConnection, workspace, listener)
DatasetOrganization.PS -> downloadDS(dsn, vol, returnEtag, zosConnection, workspace, listener, jenkinsJobUrl)
DatasetOrganization.PO, DatasetOrganization.POE -> {
listener.logger.println(Messages.zdevops_declarative_DSN_downloading_members(dsn))
ZosDsnList(zosConnection).listDsnMembers(dsn, ListParams(vol)).items.forEach {
downloadDS("${dsn}(${it.name})", vol, returnEtag, zosConnection, workspace, listener)
downloadDS("${dsn}(${it.name})", vol, returnEtag, zosConnection, workspace, listener, jenkinsJobUrl)
}
}
else -> listener.logger.println(Messages.zdevops_declarative_DSN_downloading_invalid_dsorg())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
package org.zowe.zdevops.classic.steps

import hudson.AbortException
import hudson.EnvVars
import hudson.FilePath
import hudson.model.Executor
import hudson.model.Item
import hudson.model.TaskListener
import hudson.util.FormValidation
import io.kotest.assertions.assertSoftly
import io.kotest.assertions.fail
Expand Down Expand Up @@ -68,6 +70,12 @@ class DownloadDatasetStepSpec : ShouldSpec({
every { mockInstance.currentWorkspace } returns FilePath(virtualChannel, mockDir.absolutePath)
return mockInstance
}

override fun getEnvironment(log: TaskListener): EnvVars {
val env = EnvVars()
env["JOB_URL"] = "TEST"
return env
}
}

afterEach {
Expand Down