<% '===================================================== ' release_changed.asp '===================================================== %> <% ' Release Change Mode Const enumRELEASE_CHANGE_MODE_PKG_ADDED = 1 'Package added to release Const enumRELEASE_CHANGE_MODE_PKG_REMOVED = 2 'Package removed from release Const enumRELEASE_CHANGE_MODE_PKG_RELEASED = 3 'Package released Class ReleaseChanged private m_pkg_name private m_pkg_version private m_pkg_id private m_proj_id Private m_dlocked Private m_data_collected Public last_resultCode Public last_errorMsg '----------------------------------------------------------------------------------------------------------------- ' Init class variables Private Sub Class_Initialize() m_data_collected = false last_resultCode = -1 last_errorMsg = "" End Sub '----------------------------------------------------------------------------------------------------------------- ' Queue up an action to be performed by a task running on the pkg_archive server ' Decouples the Database from the File Server ' Private Sub trigger_action(rtag_id, pv_id, sChange) ' OraDatabase.Parameters.Add "RTAG_ID", rtag_id, ORAPARM_INPUT, ORATYPE_NUMBER ' OraDatabase.Parameters.Add "PV_ID", pv_id, ORAPARM_INPUT, ORATYPE_NUMBER ' OraDatabase.Parameters.Add "MODE", sChange, ORAPARM_INPUT, ORATYPE_VARCHAR2 ' OraDatabase.Parameters.Add "USER_ID", objAccessControl.UserId, ORAPARM_INPUT, ORATYPE_NUMBER ' ' ' objEH.ErrorRedirect = FALSE ' objEH.TryORA ( OraSession ) ' On Error Resume Next ' ' OraDatabase.ExecuteSQL "BEGIN PK_TRIGGERS.log_action( :RTAG_ID, :PV_ID, :MODE, :USER_ID, null);END;" ' ' objEH.CatchORA ( OraSession ) ' ' OraDatabase.Parameters.Remove "RTAG_ID" ' OraDatabase.Parameters.Remove "PV_ID" ' OraDatabase.Parameters.Remove "MODE" ' OraDatabase.Parameters.Remove "USER_ID" ' ' If objEH.LastOraFailed Then ' Report_Event enumEVENT_ERROR, "trigger_action", objEH.MessageSummary, objEH.MessageDetails ' End If End Sub '----------------------------------------------------------------------------------------------------------------- ' Retrieves package infomation for the specified package version ' This information is required for the make_release_changed script Public Sub Get_Package_Info (artag_id,apv_id) Dim ssql, rsTemp On Error Resume Next m_data_collected = false ' Get package information ssql = _ " SELECT pv.pkg_id,pk.pkg_name,pv.pkg_version,rt.proj_id,pv.dlocked"&_ " FROM package_versions pv, packages pk, release_tags rt"&_ " WHERE" &_ " pv.pv_id = " & apv_id &_ " AND pv.pkg_id = pk.pkg_id" &_ " AND rt.rtag_id = " & artag_id Set rsTemp = OraDatabase.CreateDynaset( ssql, cint(0)) If Err.Number <> 0 Then last_resultCode = Err.Number last_errorMsg = Err.Description & ":" & ssql Exit Sub End If If ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF)) Then m_pkg_name = rsTemp("pkg_name") m_pkg_version = rsTemp("pkg_version") m_pkg_id = rsTemp("pkg_id") m_proj_id = rsTemp("proj_id") m_dlocked = rsTemp("dlocked") m_data_collected = true Else last_resultCode = 8 last_errorMsg = "Error getting package information. PV_ID:" & APV_ID & " not found in. RTAG_ID:" & artag_id Err.Raise 8, "release_changed.asp", last_errorMsg 'Call RaiseMsg ( enum_MSG_ERROR, Err.description ) End If rsTemp.Close Set rsTemp = Nothing End Sub '----------------------------------------------------------------------------------------------------------------- ' Perform the Run_ReleaseChanged function on a list of packages ' ' Args: artag_id - Release Identifier ' apv_id_list - Package Identifiers. A comma separated list of pv_id's ' amode_id - Mode of indication. One of enumRELEASE_CHANGE_MODE_* ' Sub Run_ReleaseChanged_List(artag_id,apv_id_list,amode_id) Dim pv_id, idArr idArr = Split(apv_id_list,",") For Each pv_id in idArr If IsReleased(artag_id,pv_id) Then Call Run_ReleaseChanged(artag_id,pv_id,amode_id,true) End If Next End Sub '----------------------------------------------------------------------------------------------------------------- ' Run a job on the package server to indicate that a package has been ' released. The primary purpose of this is to trigger a BLAT package transfer ' ' Perhaps it could be done via the RM Database ' ie: Have a table of blat requests. Then we have no need to perform this slow ' operation. ' ' Uses ssh to communicate with the archive server and run the unix script, make_release_changed ' ' Args: artag_id - Release Identifier ' apv_id - Package Identifier ' amode_id - Mode of indication. One of enumRELEASE_CHANGE_MODE_* ' aget_info - Boolean: true if we need to populate the global variables with pkg info ' Sub Run_ReleaseChanged(artag_id,apv_id,amode_id,aget_info) Dim pArchive_Path, sudoCmd, rv pArchive_Path = "dpkg_archive" last_resultCode = -1 if aget_info then Call Get_Package_Info (artag_id,apv_id) If Err.Number <> 0 Then Report_Event enumEVENT_ERROR, "make_release_changed", last_errorMsg, "Get_Package_Info:" & Err.Description Exit Sub End If end if ' Ensure that we have some data If not m_data_collected Then Report_Event enumEVENT_ERROR, "make_release_changed", "", "Package Info not present" Exit Sub End If ' Build up the command line to the target script ' Note: DoubleQuotes quotes will be escaped \" ' Double space will be process as for error reporting ' Chr(92) == \ ' Chr(34) == " ' Chr(39) = ' sudoCmd = "~/sbin/make_release_changed" &_ " archive=" & pArchive_Path &_ " pkg_name='" & Chr(34) & m_pkg_name & Chr(34) & "'" &_ " pkg_version='" & Chr(34) & m_pkg_version & Chr(34) & "'" &_ " rtag_id="& artag_id &_ " pkg_id=" & m_pkg_id &_ " pv_id="& apv_id &_ " proj_id="& m_proj_id &_ " mode_id="& amode_id ' Execute the command rv = ExecuteRemoteCommand(sudoCmd) ' ' Report Errors ' 105 - Package not in archive. Not a real issue If rv = 0 OR rv = 105 Then last_resultCode = 0 Else last_resultCode = 1 Report_Event enumEVENT_ERROR, "make_release_changed", Replace(sudoCmd," ", VBNewLine), "Remote command on pkg server reported:" & rv End If ' ' New mechanism ' Create an action trigger ' Dim sMode If amode_id = enumRELEASE_CHANGE_MODE_PKG_ADDED Then sMode = "add" ElseIf amode_id = enumRELEASE_CHANGE_MODE_PKG_REMOVED Then sMode = "delete" Else sMode = "new_version" End If Call trigger_action (artag_id, apv_id, sMode) End Sub '----------------------------------------------------------------------------------------------------------------------------- ' Get the package are in which the package version resides (ie wip, planned, released) Function Get_Pkg_Area (artagId, apvId) OraDatabase.Parameters.Add "RTAG_ID", artagId, ORAPARM_INPUT, ORATYPE_NUMBER OraDatabase.Parameters.Add "PV_ID", apvId, ORAPARM_INPUT, ORATYPE_NUMBER OraDatabase.Parameters.Add "PKG_AREA", -1, ORAPARM_OUTPUT,ORATYPE_NUMBER OraDatabase.ExecuteSQL _ "BEGIN "&_ " :PKG_AREA := PK_ENVIRONMENT.GET_PACKAGE_AREA ( :PV_ID, :RTAG_ID ); "&_ "END; " Get_Pkg_Area = OraDatabase.Parameters("PKG_AREA").Value OraDatabase.Parameters.Remove "RTAG_ID" OraDatabase.Parameters.Remove "PV_ID" OraDatabase.Parameters.Remove "PKG_AREA" End Function '----------------------------------------------------------------------------------------------------------------------------- ' Returns TRUE if the specified package is released Function IsReleased (artagId, apvId) IsReleased = (CInt(Get_Pkg_Area(artagId, apvId)) = CInt(enum_PKG_AREA_RELEASED)) End Function '----------------------------------------------------------------------------------------------------------------- ' Test Access to the package server ' Uses a dedicated script on the target ' Sub TestAccess(sMsg) Dim sudoCmd, rv last_resultCode = -1 ' Execute the command rv = ExecuteRemoteCommand("~/sbin/make_test_access " & sMsg) ' ' Report Errors. Expecting a '55' ' If rv = 55 Then last_resultCode = 0 Else last_resultCode = 1 last_errorMsg = "Result Code: " & rv End If End Sub '----------------------------------------------------------------------------------------------------------------- ' Make the Package Writable ' Primary Purpose is to make a 'Patch' wriable in dpkg_archive ' Uses a dedicated script on the target ' Sub MakeWritable(artag_id, apv_id) Dim pArchive_Path, sudoCmd, rv pArchive_Path = "dpkg_archive" last_resultCode = -1 Call Get_Package_Info (artag_id,apv_id) If Err.Number <> 0 Then Report_Event enumEVENT_ERROR, "make_writable", last_errorMsg, "Get_Package_Info:" & Err.Description Exit Sub End If ' Ensure that we have some data If not m_data_collected Then Report_Event enumEVENT_ERROR, "make_writable", "", "Package Info not present" Exit Sub End If ' Build up the command line to the target script ' Note: DoubleQuotes quotes will be escaped \" ' Double space will be process as for error reporting ' Chr(92) == \ ' Chr(34) == " ' Chr(39) = ' sudoCmd = "~/sbin/make_writable" &_ " " & pArchive_Path &_ " '" & m_pkg_name & "'" &_ " '" & m_pkg_version & "'" ' Execute the command rv = ExecuteRemoteCommand(sudoCmd) ' ' Report Errors If rv = 0 Then last_resultCode = 0 Else last_resultCode = 1 Report_Event enumEVENT_ERROR, "make_writable", Replace(sudoCmd," ", VBNewLine), "Remote command on pkg server reported:" & rv End If ' ' New mechanism Call trigger_action (artag_id, apv_id, "make_writable") End Sub '----------------------------------------------------------------------------------------------------------------- ' Make the Package UnWritable ' Primary Purpose is to make a 'Patch' wriable in dpkg_archive ' Uses a dedicated script on the target ' Sub MakeReadOnly(artag_id, apv_id) Dim pArchive_Path, sudoCmd, rv pArchive_Path = "dpkg_archive" last_resultCode = -1 Call Get_Package_Info (artag_id,apv_id) If Err.Number <> 0 Then Report_Event enumEVENT_ERROR, "make_readonly", last_errorMsg, "Get_Package_Info:" & Err.Description Exit Sub End If ' Ensure that we have some data If not m_data_collected Then Report_Event enumEVENT_ERROR, "make_readonly", "", "Package Info not present" Exit Sub End If ' Build up the command line to the target script ' Note: DoubleQuotes quotes will be escaped \" ' Double space will be process as for error reporting ' Chr(92) == \ ' Chr(34) == " ' Chr(39) = ' sudoCmd = "~/sbin/make_readonly" &_ " " & pArchive_Path &_ " '" & m_pkg_name & "'" &_ " '" & m_pkg_version & "'" ' Execute the command rv = ExecuteRemoteCommand(sudoCmd) ' ' Report Errors If rv = 0 Then last_resultCode = 0 Else last_resultCode = 1 Report_Event enumEVENT_ERROR, "make_readonly", Replace(sudoCmd," ", VBNewLine), "Remote command on pkg server reported:" & rv End If ' ' New mechanism Call trigger_action (artag_id, apv_id, "make_readonly") End Sub '----------------------------------------------------------------------------------------------------------------- ' Run a remote command in an ssh session ' ' Performs command line processing ' Note: DoubleQuotes quotes will be escaped \" ' Chr(92) == \ ' Chr(34) == " ' Chr(39) = ' ' Private Function ExecuteRemoteCommand(sudoCmd) Dim plinkPath, plinkCmd, wCmdLine Dim pkgCredentails, uname, upasswd pkgCredentails = split(Application("PKGARCHIVE_CREDENTIALS"),":") uname = pkgCredentails(0) upasswd = pkgCredentails(1) plinkPath = Server.MapPath("scripts\bin\plink.exe") plinkCmd = "-ssh -batch " & uname & "@" & archive_server & " -pw " & upasswd & " ""sudo " & Replace(sudoCmd,Chr(34),Chr(92)&Chr(34)) & ";""" wCmdLine = plinkPath & " " & plinkCmd Dim objWSH, rv Set objWSH = Server.CreateObject("WScript.Shell") ExecuteRemoteCommand = objWSH.Run (wCmdLine, 0, TRUE) Set objWSH = Nothing End Function End Class %>