private void redeemReservation(ReservationInfo res) { long duration = (res.endTime.Ticks - res.startTime.Ticks) / TimeSpan.TicksPerSecond; TicketLoadFactory factory = TicketLoadFactory.Instance(); ProcessAgentDB ticketing = new ProcessAgentDB(); string payload = factory.createAllowExperimentExecutionPayload( res.startTime, duration, Session["groupName"].ToString(),clientGuid); DateTime tmpTime = res.startTime.AddTicks(duration * TimeSpan.TicksPerSecond); DateTime utcNow = DateTime.UtcNow; long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond; TicketIssuerProxy ticketIssuer = new TicketIssuerProxy(); //get the SB web service URL, and set the proxy's URL accordingly ProcessAgentInfo sbInfo = ticketing.GetServiceBrokerInfo(); ticketIssuer.Url = sbInfo.webServiceUrl; //Get the agent coupon Coupon, to be embedded in the SOAP header of the web service call to the SB Coupon agentOutCoupon = sbInfo.identOut; iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader agentAuthHeader = new iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader(); //set the SOAP header (of the proxy class) to the agentCoupon agentAuthHeader.coupon = agentOutCoupon; agentAuthHeader.agentGuid = ProcessAgentDB.ServiceGuid; ticketIssuer.AgentAuthHeaderValue = agentAuthHeader; //call the CreateTicket web service method on the SB (ticket issuer) Coupon allowExecutionCoupon = ticketIssuer.CreateTicket(TicketTypes.ALLOW_EXPERIMENT_EXECUTION, sbInfo.agentGuid, ticketDuration, payload); if (allowExecutionCoupon != null) { string couponId = allowExecutionCoupon.couponId.ToString(); string passkey = allowExecutionCoupon.passkey; string issuerGuid = allowExecutionCoupon.issuerGuid; string backToSbUrl = Session["sbUrl"].ToString() + "?coupon_id=" + couponId + "&passkey=" + passkey + "&issuer_guid=" + issuerGuid; Response.Redirect(backToSbUrl, false); } else { string msg = "Exception: ExperimentExecution is not allowed."; lblErrorMessage.Text = Utilities.FormatErrorMessage(msg); lblErrorMessage.Visible = true; } }
/// <summary> /// Retrieves ticket from local database or the SB. Ticket type is needed to retrieve ticket from SB, /// </summary> /// <param name="coupon">operation coupon sent by the Process Agent</param> /// <param name="ticketType">type of the ticket to be retrieved</param> /// <returns>Retrieved ticket</returns> public Ticket RetrieveAndVerify(Coupon coupon, string ticketType) { Ticket theTicket = RetrieveTicket(coupon, ticketType, ServiceGuid); if (theTicket == null) { TicketIssuerProxy ticketIssuerProxy = new TicketIssuerProxy(); //Get the Service Broker info from the database ProcessAgentInfo sbInfo = GetServiceBrokerInfo(); //get the SB web service URL, and set the proxy's URL accordingly ticketIssuerProxy.Url = sbInfo.webServiceUrl; iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader agentAuthHeader = new iLabs.DataTypes.SoapHeaderTypes.AgentAuthHeader(); //set the SOAP header (of the proxy class) to the agentCoupon agentAuthHeader.coupon = sbInfo.identOut; agentAuthHeader.agentGuid = ServiceGuid; ticketIssuerProxy.AgentAuthHeaderValue = agentAuthHeader; //call the RetrieveTicket web service method on the SB (ticket issuer) theTicket = ticketIssuerProxy.RedeemTicket(coupon, ticketType, ServiceGuid); if (theTicket != null) { // If the ticket is no longer valid do not insert it if (!theTicket.IsExpired() && !theTicket.isCancelled) { if (!AuthenticateCoupon(coupon)) { // coupon is not in the database InsertCoupon(coupon); } InsertTicket(theTicket); } } } //if ticket not found locally or in in the Ticket issuer (SB) database, throw exception if (theTicket == null) { throw new TicketNotFoundException("The requested ticket was not found. " + "Ticket type: " + ticketType + ". Access denied."); } if (theTicket.IsExpired() || theTicket.isCancelled) { throw new TicketExpiredException("The Retrieved ticket has expired. " + "Ticket type: " + ticketType + ". Access denied."); } return theTicket; }
/// <summary> /// Method that does the actual make reservation for the user. /// makes the basis of the parameters from the message and the application database /// </summary> /// <param name="userName"> the user who is scheduling for the lab; must be registered with the service broker</param> /// <param name="groupName">the group name authorized to do a lab</param> /// <param name="labServerGuid">lab server which holds the lab that does the actual scheduling</param> /// <param name="clientGuid">Guid of the lab being registered for</param> /// <param name="start">Start time of a particular period scheduled for</param> /// <param name="end">End time of a particular period being scheduled for</param> /// <returns>returns a message string that the application bases on for to give the feedback to the user</returns> public static string MakeReservation(string userName, string groupName, string labServerGuid, string clientGuid, DateTime start, DateTime end) { string lsGuid = null; int status = -1; string message = null; if (ProcessAgentDB.ServiceAgent != null && ProcessAgentDB.ServiceAgent.domainGuid != null) { ProcessAgentDB paDb = new ProcessAgentDB(); ProcessAgentInfo domainServer = paDb.GetProcessAgentInfo(ProcessAgentDB.ServiceAgent.domainGuid); InteractiveSBProxy isbProxy = new InteractiveSBProxy(); isbProxy.AgentAuthHeaderValue = new AgentAuthHeader(); isbProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; isbProxy.AgentAuthHeaderValue.coupon = domainServer.identOut; isbProxy.Url = domainServer.ServiceUrl; string[] types = new string[] { TicketTypes.SCHEDULE_SESSION }; Coupon opCoupon = isbProxy.RequestAuthorization(types, 600, userName, groupName, labServerGuid, clientGuid); if (opCoupon != null) { TicketIssuerProxy ticketProxy = new TicketIssuerProxy(); ticketProxy.AgentAuthHeaderValue = new AgentAuthHeader(); ticketProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; ticketProxy.AgentAuthHeaderValue.coupon = domainServer.identOut; ticketProxy.Url = domainServer.ServiceUrl; //the method call below is one which does not returns a null value //in otherwards the ticket value is not created. Ticket ticketSMS = ticketProxy.RedeemTicket(opCoupon, TicketTypes.SCHEDULE_SESSION, ProcessAgentDB.ServiceGuid); if (ticketSMS != null) { if (ticketSMS.payload != null || ticketSMS.payload.Length > 0) { XmlQueryDoc xdoc = new XmlQueryDoc(ticketSMS.payload); string ussURL = xdoc.Query("ScheduleSessionPayload/ussURL"); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); ussProxy.OperationAuthHeaderValue = new OperationAuthHeader(); ussProxy.OperationAuthHeaderValue.coupon = opCoupon; ussProxy.Url = ussURL; TimePeriod[] times = ussProxy.RetrieveAvailableTimePeriods(ProcessAgentDB.ServiceAgent.domainGuid, groupName, labServerGuid, clientGuid, start, end); // Logic to check for final time DateTime resStart = start; DateTime resEnd = end; message = ussProxy.AddReservation(ProcessAgentDB.ServiceAgent.domainGuid, userName, groupName, labServerGuid, clientGuid, resStart, resEnd); } } } else { message = "coupon is null"; } } else { message = "This service is not part of a domain, please contact the administrator!"; } return message; }
public Ticket RedeemTicket(Coupon coupon, string type, string redeemerGuid) { Ticket ticket = null; if (brokerDB.AuthenticateAgentHeader(agentAuthHeader)) { if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid) { ticket = brokerDB.RetrieveIssuedTicket(coupon, type, redeemerGuid); } else { ProcessAgentInfo paInfo = brokerDB.GetProcessAgentInfo(coupon.issuerGuid); if (paInfo != null) { if (paInfo.retired) { throw new Exception("The ProcessAgent is retired"); } TicketIssuerProxy ticketProxy = new TicketIssuerProxy(); AgentAuthHeader authHeader = new AgentAuthHeader(); authHeader.coupon = paInfo.identOut; authHeader.agentGuid = ProcessAgentDB.ServiceGuid; ticketProxy.AgentAuthHeaderValue = authHeader; ticketProxy.Url = paInfo.webServiceUrl; ticket = ticketProxy.RedeemTicket(coupon, type, redeemerGuid); } else { throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request"); } } } return ticket; }
public override eStatus Close(eStatus reason) { LabDB dbService = new LabDB(); LabViewInterface lvi = null; try { if (data != null) { XmlQueryDoc taskDoc = new XmlQueryDoc(data); string viName = taskDoc.Query("task/application"); string statusVI = taskDoc.Query("task/status"); string server = taskDoc.Query("task/server"); string portStr = taskDoc.Query("task/serverPort"); #if LabVIEW_WS lvi = new LabViewInterface(); #else if ((portStr != null) && (portStr.Length > 0) && (portStr.CompareTo("0") != 0) ) { lvi = new LabViewRemote(server, Convert.ToInt32(portStr)); } else { lvi = new LabViewInterface(); } #endif // Status VI not used if ((statusVI != null) && statusVI.Length != 0) { try { if(reason == eStatus.Expired) lvi.DisplayStatus(statusVI, "You are out of time!", "0:00"); else lvi.DisplayStatus(statusVI, "Your experiment has been cancelled", "0:00"); } catch (Exception ce) { Logger.WriteLine("Trying StatusVI: " + ce.Message); } } //Get the VI and send version specfic call to get control of the VI //VirtualInstrument vi = lvi.GetVI(viName); // LV 8.2.1 //Server takes control of RemotePanel, connection not brokenS lvi.ReleaseVI(viName); } Logger.WriteLine("TaskID = " + taskID + " has expired"); dbService.SetTaskStatus(taskID, (int)reason); status = eStatus.Closed; DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID); if (dsManager != null) { dsManager.CloseDataSources(); TaskProcessor.Instance.RemoveDataManager(taskID); } dbService.SetTaskStatus(taskID, (int)status); if (couponID > 0) { // this task was created with a valid ticket, i.e. not a test. Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID); // Only use the domain ServiceBroker, do we need a test // Should only be one ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER); if ((sbs == null) || (sbs.Length < 1)) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } ProcessAgentInfo domainSB = null; foreach (ProcessAgentInfo dsb in sbs) { if (!dsb.retired) { domainSB = dsb; break; } } if (domainSB == null) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } InteractiveSBProxy iuProxy = new InteractiveSBProxy(); iuProxy.AgentAuthHeaderValue = new AgentAuthHeader(); iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut; iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; iuProxy.Url = sbs[0].webServiceUrl; StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID); Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount); // currently RequestTicketCancellation always returns false // Create ticketing service interface connection to TicketService TicketIssuerProxy ticketingInterface = new TicketIssuerProxy(); ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader(); ticketingInterface.Url = sbs[0].webServiceUrl; ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut; ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid)) { dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid); Logger.WriteLine("Canceled ticket: " + expCoupon.couponId); } else { Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId); } } } catch (Exception e1) { Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace); } finally { lvi = null; } return base.Close(); }
public bool RequestTicketCancellation(Coupon coupon, string type, string redeemerGuid) { TicketIssuerDB ticketIssuer = new TicketIssuerDB(); bool status = false; if (ticketIssuer.AuthenticateAgentHeader(agentAuthHeader)) { if (coupon.issuerGuid == ProcessAgentDB.ServiceGuid) { return ticketIssuer.RequestTicketCancellation(coupon, type, redeemerGuid); } else { ProcessAgentInfo paInfo = ticketIssuer.GetProcessAgentInfo(coupon.issuerGuid); if (paInfo != null) { if (paInfo.retired) { throw new Exception("The ProcessAgent is retired"); } TicketIssuerProxy ticketProxy = new TicketIssuerProxy(); AgentAuthHeader authHeader = new AgentAuthHeader(); authHeader.coupon = paInfo.identOut; authHeader.agentGuid = ProcessAgentDB.ServiceGuid; ticketProxy.AgentAuthHeaderValue = authHeader; ticketProxy.Url = paInfo.webServiceUrl; status = ticketProxy.RequestTicketCancellation(coupon, type, redeemerGuid); } else { throw new Exception("Unknown TicketIssuerDB in RedeemTicket Request"); } } } return status; }
public virtual eStatus Close(eStatus reason) { LabDB dbService = new LabDB(); try { if (data != null) { XmlQueryDoc taskDoc = new XmlQueryDoc(data); string app = taskDoc.Query("task/application"); string statusName = taskDoc.Query("task/status"); string server = taskDoc.Query("task/server"); string portStr = taskDoc.Query("task/serverPort"); // Status not used if ((statusName != null) && statusName.Length != 0) { try { if (reason == eStatus.Expired) DisplayStatus(statusName, "You are out of time!", "0:00"); else DisplayStatus(statusName, "Your experiment has been cancelled", "0:00"); } catch (Exception ce) { Logger.WriteLine("Trying StatusName: " + ce.Message); } } //Stop the application & close ESS sessions } Logger.WriteLine("TaskID = " + taskID + " is being closed"); dbService.SetTaskStatus(taskID, (int)reason); status = eStatus.Closed; DataSourceManager dsManager = TaskProcessor.Instance.GetDataManager(taskID); if (dsManager != null) { dsManager.CloseDataSources(); TaskProcessor.Instance.RemoveDataManager(taskID); } dbService.SetTaskStatus(taskID, (int)status); if (couponID > 0) { // this task was created with a valid ticket, i.e. not a test. Coupon expCoupon = dbService.GetCoupon(couponID, issuerGUID); // Only use the domain ServiceBroker, do we need a test // Should only be one ProcessAgentInfo[] sbs = dbService.GetProcessAgentInfos(ProcessAgentType.SERVICE_BROKER); if ((sbs == null) || (sbs.Length < 1)) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } ProcessAgentInfo domainSB = null; foreach (ProcessAgentInfo dsb in sbs) { if (!dsb.retired) { domainSB = dsb; break; } } if (domainSB == null) { Logger.WriteLine("Can not retrieve ServiceBroker!"); throw new Exception("Can not retrieve ServiceBroker!"); } InteractiveSBProxy iuProxy = new InteractiveSBProxy(); iuProxy.AgentAuthHeaderValue = new AgentAuthHeader(); iuProxy.AgentAuthHeaderValue.coupon = sbs[0].identOut; iuProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; iuProxy.Url = sbs[0].webServiceUrl; StorageStatus storageStatus = iuProxy.AgentCloseExperiment(expCoupon, experimentID); Logger.WriteLine("AgentCloseExperiment status: " + storageStatus.status + " records: " + storageStatus.recordCount); // currently RequestTicketCancellation always returns false // Create ticketing service interface connection to TicketService TicketIssuerProxy ticketingInterface = new TicketIssuerProxy(); ticketingInterface.AgentAuthHeaderValue = new AgentAuthHeader(); ticketingInterface.Url = sbs[0].webServiceUrl; ticketingInterface.AgentAuthHeaderValue.coupon = sbs[0].identOut; ticketingInterface.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; if (ticketingInterface.RequestTicketCancellation(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid)) { dbService.CancelTicket(expCoupon, TicketTypes.EXECUTE_EXPERIMENT, ProcessAgentDB.ServiceGuid); Logger.WriteLine("Canceled ticket: " + expCoupon.couponId); } else { Logger.WriteLine("Unable to cancel ticket: " + expCoupon.couponId); } } } catch (Exception e1) { Logger.WriteLine("ProcessTasks Cancelled: exception:" + e1.Message + e1.StackTrace); } return status; }