/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="groupName"></param> /// <param name="labClientName"></param> /// <param name="labClientVersion"></param> /// <returns>The redirect url where the user should be redirected, with the coupon appended to it</returns> public string ExecuteExerimentSchedulingRecipe(string ussGuid, string lssGuid, string username, string groupName, string labServerGuid, string clientGuid, string labClientName, string labClientVersion, long duration, int userTZ) { try { BrokerDB issuer = new BrokerDB(); TicketLoadFactory factory = TicketLoadFactory.Instance(); string ticketType = TicketTypes.SCHEDULE_SESSION; //the uss is the redeemer of the scheduling ticket //string redeemerId = uss.agentGuid; //the SB is the sponsor of the scheduling ticket //string sponsorId = issuer.GetIssuerGuid(); string payload1 = factory.createScheduleSessionPayload(username, groupName, issuer.GetIssuerGuid(), labServerGuid, clientGuid, labClientName, labClientVersion, userTZ); string payload2 = factory.createRequestReservationPayload(); Coupon schedulingCoupon = issuer.CreateTicket(TicketTypes.SCHEDULE_SESSION, ussGuid, issuer.GetIssuerGuid(), duration, payload1); issuer.AddTicket(schedulingCoupon, TicketTypes.REQUEST_RESERVATION, lssGuid, ussGuid, duration, payload2); // // construct the redirection url // string issuerGuid = schedulingCoupon.issuerGuid; string passkey = schedulingCoupon.passkey; string couponId = schedulingCoupon.couponId.ToString(); // obtain the reservation URL from the admin URLs table string schedulingUrl = issuer.RetrieveAdminURL(ussGuid, TicketTypes.SCHEDULE_SESSION).Url; schedulingUrl += "?coupon_id=" + couponId + "&issuer_guid=" + issuerGuid + "&passkey=" + passkey; return schedulingUrl; } catch { throw; } }
public ClientSubmissionReport Submit(string labServerID, string experimentSpecification, int priorityHint, bool emailNotification) { // Default to 24 hours duration long duration = TimeSpan.TicksPerDay/TimeSpan.TicksPerSecond; int seqNo = 0; ClientSubmissionReport clientSReport = null; try{ // Checking if user has permission to use the lab server. The method will set headers for lab server calls //if authorization is successful. CheckAndSetLSAuthorization(labServerID); //Retrieve variables from session int userID = Convert.ToInt32(Session["UserID"]); int effectiveGroupID = Convert.ToInt32(Session["GroupID"]); int clientID = 0; if (Session["ClientID"] != null ) clientID = Convert.ToInt32(Session["ClientID"]); string effectiveGroup = Session["GroupName"].ToString(); ProcessAgentInfo infoLS = dbTicketing.GetProcessAgentInfo(labServerID); if (infoLS.retired) { throw new Exception("The Batch Lab Server is retired"); } // get qualifier ID of labServer int qualifierID = AuthorizationAPI.GetQualifierID(infoLS.agentId, Qualifier.labServerQualifierTypeID); /* End collecting information */ // Checking if user has permission to use the lab server if (!AuthorizationAPI.CheckAuthorization(userID, Function.useLabServerFunctionType, qualifierID)) { // check fails throw new AccessDeniedException("Access denied using labServer '" + infoLS.agentName + "'."); } else { int[] groupIDs = new int[1]; groupIDs[0] = effectiveGroupID; SubmissionReport sReport = new SubmissionReport(); clientSReport = new ClientSubmissionReport(); clientSReport.vReport = new ValidationReport(); clientSReport.wait = new WaitEstimate(); BrokerDB brokerDB = new BrokerDB(); // 1. Create Coupon for ExperimentCollection Coupon coupon = brokerDB.CreateCoupon(); int essID = brokerDB.FindProcessAgentIdForClient(clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER); // // 2. create ServiceBroker experiment record and get corresponding experiment id // This checks authorization. long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, effectiveGroupID, infoLS.agentId, clientID, essID, DateTime.UtcNow, duration); // Store a record of the Experiment Collection Coupon DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId); //3.A create ESS administer experiment ticket, Add 10 minutes to duration // This must be created before the ESS experiment records may be created ProcessAgentInfo essAgent = brokerDB.GetProcessAgentInfo(essID); if (essAgent.retired) { throw new Exception("The Batch Lab Server is retired"); } TicketLoadFactory factory = TicketLoadFactory.Instance(); brokerDB.AddTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, ProcessAgentDB.ServiceGuid, duration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl)); //3.B create store record ticket, in the MergedSB the records are all saved via the serviceBroker brokerDB.AddTicket(coupon, TicketTypes.STORE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, duration, factory.StoreRecordsPayload(true, experimentID, essAgent.webServiceUrl)); //3.C create retrieve experiment ticket, retrieve Experiment Records never expires, unless experiment deleted // This should be changed to a long but finite period once eadExisting Expermint is in place. brokerDB.AddTicket(coupon, TicketTypes.RETRIEVE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, -1, factory.RetrieveRecordsPayload(experimentID, essAgent.webServiceUrl)); // 3.D Create the ESS Experiment Records ExperimentStorageProxy ess = new ExperimentStorageProxy(); ess.AgentAuthHeaderValue = new AgentAuthHeader(); ess.AgentAuthHeaderValue.coupon = essAgent.identOut; ess.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; ess.OperationAuthHeaderValue = new OperationAuthHeader(); ess.OperationAuthHeaderValue.coupon = coupon; ess.Url = essAgent.webServiceUrl; // Call the ESS to create the ESS Records and open the experiment StorageStatus status = ess.OpenExperiment(experimentID, duration); if (status != null) DataStorageAPI.UpdateExperimentStatus(status); seqNo = ess.AddRecord(experimentID, ProcessAgentDB.ServiceGuid, BatchRecordType.SPECIFICATION, true, experimentSpecification, null); // save lab configuration string labConfiguration = batchLS_Proxy.GetLabConfiguration(effectiveGroup); seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.LAB_CONFIGURATION, true, labConfiguration, null); // call labServer submit sReport = batchLS_Proxy.Submit(Convert.ToInt32(experimentID), experimentSpecification, effectiveGroup, priorityHint); // save submission report //wrapper.SaveSubmissionReportWrapper(experimentID, sReport); if (sReport.vReport != null) if ((sReport.vReport.errorMessage != null) && (sReport.vReport.errorMessage.CompareTo("") != 0)) { seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_ERROR, false, sReport.vReport.errorMessage, null); } if (sReport.vReport.warningMessages != null) foreach (string s in sReport.vReport.warningMessages) { if ((s != null) && (s.CompareTo("") != 0)) seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_WARNING, false, s, null); } // return clientSubmissionReport if (sReport.vReport != null) { clientSReport.vReport.accepted = sReport.vReport.accepted; clientSReport.vReport.errorMessage = sReport.vReport.errorMessage; // if error exists then change status to "an experiment with a problem" if ((sReport.vReport.errorMessage != null) && (!sReport.vReport.errorMessage.Equals(""))) { StorageStatus sStatus = new StorageStatus(); sStatus.experimentId = experimentID; //sStatus.estRuntime=sReport.vReport.estRuntime; sStatus.status = StorageStatus.BATCH_TERMINATED_ERROR; DataStorageAPI.UpdateExperimentStatus(sStatus); } clientSReport.vReport.estRuntime = sReport.vReport.estRuntime; clientSReport.vReport.warningMessages = sReport.vReport.warningMessages; } clientSReport.experimentID = Convert.ToInt32(experimentID); clientSReport.minTimeToLive = sReport.minTimetoLive; if (sReport.wait != null) { clientSReport.wait.effectiveQueueLength = sReport.wait.effectiveQueueLength; clientSReport.wait.estWait = sReport.wait.estWait; } } return clientSReport; } catch { throw; } }
private static void ExecuteExperimentExecutionRecipe(ProcessAgentInfo labServer, ref LabClient client, ref DateTime startExecution, long duration, int userTZ, int userID, int groupID, string groupName, out BrokerDB brokerDB, out Coupon coupon) { int essId = 0; ProcessAgentInfo essAgent = null; long ticketDuration = 7200; //Default to 2 hours // Add a 10 minutes to ESS ticket duration ( in seconds ) to extend beyond experiment expiration if (duration != -1) { //ticketDuration = duration + 60; // For testing only add a minute ticketDuration = duration + 600; // Add 10 minutes beyond the experiment end } else { ticketDuration = -1; } // Authorization wrapper AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); // create ticket issuer and payload factory brokerDB = new BrokerDB(); TicketLoadFactory factory = TicketLoadFactory.Instance(); if (client.needsESS) { essId = brokerDB.FindProcessAgentIdForClient(client.clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER); } // 1. Create Coupon for ExperimentCollection coupon = brokerDB.CreateCoupon(); // // 2. create ServiceBroker experiment record and get corresponding experiment id // This checks authorization. long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, groupID, labServer.agentId, client.clientID, essId, startExecution, duration); // Store a record of the Experiment Collection Coupon DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId); string essWebAddress = null; // If a ESS is specified Create the ESS Tickets, this should only happen if a resource is mapped if (essId > 0) { //3.A create ESS administer experiment ticket, Add 10 minutes to duration // This must be created before the ESS experiment records may be created essAgent = brokerDB.GetProcessAgentInfo(essId); if ((essAgent != null) && !essAgent.retired) { brokerDB.AddTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, brokerDB.GetIssuerGuid(), ticketDuration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl)); //3.B create store record ticket brokerDB.AddTicket(coupon, TicketTypes.STORE_RECORDS, essAgent.agentGuid, labServer.agentGuid, ticketDuration, factory.StoreRecordsPayload(true, experimentID, essAgent.webServiceUrl)); //3.C create retrieve experiment ticket, retrieve Experiment Records never expires, unless experiment deleted // This should be changed to a long but finite period once eadExisting Expermint is in place. brokerDB.AddTicket(coupon, TicketTypes.RETRIEVE_RECORDS, essAgent.agentGuid, brokerDB.GetIssuerGuid(), -1, factory.RetrieveRecordsPayload(experimentID, essAgent.webServiceUrl)); // 3.D Create the ESS Experiment Records ExperimentStorageProxy ess = new ExperimentStorageProxy(); ess.AgentAuthHeaderValue = new AgentAuthHeader(); ess.AgentAuthHeaderValue.coupon = essAgent.identOut; ess.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; ess.Url = essAgent.webServiceUrl; essWebAddress = essAgent.webServiceUrl; // Call the ESS to create the ESS Records and open the experiment StorageStatus status = ess.OpenExperiment(experimentID, ticketDuration); if (status != null) DataStorageAPI.UpdateExperimentStatus(status); } } // // 4. create the execution ticket for the experiment // // 4.A create payload string payload = factory.createExecuteExperimentPayload(essWebAddress, startExecution, duration, userTZ, groupName, brokerDB.GetIssuerGuid(), experimentID); // 4.B create experiment execution ticket. brokerDB.AddTicket(coupon, TicketTypes.EXECUTE_EXPERIMENT, labServer.agentGuid, labServer.agentGuid, ticketDuration, payload); // 4.C Create sessionRedemption Ticket string sessionPayload = factory.createRedeemSessionPayload(userID, groupID, client.clientID); brokerDB.AddTicket(coupon, TicketTypes.REDEEM_SESSION, brokerDB.GetIssuerGuid(), brokerDB.GetIssuerGuid(), ticketDuration, sessionPayload); }
public Ticket AddTicket(Coupon coupon, string type, string redeemerGuid, long duration, string payload) { BrokerDB brokerDB = new BrokerDB(); Ticket ticket = null; if (brokerDB.AuthenticateAgentHeader(agentAuthHeader)) { ticket = brokerDB.AddTicket(coupon, type, redeemerGuid, agentAuthHeader.agentGuid, duration, payload); } return ticket; }