Subversion Repositories DevTools

Rev

Rev 149 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'|                                                   |
'|                 ADMIN Page                        |
'|                 Daemon Instructions               |
'|                                                   |
'=====================================================
%>
<%
Option explicit
' Good idea to set when using redirect
Response.Expires = 0   ' always load the page, dont store
%>
<!--#include file="common/conf.asp"-->
<!--#include file="common/globals.asp"-->
<!--#include file="common/formating.asp"-->
<!--#include file="common/qstr.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="sec/Crypt.asp"-->
<!--#include file="common/_form_window_common.asp"-->
<!--#include file="_action_buttons.asp"-->

<!--#include file="class/classActionButtonControl.asp"-->
<!--#include file="common/daemon_instructions.asp"-->

<%
'------------ ACCESS CONTROL ------------------
%>
<!--#include file="_access_control_general.asp"-->
<!--#include file="_access_control_login.asp"-->
<%
'------------ Variable Definition -------------
Dim objBtnControl
'------------ Constants Declaration -----------
'------------ Variable Init -------------------
Set objBtnControl = New ActionButtonControl
'----------------------------------------------
%>
<%
'--------------------------------------------------------------------------------------------
' Cleans up the daemon instructions table to remove old data that might have become stranded
' due to crashed daemons or failing build machines.
'--------------------------------------------------------------------------------------------
Sub CleanupOldData()
   On Error Resume Next
   objEH.TryORA ( OraSession )
   OraDatabase.ExecuteSQL _
   "BEGIN PK_BUILDAPI.cleanup_stranded_daemon_insts; END;"
   objEH.CatchORA ( OraSession )
End Sub


'--------------------------------------------------------------------------------------------
' Get a project name from a release tag
'--------------------------------------------------------------------------------------------
Function ProjectName(nRtag_Id)
   Dim rsTemp
   Dim query_string

   ProjectName = ""

   If (NOT IsNull(nRtag_Id)) AND (nRtag_Id <> "") Then

      query_string = "SELECT proj_id FROM release_tags WHERE rtag_id = " & nRtag_Id
      Set rsTemp = OraDatabase.DbCreateDynaset( query_string, ORADYN_DEFAULT )
      If (NOT rsTemp.BOF) AND (NOT rsTemp.EOF) Then
         query_string = "SELECT proj_name FROM projects WHERE proj_id = " & rsTemp("proj_id")
         Set rsTemp = OraDatabase.DbCreateDynaset( query_string, ORADYN_DEFAULT )
         If (NOT rsTemp.BOF) AND (NOT rsTemp.EOF) Then
            ProjectName = rsTemp("proj_name")
         End If
      End If

      rsTemp.Close()
      set rsTemp = nothing
   End If
End Function

'--------------------------------------------------------------------------------------------
' Get a release name from a release tag
'--------------------------------------------------------------------------------------------
Function ReleaseName(nRtag_Id)
   Dim rsTemp
   Dim query_string

   ReleaseName = ""

   If (NOT IsNull(nRtag_Id)) AND (nRtag_Id <> "") Then

      query_string = "SELECT rtag_name FROM release_tags WHERE rtag_id = " & nRtag_Id
      Set rsTemp = OraDatabase.DbCreateDynaset( query_string, ORADYN_DEFAULT )
      If (NOT rsTemp.BOF) AND (NOT rsTemp.EOF) Then
         ReleaseName = rsTemp("rtag_name")
      End If

      rsTemp.Close()
      set rsTemp = nothing
   End If
End Function

'--------------------------------------------------------------------------------------------
' Get a user name/email from a user ID
'--------------------------------------------------------------------------------------------
Sub GetUserName(nUserId, outUserName, outUserEmail)

   Dim rsTemp
   Dim query_string

   outUserName  = ""
   outUserEmail = ""

   If (NOT IsNull(nUserId)) AND (nUserId <> "") Then

      query_string = "SELECT usr.FULL_NAME, usr.USER_EMAIL" &_
                     "  FROM USERS usr" &_
                     " WHERE usr.USER_ID = " & nUserId

      Set rsTemp = OraDatabase.DbCreateDynaset( query_string, ORADYN_DEFAULT )
      If (NOT rsTemp.BOF) AND (NOT rsTemp.EOF) Then
         outUserName  = rsTemp("full_name")
         outUserEmail = rsTemp("user_email")
      End If

      rsTemp.Close()
      set rsTemp = nothing
   End If

