/// <summary> /// Should handle all requests to launch a lab, produces a releative URL or error message /// and a status code which are returned in the IntTag. This does not make use of the 'Context'. /// This should only be called after the original request has been authorized since the /// user is assummed to have been authenticated and authorized. /// </summary> /// <param name="opCoupon">An initial operationCoupon</param> /// <param name="clientID"></param> /// <param name="labServerID"></param> /// <param name="groupID">specified by SCO, may not be the users group</param> /// <param name="userID"></param> /// <returns>A negative value for errrors or a bitmapped value indicating what should be done with the result.tag</returns> public IntTag ProcessLaunchClientRequest(Coupon opCoupon, int clientID, int labServerID, int groupID, int userID, int userTZ //, string authorityUrl, long duration, int autoStart ) { int effectiveGroupID = -1; int userGroupID = -1; string groupName = null; string effectiveGroupName = null; string userName = null; DateTime startExecution =DateTime.MinValue; long duration = -1L; ProcessAgentInfo labServer = null; StringBuilder buf = new StringBuilder(); LabClient client = AdministrativeAPI.GetLabClient(clientID); iLabParser parser = new iLabParser(); IntTag result = new IntTag(-1, "Access Denied"); if (client == null) { result.tag = "LabClient was not found"; return result; } userName = AdministrativeAPI.GetUserName(userID); if(String.IsNullOrEmpty(userName)){ result.tag = "User was not found"; return result; } // Check if user is a member of the specified group List<int> allGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUserRecursively(userID)); if(!allGroups.Contains(groupID)){ result.tag = "User does not have access to the specified group"; return result; } //TODO int qualID = AuthorizationAPI.GetQualifierID(clientID, Qualifier.labClientQualifierTypeID); int[] clientGroups = AuthorizationAPI.FindGrants(-1, Function.useLabClientFunctionType, qualID); // Find the users actual group and run as that group List<int> userGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUser(userID)); if (userGroups.Count == 1) { groupName = AdministrativeAPI.GetGroupName(userGroups[0]); } else if (userGroups.Count > 1) { } //TODO This does not seem to be working effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID, Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType); if (effectiveGroupID == groupID) { effectiveGroupName = groupName; } else if (effectiveGroupID > 0) { effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID); } ProcessAgentInfo[] paInfos = AdministrativeAPI.GetLabServersForClient(clientID); if (paInfos != null && paInfos.Length > 0) { labServer = paInfos[0]; } if (client.needsScheduling) { Ticket allowExperimentExecutionTicket = null; if (opCoupon != null) { // First check for an Allow Execution Ticket allowExperimentExecutionTicket = RetrieveTicket( opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION); } if (allowExperimentExecutionTicket == null) { // Try for a reservation int ussId = FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussId > 0) { ProcessAgent uss = GetProcessAgent(ussId); // check for current reservation //create a collection & redeemTicket string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow, userName, userID, groupName, client.clientGuid); Coupon redeemCoupon = CreateCoupon(); AddTicket(redeemCoupon, TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader op = new OperationAuthHeader(); op.coupon = redeemCoupon; ussProxy.Url = uss.webServiceUrl; ussProxy.OperationAuthHeaderValue = op; Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, userName, labServer.agentGuid, client.clientGuid); if (reservation != null) { // create the allowExecution Ticket DateTime start = reservation.Start; duration = reservation.Duration; string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload( start, duration, effectiveGroupName,client.clientGuid); DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; allowExperimentExecutionTicket = AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload); } } } if (allowExperimentExecutionTicket != null) { XmlDocument payload = new XmlDocument(); payload.LoadXml(allowExperimentExecutionTicket.payload); startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText); duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText); } else{ // No current scheduled reservations result.id = -8; result.tag = "Go to USS"; return result; } } else // Not Scheduled { } /////////////////////////// if (labServer != null) { if (client.IsReentrant) { long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(userID, effectiveGroupID, labServer.agentId,client.clientID); foreach (long id in ids) { InternalDataDB.CloseExperiment(id, StorageStatus.CLOSED_USER); } } TicketLoadFactory factory = TicketLoadFactory.Instance(); // 1. Create Coupon for ExperimentCollection Coupon expCoupon = CreateCoupon(); iLabProperties properties = new iLabProperties(); properties.Add("sb", ProcessAgentDB.ServiceAgent); properties.Add("ls", labServer); properties.Add("op", expCoupon); DateTime start = DateTime.UtcNow; duration = 7L * 24L * 60L * 60L; // default is one week RecipeExecutor executor = null; string redirectURL = null; //Create a redeemSession ticket for the experiment //payload includes username and current group name & client id. string sessionPayload = factory.createRedeemSessionPayload(userID, groupID, clientID, userName, groupName); // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon AddTicket(expCoupon, TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, duration, sessionPayload); // AdministrativeAPI.ModifyUserSession(Convert.ToInt64(Session["SessionID"]), groupID, clientID, Session.SessionID); if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT) { // execute the "interactive experiment execution recipe executor = RecipeExecutor.Instance(); // loaderScript not parsed in Recipe redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client, start, duration, userTZ, userID, effectiveGroupID, effectiveGroupName); //Do not add the returnURL // Parse & check that the default auth tokens are added result.tag = parser.Parse(redirectURL, properties, true); result.id = LabClient.INTERACTIVE_BIT | LabClient.REDIRECT_BIT; } else if (client.clientType == LabClient.INTERACTIVE_APPLET) { // execute the "interactive experiment execution recipe executor = RecipeExecutor.Instance(); // loaderScript not parsed in Recipe redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client, start, duration, userTZ, userID, effectiveGroupID, effectiveGroupName); // Applets do not use default query string parameters, parameters must be in the loader script result.tag = parser.Parse(redirectURL, properties); result.id = LabClient.INTERACTIVE_BIT | LabClient.APPLET_BIT; //string jScript = @"<script language='javascript'>parent.theapplet.location.href = '" // + "applet.aspx" + @"'</script>"; //Page.RegisterStartupScript("ReloadFrame", jScript); } // Support for Batch 6.1 Lab Clients else if (client.clientType == LabClient.BATCH_HTML_REDIRECT) { // use the Loader script for Batch experiments, for now check for default properties result.tag = parser.Parse(client.loaderScript, properties,true); result.id = LabClient.BATCH_BIT | LabClient.REDIRECT_BIT; } // use the Loader script for Batch experiments else if (client.clientType == LabClient.BATCH_APPLET) { // Do not append defaults result.tag = parser.Parse(client.loaderScript, properties); result.id = LabClient.BATCH_BIT | LabClient.APPLET_BIT; } } // labserver != null else { buf.Append(" LabServer = null"); } Logger.WriteLine(buf.ToString()); //////////////// return result; }
protected void Page_Load(object sender, System.EventArgs e) { int groupID = 0; string groupName = null; lc = wrapper.GetLabClientsWrapper(new int[] { Convert.ToInt32(Session["ClientID"]) })[0]; if (Session["GroupID"] != null && Session["GroupID"].ToString().Length > 0) { groupID = Convert.ToInt32(Session["GroupID"]); } if (Session["GroupName"] != null && Session["GroupName"].ToString().Length > 0) { groupName = Session["GroupName"].ToString(); lblGroupNameTitle.Text = groupName; lblBackToLabs.Text = groupName; if (Convert.ToInt32(Session["ClientCount"]) == 1) lblGroupNameSystemMessage.Text = "Messages for " + groupName; else lblGroupNameSystemMessage.Text = "Messages for " + lc.clientName; } if (!IsPostBack) { auto = Request.QueryString["auto"]; if (auto!= null && auto.Length > 0) { if (auto.ToLower().Contains("t")) { autoLaunch = true; } } if (lc.clientType == LabClient.INTERACTIVE_APPLET || lc.clientType == LabClient.INTERACTIVE_HTML_REDIRECT) { // retrieve parameters from URL couponId = Request.QueryString["coupon_id"]; passkey = Request.QueryString["passkey"]; issuerGuid = Request.QueryString["issuer_guid"]; if (lc.needsScheduling) { Coupon opCoupon = null; if (couponId != null && passkey != null && issuerGuid != null) { opCoupon = new Coupon(issuerGuid, Int64.Parse(couponId), passkey); // First check for an Allow Execution Ticket Ticket allowExperimentExecutionTicket = issuer.RetrieveTicket( opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION); if (allowExperimentExecutionTicket == null) { // Try for a reservation int ussId = issuer.FindProcessAgentIdForClient(lc.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussId > 0) { ProcessAgent uss = issuer.GetProcessAgent(ussId); ProcessAgent ls = issuer.GetProcessAgent(lc.labServerIDs[0]); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader op = new OperationAuthHeader(); op.coupon = opCoupon; ussProxy.Url = uss.webServiceUrl; ussProxy.OperationAuthHeaderValue = op; Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, Session["UserName"].ToString(), ls.agentGuid, lc.clientGuid); if (reservation != null) { // Find efective group string effectiveGroupName = null; int effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, lc.clientID, Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType); if (effectiveGroupID == groupID) { if (Session["groupName"] != null) { effectiveGroupName = Session["groupName"].ToString(); } else { effectiveGroupName = AdministrativeAPI.GetGroupName(groupID); Session["groupName"] = effectiveGroupName; } } else if (effectiveGroupID > 0) { effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID); } // create the allowExecution Ticket DateTime start = reservation.Start; long duration = reservation.Duration; string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload( start, duration, effectiveGroupName); DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; allowExperimentExecutionTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload); } } } if (allowExperimentExecutionTicket != null) { XmlDocument payload = new XmlDocument(); payload.LoadXml(allowExperimentExecutionTicket.payload); startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText); duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText); Session["StartExecution"] = DateUtil.ToUtcString(startExecution); Session["Duration"] = duration; //groupId = payload.GetElementsByTagName("groupID")[0].InnerText; // Display reenter button if experiment is reentrant & a current experiment exists if (lc.IsReentrant) { long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(Convert.ToInt32(Session["UserID"]), Convert.ToInt32(Session["GroupID"]), lc.labServerIDs[0], lc.clientID); if (ids.Length > 0) { btnLaunchLab.Text = "Launch New Experiment"; btnLaunchLab.Visible = true; pReenter.Visible = true; btnReenter.Visible = true; btnReenter.CommandArgument = ids[0].ToString(); } else { pReenter.Visible = false; btnReenter.Visible = false; btnLaunchLab.Text = "Launch Lab"; if (autoLaunch) { launchLabClient(lc.clientID); } else { btnLaunchLab.Visible = true; } } } else { if (autoLaunch) { launchLabClient(lc.clientID); } else { btnLaunchLab.Visible = true; } } } else { btnLaunchLab.Visible = false; } } } else { if (autoLaunch) { launchLabClient(lc.clientID); } else { btnLaunchLab.Visible = true; } } } else if (lc.clientType == LabClient.BATCH_APPLET || lc.clientType == LabClient.BATCH_HTML_REDIRECT) { if (autoLaunch) { launchLabClient(lc.clientID); } else { btnLaunchLab.Visible = true; } } } btnSchedule.Visible = lc.needsScheduling; //Session["LoaderScript"] = lc.loaderScript; lblClientName.Text = lc.clientName; lblVersion.Text = lc.version; lblLongDescription.Text = lc.clientLongDescription; lblNotes.Text = lc.notes; string emailCmd = "mailto:" + lc.contactEmail; lblEmail.Text = "<a href=" + emailCmd + ">" + lc.contactEmail + "</a>"; btnLaunchLab.Command += new CommandEventHandler(this.btnLaunchLab_Click); btnLaunchLab.CommandArgument = lc.clientID.ToString(); int count = 0; if (lc.clientInfos != null) { foreach (ClientInfo ci in lc.clientInfos) { if (ci.infoURLName.CompareTo("Documentation") != 0) { System.Web.UI.WebControls.Button b = new System.Web.UI.WebControls.Button(); b.Visible = true; b.CssClass = "button"; b.Text = ci.infoURLName; b.CommandArgument = ci.infoURL; b.CommandName = ci.infoURLName; b.ToolTip = ci.description; b.Command += new CommandEventHandler(this.HelpButton_Click); repClientInfos.Controls.AddAt(count, b); repClientInfos.Controls.AddAt(count + 1, new LiteralControl(" ")); count += 2; } } } List<SystemMessage> messagesList = new List<SystemMessage>(); SystemMessage[] groupMessages = null; if (Session["ClientCount"] != null && Convert.ToInt32(Session["ClientCount"]) == 1) { groupMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.GROUP, Convert.ToInt32(Session["GroupID"]), 0, 0); if (groupMessages != null) messagesList.AddRange(groupMessages); } foreach (int labServerID in lc.labServerIDs) { SystemMessage[] labMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.LAB, 0, 0, labServerID); if (labMessages != null) messagesList.AddRange(labMessages); } if (messagesList != null && messagesList.Count > 0) { messagesList.Sort(SystemMessage.CompareDateDesc); //messagesList.Reverse(); repSystemMessage.DataSource = messagesList; repSystemMessage.DataBind(); } else { lblGroupNameSystemMessage.Text += "</h3><p>No Messages at this time</p><h3>"; } }
protected void launchLab(int userID, int groupID, int clientID) { // Currently there is not a good solution for checking for an AllowExperiment ticket, will check the USS for reservation StringBuilder buf = new StringBuilder("~/myClient.aspx?auto=t"); string userName = null; Coupon opCoupon = null; Ticket allowTicket = null; int effectiveGroupID = 0; if (Session["UserName"] != null && Session["UserName"].ToString().Length > 0) { userName = Session["UserName"].ToString(); } else { userName = AdministrativeAPI.GetUserName(userID); } LabClient client = AdministrativeAPI.GetLabClient(clientID); if (client.clientID > 0) // It's a structure need to test for valid value { DateTime start = DateTime.UtcNow; long duration = 36000L; // default is ten hours ProcessAgentInfo labServer = null; if (client.labServerIDs.Length > 0) { labServer = issuer.GetProcessAgentInfo(client.labServerIDs[0]); } else { throw new Exception("The lab server is not specified for lab client " + client.clientName + " version: " + client.version); } // Find efective group string effectiveGroupName = null; effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID, Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType); if (effectiveGroupID == groupID) { if (Session["groupName"] != null) { effectiveGroupName = Session["groupName"].ToString(); } else { effectiveGroupName = AdministrativeAPI.GetGroupName(groupID); Session["groupName"] = effectiveGroupName; } } else if (effectiveGroupID > 0) { effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID); } //Check for Scheduling: if (client.needsScheduling) { int ussId = issuer.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussId > 0) { ProcessAgent uss = issuer.GetProcessAgent(ussId); int lssId = issuer.FindProcessAgentIdForAgent(client.labServerIDs[0], ProcessAgentType.LAB_SCHEDULING_SERVER); ProcessAgent lss = issuer.GetProcessAgent(lssId); // check for current reservation //create a collection & redeemTicket string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow); opCoupon = issuer.CreateTicket(TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader op = new OperationAuthHeader(); op.coupon = opCoupon; ussProxy.Url = uss.webServiceUrl; ussProxy.OperationAuthHeaderValue = op; Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, userName, labServer.agentGuid, client.clientGuid); if (reservation != null) { // create the allowExecution Ticket start = reservation.Start; duration = reservation.Duration; string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload( start, duration, effectiveGroupName); DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; allowTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload); // Append op coupon to url buf.Append("&coupon_id=" + opCoupon.couponId); buf.Append("&passkey=" + opCoupon.passkey); buf.Append("&issuer_guid=" + opCoupon.issuerGuid); } //else //{ // string schedulingUrl = RecipeExecutor.Instance().ExecuteExerimentSchedulingRecipe(uss.agentGuid, lss.agentGuid, userName, groupName, // labServer.agentGuid, client.clientGuid, client.clientName, client.version, // Convert.ToInt64(ConfigurationSettings.AppSettings["scheduleSessionTicketDuration"]), Convert.ToInt32(Session["UserTZ"])); // schedulingUrl += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl + "/myClient.aspx"; // Response.Redirect(schedulingUrl, true); //} } else{ // USS Not Found } } // End needsScheduling //Response.Redirect(Global.FormatRegularURL(Request, "myClient.aspx"), true); Response.Redirect(buf.ToString(), true); } // End if valid client else{ throw new Exception("The specified lab client could not be found"); } }
protected void launchLabXX(int userID, int groupID, int clientID) { // Currently there is not a good solution for checking for an AllowExperiment ticket, will check the USS for reservation Coupon allowExecutionCoupon = null; StringBuilder message = new StringBuilder("Message: clientID = " + clientID); LabClient client = AdministrativeAPI.GetLabClient(clientID); string userName = null; Coupon opCoupon = null; Ticket allowTicket = null; if (Session["UserID"] != null) { if (userID == Convert.ToInt32(Session["UserID"])) { userName = Session["UserName"].ToString(); } else { userName = AdministrativeAPI.GetUserName(userID); Session["UserID"] = userID; Session["UserName"] = userName; } string groupName = AdministrativeAPI.GetGroupName(groupID); if (client.clientID > 0) // It's a structure need to test for valid value { // create the RecipeExecutor string redirectURL = null; DateTime start = DateTime.UtcNow; long duration = 36000L; // default is ten hours ProcessAgentInfo labServer = null; if (client.labServerIDs.Length > 0) { labServer = issuer.GetProcessAgentInfo(client.labServerIDs[0]); } else { throw new Exception("The lab server is not specified for lab client " + client.clientName + " version: " + client.version); } //Check for Scheduling: if (client.needsScheduling) { int ussId = issuer.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussId > 0) { ProcessAgent uss = issuer.GetProcessAgent(ussId); //// Find efective group //string effectiveGroupName = null; //int effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID, // Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType); //if (effectiveGroupID == groupID) //{ // if(Session["groupName"] != null){ // effectiveGroupName = Session["groupName"].ToString(); // } // else{ // effectiveGroupName = AdministrativeAPI.GetGroupName(groupID); // Session["groupName"] = effectiveGroupName; // } //} //else if (effectiveGroupID > 0) //{ // effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID ); //} int lssId = issuer.FindProcessAgentIdForAgent(client.labServerIDs[0], ProcessAgentType.LAB_SCHEDULING_SERVER); ProcessAgent lss = issuer.GetProcessAgent(lssId); // check for current reservation string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow); opCoupon = issuer.CreateTicket(TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader op = new OperationAuthHeader(); op.coupon = opCoupon; ussProxy.Url = uss.webServiceUrl; ussProxy.OperationAuthHeaderValue = op; Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, userName, labServer.agentGuid, client.clientGuid); if (reservation != null) { start = reservation.Start; duration = reservation.Duration; string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload( start, duration, groupName); DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; allowTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload); } else { string schedulingUrl = RecipeExecutor.Instance().ExecuteExerimentSchedulingRecipe(uss.agentGuid, lss.agentGuid, userName, groupName, labServer.agentGuid, client.clientGuid, client.clientName, client.version, Convert.ToInt64(ConfigurationSettings.AppSettings["scheduleSessionTicketDuration"]), Convert.ToInt32(Session["UserTZ"])); schedulingUrl += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl + "/myClient.aspx"; Response.Redirect(schedulingUrl, true); } } } if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT) { if (client.IsReentrant) // check for an existing active experiment { long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(userID, groupID, client.labServerIDs[0], client.clientID); if (ids.Length > 0) { long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(ids[0]); Coupon coupon = issuer.GetIssuedCoupon(coupIDs[0]); // construct the redirect query StringBuilder url = new StringBuilder(client.loaderScript.Trim()); if (url.ToString().IndexOf("?") == -1) url.Append('?'); else url.Append('&'); url.Append("coupon_id=" + coupon.couponId + "&passkey=" + coupon.passkey + "&issuer_guid=" + issuer.GetIssuerGuid()); // Add the return url to the redirect url.Append("&sb_url="); url.Append(ProcessAgentDB.ServiceAgent.codeBaseUrl +"/myClient.aspx"); // Now open the lab within the current Window/frame Response.Redirect(url.ToString(), true); } } //Check for Scheduling: if (client.needsScheduling) { //The scheduling Ticket should exist and been parsed into the session if (allowTicket == null) { throw new Exception(" Unable to confirm a reservation for this client."); } } // execute the "experiment execution recipe redirectURL = RecipeExecutor.Instance().ExecuteExperimentExecutionRecipe(labServer, client, start, duration, Convert.ToInt32(Session["UserTZ"]), userID, groupID, (string)Session["GroupName"]); // Add the return url to the redirect redirectURL += "&sb_url=" + ProcessAgentDB.ServiceAgent.codeBaseUrl +"/myClient.aspx"; // Now open the lab within the current Window/frame Response.Redirect(redirectURL, true); } else if (client.clientType == LabClient.INTERACTIVE_APPLET) { // Note: Currently not supporting Interactive applets // use the Loader script for Batch experiments // This assumes that the client will request the experiment creation Session["LoaderScript"] = client.loaderScript; Session.Remove("RedirectURL"); string jScript = @"<script language='javascript'>parent.theapplet.location.href = '" + "applet.aspx" + @"'</script>"; Page.RegisterStartupScript("ReloadFrame", jScript); } // Support for Batch 6.1 Lab Clients else if (client.clientType == LabClient.BATCH_HTML_REDIRECT) { Session["ClientID"] = client.clientID; AdministrativeAPI.SetSessionClient(Convert.ToInt64(Session["SessionID"]), client.clientID); // use the Loader script for Batch experiments //use ticketing & redirect to url in loader script // [GeneralTicketing] retrieve static process agent corresponding to the first // association lab server */ // New comments: The HTML Client is not a static process agent, so we don't search for that at the moment. // Presumably when the interactive SB is merged with the batched, this should check for a static process agent. // - CV, 7/22/05 Session.Remove("LoaderScript"); //payload includes username and effective group name & client id. //ideally this should be encoded in xml - CV, 7/27/2005 TicketLoadFactory factory = TicketLoadFactory.Instance(); string uName = (string)Session["UserName"]; string gName = (string)Session["GroupName"]; string sessionPayload = factory.createRedeemSessionPayload(userID, groupID, clientID, uName, gName); // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon Coupon coupon = issuer.CreateTicket(TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, -1, sessionPayload); string jScript = @"<script language='javascript'> window.open ('" + client.loaderScript + "?couponID=" + coupon.couponId + "&passkey=" + coupon.passkey + "')</script>"; Page.RegisterStartupScript("HTML Client", jScript); } } // use the Loader script for Batch experiments else if (client.clientType == LabClient.BATCH_APPLET) { Session["ClientID"] = client.clientID; AdministrativeAPI.SetSessionClient(Convert.ToInt64(Session["SessionID"]), client.clientID); Session["LoaderScript"] = client.loaderScript; Session.Remove("RedirectURL"); string jScript = @"<script language='javascript'>parent.theapplet.location.href = '" + ProcessAgentDB.ServiceAgent.codeBaseUrl + @"/applet.aspx" + @"'</script>"; ClientScript.RegisterClientScriptBlock(this.GetType(), "ReloadFrame", jScript); } } else { message.Append(" LabServer = null"); } //lblDebug.Text = message.ToString(); Utilities.WriteLog(message.ToString()); }
protected void Page_Load(object sender, System.EventArgs e) { int groupID = 0; int authID = -1; Coupon opCoupon = null; string groupName = null; lblResponse.Visible = false; userTZ = Convert.ToInt32(Session["UserTZ"]); culture = DateUtil.ParseCulture(Request.Headers["Accept-Language"]); lc = null; if (!IsPostBack) { // retrieve parameters from URL couponId = Request.QueryString["coupon_id"]; passkey = Request.QueryString["passkey"]; issuerGuid = Request.QueryString["issuer_guid"]; if (couponId != null && passkey != null && issuerGuid != null) { opCoupon = new Coupon(issuerGuid, Int64.Parse(couponId), passkey); Ticket authExperimentTicket = issuer.RetrieveTicket(opCoupon, TicketTypes.CREATE_EXPERIMENT, ProcessAgentDB.ServiceGuid); if (authExperimentTicket != null) { XmlQueryDoc authDoc = new XmlQueryDoc(authExperimentTicket.payload); string auth = authDoc.Query("CreateExperimentPayload/authID"); if (auth != null && auth.Length > 0) { authID = Int32.Parse(auth); } string grpName = authDoc.Query("CreateExperimentPayload/groupName"); if (grpName != null && groupName.Length > 0) { Session["GroupName"] = grpName; int grpID = AdministrativeAPI.GetGroupID(grpName); if (grpID > 0) Session["GroupID"] = groupID; } string userName = authDoc.Query("CreateExperimentPayload/userName"); if (userName != null && userName.Length > 0) { Session["UserName"] = userName; int userID = AdministrativeAPI.GetUserID(userName,authID); if (userID > 0) Session["UserID"] = userID; } string clientGuid = authDoc.Query("CreateExperimentPayload/clientGuid"); if (clientGuid != null && clientGuid.Length > 0) { Session["ClientGuid"] = clientGuid; int clientID = AdministrativeAPI.GetLabClientID(clientGuid); if (clientID > 0) Session["ClientID"] = clientID; } } } pReenter.Visible = false; btnReenter.Visible = false; auto = Request.QueryString["auto"]; if (auto != null && auto.Length > 0) { if (auto.ToLower().Contains("t")) { autoLaunch = true; } } } if (Session["ClientID"] != null && Session["ClientID"].ToString().Length > 0) { lc = wrapper.GetLabClientsWrapper(new int[] { Convert.ToInt32(Session["ClientID"]) })[0]; } if (Session["GroupID"] != null && Session["GroupID"].ToString().Length > 0) { groupID = Convert.ToInt32(Session["GroupID"]); } if (groupID > 0 && lc != null) { setEffectiveGroup(groupID, lc.clientID); } if (Session["GroupName"] != null && Session["GroupName"].ToString().Length > 0) { groupName = Session["GroupName"].ToString(); lblGroupNameTitle.Text = groupName; } if (lc != null) { labServer = getLabServer(lc.clientID, effectiveGroupID); clientInfos = AdministrativeAPI.ListClientInfos(lc.clientID); if (lc.clientType == LabClient.INTERACTIVE_APPLET || lc.clientType == LabClient.INTERACTIVE_HTML_REDIRECT) { if (lc.needsScheduling) { Ticket allowExperimentExecutionTicket = null; if (opCoupon != null) { // First check for an Allow Execution Ticket allowExperimentExecutionTicket = issuer.RetrieveTicket( opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION); } if (allowExperimentExecutionTicket == null) { // Try for a reservation int ussId = issuer.FindProcessAgentIdForClient(lc.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussId > 0) { ProcessAgent uss = issuer.GetProcessAgent(ussId); // check for current reservation //create a collection & redeemTicket string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow, DateTime.UtcNow, Session["UserName"].ToString(), Convert.ToInt32(Session["UserID"]), groupName, lc.clientGuid); if (opCoupon == null) opCoupon = issuer.CreateCoupon(); issuer.AddTicket(opCoupon, TicketTypes.REDEEM_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, redeemPayload); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader op = new OperationAuthHeader(); op.coupon = opCoupon; ussProxy.Url = uss.webServiceUrl; ussProxy.OperationAuthHeaderValue = op; Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid, Session["UserName"].ToString(), labServer.agentGuid, lc.clientGuid); if (reservation != null) { // Find efective group setEffectiveGroup(groupID, lc.clientID); // create the allowExecution Ticket DateTime start = reservation.Start; long duration = reservation.Duration; string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload( start, duration, effectiveGroupName,lc.clientGuid); DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; allowExperimentExecutionTicket = issuer.AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload); } } } if (allowExperimentExecutionTicket != null) { XmlDocument payload = new XmlDocument(); payload.LoadXml(allowExperimentExecutionTicket.payload); startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText); duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText); Session["StartExecution"] = DateUtil.ToUtcString(startExecution); Session["Duration"] = duration; // Display reenter button if experiment is reentrant & a current experiment exists if (lc.IsReentrant) { long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(Convert.ToInt32(Session["UserID"]), effectiveGroupID, labServer.agentId, lc.clientID); if (ids.Length > 0) { btnLaunchLab.Text = "Launch New Experiment"; btnLaunchLab.OnClientClick = "javascript:return confirm('Are you sure you want to start a new experiment?\\n If you proceed the currently running experimnent will be closed.');"; btnLaunchLab.Visible = true; pLaunch.Visible = true; pReenter.Visible = true; btnReenter.Visible = true; btnReenter.CommandArgument = ids[0].ToString(); } else { //pReenter.Visible = false; //btnReenter.Visible = false; btnLaunchLab.Text = "Launch Lab"; btnLaunchLab.OnClientClick=""; if (autoLaunch) { launchLabClient(lc.clientID); } else { pLaunch.Visible = true; btnLaunchLab.Visible = true; } } } else { pLaunch.Visible = true; btnLaunchLab.Visible = true; btnLaunchLab.OnClientClick = ""; if (autoLaunch) { launchLabClient(lc.clientID); } } } else { pLaunch.Visible = false; btnLaunchLab.Visible = false; } } else { pLaunch.Visible = true; btnLaunchLab.Visible = true; if (autoLaunch) { launchLabClient(lc.clientID); } } } else if (lc.clientType == LabClient.BATCH_APPLET || lc.clientType == LabClient.BATCH_HTML_REDIRECT) { pLaunch.Visible = true; btnLaunchLab.Visible = true; if (autoLaunch) { launchLabClient(lc.clientID); } } btnSchedule.Visible = lc.needsScheduling; lblClientName.Text = lc.clientName; lblVersion.Text = lc.version; lblLongDescription.Text = lc.clientLongDescription; if (lc.notes != null && lc.notes.Length > 0) { pNotes.Visible = true; lblNotes.Text = lc.notes; } else { pNotes.Visible = false; lblNotes.Text = null; } if (lc.contactEmail != null && lc.contactEmail.Length > 0) { pEmail.Visible = true; string emailCmd = "mailto:" + lc.contactEmail; lblEmail.Text = "<a href=" + emailCmd + ">" + lc.contactEmail + "</a>"; } else { pEmail.Visible = false; lblEmail.Text = null; } if (lc.documentationURL != null && lc.documentationURL.Length > 0) { pDocURL.Visible = true; lblDocURL.Text = "<a href=" + lc.documentationURL + ">" + lc.documentationURL + "</a>"; } else { pDocURL.Visible = false; lblDocURL.Text = null; } btnLaunchLab.Command += new CommandEventHandler(this.btnLaunchLab_Click); btnLaunchLab.CommandArgument = lc.clientID.ToString(); int count = 0; if (clientInfos != null && clientInfos.Length > 0) { //repClientInfos.DataSource = clientInfos; //repClientInfos.DataBind(); foreach (ClientInfo ci in clientInfos) { System.Web.UI.WebControls.Button b = new System.Web.UI.WebControls.Button(); b.Visible = true; b.CssClass = "button"; b.Text = ci.infoURLName; b.CommandArgument = ci.infoURL; b.CommandName = ci.infoURLName; b.ToolTip = ci.description; b.Command += new CommandEventHandler(this.HelpButton_Click); repClientInfos.Controls.Add(b); repClientInfos.Controls.Add(new LiteralControl(" ")); } } } else { // No LabClient btnSchedule.Visible = false; pLaunch.Visible = false; btnLaunchLab.Visible = false; string msg = "There are no labs assigned to group: " + Session["GroupName"].ToString() + "!"; lblResponse.Text = Utilities.FormatErrorMessage(msg); lblResponse.Visible = true; } // System_Messages block SystemMessage[] groupMessages = null; SystemMessage[] serverMessages = null; groupMessages = AdministrativeAPI.SelectSystemMessagesForGroup(Convert.ToInt32(Session["GroupID"])); if (lc != null && labServer != null && labServer.agentId > 0) { serverMessages = wrapper.GetSystemMessagesWrapper(SystemMessage.LAB, 0, 0, labServer.agentId); } if ((groupMessages == null || groupMessages.Length == 0) && (serverMessages == null || serverMessages.Length == 0)) { lblGroupNameSystemMessage.Text = "No Messages at this time!"; lblGroupNameSystemMessage.Visible = true; lblServerSystemMessage.Visible = false; } else { if (groupMessages != null && groupMessages.Length > 0) { lblGroupNameSystemMessage.Text = "Group Messages:"; lblGroupNameSystemMessage.Visible = true; repGroupMessage.DataSource = groupMessages; repGroupMessage.DataBind(); } else { lblGroupNameSystemMessage.Visible = false; } if (serverMessages != null && serverMessages.Length > 0) { lblServerSystemMessage.Text = "Client/Server Messages:"; lblServerSystemMessage.Visible = true; repServerMessage.DataSource = serverMessages; repServerMessage.DataBind(); } else { lblServerSystemMessage.Visible = false; } } }