示例#1
0
        /// <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;
            }
        }
示例#2
0
        private void reenterLabClient()
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("login.aspx");
            }
            BrokerDB brokerDB = new BrokerDB();
            StringBuilder message = new StringBuilder("Message: clientID = ");
            int[] labIds = new int[1];
            message.Append(btnReenter.CommandArgument + " ");
            long expid = Convert.ToInt64(btnReenter.CommandArgument);
            LabClient client = AdministrativeAPI.GetLabClient(Convert.ToInt32(Session["ClientID"]));
            if (client.clientID > 0)
            {
                if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT || client.clientType == LabClient.INTERACTIVE_APPLET)
                {
                    long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(expid);
                    Coupon coupon = brokerDB.GetIssuedCoupon(coupIDs[0]);

                    if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                    {
                        // 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=" + brokerDB.GetIssuerGuid());

                        // Add the return url to the redirect
                        url.Append("&sb_url=");
                        url.Append(Utilities.ExportUrlPath(Request.Url));

                        // Now open the lab within the current Window/frame
                        Response.Redirect(url.ToString(), true);
                    }
                    else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                    {
                        // we have the coupon what do we need now to lauch the lab....?
                        // the whole loader script part should have run... so we should be
                        // able to skip that part.

                        // one question would be is the coupon the same...
                        // if they're not the same we need to change it.
                        // It seems that it is the same.
                        // then we just need to launch the client...

                        string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
             + "applet.aspx" + @"'</script>";
                        Page.RegisterStartupScript("ReloadFrame", jScript);

                    }

                }
            }
        }
示例#3
0
        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);
        }
示例#4
0
        public int RemoveTickets(List<Ticket> ticketList, BrokerDB brokerDb)
        {
            ArrayList coupons = new ArrayList();
            Coupon coupon = null;
            int ticketCount = 0;
            int couponCount = 0;
            if (ticketList.Count > 0)
            {
                Utilities.WriteLog("RemoveTickets: expired count = " + ticketList.Count);

                foreach (Ticket ticket in ticketList)
                {
                    if (!coupons.Contains(ticket.couponId))
                    {
                        coupons.Add(ticket.couponId);
                    }
                    if (coupon == null || coupon.couponId != ticket.couponId)
                    {
                        coupon = brokerDb.GetIssuedCoupon(ticket.couponId);
                    }
                    switch (ticket.type)
                    {
                        case TicketTypes.ADMINISTER_EXPERIMENT:

                            string payload = ticket.payload;
                            if (payload != null)
                            {
                                XmlQueryDoc xDoc = new XmlQueryDoc(payload);
                                string url = xDoc.Query("AdministerExperimentPayload/essURL");
                                string expStr = xDoc.Query("AdministerExperimentPayload/experimentID");
                                long expID = Convert.ToInt64(expStr);
                                ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                                essProxy.OperationAuthHeaderValue = new OperationAuthHeader();
                                essProxy.OperationAuthHeaderValue.coupon = coupon;
                                essProxy.Url = url;
                                StorageStatus expStatus = essProxy.SetExperimentStatus(expID, (int)StorageStatus.CLOSED_TIMEOUT);
                                DataStorageAPI.UpdateExperimentStatus(expStatus);
                            }
                            break;
                        case TicketTypes.RETRIEVE_RECORDS:
                        case TicketTypes.STORE_RECORDS:
                            break;
                        case TicketTypes.EXECUTE_EXPERIMENT:
                        case TicketTypes.ALLOW_EXPERIMENT_EXECUTION:
                            break;
                        default: // Every other Ticket type
                            break;
                    }
                    bool statusR = false;

                    if (ticket.redeemerGuid != brokerDb.GetIssuerGuid())
                    {
                        ProcessAgentInfo redeemer = brokerDb.GetProcessAgentInfo(ticket.redeemerGuid);
                        if ((redeemer != null) && !redeemer.retired)
                        {
                            ProcessAgentProxy paProxy = new ProcessAgentProxy();
                            paProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                            paProxy.Url = redeemer.webServiceUrl;
                            paProxy.AgentAuthHeaderValue.coupon = redeemer.identOut;
                            paProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                            statusR = paProxy.CancelTicket(coupon, ticket.type, ticket.redeemerGuid);
                        }
                    }
                    if (ticket.issuerGuid == brokerDb.GetIssuerGuid())
                    {
                        brokerDb.DeleteIssuedTicket(ticket.ticketId);
                        ticketCount++;
                    }
                }
                foreach (long id in coupons)
                {
                    int count = brokerDb.GetIssuedCouponCollectionCount(id);
                    if (count == 0)
                    {
                        brokerDb.DeleteIssuedCoupon(id);
                        couponCount++;
                    }
                }
                Utilities.WriteLog("RemoveTickets: ticketCount=" + ticketCount + " \tcouponCount=" + couponCount);
            }
            return ticketCount;
        }