End Sub
%>

<%
' Clean up old data
CleanupOldData

' Page Access Condition
%>
<script language="JavaScript" type="text/javascript">
<!--

// This function is designed to be called when a user resets the in-progress value from YES back to NO
function reset_in_progress(instId)
{
   var proceed = false;
   var s;
   s  = '_ResetDaemonInstruction.asp';
   s += '?inst_id=' + instId;

   proceed = confirm('Are you sure you want to reset this instructions in-progress flag?\n\n' +
                     'You should ensure that the daemons are not operating upon this instruction first.\n\n' +
                     'Check the scheduled date/time. Does it appear so far in the past that it is unlikely\n' +
                     'a daemon is still undertaking the work for the instruction?\n\n' +
                     'Press OK to reset, otherwise press CANCEL\n\n' );

   if (proceed == true) {
      document.location = s;
   }
}
//-->
</script>

<html>
   <head>
      <title>Daemon Instructions Administration</title>
      <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <link rel="stylesheet" href="images/release_manager_style.css" type="text/css">
      <link rel="stylesheet" href="images/navigation.css" type="text/css">
      <script language="JavaScript" src="images/common.js"></script>
      <!-- DROPDOWN MENUS -->
      <!--#include file="_menu_def.asp"-->
      <script language="JavaScript1.2" src="images/popup_menu.js"></script>
   </head>
   <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" >
      <!-- MENU LAYERS -------------------------------------->
      <div id="popmenu" class="menuskin" onMouseover="clearhidemenu();highlightmenu(event,'on')" onMouseout="highlightmenu(event,'off');dynamichide(event)">
      </div>
      <!-- TIPS LAYERS -------------------------------------->
      <div id="formTipsLayer" style="position: absolute; z-index: 1000; visibility: hidden; left:0; top: 0; width: 10">&nbsp;</div>
      <!-- HEADER -->
      <!--#include file="_header.asp"-->

      <%
      '-- FROM START ---------------------------------------------------------------------------------------------------------
      objFormComponent.FormName = "DAEMON_INSTRUCTIONS"
      objFormComponent.Action = ScriptName
      objFormComponent.OnSubmit = "ShowProgress();"
      Call objFormComponent.FormStart()
      %>
      <table width="100%"  border="0" cellspacing="3" cellpadding="0" >

         <div align="left" class=" body_col">
            <br>Current List of DAEMON INSTRUCTIONS
         </div>
         <tr></tr>
         <tr>
            <td></td>
            <!-- DAEMON INSTRUCTION DETAILS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">OPERATION</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">PROJECT</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">RELEASE</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">MODE</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">PACKAGE</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">VERSION</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">SCHEDULED TIME<br>(<SPAN style=color:Red>Red</SPAN> = overdue)<br>(<SPAN style=color:Green>Green</SPAN> = ready)</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">REPEAT</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">ADDED BY</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">LAST<br>UPDATED</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">IN<br>PROGRESS</td>
            <td align="left" nowrap background="images/bg_table_col.gif" class="body_col">EDIT/DELETE</td>
         </tr>
         <tr>
            <td colspan="13" background="images/bg_table_border.gif"><img src="images/spacer.gif" width="1" height="1"></td>
         </tr>

         <%
         ' Load some action buttons
         Call objBtnControl.LoadActionButtons ( Array("btnEditDaemonInst", "btnDeleteDaemonInst"), OraDatabase )
         objBtnControl.ButtonSpacer = 1

         Dim rsQry
         Dim ProjId
         Dim PkgId
         Dim PkgName
         Dim PkgVersion
         Dim UserName
         Dim UserEmail
         Dim bInProgress
         Dim bIsReady
         Dim bIsOverdue
         Dim daemonInstId  ' This variable is needed to support the action buttons to Edit/Delete
         Dim bEditEnabled
         Dim bResetInProgressEnabled

         ' determine if user can reset the in-progress state of a daemon instruction
         bResetInProgressEnabled = UserAllowedToResetInProgress()

         ' query the daemon_instructions table and also create an indication of an overdue instruction,
         ' which is defined as being one that was scheduled for action
         Set rsQry = OraDatabase.DbCreateDynaset( "SELECT DAEMON_INSTRUCTIONS_ID,"&_
                                                  "       OP_CODE,"&_
                                                  "       RTAG_ID,"&_
                                                  "       PV_ID,"&_
                                                  "       SCHEDULED_DATETIME,"&_
                                                  "       REPEAT_SECS,"&_
                                                  "       ADDED_DATETIME,"&_
                                                  "       USER_ID,"&_
                                                  "       IN_PROGRESS,"&_
                                                  "       (CASE WHEN SCHEDULED_DATETIME <= SYSDATE THEN 1 ELSE 0 END) AS READY,"&_
                                                  "       (CASE WHEN (SCHEDULED_DATETIME + (1/144)) < SYSDATE THEN 1 ELSE 0 END) AS OVERDUE"&_
                                                  "  FROM DAEMON_INSTRUCTIONS "&_
                                                  "  ORDER BY RTAG_ID, PV_ID, SCHEDULED_DATETIME, DAEMON_INSTRUCTIONS_ID", ORADYN_DEFAULT )
         While (NOT rsQry.BOF) AND (NOT rsQry.EOF)

            daemonInstId = rsQry("DAEMON_INSTRUCTIONS_ID")

            If IsNull(rsQry("IN_PROGRESS")) OR rsQry("IN_PROGRESS") = "0" Then
               bInProgress = False
            Else
               bInProgress = True
            End If

            ' only flag as overdue if time threshold has been met but the daemon has not marked the instruction as being in progress.
            If rsQry("OVERDUE") AND NOT bInProgress Then
               bIsOverdue = True
            Else
               bIsOverdue = False
            End If

            If rsQry("READY") Then
               bIsReady = True
            Else
               bIsReady = False
            End If

            ' Get as much info about the package as we can
            ProjId=""
            PkgId = 0
            PkgName = "N/A"
            PkgVersion = "N/A"
            If (NOT IsNull(rsQry("PV_ID"))) AND (rsQry("PV_ID") <> "") Then
               Call Get_Pkg_Short_Info(rsQry("PV_ID"), PkgId, PkgName, PkgVersion, NULL, NULL, NULL)
            End If

            ' derive the proj_id from the rtag_id
            If (NOT IsNull(rsQry("RTAG_ID"))) AND (rsQry("RTAG_ID") <> "") Then
               ProjId = Get_Proj_ID(rsQry("RTAG_ID"))
               ReleaseMode = GetReleaseMode( rsQry("RTAG_ID") )
            Else
               ReleaseMode = "Y" ' closed mode used to prevent editing
            End If

            ' determine if editing is enabled by permissions
            bEditEnabled = True
            If objAccessControl.UserLogedIn Then
               If NOT objAccessControl.IsDataActive ("PROJECTS", ProjId, "EditProjects") OR NOT objAccessControl.IsDataVisible ("PROJECTS", ProjId, "EditProjects")  Then
                  bEditEnabled = False
               ElseIf NOT objAccessControl.IsDataActive ("PROJECTS", ProjId, enumDB_PERMISSION_TYPE_ACTIVE) Then
                  bEditEnabled = False
               ElseIf ( ReleaseMode <> enumDB_RELEASE_IN_OPEN_MODE ) Then
                  If NOT objAccessControl.IsActive("ApproveForAutoBuild") Then
                     bEditEnabled = False
                  End If
               End If
            Else
               bEditEnabled = False
            End If

            Call GetUserName(rsQry("User_Id"), UserName, UserEmail)

            %>
            <tr>
               <input type="hidden" name="DAEMON_INSTRUCTIONS_ID_" & daemonInstId value=daemonInstId>

               <td></td>

               <td align="left" valign="top" class="body_txt">
                  <%=DaemonInstructionOperationName(rsQry("OP_CODE"))%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%If ProjId <> "" Then%>
                     <a href='rtree.asp?proj_id=<%=ProjId%>'><%=ProjectName(rsQry("RTAG_ID"))%>
                  <%End If%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%If ProjId <> "" Then%>
                     <a href='dependencies.asp?rtag_id=<%=rsQry("RTAG_ID")%>'><%=ReleaseName(rsQry("RTAG_ID"))%>
                  <%End If%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%=Get_Official(ReleaseMode)%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%If (NOT IsNull(rsQry("PV_ID"))) AND (rsQry("PV_ID") <> "") Then%>
                     <a href='fixed_issues.asp?rtag_id=<%=rsQry("RTAG_ID")%>&pv_id=<%=rsQry("PV_ID")%>'><%=PkgName%>
                  <%Else%>
                     <%=PkgName%>
                  <%End If%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%=PkgVersion%>
               </td>

               <td align="left" valign="top" class="body_txt" <%If bIsOverdue Then%>style=color:Red<%Elseif bIsReady Then%>style=color:Green<%End If%>><%=EuroDateTime(rsQry("SCHEDULED_DATETIME"))%></td>

               <td align="left" valign="top" class="body_txt"><%=DaemonInstructionRepeatString(rsQry("OP_CODE"), rsQry("REPEAT_SECS"))%></td>

               <td align="left" valign="top" class="body_txt">
                  <%If UserName <> "" AND UserEmail <> "" Then%>
                     <a href="mailto:<%=UserEmail%>" title="<%=UserEmail%>" class="txt_linked"><%=UserName%></a>
                  <%End If%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%=EuroDateTime(rsQry("ADDED_DATETIME"))%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%If bInProgress Then%>
                     <%If bResetInProgressEnabled Then%>
                        <img src="images/i_reset.gif" onclick="reset_in_progress(<%=daemonInstId%>);"></img>
                     <%End If%>
                     YES
                  <%Else%>
                     NO
                  <%End If%>
               </td>

               <td align="left" valign="top" class="body_txt">
                  <%If bEditEnabled Then%>
                     <%Call objBtnControl.Render ( Array("btnEditDaemonInst", "btnDeleteDaemonInst"), objAccessControl )%>
                  <%Else%>
                     No Edit Permission
                  <%End If%>
               </td>

            </tr>
            <%
            rsQry.MoveNext()
            %>
            <tr>
               <td colspan="13" background="images/bg_table_border.gif"><img src="images/spacer.gif" width="1" height="1"></td>
            </tr>
            <%
         Wend
         rsQry.Close()
         Set rsQry = nothing
         %>
      </table>

      <table width="50%"  border="0" cellspacing="3" cellpadding="0" >
         <tr>
            <td class="form_iname">&nbsp;</td>
            <td class="val_err"><a href=""><%Call Action_Buttons ( "Add Daemon Instruction" )%> </a>
            <td>&nbsp;</td>
         </tr>
      </table>

      <table width="100%"  border="0" cellspacing="3" cellpadding="0" >
         <tr>
            <td>NOTE:</td>
         </tr>
         <tr>
            <td valign="top" class="help_txt">1)</td>
            <td valign="top" class="help_txt">Instructions become overdue when they are more than 10 minutes old and are not in-progress</td>
         </tr>
         <tr>
            <td valign="top" class="help_txt">2)</td>
            <td valign="top" class="help_txt">Instructions that take a long time to act upon, may cause other instructions for the same release to become overdue. This is not a real problem.</td>
         </tr>
         <tr>
            <td valign="top" class="help_txt">3)</td>
            <td valign="top" class="help_txt">Instructions may become stranded in the "in-progress" state if build daemons crash, or a problem occurs on a build machine.
            Automatic deletion of the instruction will eventually occur (see next note). Contact a release manager administrator to correct this problem before automatic deletion.</td>
         </tr>
         <tr>
            <td valign="top" class="help_txt">4)</td>
            <td valign="top" class="help_txt">Instructions with scheduled times 5 days or older will be deleted automatically.</td>
         </tr>

      </table>

      <%=objPMod.ComposeHiddenTags()%>
      <input type="hidden" name="action" value="true">
      <%
      Call objFormComponent.FormEnd()
      '-- FROM END ----------------------------------------------------------------------------------------------------------------
      %>
   </body>
</html>
<!-- FOOTER -->
<!--#include file="_footer.asp"-->
<%
Call Destroy_All_Objects
%>