Subversion Repositories DevTools

Rev

Rev 4624 | Blame | Last modification | View Log | RSS feed

<%
'=====================================================
'                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

' Archive server name and credentials
'   Perhaps the credentials should come from the environment
private m_archive_server
private m_archive_user
private m_archive_password

Public last_resultCode

'-----------------------------------------------------------------------------------------------------------------
'   Retrieve information about the target server
'
Private Sub Get_Server_Info()
    m_archive_user = "releasem"    
    m_archive_password = "releasem"

    Dim sqry: sqry = "SELECT * FROM BUILD_SERVICE_CONFIG WHERE SERVICE='ARCHIVE SERVER'"
    Dim rsTemp
    Set rsTemp = OraDatabase.DbCreateDynaset( sqry , cint(0) )
    m_archive_server = rsTemp("config")
    rsTemp.Close()
    Set rsTemp = Nothing
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
  
   ' Get package information   
   ssql = _
   " SELECT pv.pkg_id,pk.pkg_name,pv.pkg_version,rt.proj_id"&_
   " 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 ((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")
   Else
      Err.Raise 8, "Error getting package information.  PV_ID, " & APV_ID & " not found in."
      Call RaiseMsg ( enum_MSG_ERROR, Err.description )
   End If
   rsTemp.Close
   Set rsTemp = Nothing
End Sub

'-----------------------------------------------------------------------------------------------------------------
' Run script job, ReleaseChanged, of script, on_Make_Official.wsf for the specified list of package versions.
' apv_id_list is a comma separated list of pv_id's
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 script job, ReleaseChanged, of script, on_Make_Official.wsf for the specified package version.
' This job calls the unix script, make_release_changed
Sub Run_ReleaseChanged(artag_id,apv_id,amode_id,aget_info)
  Dim sysShell: Set sysShell = Server.CreateObject("WScript.Shell")

  if aget_info then
    Call Get_Package_Info (artag_id,apv_id)
  end if

  ' Note: Call Run such that we wait for the result code
  '       If we don't do this then we may flood the server with requests and then it jams up.
  '
  Call sysSHell.Run("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER &"\on_Make_Official.wsf //job:ReleaseChanged" & " /pkg_name:""" & m_pkg_name & """" & " /pkg_version:""" & m_pkg_version & """" & " /rtag_id:" & artag_id & " /pkg_id:" & m_pkg_id & " /pv_id:" & apv_id & " /proj_id:" & m_proj_id & " /mode_id:" & amode_id, 0, True)
  Set sysShell = Nothing
End Sub

'-----------------------------------------------------------------------------------------------------------------
' Uses ssh to communicate with the archive server and run the unix script, make_release_changed
'   Current Issue: Does not have nice error reporting mechanism
'
Sub Run_ReleaseChanged_New_and_not_yet_used(artag_id,apv_id,amode_id,aget_info)
    Dim sudoCmd, plinkPath, plinkCmd, wCmdLine

  last_resultCode = -1
  Call Get_Server_Info
  if aget_info then
    Call Get_Package_Info (artag_id,apv_id)
  end if

  '
  ' Build up the command line to the target script
  '
    sudoCmd = "~/sbin/make_release_changed" &_
         " archive=dpkg_archive" &_
         " pkg_name='\""" & m_pkg_name & "\""'" &_
         " pkg_version='\"""& m_pkg_version &"\""'" &_
         " rtag_id="& artag_id &_
         " pkg_id=" & m_pkg_id &_
         " pv_id="& apv_id &_
         " proj_id="& m_proj_id &_
         " mode_id="& amode_id

    ' Build up the ssh command
    plinkPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "Release_Manager\scripts\bin\plink.exe"
    plinkCmd =  "-ssh -batch " & m_archive_user & "@" & m_archive_server & " -pw " & m_archive_password & " ""sudo " & sudoCmd & ";"""
    wCmdLine =  plinkPath & " " & plinkCmd
   
    ' Note: Call Run such that we wait for the result code
    '       If we don't do this then we may flood the server with requests and then it jams up.
    '
    Dim objWSH
    Set objWSH = Server.CreateObject("WScript.Shell")
    last_resultCode = objWSH.Run (wCmdLine, 0, TRUE)
    Set objWSH = Nothing

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

End Class
%>