protected void On_BlobSelected(object sender, GridViewCommandEventArgs e) { lblResponse.Visible = false; if (Session["EssGuid"] != null) { long blobId = Convert.ToInt64(e.CommandArgument); BrokerDB brokerDB = new BrokerDB(); ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(Session["EssGuid"].ToString()); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = brokerDB.GetEssOpCoupon(Convert.ToInt64(txtExperimentID.Text), TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; string url = essProxy.RequestBlobAccess(blobId, "http", 30); if (url != null) { string jScript = "<script language='javascript'>" + "window.open('" + url + "')" + "</script>"; Page.RegisterStartupScript("Open New Window", jScript); //Response.Redirect(url); } else{ lblResponse.Text = Utilities.FormatWarningMessage("Could not access BLOB. "); lblResponse.Visible = true; } } } else { lblResponse.Text = Utilities.FormatWarningMessage("No ESS is specified, so no records. "); lblResponse.Visible = true; } }
protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { clearExperimentDisplay(); long experimentID = Int64.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value); try { ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper (new long[] {experimentID}); if(expInfo[0] != null) { txtExperimentID.Text = expInfo[0].experimentId.ToString(); txtUsername.Text = expInfo[0].userName ; txtGroupName.Text = expInfo[0].groupName; txtLabServerName.Text = expInfo[0].labServerName; txtClientName.Text = expInfo[0].clientName; //Check if update needed from the ESS if one is used if( expInfo[0].essGuid != null){ int expStatus = expInfo[0].status; if((expStatus == StorageStatus.UNKNOWN || expStatus == StorageStatus.INITIALIZED || expStatus == StorageStatus.OPEN || expStatus == StorageStatus.REOPENED ||expStatus == StorageStatus.RUNNING ||expStatus == StorageStatus.BATCH_QUEUED ||expStatus == StorageStatus.BATCH_RUNNING ||expStatus == StorageStatus.BATCH_TERMINATED ||expStatus == StorageStatus.BATCH_TERMINATED_ERROR)) { // This operation should happen within the Wrapper BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(expInfo[0].essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(expInfo[0].experimentId, TicketTypes.RETRIEVE_RECORDS,60,ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; StorageStatus curStatus = essProxy.GetExperimentStatus(expInfo[0].experimentId); if (expInfo[0].status != curStatus.status || expInfo[0].recordCount != curStatus.recordCount || expInfo[0].closeTime != curStatus.closeTime) { DataStorageAPI.UpdateExperimentStatus(curStatus); expInfo[0].status = curStatus.status; expInfo[0].recordCount = curStatus.recordCount; expInfo[0].closeTime = curStatus.closeTime; } } } } txtStatus.Text = DataStorageAPI.getStatusString(expInfo[0].status); txtSubmissionTime.Text = DateUtil.ToUserTime(expInfo[0].creationTime,culture,userTZ); if ((expInfo[0].closeTime != null) && (expInfo[0].closeTime != DateTime.MinValue)) { txtCompletionTime.Text = DateUtil.ToUserTime(expInfo[0].closeTime, culture, userTZ); } else{ txtCompletionTime.Text = "Experiment Not Closed!"; } txtRecordCount.Text = expInfo[0].recordCount.ToString(" 0"); txtAnnotation.Text = expInfo[0].annotation; trSaveAnnotation.Visible = true; trDeleteExperiment.Visible = true; trShowExperiment.Visible = (expInfo[0].recordCount > 0); } } catch(Exception ex) { lblResponse.Text = Utilities.FormatErrorMessage("Error retrieving experiment information. " + ex.Message); lblResponse.Visible = true; } }
protected void displayRecords(long experimentId, string essGuid) { BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; ExperimentRecord[] records = essProxy.GetRecords(experimentId,null); if (records != null) { StringBuilder buf = null; if (cbxContents.Checked) { buf = new StringBuilder(); foreach (ExperimentRecord rec in records) { buf.AppendLine(rec.contents); } txtExperimentRecords.Text = buf.ToString(); txtExperimentRecords.Visible = true; grvExperimentRecords.Visible = false; } else { dtRecords = new DataTable(); dtRecords.Columns.Add("Seq_Num", typeof(System.Int32)); dtRecords.Columns.Add("Record Type", typeof(System.String)); dtRecords.Columns.Add("Contents", typeof(System.String)); foreach (ExperimentRecord rec in records) { DataRow recTmp = dtRecords.NewRow(); recTmp["Seq_Num"] = rec.sequenceNum; recTmp["Record Type"] = rec.type; recTmp["Contents"] = rec.contents; dtRecords.Rows.InsertAt(recTmp, dtRecords.Rows.Count); } grvExperimentRecords.DataSource = dtRecords; grvExperimentRecords.DataBind(); grvExperimentRecords.Visible = true; txtExperimentRecords.Visible = false; } divRecords.Visible = true; } Blob[] blobs = essProxy.GetBlobs(experimentId); if (blobs != null) { dtBlobs = new DataTable(); dtBlobs.Columns.Add("Blob_ID", typeof(System.Int64)); dtBlobs.Columns.Add("Seq_Num", typeof(System.Int32)); dtBlobs.Columns.Add("MimeType", typeof(System.String)); dtBlobs.Columns.Add("Description", typeof(System.String)); foreach (Blob b in blobs) { DataRow blobTmp = dtBlobs.NewRow(); blobTmp["Blob_ID"] = b.blobId; blobTmp["Seq_Num"] = b.recordNumber; blobTmp["MimeType"] = b.mimeType; blobTmp["Description"] = b.description; dtBlobs.Rows.InsertAt(blobTmp, dtBlobs.Rows.Count); } grvBlobs.DataSource = dtBlobs; grvBlobs.DataBind(); divBlobs.Visible = true; } } }
public static ExperimentInformation[] GetExperimentInformation(int[] experimentIDs) { List<ExperimentInformation> list = new List<ExperimentInformation>(); try { long[] expIDs = new long[experimentIDs.Length]; for (int i = 0; i < experimentIDs.Length; i++) { expIDs[i] = (long)experimentIDs[i]; } ExperimentAdminInfo[] expSummaries = InternalDataDB.SelectExperimentAdminInfos(expIDs); if (expSummaries != null) foreach (ExperimentAdminInfo expSum in expSummaries) { ExperimentInformation info = new ExperimentInformation(); info.experimentID = expSum.experimentID; info.userID = expSum.userID; info.effectiveGroupID = expSum.groupID; info.labServerID = expSum.agentID; info.statusCode = expSum.status & StorageStatus.BATCH_MASK; info.submissionTime = expSum.creationTime; info.completionTime = expSum.closeTime; DateTime endTime = expSum.startTime.AddSeconds(expSum.duration); info.expirationTime = endTime; double hours = new TimeSpan(endTime.Ticks - DateTime.UtcNow.Ticks).TotalHours; info.minTimeToLive = hours > 0 ? hours : 0; info.annotation = expSum.annotation; //Get the Experiment records from the ESS if one is used if (expSum.essID > 0) { // This operation should happen within the Wrapper BrokerDB brokerDB = new BrokerDB(); ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(expSum.essID); Coupon opCoupon = brokerDB.GetEssOpCoupon( expSum.experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; Criterion errors = new Criterion("record_type", "like", "*Message"); Criterion extensions = new Criterion("record_type", "like", "*Extension"); Criterion [] criteria = new Criterion[] {errors,extensions }; ExperimentRecord[] records = brokerDB.RetrieveExperimentRecords(expSum.experimentID, criteria); if (records != null) { List<String> valWarnings = new List<String>(); List<String> execWarnings = new List<String>(); foreach (ExperimentRecord rec in records) { if (rec.type.CompareTo(BatchRecordType.EXECUTION_ERROR) == 0) { info.executionErrorMessage = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.VALIDATION_ERROR) == 0) { info.validationErrorMessage = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.BLOB_EXTENSION) == 0) { info.xmlBlobExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.RESULT_EXTENSION) == 0) { info.xmlResultExtension = rec.contents; } else if (rec.type.CompareTo(BatchRecordType.EXECUTION_WARNING) == 0) { execWarnings.Add(rec.contents); } else if (rec.type.CompareTo(BatchRecordType.VALIDATION_WARNING) == 0) { valWarnings.Add(rec.contents); } } if (execWarnings.Count > 0) { info.executionWarningMessages = execWarnings.ToArray(); } if (valWarnings.Count > 0) { info.validationWarningMessages = valWarnings.ToArray(); } } } list.Add(info); } } catch { throw; } if (list.Count > 0) { return list.ToArray(); } else return null; }
/// <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; }
protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { clearExperimentDisplay(); try { ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper (new long[] {Int64.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)}); if(expInfo[0] != null) { if( expInfo[0].essGuid != null){ int expStatus = expInfo[0].status; if ((expStatus == StorageStatus.UNKNOWN || expStatus == StorageStatus.INITIALIZED || expStatus == StorageStatus.OPEN || expStatus == StorageStatus.REOPENED || expStatus == StorageStatus.RUNNING || expStatus == StorageStatus.BATCH_QUEUED || expStatus == StorageStatus.BATCH_RUNNING || expStatus == StorageStatus.BATCH_TERMINATED || expStatus == StorageStatus.BATCH_TERMINATED_ERROR)) { // This operation should happen within the Wrapper BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(expInfo[0].essGuid); if (ess.retired) { throw new Exception("The experiments ESS has been retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(expInfo[0].experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; StorageStatus curStatus = essProxy.GetExperimentStatus(expInfo[0].experimentId); if (expInfo[0].status != curStatus.status || expInfo[0].recordCount != curStatus.recordCount || expInfo[0].closeTime != curStatus.closeTime) { DataStorageAPI.UpdateExperimentStatus(curStatus); expInfo[0].status = curStatus.status; expInfo[0].recordCount = curStatus.recordCount; expInfo[0].closeTime = curStatus.closeTime; } } } } txtExperimentID.Text = expInfo[0].experimentId.ToString () ; txtUserName1.Text = expInfo[0].userName ; txtLabServerName.Text =expInfo[0].labServerName; txtClientName.Text = expInfo[0].clientName; txtGroupName1.Text = expInfo[0].groupName; txtStatus.Text = DataStorageAPI.getStatusString(expInfo[0].status); txtSubmissionTime.Text = DateUtil.ToUserTime(expInfo[0].creationTime,culture,userTZ); if ((expInfo[0].closeTime != null) && (expInfo[0].closeTime != DateTime.MinValue)) txtCompletionTime.Text = DateUtil.ToUserTime(expInfo[0].closeTime, culture, userTZ); else txtCompletionTime.Text = "Not Closed!"; txtRecordCount.Text = expInfo[0].recordCount.ToString(); txtAnnotation.Text = expInfo[0].annotation; txtAnnotation.ReadOnly = false; trShowExperiment.Visible = (expInfo[0].recordCount >0); trSaveAnnotation.Visible = true; trDeleteExperiment.Visible = true; } //txtExperimentSpecification.Text = wrapper.RetrieveExperimentSpecificationWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); //txtExperimentResult.Text = wrapper.RetrieveExperimentResultWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); //txtLabconfig.Text = wrapper.RetrieveLabConfigurationWrapper (Int32.Parse (lbxSelectExperiment.Items [lbxSelectExperiment.SelectedIndex ].Value)); } catch(Exception ex) { lblResponse.Text ="<div class=errormessage><p>Exception: Error retrieving experiment information. "+ex.Message+"</p></div>"; lblResponse.Visible=true; } }
public Experiment RetrieveExperiment(long experimentID) { Experiment experiment = null; BrokerDB brokerDB = new BrokerDB(); int roles = 0; int userID = 0; int groupID = 0; //long[] expIDs = null; Ticket expTicket = brokerDB.RetrieveTicket(opHeader.coupon, TicketTypes.REDEEM_SESSION); if (expTicket != null && !expTicket.IsExpired()) { //Parse payload, only get what is needed XmlQueryDoc expDoc = new XmlQueryDoc(expTicket.payload); //long expID = -1; string userStr = expDoc.Query("RedeemSessionPayload/userID"); if ((userStr != null) && (userStr.Length > 0)) userID = Convert.ToInt32(userStr); string groupStr = expDoc.Query("RedeemSessionPayload/groupID"); if ((groupStr != null) && (groupStr.Length > 0)) groupID = Convert.ToInt32(groupStr); if (userID > 0) { AuthorizationWrapperClass wrapper = new AuthorizationWrapperClass(); roles = wrapper.GetExperimentAuthorizationWrapper(experimentID, userID, groupID); } if ((roles | ExperimentAccess.READ) == ExperimentAccess.READ) { experiment = new Experiment(); experiment.experimentId = experimentID; experiment.issuerGuid = ProcessAgentDB.ServiceGuid; ProcessAgentInfo ess = brokerDB.GetExperimentESS(experimentID); if (ess != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); Coupon opCoupon = brokerDB.GetEssOpCoupon(experimentID, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon == null) { string payload = TicketLoadFactory.Instance().RetrieveRecordsPayload(experimentID, ess.webServiceUrl); opCoupon = brokerDB.CreateTicket(TicketTypes.RETRIEVE_RECORDS, ess.agentGuid, ProcessAgentDB.ServiceGuid, 60, payload); } essProxy.OperationAuthHeaderValue = new OperationAuthHeader(); essProxy.OperationAuthHeaderValue.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.GetRecords(experimentID, null); } } else { throw new AccessDeniedException("You do not have permission to read this experiment"); } } return experiment; }