/// <summary>
        /// Retrieves an experiment's ResultReport from the ESS
        /// </summary>
        /// <param name="experimentID"></param>
        /// <param name="roles"></param>
        /// <returns>THe ResultStatus or an empty report with status set, when the experiment has not terminated that have not</returns>
        public static ResultReport GetResultReport(int experimentID)
        {
            ResultReport report = null;
            BrokerDB brokerDB = new BrokerDB();
            try
            {
                ExperimentAdminInfo expInfo = InternalDataDB.SelectExperimentAdminInfo(experimentID);
                if (expInfo == null || expInfo.experimentID <= 0)
                {
                    //experiment does not exist
                    throw new SoapException("Invalid experiment ID. ", SoapException.ServerFaultCode);
                }
                else
                {
                    ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(expInfo.essID);
                    if(ess.retired){
                        throw new Exception("The requested ESS has been retired");
                    }
                    ExperimentStorageProxy essProxy = new ExperimentStorageProxy();
                    essProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                    essProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                    essProxy.AgentAuthHeaderValue.coupon = ess.identOut;
                    essProxy.Url = ess.webServiceUrl;

                    Coupon opCoupon = brokerDB.GetEssOpCoupon(expInfo.experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid);
                    OperationAuthHeader opHeader = new OperationAuthHeader();
                    opHeader.coupon = opCoupon;
                    essProxy.OperationAuthHeaderValue = opHeader;
                    if ((expInfo.status & StorageStatus.CLOSED) == 0)
                    {
                        ProcessAgentInfo lsInfo = brokerDB.GetProcessAgentInfo(expInfo.agentID);
                        if (lsInfo != null)
                        {
                            if(lsInfo.retired){
                                throw new Exception("The requested batch LabServer has ben retired.");
                            }
                            BatchLSProxy batchLS_Proxy = new BatchLSProxy();
                            batchLS_Proxy.AuthHeaderValue = new AuthHeader();
                            batchLS_Proxy.AuthHeaderValue.identifier = ProcessAgentDB.ServiceGuid;
                            batchLS_Proxy.AuthHeaderValue.passKey = lsInfo.identOut.passkey;
                            batchLS_Proxy.Url = lsInfo.webServiceUrl;
                            // retrieve resultReport from labServer

                            LabExperimentStatus expStatus = batchLS_Proxy.GetExperimentStatus(experimentID);
                            if (expStatus != null)
                            {
                                if ((expStatus.statusReport.statusCode >= 3) && (expStatus.statusReport.statusCode != 6))
                                {
                                    report = batchLS_Proxy.RetrieveResult(experimentID);
                                        if (report != null)
                                        {
                                            ExperimentRecord theRecord = null;
                                            List<ExperimentRecord> recordList = new List<ExperimentRecord>();
                                            if (report.experimentResults != null && report.experimentResults.Length > 0)
                                            {
                                                theRecord = new ExperimentRecord();
                                                theRecord.submitter = lsInfo.agentGuid;
                                                theRecord.type = BatchRecordType.RESULT;
                                                theRecord.contents = report.experimentResults;
                                                theRecord.xmlSearchable = false;
                                                recordList.Add(theRecord);
                                            }
                                            if (report.errorMessage != null && report.errorMessage.Length > 0)
                                            {
                                                theRecord = new ExperimentRecord();
                                                theRecord.submitter = lsInfo.agentGuid;
                                                theRecord.type = BatchRecordType.EXECUTION_ERROR;
                                                theRecord.contents = report.errorMessage;
                                                theRecord.xmlSearchable = false;
                                                recordList.Add(theRecord);
                                            }
                                            if (report.warningMessages != null && report.warningMessages.Length > 0)
                                            {
                                                foreach (string s in report.warningMessages)
                                                {
                                                    if (s.Length > 0)
                                                    {
                                                        theRecord = new ExperimentRecord();
                                                        theRecord.submitter = lsInfo.agentGuid;
                                                        theRecord.type = BatchRecordType.EXECUTION_WARNING;
                                                        theRecord.contents = s;
                                                        theRecord.xmlSearchable = false;
                                                        recordList.Add(theRecord);
                                                    }
                                                }
                                            }
                                            if (report.xmlResultExtension != null && report.xmlResultExtension.Length > 0)
                                            {
                                                theRecord = new ExperimentRecord();
                                                theRecord.submitter = lsInfo.agentGuid;
                                                theRecord.type = BatchRecordType.RESULT_EXTENSION;
                                                theRecord.contents = report.xmlResultExtension;
                                                theRecord.xmlSearchable = true;
                                                recordList.Add(theRecord);
                                            }
                                            if (report.xmlBlobExtension != null && report.xmlBlobExtension.Length > 0)
                                            {
                                                theRecord = new ExperimentRecord();
                                                theRecord.submitter = lsInfo.agentGuid;
                                                theRecord.type = BatchRecordType.BLOB_EXTENSION;
                                                theRecord.contents = report.xmlBlobExtension;
                                                theRecord.xmlSearchable = true;
                                                recordList.Add(theRecord);
                                            }
                                            if (recordList.Count > 0)
                                            {
                                                essProxy.AddRecords(experimentID, recordList.ToArray());
                                            }
                                            StorageStatus sStatus = essProxy.SetExperimentStatus(experimentID, report.statusCode | StorageStatus.CLOSED);
                                            DataStorageAPI.UpdateExperimentStatus(sStatus);
                                        }
                                    }
                                }

                        }
                    }
                    else
                    {
                        report = new ResultReport();
                        ExperimentRecord[] records = essProxy.GetRecords(experimentID, null);
                        if (records != null)
                        {
                            List<String> execWarnings = new List<String>();
                            foreach (ExperimentRecord rec in records)
                            {
                                if (rec.type.CompareTo(BatchRecordType.EXECUTION_ERROR) == 0)
                                {
                                    report.errorMessage = rec.contents;
                                }

                                else if (rec.type.CompareTo(BatchRecordType.BLOB_EXTENSION) == 0)
                                {
                                    report.xmlBlobExtension = rec.contents;
                                }
                                else if (rec.type.CompareTo(BatchRecordType.RESULT_EXTENSION) == 0)
                                {
                                    report.xmlResultExtension = rec.contents;
                                }
                                else if (rec.type.CompareTo(BatchRecordType.EXECUTION_WARNING) == 0)
                                {
                                    execWarnings.Add(rec.contents);
                                }
                                else if (rec.type.CompareTo(BatchRecordType.RESULT) == 0)
                                {
                                    report.experimentResults = rec.contents;
                                }

                            }
                            if (execWarnings.Count > 0)
                            {
                                report.warningMessages = execWarnings.ToArray();
                            }
                        }
                        report.statusCode = expInfo.status & StorageStatus.BATCH_MASK;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new SoapException(ex.Message + ". " + ex.GetBaseException(), SoapException.ServerFaultCode, ex);
            }
            return report;
        }
Exemple #2
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;
        }